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
|
|
@ -103,6 +103,8 @@ internal static unsafe class Program
|
|||
Guard("StaleHandles", () => handle = CheckStaleHandles(s, handle));
|
||||
Guard("ProfileSwitchRecreates", () => handle = CheckProfileSwitch(s));
|
||||
Guard("NoBrowserFallbackAfterNavigation", () => CheckNoFallbackAfterNavigation(s, handle));
|
||||
Guard("GpuProcessCrashKeepsPanel", () => handle = CheckGpuCrash(s));
|
||||
Guard("LateFailureForSupersededHandle", () => handle = CheckLateFailure(s));
|
||||
Guard("CreateFailureFallsBack", () => CheckCreateFailure(s));
|
||||
Guard("VisibilitySameProcess", () => handle = CheckVisibilitySameProcess(s));
|
||||
Unverified("VisibilityOtherProcess", "needs another process to take the foreground (alt-tab); the harness never forces it. Owner in-game check.");
|
||||
|
|
@ -214,8 +216,11 @@ internal static unsafe class Program
|
|||
int g = _gameKeyMsgs - g0;
|
||||
W($"page input value {value}; fake game key messages during the test: {g}; AcceleratorKeyPressed events {(int)s.Call("get_AcceleratorKeyEvents")! - k0}; panel visible={IsWindowVisible((IntPtr)s.Call("get_HostHwnd")!)}; {FgDesc()}");
|
||||
Snap((IntPtr)s.Call("get_HostHwnd")!, Path.Combine(_root, "panel-keys.png"));
|
||||
// The game-side count is informational only: the keys are posted straight to the Chromium window, so the
|
||||
// game could not see them here whatever the host did. Input isolation (unowned popup, separate queue) is an
|
||||
// owner in-game check: type in the panel, nothing reaches AC's chat.
|
||||
W($"(informational, cannot fail: game key messages {g})");
|
||||
if (!value.Contains("x1q")) Fail("KeysStayInPage", $"page input is {value}, want x1q");
|
||||
else if (g != 0) Fail("KeysStayInPage", $"the game window saw {g} key message(s)");
|
||||
else Ok("KeysStayInPage");
|
||||
return h;
|
||||
}
|
||||
|
|
@ -244,7 +249,6 @@ internal static unsafe class Program
|
|||
return;
|
||||
}
|
||||
if (!closed) { Fail("EscapeClosesAndRefocusesGame", $"AcceleratorKeyPressed fired but the panel is {st[2]}, not Closed"); return; }
|
||||
if (g != 0) { Fail("EscapeClosesAndRefocusesGame", $"the game saw {g} key message(s)"); return; }
|
||||
if (!panelFg) { Unverified("EscapeClosesAndRefocusesGame", "closed, game saw 0 keys; the foreground hand-back could not be checked (the panel did not hold the foreground)"); return; }
|
||||
if (fg != _game) { Fail("EscapeClosesAndRefocusesGame", "closed, but the foreground is not the game"); return; }
|
||||
Ok("EscapeClosesAndRefocusesGame");
|
||||
|
|
@ -388,6 +392,92 @@ internal static unsafe class Program
|
|||
else Fail("OpenAfterProcessFailedRecreates", $"[{string.Join(",", st2)}]");
|
||||
}
|
||||
|
||||
private static int CheckGpuCrash(Session s)
|
||||
{
|
||||
var (h, _) = Open(s, "https://panel.test/index.html", Allow, title: "GPU crash");
|
||||
if (!WaitStatus(s, h, StatusReady, 30000, out int[] a)) { Fail("GpuProcessCrashKeepsPanel", $"not Ready [{string.Join(",", a)}]"); return h; }
|
||||
uint browser = (uint)(int)s.Call("get_BrowserProcessId")!;
|
||||
int children = 0, readable = 0, gpu = 0;
|
||||
foreach (Process p in Process.GetProcessesByName("msedgewebview2"))
|
||||
{
|
||||
using (p)
|
||||
{
|
||||
if (ParentPid(p.Id) != browser) continue;
|
||||
children++;
|
||||
string? cmd = CommandLine(p.Id);
|
||||
if (cmd == null) continue;
|
||||
readable++;
|
||||
if (gpu == 0 && cmd.Contains("--type=gpu-process", StringComparison.Ordinal)) gpu = p.Id;
|
||||
}
|
||||
}
|
||||
W($"browser pid {browser}: {children} child process(es), {readable} command line(s) readable, gpu-process pid {gpu}");
|
||||
if (gpu == 0) { Unverified("GpuProcessCrashKeepsPanel", $"no msedgewebview2 child of browser pid {browser} with --type=gpu-process ({children} children, {readable} command lines read)"); return h; }
|
||||
int logs0 = LogLines.Count;
|
||||
try { using var p = Process.GetProcessById(gpu); p.Kill(); }
|
||||
catch (Exception ex) { Unverified("GpuProcessCrashKeepsPanel", "could not kill the gpu process: " + ex.Message); return h; }
|
||||
Thread.Sleep(3000);
|
||||
int[] st = State(s, h);
|
||||
string alive = (string)s.Call("Eval", "document.title", 5000)!;
|
||||
bool open = (bool)s.Call("get_PanelOpen")!;
|
||||
var newLogs = LogLines.Skip(logs0).ToList();
|
||||
W($"killed gpu pid {gpu}: state [{string.Join(",", st)}], panel open {open}, page title {alive}; log: {string.Join(" | ", newLogs)}");
|
||||
if (st[2] != StatusReady || st[4] != 0) Fail("GpuProcessCrashKeepsPanel", $"status {st[2]} error {st[4]}, want Ready with no error");
|
||||
else if (!open) Fail("GpuProcessCrashKeepsPanel", "the panel closed");
|
||||
else if (!newLogs.Any(l => l.Contains("GpuProcessExited"))) Unverified("GpuProcessCrashKeepsPanel", "panel stayed Ready, but no GpuProcessExited ProcessFailed event arrived within 3 s, so the handler path was not shown");
|
||||
else Ok("GpuProcessCrashKeepsPanel");
|
||||
return h;
|
||||
}
|
||||
|
||||
private static int CheckLateFailure(Session s)
|
||||
{
|
||||
var (a, _) = Open(s, "https://panel.test/index.html", Allow, title: "Old");
|
||||
bool ra = WaitStatus(s, a, StatusReady, 30000, out _);
|
||||
var (b, _) = Open(s, "https://panel.test/b.html", Allow, title: "New");
|
||||
bool rb = WaitStatus(s, b, StatusReady, 30000, out _);
|
||||
bool open0 = (bool)s.Call("get_PanelOpen")!;
|
||||
bool posted = (bool)s.Call("FailHandle", a)!;
|
||||
Thread.Sleep(600);
|
||||
int[] st = State(s, b);
|
||||
bool open = (bool)s.Call("get_PanelOpen")!;
|
||||
W($"late synthetic failure for superseded handle {a} (posted {posted}): newer handle {b} state [{string.Join(",", st)}], panel open before {open0} after {open}");
|
||||
if (!ra || !rb || !open0) Fail("LateFailureForSupersededHandle", "setup: panels not Ready/open");
|
||||
else if (st[2] != StatusReady) Fail("LateFailureForSupersededHandle", $"newer panel status {st[2]}, want Ready");
|
||||
else if (!open) Fail("LateFailureForSupersededHandle", "the late failure hid the newer panel");
|
||||
else Ok("LateFailureForSupersededHandle");
|
||||
return b;
|
||||
}
|
||||
|
||||
private static uint ParentPid(int pid)
|
||||
{
|
||||
IntPtr h = OpenProcess(0x1000 /* PROCESS_QUERY_LIMITED_INFORMATION */, false, pid);
|
||||
if (h == IntPtr.Zero) return 0;
|
||||
try
|
||||
{
|
||||
PROCESS_BASIC_INFORMATION pbi;
|
||||
return NtQueryInformationProcess(h, 0, &pbi, sizeof(PROCESS_BASIC_INFORMATION), out _) == 0 ? (uint)pbi.InheritedFromUniqueProcessId.ToInt64() : 0;
|
||||
}
|
||||
finally { CloseHandle(h); }
|
||||
}
|
||||
|
||||
/// <summary>ProcessCommandLineInformation (60): a UNICODE_STRING followed by its text, in our buffer.</summary>
|
||||
private static string? CommandLine(int pid)
|
||||
{
|
||||
IntPtr h = OpenProcess(0x1000, false, pid);
|
||||
if (h == IntPtr.Zero) return null;
|
||||
try
|
||||
{
|
||||
byte[] buf = new byte[65536];
|
||||
fixed (byte* b = buf)
|
||||
{
|
||||
if (NtQueryInformationProcess(h, 60, b, buf.Length, out _) != 0) return null;
|
||||
int len = *(ushort*)b;
|
||||
char* text = *(char**)(b + IntPtr.Size);
|
||||
return text == null ? null : new string(text, 0, len / 2);
|
||||
}
|
||||
}
|
||||
finally { CloseHandle(h); }
|
||||
}
|
||||
|
||||
private static void CheckCreateFailure(Session s)
|
||||
{
|
||||
Drain(BrowserCalls);
|
||||
|
|
@ -492,14 +582,15 @@ internal static unsafe class Program
|
|||
_pumpSession = s;
|
||||
var (h, _) = Open(s, "https://panel.test/launch.html?code=" + Secret, Allow);
|
||||
if (!WaitStatus(s, h, StatusReady, 30000, out int[] st)) { Fail("UnloadWhileVisibleCollected", $"not Ready [{string.Join(",", st)}]"); }
|
||||
W($"session 2 open: state [{string.Join(",", State(s, h))}] host visible {IsWindowVisible((IntPtr)s.Call("get_HostHwnd")!)}");
|
||||
bool visible = IsWindowVisible((IntPtr)s.Call("get_HostHwnd")!);
|
||||
W($"session 2 open: state [{string.Join(",", State(s, h))}] host visible {visible}");
|
||||
var sd = Stopwatch.StartNew();
|
||||
s.Call("Shutdown", 2000);
|
||||
W($"Shutdown(2000) returned in {sd.ElapsedMilliseconds} ms (panel open; window shown only if the harness held the foreground)");
|
||||
UnloadAndJudge("UnloadWhileVisibleCollected", ref s);
|
||||
UnloadAndJudge("UnloadWhileVisibleCollected", ref s, visible ? null : "collected, but the panel window was not visible (the PID rule hid it: the harness did not hold the foreground), so the visible-teardown path was not shown");
|
||||
}
|
||||
|
||||
private static void UnloadAndJudge(string name, ref Session s)
|
||||
private static void UnloadAndJudge(string name, ref Session s, string? unverifiedIfCollected = null)
|
||||
{
|
||||
_pumpSession = null;
|
||||
_pumpHandle = 0;
|
||||
|
|
@ -511,6 +602,7 @@ internal static unsafe class Program
|
|||
while (weak.IsAlive && sw.ElapsedMilliseconds < 3000) { GC.Collect(); GC.WaitForPendingFinalizers(); if (weak.IsAlive) Thread.Sleep(20); }
|
||||
W($"{name}: context {(weak.IsAlive ? "STILL HELD" : "collected")} after {sw.ElapsedMilliseconds} ms");
|
||||
if (weak.IsAlive) Fail(name, "the payload context was not collected within 3000 ms");
|
||||
else if (unverifiedIfCollected != null) Unverified(name, unverifiedIfCollected);
|
||||
else Ok(name);
|
||||
}
|
||||
|
||||
|
|
@ -933,6 +1025,10 @@ internal static unsafe class Program
|
|||
[DllImport("gdi32.dll")] private static extern bool DeleteObject(IntPtr o);
|
||||
[DllImport("gdi32.dll")] private static extern bool DeleteDC(IntPtr dc);
|
||||
[DllImport("gdi32.dll")] private static extern int GetDIBits(IntPtr dc, IntPtr bmp, uint start, uint lines, byte* bits, ref BITMAPINFOHEADER bi, uint usage);
|
||||
[StructLayout(LayoutKind.Sequential)] private struct PROCESS_BASIC_INFORMATION { public IntPtr ExitStatus, PebBaseAddress, AffinityMask, BasePriority, UniqueProcessId, InheritedFromUniqueProcessId; }
|
||||
[DllImport("ntdll.dll")] private static extern int NtQueryInformationProcess(IntPtr h, int cls, void* info, int len, out int ret);
|
||||
[DllImport("kernel32.dll")] private static extern IntPtr OpenProcess(uint access, bool inherit, int pid);
|
||||
[DllImport("kernel32.dll")] private static extern bool CloseHandle(IntPtr h);
|
||||
[DllImport("kernel32.dll")] private static extern uint GetCurrentThreadId();
|
||||
[DllImport("kernel32.dll")] private static extern IntPtr GetModuleHandleW(IntPtr n);
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue