[webdriver] Move Webdriver to ServoShell (#36714)

Moving `webdriver` to `servoshell`:

- Let `servoshell` manage lifecycle of `webdriver`
- One by one, move the handling of webdriver commands from
`constellation` to `embedder`

Partially fix: https://github.com/servo/servo/issues/37370
Partially fix webdriver test timeout with `no_top_browsing_context`

cc: @xiaochengh

---------

Signed-off-by: batu_hoang <longvatrong111@gmail.com>
This commit is contained in:
batu_hoang 2025-06-19 17:52:01 +08:00 committed by GitHub
parent d55e2c4c90
commit d0100797e8
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
9 changed files with 156 additions and 35 deletions

View file

@ -7,6 +7,7 @@ use std::collections::HashMap;
use std::path::PathBuf;
use std::rc::Rc;
use crossbeam_channel::Receiver;
use euclid::Vector2D;
use keyboard_types::{Key, Modifiers, ShortcutMatcher};
use log::{error, info};
@ -18,7 +19,7 @@ use servo::webrender_api::units::{DeviceIntPoint, DeviceIntSize};
use servo::{
AllowOrDenyRequest, AuthenticationRequest, FilterPattern, FormControl, GamepadHapticEffectType,
KeyboardEvent, LoadStatus, PermissionRequest, Servo, ServoDelegate, ServoError, SimpleDialog,
TouchEventType, WebView, WebViewBuilder, WebViewDelegate,
TouchEventType, WebDriverCommandMsg, WebView, WebViewBuilder, WebViewDelegate,
};
use url::Url;
@ -44,6 +45,9 @@ pub(crate) struct RunningAppState {
/// The preferences for this run of servoshell. This is not mutable, so doesn't need to
/// be stored inside the [`RunningAppStateInner`].
servoshell_preferences: ServoShellPreferences,
/// A [`Receiver`] for receiving commands from a running WebDriver server, if WebDriver
/// was enabled.
webdriver_receiver: Option<Receiver<WebDriverCommandMsg>>,
inner: RefCell<RunningAppStateInner>,
}
@ -88,11 +92,13 @@ impl RunningAppState {
servo: Servo,
window: Rc<dyn WindowPortsMethods>,
servoshell_preferences: ServoShellPreferences,
webdriver_receiver: Option<Receiver<WebDriverCommandMsg>>,
) -> RunningAppState {
servo.set_delegate(Rc::new(ServoShellServoDelegate));
RunningAppState {
servo,
servoshell_preferences,
webdriver_receiver,
inner: RefCell::new(RunningAppStateInner {
webviews: HashMap::default(),
creation_order: Default::default(),
@ -132,6 +138,14 @@ impl RunningAppState {
&self.servo
}
pub(crate) fn webdriver_receiver(&self) -> Option<&Receiver<WebDriverCommandMsg>> {
self.webdriver_receiver.as_ref()
}
pub(crate) fn forward_webdriver_command(&self, command: WebDriverCommandMsg) {
self.servo().execute_webdriver_command(command);
}
pub(crate) fn hidpi_scale_factor_changed(&self) {
let inner = self.inner();
let new_scale_factor = inner.window.hidpi_scale_factor();
@ -261,6 +275,10 @@ impl RunningAppState {
.collect()
}
pub fn webview_by_id(&self, id: WebViewId) -> Option<WebView> {
self.inner().webviews.get(&id).cloned()
}
pub fn handle_gamepad_events(&self) {
let Some(active_webview) = self.focused_webview() else {
return;