Skip to content

Truly independent web browser

LibWebView: Hold the embedder policy of each document's policy container

Shannon Booth1674f588443b
diff --git a/Libraries/LibWebView/CanonicalBrowsingContext.cpp b/Libraries/LibWebView/CanonicalBrowsingContext.cpp
index d2e69ea4cf0..ec0493b47b2 100644
--- a/Libraries/LibWebView/CanonicalBrowsingContext.cpp
+++ b/Libraries/LibWebView/CanonicalBrowsingContext.cpp
@@ -89,12 +89,15 @@ CanonicalBrowsingContext::BrowsingContextAndDocument CanonicalBrowsingContext::c
auto document = CanonicalDocument::create(document_id, URL::about_blank(), origin, browsing_context, window, sandbox_flags, CanonicalDocument::IsInitialAboutBlank::Yes);
// 19. If creator is non-null:
+ // 2. Set document's policy container to a clone of creator's policy container.
// 3. If creator's origin is same origin with creator's relevant settings object's top-level origin, then set
// document's opener policy to creator's browsing context's top-level browsing context's active document's
// opener policy.
- // NB: creator is fully active, so its relevant settings object's top-level origin is its top-level browsing
- // context's active document's origin.
+ // NB: The UI process holds the embedder policy of a document's policy container. creator is fully active, so its
+ // relevant settings object's top-level origin is its top-level browsing context's active document's origin.
if (creator) {
+ document->set_embedder_policy(creator->embedder_policy());
+
auto top_level_document = creator->browsing_context().top_level_browsing_context().active_document();
if (creator->origin().is_same_origin(top_level_document->origin()))
document->set_opener_policy(top_level_document->opener_policy());
diff --git a/Libraries/LibWebView/CanonicalDocument.h b/Libraries/LibWebView/CanonicalDocument.h
index c62ca5d35f4..2aec4e00ea6 100644
--- a/Libraries/LibWebView/CanonicalDocument.h
+++ b/Libraries/LibWebView/CanonicalDocument.h
@@ -14,6 +14,7 @@
#include <LibURL/URL.h>
#include <LibWebCommon/HTML/CrossOrigin/OpenerPolicy.h>
#include <LibWebCommon/HTML/CrossProcessId.h>
+#include <LibWebCommon/HTML/EmbedderPolicy.h>
#include <LibWebCommon/HTML/SandboxingFlagSet.h>
#include <LibWebView/Export.h>
#include <LibWebView/Forward.h>
@@ -59,6 +60,11 @@ public:
Web::HTML::OpenerPolicy const& opener_policy() const { return m_opener_policy; }
void set_opener_policy(Web::HTML::OpenerPolicy opener_policy) { m_opener_policy = move(opener_policy); }
+ // https://html.spec.whatwg.org/multipage/browsers.html#policy-container-embedder-policy
+ // The embedder policy of the document's policy container.
+ Web::HTML::EmbedderPolicy const& embedder_policy() const { return m_embedder_policy; }
+ void set_embedder_policy(Web::HTML::EmbedderPolicy embedder_policy) { m_embedder_policy = move(embedder_policy); }
+
// https://html.spec.whatwg.org/multipage/dom.html#completely-loaded
bool is_completely_loaded() const { return m_completely_loaded; }
void set_completely_loaded() { m_completely_loaded = true; }
@@ -103,6 +109,7 @@ private:
Web::HTML::SandboxingFlagSet m_active_sandboxing_flag_set {};
IsInitialAboutBlank m_is_initial_about_blank { IsInitialAboutBlank::No };
Web::HTML::OpenerPolicy m_opener_policy;
+ Web::HTML::EmbedderPolicy m_embedder_policy;
bool m_completely_loaded { false };
u32 m_unload_counter { 0 };
bool m_is_local_file_content { false };
diff --git a/Libraries/LibWebView/CanonicalNavigable.cpp b/Libraries/LibWebView/CanonicalNavigable.cpp
index 4fce57939ba..241bb8a0f4d 100644
--- a/Libraries/LibWebView/CanonicalNavigable.cpp
+++ b/Libraries/LibWebView/CanonicalNavigable.cpp
@@ -430,12 +430,15 @@ NonnullRefPtr<CanonicalDocument> CanonicalNavigable::create_and_initialize_a_doc
// 9. Let document be a new Document, with
// origin: navigationParams's origin
// browsing context: browsingContext
+ // policy container: navigationParams's policy container
// active sandboxing flag set: navigationParams's final sandboxing flag set
// opener policy: navigationParams's cross-origin opener policy
// URL: creationURL
// NB: The process hosting window's agent creates the document, with its other fields, and runs the remaining steps.
+ // The UI process holds the embedder policy of the document's policy container.
auto document = CanonicalDocument::create(navigation_params.document_id, move(creation_url), navigation_params.origin, browsing_context, window.release_nonnull(), navigation_params.final_sandboxing_flag_set, CanonicalDocument::IsInitialAboutBlank::No);
document->set_opener_policy(navigation_params.opener_policy);
+ document->set_embedder_policy(navigation_params.embedder_policy);
// 22. Return document.
return document;
@@ -924,6 +927,7 @@ void CanonicalNavigable::did_create_populated_document_with_an_origin_of_its_own
.request_current_url = {},
.origin = origin,
.opener_policy = {},
+ .embedder_policy = {},
.final_sandboxing_flag_set = populated_document->document->active_sandboxing_flag_set(),
.environment_id = environment_id,
.document_id = document_id,
diff --git a/Libraries/LibWebView/CanonicalTraversable.cpp b/Libraries/LibWebView/CanonicalTraversable.cpp
index 8df1cee3d13..78c0359b9ba 100644
--- a/Libraries/LibWebView/CanonicalTraversable.cpp
+++ b/Libraries/LibWebView/CanonicalTraversable.cpp
@@ -1970,6 +1970,7 @@ void CanonicalTraversable::did_attempt_to_populate_the_history_entry_document(We
.request_current_url = {},
.origin = *initiator_origin,
.opener_policy = coop,
+ .embedder_policy = navigable->active_document().embedder_policy(),
.final_sandboxing_flag_set = navigable->active_document().active_sandboxing_flag_set(),
.environment_id = parameters.environment_id,
.document_id = *parameters.document_id,
diff --git a/Libraries/LibWebView/NavigationLoader.cpp b/Libraries/LibWebView/NavigationLoader.cpp
index 7c8d70ace3a..637fcdab153 100644
--- a/Libraries/LibWebView/NavigationLoader.cpp
+++ b/Libraries/LibWebView/NavigationLoader.cpp
@@ -58,6 +58,7 @@ Optional<NavigationLoader::ResponseDocument> NavigationLoader::response_document
.request_current_url = {},
.origin = origin,
.opener_policy = {},
+ .embedder_policy = {},
.final_sandboxing_flag_set = {},
.environment_id = {},
.document_id = {},
@@ -86,6 +87,7 @@ Optional<NavigationLoader::ResponseDocument> NavigationLoader::response_document
: Optional<URL::URL> {},
.origin = fetched_navigation_params.origin,
.opener_policy = fetched_navigation_params.opener_policy,
+ .embedder_policy = fetched_navigation_params.policy_container.embedder_policy,
.final_sandboxing_flag_set = fetched_navigation_params.final_sandboxing_flag_set,
.environment_id = {},
.document_id = {},
diff --git a/Libraries/LibWebView/NavigationLoader.h b/Libraries/LibWebView/NavigationLoader.h
index 2593fe96cdf..e7b391e5ca7 100644
--- a/Libraries/LibWebView/NavigationLoader.h
+++ b/Libraries/LibWebView/NavigationLoader.h
@@ -47,6 +47,8 @@ public:
Optional<URL::URL> request_current_url;
URL::Origin origin;
Web::HTML::OpenerPolicy opener_policy;
+ // The embedder policy of navigationParams's policy container.
+ Web::HTML::EmbedderPolicy embedder_policy;
Web::HTML::SandboxingFlagSet final_sandboxing_flag_set {};
// The id of the window environment a process created the document with before the UI process heard of it.
Optional<Web::HTML::EnvironmentId> environment_id;
diff --git a/Tests/LibWebView/TestCanonicalBrowsingContextGroup.cpp b/Tests/LibWebView/TestCanonicalBrowsingContextGroup.cpp
index 9ac09beaeec..cf080d82f03 100644
--- a/Tests/LibWebView/TestCanonicalBrowsingContextGroup.cpp
+++ b/Tests/LibWebView/TestCanonicalBrowsingContextGroup.cpp
@@ -177,6 +177,7 @@ TEST_CASE(response_browsing_context_is_activated_only_at_commit)
.request_current_url = {},
.origin = destination_url.origin(),
.opener_policy = {},
+ .embedder_policy = {},
.environment_id = {},
.document_id = {},
});
@@ -230,6 +231,7 @@ TEST_CASE(child_navigation_under_a_document_that_switched_groups_uses_its_group)
.request_current_url = {},
.origin = destination_url.origin(),
.opener_policy = {},
+ .embedder_policy = {},
.environment_id = {},
.document_id = {},
});
@@ -268,6 +270,7 @@ TEST_CASE(child_navigation_under_a_document_that_switched_groups_uses_its_group)
.request_current_url = {},
.origin = frame_url.origin(),
.opener_policy = {},
+ .embedder_policy = {},
.environment_id = {},
.document_id = {},
});
@@ -441,6 +444,7 @@ static NonnullRefPtr<WebView::CanonicalDocument> navigate_to_a_new_group(WebView
.request_current_url = {},
.origin = destination_url.origin(),
.opener_policy = opener_policy,
+ .embedder_policy = {},
.environment_id = {},
.document_id = {},
});