Truly independent web browser
LibWebView+LibWeb+WebContent: Notify activation across processes
Luke Wilde7ed2f0b0ec41
diff --git a/Libraries/LibWeb/Page/Page.cpp b/Libraries/LibWeb/Page/Page.cppindex b2b28fd2fc8..50311bcdb1e 100644--- a/Libraries/LibWeb/Page/Page.cpp+++ b/Libraries/LibWeb/Page/Page.cpp@@ -181,6 +181,23 @@ bool Page::top_level_traversable_has_user_attention() constreturn m_system_visibility_state == HTML::VisibilityState::Visible && client().has_focus();}+// https://html.spec.whatwg.org/multipage/interaction.html#activation-notification+// NB: The UI process gathers the windows of steps 2 to 4, which documents in other processes can hold, and names each+// one this page hosts.+void Page::notify_document_about_user_activation(HTML::CrossProcessId document_id)+{+ for (auto const& navigable : hosted_navigables()) {+ auto document = navigable->active_document();+ if (!document || !document->is_fully_active() || document->id() != document_id)+ continue;++ // 5.1. Set window's last activation timestamp to the current high resolution time.+ // 5.2. Notify the close watcher manager about user activation given window.+ document->window()->notify_about_user_activation();+ return;+ }+}+// The navigable keyboard input goes to in the tab, which is the top-level traversable until focus moves into another.GC::Ptr<HTML::Navigable> Page::focused_navigable() const{diff --git a/Libraries/LibWeb/Page/Page.h b/Libraries/LibWeb/Page/Page.hindex ba9ad445711..767b9aa574f 100644--- a/Libraries/LibWeb/Page/Page.h+++ b/Libraries/LibWeb/Page/Page.h@@ -164,6 +164,7 @@ public:HTML::VisibilityState system_visibility_state() const { return m_system_visibility_state; }void set_system_visibility_state(HTML::VisibilityState visibility_state) { m_system_visibility_state = visibility_state; }bool top_level_traversable_has_user_attention() const;+ void notify_document_about_user_activation(HTML::CrossProcessId document_id);void unfullscreen_descendant_documents(Vector<GC::Root<HTML::Navigable>> const&);enum class ElementIsRequestedElement : u8 {No,diff --git a/Libraries/LibWebView/CanonicalNavigable.cpp b/Libraries/LibWebView/CanonicalNavigable.cppindex d49c3854ed1..fd14a333542 100644--- a/Libraries/LibWebView/CanonicalNavigable.cpp+++ b/Libraries/LibWebView/CanonicalNavigable.cpp@@ -581,6 +581,38 @@ bool CanonicalNavigable::active_document_is_fully_active_descendant_of_a_top_levreturn m_hosted_state.has_value() && m_hosted_state->active_document_is_fully_active && top_level_traversable().has_user_attention();}+// https://html.spec.whatwg.org/multipage/interaction.html#activation-notification+void CanonicalNavigable::run_activation_notification_steps_for_active_document(HashTable<Web::HTML::CrossProcessId>& notified_document_ids) const+{+ auto const& document = active_document();++ // 2. Let windows be « document's relevant global object ».+ Vector<NonnullRefPtr<CanonicalDocument const>> windows { document };++ // 3. Extend windows with the active window of each of document's ancestor navigables.+ for (auto const* ancestor = parent(); ancestor; ancestor = ancestor->parent())+ windows.append(ancestor->active_document());++ // 4. Extend windows with the active window of each of document's descendant navigables, filtered to include only+ // those navigables whose active document's origin is same origin with document's origin.+ for_each_in_subtree([&](CanonicalNavigable const& descendant) {+ auto const& descendant_document = descendant.active_document();+ if (descendant_document.origin().is_same_origin(document.origin()))+ windows.append(descendant_document);+ return IterationDecision::Continue;+ });++ // 5. For each window in windows:+ // NB: The page hosting the window's document runs steps 5.1 and 5.2. Running them again for the same input changes+ // nothing, so a window already notified for it is skipped.+ for (auto const& window : windows) {+ if (notified_document_ids.set(window->id()) != HashSetResult::InsertedNewEntry)+ continue;+ if (auto const& host = window->host())+ host->notify_about_user_activation(window->id());+ }+}+// https://html.spec.whatwg.org/multipage/document-sequences.html#familiar-with// NB: Stated on the navigables whose active browsing contexts are compared, as in the renderer.bool CanonicalNavigable::is_familiar_with(CanonicalNavigable const& other) constdiff --git a/Libraries/LibWebView/CanonicalNavigable.h b/Libraries/LibWebView/CanonicalNavigable.hindex 5cb4bedeec4..a55ebe883b0 100644--- a/Libraries/LibWebView/CanonicalNavigable.h+++ b/Libraries/LibWebView/CanonicalNavigable.h@@ -7,6 +7,7 @@#pragma once#include <AK/Function.h>+#include <AK/HashTable.h>#include <AK/IterationDecision.h>#include <AK/NonnullOwnPtr.h>#include <AK/NonnullRefPtr.h>@@ -129,6 +130,7 @@ public:NonnullOwnPtr<CanonicalNavigable> remove_child(CanonicalNavigable&);bool is_ancestor_of(CanonicalNavigable const&) const;bool active_document_is_fully_active_descendant_of_a_top_level_traversable_with_user_attention() const;+ void run_activation_notification_steps_for_active_document(HashTable<Web::HTML::CrossProcessId>& notified_document_ids) 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-navigablediff --git a/Libraries/LibWebView/WebContentPage.cpp b/Libraries/LibWebView/WebContentPage.cppindex 7cd664d5855..25d6e1a4661 100644--- a/Libraries/LibWebView/WebContentPage.cpp+++ b/Libraries/LibWebView/WebContentPage.cpp@@ -1398,6 +1398,12 @@ void WebContentPage::give_user_activation()m_last_user_activation = MonotonicTime::now();}+void WebContentPage::notify_about_user_activation(Web::HTML::CrossProcessId document_id)+{+ give_user_activation();+ async_notify_about_user_activation(document_id);+}+bool WebContentPage::has_transient_user_activation() const{// NB: Automation lets a renderer synthesize the input that gives it activation.diff --git a/Libraries/LibWebView/WebContentPage.h b/Libraries/LibWebView/WebContentPage.hindex 9d5039a7019..f3722883013 100644--- a/Libraries/LibWebView/WebContentPage.h+++ b/Libraries/LibWebView/WebContentPage.h@@ -136,6 +136,7 @@ public:// The user activation the UI process gives a page when it delivers input the user produced. Unlike the activation// a renderer reports, a compromised renderer cannot claim it.void give_user_activation();+ void notify_about_user_activation(Web::HTML::CrossProcessId document_id);bool has_transient_user_activation() const;// Consumes the activation of every page of the tab, as consuming a window's activation does for the windows of its// top-level traversable. Returns false, consuming nothing, when the page has no transient activation.diff --git a/Services/WebContent/ConnectionFromClient.cpp b/Services/WebContent/ConnectionFromClient.cppindex a0cfc5148e5..11bdbfdc7ec 100644--- a/Services/WebContent/ConnectionFromClient.cpp+++ b/Services/WebContent/ConnectionFromClient.cpp@@ -3242,6 +3242,12 @@ void ConnectionFromClient::consume_user_activation(Web::PageId page_id, Web::HTMWeb::HTML::Window::consume_user_activation_of_windows_hosted_by(page->page(), consumption);}+void ConnectionFromClient::notify_about_user_activation(Web::PageId page_id, Web::HTML::CrossProcessId document_id)+{+ if (auto page = this->page(page_id); page.has_value())+ page->page().notify_document_about_user_activation(document_id);+}+void ConnectionFromClient::set_enable_global_privacy_control(Web::PageId, bool enable){Web::update_loader_config([&](auto& config) { config.enable_global_privacy_control = enable; });diff --git a/Services/WebContent/ConnectionFromClient.h b/Services/WebContent/ConnectionFromClient.hindex cefc261c26a..eb64b86df37 100644--- a/Services/WebContent/ConnectionFromClient.h+++ b/Services/WebContent/ConnectionFromClient.h@@ -261,6 +261,7 @@ private:virtual void set_has_focus(Web::PageId page_id, bool) override;virtual void set_focused_navigable(Web::PageId page_id, Web::HTML::CrossProcessId navigable_id) override;virtual void consume_user_activation(Web::PageId page_id, Web::HTML::UserActivationConsumption) override;+ virtual void notify_about_user_activation(Web::PageId page_id, Web::HTML::CrossProcessId document_id) override;virtual void set_is_scripting_enabled(Web::PageId page_id, bool) override;virtual void set_zoom_level(Web::PageId page_id, double zoom_level) override;virtual void set_maximum_frames_per_second(Web::PageId page_id, double) override;diff --git a/Services/WebContent/WebContentServer.ipc b/Services/WebContent/WebContentServer.ipcindex 34eb5c3223b..ef9237c35ba 100644--- a/Services/WebContent/WebContentServer.ipc+++ b/Services/WebContent/WebContentServer.ipc@@ -269,6 +269,7 @@ endpoint WebContentServer routed by Web::PageId page_idset_has_focus(Web::PageId page_id, bool has_focus) =|set_focused_navigable(Web::PageId page_id, Web::HTML::CrossProcessId navigable_id) =|consume_user_activation(Web::PageId page_id, Web::HTML::UserActivationConsumption consumption) =|+ notify_about_user_activation(Web::PageId page_id, Web::HTML::CrossProcessId document_id) =|set_is_scripting_enabled(Web::PageId page_id, bool is_scripting_enabled) =|set_zoom_level(Web::PageId page_id, double zoom_level) =|set_maximum_frames_per_second(Web::PageId page_id, double maximum_frames_per_second) =|