WebPanel: publish Failed together with the browser-fallback outcome
A plugin polling between Failed and OpenedInBrowser saw Failed with no flag and, per the docs, opened the page itself: a second open with a spent code. While the fallback is pending the status keeps its pre-failure value; after OpenInBrowser (outside the lock) one lock sets Failed, the error and, when the browser opened, the flag. The no-fallback path is unchanged. Harness: OpenInBrowser delay mode and a continuous poll in CreateFailureFallsBack. Show comments reworded as defensive, not observed. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
537a40a430
commit
7e2cf67e30
3 changed files with 49 additions and 11 deletions
|
|
@ -855,15 +855,20 @@ internal sealed unsafe class WebPanelHost
|
|||
}
|
||||
else
|
||||
{
|
||||
_status = (int)WebPanelStatusCode.Failed;
|
||||
_error = (int)code;
|
||||
WebPanelRequest? r = _req;
|
||||
if (allowFallback && r != null && (code == WebPanelCode.RuntimeMissing || code == WebPanelCode.CreateFailed)
|
||||
&& (r.Flags & FlagFallback) != 0 && _navCount == 0 && WebPanelUrlPolicy.IsBrowserSafe(r.Url))
|
||||
{
|
||||
// Failed is published only together with the fallback's outcome (below): a plugin polling in
|
||||
// between must never see Failed without OpenedInBrowser and open the page a second time.
|
||||
fallback = true;
|
||||
url = r.Url;
|
||||
}
|
||||
else
|
||||
{
|
||||
_status = (int)WebPanelStatusCode.Failed;
|
||||
_error = (int)code;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (ignored) { SafeLog($"panel failure after close or supersede, panel left as it is: {code} ({reason})"); return; }
|
||||
|
|
@ -872,8 +877,17 @@ internal sealed unsafe class WebPanelHost
|
|||
if (!fallback) return;
|
||||
bool ok = false;
|
||||
try { ok = _env.OpenInBrowser(url); } catch { }
|
||||
// The flag reports what happened, so it is set only once the browser opened, and only for the panel that failed.
|
||||
if (ok) lock (_sync) if (handle == _live) _flags |= StateOpenedInBrowser;
|
||||
// One lock: Failed, the error and (only when the browser opened) the flag become visible together, and only
|
||||
// for the panel that failed; a Close or a newer Open in the meantime wins.
|
||||
lock (_sync)
|
||||
{
|
||||
if (handle == _live && _status != (int)WebPanelStatusCode.Closed)
|
||||
{
|
||||
_status = (int)WebPanelStatusCode.Failed;
|
||||
_error = (int)code;
|
||||
if (ok) _flags |= StateOpenedInBrowser;
|
||||
}
|
||||
}
|
||||
SafeLog((ok ? "fallback: opened in the system browser: " : "fallback: the system browser did not open: ") + WebPanelUrlPolicy.Redact(url));
|
||||
string why = code == WebPanelCode.RuntimeMissing ? "WebView2 runtime not installed" : "it failed to start";
|
||||
SafeChat(ok
|
||||
|
|
@ -888,12 +902,13 @@ internal sealed unsafe class WebPanelHost
|
|||
// Focus the panel only from within this process (the game, or a pop-out): a plugin opening it while the
|
||||
// player is in another program must not pull the foreground away (the PID rule keeps it hidden meanwhile).
|
||||
// Never while the foreground is null (mid alt-tab): that would grab focus on the way to another program.
|
||||
// Only this process: a foreground in the WebView2 browser process is the page's own dialog, which keeps
|
||||
// it (IsOurPid, which includes the browser, is for the visibility rule only).
|
||||
// Only this process, defensively: a foreground in the WebView2 browser process is assumed (not observed) to
|
||||
// be the page's own dialog, which should keep it (IsOurPid, which includes the browser, is for the
|
||||
// visibility rule only).
|
||||
bool inProcess = ForegroundIsThisProcess();
|
||||
if (inProcess) SetForegroundWindow(_staHwnd);
|
||||
if (_ctl != null) { try { _ctl.IsVisible = true; } catch { } }
|
||||
if (inProcess) FocusPage(); // same rule: moving WebView2 focus can activate the host window
|
||||
if (inProcess) FocusPage(); // same rule, defensively: moving WebView2 focus might activate the host window (not observed)
|
||||
if (!_timerOn) { SetTimer(_staHwnd, TimerId, 50, IntPtr.Zero); _timerOn = true; }
|
||||
UpdateStateFlags();
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue