Web panel host fix round 1: non-fatal process kinds, late failures, thread restart, focus and permission guards
- ProcessFailed: only BrowserProcessExited (teardown) and RenderProcessExited (about:blank, recreate on the next Open) fail the panel, as WebView2's docs describe the kinds; GPU, utility, sandbox, PPAPI and frame-only renderer exits are logged only. RenderProcessUnresponsive fails it at 3 reports within 30 s. The handler acts on the panel being served now. - Fail decides "ignored" under the lock first and hides the panel only when the failure is live: a late failure for a superseded handle no longer hides the newer panel. - The panel thread's finally restarts the thread when an Open is still queued and the host is not shutting down; _threadDone goes false only after StartStaThread returns. - Show takes the foreground only when a window of this process (or of this panel's WebView2 browser process) holds it, never while the foreground is null. The visibility rule counts the browser process (CoreWebView2.BrowserProcessId) as ours, so the page's own dialogs do not hide the panel. - ClipboardRead is allowed only for an allowlisted origin. NavigationStarting and NewWindowRequested fail closed on an exception. - WebPanelApiRules: the ABI glue's pure parts (refusals, GetState Size check, state write), tested in WebPanelTests with WebPanelNativeArgs. WebPanelApi.LiveHandle and the browser pid in Describe for Task 4. - Harness: GpuProcessCrashKeepsPanel and LateFailureForSupersededHandle (both RED before the fix), UnloadWhileVisibleCollected reports UNVERIFIED when the window was not visible, the game-side key count is informational. EngineSettingsTests: WebPanel default-on round trip and setter case. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
f130be3d2b
commit
388f3fd908
9 changed files with 427 additions and 64 deletions
|
|
@ -21,8 +21,8 @@ internal static unsafe class WebPanelApi
|
|||
{
|
||||
try
|
||||
{
|
||||
if (s_shutdown || EngineLifecycle.IsShuttingDown) return (int)WebPanelCode.ShuttingDown;
|
||||
if (!EngineSettings.WebPanel) return (int)WebPanelCode.Unavailable;
|
||||
int refusal = WebPanelApiRules.OpenRefusal(s_shutdown || EngineLifecycle.IsShuttingDown, EngineSettings.WebPanel);
|
||||
if (refusal != 0) return refusal;
|
||||
EngineWebPanelEnvironment env;
|
||||
WebPanelHost host;
|
||||
lock (Sync)
|
||||
|
|
@ -46,7 +46,8 @@ internal static unsafe class WebPanelApi
|
|||
{
|
||||
try
|
||||
{
|
||||
if (s_shutdown) return (int)WebPanelCode.ShuttingDown;
|
||||
int refusal = WebPanelApiRules.CallRefusal(s_shutdown);
|
||||
if (refusal != 0) return refusal;
|
||||
if (!WebPanelNativeArgs.TryReadUtf8(urlUtf8, WebPanelUrlPolicy.MaxUrlBytes, true, out string url)) return (int)WebPanelCode.BadArgs;
|
||||
WebPanelHost? host = s_host;
|
||||
return host == null ? (int)WebPanelCode.StaleHandle : host.Navigate(handle, url);
|
||||
|
|
@ -62,7 +63,8 @@ internal static unsafe class WebPanelApi
|
|||
{
|
||||
try
|
||||
{
|
||||
if (s_shutdown) return (int)WebPanelCode.ShuttingDown;
|
||||
int refusal = WebPanelApiRules.CallRefusal(s_shutdown);
|
||||
if (refusal != 0) return refusal;
|
||||
WebPanelHost? host = s_host;
|
||||
return host == null ? (int)WebPanelCode.StaleHandle : host.Close(handle);
|
||||
}
|
||||
|
|
@ -77,26 +79,22 @@ internal static unsafe class WebPanelApi
|
|||
{
|
||||
try
|
||||
{
|
||||
if (state == null || state->Size < (uint)((byte*)state->Reserved - (byte*)state)) return (int)WebPanelCode.BadArgs;
|
||||
if (s_shutdown) return (int)WebPanelCode.ShuttingDown;
|
||||
if (!WebPanelApiRules.StateArgsOk(state)) return (int)WebPanelCode.BadArgs;
|
||||
int refusal = WebPanelApiRules.CallRefusal(s_shutdown);
|
||||
if (refusal != 0) return refusal;
|
||||
WebPanelHost? host = s_host;
|
||||
WebPanelSnapshot s;
|
||||
int r;
|
||||
if (host == null)
|
||||
{
|
||||
s = new WebPanelSnapshot(handle, (int)WebPanelStatusCode.Superseded, 0, 0, 0, 0);
|
||||
r = (int)WebPanelStatusCode.Superseded;
|
||||
s = WebPanelApiRules.NoPanel(handle);
|
||||
r = s.Status;
|
||||
}
|
||||
else
|
||||
{
|
||||
r = host.GetState(handle, out s);
|
||||
}
|
||||
state->Handle = s.Handle;
|
||||
state->Status = s.Status;
|
||||
state->Flags = s.Flags;
|
||||
state->Error = s.Error;
|
||||
state->LastHttpStatus = s.LastHttpStatus;
|
||||
state->NavigationCount = s.NavigationCount;
|
||||
WebPanelApiRules.WriteState(state, s);
|
||||
return r;
|
||||
}
|
||||
catch (System.Exception ex)
|
||||
|
|
@ -118,7 +116,10 @@ internal static unsafe class WebPanelApi
|
|||
host?.Shutdown(ShutdownBudgetMs);
|
||||
}
|
||||
|
||||
/// <summary>Redacted one-liner (no query, fragment or userinfo).</summary>
|
||||
/// <summary>The live panel handle, 0 when none was opened: lets the engine close it (WebPanelApi.Close(LiveHandle)).</summary>
|
||||
internal static int LiveHandle => s_host?.LiveHandle ?? 0;
|
||||
|
||||
/// <summary>Redacted one-liner (no query, fragment or userinfo); includes the WebView2 browser pid.</summary>
|
||||
internal static string Describe()
|
||||
{
|
||||
WebPanelHost? host = s_host;
|
||||
|
|
@ -135,6 +136,7 @@ internal static unsafe class WebPanelApi
|
|||
internal static int Close(int handle) => (int)WebPanelCode.Unavailable;
|
||||
internal static int GetState(int handle, WebPanelStateNative* state) => (int)WebPanelCode.Unavailable;
|
||||
internal static void Shutdown() { }
|
||||
internal static int LiveHandle => 0;
|
||||
internal static string Describe() => "web panel: not available in this engine build";
|
||||
}
|
||||
#endif
|
||||
|
|
|
|||
46
src/RynthCore.Engine/WebPanel/WebPanelApiRules.cs
Normal file
46
src/RynthCore.Engine/WebPanel/WebPanelApiRules.cs
Normal file
|
|
@ -0,0 +1,46 @@
|
|||
using RynthCore.Engine.Plugins;
|
||||
|
||||
namespace RynthCore.Engine.WebPanel;
|
||||
|
||||
/// <summary>What WebPanelGetState reports for one handle.</summary>
|
||||
internal readonly record struct WebPanelSnapshot(int Handle, int Status, uint Flags, int Error, int LastHttpStatus, uint NavigationCount);
|
||||
|
||||
/// <summary>
|
||||
/// The pure decisions of the v93 ABI glue (WebPanelApi.cs), kept apart so tools\WebPanelTests can check them
|
||||
/// without the engine: refusals, the GetState argument check, and writing the result struct.
|
||||
/// </summary>
|
||||
internal static unsafe class WebPanelApiRules
|
||||
{
|
||||
/// <summary>0 to go on, else the refusal. Shutting down wins over the engine.json "WebPanel" kill switch.</summary>
|
||||
public static int OpenRefusal(bool shuttingDown, bool enabled) =>
|
||||
shuttingDown ? (int)WebPanelCode.ShuttingDown : enabled ? 0 : (int)WebPanelCode.Unavailable;
|
||||
|
||||
/// <summary>Navigate, Close and GetState: 0 to go on, else ShuttingDown.</summary>
|
||||
public static int CallRefusal(bool shuttingDown) => shuttingDown ? (int)WebPanelCode.ShuttingDown : 0;
|
||||
|
||||
/// <summary>OffsetOf(Reserved): the smallest Size a caller's WebPanelStateNative may declare (32 on x86).</summary>
|
||||
public static uint StateMinSize
|
||||
{
|
||||
get
|
||||
{
|
||||
WebPanelStateNative s = default;
|
||||
return (uint)((byte*)s.Reserved - (byte*)&s);
|
||||
}
|
||||
}
|
||||
|
||||
public static bool StateArgsOk(WebPanelStateNative* state) => state != null && state->Size >= StateMinSize;
|
||||
|
||||
/// <summary>What a handle reads when no panel was ever opened.</summary>
|
||||
public static WebPanelSnapshot NoPanel(int handle) => new(handle, (int)WebPanelStatusCode.Superseded, 0, 0, 0, 0);
|
||||
|
||||
/// <summary>Writes the fields before Reserved only (the caller's Size covers at least those).</summary>
|
||||
public static void WriteState(WebPanelStateNative* state, in WebPanelSnapshot s)
|
||||
{
|
||||
state->Handle = s.Handle;
|
||||
state->Status = s.Status;
|
||||
state->Flags = s.Flags;
|
||||
state->Error = s.Error;
|
||||
state->LastHttpStatus = s.LastHttpStatus;
|
||||
state->NavigationCount = s.NavigationCount;
|
||||
}
|
||||
}
|
||||
|
|
@ -29,8 +29,6 @@ using static RynthCore.Engine.WebPanel.WebPanelNative;
|
|||
|
||||
namespace RynthCore.Engine.WebPanel;
|
||||
|
||||
internal readonly record struct WebPanelSnapshot(int Handle, int Status, uint Flags, int Error, int LastHttpStatus, uint NavigationCount);
|
||||
|
||||
internal sealed unsafe class WebPanelHost
|
||||
{
|
||||
private const uint WM_RUN = WM_APP + 1;
|
||||
|
|
@ -66,7 +64,8 @@ internal sealed unsafe class WebPanelHost
|
|||
// ---- panel thread only ----
|
||||
private IntPtr _staHwnd, _hook, _bgBrush, _captionBrush;
|
||||
private string _className = "";
|
||||
private bool _windowFailed, _tornDown, _open, _timerOn, _inSizeMove;
|
||||
private bool _windowFailed, _tornDown, _timerOn, _inSizeMove;
|
||||
private volatile bool _open;
|
||||
private int _serving; // the handle whose request the panel shows
|
||||
private WebPanelRequest? _req;
|
||||
private string _title = "RynthCore";
|
||||
|
|
@ -115,9 +114,7 @@ internal sealed unsafe class WebPanelHost
|
|||
{
|
||||
// First call (or the thread died): start it and return at once. The thread creates its
|
||||
// window first, then drains the queue.
|
||||
_threadDone = false;
|
||||
_hwnd = IntPtr.Zero;
|
||||
_thread = _env.StartStaThread("RynthCore.WebPanel", ThreadMain);
|
||||
StartThreadLocked();
|
||||
}
|
||||
else if (_hwnd != IntPtr.Zero)
|
||||
{
|
||||
|
|
@ -199,6 +196,9 @@ internal sealed unsafe class WebPanelHost
|
|||
SafeLog($"shutdown: the panel thread did not finish within {budgetMs} ms");
|
||||
}
|
||||
|
||||
/// <summary>The live handle (0 before the first Open), for engine-side callers such as a close-on-command.</summary>
|
||||
public int LiveHandle { get { lock (_sync) return _live; } }
|
||||
|
||||
public string Describe()
|
||||
{
|
||||
lock (_sync)
|
||||
|
|
@ -206,10 +206,18 @@ internal sealed unsafe class WebPanelHost
|
|||
string thread = _thread == null ? "not started" : _threadDone ? "stopped" : "running";
|
||||
string status = ((WebPanelStatusCode)_status).ToString();
|
||||
return $"web panel: thread {thread}{(_shuttingDown ? " (shut down)" : "")}, handle {_live}, {status}, error {_error}, " +
|
||||
$"http {_http}, navigations {_navCount}, environments {_environmentCount}, flags {_flags}, url {WebPanelUrlPolicy.Redact(_liveUrl)}";
|
||||
$"http {_http}, navigations {_navCount}, environments {_environmentCount}, flags {_flags}, browser pid {_browserPid}, url {WebPanelUrlPolicy.Redact(_liveUrl)}";
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>Under _sync. _threadDone goes false only once the thread exists, so a failed start leaves it true.</summary>
|
||||
private void StartThreadLocked()
|
||||
{
|
||||
_hwnd = IntPtr.Zero;
|
||||
_thread = _env.StartStaThread("RynthCore.WebPanel", ThreadMain);
|
||||
_threadDone = false;
|
||||
}
|
||||
|
||||
// The live request's allowlist, for Navigate's caller-side check (set on Open, under _sync).
|
||||
private string[] _currentAllowlist = Array.Empty<string>();
|
||||
|
||||
|
|
@ -241,6 +249,9 @@ internal sealed unsafe class WebPanelHost
|
|||
internal string SourceForTests => _source;
|
||||
internal bool ThreadRunningForTests { get { lock (_sync) return _thread != null && !_threadDone && _thread.IsAlive; } }
|
||||
internal bool PostForTests(Action<CoreWebView2?> a) => Post(() => a(_web));
|
||||
internal bool PanelOpenForTests => _open;
|
||||
/// <summary>A failure arriving late for <paramref name="handle"/> (the harness passes a superseded one).</summary>
|
||||
internal bool FailForTests(int handle) => Post(() => Fail(handle, WebPanelCode.ProcessFailed, "synthetic (harness)", allowFallback: false));
|
||||
|
||||
// ============================ panel thread ============================
|
||||
|
||||
|
|
@ -286,6 +297,14 @@ internal sealed unsafe class WebPanelHost
|
|||
{
|
||||
_threadDone = true;
|
||||
_hwnd = IntPtr.Zero;
|
||||
// An Open queued after this thread's last drain (e.g. while a failed window creation was being
|
||||
// torn down) would otherwise wait for the next Open: start a fresh thread for it now. The new
|
||||
// thread cannot finish (its finally takes this lock) before _threadDone is set back.
|
||||
if (!_shuttingDown && !_queue.IsEmpty)
|
||||
{
|
||||
try { StartThreadLocked(); }
|
||||
catch (Exception ex) { SafeLog("could not restart the panel thread: " + ex.GetType().Name); }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -623,21 +642,29 @@ internal sealed unsafe class WebPanelHost
|
|||
|
||||
private void OnNavigationStarting(object? sender, CoreWebView2NavigationStartingEventArgs e)
|
||||
{
|
||||
string url = e.Uri;
|
||||
if (string.Equals(url, "about:blank", StringComparison.OrdinalIgnoreCase)) return; // our own close, or the page's
|
||||
string[] allow = _req?.Allowlist ?? Array.Empty<string>();
|
||||
if (!WebPanelUrlPolicy.IsAllowed(url, allow))
|
||||
try
|
||||
{
|
||||
e.Cancel = true;
|
||||
RouteOffList(url);
|
||||
return;
|
||||
string url = e.Uri;
|
||||
if (string.Equals(url, "about:blank", StringComparison.OrdinalIgnoreCase)) return; // our own close, or the page's
|
||||
string[] allow = _req?.Allowlist ?? Array.Empty<string>();
|
||||
if (!WebPanelUrlPolicy.IsAllowed(url, allow))
|
||||
{
|
||||
e.Cancel = true;
|
||||
RouteOffList(url);
|
||||
return;
|
||||
}
|
||||
int handle = _serving;
|
||||
SetState(handle, () =>
|
||||
{
|
||||
_navCount++;
|
||||
if (_status != (int)WebPanelStatusCode.Closed && _status != (int)WebPanelStatusCode.Failed) _status = (int)WebPanelStatusCode.Loading;
|
||||
});
|
||||
}
|
||||
int handle = _serving;
|
||||
SetState(handle, () =>
|
||||
catch
|
||||
{
|
||||
_navCount++;
|
||||
if (_status != (int)WebPanelStatusCode.Closed && _status != (int)WebPanelStatusCode.Failed) _status = (int)WebPanelStatusCode.Loading;
|
||||
});
|
||||
// Fail closed: a guard that threw must not let the navigation through.
|
||||
try { e.Cancel = true; } catch { }
|
||||
}
|
||||
}
|
||||
|
||||
private void OnNavigationCompleted(object? sender, CoreWebView2NavigationCompletedEventArgs e)
|
||||
|
|
@ -657,16 +684,24 @@ internal sealed unsafe class WebPanelHost
|
|||
|
||||
private void OnNewWindowRequested(object? sender, CoreWebView2NewWindowRequestedEventArgs e)
|
||||
{
|
||||
e.Handled = true; // never a second window
|
||||
string url = e.Uri;
|
||||
string[] allow = _req?.Allowlist ?? Array.Empty<string>();
|
||||
if (WebPanelUrlPolicy.IsAllowed(url, allow))
|
||||
try
|
||||
{
|
||||
try { _web?.Navigate(url); } catch { }
|
||||
e.Handled = true; // never a second window
|
||||
string url = e.Uri;
|
||||
string[] allow = _req?.Allowlist ?? Array.Empty<string>();
|
||||
if (WebPanelUrlPolicy.IsAllowed(url, allow))
|
||||
{
|
||||
try { _web?.Navigate(url); } catch { }
|
||||
}
|
||||
else
|
||||
{
|
||||
RouteOffList(url);
|
||||
}
|
||||
}
|
||||
else
|
||||
catch
|
||||
{
|
||||
RouteOffList(url);
|
||||
// Fail closed: still no second window.
|
||||
try { e.Handled = true; } catch { }
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -704,9 +739,16 @@ internal sealed unsafe class WebPanelHost
|
|||
|
||||
private void OnPermissionRequested(object? sender, CoreWebView2PermissionRequestedEventArgs e)
|
||||
{
|
||||
e.State = e.PermissionKind == CoreWebView2PermissionKind.ClipboardRead
|
||||
? CoreWebView2PermissionState.Allow
|
||||
: CoreWebView2PermissionState.Deny;
|
||||
// ClipboardRead only for a frame on the allowlist (iframes are unrestricted otherwise); everything else denied.
|
||||
CoreWebView2PermissionState state = CoreWebView2PermissionState.Deny;
|
||||
try
|
||||
{
|
||||
if (e.PermissionKind == CoreWebView2PermissionKind.ClipboardRead
|
||||
&& WebPanelUrlPolicy.IsAllowed(e.Uri, _req?.Allowlist ?? Array.Empty<string>()))
|
||||
state = CoreWebView2PermissionState.Allow;
|
||||
}
|
||||
catch { state = CoreWebView2PermissionState.Deny; }
|
||||
e.State = state;
|
||||
}
|
||||
|
||||
private void OnAcceleratorKeyPressed(object? sender, CoreWebView2AcceleratorKeyPressedEventArgs e)
|
||||
|
|
@ -722,22 +764,54 @@ internal sealed unsafe class WebPanelHost
|
|||
private void OnProcessFailed(object? sender, CoreWebView2ProcessFailedEventArgs e)
|
||||
{
|
||||
CoreWebView2ProcessFailedKind kind = e.ProcessFailedKind;
|
||||
int handle = _serving;
|
||||
Post(() => HandleProcessFailed(handle, kind)); // tear down outside WebView2's own callback
|
||||
Post(() => HandleProcessFailed(kind)); // act outside WebView2's own callback
|
||||
}
|
||||
|
||||
private void HandleProcessFailed(int handle, CoreWebView2ProcessFailedKind kind)
|
||||
// RenderProcessUnresponsive: WebView2 raises it repeatedly while the main frame's renderer stays hung. One
|
||||
// report can be a long script; this many within the window fails the panel like a renderer exit.
|
||||
private const int UnresponsiveLimit = 3;
|
||||
private const long UnresponsiveWindowMs = 30000;
|
||||
private int _unresponsiveCount;
|
||||
private long _unresponsiveSinceMs;
|
||||
|
||||
/// <summary>
|
||||
/// Only two kinds end the panel (WebView2's own docs, Microsoft.Web.WebView2.Core.xml,
|
||||
/// CoreWebView2ProcessFailedKind): BrowserProcessExited (everything is gone: full teardown) and
|
||||
/// RenderProcessExited (the main frame's renderer: about:blank, recreate on the next Open). GPU, utility,
|
||||
/// sandbox helper and PPAPI processes are recreated by WebView2 and are not fatal; a frame-only renderer exit
|
||||
/// does not touch the top-level document; those are logged only. Acts on the panel being served now, not on
|
||||
/// the handle when the event fired, so a late event never hides a newer panel (Fail ignores a non-live handle).
|
||||
/// </summary>
|
||||
private void HandleProcessFailed(CoreWebView2ProcessFailedKind kind)
|
||||
{
|
||||
if (_tornDown) return;
|
||||
SafeLog("WebView2 process failed: " + kind);
|
||||
if (kind == CoreWebView2ProcessFailedKind.BrowserProcessExited)
|
||||
int handle = _serving;
|
||||
switch (kind)
|
||||
{
|
||||
TearDownWebView();
|
||||
}
|
||||
else
|
||||
{
|
||||
try { _web?.Navigate("about:blank"); } catch { }
|
||||
_needsRecreate = true; // the next Open recreates the controller and environment
|
||||
case CoreWebView2ProcessFailedKind.BrowserProcessExited:
|
||||
SafeLog("WebView2 process failed: " + kind);
|
||||
TearDownWebView();
|
||||
break;
|
||||
case CoreWebView2ProcessFailedKind.RenderProcessExited:
|
||||
SafeLog("WebView2 process failed: " + kind);
|
||||
try { _web?.Navigate("about:blank"); } catch { }
|
||||
_needsRecreate = true; // the next Open recreates the controller and environment
|
||||
break;
|
||||
case CoreWebView2ProcessFailedKind.RenderProcessUnresponsive:
|
||||
{
|
||||
long now = Environment.TickCount64;
|
||||
if (_unresponsiveCount == 0 || now - _unresponsiveSinceMs > UnresponsiveWindowMs) { _unresponsiveCount = 0; _unresponsiveSinceMs = now; }
|
||||
_unresponsiveCount++;
|
||||
SafeLog($"WebView2 renderer unresponsive ({_unresponsiveCount} of {UnresponsiveLimit} within {UnresponsiveWindowMs / 1000} s)");
|
||||
if (_unresponsiveCount < UnresponsiveLimit) return;
|
||||
_unresponsiveCount = 0;
|
||||
try { _web?.Navigate("about:blank"); } catch { }
|
||||
_needsRecreate = true;
|
||||
break;
|
||||
}
|
||||
default:
|
||||
SafeLog("WebView2 process failed (not fatal, panel kept): " + kind);
|
||||
return;
|
||||
}
|
||||
// Never a browser fallback here: a navigation already ran, so the launch code is spent.
|
||||
Fail(handle, WebPanelCode.ProcessFailed, kind.ToString(), allowFallback: false);
|
||||
|
|
@ -747,7 +821,6 @@ internal sealed unsafe class WebPanelHost
|
|||
|
||||
private void Fail(int handle, WebPanelCode code, string reason, bool allowFallback)
|
||||
{
|
||||
HidePanel();
|
||||
bool fallback = false, ignored = false;
|
||||
string url = "";
|
||||
lock (_sync)
|
||||
|
|
@ -770,7 +843,8 @@ internal sealed unsafe class WebPanelHost
|
|||
}
|
||||
}
|
||||
}
|
||||
if (ignored) { SafeLog($"panel failure after close or supersede: {code} ({reason})"); return; }
|
||||
if (ignored) { SafeLog($"panel failure after close or supersede, panel left as it is: {code} ({reason})"); return; }
|
||||
HidePanel();
|
||||
SafeLog($"panel failed: {code} ({reason})");
|
||||
if (!fallback) return;
|
||||
bool ok = false;
|
||||
|
|
@ -786,10 +860,11 @@ internal sealed unsafe class WebPanelHost
|
|||
ShowWindow(_staHwnd, SW_SHOWNA);
|
||||
// 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.
|
||||
IntPtr fg = GetForegroundWindow();
|
||||
uint fgPid = 0;
|
||||
if (fg != IntPtr.Zero) GetWindowThreadProcessId(fg, out fgPid);
|
||||
if (fg == IntPtr.Zero || fgPid == _ourPid) SetForegroundWindow(_staHwnd);
|
||||
if (fg != IntPtr.Zero && IsOurPid(fgPid)) SetForegroundWindow(_staHwnd);
|
||||
if (_ctl != null) { try { _ctl.IsVisible = true; } catch { } }
|
||||
FocusPage();
|
||||
if (!_timerOn) { SetTimer(_staHwnd, TimerId, 50, IntPtr.Zero); _timerOn = true; }
|
||||
|
|
@ -849,6 +924,9 @@ internal sealed unsafe class WebPanelHost
|
|||
IntPtr fg = GetForegroundWindow();
|
||||
uint fgPid = 0;
|
||||
if (fg != IntPtr.Zero) GetWindowThreadProcessId(fg, out fgPid);
|
||||
// The page's own dialogs (alert, file picker, sign-in) are windows of the WebView2 browser process: count
|
||||
// that process as ours so they do not hide the panel they belong to.
|
||||
if (IsOurPid(fgPid)) fgPid = _ourPid;
|
||||
bool? visible = WebPanelWindowPolicy.Visible(true, true, IsIconic(game), IsWindowVisible(game), fg == IntPtr.Zero, fgPid, _ourPid);
|
||||
bool shown = IsWindowVisible(_staHwnd);
|
||||
if (visible == false)
|
||||
|
|
@ -867,6 +945,17 @@ internal sealed unsafe class WebPanelHost
|
|||
UpdateStateFlags();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// This process, or this panel's WebView2 browser process. The browser PID is CoreWebView2.BrowserProcessId,
|
||||
/// read when the controller is created (OnController) and cleared by TearDownWebView; 0 while there is none.
|
||||
/// </summary>
|
||||
private bool IsOurPid(uint pid)
|
||||
{
|
||||
if (pid == 0) return false;
|
||||
uint browser = _browserPid;
|
||||
return pid == _ourPid || (browser != 0 && pid == browser);
|
||||
}
|
||||
|
||||
private bool GameClientScreen(out PanelRect rect)
|
||||
{
|
||||
rect = default;
|
||||
|
|
|
|||
Loading…
Reference in a new issue