From ebe89a32073a1b838f2d1e04d2146f2dfae6b6f7 Mon Sep 17 00:00:00 2001 From: Timothy Flynn Date: Mon, 21 Oct 2024 12:39:53 -0400 Subject: [PATCH] WebContent: Parse the type hint in WebDriver's New Window endpoint Although we aren't using this hint (we always create tabs), we do need to validate the payload. --- Userland/Services/WebContent/WebDriverConnection.cpp | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/Userland/Services/WebContent/WebDriverConnection.cpp b/Userland/Services/WebContent/WebDriverConnection.cpp index 1109a6eeff0..ecfd6345186 100644 --- a/Userland/Services/WebContent/WebDriverConnection.cpp +++ b/Userland/Services/WebContent/WebDriverConnection.cpp @@ -465,7 +465,7 @@ Messages::WebDriverClient::SwitchToWindowResponse WebDriverConnection::switch_to } // 11.5 New Window, https://w3c.github.io/webdriver/#dfn-new-window -Messages::WebDriverClient::NewWindowResponse WebDriverConnection::new_window(JsonValue const&) +Messages::WebDriverClient::NewWindowResponse WebDriverConnection::new_window(JsonValue const& payload) { // 1. If the implementation does not support creating new top-level browsing contexts, return error with error code unsupported operation. @@ -475,7 +475,14 @@ Messages::WebDriverClient::NewWindowResponse WebDriverConnection::new_window(Jso // 3. Handle any user prompts and return its value if it is an error. TRY(handle_any_user_prompts()); - // FIXME: 4. Let type hint be the result of getting the property "type" from the parameters argument. + // 4. Let type hint be the result of getting the property "type" from the parameters argument. + if (!payload.is_object()) + return Web::WebDriver::Error::from_code(Web::WebDriver::ErrorCode::InvalidArgument, "Payload is not a JSON object"); + + // FIXME: Actually use this value to decide between an OS window or tab. + auto type_hint = payload.as_object().get("type"sv); + if (type_hint.has_value() && !type_hint->is_null() && !type_hint->is_string()) + return Web::WebDriver::Error::from_code(Web::WebDriver::ErrorCode::InvalidArgument, "Payload property `type` is not null or a string"sv); // 5. Create a new top-level browsing context by running the window open steps with url set to "about:blank", // target set to the empty string, and features set to "noopener" and the user agent configured to create a new