Truly independent web browser
LibWeb: Don't stop hosting a navigable its pagehide handler destroyed
Andreas Kling31fc7c79e1a3
diff --git a/Libraries/LibWeb/HTML/LocalNavigable.cpp b/Libraries/LibWeb/HTML/LocalNavigable.cppindex 2f7a535f1ab..983540fc031 100644--- a/Libraries/LibWeb/HTML/LocalNavigable.cpp+++ b/Libraries/LibWeb/HTML/LocalNavigable.cpp@@ -1263,7 +1263,10 @@ void LocalNavigable::run_ui_descendant_unload_task(ChildNavigableDestruction chi// Another page hosts the navigable's next document, or destroys the navigable. A RemoteNavigable takes// the navigable's place in the same task, so no task here sees the navigable without an active// document.- if (stop_hosting_after_unload == StopHostingAfterUnload::Yes)+ // NB: An unload handler can remove the navigable's container, which destroys the navigable. Nothing is+ // left to stop hosting then: the container's removal tells the UI process the navigable is gone, and+ // scripts holding the WindowProxy see the window of a removed iframe.+ if (stop_hosting_after_unload == StopHostingAfterUnload::Yes && !navigable->has_been_destroyed())navigable->page().stop_hosting(*navigable, move(replicated_state));}on_complete->function()();diff --git a/Tests/LibWeb/Text/expected/SiteIsolation/iframe/iframe-removed-by-pagehide-while-leaving-for-another-process.txt b/Tests/LibWeb/Text/expected/SiteIsolation/iframe/iframe-removed-by-pagehide-while-leaving-for-another-process.txtnew file mode 100644index 00000000000..b60f44e68f0--- /dev/null+++ b/Tests/LibWeb/Text/expected/SiteIsolation/iframe/iframe-removed-by-pagehide-while-leaving-for-another-process.txt@@ -0,0 +1,2 @@+iframe removed+WebContent#0diff --git a/Tests/LibWeb/Text/input/SiteIsolation/iframe/iframe-removed-by-pagehide-while-leaving-for-another-process.html b/Tests/LibWeb/Text/input/SiteIsolation/iframe/iframe-removed-by-pagehide-while-leaving-for-another-process.htmlnew file mode 100644index 00000000000..f09e0e84b27--- /dev/null+++ b/Tests/LibWeb/Text/input/SiteIsolation/iframe/iframe-removed-by-pagehide-while-leaving-for-another-process.html@@ -0,0 +1,47 @@+<!doctype html>+<script src="../../include.js"></script>+<script>+ // Navigating a local iframe to a site another process hosts unloads its document first. The document's pagehide+ // handler removing the iframe destroys the navigable before this process would stop hosting it.+ promiseTest(async () => {+ const httpServer = httpTestServer();++ const firstUrl = new URL(+ await httpServer.createEcho("GET", "/pagehide-removes-frame-first", {+ status: 200,+ headers: { "Content-Type": "text/html" },+ body: `<!DOCTYPE html><script>onpagehide = () => frameElement.remove();<\/script>`,+ })+ );++ const secondUrl = new URL(+ await httpServer.createEcho("GET", "/pagehide-removes-frame-second", {+ status: 200,+ headers: { "Content-Type": "text/html" },+ body: `<!DOCTYPE html>second`,+ })+ );+ secondUrl.hostname = uniqueLocalhostHostname("pagehide-removes-frame-second");++ const iframe = document.createElement("iframe");+ iframe.src = firstUrl;+ await new Promise(resolve => {+ iframe.onload = resolve;+ document.body.appendChild(iframe);+ });++ iframe.src = secondUrl;+ if (!(await waitForCondition(() => !iframe.isConnected))) {+ println("pagehide did not remove the iframe");+ return;+ }+ // The removed iframe's navigable leaves the frame tree once the UI process has unloaded it.+ if (!(await waitForCondition(() => !internals.dumpSiteIsolationProcessTree().includes("iframe")))) {+ println("frame tree still has the iframe");+ return;+ }+ await animationFrame();+ println("iframe removed");+ println(internals.dumpSiteIsolationProcessTree().trimEnd());+ });+</script>diff --git a/Tests/LibWeb/Text/input/SiteIsolation/iframe/iframe-removed-by-pagehide-while-leaving-for-another-process.html.headers b/Tests/LibWeb/Text/input/SiteIsolation/iframe/iframe-removed-by-pagehide-while-leaving-for-another-process.html.headersnew file mode 100644index 00000000000..156209f9c81--- /dev/null+++ b/Tests/LibWeb/Text/input/SiteIsolation/iframe/iframe-removed-by-pagehide-while-leaving-for-another-process.html.headers@@ -0,0 +1 @@+Content-Type: text/html