mirror of
https://github.com/servo/servo.git
synced 2025-08-06 14:10:11 +01:00
libservo: Move WebDriver messages to the embedder
crate (#35602)
This is the first step toward moving the WebDriver implementation to servoshell. This move will make it possible to start testing the embedding API with WebDriver. See [this zulip thread][a] for more details. While WebDriver will be able to use a lot of API commands to do what it is doing now, there will still need to be some "cheat codes" for more gnarly access to `ScriptThread` details. That's why we likely won't be able to remove all WebDriver-specific messages from the API -- but maybe they will be useful for embedders somehow. A couple messages have to change as they depended on `script_traits` types, particularly those that used `WindowSizeData` and `LoadData`. I think this helps to encapsulate the WebDriver commands a bit more though. [a]: https://servo.zulipchat.com/#narrow/channel/437943-embedding/topic/webdriver.20as.20embedding.20api.20playgound Signed-off-by: Martin Robinson <mrobinson@igalia.com>
This commit is contained in:
parent
41c2422a66
commit
6062995636
12 changed files with 125 additions and 124 deletions
|
@ -17,6 +17,7 @@ webxr = ["dep:webxr-api"]
|
|||
[dependencies]
|
||||
base = { workspace = true }
|
||||
cfg-if = { workspace = true }
|
||||
cookie = { workspace = true }
|
||||
crossbeam-channel = { workspace = true }
|
||||
euclid = { workspace = true }
|
||||
http = { workspace = true }
|
||||
|
@ -28,8 +29,11 @@ num-derive = "0.4"
|
|||
malloc_size_of = { workspace = true }
|
||||
malloc_size_of_derive = { workspace = true }
|
||||
num-traits = { workspace = true }
|
||||
pixels = { path = "../../pixels" }
|
||||
serde = { workspace = true }
|
||||
servo_url = { path = "../../url" }
|
||||
style_traits = { workspace = true }
|
||||
url = { workspace = true }
|
||||
webdriver = { workspace = true }
|
||||
webrender_api = { workspace = true }
|
||||
webxr-api = { workspace = true, features = ["ipc"], optional = true }
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
|
||||
pub mod input_events;
|
||||
pub mod resources;
|
||||
mod webdriver;
|
||||
|
||||
use std::fmt::{Debug, Error, Formatter};
|
||||
use std::path::PathBuf;
|
||||
|
@ -22,6 +23,7 @@ use url::Url;
|
|||
use webrender_api::units::{DeviceIntPoint, DeviceIntRect, DeviceIntSize};
|
||||
|
||||
pub use crate::input_events::*;
|
||||
pub use crate::webdriver::*;
|
||||
|
||||
/// Tracks whether Servo isn't shutting down, is in the process of shutting down,
|
||||
/// or has finished shutting down.
|
||||
|
|
191
components/shared/embedder/webdriver.rs
Normal file
191
components/shared/embedder/webdriver.rs
Normal file
|
@ -0,0 +1,191 @@
|
|||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
|
||||
|
||||
#![allow(missing_docs)]
|
||||
|
||||
use std::collections::HashMap;
|
||||
|
||||
use base::id::{BrowsingContextId, WebViewId};
|
||||
use cookie::Cookie;
|
||||
use euclid::default::Rect as UntypedRect;
|
||||
use euclid::{Rect, Size2D};
|
||||
use hyper_serde::Serde;
|
||||
use ipc_channel::ipc::IpcSender;
|
||||
use keyboard_types::webdriver::Event as WebDriverInputEvent;
|
||||
use keyboard_types::KeyboardEvent;
|
||||
use pixels::Image;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use servo_url::ServoUrl;
|
||||
use style_traits::CSSPixel;
|
||||
use webdriver::common::{WebElement, WebFrame, WebWindow};
|
||||
use webdriver::error::ErrorStatus;
|
||||
use webrender_api::units::DeviceIntSize;
|
||||
|
||||
use crate::{MouseButton, MouseButtonAction};
|
||||
|
||||
/// Messages to the constellation originating from the WebDriver server.
|
||||
#[derive(Debug, Deserialize, Serialize)]
|
||||
pub enum WebDriverCommandMsg {
|
||||
/// Get the window size.
|
||||
GetWindowSize(WebViewId, IpcSender<Size2D<f32, CSSPixel>>),
|
||||
/// Load a URL in the top-level browsing context with the given ID.
|
||||
LoadUrl(WebViewId, ServoUrl, IpcSender<WebDriverLoadStatus>),
|
||||
/// Refresh the top-level browsing context with the given ID.
|
||||
Refresh(WebViewId, IpcSender<WebDriverLoadStatus>),
|
||||
/// Pass a webdriver command to the script thread of the current pipeline
|
||||
/// of a browsing context.
|
||||
ScriptCommand(BrowsingContextId, WebDriverScriptCommand),
|
||||
/// Act as if keys were pressed in the browsing context with the given ID.
|
||||
SendKeys(BrowsingContextId, Vec<WebDriverInputEvent>),
|
||||
/// Act as if keys were pressed or release in the browsing context with the given ID.
|
||||
KeyboardAction(BrowsingContextId, KeyboardEvent),
|
||||
/// Act as if the mouse was clicked in the browsing context with the given ID.
|
||||
MouseButtonAction(MouseButtonAction, MouseButton, f32, f32),
|
||||
/// Act as if the mouse was moved in the browsing context with the given ID.
|
||||
MouseMoveAction(f32, f32),
|
||||
/// Set the window size.
|
||||
SetWindowSize(WebViewId, DeviceIntSize, IpcSender<Size2D<f32, CSSPixel>>),
|
||||
/// Take a screenshot of the window.
|
||||
TakeScreenshot(
|
||||
WebViewId,
|
||||
Option<Rect<f32, CSSPixel>>,
|
||||
IpcSender<Option<Image>>,
|
||||
),
|
||||
/// Create a new webview that loads about:blank. The constellation will use
|
||||
/// the provided channels to return the top level browsing context id
|
||||
/// associated with the new webview, and a notification when the initial
|
||||
/// load is complete.
|
||||
NewWebView(
|
||||
WebViewId,
|
||||
IpcSender<WebViewId>,
|
||||
IpcSender<WebDriverLoadStatus>,
|
||||
),
|
||||
/// Close the webview associated with the provided id.
|
||||
CloseWebView(WebViewId),
|
||||
/// Focus the webview associated with the provided id.
|
||||
FocusWebView(WebViewId),
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize, Serialize)]
|
||||
pub enum WebDriverScriptCommand {
|
||||
AddCookie(
|
||||
#[serde(
|
||||
deserialize_with = "::hyper_serde::deserialize",
|
||||
serialize_with = "::hyper_serde::serialize"
|
||||
)]
|
||||
Cookie<'static>,
|
||||
IpcSender<Result<(), WebDriverCookieError>>,
|
||||
),
|
||||
DeleteCookies(IpcSender<Result<(), ErrorStatus>>),
|
||||
ExecuteScript(String, IpcSender<WebDriverJSResult>),
|
||||
ExecuteAsyncScript(String, IpcSender<WebDriverJSResult>),
|
||||
FindElementCSS(String, IpcSender<Result<Option<String>, ErrorStatus>>),
|
||||
FindElementLinkText(String, bool, IpcSender<Result<Option<String>, ErrorStatus>>),
|
||||
FindElementTagName(String, IpcSender<Result<Option<String>, ErrorStatus>>),
|
||||
FindElementsCSS(String, IpcSender<Result<Vec<String>, ErrorStatus>>),
|
||||
FindElementsLinkText(String, bool, IpcSender<Result<Vec<String>, ErrorStatus>>),
|
||||
FindElementsTagName(String, IpcSender<Result<Vec<String>, ErrorStatus>>),
|
||||
FindElementElementCSS(
|
||||
String,
|
||||
String,
|
||||
IpcSender<Result<Option<String>, ErrorStatus>>,
|
||||
),
|
||||
FindElementElementLinkText(
|
||||
String,
|
||||
String,
|
||||
bool,
|
||||
IpcSender<Result<Option<String>, ErrorStatus>>,
|
||||
),
|
||||
FindElementElementTagName(
|
||||
String,
|
||||
String,
|
||||
IpcSender<Result<Option<String>, ErrorStatus>>,
|
||||
),
|
||||
FindElementElementsCSS(String, String, IpcSender<Result<Vec<String>, ErrorStatus>>),
|
||||
FindElementElementsLinkText(
|
||||
String,
|
||||
String,
|
||||
bool,
|
||||
IpcSender<Result<Vec<String>, ErrorStatus>>,
|
||||
),
|
||||
FindElementElementsTagName(String, String, IpcSender<Result<Vec<String>, ErrorStatus>>),
|
||||
FocusElement(String, IpcSender<Result<(), ErrorStatus>>),
|
||||
ElementClick(String, IpcSender<Result<Option<String>, ErrorStatus>>),
|
||||
GetActiveElement(IpcSender<Option<String>>),
|
||||
GetCookie(String, IpcSender<Vec<Serde<Cookie<'static>>>>),
|
||||
GetCookies(IpcSender<Vec<Serde<Cookie<'static>>>>),
|
||||
GetElementAttribute(
|
||||
String,
|
||||
String,
|
||||
IpcSender<Result<Option<String>, ErrorStatus>>,
|
||||
),
|
||||
GetElementProperty(
|
||||
String,
|
||||
String,
|
||||
IpcSender<Result<WebDriverJSValue, ErrorStatus>>,
|
||||
),
|
||||
GetElementCSS(String, String, IpcSender<Result<String, ErrorStatus>>),
|
||||
GetElementRect(String, IpcSender<Result<UntypedRect<f64>, ErrorStatus>>),
|
||||
GetElementTagName(String, IpcSender<Result<String, ErrorStatus>>),
|
||||
GetElementText(String, IpcSender<Result<String, ErrorStatus>>),
|
||||
GetElementInViewCenterPoint(String, IpcSender<Result<Option<(i64, i64)>, ErrorStatus>>),
|
||||
GetBoundingClientRect(String, IpcSender<Result<UntypedRect<f32>, ErrorStatus>>),
|
||||
GetBrowsingContextId(
|
||||
WebDriverFrameId,
|
||||
IpcSender<Result<BrowsingContextId, ErrorStatus>>,
|
||||
),
|
||||
GetUrl(IpcSender<ServoUrl>),
|
||||
GetPageSource(IpcSender<Result<String, ErrorStatus>>),
|
||||
IsEnabled(String, IpcSender<Result<bool, ErrorStatus>>),
|
||||
IsSelected(String, IpcSender<Result<bool, ErrorStatus>>),
|
||||
GetTitle(IpcSender<String>),
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize, Serialize)]
|
||||
pub enum WebDriverCookieError {
|
||||
InvalidDomain,
|
||||
UnableToSetCookie,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Deserialize, Serialize)]
|
||||
pub enum WebDriverJSValue {
|
||||
Undefined,
|
||||
Null,
|
||||
Boolean(bool),
|
||||
Int(i32),
|
||||
Number(f64),
|
||||
String(String),
|
||||
Element(WebElement),
|
||||
Frame(WebFrame),
|
||||
Window(WebWindow),
|
||||
ArrayLike(Vec<WebDriverJSValue>),
|
||||
Object(HashMap<String, WebDriverJSValue>),
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize, Serialize)]
|
||||
pub enum WebDriverJSError {
|
||||
/// Occurs when handler received an event message for a layout channel that is not
|
||||
/// associated with the current script thread
|
||||
BrowsingContextNotFound,
|
||||
JSError,
|
||||
StaleElementReference,
|
||||
Timeout,
|
||||
UnknownType,
|
||||
}
|
||||
|
||||
pub type WebDriverJSResult = Result<WebDriverJSValue, WebDriverJSError>;
|
||||
|
||||
#[derive(Debug, Deserialize, Serialize)]
|
||||
pub enum WebDriverFrameId {
|
||||
Short(u16),
|
||||
Element(String),
|
||||
Parent,
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize, Serialize)]
|
||||
pub enum WebDriverLoadStatus {
|
||||
Complete,
|
||||
Timeout,
|
||||
Canceled,
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue