Truly independent web browser
LibWeb: Don't find provisional top-level navigables by target name
Andreas Kling4843931249fb
diff --git a/Libraries/LibWeb/HTML/Navigable.cpp b/Libraries/LibWeb/HTML/Navigable.cppindex c43188a9cf2..bc25c55e054 100644--- a/Libraries/LibWeb/HTML/Navigable.cpp+++ b/Libraries/LibWeb/HTML/Navigable.cpp@@ -310,6 +310,7 @@ GC::Ptr<Navigable> navigable_with_id_in_any_page(Page const& preferred_page, Cro// The top-level browsing contexts of a group, as the navigables they are active in: the traversables this process// hosts, and its stand-ins for those other processes host. A traversable hosted here stands ahead of any stand-in.+// A provisional traversable is not active yet: the stand-in for the traversable another process hosts represents it.Vector<GC::Root<Navigable>> top_level_navigables_in_browsing_context_group(Optional<u64> browsing_context_group_id){Vector<GC::Root<Navigable>> navigables;@@ -318,6 +319,8 @@ Vector<GC::Root<Navigable>> top_level_navigables_in_browsing_context_group(Optioauto consider = [&](Navigable& navigable) {if (!navigable.is_top_level_traversable() || navigable.has_been_destroyed() || navigable.browsing_context_group_id() != browsing_context_group_id)return;+ if (auto* local_navigable = as_if<LocalNavigable>(navigable); local_navigable && local_navigable->is_provisional())+ return;if (any_of(navigables, [&](auto const& seen) { return seen->id() == navigable.id(); }))return;navigables.append(navigable);diff --git a/Tests/LibWeb/Text/expected/SiteIsolation/popup-coming-back-to-this-process-is-found-by-name.txt b/Tests/LibWeb/Text/expected/SiteIsolation/popup-coming-back-to-this-process-is-found-by-name.txtnew file mode 100644index 00000000000..5221c5cd1cf--- /dev/null+++ b/Tests/LibWeb/Text/expected/SiteIsolation/popup-coming-back-to-this-process-is-found-by-name.txt@@ -0,0 +1,4 @@+arrived+unloading+found the popup by name: true+popup navigateddiff --git a/Tests/LibWeb/Text/input/SiteIsolation/popup-coming-back-to-this-process-is-found-by-name.html b/Tests/LibWeb/Text/input/SiteIsolation/popup-coming-back-to-this-process-is-found-by-name.htmlnew file mode 100644index 00000000000..98ee75f9698--- /dev/null+++ b/Tests/LibWeb/Text/input/SiteIsolation/popup-coming-back-to-this-process-is-found-by-name.html@@ -0,0 +1,45 @@+<!DOCTYPE html>+<script src="../include.js"></script>+<script>+ // A popup in another process navigates back to this page's site, and this process hosts its next document+ // provisionally while the popup's document unloads. Looking the popup up by name meanwhile finds the popup itself,+ // not the provisional navigable populating its next document.+ promiseTest(async () => {+ const httpServer = httpTestServer();+ const nextMessage = () => new Promise(resolve => addEventListener("message", event => resolve(event.data), { once: true }));++ const echo = async (name, body) => httpServer.createEcho("GET", `/${name}`, {+ status: 200,+ headers: { "Content-Type": "text/html" },+ body: `<!DOCTYPE html><script>${body}<\/script>`,+ });++ const sameSiteUrl = await echo("found-by-name-same-site", `opener.postMessage("came back", "*");`);+ const finalUrl = await echo("found-by-name-final", `opener.postMessage("navigated by name", "*");`);+ const crossSiteUrl = new URL(await echo("found-by-name-cross-site", `+ onpagehide = () => {+ opener.postMessage("unloading", "*");+ const end = Date.now() + 500;+ while (Date.now() < end) { }+ };+ opener.postMessage("arrived", "*");+ `));+ crossSiteUrl.hostname = uniqueLocalhostHostname("found-by-name-cross-site");++ const arrived = nextMessage();+ const popup = window.open(crossSiteUrl.href, "popup");+ println(await arrived);++ const unloading = nextMessage();+ popup.location.href = sameSiteUrl;+ println(await unloading);++ // The popup's next document can win over this navigation, so either document posting a message will do.+ const navigated = nextMessage();+ println(`found the popup by name: ${window.open("", "popup") === popup}`);+ window.open(finalUrl, "popup");+ await navigated;+ println("popup navigated");+ popup.close();+ });+</script>diff --git a/Tests/LibWeb/Text/input/SiteIsolation/popup-coming-back-to-this-process-is-found-by-name.html.headers b/Tests/LibWeb/Text/input/SiteIsolation/popup-coming-back-to-this-process-is-found-by-name.html.headersnew file mode 100644index 00000000000..156209f9c81--- /dev/null+++ b/Tests/LibWeb/Text/input/SiteIsolation/popup-coming-back-to-this-process-is-found-by-name.html.headers@@ -0,0 +1 @@+Content-Type: text/html