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

@ -14,7 +14,7 @@ use std::sync::Arc;
use std::time::{Duration, Instant, SystemTime, UNIX_EPOCH}; use std::time::{Duration, Instant, SystemTime, UNIX_EPOCH};
use base::cross_process_instant::CrossProcessInstant; use base::cross_process_instant::CrossProcessInstant;
use base::id::{PipelineId, TopLevelBrowsingContextId, WebViewId}; use base::id::{PipelineId, WebViewId};
use base::{Epoch, WebRenderEpochToU16}; use base::{Epoch, WebRenderEpochToU16};
use bitflags::bitflags; use bitflags::bitflags;
use compositing_traits::{ use compositing_traits::{
@ -542,8 +542,8 @@ impl IOCompositor {
self.set_frame_tree_for_webview(&frame_tree); self.set_frame_tree_for_webview(&frame_tree);
}, },
CompositorMsg::RemoveWebView(top_level_browsing_context_id) => { CompositorMsg::RemoveWebView(webview_id) => {
self.remove_webview(top_level_browsing_context_id); self.remove_webview(webview_id);
}, },
CompositorMsg::TouchEventProcessed(webview_id, result) => { CompositorMsg::TouchEventProcessed(webview_id, result) => {
@ -1097,7 +1097,7 @@ impl IOCompositor {
fn set_frame_tree_for_webview(&mut self, frame_tree: &SendableFrameTree) { fn set_frame_tree_for_webview(&mut self, frame_tree: &SendableFrameTree) {
debug!("{}: Setting frame tree for webview", frame_tree.pipeline.id); debug!("{}: Setting frame tree for webview", frame_tree.pipeline.id);
let webview_id = frame_tree.pipeline.top_level_browsing_context_id; let webview_id = frame_tree.pipeline.webview_id;
let Some(webview) = self.webviews.get_mut(webview_id) else { let Some(webview) = self.webviews.get_mut(webview_id) else {
warn!( warn!(
"Attempted to set frame tree on unknown WebView (perhaps closed?): {webview_id:?}" "Attempted to set frame tree on unknown WebView (perhaps closed?): {webview_id:?}"
@ -1119,7 +1119,7 @@ impl IOCompositor {
self.send_root_pipeline_display_list(); self.send_root_pipeline_display_list();
} }
pub fn move_resize_webview(&mut self, webview_id: TopLevelBrowsingContextId, rect: DeviceRect) { pub fn move_resize_webview(&mut self, webview_id: WebViewId, rect: DeviceRect) {
debug!("{webview_id}: Moving and/or resizing webview; rect={rect:?}"); debug!("{webview_id}: Moving and/or resizing webview; rect={rect:?}");
let rect_changed; let rect_changed;
let size_changed; let size_changed;
@ -1203,14 +1203,14 @@ impl IOCompositor {
fn send_window_size_message_for_top_level_browser_context( fn send_window_size_message_for_top_level_browser_context(
&self, &self,
rect: DeviceRect, rect: DeviceRect,
top_level_browsing_context_id: TopLevelBrowsingContextId, webview_id: WebViewId,
) { ) {
// The device pixel ratio used by the style system should include the scale from page pixels // The device pixel ratio used by the style system should include the scale from page pixels
// to device pixels, but not including any pinch zoom. // to device pixels, but not including any pinch zoom.
let device_pixel_ratio = self.device_pixels_per_page_pixel_not_including_page_zoom(); let device_pixel_ratio = self.device_pixels_per_page_pixel_not_including_page_zoom();
let initial_viewport = rect.size().to_f32() / device_pixel_ratio; let initial_viewport = rect.size().to_f32() / device_pixel_ratio;
let msg = ConstellationMsg::WindowSize( let msg = ConstellationMsg::WindowSize(
top_level_browsing_context_id, webview_id,
WindowSizeData { WindowSizeData {
device_pixel_ratio, device_pixel_ratio,
initial_viewport, initial_viewport,
@ -1320,11 +1320,8 @@ impl IOCompositor {
} }
fn update_after_zoom_or_hidpi_change(&mut self) { fn update_after_zoom_or_hidpi_change(&mut self) {
for (top_level_browsing_context_id, webview) in self.webviews.painting_order() { for (webview_id, webview) in self.webviews.painting_order() {
self.send_window_size_message_for_top_level_browser_context( self.send_window_size_message_for_top_level_browser_context(webview.rect, *webview_id);
webview.rect,
*top_level_browsing_context_id,
);
} }
// Update the root transform in WebRender to reflect the new zoom. // Update the root transform in WebRender to reflect the new zoom.

View file

@ -943,14 +943,13 @@ mod test {
use std::num::NonZeroU32; use std::num::NonZeroU32;
use base::id::{ use base::id::{
BrowsingContextId, BrowsingContextIndex, PipelineNamespace, PipelineNamespaceId, BrowsingContextId, BrowsingContextIndex, PipelineNamespace, PipelineNamespaceId, WebViewId,
TopLevelBrowsingContextId,
}; };
use crate::webview::{UnknownWebView, WebViewAlreadyExists, WebViewManager}; use crate::webview::{UnknownWebView, WebViewAlreadyExists, WebViewManager};
fn top_level_id(namespace_id: u32, index: u32) -> TopLevelBrowsingContextId { fn top_level_id(namespace_id: u32, index: u32) -> WebViewId {
TopLevelBrowsingContextId(BrowsingContextId { WebViewId(BrowsingContextId {
namespace_id: PipelineNamespaceId(namespace_id), namespace_id: PipelineNamespaceId(namespace_id),
index: BrowsingContextIndex(NonZeroU32::new(index).unwrap()), index: BrowsingContextIndex(NonZeroU32::new(index).unwrap()),
}) })
@ -958,7 +957,7 @@ mod test {
fn webviews_sorted<WebView: Clone>( fn webviews_sorted<WebView: Clone>(
webviews: &WebViewManager<WebView>, webviews: &WebViewManager<WebView>,
) -> Vec<(TopLevelBrowsingContextId, WebView)> { ) -> Vec<(WebViewId, WebView)> {
let mut keys = webviews.webviews.keys().collect::<Vec<_>>(); let mut keys = webviews.webviews.keys().collect::<Vec<_>>();
keys.sort(); keys.sort();
keys.iter() keys.iter()
@ -972,9 +971,9 @@ mod test {
let mut webviews = WebViewManager::default(); let mut webviews = WebViewManager::default();
// add() adds the webview to the map, but not the painting order. // add() adds the webview to the map, but not the painting order.
assert!(webviews.add(TopLevelBrowsingContextId::new(), 'a').is_ok()); assert!(webviews.add(WebViewId::new(), 'a').is_ok());
assert!(webviews.add(TopLevelBrowsingContextId::new(), 'b').is_ok()); assert!(webviews.add(WebViewId::new(), 'b').is_ok());
assert!(webviews.add(TopLevelBrowsingContextId::new(), 'c').is_ok()); assert!(webviews.add(WebViewId::new(), 'c').is_ok());
assert_eq!( assert_eq!(
webviews_sorted(&webviews), webviews_sorted(&webviews),
vec![ vec![

View file

@ -4,7 +4,7 @@
use std::collections::{HashMap, HashSet}; use std::collections::{HashMap, HashSet};
use base::id::{BrowsingContextGroupId, BrowsingContextId, PipelineId, TopLevelBrowsingContextId}; use base::id::{BrowsingContextGroupId, BrowsingContextId, PipelineId, WebViewId};
use euclid::Size2D; use euclid::Size2D;
use log::warn; use log::warn;
use style_traits::CSSPixel; use style_traits::CSSPixel;
@ -48,7 +48,7 @@ pub struct BrowsingContext {
pub id: BrowsingContextId, pub id: BrowsingContextId,
/// The top-level browsing context ancestor /// The top-level browsing context ancestor
pub top_level_id: TopLevelBrowsingContextId, pub top_level_id: WebViewId,
/// The size of the frame. /// The size of the frame.
pub size: Size2D<f32, CSSPixel>, pub size: Size2D<f32, CSSPixel>,
@ -82,7 +82,7 @@ impl BrowsingContext {
pub fn new( pub fn new(
bc_group_id: BrowsingContextGroupId, bc_group_id: BrowsingContextGroupId,
id: BrowsingContextId, id: BrowsingContextId,
top_level_id: TopLevelBrowsingContextId, top_level_id: WebViewId,
pipeline_id: PipelineId, pipeline_id: PipelineId,
parent_pipeline_id: Option<PipelineId>, parent_pipeline_id: Option<PipelineId>,
size: Size2D<f32, CSSPixel>, size: Size2D<f32, CSSPixel>,

File diff suppressed because it is too large Load diff

View file

@ -11,7 +11,7 @@ use std::sync::Arc;
use std::thread; use std::thread;
use backtrace::Backtrace; use backtrace::Backtrace;
use base::id::TopLevelBrowsingContextId; use base::id::WebViewId;
use compositing_traits::ConstellationMsg as FromCompositorMsg; use compositing_traits::ConstellationMsg as FromCompositorMsg;
use crossbeam_channel::Sender; use crossbeam_channel::Sender;
use log::{Level, LevelFilter, Log, Metadata, Record}; use log::{Level, LevelFilter, Log, Metadata, Record};
@ -87,7 +87,7 @@ impl Log for FromCompositorLogger {
fn log(&self, record: &Record) { fn log(&self, record: &Record) {
if let Some(entry) = log_entry(record) { if let Some(entry) = log_entry(record) {
let top_level_id = TopLevelBrowsingContextId::installed(); let top_level_id = WebViewId::installed();
let thread_name = thread::current().name().map(ToOwned::to_owned); let thread_name = thread::current().name().map(ToOwned::to_owned);
let msg = FromCompositorMsg::LogEntry(top_level_id, thread_name, entry); let msg = FromCompositorMsg::LogEntry(top_level_id, thread_name, entry);
let chan = self.constellation_chan.lock(); let chan = self.constellation_chan.lock();

View file

@ -14,7 +14,7 @@ use background_hang_monitor_api::{
use base::Epoch; use base::Epoch;
use base::id::{ use base::id::{
BrowsingContextId, HistoryStateId, PipelineId, PipelineNamespace, PipelineNamespaceId, BrowsingContextId, HistoryStateId, PipelineId, PipelineNamespace, PipelineNamespaceId,
PipelineNamespaceRequest, TopLevelBrowsingContextId, PipelineNamespaceRequest, WebViewId,
}; };
#[cfg(feature = "bluetooth")] #[cfg(feature = "bluetooth")]
use bluetooth_traits::BluetoothRequest; use bluetooth_traits::BluetoothRequest;
@ -58,7 +58,7 @@ pub struct Pipeline {
pub browsing_context_id: BrowsingContextId, pub browsing_context_id: BrowsingContextId,
/// The ID of the top-level browsing context that contains this Pipeline. /// The ID of the top-level browsing context that contains this Pipeline.
pub top_level_browsing_context_id: TopLevelBrowsingContextId, pub webview_id: WebViewId,
pub opener: Option<BrowsingContextId>, pub opener: Option<BrowsingContextId>,
@ -112,7 +112,7 @@ pub struct InitialPipelineState {
pub browsing_context_id: BrowsingContextId, pub browsing_context_id: BrowsingContextId,
/// The ID of the top-level browsing context that contains this Pipeline. /// The ID of the top-level browsing context that contains this Pipeline.
pub top_level_browsing_context_id: TopLevelBrowsingContextId, pub webview_id: WebViewId,
/// The ID of the parent pipeline and frame type, if any. /// The ID of the parent pipeline and frame type, if any.
/// If `None`, this is the root. /// If `None`, this is the root.
@ -219,7 +219,7 @@ impl Pipeline {
parent_info: state.parent_pipeline_id, parent_info: state.parent_pipeline_id,
new_pipeline_id: state.id, new_pipeline_id: state.id,
browsing_context_id: state.browsing_context_id, browsing_context_id: state.browsing_context_id,
top_level_browsing_context_id: state.top_level_browsing_context_id, webview_id: state.webview_id,
opener: state.opener, opener: state.opener,
load_data: state.load_data.clone(), load_data: state.load_data.clone(),
window_size: state.window_size, window_size: state.window_size,
@ -261,7 +261,7 @@ impl Pipeline {
let mut unprivileged_pipeline_content = UnprivilegedPipelineContent { let mut unprivileged_pipeline_content = UnprivilegedPipelineContent {
id: state.id, id: state.id,
browsing_context_id: state.browsing_context_id, browsing_context_id: state.browsing_context_id,
top_level_browsing_context_id: state.top_level_browsing_context_id, webview_id: state.webview_id,
parent_pipeline_id: state.parent_pipeline_id, parent_pipeline_id: state.parent_pipeline_id,
opener: state.opener, opener: state.opener,
script_to_constellation_chan: state.script_to_constellation_chan.clone(), script_to_constellation_chan: state.script_to_constellation_chan.clone(),
@ -327,7 +327,7 @@ impl Pipeline {
let pipeline = Pipeline::new( let pipeline = Pipeline::new(
state.id, state.id,
state.browsing_context_id, state.browsing_context_id,
state.top_level_browsing_context_id, state.webview_id,
state.opener, state.opener,
script_chan, script_chan,
state.compositor_proxy, state.compositor_proxy,
@ -345,7 +345,7 @@ impl Pipeline {
pub fn new( pub fn new(
id: PipelineId, id: PipelineId,
browsing_context_id: BrowsingContextId, browsing_context_id: BrowsingContextId,
top_level_browsing_context_id: TopLevelBrowsingContextId, webview_id: WebViewId,
opener: Option<BrowsingContextId>, opener: Option<BrowsingContextId>,
event_loop: Rc<EventLoop>, event_loop: Rc<EventLoop>,
compositor_proxy: CompositorProxy, compositor_proxy: CompositorProxy,
@ -355,7 +355,7 @@ impl Pipeline {
let pipeline = Pipeline { let pipeline = Pipeline {
id, id,
browsing_context_id, browsing_context_id,
top_level_browsing_context_id, webview_id,
opener, opener,
event_loop, event_loop,
compositor_proxy, compositor_proxy,
@ -387,7 +387,7 @@ impl Pipeline {
// since the compositor never blocks on the constellation. // since the compositor never blocks on the constellation.
if let Ok((sender, receiver)) = ipc::channel() { if let Ok((sender, receiver)) = ipc::channel() {
self.compositor_proxy.send(CompositorMsg::PipelineExited( self.compositor_proxy.send(CompositorMsg::PipelineExited(
self.top_level_browsing_context_id, self.webview_id,
self.id, self.id,
sender, sender,
)); ));
@ -425,7 +425,7 @@ impl Pipeline {
pub fn to_sendable(&self) -> CompositionPipeline { pub fn to_sendable(&self) -> CompositionPipeline {
CompositionPipeline { CompositionPipeline {
id: self.id, id: self.id,
top_level_browsing_context_id: self.top_level_browsing_context_id, webview_id: self.webview_id,
script_chan: self.event_loop.sender(), script_chan: self.event_loop.sender(),
} }
} }
@ -458,8 +458,7 @@ impl Pipeline {
/// running timers at a heavily limited rate. /// running timers at a heavily limited rate.
pub fn set_throttled(&self, throttled: bool) { pub fn set_throttled(&self, throttled: bool) {
let script_msg = ScriptThreadMessage::SetThrottled(self.id, throttled); let script_msg = ScriptThreadMessage::SetThrottled(self.id, throttled);
let compositor_msg = let compositor_msg = CompositorMsg::SetThrottled(self.webview_id, self.id, throttled);
CompositorMsg::SetThrottled(self.top_level_browsing_context_id, self.id, throttled);
let err = self.event_loop.send(script_msg); let err = self.event_loop.send(script_msg);
if let Err(e) = err { if let Err(e) = err {
warn!("Sending SetThrottled to script failed ({}).", e); warn!("Sending SetThrottled to script failed ({}).", e);
@ -474,7 +473,7 @@ impl Pipeline {
#[derive(Deserialize, Serialize)] #[derive(Deserialize, Serialize)]
pub struct UnprivilegedPipelineContent { pub struct UnprivilegedPipelineContent {
id: PipelineId, id: PipelineId,
top_level_browsing_context_id: TopLevelBrowsingContextId, webview_id: WebViewId,
browsing_context_id: BrowsingContextId, browsing_context_id: BrowsingContextId,
parent_pipeline_id: Option<PipelineId>, parent_pipeline_id: Option<PipelineId>,
opener: Option<BrowsingContextId>, opener: Option<BrowsingContextId>,
@ -527,7 +526,7 @@ impl UnprivilegedPipelineContent {
InitialScriptState { InitialScriptState {
id: self.id, id: self.id,
browsing_context_id: self.browsing_context_id, browsing_context_id: self.browsing_context_id,
top_level_browsing_context_id: self.top_level_browsing_context_id, webview_id: self.webview_id,
parent_info: self.parent_pipeline_id, parent_info: self.parent_pipeline_id,
opener: self.opener, opener: self.opener,
constellation_sender: self.script_chan.clone(), constellation_sender: self.script_chan.clone(),

View file

@ -5,7 +5,7 @@
use std::cmp::PartialEq; use std::cmp::PartialEq;
use std::fmt; use std::fmt;
use base::id::{BrowsingContextId, HistoryStateId, PipelineId, TopLevelBrowsingContextId}; use base::id::{BrowsingContextId, HistoryStateId, PipelineId, WebViewId};
use euclid::Size2D; use euclid::Size2D;
use log::debug; use log::debug;
use script_traits::LoadData; use script_traits::LoadData;
@ -115,7 +115,7 @@ pub struct SessionHistoryChange {
pub browsing_context_id: BrowsingContextId, pub browsing_context_id: BrowsingContextId,
/// The top-level browsing context ancestor. /// The top-level browsing context ancestor.
pub top_level_browsing_context_id: TopLevelBrowsingContextId, pub webview_id: WebViewId,
/// The pipeline for the document being loaded. /// The pipeline for the document being loaded.
pub new_pipeline_id: PipelineId, pub new_pipeline_id: PipelineId,

View file

@ -4,16 +4,16 @@
use std::collections::HashMap; use std::collections::HashMap;
use base::id::TopLevelBrowsingContextId; use base::id::WebViewId;
#[derive(Debug)] #[derive(Debug)]
pub struct WebViewManager<WebView> { pub struct WebViewManager<WebView> {
/// Our top-level browsing contexts. In the WebRender scene, their pipelines are the children of /// Our top-level browsing contexts. In the WebRender scene, their pipelines are the children of
/// a single root pipeline that also applies any pinch zoom transformation. /// a single root pipeline that also applies any pinch zoom transformation.
webviews: HashMap<TopLevelBrowsingContextId, WebView>, webviews: HashMap<WebViewId, WebView>,
/// The order in which they were focused, latest last. /// The order in which they were focused, latest last.
focus_order: Vec<TopLevelBrowsingContextId>, focus_order: Vec<WebViewId>,
/// Whether the latest webview in focus order is currently focused. /// Whether the latest webview in focus order is currently focused.
is_focused: bool, is_focused: bool,
@ -30,63 +30,47 @@ impl<WebView> Default for WebViewManager<WebView> {
} }
impl<WebView> WebViewManager<WebView> { impl<WebView> WebViewManager<WebView> {
pub fn add( pub fn add(&mut self, webview_id: WebViewId, webview: WebView) {
&mut self, self.webviews.insert(webview_id, webview);
top_level_browsing_context_id: TopLevelBrowsingContextId,
webview: WebView,
) {
self.webviews.insert(top_level_browsing_context_id, webview);
} }
pub fn remove( pub fn remove(&mut self, webview_id: WebViewId) -> Option<WebView> {
&mut self, if self.focus_order.last() == Some(&webview_id) {
top_level_browsing_context_id: TopLevelBrowsingContextId,
) -> Option<WebView> {
if self.focus_order.last() == Some(&top_level_browsing_context_id) {
self.is_focused = false; self.is_focused = false;
} }
self.focus_order self.focus_order.retain(|b| *b != webview_id);
.retain(|b| *b != top_level_browsing_context_id); self.webviews.remove(&webview_id)
self.webviews.remove(&top_level_browsing_context_id)
} }
pub fn get( pub fn get(&self, webview_id: WebViewId) -> Option<&WebView> {
&self, self.webviews.get(&webview_id)
top_level_browsing_context_id: TopLevelBrowsingContextId,
) -> Option<&WebView> {
self.webviews.get(&top_level_browsing_context_id)
} }
pub fn get_mut( pub fn get_mut(&mut self, webview_id: WebViewId) -> Option<&mut WebView> {
&mut self, self.webviews.get_mut(&webview_id)
top_level_browsing_context_id: TopLevelBrowsingContextId,
) -> Option<&mut WebView> {
self.webviews.get_mut(&top_level_browsing_context_id)
} }
pub fn focused_webview(&self) -> Option<(TopLevelBrowsingContextId, &WebView)> { pub fn focused_webview(&self) -> Option<(WebViewId, &WebView)> {
if !self.is_focused { if !self.is_focused {
return None; return None;
} }
if let Some(top_level_browsing_context_id) = self.focus_order.last().cloned() { if let Some(webview_id) = self.focus_order.last().cloned() {
debug_assert!( debug_assert!(
self.webviews.contains_key(&top_level_browsing_context_id), self.webviews.contains_key(&webview_id),
"BUG: webview in .focus_order not in .webviews!", "BUG: webview in .focus_order not in .webviews!",
); );
self.get(top_level_browsing_context_id) self.get(webview_id).map(|webview| (webview_id, webview))
.map(|webview| (top_level_browsing_context_id, webview))
} else { } else {
debug_assert!(false, "BUG: .is_focused but no webviews in .focus_order!"); debug_assert!(false, "BUG: .is_focused but no webviews in .focus_order!");
None None
} }
} }
pub fn focus(&mut self, top_level_browsing_context_id: TopLevelBrowsingContextId) { pub fn focus(&mut self, webview_id: WebViewId) {
debug_assert!(self.webviews.contains_key(&top_level_browsing_context_id)); debug_assert!(self.webviews.contains_key(&webview_id));
self.focus_order self.focus_order.retain(|b| *b != webview_id);
.retain(|b| *b != top_level_browsing_context_id); self.focus_order.push(webview_id);
self.focus_order.push(top_level_browsing_context_id);
self.is_focused = true; self.is_focused = true;
} }
@ -100,14 +84,13 @@ mod test {
use std::num::NonZeroU32; use std::num::NonZeroU32;
use base::id::{ use base::id::{
BrowsingContextId, BrowsingContextIndex, PipelineNamespace, PipelineNamespaceId, BrowsingContextId, BrowsingContextIndex, PipelineNamespace, PipelineNamespaceId, WebViewId,
TopLevelBrowsingContextId, WebViewId,
}; };
use crate::webview::WebViewManager; use crate::webview::WebViewManager;
fn id(namespace_id: u32, index: u32) -> WebViewId { fn id(namespace_id: u32, index: u32) -> WebViewId {
TopLevelBrowsingContextId(BrowsingContextId { WebViewId(BrowsingContextId {
namespace_id: PipelineNamespaceId(namespace_id), namespace_id: PipelineNamespaceId(namespace_id),
index: BrowsingContextIndex(NonZeroU32::new(index).expect("Incorrect test case")), index: BrowsingContextIndex(NonZeroU32::new(index).expect("Incorrect test case")),
}) })

View file

@ -6,7 +6,7 @@ use std::sync::Arc;
use std::sync::atomic::AtomicBool; use std::sync::atomic::AtomicBool;
use std::thread::{self, JoinHandle}; use std::thread::{self, JoinHandle};
use base::id::{BrowsingContextId, PipelineId, TopLevelBrowsingContextId, WebViewId}; use base::id::{BrowsingContextId, PipelineId, WebViewId};
use crossbeam_channel::{Receiver, Sender, unbounded}; use crossbeam_channel::{Receiver, Sender, unbounded};
use devtools_traits::DevtoolScriptControlMsg; use devtools_traits::DevtoolScriptControlMsg;
use dom_struct::dom_struct; use dom_struct::dom_struct;
@ -349,7 +349,7 @@ impl DedicatedWorkerGlobalScope {
insecure_requests_policy: InsecureRequestsPolicy, insecure_requests_policy: InsecureRequestsPolicy,
) -> JoinHandle<()> { ) -> JoinHandle<()> {
let serialized_worker_url = worker_url.to_string(); let serialized_worker_url = worker_url.to_string();
let top_level_browsing_context_id = TopLevelBrowsingContextId::installed(); let webview_id = WebViewId::installed();
let current_global = GlobalScope::current().expect("No current global object"); let current_global = GlobalScope::current().expect("No current global object");
let origin = current_global.origin().immutable().clone(); let origin = current_global.origin().immutable().clone();
let referrer = current_global.get_referrer(); let referrer = current_global.get_referrer();
@ -361,8 +361,8 @@ impl DedicatedWorkerGlobalScope {
.spawn(move || { .spawn(move || {
thread_state::initialize(ThreadState::SCRIPT | ThreadState::IN_WORKER); thread_state::initialize(ThreadState::SCRIPT | ThreadState::IN_WORKER);
if let Some(top_level_browsing_context_id) = top_level_browsing_context_id { if let Some(webview_id) = webview_id {
TopLevelBrowsingContextId::install(top_level_browsing_context_id); WebViewId::install(webview_id);
} }
let roots = RootCollection::new(); let roots = RootCollection::new();
@ -376,21 +376,17 @@ impl DedicatedWorkerGlobalScope {
let referrer = referrer_url.map(Referrer::ReferrerUrl).unwrap_or(referrer); let referrer = referrer_url.map(Referrer::ReferrerUrl).unwrap_or(referrer);
let request = RequestBuilder::new( let request = RequestBuilder::new(webview_id, worker_url.clone(), referrer)
top_level_browsing_context_id, .destination(Destination::Worker)
worker_url.clone(), .mode(RequestMode::SameOrigin)
referrer, .credentials_mode(CredentialsMode::CredentialsSameOrigin)
) .parser_metadata(ParserMetadata::NotParserInserted)
.destination(Destination::Worker) .use_url_credentials(true)
.mode(RequestMode::SameOrigin) .pipeline_id(Some(pipeline_id))
.credentials_mode(CredentialsMode::CredentialsSameOrigin) .referrer_policy(referrer_policy)
.parser_metadata(ParserMetadata::NotParserInserted) .referrer_policy(referrer_policy)
.use_url_credentials(true) .insecure_requests_policy(insecure_requests_policy)
.pipeline_id(Some(pipeline_id)) .origin(origin);
.referrer_policy(referrer_policy)
.referrer_policy(referrer_policy)
.insecure_requests_policy(insecure_requests_policy)
.origin(origin);
let runtime = unsafe { let runtime = unsafe {
let task_source = SendableTaskSource { let task_source = SendableTaskSource {

View file

@ -4,7 +4,7 @@
use std::cell::Cell; use std::cell::Cell;
use base::id::{BrowsingContextId, PipelineId, TopLevelBrowsingContextId}; use base::id::{BrowsingContextId, PipelineId, WebViewId};
use bitflags::bitflags; use bitflags::bitflags;
use dom_struct::dom_struct; use dom_struct::dom_struct;
use html5ever::{LocalName, Prefix, local_name, namespace_url, ns}; use html5ever::{LocalName, Prefix, local_name, namespace_url, ns};
@ -74,7 +74,7 @@ enum ProcessingMode {
pub(crate) struct HTMLIFrameElement { pub(crate) struct HTMLIFrameElement {
htmlelement: HTMLElement, htmlelement: HTMLElement,
#[no_trace] #[no_trace]
top_level_browsing_context_id: Cell<Option<TopLevelBrowsingContextId>>, webview_id: Cell<Option<WebViewId>>,
#[no_trace] #[no_trace]
browsing_context_id: Cell<Option<BrowsingContextId>>, browsing_context_id: Cell<Option<BrowsingContextId>>,
#[no_trace] #[no_trace]
@ -143,7 +143,7 @@ impl HTMLIFrameElement {
Some(id) => id, Some(id) => id,
}; };
let top_level_browsing_context_id = match self.top_level_browsing_context_id() { let webview_id = match self.webview_id() {
None => return warn!("Attempted to start a new pipeline on an unattached iframe."), None => return warn!("Attempted to start a new pipeline on an unattached iframe."),
Some(id) => id, Some(id) => id,
}; };
@ -188,7 +188,7 @@ impl HTMLIFrameElement {
let load_info = IFrameLoadInfo { let load_info = IFrameLoadInfo {
parent_pipeline_id: window.pipeline_id(), parent_pipeline_id: window.pipeline_id(),
browsing_context_id, browsing_context_id,
top_level_browsing_context_id, webview_id,
new_pipeline_id, new_pipeline_id,
is_private: false, // FIXME is_private: false, // FIXME
inherited_secure_context: load_data.inherited_secure_context, inherited_secure_context: load_data.inherited_secure_context,
@ -223,7 +223,7 @@ impl HTMLIFrameElement {
parent_info: Some(window.pipeline_id()), parent_info: Some(window.pipeline_id()),
new_pipeline_id, new_pipeline_id,
browsing_context_id, browsing_context_id,
top_level_browsing_context_id, webview_id,
opener: None, opener: None,
load_data, load_data,
window_size, window_size,
@ -406,11 +406,10 @@ impl HTMLIFrameElement {
Some(document.insecure_requests_policy()), Some(document.insecure_requests_policy()),
); );
let browsing_context_id = BrowsingContextId::new(); let browsing_context_id = BrowsingContextId::new();
let top_level_browsing_context_id = window.window_proxy().top_level_browsing_context_id(); let webview_id = window.window_proxy().webview_id();
self.pipeline_id.set(None); self.pipeline_id.set(None);
self.pending_pipeline_id.set(None); self.pending_pipeline_id.set(None);
self.top_level_browsing_context_id self.webview_id.set(Some(webview_id));
.set(Some(top_level_browsing_context_id));
self.browsing_context_id.set(Some(browsing_context_id)); self.browsing_context_id.set(Some(browsing_context_id));
self.start_new_pipeline( self.start_new_pipeline(
load_data, load_data,
@ -424,7 +423,7 @@ impl HTMLIFrameElement {
self.pipeline_id.set(None); self.pipeline_id.set(None);
self.pending_pipeline_id.set(None); self.pending_pipeline_id.set(None);
self.about_blank_pipeline_id.set(None); self.about_blank_pipeline_id.set(None);
self.top_level_browsing_context_id.set(None); self.webview_id.set(None);
self.browsing_context_id.set(None); self.browsing_context_id.set(None);
} }
@ -460,7 +459,7 @@ impl HTMLIFrameElement {
HTMLIFrameElement { HTMLIFrameElement {
htmlelement: HTMLElement::new_inherited(local_name, prefix, document), htmlelement: HTMLElement::new_inherited(local_name, prefix, document),
browsing_context_id: Cell::new(None), browsing_context_id: Cell::new(None),
top_level_browsing_context_id: Cell::new(None), webview_id: Cell::new(None),
pipeline_id: Cell::new(None), pipeline_id: Cell::new(None),
pending_pipeline_id: Cell::new(None), pending_pipeline_id: Cell::new(None),
about_blank_pipeline_id: Cell::new(None), about_blank_pipeline_id: Cell::new(None),
@ -500,8 +499,8 @@ impl HTMLIFrameElement {
} }
#[inline] #[inline]
pub(crate) fn top_level_browsing_context_id(&self) -> Option<TopLevelBrowsingContextId> { pub(crate) fn webview_id(&self) -> Option<WebViewId> {
self.top_level_browsing_context_id.get() self.webview_id.get()
} }
pub(crate) fn set_throttled(&self, throttled: bool) { pub(crate) fn set_throttled(&self, throttled: bool) {

View file

@ -5,7 +5,7 @@
use std::cell::Cell; use std::cell::Cell;
use std::ptr; use std::ptr;
use base::id::{BrowsingContextId, PipelineId, TopLevelBrowsingContextId}; use base::id::{BrowsingContextId, PipelineId, WebViewId};
use dom_struct::dom_struct; use dom_struct::dom_struct;
use html5ever::local_name; use html5ever::local_name;
use indexmap::map::IndexMap; use indexmap::map::IndexMap;
@ -81,7 +81,7 @@ pub(crate) struct WindowProxy {
/// The frame id of the top-level ancestor browsing context. /// The frame id of the top-level ancestor browsing context.
/// In the case that this is a top-level window, this is our id. /// In the case that this is a top-level window, this is our id.
#[no_trace] #[no_trace]
top_level_browsing_context_id: TopLevelBrowsingContextId, webview_id: WebViewId,
/// The name of the browsing context (sometimes, but not always, /// The name of the browsing context (sometimes, but not always,
/// equal to the name of a container element) /// equal to the name of a container element)
@ -128,7 +128,7 @@ pub(crate) struct WindowProxy {
impl WindowProxy { impl WindowProxy {
fn new_inherited( fn new_inherited(
browsing_context_id: BrowsingContextId, browsing_context_id: BrowsingContextId,
top_level_browsing_context_id: TopLevelBrowsingContextId, webview_id: WebViewId,
currently_active: Option<PipelineId>, currently_active: Option<PipelineId>,
frame_element: Option<&Element>, frame_element: Option<&Element>,
parent: Option<&WindowProxy>, parent: Option<&WindowProxy>,
@ -141,7 +141,7 @@ impl WindowProxy {
WindowProxy { WindowProxy {
reflector: Reflector::new(), reflector: Reflector::new(),
browsing_context_id, browsing_context_id,
top_level_browsing_context_id, webview_id,
name: DomRefCell::new(name), name: DomRefCell::new(name),
currently_active: Cell::new(currently_active), currently_active: Cell::new(currently_active),
discarded: Cell::new(false), discarded: Cell::new(false),
@ -161,7 +161,7 @@ impl WindowProxy {
pub(crate) fn new( pub(crate) fn new(
window: &Window, window: &Window,
browsing_context_id: BrowsingContextId, browsing_context_id: BrowsingContextId,
top_level_browsing_context_id: TopLevelBrowsingContextId, webview_id: WebViewId,
frame_element: Option<&Element>, frame_element: Option<&Element>,
parent: Option<&WindowProxy>, parent: Option<&WindowProxy>,
opener: Option<BrowsingContextId>, opener: Option<BrowsingContextId>,
@ -187,7 +187,7 @@ impl WindowProxy {
let current = Some(window.global().pipeline_id()); let current = Some(window.global().pipeline_id());
let window_proxy = Box::new(WindowProxy::new_inherited( let window_proxy = Box::new(WindowProxy::new_inherited(
browsing_context_id, browsing_context_id,
top_level_browsing_context_id, webview_id,
current, current,
frame_element, frame_element,
parent, parent,
@ -221,7 +221,7 @@ impl WindowProxy {
pub(crate) fn new_dissimilar_origin( pub(crate) fn new_dissimilar_origin(
global_to_clone_from: &GlobalScope, global_to_clone_from: &GlobalScope,
browsing_context_id: BrowsingContextId, browsing_context_id: BrowsingContextId,
top_level_browsing_context_id: TopLevelBrowsingContextId, webview_id: WebViewId,
parent: Option<&WindowProxy>, parent: Option<&WindowProxy>,
opener: Option<BrowsingContextId>, opener: Option<BrowsingContextId>,
creator: CreatorBrowsingContextInfo, creator: CreatorBrowsingContextInfo,
@ -234,7 +234,7 @@ impl WindowProxy {
// Create a new browsing context. // Create a new browsing context.
let window_proxy = Box::new(WindowProxy::new_inherited( let window_proxy = Box::new(WindowProxy::new_inherited(
browsing_context_id, browsing_context_id,
top_level_browsing_context_id, webview_id,
None, None,
None, None,
parent, parent,
@ -322,7 +322,7 @@ impl WindowProxy {
parent_info: None, parent_info: None,
new_pipeline_id: response.new_pipeline_id, new_pipeline_id: response.new_pipeline_id,
browsing_context_id: new_browsing_context_id, browsing_context_id: new_browsing_context_id,
top_level_browsing_context_id: response.new_webview_id, webview_id: response.new_webview_id,
opener: Some(self.browsing_context_id), opener: Some(self.browsing_context_id),
load_data, load_data,
window_size: window.window_size(), window_size: window.window_size(),
@ -585,8 +585,8 @@ impl WindowProxy {
self.browsing_context_id self.browsing_context_id
} }
pub(crate) fn top_level_browsing_context_id(&self) -> TopLevelBrowsingContextId { pub(crate) fn webview_id(&self) -> WebViewId {
self.top_level_browsing_context_id self.webview_id
} }
pub(crate) fn frame_element(&self) -> Option<&Element> { pub(crate) fn frame_element(&self) -> Option<&Element> {

View file

@ -9,7 +9,7 @@
use std::cell::Cell; use std::cell::Cell;
use base::cross_process_instant::CrossProcessInstant; use base::cross_process_instant::CrossProcessInstant;
use base::id::{BrowsingContextId, PipelineId, TopLevelBrowsingContextId}; use base::id::{BrowsingContextId, PipelineId, WebViewId};
use content_security_policy::Destination; use content_security_policy::Destination;
use crossbeam_channel::Sender; use crossbeam_channel::Sender;
use http::header; use http::header;
@ -128,7 +128,7 @@ pub(crate) struct InProgressLoad {
pub(crate) browsing_context_id: BrowsingContextId, pub(crate) browsing_context_id: BrowsingContextId,
/// The top level ancestor browsing context. /// The top level ancestor browsing context.
#[no_trace] #[no_trace]
pub(crate) top_level_browsing_context_id: TopLevelBrowsingContextId, pub(crate) webview_id: WebViewId,
/// The parent pipeline and frame type associated with this load, if any. /// The parent pipeline and frame type associated with this load, if any.
#[no_trace] #[no_trace]
pub(crate) parent_info: Option<PipelineId>, pub(crate) parent_info: Option<PipelineId>,
@ -166,7 +166,7 @@ impl InProgressLoad {
pub(crate) fn new( pub(crate) fn new(
id: PipelineId, id: PipelineId,
browsing_context_id: BrowsingContextId, browsing_context_id: BrowsingContextId,
top_level_browsing_context_id: TopLevelBrowsingContextId, webview_id: WebViewId,
parent_info: Option<PipelineId>, parent_info: Option<PipelineId>,
opener: Option<BrowsingContextId>, opener: Option<BrowsingContextId>,
window_size: WindowSizeData, window_size: WindowSizeData,
@ -177,7 +177,7 @@ impl InProgressLoad {
InProgressLoad { InProgressLoad {
pipeline_id: id, pipeline_id: id,
browsing_context_id, browsing_context_id,
top_level_browsing_context_id, webview_id,
parent_info, parent_info,
opener, opener,
window_size, window_size,
@ -193,9 +193,9 @@ impl InProgressLoad {
pub(crate) fn request_builder(&mut self) -> RequestBuilder { pub(crate) fn request_builder(&mut self) -> RequestBuilder {
let id = self.pipeline_id; let id = self.pipeline_id;
let top_level_browsing_context_id = self.top_level_browsing_context_id; let webview_id = self.webview_id;
let mut request_builder = RequestBuilder::new( let mut request_builder = RequestBuilder::new(
Some(top_level_browsing_context_id), Some(webview_id),
self.load_data.url.clone(), self.load_data.url.clone(),
self.load_data.referrer.clone(), self.load_data.referrer.clone(),
) )

View file

@ -35,9 +35,7 @@ use background_hang_monitor_api::{
}; };
use base::Epoch; use base::Epoch;
use base::cross_process_instant::CrossProcessInstant; use base::cross_process_instant::CrossProcessInstant;
use base::id::{ use base::id::{BrowsingContextId, HistoryStateId, PipelineId, PipelineNamespace, WebViewId};
BrowsingContextId, HistoryStateId, PipelineId, PipelineNamespace, TopLevelBrowsingContextId,
};
use canvas_traits::webgl::WebGLPipeline; use canvas_traits::webgl::WebGLPipeline;
use chrono::{DateTime, Local}; use chrono::{DateTime, Local};
use crossbeam_channel::unbounded; use crossbeam_channel::unbounded;
@ -401,12 +399,12 @@ impl ScriptThreadFactory for ScriptThread {
.spawn(move || { .spawn(move || {
thread_state::initialize(ThreadState::SCRIPT | ThreadState::LAYOUT); thread_state::initialize(ThreadState::SCRIPT | ThreadState::LAYOUT);
PipelineNamespace::install(state.pipeline_namespace_id); PipelineNamespace::install(state.pipeline_namespace_id);
TopLevelBrowsingContextId::install(state.top_level_browsing_context_id); WebViewId::install(state.webview_id);
let roots = RootCollection::new(); let roots = RootCollection::new();
let _stack_roots = ThreadLocalStackRoots::new(&roots); let _stack_roots = ThreadLocalStackRoots::new(&roots);
let id = state.id; let id = state.id;
let browsing_context_id = state.browsing_context_id; let browsing_context_id = state.browsing_context_id;
let top_level_browsing_context_id = state.top_level_browsing_context_id; let webview_id = state.webview_id;
let parent_info = state.parent_info; let parent_info = state.parent_info;
let opener = state.opener; let opener = state.opener;
let memory_profiler_sender = state.memory_profiler_sender.clone(); let memory_profiler_sender = state.memory_profiler_sender.clone();
@ -425,7 +423,7 @@ impl ScriptThreadFactory for ScriptThread {
script_thread.pre_page_load(InProgressLoad::new( script_thread.pre_page_load(InProgressLoad::new(
id, id,
browsing_context_id, browsing_context_id,
top_level_browsing_context_id, webview_id,
parent_info, parent_info,
opener, opener,
window_size, window_size,
@ -661,7 +659,7 @@ impl ScriptThread {
pub(crate) fn get_top_level_for_browsing_context( pub(crate) fn get_top_level_for_browsing_context(
sender_pipeline: PipelineId, sender_pipeline: PipelineId,
browsing_context_id: BrowsingContextId, browsing_context_id: BrowsingContextId,
) -> Option<TopLevelBrowsingContextId> { ) -> Option<WebViewId> {
with_script_thread(|script_thread| { with_script_thread(|script_thread| {
script_thread.ask_constellation_for_top_level_info(sender_pipeline, browsing_context_id) script_thread.ask_constellation_for_top_level_info(sender_pipeline, browsing_context_id)
}) })
@ -1791,13 +1789,13 @@ impl ScriptThread {
ScriptThreadMessage::UpdatePipelineId( ScriptThreadMessage::UpdatePipelineId(
parent_pipeline_id, parent_pipeline_id,
browsing_context_id, browsing_context_id,
top_level_browsing_context_id, webview_id,
new_pipeline_id, new_pipeline_id,
reason, reason,
) => self.handle_update_pipeline_id( ) => self.handle_update_pipeline_id(
parent_pipeline_id, parent_pipeline_id,
browsing_context_id, browsing_context_id,
top_level_browsing_context_id, webview_id,
new_pipeline_id, new_pipeline_id,
reason, reason,
can_gc, can_gc,
@ -2381,7 +2379,7 @@ impl ScriptThread {
parent_info, parent_info,
new_pipeline_id, new_pipeline_id,
browsing_context_id, browsing_context_id,
top_level_browsing_context_id, webview_id,
opener, opener,
load_data, load_data,
window_size, window_size,
@ -2392,7 +2390,7 @@ impl ScriptThread {
let new_load = InProgressLoad::new( let new_load = InProgressLoad::new(
new_pipeline_id, new_pipeline_id,
browsing_context_id, browsing_context_id,
top_level_browsing_context_id, webview_id,
parent_info, parent_info,
opener, opener,
window_size, window_size,
@ -2518,7 +2516,7 @@ impl ScriptThread {
&self, &self,
pipeline_id: PipelineId, pipeline_id: PipelineId,
source_pipeline_id: PipelineId, source_pipeline_id: PipelineId,
source_browsing_context: TopLevelBrowsingContextId, source_browsing_context: WebViewId,
origin: Option<ImmutableOrigin>, origin: Option<ImmutableOrigin>,
source_origin: ImmutableOrigin, source_origin: ImmutableOrigin,
data: StructuredSerializedData, data: StructuredSerializedData,
@ -2573,7 +2571,7 @@ impl ScriptThread {
&self, &self,
parent_pipeline_id: PipelineId, parent_pipeline_id: PipelineId,
browsing_context_id: BrowsingContextId, browsing_context_id: BrowsingContextId,
top_level_browsing_context_id: TopLevelBrowsingContextId, webview_id: WebViewId,
new_pipeline_id: PipelineId, new_pipeline_id: PipelineId,
reason: UpdatePipelineIdReason, reason: UpdatePipelineIdReason,
can_gc: CanGc, can_gc: CanGc,
@ -2592,7 +2590,7 @@ impl ScriptThread {
let _ = self.local_window_proxy( let _ = self.local_window_proxy(
&window, &window,
browsing_context_id, browsing_context_id,
top_level_browsing_context_id, webview_id,
Some(parent_pipeline_id), Some(parent_pipeline_id),
// Any local window proxy has already been created, so there // Any local window proxy has already been created, so there
// is no need to pass along existing opener information that // is no need to pass along existing opener information that
@ -2899,7 +2897,7 @@ impl ScriptThread {
&self, &self,
sender_pipeline: PipelineId, sender_pipeline: PipelineId,
browsing_context_id: BrowsingContextId, browsing_context_id: BrowsingContextId,
) -> Option<TopLevelBrowsingContextId> { ) -> Option<WebViewId> {
let (result_sender, result_receiver) = ipc::channel().unwrap(); let (result_sender, result_receiver) = ipc::channel().unwrap();
let msg = ScriptMsg::GetTopForBrowsingContext(browsing_context_id, result_sender); let msg = ScriptMsg::GetTopForBrowsingContext(browsing_context_id, result_sender);
self.senders self.senders
@ -2920,7 +2918,7 @@ impl ScriptThread {
fn remote_window_proxy( fn remote_window_proxy(
&self, &self,
global_to_clone: &GlobalScope, global_to_clone: &GlobalScope,
top_level_browsing_context_id: TopLevelBrowsingContextId, webview_id: WebViewId,
pipeline_id: PipelineId, pipeline_id: PipelineId,
opener: Option<BrowsingContextId>, opener: Option<BrowsingContextId>,
) -> Option<DomRoot<WindowProxy>> { ) -> Option<DomRoot<WindowProxy>> {
@ -2931,12 +2929,7 @@ impl ScriptThread {
} }
let parent_browsing_context = parent_pipeline_id.and_then(|parent_id| { let parent_browsing_context = parent_pipeline_id.and_then(|parent_id| {
self.remote_window_proxy( self.remote_window_proxy(global_to_clone, webview_id, parent_id, opener)
global_to_clone,
top_level_browsing_context_id,
parent_id,
opener,
)
}); });
let opener_browsing_context = opener.and_then(ScriptThread::find_window_proxy); let opener_browsing_context = opener.and_then(ScriptThread::find_window_proxy);
@ -2949,7 +2942,7 @@ impl ScriptThread {
let window_proxy = WindowProxy::new_dissimilar_origin( let window_proxy = WindowProxy::new_dissimilar_origin(
global_to_clone, global_to_clone,
browsing_context_id, browsing_context_id,
top_level_browsing_context_id, webview_id,
parent_browsing_context.as_deref(), parent_browsing_context.as_deref(),
opener, opener,
creator, creator,
@ -2970,7 +2963,7 @@ impl ScriptThread {
&self, &self,
window: &Window, window: &Window,
browsing_context_id: BrowsingContextId, browsing_context_id: BrowsingContextId,
top_level_browsing_context_id: TopLevelBrowsingContextId, webview_id: WebViewId,
parent_info: Option<PipelineId>, parent_info: Option<PipelineId>,
opener: Option<BrowsingContextId>, opener: Option<BrowsingContextId>,
) -> DomRoot<WindowProxy> { ) -> DomRoot<WindowProxy> {
@ -2986,12 +2979,9 @@ impl ScriptThread {
}); });
let parent_browsing_context = match (parent_info, iframe.as_ref()) { let parent_browsing_context = match (parent_info, iframe.as_ref()) {
(_, Some(iframe)) => Some(iframe.owner_window().window_proxy()), (_, Some(iframe)) => Some(iframe.owner_window().window_proxy()),
(Some(parent_id), _) => self.remote_window_proxy( (Some(parent_id), _) => {
window.upcast(), self.remote_window_proxy(window.upcast(), webview_id, parent_id, opener)
top_level_browsing_context_id, },
parent_id,
opener,
),
_ => None, _ => None,
}; };
@ -3005,7 +2995,7 @@ impl ScriptThread {
let window_proxy = WindowProxy::new( let window_proxy = WindowProxy::new(
window, window,
browsing_context_id, browsing_context_id,
top_level_browsing_context_id, webview_id,
iframe.as_deref().map(Castable::upcast), iframe.as_deref().map(Castable::upcast),
parent_browsing_context.as_deref(), parent_browsing_context.as_deref(),
opener, opener,
@ -3053,7 +3043,7 @@ impl ScriptThread {
}; };
let paint_time_metrics = PaintTimeMetrics::new( let paint_time_metrics = PaintTimeMetrics::new(
incomplete.top_level_browsing_context_id, incomplete.webview_id,
incomplete.pipeline_id, incomplete.pipeline_id,
self.senders.time_profiler_sender.clone(), self.senders.time_profiler_sender.clone(),
self.senders.layout_to_constellation_ipc_sender.clone(), self.senders.layout_to_constellation_ipc_sender.clone(),
@ -3070,7 +3060,7 @@ impl ScriptThread {
let layout_config = LayoutConfig { let layout_config = LayoutConfig {
id: incomplete.pipeline_id, id: incomplete.pipeline_id,
webview_id: incomplete.top_level_browsing_context_id, webview_id: incomplete.webview_id,
url: final_url.clone(), url: final_url.clone(),
is_iframe: incomplete.parent_info.is_some(), is_iframe: incomplete.parent_info.is_some(),
script_chan: self.senders.constellation_sender.clone(), script_chan: self.senders.constellation_sender.clone(),
@ -3084,7 +3074,7 @@ impl ScriptThread {
// Create the window and document objects. // Create the window and document objects.
let window = Window::new( let window = Window::new(
incomplete.top_level_browsing_context_id, incomplete.webview_id,
self.js_runtime.clone(), self.js_runtime.clone(),
self.senders.self_sender.clone(), self.senders.self_sender.clone(),
self.layout_factory.create(layout_config), self.layout_factory.create(layout_config),
@ -3129,7 +3119,7 @@ impl ScriptThread {
let window_proxy = self.local_window_proxy( let window_proxy = self.local_window_proxy(
&window, &window,
incomplete.browsing_context_id, incomplete.browsing_context_id,
incomplete.top_level_browsing_context_id, incomplete.webview_id,
incomplete.parent_info, incomplete.parent_info,
incomplete.opener, incomplete.opener,
); );
@ -3225,7 +3215,7 @@ impl ScriptThread {
self.handle_update_pipeline_id( self.handle_update_pipeline_id(
parent_pipeline, parent_pipeline,
window_proxy.browsing_context_id(), window_proxy.browsing_context_id(),
window_proxy.top_level_browsing_context_id(), window_proxy.webview_id(),
incomplete.pipeline_id, incomplete.pipeline_id,
UpdatePipelineIdReason::Navigation, UpdatePipelineIdReason::Navigation,
can_gc, can_gc,
@ -3238,8 +3228,7 @@ impl ScriptThread {
.unwrap(); .unwrap();
// Notify devtools that a new script global exists. // Notify devtools that a new script global exists.
let is_top_level_global = let is_top_level_global = incomplete.webview_id.0 == incomplete.browsing_context_id;
incomplete.top_level_browsing_context_id.0 == incomplete.browsing_context_id;
self.notify_devtools( self.notify_devtools(
document.Title(), document.Title(),
final_url.clone(), final_url.clone(),

View file

@ -264,9 +264,7 @@ pub(crate) unsafe fn jsval_to_webdriver(
let window_proxy = window.window_proxy(); let window_proxy = window.window_proxy();
if window_proxy.is_browsing_context_discarded() { if window_proxy.is_browsing_context_discarded() {
Err(WebDriverJSError::StaleElementReference) Err(WebDriverJSError::StaleElementReference)
} else if window_proxy.browsing_context_id() == } else if window_proxy.browsing_context_id() == window_proxy.webview_id() {
window_proxy.top_level_browsing_context_id()
{
Ok(WebDriverJSValue::Window(WebWindow( Ok(WebDriverJSValue::Window(WebWindow(
window.Document().upcast::<Node>().unique_id(), window.Document().upcast::<Node>().unique_id(),
))) )))

View file

@ -32,8 +32,8 @@ use std::rc::{Rc, Weak};
use std::sync::{Arc, Mutex}; use std::sync::{Arc, Mutex};
use std::thread; use std::thread;
pub use base::id::TopLevelBrowsingContextId; pub use base::id::WebViewId;
use base::id::{PipelineNamespace, PipelineNamespaceId, WebViewId}; use base::id::{PipelineNamespace, PipelineNamespaceId};
#[cfg(feature = "bluetooth")] #[cfg(feature = "bluetooth")]
use bluetooth::BluetoothThreadFactory; use bluetooth::BluetoothThreadFactory;
#[cfg(feature = "bluetooth")] #[cfg(feature = "bluetooth")]
@ -312,7 +312,7 @@ impl Servo {
} }
debug_assert_eq!(webrender_gl.get_error(), gleam::gl::NO_ERROR,); debug_assert_eq!(webrender_gl.get_error(), gleam::gl::NO_ERROR,);
// Reserving a namespace to create TopLevelBrowsingContextId. // Reserving a namespace to create WebViewId.
PipelineNamespace::install(PipelineNamespaceId(0)); PipelineNamespace::install(PipelineNamespaceId(0));
// Get both endpoints of a special channel for communication between // Get both endpoints of a special channel for communication between

View file

@ -275,61 +275,58 @@ impl fmt::Display for BrowsingContextGroupId {
} }
} }
thread_local!(pub static TOP_LEVEL_BROWSING_CONTEXT_ID: Cell<Option<TopLevelBrowsingContextId>> = thread_local!(pub static WEBVIEW_ID: Cell<Option<WebViewId>> =
const { Cell::new(None) }); const { Cell::new(None) });
#[derive( #[derive(
Clone, Copy, Deserialize, Eq, Hash, MallocSizeOf, Ord, PartialEq, PartialOrd, Serialize, Clone, Copy, Deserialize, Eq, Hash, MallocSizeOf, Ord, PartialEq, PartialOrd, Serialize,
)] )]
pub struct TopLevelBrowsingContextId(pub BrowsingContextId); pub struct WebViewId(pub BrowsingContextId);
/// An alias to ID of top level browsing context. A web view is usually what people would treat as
/// a normal web page.
pub type WebViewId = TopLevelBrowsingContextId;
size_of_test!(TopLevelBrowsingContextId, 8); size_of_test!(WebViewId, 8);
size_of_test!(Option<TopLevelBrowsingContextId>, 8); size_of_test!(Option<WebViewId>, 8);
impl fmt::Debug for TopLevelBrowsingContextId { impl fmt::Debug for WebViewId {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "TopLevel{:?}", self.0) write!(f, "TopLevel{:?}", self.0)
} }
} }
impl fmt::Display for TopLevelBrowsingContextId { impl fmt::Display for WebViewId {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "TopLevel{}", self.0) write!(f, "TopLevel{}", self.0)
} }
} }
impl TopLevelBrowsingContextId { impl WebViewId {
pub fn new() -> TopLevelBrowsingContextId { pub fn new() -> WebViewId {
TopLevelBrowsingContextId(BrowsingContextId::new()) WebViewId(BrowsingContextId::new())
} }
/// Each script and layout thread should have the top-level browsing context id installed, /// Each script and layout thread should have the top-level browsing context id installed,
/// since it is used by crash reporting. /// since it is used by crash reporting.
pub fn install(id: TopLevelBrowsingContextId) { pub fn install(id: WebViewId) {
TOP_LEVEL_BROWSING_CONTEXT_ID.with(|tls| tls.set(Some(id))) WEBVIEW_ID.with(|tls| tls.set(Some(id)))
} }
pub fn installed() -> Option<TopLevelBrowsingContextId> { pub fn installed() -> Option<WebViewId> {
TOP_LEVEL_BROWSING_CONTEXT_ID.with(|tls| tls.get()) WEBVIEW_ID.with(|tls| tls.get())
} }
} }
impl From<TopLevelBrowsingContextId> for BrowsingContextId { impl From<WebViewId> for BrowsingContextId {
fn from(id: TopLevelBrowsingContextId) -> BrowsingContextId { fn from(id: WebViewId) -> BrowsingContextId {
id.0 id.0
} }
} }
impl PartialEq<TopLevelBrowsingContextId> for BrowsingContextId { impl PartialEq<WebViewId> for BrowsingContextId {
fn eq(&self, rhs: &TopLevelBrowsingContextId) -> bool { fn eq(&self, rhs: &WebViewId) -> bool {
self.eq(&rhs.0) self.eq(&rhs.0)
} }
} }
impl PartialEq<BrowsingContextId> for TopLevelBrowsingContextId { impl PartialEq<BrowsingContextId> for WebViewId {
fn eq(&self, rhs: &BrowsingContextId) -> bool { fn eq(&self, rhs: &BrowsingContextId) -> bool {
self.0.eq(rhs) self.0.eq(rhs)
} }
@ -444,4 +441,4 @@ pub const TEST_BROWSING_CONTEXT_ID: BrowsingContextId = BrowsingContextId {
index: TEST_BROWSING_CONTEXT_INDEX, index: TEST_BROWSING_CONTEXT_INDEX,
}; };
pub const TEST_WEBVIEW_ID: WebViewId = TopLevelBrowsingContextId(TEST_BROWSING_CONTEXT_ID); pub const TEST_WEBVIEW_ID: WebViewId = WebViewId(TEST_BROWSING_CONTEXT_ID);

View file

@ -7,7 +7,7 @@ use std::fmt;
use std::time::Duration; use std::time::Duration;
use base::Epoch; use base::Epoch;
use base::id::{BrowsingContextId, PipelineId, TopLevelBrowsingContextId, WebViewId}; use base::id::{BrowsingContextId, PipelineId, WebViewId};
use embedder_traits::{ use embedder_traits::{
Cursor, InputEvent, MediaSessionActionType, Theme, TraversalDirection, WebDriverCommandMsg, Cursor, InputEvent, MediaSessionActionType, Theme, TraversalDirection, WebDriverCommandMsg,
}; };
@ -28,19 +28,19 @@ pub enum ConstellationMsg {
GetPipeline(BrowsingContextId, IpcSender<Option<PipelineId>>), GetPipeline(BrowsingContextId, IpcSender<Option<PipelineId>>),
/// Request that the constellation send the current focused top-level browsing context id, /// Request that the constellation send the current focused top-level browsing context id,
/// over a provided channel. /// over a provided channel.
GetFocusTopLevelBrowsingContext(IpcSender<Option<TopLevelBrowsingContextId>>), GetFocusTopLevelBrowsingContext(IpcSender<Option<WebViewId>>),
/// Query the constellation to see if the current compositor output is stable /// Query the constellation to see if the current compositor output is stable
IsReadyToSaveImage(HashMap<PipelineId, Epoch>), IsReadyToSaveImage(HashMap<PipelineId, Epoch>),
/// Whether to allow script to navigate. /// Whether to allow script to navigate.
AllowNavigationResponse(PipelineId, bool), AllowNavigationResponse(PipelineId, bool),
/// Request to load a page. /// Request to load a page.
LoadUrl(TopLevelBrowsingContextId, ServoUrl), LoadUrl(WebViewId, ServoUrl),
/// Clear the network cache. /// Clear the network cache.
ClearCache, ClearCache,
/// Request to traverse the joint session history of the provided browsing context. /// Request to traverse the joint session history of the provided browsing context.
TraverseHistory(TopLevelBrowsingContextId, TraversalDirection), TraverseHistory(WebViewId, TraversalDirection),
/// Inform the constellation of a window being resized. /// Inform the constellation of a window being resized.
WindowSize(TopLevelBrowsingContextId, WindowSizeData, WindowSizeType), WindowSize(WebViewId, WindowSizeData, WindowSizeType),
/// Inform the constellation of a theme change. /// Inform the constellation of a theme change.
ThemeChange(Theme), ThemeChange(Theme),
/// Requests that the constellation instruct layout to begin a new tick of the animation. /// Requests that the constellation instruct layout to begin a new tick of the animation.
@ -48,17 +48,17 @@ pub enum ConstellationMsg {
/// Dispatch a webdriver command /// Dispatch a webdriver command
WebDriverCommand(WebDriverCommandMsg), WebDriverCommand(WebDriverCommandMsg),
/// Reload a top-level browsing context. /// Reload a top-level browsing context.
Reload(TopLevelBrowsingContextId), Reload(WebViewId),
/// A log entry, with the top-level browsing context id and thread name /// A log entry, with the top-level browsing context id and thread name
LogEntry(Option<TopLevelBrowsingContextId>, Option<String>, LogEntry), LogEntry(Option<WebViewId>, Option<String>, LogEntry),
/// Create a new top level browsing context. /// Create a new top level browsing context.
NewWebView(ServoUrl, TopLevelBrowsingContextId), NewWebView(ServoUrl, WebViewId),
/// Close a top level browsing context. /// Close a top level browsing context.
CloseWebView(TopLevelBrowsingContextId), CloseWebView(WebViewId),
/// Panic a top level browsing context. /// Panic a top level browsing context.
SendError(Option<TopLevelBrowsingContextId>, String), SendError(Option<WebViewId>, String),
/// Make a webview focused. /// Make a webview focused.
FocusWebView(TopLevelBrowsingContextId), FocusWebView(WebViewId),
/// Make none of the webviews focused. /// Make none of the webviews focused.
BlurWebView, BlurWebView,
/// Forward an input event to an appropriate ScriptTask. /// Forward an input event to an appropriate ScriptTask.
@ -68,11 +68,11 @@ pub enum ConstellationMsg {
/// Enable the sampling profiler, with a given sampling rate and max total sampling duration. /// Enable the sampling profiler, with a given sampling rate and max total sampling duration.
ToggleProfiler(Duration, Duration), ToggleProfiler(Duration, Duration),
/// Request to exit from fullscreen mode /// Request to exit from fullscreen mode
ExitFullScreen(TopLevelBrowsingContextId), ExitFullScreen(WebViewId),
/// Media session action. /// Media session action.
MediaSessionAction(MediaSessionActionType), MediaSessionAction(MediaSessionActionType),
/// Set whether to use less resources, by stopping animations and running timers at a heavily limited rate. /// Set whether to use less resources, by stopping animations and running timers at a heavily limited rate.
SetWebViewThrottled(TopLevelBrowsingContextId, bool), SetWebViewThrottled(WebViewId, bool),
} }
impl fmt::Debug for ConstellationMsg { impl fmt::Debug for ConstellationMsg {

View file

@ -9,7 +9,7 @@ mod constellation_msg;
use std::fmt::{Debug, Error, Formatter}; use std::fmt::{Debug, Error, Formatter};
use base::Epoch; use base::Epoch;
use base::id::{PipelineId, TopLevelBrowsingContextId, WebViewId}; use base::id::{PipelineId, WebViewId};
pub use constellation_msg::ConstellationMsg; pub use constellation_msg::ConstellationMsg;
use crossbeam_channel::{Receiver, Sender}; use crossbeam_channel::{Receiver, Sender};
use embedder_traits::{EventLoopWaker, MouseButton, MouseButtonAction}; use embedder_traits::{EventLoopWaker, MouseButton, MouseButtonAction};
@ -63,7 +63,7 @@ pub enum CompositorMsg {
/// Create or update a webview, given its frame tree. /// Create or update a webview, given its frame tree.
CreateOrUpdateWebView(SendableFrameTree), CreateOrUpdateWebView(SendableFrameTree),
/// Remove a webview. /// Remove a webview.
RemoveWebView(TopLevelBrowsingContextId), RemoveWebView(WebViewId),
/// Script has handled a touch event, and either prevented or allowed default actions. /// Script has handled a touch event, and either prevented or allowed default actions.
TouchEventProcessed(WebViewId, TouchEventResult), TouchEventProcessed(WebViewId, TouchEventResult),
/// Composite to a PNG file and return the Image over a passed channel. /// Composite to a PNG file and return the Image over a passed channel.
@ -87,7 +87,7 @@ pub enum CompositorMsg {
/// WebViewId and PipelienId. /// WebViewId and PipelienId.
PendingPaintMetric(WebViewId, PipelineId, Epoch), PendingPaintMetric(WebViewId, PipelineId, Epoch),
/// The load of a page has completed /// The load of a page has completed
LoadComplete(TopLevelBrowsingContextId), LoadComplete(WebViewId),
/// WebDriver mouse button event /// WebDriver mouse button event
WebDriverMouseButtonEvent(WebViewId, MouseButtonAction, MouseButton, f32, f32), WebDriverMouseButtonEvent(WebViewId, MouseButtonAction, MouseButton, f32, f32),
/// WebDriver mouse move event /// WebDriver mouse move event
@ -107,7 +107,7 @@ pub struct SendableFrameTree {
#[derive(Clone)] #[derive(Clone)]
pub struct CompositionPipeline { pub struct CompositionPipeline {
pub id: PipelineId, pub id: PipelineId,
pub top_level_browsing_context_id: TopLevelBrowsingContextId, pub webview_id: WebViewId,
pub script_chan: IpcSender<ScriptThreadMessage>, pub script_chan: IpcSender<ScriptThreadMessage>,
} }

View file

@ -23,7 +23,7 @@ use base::Epoch;
use base::cross_process_instant::CrossProcessInstant; use base::cross_process_instant::CrossProcessInstant;
use base::id::{ use base::id::{
BlobId, BrowsingContextId, HistoryStateId, MessagePortId, PipelineId, PipelineNamespaceId, BlobId, BrowsingContextId, HistoryStateId, MessagePortId, PipelineId, PipelineNamespaceId,
TopLevelBrowsingContextId, WebViewId, WebViewId,
}; };
use bitflags::bitflags; use bitflags::bitflags;
#[cfg(feature = "bluetooth")] #[cfg(feature = "bluetooth")]
@ -216,7 +216,7 @@ pub struct NewLayoutInfo {
/// Id of the browsing context associated with this pipeline. /// Id of the browsing context associated with this pipeline.
pub browsing_context_id: BrowsingContextId, pub browsing_context_id: BrowsingContextId,
/// Id of the top-level browsing context associated with this pipeline. /// Id of the top-level browsing context associated with this pipeline.
pub top_level_browsing_context_id: TopLevelBrowsingContextId, pub webview_id: WebViewId,
/// Id of the opener, if any /// Id of the opener, if any
pub opener: Option<BrowsingContextId>, pub opener: Option<BrowsingContextId>,
/// Network request data which will be initiated by the script thread. /// Network request data which will be initiated by the script thread.
@ -337,7 +337,7 @@ pub enum ScriptThreadMessage {
/// The source of the message. /// The source of the message.
source: PipelineId, source: PipelineId,
/// The top level browsing context associated with the source pipeline. /// The top level browsing context associated with the source pipeline.
source_browsing_context: TopLevelBrowsingContextId, source_browsing_context: WebViewId,
/// The expected origin of the target. /// The expected origin of the target.
target_origin: Option<ImmutableOrigin>, target_origin: Option<ImmutableOrigin>,
/// The source origin of the message. /// The source origin of the message.
@ -351,7 +351,7 @@ pub enum ScriptThreadMessage {
UpdatePipelineId( UpdatePipelineId(
PipelineId, PipelineId,
BrowsingContextId, BrowsingContextId,
TopLevelBrowsingContextId, WebViewId,
PipelineId, PipelineId,
UpdatePipelineIdReason, UpdatePipelineIdReason,
), ),
@ -497,7 +497,7 @@ pub struct InitialScriptState {
/// The ID of the browsing context this script is part of. /// The ID of the browsing context this script is part of.
pub browsing_context_id: BrowsingContextId, pub browsing_context_id: BrowsingContextId,
/// The ID of the top-level browsing context this script is part of. /// The ID of the top-level browsing context this script is part of.
pub top_level_browsing_context_id: TopLevelBrowsingContextId, pub webview_id: WebViewId,
/// The ID of the opener, if any. /// The ID of the opener, if any.
pub opener: Option<BrowsingContextId>, pub opener: Option<BrowsingContextId>,
/// Loading into a Secure Context /// Loading into a Secure Context
@ -589,7 +589,7 @@ pub struct IFrameLoadInfo {
/// The ID for this iframe's nested browsing context. /// The ID for this iframe's nested browsing context.
pub browsing_context_id: BrowsingContextId, pub browsing_context_id: BrowsingContextId,
/// The ID for the top-level ancestor browsing context of this iframe's nested browsing context. /// The ID for the top-level ancestor browsing context of this iframe's nested browsing context.
pub top_level_browsing_context_id: TopLevelBrowsingContextId, pub webview_id: WebViewId,
/// The new pipeline ID that the iframe has generated. /// The new pipeline ID that the iframe has generated.
pub new_pipeline_id: PipelineId, pub new_pipeline_id: PipelineId,
/// Whether this iframe should be considered private /// Whether this iframe should be considered private

View file

@ -8,8 +8,7 @@ use std::fmt;
use base::Epoch; use base::Epoch;
use base::id::{ use base::id::{
BroadcastChannelRouterId, BrowsingContextId, HistoryStateId, MessagePortId, BroadcastChannelRouterId, BrowsingContextId, HistoryStateId, MessagePortId,
MessagePortRouterId, PipelineId, ServiceWorkerId, ServiceWorkerRegistrationId, MessagePortRouterId, PipelineId, ServiceWorkerId, ServiceWorkerRegistrationId, WebViewId,
TopLevelBrowsingContextId, WebViewId,
}; };
use canvas_traits::canvas::{CanvasId, CanvasMsg}; use canvas_traits::canvas::{CanvasId, CanvasMsg};
use devtools_traits::{ScriptToDevtoolsControlMsg, WorkerId}; use devtools_traits::{ScriptToDevtoolsControlMsg, WorkerId};
@ -150,10 +149,7 @@ pub enum ScriptMsg {
/// Notifies the constellation that this frame has received focus. /// Notifies the constellation that this frame has received focus.
Focus, Focus,
/// Get the top-level browsing context info for a given browsing context. /// Get the top-level browsing context info for a given browsing context.
GetTopForBrowsingContext( GetTopForBrowsingContext(BrowsingContextId, IpcSender<Option<WebViewId>>),
BrowsingContextId,
IpcSender<Option<TopLevelBrowsingContextId>>,
),
/// Get the browsing context id of the browsing context in which pipeline is /// Get the browsing context id of the browsing context in which pipeline is
/// embedded and the parent pipeline id of that browsing context. /// embedded and the parent pipeline id of that browsing context.
GetBrowsingContextInfo( GetBrowsingContextInfo(

View file

@ -279,7 +279,7 @@ impl Handler {
let button = (action.button as u16).into(); let button = (action.button as u16).into();
let cmd_msg = WebDriverCommandMsg::MouseButtonAction( let cmd_msg = WebDriverCommandMsg::MouseButtonAction(
session.top_level_browsing_context_id, session.webview_id,
MouseButtonAction::Down, MouseButtonAction::Down,
button, button,
pointer_input_state.x as f32, pointer_input_state.x as f32,
@ -326,7 +326,7 @@ impl Handler {
let button = (action.button as u16).into(); let button = (action.button as u16).into();
let cmd_msg = WebDriverCommandMsg::MouseButtonAction( let cmd_msg = WebDriverCommandMsg::MouseButtonAction(
session.top_level_browsing_context_id, session.webview_id,
MouseButtonAction::Up, MouseButtonAction::Up,
button, button,
pointer_input_state.x as f32, pointer_input_state.x as f32,
@ -389,10 +389,8 @@ impl Handler {
}; };
let (sender, receiver) = ipc::channel().unwrap(); let (sender, receiver) = ipc::channel().unwrap();
let cmd_msg = WebDriverCommandMsg::GetWindowSize( let cmd_msg =
self.session.as_ref().unwrap().top_level_browsing_context_id, WebDriverCommandMsg::GetWindowSize(self.session.as_ref().unwrap().webview_id, sender);
sender,
);
self.constellation_chan self.constellation_chan
.send(ConstellationMsg::WebDriverCommand(cmd_msg)) .send(ConstellationMsg::WebDriverCommand(cmd_msg))
.unwrap(); .unwrap();
@ -471,11 +469,8 @@ impl Handler {
// Step 7 // Step 7
if x != current_x || y != current_y { if x != current_x || y != current_y {
// Step 7.2 // Step 7.2
let cmd_msg = WebDriverCommandMsg::MouseMoveAction( let cmd_msg =
session.top_level_browsing_context_id, WebDriverCommandMsg::MouseMoveAction(session.webview_id, x as f32, y as f32);
x as f32,
y as f32,
);
self.constellation_chan self.constellation_chan
.send(ConstellationMsg::WebDriverCommand(cmd_msg)) .send(ConstellationMsg::WebDriverCommand(cmd_msg))
.unwrap(); .unwrap();

View file

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