Truly independent web browser
LibWeb+LibWebView: Set the opener of a navigable in another tab
Shannon Bootha5b0e5c967ef
diff --git a/Libraries/LibWeb/HTML/Window.cpp b/Libraries/LibWeb/HTML/Window.cppindex be742ee1546..bd92b8eaafb 100644--- a/Libraries/LibWeb/HTML/Window.cpp+++ b/Libraries/LibWeb/HTML/Window.cpp@@ -562,8 +562,9 @@ WebIDL::ExceptionOr<Window::OpenedWindow> Window::window_open_steps_internal(Utflocal_target_navigable->report_opener_browsing_context();} else {// NB: That browsing context is in the process hosting targetNavigable, which the UI process asks to set- // it to the one active in sourceDocument's node navigable.- source_document.page().client().request_set_opener_of_remote_navigable(as<RemoteNavigable>(*target_navigable), *source_document.navigable());+ // it to the one active in sourceDocument's node navigable. The request goes through the page holding+ // targetNavigable's tab, which is not sourceDocument's when the two are different tabs.+ target_navigable->page().client().request_set_opener_of_remote_navigable(as<RemoteNavigable>(*target_navigable), *source_document.navigable());}}}diff --git a/Libraries/LibWebView/CanonicalNavigable.cpp b/Libraries/LibWebView/CanonicalNavigable.cppindex 6c5db27d8fa..d981f451264 100644--- a/Libraries/LibWebView/CanonicalNavigable.cpp+++ b/Libraries/LibWebView/CanonicalNavigable.cpp@@ -1357,8 +1357,14 @@ void CanonicalNavigable::did_set_opener_browsing_context(Optional<Web::HTML::CroRefPtr<CanonicalBrowsingContext> opener_browsing_context;if (opener_navigable_id.has_value()) {if (auto* opener_traversable = CanonicalTraversable::traversable_containing(*opener_navigable_id)) {- if (auto opener = opener_traversable->find(*opener_navigable_id); opener.has_value())+ if (auto opener = opener_traversable->find(*opener_navigable_id); opener.has_value()) {+ // window.open() only finds navigables in the group of the source document's top-level browsing+ // context, so the opener it sets is one of the group's.+ auto group = top_level_traversable().active_browsing_context().group();+ if (!group || opener_traversable->active_browsing_context().group() != group)+ return;opener_browsing_context = opener->active_browsing_context();+ }}}active_browsing_context().set_opener_browsing_context(opener_browsing_context);diff --git a/Tests/LibWeb/Text/input/SiteIsolation/iframe/isolated-iframe-finds-a-popup-of-its-top-level-by-target-name.html b/Tests/LibWeb/Text/input/SiteIsolation/iframe/isolated-iframe-finds-a-popup-of-its-top-level-by-target-name.htmlindex d24e4516056..7caaebffebb 100644--- a/Tests/LibWeb/Text/input/SiteIsolation/iframe/isolated-iframe-finds-a-popup-of-its-top-level-by-target-name.html+++ b/Tests/LibWeb/Text/input/SiteIsolation/iframe/isolated-iframe-finds-a-popup-of-its-top-level-by-target-name.html@@ -20,6 +20,11 @@headers: { "Content-Type": "text/html" },body: `<!DOCTYPE html><script>addEventListener("message", event => {+ // Opening the popup made this iframe its opener, so the popup reports here.+ if (event.data.popup) {+ parent.postMessage(event.data, "*");+ return;+ }const found = window.open(event.data.url, event.data.name);parent.postMessage({ iframe: "opened", found: found !== null }, "*");});