Browse Source

WebContent+LibWebView: Add support for user style sheets

Sam Atkins 1 năm trước cách đây
mục cha
commit
ec340f03a5

+ 5 - 0
Userland/Libraries/LibWebView/OutOfProcessWebView.cpp

@@ -516,4 +516,9 @@ void OutOfProcessWebView::set_content_scales_to_viewport(bool b)
     m_content_scales_to_viewport = b;
 }
 
+void OutOfProcessWebView::set_user_style_sheet(String source)
+{
+    client().async_set_user_style(source);
+}
+
 }

+ 2 - 0
Userland/Libraries/LibWebView/OutOfProcessWebView.h

@@ -54,6 +54,8 @@ public:
     // In practice, this means that OOPWV may render scaled stale versions of the content while resizing.
     void set_content_scales_to_viewport(bool);
 
+    void set_user_style_sheet(String source);
+
 private:
     OutOfProcessWebView();
 

+ 6 - 1
Userland/Services/WebContent/ConnectionFromClient.cpp

@@ -1,6 +1,6 @@
 /*
  * Copyright (c) 2020-2023, Andreas Kling <kling@serenityos.org>
- * Copyright (c) 2021, Sam Atkins <atkinssj@serenityos.org>
+ * Copyright (c) 2021-2023, Sam Atkins <atkinssj@serenityos.org>
  * Copyright (c) 2021-2023, Linus Groh <linusg@serenityos.org>
  * Copyright (c) 2022, Tobias Christiansen <tobyase@serenityos.org>
  * Copyright (c) 2022, Tim Flynn <trflynn89@serenityos.org>
@@ -859,6 +859,11 @@ void ConnectionFromClient::toggle_media_controls_state()
     m_page_host->toggle_media_controls_state().release_value_but_fixme_should_propagate_errors();
 }
 
+void ConnectionFromClient::set_user_style(String const& source)
+{
+    m_page_host->set_user_style(source);
+}
+
 void ConnectionFromClient::inspect_accessibility_tree()
 {
     if (auto* doc = page().top_level_browsing_context().active_document()) {

+ 2 - 0
Userland/Services/WebContent/ConnectionFromClient.h

@@ -102,6 +102,8 @@ private:
     virtual void toggle_media_loop_state() override;
     virtual void toggle_media_controls_state() override;
 
+    virtual void set_user_style(String const&) override;
+
     virtual Messages::WebContentServer::TakeDocumentScreenshotResponse take_document_screenshot() override;
 
     virtual Messages::WebContentServer::GetLocalStorageEntriesResponse get_local_storage_entries() override;

+ 5 - 0
Userland/Services/WebContent/PageHost.cpp

@@ -366,6 +366,11 @@ Web::WebIDL::ExceptionOr<void> PageHost::toggle_media_controls_state()
     return page().toggle_media_controls_state();
 }
 
+void PageHost::set_user_style(String source)
+{
+    page().set_user_style(source);
+}
+
 void PageHost::page_did_request_accept_dialog()
 {
     m_client.async_did_request_accept_dialog();

+ 2 - 0
Userland/Services/WebContent/PageHost.h

@@ -56,6 +56,8 @@ public:
 
     [[nodiscard]] Gfx::Color background_color() const;
 
+    void set_user_style(String source);
+
 private:
     // ^PageClient
     virtual bool is_connection_open() const override;

+ 2 - 0
Userland/Services/WebContent/WebContentServer.ipc

@@ -83,4 +83,6 @@ endpoint WebContentServer
     toggle_media_mute_state() =|
     toggle_media_loop_state() =|
     toggle_media_controls_state() =|
+
+    set_user_style(String source) =|
 }