Skip to content

Truly independent web browser

LibWeb+LibWebView: Choose a popup's traversable in the UI process

Shannon Booth61ac7bf935dc
diff --git a/Libraries/LibWeb/HTML/LocalNavigable.cpp b/Libraries/LibWeb/HTML/LocalNavigable.cpp
index e2c1a44b9e1..aa619ea0b8b 100644
--- a/Libraries/LibWeb/HTML/LocalNavigable.cpp
+++ b/Libraries/LibWeb/HTML/LocalNavigable.cpp
@@ -1817,56 +1817,12 @@ LocalNavigable::ChosenNavigable LocalNavigable::choose_a_navigable(Utf16View nam
// agent's configuration and abilities — it is determined by the rules given for the first applicable option
// from the following list:
if (!chosen) {
- // NB: Steps 2 to 6 of the "create a new top-level traversable" branch below only read state, and the owner
- // needs their result to create the traversable, so they run before the request. Step 1 stays in the
- // branch: activation is consumed only once a traversable was created.
-
- // 2. Set windowType to "new and unrestricted".
- auto new_window_type = WindowType::NewAndUnrestricted;
- auto new_no_opener = no_opener;
- auto new_name = name;
-
- // 3. Let currentDocument be currentNavigable's active document.
- // 4. If currentDocument's opener policy's value is "same-origin" or "same-origin-plus-COEP",
- // and currentDocument's origin is not same origin with currentDocument's relevant settings object's top-level origin, then:
- auto current_document_for_opener_policy = active_document();
- if (current_document_for_opener_policy
- && (current_document_for_opener_policy->opener_policy().value == OpenerPolicyValue::SameOrigin || current_document_for_opener_policy->opener_policy().value == OpenerPolicyValue::SameOriginPlusCOEP)
- && !current_document_for_opener_policy->origin().is_same_origin(relevant_settings_object(*current_document_for_opener_policy).top_level_origin.value())) {
-
- // 1. Set noopener to true.
- new_no_opener = TokenizedFeature::NoOpener::Yes;
-
- // 2. Set name to "_blank".
- new_name = u"_blank"sv;
-
- // 3. Set windowType to "new with no opener".
- new_window_type = WindowType::NewWithNoOpener;
- }
- // NOTE: In the presence of an opener policy,
- // nested documents that are cross-origin with their top-level browsing context's active document always set noopener to true.
-
- // 5. Let targetName be the empty string.
- Utf16String new_target_name;
-
- // 6. If name is not an ASCII case-insensitive match for "_blank", then set targetName to name.
- if (!new_name.equals_ignoring_ascii_case(u"_blank"sv))
- new_target_name = Utf16String::from_utf16(new_name);
-
+ // NB: The UI process runs the "create a new top-level traversable" branch below for the traversable it creates,
+ // and returns windowType. The renderer runs it too, for its page of the traversable.
auto request_new_web_view = [&] {
TokenizedFeature::Map empty_window_features;
auto hints = web_view_hints_from_tokenised_features(window_features.has_value() ? *window_features : empty_window_features, page());
- Optional<CrossProcessId> opener_navigable_id;
- Optional<URL::URL> opener_base_url;
- if (new_no_opener == TokenizedFeature::NoOpener::No) {
- opener_navigable_id = id();
- opener_base_url = active_document()->base_url();
- }
- // NB: The UI process creates chosen's active browsing context with the popup sandboxing flag set.
- auto popup_sandboxing_flag_set = has_flag(sandboxing_flag_set, SandboxingFlagSet::SandboxPropagatesToAuxiliaryBrowsingContexts)
- ? sandboxing_flag_set
- : SandboxingFlagSet {};
- return page().client().page_did_request_new_web_view(activate_tab, hints, opener_navigable_id, move(opener_base_url), new_target_name, popup_sandboxing_flag_set);
+ return page().client().page_did_request_new_web_view(activate_tab, hints, id(), Utf16String::from_utf16(name), no_opener, active_document()->base_url());
};
// --> If currentNavigable's active window does not have transient activation and the user agent has been configured to
@@ -1887,10 +1843,29 @@ LocalNavigable::ChosenNavigable LocalNavigable::choose_a_navigable(Utf16View nam
// 1. Consume user activation of currentNavigable's active window.
active_window()->consume_user_activation();
- // 2 to 6. Computed above, before the traversable's owner was asked to create it.
- no_opener = new_no_opener;
- name = new_name;
- window_type = new_window_type;
+ // 2. Set windowType to "new and unrestricted".
+ // NB: The UI process runs steps 2 to 4, as it creates the traversable with or without an opener, and returns
+ // windowType.
+ window_type = new_web_view.window_type;
+
+ // 3. Let currentDocument be currentNavigable's active document.
+ // 4. If currentDocument's opener policy's value is "same-origin" or "same-origin-plus-COEP",
+ // and currentDocument's origin is not same origin with currentDocument's relevant settings object's top-level origin, then:
+ if (window_type == WindowType::NewWithNoOpener) {
+ // 1. Set noopener to true.
+ no_opener = TokenizedFeature::NoOpener::Yes;
+
+ // 2. Set name to "_blank".
+ name = u"_blank"sv;
+
+ // 3. Set windowType to "new with no opener".
+ }
+ // NOTE: In the presence of an opener policy,
+ // nested documents that are cross-origin with their top-level browsing context's active document always set noopener to true.
+
+ // 5. Let targetName be the empty string.
+ // 6. If name is not an ASCII case-insensitive match for "_blank", then set targetName to name.
+ // NB: The UI process gives chosen its target name.
auto create_new_traversable = [&](GC::Ptr<BrowsingContext> opener) {
return LocalTraversableNavigable::create_for_new_web_view(move(new_web_view), opener);
diff --git a/Libraries/LibWeb/Page/Page.h b/Libraries/LibWeb/Page/Page.h
index 974c4d05092..857621f0eeb 100644
--- a/Libraries/LibWeb/Page/Page.h
+++ b/Libraries/LibWeb/Page/Page.h
@@ -80,6 +80,7 @@
#include <LibWebCommon/HTML/SelectItem.h>
#include <LibWebCommon/HTML/UserActivationConsumption.h>
#include <LibWebCommon/HTML/VisibilityState.h>
+#include <LibWebCommon/HTML/WindowType.h>
#include <LibWebCommon/HTML/WorkerAgentForward.h>
#include <LibWebCommon/IndexedDB/TransactionChanges.h>
#include <LibWebCommon/Page/ContextMenuForInputEventsTarget.h>
@@ -828,8 +829,9 @@ public:
Optional<Web::HTML::EnvironmentId> initial_environment_id;
Optional<HTML::CrossProcessId> initial_document_id;
Optional<u64> browsing_context_group_id;
+ HTML::WindowType window_type { HTML::WindowType::NewAndUnrestricted };
};
- virtual NewWebViewResult page_did_request_new_web_view(HTML::ActivateTab, HTML::WebViewHints, [[maybe_unused]] Optional<HTML::CrossProcessId> opener_navigable_id, [[maybe_unused]] Optional<URL::URL> opener_base_url, [[maybe_unused]] Utf16String const& target_name, [[maybe_unused]] HTML::SandboxingFlagSet popup_sandboxing_flag_set) { return {}; }
+ virtual NewWebViewResult page_did_request_new_web_view(HTML::ActivateTab, HTML::WebViewHints, [[maybe_unused]] HTML::CrossProcessId current_navigable_id, [[maybe_unused]] Utf16String const& name, [[maybe_unused]] HTML::TokenizedFeature::NoOpener no_opener, [[maybe_unused]] Optional<URL::URL> current_document_base_url) { return {}; }
virtual void page_did_close() { }
virtual void page_did_update_session_history_entry_navigation_api_state([[maybe_unused]] HTML::CrossProcessId navigable_id, [[maybe_unused]] HTML::SessionHistoryEntryIdentity const& entry_identity, [[maybe_unused]] HTML::StorageSerializationRecord const& navigation_api_state) { }
virtual void page_did_update_session_history_entry_scroll_restoration_mode([[maybe_unused]] HTML::CrossProcessId navigable_id, [[maybe_unused]] HTML::SessionHistoryEntryIdentity const& entry_identity, [[maybe_unused]] HTML::ScrollRestorationMode scroll_restoration_mode) { }
diff --git a/Libraries/LibWeb/PictureInPicture/PictureInPictureController.cpp b/Libraries/LibWeb/PictureInPicture/PictureInPictureController.cpp
index 51ca5fd1a99..a69b20b1be4 100644
--- a/Libraries/LibWeb/PictureInPicture/PictureInPictureController.cpp
+++ b/Libraries/LibWeb/PictureInPicture/PictureInPictureController.cpp
@@ -186,7 +186,7 @@ void PictureInPictureController::run_request_steps(Request const& request)
.navigable_id = navigable->id(),
.video_size = Gfx::Size<u32> { video.video_width(), video.video_height() }.to_type<int>(),
};
- new_web_view = m_page->client().page_did_request_new_web_view(HTML::ActivateTab::No, hints, {}, {}, {}, {});
+ new_web_view = m_page->client().page_did_request_new_web_view(HTML::ActivateTab::No, hints, navigable->id(), {}, HTML::TokenizedFeature::NoOpener::Yes, {});
}
// 3. If the previous step failed:
diff --git a/Libraries/LibWebView/CanonicalNavigable.cpp b/Libraries/LibWebView/CanonicalNavigable.cpp
index 29d882af80e..4e7afce6a2b 100644
--- a/Libraries/LibWebView/CanonicalNavigable.cpp
+++ b/Libraries/LibWebView/CanonicalNavigable.cpp
@@ -598,6 +598,72 @@ bool CanonicalNavigable::is_familiar_with(CanonicalNavigable const& other) const
return false;
}
+// https://html.spec.whatwg.org/multipage/document-sequences.html#the-rules-for-choosing-a-navigable
+CanonicalNavigable::ChosenTopLevelTraversable CanonicalNavigable::choose_a_new_top_level_traversable(WebContentPage& current_page, Utf16View name, bool no_opener, Optional<URL::URL> current_document_base_url, Web::HTML::CrossProcessId id, Web::HTML::CrossProcessId document_id)
+{
+ // NB: The branch in which the user agent creates a new top-level traversable. The renderer runs the rules up to it,
+ // and runs the branch for its page of the traversable with the windowType returned here.
+ auto& current_navigable = *this;
+
+ // NB: sandboxingFlagSet is currentNavigable's active document's active sandboxing flag set.
+ auto sandboxing_flag_set = current_navigable.active_document().active_sandboxing_flag_set();
+
+ // 1. Consume user activation of currentNavigable's active window.
+ // NB: The UI process holds the activation of the input it delivered to the page hosting currentNavigable.
+ current_page.consume_transient_user_activation();
+
+ // 2. Set windowType to "new and unrestricted".
+ auto window_type = Web::HTML::WindowType::NewAndUnrestricted;
+
+ // 3. Let currentDocument be currentNavigable's active document.
+ auto& current_document = current_navigable.active_document();
+
+ // 4. If currentDocument's opener policy's value is "same-origin" or "same-origin-plus-COEP", and currentDocument's
+ // origin is not same origin with currentDocument's relevant settings object's top-level origin, then:
+ // NB: A document whose top-level browsing context was discarded has no top-level origin to be same origin with.
+ auto top_level_origin = current_document.relevant_global_object().relevant_settings_object().top_level_origin();
+ if ((current_document.opener_policy().value == Web::HTML::OpenerPolicyValue::SameOrigin || current_document.opener_policy().value == Web::HTML::OpenerPolicyValue::SameOriginPlusCOEP)
+ && (!top_level_origin.has_value() || !current_document.origin().is_same_origin(*top_level_origin))) {
+ // 1. Set noopener to true.
+ no_opener = true;
+
+ // 2. Set name to "_blank".
+ name = u"_blank"sv;
+
+ // 3. Set windowType to "new with no opener".
+ window_type = Web::HTML::WindowType::NewWithNoOpener;
+ }
+ // NOTE: In the presence of an opener policy, nested documents that are cross-origin with their top-level browsing
+ // context's active document always set noopener to true.
+
+ // 5. Let targetName be the empty string.
+ Utf16String target_name;
+
+ // 6. If name is not an ASCII case-insensitive match for "_blank", then set targetName to name.
+ if (!name.equals_ignoring_ascii_case(u"_blank"sv))
+ target_name = Utf16String::from_utf16(name);
+
+ // 7. If noopener is true, then set chosen to the result of creating a new top-level traversable given null and targetName.
+ // 8. Otherwise:
+ // 1. Set chosen to the result of creating a new top-level traversable given currentNavigable's active browsing
+ // context, targetName, and currentNavigable.
+ // NB: The about:blank document created with an opener takes the opener's document base URL, which the renderer
+ // sends, as the UI process does not hold it.
+ auto opener = no_opener ? Optional<CanonicalNavigable&> {} : current_navigable;
+ auto initial_history_entry = Web::HTML::create_initial_session_history_entry_descriptor(Application::the().allocate_ui_process_cross_process_id(), opener.has_value() ? move(current_document_base_url) : Optional<URL::URL> {}, move(target_name));
+ auto& chosen = CanonicalTraversable::create_a_new_top_level_traversable(id, opener, move(initial_history_entry), document_id);
+
+ // 9. If sandboxingFlagSet's sandbox propagates to auxiliary browsing contexts flag is set, then all the flags that are
+ // set in sandboxingFlagSet must be set in chosen's active browsing context's popup sandboxing flag set.
+ if (has_flag(sandboxing_flag_set, Web::HTML::SandboxingFlagSet::SandboxPropagatesToAuxiliaryBrowsingContexts))
+ chosen.active_browsing_context().set_popup_sandboxing_flag_set(sandboxing_flag_set);
+
+ // 10. Set chosen's is created by web content to true.
+ chosen.set_is_created_by_web_content(true);
+
+ return { chosen, window_type };
+}
+
// https://html.spec.whatwg.org/multipage/browsing-the-web.html#allowed-to-navigate
bool CanonicalNavigable::allowed_by_sandboxing_to_navigate(CanonicalNavigable const& target, Web::InitiatorSourceSnapshot const& source_snapshot_params) const
{
diff --git a/Libraries/LibWebView/CanonicalNavigable.h b/Libraries/LibWebView/CanonicalNavigable.h
index 3b037ba7a68..08767e86114 100644
--- a/Libraries/LibWebView/CanonicalNavigable.h
+++ b/Libraries/LibWebView/CanonicalNavigable.h
@@ -30,6 +30,7 @@
#include <LibWebCommon/HTML/ReplicatedNavigableState.h>
#include <LibWebCommon/HTML/SameDocumentNavigationEntry.h>
#include <LibWebCommon/HTML/SessionHistoryEntryDescriptor.h>
+#include <LibWebCommon/HTML/WindowType.h>
#include <LibWebCommon/Page/PageId.h>
#include <LibWebCommon/PermissionsPolicy/PermissionsPolicy.h>
#include <LibWebCommon/PixelUnits.h>
@@ -129,6 +130,12 @@ public:
bool is_ancestor_of(CanonicalNavigable const&) const;
bool allowed_by_sandboxing_to_navigate(CanonicalNavigable const& target, Web::InitiatorSourceSnapshot const& source_snapshot_params) const;
bool is_familiar_with(CanonicalNavigable const&) const;
+ // https://html.spec.whatwg.org/multipage/document-sequences.html#the-rules-for-choosing-a-navigable
+ struct ChosenTopLevelTraversable {
+ CanonicalTraversable& traversable;
+ Web::HTML::WindowType window_type;
+ };
+ ChosenTopLevelTraversable choose_a_new_top_level_traversable(WebContentPage& current_page, Utf16View name, bool no_opener, Optional<URL::URL> current_document_base_url, Web::HTML::CrossProcessId id, Web::HTML::CrossProcessId document_id);
// https://html.spec.whatwg.org/multipage/browsing-the-web.html#snapshotting-target-snapshot-params
Web::HTML::TargetSnapshotParams snapshot_target_snapshot_params() const;
diff --git a/Libraries/LibWebView/WebContentClient.cpp b/Libraries/LibWebView/WebContentClient.cpp
index d108e852b5f..112a23f6d38 100644
--- a/Libraries/LibWebView/WebContentClient.cpp
+++ b/Libraries/LibWebView/WebContentClient.cpp
@@ -769,12 +769,12 @@ Messages::WebContentClient::DidStartDownloadResponse WebContentClient::did_start
return Optional<u64> {};
}
-Messages::WebContentClient::DidRequestNewWebViewResponse WebContentClient::did_request_new_web_view(Web::PageId page_id, Web::HTML::ActivateTab activate_tab, Web::HTML::WebViewHints hints, Optional<Web::HTML::CrossProcessId> opener_navigable_id, Optional<URL::URL> opener_base_url, Utf16String target_name, Web::HTML::SandboxingFlagSet popup_sandboxing_flag_set)
+Messages::WebContentClient::DidRequestNewWebViewResponse WebContentClient::did_request_new_web_view(Web::PageId page_id, Web::HTML::ActivateTab activate_tab, Web::HTML::WebViewHints hints, Web::HTML::CrossProcessId current_navigable_id, Utf16String name, bool no_opener, Optional<URL::URL> current_document_base_url)
{
if (auto* page = this->page(page_id))
- return page->did_request_new_web_view(activate_tab, hints, opener_navigable_id, move(opener_base_url), move(target_name), popup_sandboxing_flag_set);
+ return page->did_request_new_web_view(activate_tab, hints, current_navigable_id, move(name), no_opener, move(current_document_base_url));
- return { Optional<Web::PageId> {}, Optional<Web::HTML::CrossProcessId> {}, Optional<Web::HTML::SessionHistoryEntryDescriptor> {}, Optional<Web::HTML::EnvironmentId> {}, Optional<Web::HTML::CrossProcessId> {}, Optional<u64> {}, Web::HTML::VisibilityState::Hidden, String {} };
+ return { Optional<Web::PageId> {}, Optional<Web::HTML::CrossProcessId> {}, Optional<Web::HTML::SessionHistoryEntryDescriptor> {}, Optional<Web::HTML::EnvironmentId> {}, Optional<Web::HTML::CrossProcessId> {}, Optional<u64> {}, Web::HTML::WindowType::ExistingOrNone, Web::HTML::VisibilityState::Hidden, String {} };
}
Messages::WebContentClient::StartWorkerAgentResponse WebContentClient::start_worker_agent(Web::PageId page_id, Web::HTML::WorkerAgentStartRequest request)
diff --git a/Libraries/LibWebView/WebContentClient.h b/Libraries/LibWebView/WebContentClient.h
index c3572c0df9b..701b1e2bafe 100644
--- a/Libraries/LibWebView/WebContentClient.h
+++ b/Libraries/LibWebView/WebContentClient.h
@@ -212,7 +212,7 @@ private:
virtual void storage_area_reset(Web::StorageAPI::StorageAreaId, Vector<StorageItem>) override;
virtual Messages::WebContentClient::DidStartDownloadWithoutRequestResponse did_start_download_without_request(Web::PageId page_id, URL::URL, ByteString suggested_filename, Optional<u64> total_size) override;
virtual Messages::WebContentClient::DidStartDownloadResponse did_start_download(Web::PageId page_id, Web::HTML::CrossProcessId navigable_id, Optional<Utf16String> navigation_id, URL::URL, ByteString suggested_filename, Optional<u64> total_size, int request_server_client_id, u64 request_server_request_id, ByteBuffer initial_data, JsonValue network_response) override;
- virtual Messages::WebContentClient::DidRequestNewWebViewResponse did_request_new_web_view(Web::PageId page_id, Web::HTML::ActivateTab, Web::HTML::WebViewHints, Optional<Web::HTML::CrossProcessId> opener_navigable_id, Optional<URL::URL> opener_base_url, Utf16String target_name, Web::HTML::SandboxingFlagSet popup_sandboxing_flag_set) override;
+ virtual Messages::WebContentClient::DidRequestNewWebViewResponse did_request_new_web_view(Web::PageId page_id, Web::HTML::ActivateTab, Web::HTML::WebViewHints, Web::HTML::CrossProcessId current_navigable_id, Utf16String name, bool no_opener, Optional<URL::URL> current_document_base_url) override;
virtual Messages::WebContentClient::StartWorkerAgentResponse start_worker_agent(Web::PageId page_id, Web::HTML::WorkerAgentStartRequest request) override;
virtual void did_update_cookie(HTTP::Cookie::Cookie) override;
virtual Messages::WebContentClient::DidIsKnownHstsHostResponse did_is_known_hsts_host(String) override;
diff --git a/Libraries/LibWebView/WebContentPage.cpp b/Libraries/LibWebView/WebContentPage.cpp
index 289f0575511..339224083f6 100644
--- a/Libraries/LibWebView/WebContentPage.cpp
+++ b/Libraries/LibWebView/WebContentPage.cpp
@@ -2668,57 +2668,43 @@ void WebContentPage::did_request_delete_all_cookies(u64 request_id, URL::URL url
async_did_delete_all_cookies(request_id);
}
-Messages::WebContentClient::DidRequestNewWebViewResponse WebContentPage::did_request_new_web_view(Web::HTML::ActivateTab activate_tab, Web::HTML::WebViewHints hints, Optional<Web::HTML::CrossProcessId> opener_navigable_id, Optional<URL::URL> opener_base_url, Utf16String target_name, Web::HTML::SandboxingFlagSet popup_sandboxing_flag_set)
+Messages::WebContentClient::DidRequestNewWebViewResponse WebContentPage::did_request_new_web_view(Web::HTML::ActivateTab activate_tab, Web::HTML::WebViewHints hints, Web::HTML::CrossProcessId current_navigable_id, Utf16String name, bool no_opener, Optional<URL::URL> current_document_base_url)
{
- // The opener is a navigable the requesting page hosts. A request naming one it does not is refused before the
+ // The requesting navigable is one the requesting page hosts. A request naming one it does not is refused before the
// chrome is asked for a view, so nothing is created for a traversable that never will be.
- Optional<CanonicalNavigable&> opener;
- if (opener_navigable_id.has_value()) {
- opener = hosted_navigable(*opener_navigable_id);
- if (!opener.has_value())
- return { {}, {}, {}, {}, {}, {}, Web::HTML::VisibilityState::Hidden, {} };
- }
+ auto current_navigable = hosted_navigable(current_navigable_id);
+ if (!current_navigable.has_value())
+ return { {}, {}, {}, {}, {}, {}, {}, Web::HTML::VisibilityState::Hidden, {} };
Optional<CanonicalNavigable&> picture_in_picture_navigable;
if (hints.picture_in_picture_window.has_value()) {
picture_in_picture_navigable = hosted_navigable(hints.picture_in_picture_window->navigable_id);
if (!picture_in_picture_navigable.has_value())
- return { {}, {}, {}, {}, {}, {}, Web::HTML::VisibilityState::Hidden, {} };
+ return { {}, {}, {}, {}, {}, {}, {}, Web::HTML::VisibilityState::Hidden, {} };
// https://w3c.github.io/picture-in-picture/#request-picture-in-picture
// A window needs and consumes the activation of the user's input, which the renderer checks, unless the document
// asking for it has one open. A compromised renderer skips that check, so whatever the popup setting, the UI
// process checks the activation of input it delivered, and the window it opened for the navigable's document.
if (!PictureInPictureManager::the().document_has_open_window(*picture_in_picture_navigable) && !consume_transient_user_activation())
- return { {}, {}, {}, {}, {}, {}, Web::HTML::VisibilityState::Hidden, {} };
+ return { {}, {}, {}, {}, {}, {}, {}, Web::HTML::VisibilityState::Hidden, {} };
} else {
- // The popup blocker runs in the renderer, which a compromised renderer skips. Each popup takes the activation of
- // input the UI process delivered to the page, as the renderer's popup consumes the activation of its window.
- if (Application::the().blocks_pop_ups() && !consume_transient_user_activation())
- return { {}, {}, {}, {}, {}, {}, Web::HTML::VisibilityState::Hidden, {} };
+ // https://html.spec.whatwg.org/multipage/document-sequences.html#the-rules-for-choosing-a-navigable
+ // --> If currentNavigable's active window does not have transient activation and the user agent has been
+ // configured to not show popups
+ // NB: The popup blocker runs in the renderer, which a compromised renderer skips, so the UI process checks the
+ // activation of the input it delivered to the page.
+ if (Application::the().blocks_pop_ups() && !has_transient_user_activation())
+ return { {}, {}, {}, {}, {}, {}, {}, Web::HTML::VisibilityState::Hidden, {} };
}
auto root_navigable_id = Application::the().allocate_ui_process_cross_process_id();
- auto initial_history_entry = Web::HTML::create_initial_session_history_entry_descriptor(
- Application::the().allocate_ui_process_cross_process_id(), move(opener_base_url), move(target_name));
auto document_id = Application::the().allocate_ui_process_cross_process_id();
- auto& traversable = CanonicalTraversable::create_a_new_top_level_traversable(root_navigable_id, opener, move(initial_history_entry), document_id);
-
- // https://html.spec.whatwg.org/multipage/document-sequences.html#the-rules-for-choosing-a-navigable
- // If sandboxingFlagSet's sandbox propagates to auxiliary browsing contexts flag is set, then all the flags that are
- // set in sandboxingFlagSet must be set in chosen's active browsing context's popup sandboxing flag set.
- // NB: sandboxingFlagSet is currentNavigable's active document's active sandboxing flag set, which the UI process
- // holds for an opener. The requesting process gives it for a popup without one.
- if (opener.has_value()) {
- auto sandboxing_flag_set = opener->active_document().active_sandboxing_flag_set();
- if (has_flag(sandboxing_flag_set, Web::HTML::SandboxingFlagSet::SandboxPropagatesToAuxiliaryBrowsingContexts))
- popup_sandboxing_flag_set |= sandboxing_flag_set;
- }
- traversable.active_browsing_context().set_popup_sandboxing_flag_set(popup_sandboxing_flag_set);
- // 10. Set chosen's is created by web content to true.
- if (!picture_in_picture_navigable.has_value())
- traversable.set_is_created_by_web_content(true);
+ // A Picture-in-Picture window is not chosen by web content, so it skips the rules for choosing a navigable.
+ auto [traversable, window_type] = picture_in_picture_navigable.has_value()
+ ? CanonicalNavigable::ChosenTopLevelTraversable { CanonicalTraversable::create_a_new_top_level_traversable(root_navigable_id, {}, Web::HTML::create_initial_session_history_entry_descriptor(Application::the().allocate_ui_process_cross_process_id(), {}, {}), document_id), Web::HTML::WindowType::NewAndUnrestricted }
+ : current_navigable->choose_a_new_top_level_traversable(*this, name, no_opener, move(current_document_base_url), root_navigable_id, document_id);
auto new_page_id = Application::the().allocate_page_id();
client().open_page_for_new_top_level_traversable(new_page_id, traversable);
@@ -2733,13 +2719,13 @@ Messages::WebContentClient::DidRequestNewWebViewResponse WebContentPage::did_req
if (!traversable.view().has_value()) {
client().discard_page_of_undisplayed_top_level_traversable(new_page_id);
CanonicalTraversable::remove_from_user_agent_top_level_traversable_set(traversable);
- return { {}, {}, {}, {}, {}, {}, Web::HTML::VisibilityState::Hidden, move(window_handle) };
+ return { {}, {}, {}, {}, {}, {}, {}, Web::HTML::VisibilityState::Hidden, move(window_handle) };
}
traversable.represent_group_everywhere();
auto environment_id = traversable.active_document().relevant_global_object().relevant_settings_object().id();
Optional<u64> browsing_context_group_id = traversable.active_browsing_context().group()->id();
- return { new_page_id, root_navigable_id, traversable.active_session_history_entry()->descriptor(), move(environment_id), document_id, browsing_context_group_id, traversable.system_visibility_state(), move(window_handle) };
+ return { new_page_id, root_navigable_id, traversable.active_session_history_entry()->descriptor(), move(environment_id), document_id, browsing_context_group_id, window_type, traversable.system_visibility_state(), move(window_handle) };
}
void WebContentPage::did_close_browsing_context()
diff --git a/Libraries/LibWebView/WebContentPage.h b/Libraries/LibWebView/WebContentPage.h
index d7e7f045954..882c2b4a20d 100644
--- a/Libraries/LibWebView/WebContentPage.h
+++ b/Libraries/LibWebView/WebContentPage.h
@@ -347,7 +347,7 @@ private:
virtual void did_request_prompt(Utf16String message, Utf16String default_) override;
virtual void did_change_favicon(Gfx::ShareableBitmap favicon) override;
virtual void did_request_delete_all_cookies(u64 request_id, URL::URL url) override;
- Messages::WebContentClient::DidRequestNewWebViewResponse did_request_new_web_view(Web::HTML::ActivateTab activate_tab, Web::HTML::WebViewHints hints, Optional<Web::HTML::CrossProcessId> opener_navigable_id, Optional<URL::URL> opener_base_url, Utf16String target_name, Web::HTML::SandboxingFlagSet popup_sandboxing_flag_set);
+ Messages::WebContentClient::DidRequestNewWebViewResponse did_request_new_web_view(Web::HTML::ActivateTab activate_tab, Web::HTML::WebViewHints hints, Web::HTML::CrossProcessId current_navigable_id, Utf16String name, bool no_opener, Optional<URL::URL> current_document_base_url);
void did_close_browsing_context();
virtual void did_complete_close_preflight(u64 request_id, bool approved) override;
virtual void did_request_select_dropdown(Web::HTML::CrossProcessId local_root_id, Gfx::IntPoint content_position, i32 minimum_width, Vector<Web::HTML::SelectItem> items) override;
diff --git a/Services/WebContent/PageClient.cpp b/Services/WebContent/PageClient.cpp
index f21a76f6dc4..73a943cd2ce 100644
--- a/Services/WebContent/PageClient.cpp
+++ b/Services/WebContent/PageClient.cpp
@@ -1598,13 +1598,13 @@ void PageClient::page_did_update_resource_count(i32 count_waiting)
client().async_did_update_resource_count(m_id, count_waiting);
}
-PageClient::NewWebViewResult PageClient::page_did_request_new_web_view(Web::HTML::ActivateTab activate_tab, Web::HTML::WebViewHints hints, Optional<Web::HTML::CrossProcessId> opener_navigable_id, Optional<URL::URL> opener_base_url, Utf16String const& target_name, Web::HTML::SandboxingFlagSet popup_sandboxing_flag_set)
+PageClient::NewWebViewResult PageClient::page_did_request_new_web_view(Web::HTML::ActivateTab activate_tab, Web::HTML::WebViewHints hints, Web::HTML::CrossProcessId current_navigable_id, Utf16String const& name, Web::HTML::TokenizedFeature::NoOpener no_opener, Optional<URL::URL> current_document_base_url)
{
// FIXME: Create an abstraction to let this WebContent process know about a new process we create?
// FIXME: For now, just create a new page in the same process anyway
// FIXME: Proper agent-cluster separation must also cover same-process
// COOP/noopener popups before they receive distinct main-world cells.
- auto response = client().send_sync_but_allow_failure<Messages::WebContentClient::DidRequestNewWebView>(m_id, activate_tab, hints, opener_navigable_id, move(opener_base_url), target_name, popup_sandboxing_flag_set);
+ auto response = client().send_sync_but_allow_failure<Messages::WebContentClient::DidRequestNewWebView>(m_id, activate_tab, hints, current_navigable_id, name, no_opener == Web::HTML::TokenizedFeature::NoOpener::Yes, move(current_document_base_url));
if (!response) {
dbgln("WebContent client disconnected during DidRequestNewWebView. Exiting peacefully.");
Core::Process::terminate_immediately(0);
@@ -1619,7 +1619,7 @@ PageClient::NewWebViewResult PageClient::page_did_request_new_web_view(Web::HTML
auto& new_client = m_owner.create_page(*response->new_page_id(), *response->root_navigable_id());
new_client.page().set_system_visibility_state(response->system_visibility_state());
- return { &new_client.page(), response->take_handle(), response->take_initial_history_entry(), response->take_initial_environment_id(), response->initial_document_id(), response->browsing_context_group_id() };
+ return { &new_client.page(), response->take_handle(), response->take_initial_history_entry(), response->take_initial_environment_id(), response->initial_document_id(), response->browsing_context_group_id(), response->window_type() };
}
void PageClient::page_did_close()
diff --git a/Services/WebContent/PageClient.h b/Services/WebContent/PageClient.h
index 9c49ceea9c3..8f6906ec1c0 100644
--- a/Services/WebContent/PageClient.h
+++ b/Services/WebContent/PageClient.h
@@ -304,7 +304,7 @@ private:
virtual u64 page_did_request_storage_usage(Web::HTML::EnvironmentId const& environment_id) override;
virtual void page_did_update_indexed_database(String const& url, Web::IndexedDB::TransactionChanges const&) override;
virtual void page_did_update_resource_count(i32) override;
- virtual NewWebViewResult page_did_request_new_web_view(Web::HTML::ActivateTab, Web::HTML::WebViewHints, Optional<Web::HTML::CrossProcessId> opener_navigable_id, Optional<URL::URL> opener_base_url, Utf16String const& target_name, Web::HTML::SandboxingFlagSet popup_sandboxing_flag_set) override;
+ virtual NewWebViewResult page_did_request_new_web_view(Web::HTML::ActivateTab, Web::HTML::WebViewHints, Web::HTML::CrossProcessId current_navigable_id, Utf16String const& name, Web::HTML::TokenizedFeature::NoOpener no_opener, Optional<URL::URL> current_document_base_url) override;
virtual void page_did_close() override;
virtual void page_did_change_needs_beforeunload_check(bool needs_beforeunload_check) override;
virtual void page_did_consume_user_activation(Web::HTML::UserActivationConsumption) override;
diff --git a/Services/WebContent/WebContentClient.ipc b/Services/WebContent/WebContentClient.ipc
index dc8326ca438..2dfcf31109f 100644
--- a/Services/WebContent/WebContentClient.ipc
+++ b/Services/WebContent/WebContentClient.ipc
@@ -47,6 +47,7 @@
#include <LibWebCommon/HTML/UserActivationConsumption.h>
#include <LibWebCommon/HTML/VisibilityState.h>
#include <LibWebCommon/HTML/WebViewHints.h>
+#include <LibWebCommon/HTML/WindowType.h>
#include <LibWebCommon/HTML/WorkerAgentForward.h>
#include <LibWebCommon/HTML/WorkerAgentTypes.h>
#include <LibWebCommon/Page/CompositorContextId.h>
@@ -207,7 +208,7 @@ endpoint WebContentClient routed by Web::PageId page_id
did_post_broadcast_channel_message(Web::PageId page_id, Web::HTML::PostedBroadcastChannelMessage message) =|
did_update_resource_count(Web::PageId page_id, i32 count_waiting) =|
- [NotRouted] did_request_new_web_view(Web::PageId page_id, Web::HTML::ActivateTab activate_tab, Web::HTML::WebViewHints hints, Optional<Web::HTML::CrossProcessId> opener_navigable_id, Optional<URL::URL> opener_base_url, Utf16String target_name, Web::HTML::SandboxingFlagSet popup_sandboxing_flag_set) => (Optional<Web::PageId> new_page_id, Optional<Web::HTML::CrossProcessId> root_navigable_id, Optional<Web::HTML::SessionHistoryEntryDescriptor> initial_history_entry, Optional<Web::HTML::EnvironmentId> initial_environment_id, Optional<Web::HTML::CrossProcessId> initial_document_id, Optional<u64> browsing_context_group_id, Web::HTML::VisibilityState system_visibility_state, String handle)
+ [NotRouted] did_request_new_web_view(Web::PageId page_id, Web::HTML::ActivateTab activate_tab, Web::HTML::WebViewHints hints, Web::HTML::CrossProcessId current_navigable_id, Utf16String name, bool no_opener, Optional<URL::URL> current_document_base_url) => (Optional<Web::PageId> new_page_id, Optional<Web::HTML::CrossProcessId> root_navigable_id, Optional<Web::HTML::SessionHistoryEntryDescriptor> initial_history_entry, Optional<Web::HTML::EnvironmentId> initial_environment_id, Optional<Web::HTML::CrossProcessId> initial_document_id, Optional<u64> browsing_context_group_id, Web::HTML::WindowType window_type, Web::HTML::VisibilityState system_visibility_state, String handle)
[NotRouted] did_close_browsing_context(Web::PageId page_id) =|
did_complete_close_preflight(Web::PageId page_id, u64 request_id, bool approved) =|
did_change_needs_beforeunload_check(Web::PageId page_id, bool needs_beforeunload_check) =|
diff --git a/Tests/LibWebView/TestBrowserHistoryTraversal.cpp b/Tests/LibWebView/TestBrowserHistoryTraversal.cpp
index 96c411bd00b..7b6a5802cb7 100644
--- a/Tests/LibWebView/TestBrowserHistoryTraversal.cpp
+++ b/Tests/LibWebView/TestBrowserHistoryTraversal.cpp
@@ -357,7 +357,7 @@ ErrorOr<int> ladybird_main(Main::Arguments arguments)
rejected_page_id = traversable.display_page()->id();
return String {};
};
- auto rejected_popup = stub.did_request_new_web_view(restored_view->page().id(), Web::HTML::ActivateTab::No, {}, {}, {}, {}, {});
+ auto rejected_popup = stub.did_request_new_web_view(restored_view->page().id(), Web::HTML::ActivateTab::No, {}, restored_view->traversable().id(), {}, true, {});
VERIFY(!rejected_popup.new_page_id().has_value());
VERIFY(rejected_page_id != 0);
VERIFY(!client.may_act_for_page(rejected_page_id));