base: Finish rename of TopLevelBrowsingContextId to WebViewId (#35896)

The `WebViewId` name is a lot more descriptive these days to the casual
reader, so I think we can go ahead and finish the rename.

Signed-off-by: Martin Robinson <mrobinson@igalia.com>
This commit is contained in:
Martin Robinson 2025-03-11 11:56:10 +01:00 committed by GitHub
parent 81fe4bbb1e
commit 2464d0937f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
22 changed files with 416 additions and 570 deletions

View file

@ -16,7 +16,7 @@ use std::net::{SocketAddr, SocketAddrV4};
use std::time::Duration;
use std::{env, fmt, mem, process, thread};
use base::id::{BrowsingContextId, TopLevelBrowsingContextId};
use base::id::{BrowsingContextId, WebViewId};
use base64::Engine;
use capabilities::ServoCapabilities;
use compositing_traits::ConstellationMsg;
@ -125,9 +125,9 @@ pub fn start_server(port: u16, constellation_chan: Sender<ConstellationMsg>) {
pub struct WebDriverSession {
id: Uuid,
browsing_context_id: BrowsingContextId,
top_level_browsing_context_id: TopLevelBrowsingContextId,
webview_id: WebViewId,
window_handles: HashMap<TopLevelBrowsingContextId, String>,
window_handles: HashMap<WebViewId, String>,
/// Time to wait for injected scripts to run before interrupting them. A [`None`] value
/// specifies that the script should run indefinitely.
@ -153,18 +153,15 @@ pub struct WebDriverSession {
}
impl WebDriverSession {
pub fn new(
browsing_context_id: BrowsingContextId,
top_level_browsing_context_id: TopLevelBrowsingContextId,
) -> WebDriverSession {
pub fn new(browsing_context_id: BrowsingContextId, webview_id: WebViewId) -> WebDriverSession {
let mut window_handles = HashMap::new();
let handle = Uuid::new_v4().to_string();
window_handles.insert(top_level_browsing_context_id, handle);
window_handles.insert(webview_id, handle);
WebDriverSession {
id: Uuid::new_v4(),
browsing_context_id,
top_level_browsing_context_id,
webview_id,
window_handles,
@ -422,7 +419,7 @@ impl Handler {
}
}
fn focus_top_level_browsing_context_id(&self) -> WebDriverResult<TopLevelBrowsingContextId> {
fn focus_webview_id(&self) -> WebDriverResult<WebViewId> {
debug!("Getting focused context.");
let interval = 20;
let iterations = 30_000 / interval;
@ -483,12 +480,9 @@ impl Handler {
if self.session.is_none() {
match processed_capabilities {
Some(mut processed) => {
let top_level_browsing_context_id =
self.focus_top_level_browsing_context_id()?;
let browsing_context_id =
BrowsingContextId::from(top_level_browsing_context_id);
let mut session =
WebDriverSession::new(browsing_context_id, top_level_browsing_context_id);
let webview_id = self.focus_webview_id()?;
let browsing_context_id = BrowsingContextId::from(webview_id);
let mut session = WebDriverSession::new(browsing_context_id, webview_id);
match processed.get("pageLoadStrategy") {
Some(strategy) => session.page_loading_strategy = strategy.to_string(),
@ -638,8 +632,7 @@ impl Handler {
}
fn top_level_script_command(&self, cmd_msg: WebDriverScriptCommand) -> WebDriverResult<()> {
let browsing_context_id =
BrowsingContextId::from(self.session()?.top_level_browsing_context_id);
let browsing_context_id = BrowsingContextId::from(self.session()?.webview_id);
let msg = ConstellationMsg::WebDriverCommand(WebDriverCommandMsg::ScriptCommand(
browsing_context_id,
cmd_msg,
@ -659,13 +652,10 @@ impl Handler {
},
};
let top_level_browsing_context_id = self.session()?.top_level_browsing_context_id;
let webview_id = self.session()?.webview_id;
let cmd_msg = WebDriverCommandMsg::LoadUrl(
top_level_browsing_context_id,
url,
self.load_status_sender.clone(),
);
let cmd_msg =
WebDriverCommandMsg::LoadUrl(webview_id, url, self.load_status_sender.clone());
self.constellation_chan
.send(ConstellationMsg::WebDriverCommand(cmd_msg))
.unwrap();
@ -699,8 +689,8 @@ impl Handler {
fn handle_window_size(&self) -> WebDriverResult<WebDriverResponse> {
let (sender, receiver) = ipc::channel().unwrap();
let top_level_browsing_context_id = self.session()?.top_level_browsing_context_id;
let cmd_msg = WebDriverCommandMsg::GetWindowSize(top_level_browsing_context_id, sender);
let webview_id = self.session()?.webview_id;
let cmd_msg = WebDriverCommandMsg::GetWindowSize(webview_id, sender);
self.constellation_chan
.send(ConstellationMsg::WebDriverCommand(cmd_msg))
@ -731,12 +721,8 @@ impl Handler {
let width = params.width.unwrap_or(0);
let height = params.height.unwrap_or(0);
let size = Size2D::new(width as u32, height as u32);
let top_level_browsing_context_id = self.session()?.top_level_browsing_context_id;
let cmd_msg = WebDriverCommandMsg::SetWindowSize(
top_level_browsing_context_id,
size.to_i32(),
sender.clone(),
);
let webview_id = self.session()?.webview_id;
let cmd_msg = WebDriverCommandMsg::SetWindowSize(webview_id, size.to_i32(), sender.clone());
self.constellation_chan
.send(ConstellationMsg::WebDriverCommand(cmd_msg))
@ -748,7 +734,7 @@ impl Handler {
// On timeout, we send a GetWindowSize message to the constellation,
// which will give the current window size.
thread::sleep(Duration::from_millis(timeout as u64));
let cmd_msg = WebDriverCommandMsg::GetWindowSize(top_level_browsing_context_id, sender);
let cmd_msg = WebDriverCommandMsg::GetWindowSize(webview_id, sender);
constellation_chan
.send(ConstellationMsg::WebDriverCommand(cmd_msg))
.unwrap();
@ -797,28 +783,25 @@ impl Handler {
}
fn handle_go_back(&self) -> WebDriverResult<WebDriverResponse> {
let top_level_browsing_context_id = self.session()?.top_level_browsing_context_id;
let webview_id = self.session()?.webview_id;
let direction = TraversalDirection::Back(1);
let msg = ConstellationMsg::TraverseHistory(top_level_browsing_context_id, direction);
let msg = ConstellationMsg::TraverseHistory(webview_id, direction);
self.constellation_chan.send(msg).unwrap();
Ok(WebDriverResponse::Void)
}
fn handle_go_forward(&self) -> WebDriverResult<WebDriverResponse> {
let top_level_browsing_context_id = self.session()?.top_level_browsing_context_id;
let webview_id = self.session()?.webview_id;
let direction = TraversalDirection::Forward(1);
let msg = ConstellationMsg::TraverseHistory(top_level_browsing_context_id, direction);
let msg = ConstellationMsg::TraverseHistory(webview_id, direction);
self.constellation_chan.send(msg).unwrap();
Ok(WebDriverResponse::Void)
}
fn handle_refresh(&self) -> WebDriverResult<WebDriverResponse> {
let top_level_browsing_context_id = self.session()?.top_level_browsing_context_id;
let webview_id = self.session()?.webview_id;
let cmd_msg = WebDriverCommandMsg::Refresh(
top_level_browsing_context_id,
self.load_status_sender.clone(),
);
let cmd_msg = WebDriverCommandMsg::Refresh(webview_id, self.load_status_sender.clone());
self.constellation_chan
.send(ConstellationMsg::WebDriverCommand(cmd_msg))
.unwrap();
@ -839,10 +822,7 @@ impl Handler {
fn handle_window_handle(&self) -> WebDriverResult<WebDriverResponse> {
let session = self.session.as_ref().unwrap();
match session
.window_handles
.get(&session.top_level_browsing_context_id)
{
match session.window_handles.get(&session.webview_id) {
Some(handle) => Ok(WebDriverResponse::Generic(ValueResponse(
serde_json::to_value(handle)?,
))),
@ -910,19 +890,17 @@ impl Handler {
fn handle_close_window(&mut self) -> WebDriverResult<WebDriverResponse> {
{
let session = self.session_mut().unwrap();
session
.window_handles
.remove(&session.top_level_browsing_context_id);
let cmd_msg = WebDriverCommandMsg::CloseWebView(session.top_level_browsing_context_id);
session.window_handles.remove(&session.webview_id);
let cmd_msg = WebDriverCommandMsg::CloseWebView(session.webview_id);
self.constellation_chan
.send(ConstellationMsg::WebDriverCommand(cmd_msg))
.unwrap();
}
let top_level_browsing_context_id = self.focus_top_level_browsing_context_id()?;
let browsing_context_id = BrowsingContextId::from(top_level_browsing_context_id);
let webview_id = self.focus_webview_id()?;
let browsing_context_id = BrowsingContextId::from(webview_id);
let session = self.session_mut().unwrap();
session.top_level_browsing_context_id = top_level_browsing_context_id;
session.webview_id = webview_id;
session.browsing_context_id = browsing_context_id;
Ok(WebDriverResponse::CloseWindow(CloseWindowResponse(
@ -938,7 +916,7 @@ impl Handler {
let session = self.session().unwrap();
let cmd_msg = WebDriverCommandMsg::NewWebView(
session.top_level_browsing_context_id,
session.webview_id,
sender,
self.load_status_sender.clone(),
);
@ -946,15 +924,12 @@ impl Handler {
.send(ConstellationMsg::WebDriverCommand(cmd_msg))
.unwrap();
if let Ok(new_top_level_browsing_context_id) = receiver.recv() {
if let Ok(new_webview_id) = receiver.recv() {
let session = self.session_mut().unwrap();
session.top_level_browsing_context_id = new_top_level_browsing_context_id;
session.browsing_context_id =
BrowsingContextId::from(new_top_level_browsing_context_id);
session.webview_id = new_webview_id;
session.browsing_context_id = BrowsingContextId::from(new_webview_id);
let new_handle = Uuid::new_v4().to_string();
session
.window_handles
.insert(new_top_level_browsing_context_id, new_handle);
session.window_handles.insert(new_webview_id, new_handle);
}
let _ = self.wait_for_load();
@ -974,8 +949,7 @@ impl Handler {
let frame_id = match parameters.id {
FrameId::Top => {
let session = self.session_mut()?;
session.browsing_context_id =
BrowsingContextId::from(session.top_level_browsing_context_id);
session.browsing_context_id = BrowsingContextId::from(session.webview_id);
return Ok(WebDriverResponse::Void);
},
FrameId::Short(ref x) => WebDriverFrameId::Short(*x),
@ -998,16 +972,16 @@ impl Handler {
if session.id.to_string() == parameters.handle {
// There's only one main window, so there's nothing to do here.
Ok(WebDriverResponse::Void)
} else if let Some((top_level_browsing_context_id, _)) = session
} else if let Some((webview_id, _)) = session
.window_handles
.iter()
.find(|(_k, v)| **v == parameters.handle)
{
let top_level_browsing_context_id = *top_level_browsing_context_id;
session.top_level_browsing_context_id = top_level_browsing_context_id;
session.browsing_context_id = BrowsingContextId::from(top_level_browsing_context_id);
let webview_id = *webview_id;
session.webview_id = webview_id;
session.browsing_context_id = BrowsingContextId::from(webview_id);
let msg = ConstellationMsg::FocusWebView(top_level_browsing_context_id);
let msg = ConstellationMsg::FocusWebView(webview_id);
self.constellation_chan.send(msg).unwrap();
Ok(WebDriverResponse::Void)
} else {
@ -1668,11 +1642,8 @@ impl Handler {
for _ in 0..iterations {
let (sender, receiver) = ipc::channel().unwrap();
let cmd_msg = WebDriverCommandMsg::TakeScreenshot(
self.session()?.top_level_browsing_context_id,
rect,
sender,
);
let cmd_msg =
WebDriverCommandMsg::TakeScreenshot(self.session()?.webview_id, rect, sender);
self.constellation_chan
.send(ConstellationMsg::WebDriverCommand(cmd_msg))
.unwrap();