diff options
author | Andreas Kling <kling@serenityos.org> | 2021-09-27 11:39:17 +0200 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2021-09-27 11:40:56 +0200 |
commit | a79bdd2bd544c6111c1e5c2876af4875f613437b (patch) | |
tree | 27cf923ab66add87f2521e3ddcfaff722ba4a2ba | |
parent | b0858b2a55814291bf822007a3a0c5aea5455a56 (diff) | |
download | serenity-a79bdd2bd544c6111c1e5c2876af4875f613437b.zip |
LibWeb+Browser: Make ad blocking work in the multi-process world
We now send the list of content filters over to new WebContent processes
after creating an OutOfProcessWebView. :^)
-rw-r--r-- | Userland/Applications/Browser/Browser.h | 1 | ||||
-rw-r--r-- | Userland/Applications/Browser/Tab.cpp | 1 | ||||
-rw-r--r-- | Userland/Applications/Browser/main.cpp | 6 | ||||
-rw-r--r-- | Userland/Libraries/LibWeb/OutOfProcessWebView.cpp | 5 | ||||
-rw-r--r-- | Userland/Libraries/LibWeb/OutOfProcessWebView.h | 2 | ||||
-rw-r--r-- | Userland/Services/WebContent/ClientConnection.cpp | 7 | ||||
-rw-r--r-- | Userland/Services/WebContent/ClientConnection.h | 1 | ||||
-rw-r--r-- | Userland/Services/WebContent/WebContentServer.ipc | 3 |
8 files changed, 22 insertions, 4 deletions
diff --git a/Userland/Applications/Browser/Browser.h b/Userland/Applications/Browser/Browser.h index b3152d2881..fade37a00b 100644 --- a/Userland/Applications/Browser/Browser.h +++ b/Userland/Applications/Browser/Browser.h @@ -12,5 +12,6 @@ namespace Browser { extern String g_home_url; extern String g_search_engine; +extern Vector<String> g_content_filters; } diff --git a/Userland/Applications/Browser/Tab.cpp b/Userland/Applications/Browser/Tab.cpp index 651550f690..02d7733f9b 100644 --- a/Userland/Applications/Browser/Tab.cpp +++ b/Userland/Applications/Browser/Tab.cpp @@ -87,6 +87,7 @@ Tab::Tab(BrowserWindow& window) auto& webview_container = *find_descendant_of_type_named<GUI::Widget>("webview_container"); m_web_content_view = webview_container.add<Web::OutOfProcessWebView>(); + m_web_content_view->set_content_filters(g_content_filters); auto& go_back_button = toolbar.add_action(window.go_back_action()); go_back_button.on_context_menu_request = [this](auto& context_menu_event) { diff --git a/Userland/Applications/Browser/main.cpp b/Userland/Applications/Browser/main.cpp index 50cf2063fb..fe3ba22e72 100644 --- a/Userland/Applications/Browser/main.cpp +++ b/Userland/Applications/Browser/main.cpp @@ -19,9 +19,6 @@ #include <LibGUI/BoxLayout.h> #include <LibGUI/Icon.h> #include <LibGUI/TabWidget.h> -#include <LibWeb/HTML/WebSocket.h> -#include <LibWeb/Loader/ContentFilter.h> -#include <LibWeb/Loader/ResourceLoader.h> #include <stdio.h> #include <unistd.h> @@ -29,6 +26,7 @@ namespace Browser { String g_search_engine; String g_home_url; +Vector<String> g_content_filters; } @@ -107,7 +105,7 @@ int main(int argc, char** argv) auto line = ad_filter_list.read_line(); if (line.is_empty()) continue; - Web::ContentFilter::the().add_pattern(line); + Browser::g_content_filters.append(move(line)); } } diff --git a/Userland/Libraries/LibWeb/OutOfProcessWebView.cpp b/Userland/Libraries/LibWeb/OutOfProcessWebView.cpp index 4bf06133d5..28bd7dffce 100644 --- a/Userland/Libraries/LibWeb/OutOfProcessWebView.cpp +++ b/Userland/Libraries/LibWeb/OutOfProcessWebView.cpp @@ -472,4 +472,9 @@ String OutOfProcessWebView::dump_layout_tree() return client().dump_layout_tree(); } +void OutOfProcessWebView::set_content_filters(Vector<String> filters) +{ + client().async_set_content_filters(filters); +} + } diff --git a/Userland/Libraries/LibWeb/OutOfProcessWebView.h b/Userland/Libraries/LibWeb/OutOfProcessWebView.h index 9e70436725..b5e1bfeecd 100644 --- a/Userland/Libraries/LibWeb/OutOfProcessWebView.h +++ b/Userland/Libraries/LibWeb/OutOfProcessWebView.h @@ -51,6 +51,8 @@ public: String dump_layout_tree(); + void set_content_filters(Vector<String>); + void notify_server_did_layout(Badge<WebContentClient>, const Gfx::IntSize& content_size); void notify_server_did_paint(Badge<WebContentClient>, i32 bitmap_id); void notify_server_did_invalidate_content_rect(Badge<WebContentClient>, const Gfx::IntRect&); diff --git a/Userland/Services/WebContent/ClientConnection.cpp b/Userland/Services/WebContent/ClientConnection.cpp index e3c48c5d01..0032be4353 100644 --- a/Userland/Services/WebContent/ClientConnection.cpp +++ b/Userland/Services/WebContent/ClientConnection.cpp @@ -19,6 +19,7 @@ #include <LibWeb/DOM/Document.h> #include <LibWeb/Dump.h> #include <LibWeb/Layout/InitialContainingBlock.h> +#include <LibWeb/Loader/ContentFilter.h> #include <LibWeb/Loader/ResourceLoader.h> #include <LibWeb/Page/BrowsingContext.h> #include <WebContent/ClientConnection.h> @@ -338,4 +339,10 @@ Messages::WebContentServer::DumpLayoutTreeResponse ClientConnection::dump_layout return builder.to_string(); } +void ClientConnection::set_content_filters(Vector<String> const& filters) +{ + for (auto& filter : filters) + Web::ContentFilter::the().add_pattern(filter); +} + } diff --git a/Userland/Services/WebContent/ClientConnection.h b/Userland/Services/WebContent/ClientConnection.h index 7a0f116c88..79fe50f866 100644 --- a/Userland/Services/WebContent/ClientConnection.h +++ b/Userland/Services/WebContent/ClientConnection.h @@ -55,6 +55,7 @@ private: virtual Messages::WebContentServer::InspectDomNodeResponse inspect_dom_node(i32) override; virtual Messages::WebContentServer::GetHoveredNodeIdResponse get_hovered_node_id() override; virtual Messages::WebContentServer::DumpLayoutTreeResponse dump_layout_tree() override; + virtual void set_content_filters(Vector<String> const&) override; virtual void js_console_input(String const&) override; virtual void run_javascript(String const&) override; diff --git a/Userland/Services/WebContent/WebContentServer.ipc b/Userland/Services/WebContent/WebContentServer.ipc index a8307c784f..a79859d381 100644 --- a/Userland/Services/WebContent/WebContentServer.ipc +++ b/Userland/Services/WebContent/WebContentServer.ipc @@ -38,4 +38,7 @@ endpoint WebContentServer get_selected_text() => (String selection) select_all() =| + + set_content_filters(Vector<String> filters) =| + } |