Selaa lähdekoodia

LibWeb+WebContent: Add plumbing for 'webdriver-active flag'

Linus Groh 2 vuotta sitten
vanhempi
commit
3f24a444f9

+ 8 - 0
Userland/Libraries/LibWeb/Page/Page.h

@@ -1,5 +1,6 @@
 /*
  * Copyright (c) 2020-2021, Andreas Kling <kling@serenityos.org>
+ * Copyright (c) 2021-2022, Linus Groh <linusg@serenityos.org>
  *
  * SPDX-License-Identifier: BSD-2-Clause
  */
@@ -67,6 +68,9 @@ public:
     bool is_scripting_enabled() const { return m_is_scripting_enabled; }
     void set_is_scripting_enabled(bool b) { m_is_scripting_enabled = b; }
 
+    bool is_webdriver_active() const { return m_is_webdriver_active; }
+    void set_is_webdriver_active(bool b) { m_is_webdriver_active = b; }
+
 private:
     PageClient& m_client;
 
@@ -77,6 +81,10 @@ private:
     bool m_same_origin_policy_enabled { false };
 
     bool m_is_scripting_enabled { true };
+
+    // https://w3c.github.io/webdriver/#dfn-webdriver-active-flag
+    // The webdriver-active flag is set to true when the user agent is under remote control. It is initially false.
+    bool m_is_webdriver_active { false };
 };
 
 class PageClient {

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

@@ -530,6 +530,11 @@ void OutOfProcessWebView::set_preferred_color_scheme(Web::CSS::PreferredColorSch
     client().async_set_preferred_color_scheme(color_scheme);
 }
 
+void OutOfProcessWebView::set_is_webdriver_active(bool is_webdriver_enabled)
+{
+    client().async_set_is_webdriver_active(is_webdriver_enabled);
+}
+
 void OutOfProcessWebView::focusin_event(GUI::FocusEvent&)
 {
     client().async_set_has_focus(true);

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

@@ -61,6 +61,7 @@ public:
     void set_content_filters(Vector<String>);
     void set_proxy_mappings(Vector<String> proxies, HashMap<String, size_t> mappings);
     void set_preferred_color_scheme(Web::CSS::PreferredColorScheme);
+    void set_is_webdriver_active(bool);
 
     Function<void(Gfx::IntPoint const& screen_position)> on_context_menu_request;
     Function<void(const AK::URL&, String const& target, unsigned modifiers)> on_link_click;

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

@@ -1,6 +1,7 @@
 /*
  * Copyright (c) 2020-2022, Andreas Kling <kling@serenityos.org>
  * Copyright (c) 2021, Sam Atkins <atkinssj@serenityos.org>
+ * Copyright (c) 2021-2022, Linus Groh <linusg@serenityos.org>
  *
  * SPDX-License-Identifier: BSD-2-Clause
  */
@@ -498,6 +499,11 @@ void ConnectionFromClient::set_is_scripting_enabled(bool is_scripting_enabled)
     m_page_host->set_is_scripting_enabled(is_scripting_enabled);
 }
 
+void ConnectionFromClient::set_is_webdriver_active(bool is_webdriver_active)
+{
+    m_page_host->set_is_webdriver_active(is_webdriver_active);
+}
+
 Messages::WebContentServer::GetLocalStorageEntriesResponse ConnectionFromClient::get_local_storage_entries()
 {
     auto* document = page().top_level_browsing_context().active_document();

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

@@ -1,5 +1,6 @@
 /*
  * Copyright (c) 2018-2021, Andreas Kling <kling@serenityos.org>
+ * Copyright (c) 2021-2022, Linus Groh <linusg@serenityos.org>
  *
  * SPDX-License-Identifier: BSD-2-Clause
  */
@@ -70,6 +71,7 @@ private:
     virtual void set_preferred_color_scheme(Web::CSS::PreferredColorScheme const&) override;
     virtual void set_has_focus(bool) override;
     virtual void set_is_scripting_enabled(bool) override;
+    virtual void set_is_webdriver_active(bool) override;
     virtual void handle_file_return(i32 error, Optional<IPC::File> const& file, i32 request_id) override;
     virtual void set_system_visibility_state(bool visible) override;
 

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

@@ -1,5 +1,6 @@
 /*
  * Copyright (c) 2020-2021, Andreas Kling <kling@serenityos.org>
+ * Copyright (c) 2021-2022, Linus Groh <linusg@serenityos.org>
  *
  * SPDX-License-Identifier: BSD-2-Clause
  */
@@ -70,6 +71,11 @@ void PageHost::set_is_scripting_enabled(bool is_scripting_enabled)
     page().set_is_scripting_enabled(is_scripting_enabled);
 }
 
+void PageHost::set_is_webdriver_active(bool is_webdriver_active)
+{
+    page().set_is_webdriver_active(is_webdriver_active);
+}
+
 Web::Layout::InitialContainingBlock* PageHost::layout_root()
 {
     auto* document = page().top_level_browsing_context().active_document();

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

@@ -1,5 +1,6 @@
 /*
  * Copyright (c) 2020-2021, Andreas Kling <kling@serenityos.org>
+ * Copyright (c) 2021-2022, Linus Groh <linusg@serenityos.org>
  *
  * SPDX-License-Identifier: BSD-2-Clause
  */
@@ -30,10 +31,10 @@ public:
     void set_viewport_rect(Gfx::IntRect const&);
     void set_screen_rects(Vector<Gfx::IntRect, 4> const& rects, size_t main_screen_index) { m_screen_rect = rects[main_screen_index]; };
     void set_preferred_color_scheme(Web::CSS::PreferredColorScheme);
-
     void set_should_show_line_box_borders(bool b) { m_should_show_line_box_borders = b; }
     void set_has_focus(bool);
     void set_is_scripting_enabled(bool);
+    void set_is_webdriver_active(bool);
 
 private:
     // ^PageClient

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

@@ -49,6 +49,7 @@ endpoint WebContentServer
     set_preferred_color_scheme(Web::CSS::PreferredColorScheme color_scheme) =|
     set_has_focus(bool has_focus) =|
     set_is_scripting_enabled(bool is_scripting_enabled) =|
+    set_is_webdriver_active(bool is_webdriver_active) =|
 
     get_local_storage_entries() => (OrderedHashMap<String,String> entries)
     get_session_storage_entries() => (OrderedHashMap<String,String> entries)