Quellcode durchsuchen

LibWeb+Browser: Remove Web::WebViewHooks class

This was a mixin class that allowed sharing a set of hooks between
InProcessWebView and OutOfProcessWebView. Now that there is only OOPWV,
we don't need the mixin.
Andreas Kling vor 3 Jahren
Ursprung
Commit
06d97c892b

+ 18 - 18
Userland/Applications/Browser/BrowserWindow.cpp

@@ -195,18 +195,18 @@ void BrowserWindow::build_menus()
 
     m_copy_selection_action = GUI::CommonActions::make_copy_action([this](auto&) {
         auto& tab = active_tab();
-        auto selected_text = tab.m_web_content_view->selected_text();
+        auto selected_text = tab.view().selected_text();
         if (!selected_text.is_empty())
             GUI::Clipboard::the().set_plain_text(selected_text);
     });
 
     m_select_all_action = GUI::CommonActions::make_select_all_action([this](auto&) {
-        active_tab().m_web_content_view->select_all();
+        active_tab().view().select_all();
     });
 
     m_view_source_action = GUI::Action::create(
         "View &Source", { Mod_Ctrl, Key_U }, g_icon_bag.code, [this](auto&) {
-            active_tab().m_web_content_view->get_source();
+            active_tab().view().get_source();
         },
         this);
     m_view_source_action->set_status_tip("View source code of the current page");
@@ -278,7 +278,7 @@ void BrowserWindow::build_menus()
             auto action = GUI::Action::create_checkable(
                 name, [=, this](auto&) {
                     Config::write_string("Browser", "Preferences", "ColorScheme", Web::CSS::preferred_color_scheme_to_string(preference_value));
-                    active_tab().m_web_content_view->set_preferred_color_scheme(preference_value);
+                    active_tab().view().set_preferred_color_scheme(preference_value);
                 },
                 this);
             if (current_setting == preference_value)
@@ -302,22 +302,22 @@ void BrowserWindow::build_menus()
     auto& debug_menu = add_menu("&Debug");
     debug_menu.add_action(GUI::Action::create(
         "Dump &DOM Tree", g_icon_bag.dom_tree, [this](auto&) {
-            active_tab().m_web_content_view->debug_request("dump-dom-tree");
+            active_tab().view().debug_request("dump-dom-tree");
         },
         this));
     debug_menu.add_action(GUI::Action::create(
         "Dump &Layout Tree", g_icon_bag.layout, [this](auto&) {
-            active_tab().m_web_content_view->debug_request("dump-layout-tree");
+            active_tab().view().debug_request("dump-layout-tree");
         },
         this));
     debug_menu.add_action(GUI::Action::create(
         "Dump S&tacking Context Tree", g_icon_bag.layers, [this](auto&) {
-            active_tab().m_web_content_view->debug_request("dump-stacking-context-tree");
+            active_tab().view().debug_request("dump-stacking-context-tree");
         },
         this));
     debug_menu.add_action(GUI::Action::create(
         "Dump &Style Sheets", g_icon_bag.filetype_css, [this](auto&) {
-            active_tab().m_web_content_view->debug_request("dump-style-sheets");
+            active_tab().view().debug_request("dump-style-sheets");
         },
         this));
     debug_menu.add_action(GUI::Action::create("Dump &History", { Mod_Ctrl, Key_H }, g_icon_bag.history, [this](auto&) {
@@ -329,12 +329,12 @@ void BrowserWindow::build_menus()
             tab.on_dump_cookies();
     }));
     debug_menu.add_action(GUI::Action::create("Dump Loc&al Storage", g_icon_bag.local_storage, [this](auto&) {
-        active_tab().m_web_content_view->debug_request("dump-local-storage");
+        active_tab().view().debug_request("dump-local-storage");
     }));
     debug_menu.add_separator();
     auto line_box_borders_action = GUI::Action::create_checkable(
         "Line &Box Borders", [this](auto& action) {
-            active_tab().m_web_content_view->debug_request("set-line-box-borders", action.is_checked() ? "on" : "off");
+            active_tab().view().debug_request("set-line-box-borders", action.is_checked() ? "on" : "off");
         },
         this);
     line_box_borders_action->set_checked(false);
@@ -342,16 +342,16 @@ void BrowserWindow::build_menus()
 
     debug_menu.add_separator();
     debug_menu.add_action(GUI::Action::create("Collect &Garbage", { Mod_Ctrl | Mod_Shift, Key_G }, g_icon_bag.trash_can, [this](auto&) {
-        active_tab().m_web_content_view->debug_request("collect-garbage");
+        active_tab().view().debug_request("collect-garbage");
     }));
     debug_menu.add_action(GUI::Action::create("Clear &Cache", { Mod_Ctrl | Mod_Shift, Key_C }, g_icon_bag.clear_cache, [this](auto&) {
-        active_tab().m_web_content_view->debug_request("clear-cache");
+        active_tab().view().debug_request("clear-cache");
     }));
 
     m_user_agent_spoof_actions.set_exclusive(true);
     auto& spoof_user_agent_menu = debug_menu.add_submenu("Spoof &User Agent");
     m_disable_user_agent_spoofing = GUI::Action::create_checkable("Disabled", [this](auto&) {
-        active_tab().m_web_content_view->debug_request("spoof-user-agent", Web::default_user_agent);
+        active_tab().view().debug_request("spoof-user-agent", Web::default_user_agent);
     });
     m_disable_user_agent_spoofing->set_status_tip(Web::default_user_agent);
     spoof_user_agent_menu.add_action(*m_disable_user_agent_spoofing);
@@ -361,7 +361,7 @@ void BrowserWindow::build_menus()
 
     auto add_user_agent = [this, &spoof_user_agent_menu](auto& name, auto& user_agent) {
         auto action = GUI::Action::create_checkable(name, [this, user_agent](auto&) {
-            active_tab().m_web_content_view->debug_request("spoof-user-agent", user_agent);
+            active_tab().view().debug_request("spoof-user-agent", user_agent);
         });
         action->set_status_tip(user_agent);
         spoof_user_agent_menu.add_action(action);
@@ -380,7 +380,7 @@ void BrowserWindow::build_menus()
             m_disable_user_agent_spoofing->activate();
             return;
         }
-        active_tab().m_web_content_view->debug_request("spoof-user-agent", user_agent);
+        active_tab().view().debug_request("spoof-user-agent", user_agent);
         action.set_status_tip(user_agent);
     });
     spoof_user_agent_menu.add_action(custom_user_agent);
@@ -389,7 +389,7 @@ void BrowserWindow::build_menus()
     debug_menu.add_separator();
     auto scripting_enabled_action = GUI::Action::create_checkable(
         "Enable Scripting", [this](auto& action) {
-            active_tab().m_web_content_view->debug_request("scripting", action.is_checked() ? "on" : "off");
+            active_tab().view().debug_request("scripting", action.is_checked() ? "on" : "off");
         },
         this);
     scripting_enabled_action->set_checked(true);
@@ -397,7 +397,7 @@ void BrowserWindow::build_menus()
 
     auto same_origin_policy_action = GUI::Action::create_checkable(
         "Enable Same Origin &Policy", [this](auto& action) {
-            active_tab().m_web_content_view->debug_request("same-origin-policy", action.is_checked() ? "on" : "off");
+            active_tab().view().debug_request("same-origin-policy", action.is_checked() ? "on" : "off");
         },
         this);
     same_origin_policy_action->set_checked(false);
@@ -556,7 +556,7 @@ void BrowserWindow::create_new_tab(URL url, bool activate)
     };
 
     new_tab.on_get_local_storage_entries = [this]() {
-        return active_tab().m_web_content_view->get_local_storage_entries();
+        return active_tab().view().get_local_storage_entries();
     };
 
     new_tab.load(url);

+ 24 - 34
Userland/Applications/Browser/Tab.cpp

@@ -189,7 +189,7 @@ Tab::Tab(BrowserWindow& window)
         },
         this);
 
-    hooks().on_load_start = [this](auto& url) {
+    view().on_load_start = [this](auto& url) {
         m_navigating_url = url;
         m_loaded = false;
 
@@ -213,7 +213,7 @@ Tab::Tab(BrowserWindow& window)
             m_console_widget->reset();
     };
 
-    hooks().on_load_finish = [this](auto&) {
+    view().on_load_finish = [this](auto&) {
         m_navigating_url = {};
         m_loaded = true;
 
@@ -223,7 +223,7 @@ Tab::Tab(BrowserWindow& window)
             m_web_content_view->inspect_dom_tree();
     };
 
-    hooks().on_link_click = [this](auto& url, auto& target, unsigned modifiers) {
+    view().on_link_click = [this](auto& url, auto& target, unsigned modifiers) {
         if (target == "_blank" || modifiers == Mod_Ctrl) {
             on_tab_open_request(url);
         } else {
@@ -231,18 +231,18 @@ Tab::Tab(BrowserWindow& window)
         }
     };
 
-    hooks().on_resource_status_change = [this](auto count_waiting) {
+    view().on_resource_status_change = [this](auto count_waiting) {
         update_status({}, count_waiting);
     };
 
     m_link_context_menu = GUI::Menu::construct();
     auto link_default_action = GUI::Action::create("&Open", [this](auto&) {
-        hooks().on_link_click(m_link_context_menu_url, "", 0);
+        view().on_link_click(m_link_context_menu_url, "", 0);
     });
     m_link_context_menu->add_action(link_default_action);
     m_link_context_menu_default_action = link_default_action;
     m_link_context_menu->add_action(GUI::Action::create("Open in New &Tab", [this](auto&) {
-        hooks().on_link_click(m_link_context_menu_url, "_blank", 0);
+        view().on_link_click(m_link_context_menu_url, "_blank", 0);
     }));
     m_link_context_menu->add_separator();
     m_link_context_menu->add_action(GUI::Action::create("&Copy URL", [this](auto&) {
@@ -255,17 +255,17 @@ Tab::Tab(BrowserWindow& window)
     m_link_context_menu->add_separator();
     m_link_context_menu->add_action(window.inspect_dom_node_action());
 
-    hooks().on_link_context_menu_request = [this](auto& url, auto& screen_position) {
+    view().on_link_context_menu_request = [this](auto& url, auto& screen_position) {
         m_link_context_menu_url = url;
         m_link_context_menu->popup(screen_position, m_link_context_menu_default_action);
     };
 
     m_image_context_menu = GUI::Menu::construct();
     m_image_context_menu->add_action(GUI::Action::create("&Open Image", [this](auto&) {
-        hooks().on_link_click(m_image_context_menu_url, "", 0);
+        view().on_link_click(m_image_context_menu_url, "", 0);
     }));
     m_image_context_menu->add_action(GUI::Action::create("Open Image in New &Tab", [this](auto&) {
-        hooks().on_link_click(m_image_context_menu_url, "_blank", 0);
+        view().on_link_click(m_image_context_menu_url, "_blank", 0);
     }));
     m_image_context_menu->add_separator();
     m_image_context_menu->add_action(GUI::Action::create("&Copy Image", [this](auto&) {
@@ -282,17 +282,17 @@ Tab::Tab(BrowserWindow& window)
     m_image_context_menu->add_separator();
     m_image_context_menu->add_action(window.inspect_dom_node_action());
 
-    hooks().on_image_context_menu_request = [this](auto& image_url, auto& screen_position, Gfx::ShareableBitmap const& shareable_bitmap) {
+    view().on_image_context_menu_request = [this](auto& image_url, auto& screen_position, Gfx::ShareableBitmap const& shareable_bitmap) {
         m_image_context_menu_url = image_url;
         m_image_context_menu_bitmap = shareable_bitmap;
         m_image_context_menu->popup(screen_position);
     };
 
-    hooks().on_link_middle_click = [this](auto& href, auto&, auto) {
-        hooks().on_link_click(href, "_blank", 0);
+    view().on_link_middle_click = [this](auto& href, auto&, auto) {
+        view().on_link_click(href, "_blank", 0);
     };
 
-    hooks().on_title_change = [this](auto& title) {
+    view().on_title_change = [this](auto& title) {
         if (title.is_null()) {
             m_history.update_title(url().to_string());
             m_title = url().to_string();
@@ -304,43 +304,43 @@ Tab::Tab(BrowserWindow& window)
             on_title_change(m_title);
     };
 
-    hooks().on_favicon_change = [this](auto& icon) {
+    view().on_favicon_change = [this](auto& icon) {
         m_icon = icon;
         m_location_box->set_icon(&icon);
         if (on_favicon_change)
             on_favicon_change(icon);
     };
 
-    hooks().on_get_cookie = [this](auto& url, auto source) -> String {
+    view().on_get_cookie = [this](auto& url, auto source) -> String {
         if (on_get_cookie)
             return on_get_cookie(url, source);
         return {};
     };
 
-    hooks().on_set_cookie = [this](auto& url, auto& cookie, auto source) {
+    view().on_set_cookie = [this](auto& url, auto& cookie, auto source) {
         if (on_set_cookie)
             on_set_cookie(url, cookie, source);
     };
 
-    hooks().on_get_source = [this](auto& url, auto& source) {
+    view().on_get_source = [this](auto& url, auto& source) {
         view_source(url, source);
     };
 
-    hooks().on_get_dom_tree = [this](auto& dom_tree) {
+    view().on_get_dom_tree = [this](auto& dom_tree) {
         if (m_dom_inspector_widget)
             m_dom_inspector_widget->set_dom_json(dom_tree);
     };
 
-    hooks().on_get_dom_node_properties = [this](auto node_id, auto& specified, auto& computed, auto& custom_properties, auto& node_box_sizing) {
+    view().on_get_dom_node_properties = [this](auto node_id, auto& specified, auto& computed, auto& custom_properties, auto& node_box_sizing) {
         m_dom_inspector_widget->set_dom_node_properties_json({ node_id }, specified, computed, custom_properties, node_box_sizing);
     };
 
-    hooks().on_js_console_new_message = [this](auto message_index) {
+    view().on_js_console_new_message = [this](auto message_index) {
         if (m_console_widget)
             m_console_widget->notify_about_new_console_message(message_index);
     };
 
-    hooks().on_get_js_console_messages = [this](auto start_index, auto& message_types, auto& messages) {
+    view().on_get_js_console_messages = [this](auto start_index, auto& message_types, auto& messages) {
         if (m_console_widget)
             m_console_widget->handle_console_messages(start_index, message_types, messages);
     };
@@ -354,14 +354,14 @@ Tab::Tab(BrowserWindow& window)
 
     m_statusbar = *find_descendant_of_type_named<GUI::Statusbar>("statusbar");
 
-    hooks().on_link_hover = [this](auto& url) {
+    view().on_link_hover = [this](auto& url) {
         if (url.is_valid())
             update_status(url.to_string());
         else
             update_status();
     };
 
-    hooks().on_url_drop = [this](auto& url) {
+    view().on_url_drop = [this](auto& url) {
         load(url);
     };
 
@@ -390,7 +390,7 @@ Tab::Tab(BrowserWindow& window)
     m_page_context_menu->add_action(window.view_source_action());
     m_page_context_menu->add_action(window.inspect_dom_tree_action());
     m_page_context_menu->add_action(window.inspect_dom_node_action());
-    hooks().on_context_menu_request = [&](auto& screen_position) {
+    view().on_context_menu_request = [&](auto& screen_position) {
         m_page_context_menu->popup(screen_position);
     };
 }
@@ -516,16 +516,6 @@ void Tab::content_filters_changed()
         m_web_content_view->set_content_filters({});
 }
 
-GUI::AbstractScrollableWidget& Tab::view()
-{
-    return *m_web_content_view;
-}
-
-Web::WebViewHooks& Tab::hooks()
-{
-    return *m_web_content_view;
-}
-
 void Tab::action_entered(GUI::Action& action)
 {
     m_statusbar->set_override_text(action.status_tip());

+ 1 - 3
Userland/Applications/Browser/Tab.h

@@ -18,7 +18,6 @@
 
 namespace Web {
 class OutOfProcessWebView;
-class WebViewHooks;
 }
 
 namespace Browser {
@@ -79,7 +78,7 @@ public:
     String const& title() const { return m_title; }
     Gfx::Bitmap const* icon() const { return m_icon; }
 
-    GUI::AbstractScrollableWidget& view();
+    Web::OutOfProcessWebView& view() { return *m_web_content_view; }
 
 private:
     explicit Tab(BrowserWindow&);
@@ -87,7 +86,6 @@ private:
     BrowserWindow const& window() const;
     BrowserWindow& window();
 
-    Web::WebViewHooks& hooks();
     void update_actions();
     void bookmark_current_url();
     void update_bookmark_button(String const& url);

+ 23 - 5
Userland/Libraries/LibWeb/OutOfProcessWebView.h

@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2020, Andreas Kling <kling@serenityos.org>
+ * Copyright (c) 2020-2022, Andreas Kling <kling@serenityos.org>
  *
  * SPDX-License-Identifier: BSD-2-Clause
  */
@@ -11,15 +11,12 @@
 #include <LibGUI/Widget.h>
 #include <LibWeb/CSS/Selector.h>
 #include <LibWeb/Page/Page.h>
-#include <LibWeb/WebViewHooks.h>
 
 namespace Web {
 
 class WebContentClient;
 
-class OutOfProcessWebView final
-    : public GUI::AbstractScrollableWidget
-    , public Web::WebViewHooks {
+class OutOfProcessWebView final : public GUI::AbstractScrollableWidget {
     C_OBJECT(OutOfProcessWebView);
 
 public:
@@ -60,6 +57,27 @@ public:
     void set_content_filters(Vector<String>);
     void set_preferred_color_scheme(Web::CSS::PreferredColorScheme);
 
+    Function<void(Gfx::IntPoint const& screen_position)> on_context_menu_request;
+    Function<void(const AK::URL&, String const& target, unsigned modifiers)> on_link_click;
+    Function<void(const AK::URL&, Gfx::IntPoint const& screen_position)> on_link_context_menu_request;
+    Function<void(const AK::URL&, Gfx::IntPoint const& screen_position, Gfx::ShareableBitmap const&)> on_image_context_menu_request;
+    Function<void(const AK::URL&, String const& target, unsigned modifiers)> on_link_middle_click;
+    Function<void(const AK::URL&)> on_link_hover;
+    Function<void(String const&)> on_title_change;
+    Function<void(const AK::URL&)> on_load_start;
+    Function<void(const AK::URL&)> on_load_finish;
+    Function<void(Gfx::Bitmap const&)> on_favicon_change;
+    Function<void(const AK::URL&)> on_url_drop;
+    Function<void(DOM::Document*)> on_set_document;
+    Function<void(const AK::URL&, String const&)> on_get_source;
+    Function<void(String const&)> on_get_dom_tree;
+    Function<void(i32 node_id, String const& specified_style, String const& computed_style, String const& custom_properties, String const& node_box_sizing)> on_get_dom_node_properties;
+    Function<void(i32 message_id)> on_js_console_new_message;
+    Function<void(i32 start_index, Vector<String> const& message_types, Vector<String> const& messages)> on_get_js_console_messages;
+    Function<String(const AK::URL& url, Cookie::Source source)> on_get_cookie;
+    Function<void(const AK::URL& url, Cookie::ParsedCookie const& cookie, Cookie::Source source)> on_set_cookie;
+    Function<void(i32 count_waiting)> on_resource_status_change;
+
     void notify_server_did_layout(Badge<WebContentClient>, Gfx::IntSize const& content_size);
     void notify_server_did_paint(Badge<WebContentClient>, i32 bitmap_id);
     void notify_server_did_invalidate_content_rect(Badge<WebContentClient>, Gfx::IntRect const&);

+ 0 - 40
Userland/Libraries/LibWeb/WebViewHooks.h

@@ -1,40 +0,0 @@
-/*
- * Copyright (c) 2020, Andreas Kling <kling@serenityos.org>
- *
- * SPDX-License-Identifier: BSD-2-Clause
- */
-
-#pragma once
-
-#include <AK/Function.h>
-#include <AK/URL.h>
-#include <LibGfx/Forward.h>
-#include <LibWeb/Forward.h>
-
-namespace Web {
-
-class WebViewHooks {
-public:
-    Function<void(Gfx::IntPoint const& screen_position)> on_context_menu_request;
-    Function<void(const AK::URL&, String const& target, unsigned modifiers)> on_link_click;
-    Function<void(const AK::URL&, Gfx::IntPoint const& screen_position)> on_link_context_menu_request;
-    Function<void(const AK::URL&, Gfx::IntPoint const& screen_position, Gfx::ShareableBitmap const&)> on_image_context_menu_request;
-    Function<void(const AK::URL&, String const& target, unsigned modifiers)> on_link_middle_click;
-    Function<void(const AK::URL&)> on_link_hover;
-    Function<void(String const&)> on_title_change;
-    Function<void(const AK::URL&)> on_load_start;
-    Function<void(const AK::URL&)> on_load_finish;
-    Function<void(Gfx::Bitmap const&)> on_favicon_change;
-    Function<void(const AK::URL&)> on_url_drop;
-    Function<void(DOM::Document*)> on_set_document;
-    Function<void(const AK::URL&, String const&)> on_get_source;
-    Function<void(String const&)> on_get_dom_tree;
-    Function<void(i32 node_id, String const& specified_style, String const& computed_style, String const& custom_properties, String const& node_box_sizing)> on_get_dom_node_properties;
-    Function<void(i32 message_id)> on_js_console_new_message;
-    Function<void(i32 start_index, Vector<String> const& message_types, Vector<String> const& messages)> on_get_js_console_messages;
-    Function<String(const AK::URL& url, Cookie::Source source)> on_get_cookie;
-    Function<void(const AK::URL& url, Cookie::ParsedCookie const& cookie, Cookie::Source source)> on_set_cookie;
-    Function<void(i32 count_waiting)> on_resource_status_change;
-};
-
-}