WebPanel final-review fix: truthful browser fallback, focus gate, docs

- Creation-failure fallback sets OpenedInBrowser and says "opened" only
  when the system browser actually opened; otherwise chat says the
  browser did not open. Harness check CreateFailureBrowserFails.
- FocusPage follows the same in-process foreground rule as
  SetForegroundWindow (Show and controller creation). Harness check
  NoFocusFromAnotherProcess; posted-key checks report UNVERIFIED when
  another process holds the foreground.
- PermissionRequested: SavesInProfile = false.
- WEB_PANEL.md: allowlist empty-entry rule, GetState -4, AOT renumber
  caveat, softened focus claim (also in the Changelog).
- Formatting: ChatCommandReplyTests brace, /rc layout comment,
  PluginContract blank line.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Daniel Wallace 2026-11-07 16:14:57 -08:00
commit 537a40a430
7 changed files with 116 additions and 21 deletions

View file

@ -619,7 +619,7 @@ internal sealed unsafe class WebPanelHost
{
_ctl.IsVisible = true;
NavigatePending(_serving);
FocusPage();
if (ForegroundIsThisProcess()) FocusPage(); // the rule Show uses: never focus from another program
}
else
{
@ -770,6 +770,8 @@ internal sealed unsafe class WebPanelHost
state = CoreWebView2PermissionState.Allow;
}
catch { state = CoreWebView2PermissionState.Deny; }
// Never remember a decision in the profile: an Allow must not outlive an allowlist change.
try { e.SavesInProfile = false; } catch { }
e.State = state;
}
@ -861,7 +863,6 @@ internal sealed unsafe class WebPanelHost
{
fallback = true;
url = r.Url;
_flags |= StateOpenedInBrowser;
}
}
}
@ -871,9 +872,13 @@ 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;
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("[RynthCore] The in-game browser could not start (" + why + "); opened the page in your web browser.");
SafeChat(ok
? "[RynthCore] The in-game browser could not start (" + why + "); opened the page in your web browser."
: "[RynthCore] The in-game browser could not start (" + why + "), and your web browser did not open.");
}
private void Show()
@ -885,16 +890,23 @@ internal sealed unsafe class WebPanelHost
// 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).
IntPtr fg = GetForegroundWindow();
uint fgPid = 0;
if (fg != IntPtr.Zero) GetWindowThreadProcessId(fg, out fgPid);
if (fg != IntPtr.Zero && fgPid == _ourPid) SetForegroundWindow(_staHwnd);
bool inProcess = ForegroundIsThisProcess();
if (inProcess) SetForegroundWindow(_staHwnd);
if (_ctl != null) { try { _ctl.IsVisible = true; } catch { } }
FocusPage();
if (inProcess) FocusPage(); // same rule: moving WebView2 focus can activate the host window
if (!_timerOn) { SetTimer(_staHwnd, TimerId, 50, IntPtr.Zero); _timerOn = true; }
UpdateStateFlags();
}
/// <summary>The foreground is a window of this process (not null, not another program, not the browser process).</summary>
private bool ForegroundIsThisProcess()
{
IntPtr fg = GetForegroundWindow();
if (fg == IntPtr.Zero) return false;
GetWindowThreadProcessId(fg, out uint fgPid);
return fgPid == _ourPid;
}
private void FocusPage()
{
try { _ctl?.MoveFocus(CoreWebView2MoveFocusReason.Programmatic); } catch { }