Skip to content

Truly independent web browser

LibWeb: Don't activate a document for a removed remote iframe

Andreas Klingbbad56640eb8
diff --git a/Libraries/LibWeb/HTML/HistoryExecutor.cpp b/Libraries/LibWeb/HTML/HistoryExecutor.cpp
index 2ac2d03434c..23e70dd9e56 100644
--- a/Libraries/LibWeb/HTML/HistoryExecutor.cpp
+++ b/Libraries/LibWeb/HTML/HistoryExecutor.cpp
@@ -14,6 +14,7 @@
#include <LibWeb/HTML/LocalTraversableNavigable.h>
#include <LibWeb/HTML/Navigation.h>
#include <LibWeb/HTML/NavigationParamsDescriptor.h>
+#include <LibWeb/HTML/RemoteNavigable.h>
#include <LibWeb/HTML/SameDocumentNavigationEntry.h>
#include <LibWeb/HTML/Scripting/Environments.h>
#include <LibWeb/HTML/Scripting/TemporaryExecutionContext.h>
@@ -606,6 +607,14 @@ Optional<HistoryExecutor::DequeuedChangingNavigableContinuation> HistoryExecutor
// 12. In both cases, let afterPotentialUnloads be the following steps:
bool const update_only = continuation->update_only;
auto after_potential_unload = GC::create_function(heap(), [this, navigable, update_only, target_entry, continuation, population_output, old_origin, displayed_document = GC::Ref { *displayed_document }, script_history_length, script_history_index, entries_for_navigation_api = move(entries_for_navigation_api), navigation_type = continuation->navigation_type, on_complete] {
+ // AD-HOC: A provisional navigable stands in for a navigable another process hosts, which is destroyed as soon
+ // as its container is removed, e.g. while displayedDocument unloads. The provisional navigable is only
+ // discarded once that navigable's subtree has unloaded, and has no container to take over until then.
+ if (auto provisional_for = navigable->provisional_for(); provisional_for && provisional_for->is_in_a_destroyed_subtree()) {
+ on_complete->function()({}, {});
+ return;
+ }
+
// NB: Only step 14.10 applies a same-document push or replace: its targetEntry's document is displayedDocument.
if (is_same_document_push_or_replace(navigation_type, *target_entry, displayed_document)
&& navigable->active_session_history_entry() != target_entry) {
diff --git a/Tests/LibWeb/Text/expected/SiteIsolation/iframe/remote-iframe-removed-while-coming-back-to-this-process.txt b/Tests/LibWeb/Text/expected/SiteIsolation/iframe/remote-iframe-removed-while-coming-back-to-this-process.txt
new file mode 100644
index 00000000000..3da67ab4891
--- /dev/null
+++ b/Tests/LibWeb/Text/expected/SiteIsolation/iframe/remote-iframe-removed-while-coming-back-to-this-process.txt
@@ -0,0 +1 @@
+all iframes removed
diff --git a/Tests/LibWeb/Text/input/SiteIsolation/iframe/remote-iframe-removed-while-coming-back-to-this-process.html b/Tests/LibWeb/Text/input/SiteIsolation/iframe/remote-iframe-removed-while-coming-back-to-this-process.html
new file mode 100644
index 00000000000..6cb461304cb
--- /dev/null
+++ b/Tests/LibWeb/Text/input/SiteIsolation/iframe/remote-iframe-removed-while-coming-back-to-this-process.html
@@ -0,0 +1,58 @@
+<!DOCTYPE html>
+<script src="../../include.js"></script>
+<script>
+ // Going back takes each iframe from a document another process hosts back to one this process hosts, and each is
+ // removed at a different point of that, so some are removed after their document is populated here and before it
+ // activates.
+ promiseTest(async () => {
+ const httpServer = httpTestServer();
+ const FRAME_COUNT = 30;
+
+ const localUrl = await httpServer.createEcho("GET", "/remote-iframe-removed-while-coming-back-local", {
+ status: 200,
+ headers: { "Content-Type": "text/html", "Cache-Control": "no-store" },
+ body: "<!DOCTYPE html>local",
+ });
+ const remoteUrl = new URL(
+ await httpServer.createEcho("GET", "/remote-iframe-removed-while-coming-back-remote", {
+ status: 200,
+ headers: { "Content-Type": "text/html" },
+ body: "<!DOCTYPE html>remote",
+ })
+ );
+ remoteUrl.hostname = uniqueLocalhostHostname("remote-iframe-removed-while-coming-back");
+
+ const frames = [];
+ for (let i = 0; i < FRAME_COUNT; ++i) {
+ const frame = document.createElement("iframe");
+ frame.src = localUrl;
+ frames.push(frame);
+ document.body.appendChild(frame);
+ await new Promise(resolve => (frame.onload = resolve));
+ }
+ for (const frame of frames) {
+ frame.contentWindow.location.href = remoteUrl.href;
+ await new Promise(resolve => (frame.onload = resolve));
+ }
+ if (remoteFrameCount() !== FRAME_COUNT) {
+ println("iframes did not become remote");
+ return;
+ }
+
+ history.go(-FRAME_COUNT);
+ await Promise.all(frames.map((frame, i) => new Promise(resolve => {
+ setTimeout(() => {
+ frame.remove();
+ resolve();
+ }, i * 25);
+ })));
+
+ if (!(await waitForCondition(() => remoteFrameCount() === 0))) {
+ println("frame tree still has remote frames");
+ return;
+ }
+ await animationFrame();
+ await animationFrame();
+ println("all iframes removed");
+ });
+</script>
diff --git a/Tests/LibWeb/Text/input/SiteIsolation/iframe/remote-iframe-removed-while-coming-back-to-this-process.html.headers b/Tests/LibWeb/Text/input/SiteIsolation/iframe/remote-iframe-removed-while-coming-back-to-this-process.html.headers
new file mode 100644
index 00000000000..156209f9c81
--- /dev/null
+++ b/Tests/LibWeb/Text/input/SiteIsolation/iframe/remote-iframe-removed-while-coming-back-to-this-process.html.headers
@@ -0,0 +1 @@
+Content-Type: text/html