Sfoglia il codice sorgente

WebContent+WebDriver: Move the Get Current URL command to WebContent

Timothy Flynn 2 anni fa
parent
commit
3ba6b5a7cb

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

@@ -3,4 +3,5 @@
 endpoint WebDriverClient {
     set_is_webdriver_active(bool active) =|
     navigate_to(JsonValue payload) => (Web::WebDriver::Response response)
+    get_current_url() => (Web::WebDriver::Response response)
 }

+ 18 - 0
Userland/Services/WebContent/WebDriverConnection.cpp

@@ -11,6 +11,7 @@
 #include <AK/JsonObject.h>
 #include <AK/JsonValue.h>
 #include <AK/Vector.h>
+#include <LibWeb/DOM/Document.h>
 #include <LibWeb/HTML/BrowsingContext.h>
 #include <LibWeb/Page/Page.h>
 #include <LibWeb/Platform/Timer.h>
@@ -86,6 +87,23 @@ Messages::WebDriverClient::NavigateToResponse WebDriverConnection::navigate_to(J
     return { make_success_response({}) };
 }
 
+// 10.2 Get Current URL, https://w3c.github.io/webdriver/#get-current-url
+Messages::WebDriverClient::GetCurrentUrlResponse WebDriverConnection::get_current_url()
+{
+    dbgln_if(WEBDRIVER_DEBUG, "WebDriverConnection::get_current_url");
+
+    // 1. If the current top-level browsing context is no longer open, return error with error code no such window.
+    DRIVER_TRY(ensure_open_top_level_browsing_context());
+
+    // FIXME: 2. Handle any user prompts and return its value if it is an error.
+
+    // 3. Let url be the serialization of the current top-level browsing context’s active document’s document URL.
+    auto url = m_page_host.page().top_level_browsing_context().active_document()->url().to_string();
+
+    // 4. Return success with data url.
+    return { make_success_response(url) };
+}
+
 // https://w3c.github.io/webdriver/#dfn-no-longer-open
 ErrorOr<void, Web::WebDriver::Error> WebDriverConnection::ensure_open_top_level_browsing_context()
 {

+ 1 - 0
Userland/Services/WebContent/WebDriverConnection.h

@@ -30,6 +30,7 @@ private:
     virtual void die() override { }
     virtual void set_is_webdriver_active(bool) override;
     virtual Messages::WebDriverClient::NavigateToResponse navigate_to(JsonValue const& payload) override;
+    virtual Messages::WebDriverClient::GetCurrentUrlResponse get_current_url() override;
 
     ErrorOr<void, Web::WebDriver::Error> ensure_open_top_level_browsing_context();
 

+ 1 - 2
Userland/Services/WebDriver/Client.cpp

@@ -491,8 +491,7 @@ Web::WebDriver::Response Client::handle_get_current_url(Vector<StringView> const
 {
     dbgln_if(WEBDRIVER_DEBUG, "Handling GET /session/<session_id>/url");
     auto* session = TRY(find_session_with_id(parameters[0]));
-    auto result = TRY(session->get_current_url());
-    return make_json_value(result);
+    return session->web_content_connection().get_current_url();
 }
 
 // 10.3 Back, https://w3c.github.io/webdriver/#dfn-back

+ 0 - 15
Userland/Services/WebDriver/Session.cpp

@@ -165,21 +165,6 @@ Web::WebDriver::Response Session::set_timeouts(JsonValue const& payload)
     return JsonValue {};
 }
 
-// 10.2 Get Current URL, https://w3c.github.io/webdriver/#dfn-get-current-url
-Web::WebDriver::Response Session::get_current_url()
-{
-    // 1. If the current top-level browsing context is no longer open, return error with error code no such window.
-    TRY(check_for_open_top_level_browsing_context_or_return_error());
-
-    // FIXME: 2. Handle any user prompts and return its value if it is an error.
-
-    // 3. Let url be the serialization of the current top-level browsing context’s active document’s document URL.
-    auto url = m_browser_connection->get_url().to_string();
-
-    // 4. Return success with data url.
-    return JsonValue(url);
-}
-
 // 10.3 Back, https://w3c.github.io/webdriver/#dfn-back
 Web::WebDriver::Response Session::back()
 {

+ 0 - 1
Userland/Services/WebDriver/Session.h

@@ -51,7 +51,6 @@ public:
     ErrorOr<void> stop();
     JsonObject get_timeouts();
     Web::WebDriver::Response set_timeouts(JsonValue const& payload);
-    Web::WebDriver::Response get_current_url();
     Web::WebDriver::Response back();
     Web::WebDriver::Response forward();
     Web::WebDriver::Response refresh();