Truly independent web browser
LibWeb+LibWebView: Name the document a child frame is created in
Shannon Bootha0ccd0c44161
diff --git a/Libraries/LibWeb/HTML/LocalNavigable.cpp b/Libraries/LibWeb/HTML/LocalNavigable.cppindex cec022c7ffd..b01bbe924fe 100644--- a/Libraries/LibWeb/HTML/LocalNavigable.cpp+++ b/Libraries/LibWeb/HTML/LocalNavigable.cpp@@ -3667,6 +3667,10 @@ void LocalNavigable::begin_navigation(PreparedNavigation navigation)if (!active_window())return;+ // AD-HOC: An SVG image's page has no UI process to navigate in, so its navigables keep their initial documents.+ if (active_browsing_context()->page().client().is_svg_page_client())+ return;+// NB: A provisional navigable's document stands in for one another page hosts, which the navigation navigates.VERIFY(!is_provisional());diff --git a/Libraries/LibWeb/HTML/NavigableContainer.cpp b/Libraries/LibWeb/HTML/NavigableContainer.cppindex 8e8153df935..c363d70e557 100644--- a/Libraries/LibWeb/HTML/NavigableContainer.cpp+++ b/Libraries/LibWeb/HTML/NavigableContainer.cpp@@ -113,7 +113,13 @@ void NavigableContainer::create_new_child_navigable()// 10. Let historyEntry be navigable's active session history entry.auto history_entry = navigable->active_session_history_entry();- page.client().page_did_create_child_frame(parent_navigable->id(), navigable->id(), navigable->hosted_state(), create_pending_session_history_entry_descriptor(*history_entry), document->origin(), document->relevant_settings_object().id, document->id());+ page.client().page_did_create_child_frame(parent_navigable->id(), this->document(), navigable->id(), navigable->hosted_state(), create_pending_session_history_entry_descriptor(*history_entry), document->origin(), document->relevant_settings_object().id, document->id());++ // NB: An SVG image's page has no UI process to run the traversal steps.+ if (page.client().is_svg_page_client()) {+ navigable->set_has_session_history_entry_and_ready_for_navigation();+ return;+ }// 12. Append the following session history traversal steps to traversable:page.history_executor().request_history_operation(diff --git a/Libraries/LibWeb/Page/Page.h b/Libraries/LibWeb/Page/Page.hindex 3b3ba1408e0..0bcf2a58b5e 100644--- a/Libraries/LibWeb/Page/Page.h+++ b/Libraries/LibWeb/Page/Page.h@@ -608,7 +608,7 @@ public:virtual void history_navigation_params_creation_finished(HTML::CrossProcessId operation_id, HTML::HistoryNavigationPopulation);virtual void navigation_population_failed(HTML::CrossProcessId, Utf16String const&) { }virtual void page_did_create_populated_document_with_an_origin_of_its_own(HTML::CrossProcessId, HTML::CrossProcessId, HTML::PopulatedDocumentOrigin, HTML::EnvironmentId const&) { }- virtual void page_did_create_child_frame(HTML::CrossProcessId, HTML::CrossProcessId, HTML::HostedNavigableState const&, HTML::PendingSessionHistoryEntryDescriptor const&, URL::Origin const&, HTML::EnvironmentId const&, HTML::CrossProcessId) { }+ virtual void page_did_create_child_frame(HTML::CrossProcessId, DOM::Document const&, HTML::CrossProcessId, HTML::HostedNavigableState const&, HTML::PendingSessionHistoryEntryDescriptor const&, URL::Origin const&, HTML::EnvironmentId const&, HTML::CrossProcessId) { }virtual void page_did_change_hosted_navigable_state([[maybe_unused]] HTML::CrossProcessId navigable_id, [[maybe_unused]] HTML::HostedNavigableState const& state) { }virtual void page_did_set_opener_browsing_context([[maybe_unused]] HTML::CrossProcessId navigable_id, [[maybe_unused]] Optional<HTML::CrossProcessId> opener_navigable_id) { }virtual void page_did_completely_finish_loading([[maybe_unused]] HTML::CrossProcessId navigable_id) { }diff --git a/Libraries/LibWebView/CanonicalNavigable.cpp b/Libraries/LibWebView/CanonicalNavigable.cppindex 87dbd92901f..3e4bdab2967 100644--- a/Libraries/LibWebView/CanonicalNavigable.cpp+++ b/Libraries/LibWebView/CanonicalNavigable.cpp@@ -794,6 +794,18 @@ RefPtr<CanonicalDocument> CanonicalNavigable::document_populated_for(CanonicalDoreturn document;}+RefPtr<CanonicalDocument> CanonicalNavigable::document_with_id(Web::HTML::CrossProcessId id) const+{+ if (active_document().id() == id)+ return active_document();+ RefPtr<CanonicalDocument> document;+ for_each_populated_document([&](PopulatedDocument const& populated_document) {+ if (populated_document.document->id() == id)+ document = populated_document.document;+ });+ return document;+}+void CanonicalNavigable::populate_document(NonnullRefPtr<CanonicalDocumentState> document_state, NonnullRefPtr<CanonicalDocument> document, Optional<URL::Origin> inline_content_origin){document->determine_whether_it_is_local_file_content(blob_url_store());@@ -1192,16 +1204,13 @@ void CanonicalNavigable::did_commit_navigation(CanonicalSessionHistoryEntry& ent}update_hosted_state(move(hosted_state));- // The displaced document is gone, and its child navigables with it. The page that hosted it reported their- // destruction when it unloaded the document, unless another page hosts the activated document: that page holds- // the navigable remotely from now on, and the child navigables of the displaced document go here.+ // The displaced document is gone, and its child navigables with it. When another page hosts the activated+ // document, the page that hosted the displaced one holds the navigable remotely from now on.if (document != previous_document) {- if (auto previous_host = previous_document->host(); previous_host != document->host()) {- auto& traversable = top_level_traversable();- traversable.remove_child_navigables_of(*this, *previous_document);- if (previous_host && previous_host->is_open())- traversable.stop_hosting_in_page(*this, previous_host.release_nonnull());- }+ auto& traversable = top_level_traversable();+ traversable.remove_child_navigables_of(*this, *previous_document);+ if (auto previous_host = previous_document->host(); previous_host && previous_host != document->host() && previous_host->is_open())+ traversable.stop_hosting_in_page(*this, previous_host.release_nonnull());}// A navigation can commit while a newer navigation is already in flight. In that case update the replicateddiff --git a/Libraries/LibWebView/CanonicalNavigable.h b/Libraries/LibWebView/CanonicalNavigable.hindex a0cc87111be..d7885eedc5e 100644--- a/Libraries/LibWebView/CanonicalNavigable.h+++ b/Libraries/LibWebView/CanonicalNavigable.h@@ -97,6 +97,7 @@ public:RefPtr<CanonicalDocumentState> populating_document_state() const;RefPtr<CanonicalDocument> pending_document() const;RefPtr<CanonicalDocument> document_populated_for(CanonicalDocumentState const&) const;+ RefPtr<CanonicalDocument> document_with_id(Web::HTML::CrossProcessId) const;void populate_document(NonnullRefPtr<CanonicalDocumentState>, NonnullRefPtr<CanonicalDocument>, Optional<URL::Origin> inline_content_origin = {});void populate_document_for_ongoing_navigation(NonnullRefPtr<CanonicalDocumentState>, NonnullRefPtr<CanonicalDocument>, Optional<URL::Origin> inline_content_origin = {});// Returns false, populating nothing, for a document that would hold access the active document lacks.diff --git a/Libraries/LibWebView/CanonicalTraversable.cpp b/Libraries/LibWebView/CanonicalTraversable.cppindex 66270a7e157..193017e5849 100644--- a/Libraries/LibWebView/CanonicalTraversable.cpp+++ b/Libraries/LibWebView/CanonicalTraversable.cpp@@ -1070,20 +1070,6 @@ CanonicalTraversable::~CanonicalTraversable()});}-// A page holds the document of a navigable that it hosts, or the document of the navigable's next activation that it-// populates while another page hosts the active document.-CanonicalDocument& CanonicalTraversable::document_active_in(CanonicalNavigable& navigable, WebContentPage const& page) const-{- if (navigable.active_document().host() == &page)- return navigable.active_document();- RefPtr<CanonicalDocument> document;- navigable.for_each_populated_document([&](PopulatedDocument const& populated_document) {- if (populated_document.document->host() == &page)- document = populated_document.document;- });- return document ? *document : navigable.active_document();-}-Optional<size_t> CanonicalTraversable::effective_current_session_history_step_index() const{for (auto const& operation : m_history_operations) {diff --git a/Libraries/LibWebView/CanonicalTraversable.h b/Libraries/LibWebView/CanonicalTraversable.hindex 224010595f3..16fcb90f027 100644--- a/Libraries/LibWebView/CanonicalTraversable.h+++ b/Libraries/LibWebView/CanonicalTraversable.h@@ -50,7 +50,6 @@ public:virtual ~CanonicalTraversable() override;virtual bool is_top_level_traversable() const override { return true; }- CanonicalDocument& document_active_in(CanonicalNavigable&, WebContentPage const&) const;// Apply-the-history-step coordination. Operations serialize on the traversable's session history traversal// queue; the algorithm runs here and dispatches its per-navigable jobs to the processes hosting the documents.diff --git a/Libraries/LibWebView/WebContentPage.cpp b/Libraries/LibWebView/WebContentPage.cppindex 51b4cfcd2fb..31ad69b270b 100644--- a/Libraries/LibWebView/WebContentPage.cpp+++ b/Libraries/LibWebView/WebContentPage.cpp@@ -735,7 +735,7 @@ void WebContentPage::did_create_populated_document_with_an_origin_of_its_own(Webnavigable->did_create_populated_document_with_an_origin_of_its_own(*this, document_id, origin, environment_id);}-void WebContentPage::did_create_child_frame(Web::HTML::CrossProcessId parent_frame_id, Web::HTML::CrossProcessId frame_id, Web::HTML::HostedNavigableState hosted_state, Web::HTML::PendingSessionHistoryEntryDescriptor initial_history_entry, URL::Origin origin, Web::HTML::EnvironmentId environment_id, Web::HTML::CrossProcessId document_id)+void WebContentPage::did_create_child_frame(Web::HTML::CrossProcessId parent_frame_id, Web::HTML::CrossProcessId container_document_id, Web::HTML::CrossProcessId frame_id, Web::HTML::HostedNavigableState hosted_state, Web::HTML::PendingSessionHistoryEntryDescriptor initial_history_entry, URL::Origin origin, Web::HTML::EnvironmentId environment_id, Web::HTML::CrossProcessId document_id){auto& traversable = this->traversable();@@ -744,18 +744,21 @@ void WebContentPage::did_create_child_frame(Web::HTML::CrossProcessId parent_fraauto parent = traversable.find(parent_frame_id);auto& parent_navigable = parent.has_value() ? *parent : static_cast<CanonicalNavigable&>(traversable);- // The page creates frames in the parent's document that is fully active in it.- auto& container_document = traversable.document_active_in(parent_navigable, *this);+ auto container_document = parent_navigable.document_with_id(container_document_id);+ if (!container_document || container_document->host() != this) {+ client().did_misbehave("did_create_child_frame"sv, "frame created in a document the page does not hold"sv);+ return;+ }if (auto existing_navigable = traversable.find(frame_id); existing_navigable.has_value()) {if (existing_navigable->parent() != &parent_navigable) {client().did_misbehave("did_create_child_frame"sv, "frame created under another parent"sv);return;}- traversable.rehost(*existing_navigable, *this, container_document, move(hosted_state));+ traversable.rehost(*existing_navigable, *this, *container_document, move(hosted_state));return;}- traversable.adopt_nested_history_for_created_child(parent_navigable, container_document, frame_id);+ traversable.adopt_nested_history_for_created_child(parent_navigable, *container_document, frame_id);// https://html.spec.whatwg.org/multipage/document-sequences.html#create-a-new-child-navigable// NB: The process creating the navigable reports the entry that initializing it, in step 8, created.@@ -766,10 +769,10 @@ void WebContentPage::did_create_child_frame(Web::HTML::CrossProcessId parent_fra}// 2. Let group be element's node document's browsing context's top-level browsing context's group.- auto group = container_document.browsing_context().top_level_browsing_context().group();+ auto group = container_document->browsing_context().top_level_browsing_context().group();// 3. Let browsingContext and document be the result of creating a new browsing context and document given element's node document, element, and group.- auto document = CanonicalBrowsingContext::create_a_new_browsing_context_and_document(&container_document, hosted_state.container, *group, document_id, move(environment_id), move(origin)).document;+ auto document = CanonicalBrowsingContext::create_a_new_browsing_context_and_document(container_document.ptr(), hosted_state.container, *group, document_id, move(environment_id), move(origin)).document;// 6. Let documentState be a new document state, with// document: document@@ -785,7 +788,7 @@ void WebContentPage::did_create_child_frame(Web::HTML::CrossProcessId parent_fra// 7. Let navigable be a new navigable.// 8. Initialize the navigable navigable given documentState and parentNavigable.- traversable.insert(*this, parent_navigable, container_document, frame_id, move(hosted_state), initial_entry.release_value(), move(document));+ traversable.insert(*this, parent_navigable, *container_document, frame_id, move(hosted_state), initial_entry.release_value(), move(document));}void WebContentPage::did_set_browser_zoom(double factor)diff --git a/Libraries/LibWebView/WebContentPage.h b/Libraries/LibWebView/WebContentPage.hindex 879e528a9ae..0413d3aeb04 100644--- a/Libraries/LibWebView/WebContentPage.h+++ b/Libraries/LibWebView/WebContentPage.h@@ -174,7 +174,7 @@ private:virtual void did_request_set_opener_of_navigable(Web::HTML::CrossProcessId navigable_id, Web::HTML::CrossProcessId opener_navigable_id) override;virtual void did_completely_finish_loading(Web::HTML::CrossProcessId navigable_id) override;virtual void did_create_populated_document_with_an_origin_of_its_own(Web::HTML::CrossProcessId navigable_id, Web::HTML::CrossProcessId document_id, Web::HTML::PopulatedDocumentOrigin origin, Web::HTML::EnvironmentId environment_id) override;- virtual void did_create_child_frame(Web::HTML::CrossProcessId parent_frame_id, Web::HTML::CrossProcessId frame_id, Web::HTML::HostedNavigableState replicated_state, Web::HTML::PendingSessionHistoryEntryDescriptor initial_history_entry, URL::Origin origin, Web::HTML::EnvironmentId environment_id, Web::HTML::CrossProcessId document_id) override;+ virtual void did_create_child_frame(Web::HTML::CrossProcessId parent_frame_id, Web::HTML::CrossProcessId container_document_id, Web::HTML::CrossProcessId frame_id, Web::HTML::HostedNavigableState replicated_state, Web::HTML::PendingSessionHistoryEntryDescriptor initial_history_entry, URL::Origin origin, Web::HTML::EnvironmentId environment_id, Web::HTML::CrossProcessId document_id) override;virtual void did_set_browser_zoom(double factor) override;virtual void did_set_device_pixel_ratio_for_testing(double device_pixel_ratio) override;virtual void did_find_in_page(size_t current_match_index, Optional<size_t> total_match_count) override;diff --git a/Services/WebContent/PageClient.cpp b/Services/WebContent/PageClient.cppindex e55bd10d228..7d9cdb886bc 100644--- a/Services/WebContent/PageClient.cpp+++ b/Services/WebContent/PageClient.cpp@@ -406,9 +406,9 @@ void PageClient::page_did_create_populated_document_with_an_origin_of_its_own(Weclient().async_did_create_populated_document_with_an_origin_of_its_own(m_id, navigable_id, document_id, origin, environment_id);}-void PageClient::page_did_create_child_frame(Web::HTML::CrossProcessId parent_frame_id, Web::HTML::CrossProcessId frame_id, Web::HTML::HostedNavigableState const& replicated_state, Web::HTML::PendingSessionHistoryEntryDescriptor const& initial_history_entry, URL::Origin const& origin, Web::HTML::EnvironmentId const& environment_id, Web::HTML::CrossProcessId document_id)+void PageClient::page_did_create_child_frame(Web::HTML::CrossProcessId parent_frame_id, Web::DOM::Document const& container_document, Web::HTML::CrossProcessId frame_id, Web::HTML::HostedNavigableState const& replicated_state, Web::HTML::PendingSessionHistoryEntryDescriptor const& initial_history_entry, URL::Origin const& origin, Web::HTML::EnvironmentId const& environment_id, Web::HTML::CrossProcessId document_id){- client().async_did_create_child_frame(m_id, parent_frame_id, frame_id, replicated_state, initial_history_entry, origin, environment_id, document_id);+ client().async_did_create_child_frame(m_id, parent_frame_id, container_document.id(), frame_id, replicated_state, initial_history_entry, origin, environment_id, document_id);}void PageClient::page_did_update_child_frame_viewport(Web::HTML::CrossProcessId frame_id, Web::DevicePixelRect viewport_rect, Web::DevicePixelRect viewport_intersection)diff --git a/Services/WebContent/PageClient.h b/Services/WebContent/PageClient.hindex 5cae0451474..2fdcde863f7 100644--- a/Services/WebContent/PageClient.h+++ b/Services/WebContent/PageClient.h@@ -202,7 +202,7 @@ private:virtual void page_did_completely_finish_loading(Web::HTML::CrossProcessId navigable_id) override;virtual void page_did_change_navigable_container_state(Web::HTML::CrossProcessId navigable_id, Web::HTML::ReplicatedContainerState const&) override;virtual void page_did_create_populated_document_with_an_origin_of_its_own(Web::HTML::CrossProcessId navigable_id, Web::HTML::CrossProcessId document_id, Web::HTML::PopulatedDocumentOrigin, Web::HTML::EnvironmentId const& environment_id) override;- virtual void page_did_create_child_frame(Web::HTML::CrossProcessId parent_frame_id, Web::HTML::CrossProcessId frame_id, Web::HTML::HostedNavigableState const&, Web::HTML::PendingSessionHistoryEntryDescriptor const& initial_history_entry, URL::Origin const& origin, Web::HTML::EnvironmentId const& environment_id, Web::HTML::CrossProcessId document_id) override;+ virtual void page_did_create_child_frame(Web::HTML::CrossProcessId parent_frame_id, Web::DOM::Document const& container_document, Web::HTML::CrossProcessId frame_id, Web::HTML::HostedNavigableState const&, Web::HTML::PendingSessionHistoryEntryDescriptor const& initial_history_entry, URL::Origin const& origin, Web::HTML::EnvironmentId const& environment_id, Web::HTML::CrossProcessId document_id) override;virtual void page_did_update_child_frame_viewport(Web::HTML::CrossProcessId frame_id, Web::DevicePixelRect viewport_rect, Web::DevicePixelRect viewport_intersection) override;virtual void forward_mouse_event_to_remote_navigable(Web::PageId, Web::HTML::CrossProcessId navigable_id, Web::MouseEvent) override;virtual void page_did_destroy_child_frame(Web::HTML::CrossProcessId frame_id) override;diff --git a/Services/WebContent/WebContentClient.ipc b/Services/WebContent/WebContentClient.ipcindex bdb3033056c..fd2d0dfc3d1 100644--- a/Services/WebContent/WebContentClient.ipc+++ b/Services/WebContent/WebContentClient.ipc@@ -96,7 +96,7 @@ endpoint WebContentClient routed by Web::PageId page_iddid_finish_navigation_params_creation(Web::PageId page_id, Web::HTML::CrossProcessId navigable_id, Utf16String navigation_id, Optional<Web::HTML::NavigationPopulationResult> result) =|did_fail_navigation_population(Web::PageId page_id, Web::HTML::CrossProcessId navigable_id, Utf16String navigation_id) =|did_create_populated_document_with_an_origin_of_its_own(Web::PageId page_id, Web::HTML::CrossProcessId navigable_id, Web::HTML::CrossProcessId document_id, Web::HTML::PopulatedDocumentOrigin origin, Web::HTML::EnvironmentId environment_id) =|- did_create_child_frame(Web::PageId page_id, Web::HTML::CrossProcessId parent_frame_id, Web::HTML::CrossProcessId frame_id, Web::HTML::HostedNavigableState hosted_state, Web::HTML::PendingSessionHistoryEntryDescriptor initial_history_entry, URL::Origin origin, Web::HTML::EnvironmentId environment_id, Web::HTML::CrossProcessId document_id) =|+ did_create_child_frame(Web::PageId page_id, Web::HTML::CrossProcessId parent_frame_id, Web::HTML::CrossProcessId container_document_id, Web::HTML::CrossProcessId frame_id, Web::HTML::HostedNavigableState hosted_state, Web::HTML::PendingSessionHistoryEntryDescriptor initial_history_entry, URL::Origin origin, Web::HTML::EnvironmentId environment_id, Web::HTML::CrossProcessId document_id) =|did_change_hosted_navigable_state(Web::PageId page_id, Web::HTML::CrossProcessId navigable_id, Web::HTML::HostedNavigableState state) =|did_set_opener_browsing_context(Web::PageId page_id, Web::HTML::CrossProcessId navigable_id, Optional<Web::HTML::CrossProcessId> opener_navigable_id) =|did_completely_finish_loading(Web::PageId page_id, Web::HTML::CrossProcessId navigable_id) =|diff --git a/Tests/LibWeb/Crash/SVG/iframe-in-svg-image.html b/Tests/LibWeb/Crash/SVG/iframe-in-svg-image.htmlnew file mode 100644index 00000000000..53f4f84c4ec--- /dev/null+++ b/Tests/LibWeb/Crash/SVG/iframe-in-svg-image.html@@ -0,0 +1,2 @@+<!DOCTYPE html>+<img src="data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg'><foreignObject width='100' height='100'><iframe xmlns='http://www.w3.org/1999/xhtml'></iframe></foreignObject></svg>">diff --git a/Tests/LibWeb/Crash/SVG/iframe-with-src-in-svg-image.html b/Tests/LibWeb/Crash/SVG/iframe-with-src-in-svg-image.htmlnew file mode 100644index 00000000000..33c4a85772e--- /dev/null+++ b/Tests/LibWeb/Crash/SVG/iframe-with-src-in-svg-image.html@@ -0,0 +1,2 @@+<!DOCTYPE html>+<img src="data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg'><foreignObject width='100' height='100'><iframe xmlns='http://www.w3.org/1999/xhtml' src='data:text/html,hi'></iframe></foreignObject></svg>">