Se «Scollega» faceva ripartire il browser mentre il primo avvio aspettava il tentativo successivo, quel tentativo creava un secondo WebView nella stessa finestra senza chiudere il primo. Il processo orfano teneva il profilo: il «Scollega» dopo aspettava 20 s e non riusciva a cancellare la sessione di Instagram, e l'uscita aspettava 15 s a vuoto (rilievo R2 della revisione, riprodotto con WebView2 vero). Ora l'avvio, dentro la sezione esclusiva di WebView2Host, non fa nulla se un WebView è già collegato, chiude prima i resti di uno morto e, se fallisce, chiude da sé ciò che ha creato. Il ciclo dei tentativi non chiude più niente da fuori: poteva chiudere un browser appena fatto ripartire da «Scollega». La ripartenza dopo un arresto del processo usa lo stesso avvio, e chiudere un WebView ne cambia la generazione, così i suoi eventi tardivi non contano più. Nuova prova di regressione: «Scollega» durante i tentativi lascia un solo controllo nella finestra, il «Scollega» dopo riesce in meno di un secondo e l'uscita non aspetta. Rossa prima della correzione (due Chrome_WidgetWin_0), verde dopo. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
32 lines
1.3 KiB
C#
32 lines
1.3 KiB
C#
using System.Runtime.InteropServices;
|
|
|
|
namespace Febe.Tests.Windows.Support;
|
|
|
|
/// <summary>
|
|
/// The direct child windows of a window, by class name. WebView2 hosted in a window («finestra») puts one child window
|
|
/// per controller into its parent: two of them in «Browser di Febe» mean two WebViews, one of them orphaned.
|
|
/// </summary>
|
|
internal static class ChildWindows
|
|
{
|
|
/// <summary>The class names of the direct children of <paramref name="parent"/>, in Z order.</summary>
|
|
public static IReadOnlyList<string> Of(IntPtr parent)
|
|
{
|
|
var names = new List<string>();
|
|
var buffer = new char[256];
|
|
var child = IntPtr.Zero;
|
|
while ((child = FindWindowEx(parent, child, null, null)) != IntPtr.Zero)
|
|
{
|
|
var length = GetClassName(child, buffer, buffer.Length);
|
|
names.Add(new string(buffer, 0, Math.Max(length, 0)));
|
|
}
|
|
|
|
return names;
|
|
}
|
|
|
|
[DllImport("user32.dll", EntryPoint = "FindWindowExW", CharSet = CharSet.Unicode)]
|
|
private static extern IntPtr FindWindowEx(IntPtr parent, IntPtr childAfter, string? className, string? windowName);
|
|
|
|
[DllImport("user32.dll", EntryPoint = "GetClassNameW", CharSet = CharSet.Unicode)]
|
|
private static extern int GetClassName(IntPtr window, [Out] char[] className, int maxCount);
|
|
}
|