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:
Martin Robinson 2025-02-24 14:57:28 +01:00 committed by GitHub
parent 41c2422a66
commit 6062995636
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
12 changed files with 125 additions and 124 deletions

View file

@ -22,7 +22,11 @@ use capabilities::ServoCapabilities;
use compositing_traits::ConstellationMsg;
use cookie::{CookieBuilder, Expiration};
use crossbeam_channel::{after, select, unbounded, Receiver, Sender};
use embedder_traits::TraversalDirection;
use embedder_traits::{
TraversalDirection, WebDriverCommandMsg, WebDriverCookieError, WebDriverFrameId,
WebDriverJSError, WebDriverJSResult, WebDriverJSValue, WebDriverLoadStatus,
WebDriverScriptCommand,
};
use euclid::{Rect, Size2D};
use http::method::Method;
use image::{DynamicImage, ImageFormat, RgbaImage};
@ -30,14 +34,7 @@ use ipc_channel::ipc::{self, IpcSender};
use ipc_channel::router::ROUTER;
use keyboard_types::webdriver::send_keys;
use log::{debug, info};
use net_traits::request::Referrer;
use net_traits::ReferrerPolicy;
use pixels::PixelFormat;
use script_traits::webdriver_msg::{
LoadStatus, WebDriverCookieError, WebDriverFrameId, WebDriverJSError, WebDriverJSResult,
WebDriverJSValue, WebDriverScriptCommand,
};
use script_traits::{LoadData, LoadOrigin, WebDriverCommandMsg};
use serde::de::{Deserializer, MapAccess, Visitor};
use serde::ser::Serializer;
use serde::{Deserialize, Serialize};
@ -189,11 +186,11 @@ struct Handler {
/// The threaded receiver on which we can block for a load-status.
/// It will receive messages sent on the load_status_sender,
/// and forwarded by the IPC router.
load_status_receiver: Receiver<LoadStatus>,
load_status_receiver: Receiver<WebDriverLoadStatus>,
/// The IPC sender which we can clone and pass along to the constellation,
/// for it to send us a load-status. Messages sent on it
/// will be forwarded to the load_status_receiver.
load_status_sender: IpcSender<LoadStatus>,
load_status_sender: IpcSender<WebDriverLoadStatus>,
session: Option<WebDriverSession>,
constellation_chan: Sender<ConstellationMsg>,
resize_timeout: u32,
@ -662,18 +659,9 @@ impl Handler {
let top_level_browsing_context_id = self.session()?.top_level_browsing_context_id;
let load_data = LoadData::new(
LoadOrigin::WebDriver,
url,
None,
Referrer::NoReferrer,
ReferrerPolicy::EmptyString,
None,
None,
);
let cmd_msg = WebDriverCommandMsg::LoadUrl(
top_level_browsing_context_id,
load_data,
url,
self.load_status_sender.clone(),
);
self.constellation_chan
@ -717,12 +705,11 @@ impl Handler {
.unwrap();
let window_size = receiver.recv().unwrap();
let vp = window_size.initial_viewport;
let window_size_response = WindowRectResponse {
x: 0,
y: 0,
width: vp.width as i32,
height: vp.height as i32,
width: window_size.width as i32,
height: window_size.height as i32,
};
Ok(WebDriverResponse::WindowRect(window_size_response))
}
@ -766,12 +753,11 @@ impl Handler {
});
let window_size = receiver.recv().unwrap();
let vp = window_size.initial_viewport;
let window_size_response = WindowRectResponse {
x: 0,
y: 0,
width: vp.width as i32,
height: vp.height as i32,
width: window_size.width as i32,
height: window_size.height as i32,
};
Ok(WebDriverResponse::WindowRect(window_size_response))
}