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 base::cross_process_instant::CrossProcessInstant;
use base::id::{PipelineId, TopLevelBrowsingContextId, WebViewId};
use base::id::{PipelineId, WebViewId};
use base::{Epoch, WebRenderEpochToU16};
use bitflags::bitflags;
use compositing_traits::{
@ -542,8 +542,8 @@ impl IOCompositor {
self.set_frame_tree_for_webview(&frame_tree);
},
CompositorMsg::RemoveWebView(top_level_browsing_context_id) => {
self.remove_webview(top_level_browsing_context_id);
CompositorMsg::RemoveWebView(webview_id) => {
self.remove_webview(webview_id);
},
CompositorMsg::TouchEventProcessed(webview_id, result) => {
@ -1097,7 +1097,7 @@ impl IOCompositor {
fn set_frame_tree_for_webview(&mut self, frame_tree: &SendableFrameTree) {
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 {
warn!(
"Attempted to set frame tree on unknown WebView (perhaps closed?): {webview_id:?}"
@ -1119,7 +1119,7 @@ impl IOCompositor {
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:?}");
let rect_changed;
let size_changed;
@ -1203,14 +1203,14 @@ impl IOCompositor {
fn send_window_size_message_for_top_level_browser_context(
&self,
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
// to device pixels, but not including any pinch 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 msg = ConstellationMsg::WindowSize(
top_level_browsing_context_id,
webview_id,
WindowSizeData {
device_pixel_ratio,
initial_viewport,
@ -1320,11 +1320,8 @@ impl IOCompositor {
}
fn update_after_zoom_or_hidpi_change(&mut self) {
for (top_level_browsing_context_id, webview) in self.webviews.painting_order() {
self.send_window_size_message_for_top_level_browser_context(
webview.rect,
*top_level_browsing_context_id,
);
for (webview_id, webview) in self.webviews.painting_order() {
self.send_window_size_message_for_top_level_browser_context(webview.rect, *webview_id);
}
// Update the root transform in WebRender to reflect the new zoom.

View file

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

View file

@ -4,7 +4,7 @@
use std::collections::{HashMap, HashSet};
use base::id::{BrowsingContextGroupId, BrowsingContextId, PipelineId, TopLevelBrowsingContextId};
use base::id::{BrowsingContextGroupId, BrowsingContextId, PipelineId, WebViewId};
use euclid::Size2D;
use log::warn;
use style_traits::CSSPixel;
@ -48,7 +48,7 @@ pub struct BrowsingContext {
pub id: BrowsingContextId,
/// The top-level browsing context ancestor
pub top_level_id: TopLevelBrowsingContextId,
pub top_level_id: WebViewId,
/// The size of the frame.
pub size: Size2D<f32, CSSPixel>,
@ -82,7 +82,7 @@ impl BrowsingContext {
pub fn new(
bc_group_id: BrowsingContextGroupId,
id: BrowsingContextId,
top_level_id: TopLevelBrowsingContextId,
top_level_id: WebViewId,
pipeline_id: PipelineId,
parent_pipeline_id: Option<PipelineId>,
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 backtrace::Backtrace;
use base::id::TopLevelBrowsingContextId;
use base::id::WebViewId;
use compositing_traits::ConstellationMsg as FromCompositorMsg;
use crossbeam_channel::Sender;
use log::{Level, LevelFilter, Log, Metadata, Record};
@ -87,7 +87,7 @@ impl Log for FromCompositorLogger {
fn log(&self, record: &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 msg = FromCompositorMsg::LogEntry(top_level_id, thread_name, entry);
let chan = self.constellation_chan.lock();

View file

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

View file

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

View file

@ -4,16 +4,16 @@
use std::collections::HashMap;
use base::id::TopLevelBrowsingContextId;
use base::id::WebViewId;
#[derive(Debug)]
pub struct WebViewManager<WebView> {
/// 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.
webviews: HashMap<TopLevelBrowsingContextId, WebView>,
webviews: HashMap<WebViewId, WebView>,
/// 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.
is_focused: bool,
@ -30,63 +30,47 @@ impl<WebView> Default for WebViewManager<WebView> {
}
impl<WebView> WebViewManager<WebView> {
pub fn add(
&mut self,
top_level_browsing_context_id: TopLevelBrowsingContextId,
webview: WebView,
) {
self.webviews.insert(top_level_browsing_context_id, webview);
pub fn add(&mut self, webview_id: WebViewId, webview: WebView) {
self.webviews.insert(webview_id, webview);
}
pub fn remove(
&mut self,
top_level_browsing_context_id: TopLevelBrowsingContextId,
) -> Option<WebView> {
if self.focus_order.last() == Some(&top_level_browsing_context_id) {
pub fn remove(&mut self, webview_id: WebViewId) -> Option<WebView> {
if self.focus_order.last() == Some(&webview_id) {
self.is_focused = false;
}
self.focus_order
.retain(|b| *b != top_level_browsing_context_id);
self.webviews.remove(&top_level_browsing_context_id)
self.focus_order.retain(|b| *b != webview_id);
self.webviews.remove(&webview_id)
}
pub fn get(
&self,
top_level_browsing_context_id: TopLevelBrowsingContextId,
) -> Option<&WebView> {
self.webviews.get(&top_level_browsing_context_id)
pub fn get(&self, webview_id: WebViewId) -> Option<&WebView> {
self.webviews.get(&webview_id)
}
pub fn get_mut(
&mut self,
top_level_browsing_context_id: TopLevelBrowsingContextId,
) -> Option<&mut WebView> {
self.webviews.get_mut(&top_level_browsing_context_id)
pub fn get_mut(&mut self, webview_id: WebViewId) -> Option<&mut WebView> {
self.webviews.get_mut(&webview_id)
}
pub fn focused_webview(&self) -> Option<(TopLevelBrowsingContextId, &WebView)> {
pub fn focused_webview(&self) -> Option<(WebViewId, &WebView)> {
if !self.is_focused {
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!(
self.webviews.contains_key(&top_level_browsing_context_id),
self.webviews.contains_key(&webview_id),
"BUG: webview in .focus_order not in .webviews!",
);
self.get(top_level_browsing_context_id)
.map(|webview| (top_level_browsing_context_id, webview))
self.get(webview_id).map(|webview| (webview_id, webview))
} else {
debug_assert!(false, "BUG: .is_focused but no webviews in .focus_order!");
None
}
}
pub fn focus(&mut self, top_level_browsing_context_id: TopLevelBrowsingContextId) {
debug_assert!(self.webviews.contains_key(&top_level_browsing_context_id));
self.focus_order
.retain(|b| *b != top_level_browsing_context_id);
self.focus_order.push(top_level_browsing_context_id);
pub fn focus(&mut self, webview_id: WebViewId) {
debug_assert!(self.webviews.contains_key(&webview_id));
self.focus_order.retain(|b| *b != webview_id);
self.focus_order.push(webview_id);
self.is_focused = true;
}
@ -100,14 +84,13 @@ mod test {
use std::num::NonZeroU32;
use base::id::{
BrowsingContextId, BrowsingContextIndex, PipelineNamespace, PipelineNamespaceId,
TopLevelBrowsingContextId, WebViewId,
BrowsingContextId, BrowsingContextIndex, PipelineNamespace, PipelineNamespaceId, WebViewId,
};
use crate::webview::WebViewManager;
fn id(namespace_id: u32, index: u32) -> WebViewId {
TopLevelBrowsingContextId(BrowsingContextId {
WebViewId(BrowsingContextId {
namespace_id: PipelineNamespaceId(namespace_id),
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::thread::{self, JoinHandle};
use base::id::{BrowsingContextId, PipelineId, TopLevelBrowsingContextId, WebViewId};
use base::id::{BrowsingContextId, PipelineId, WebViewId};
use crossbeam_channel::{Receiver, Sender, unbounded};
use devtools_traits::DevtoolScriptControlMsg;
use dom_struct::dom_struct;
@ -349,7 +349,7 @@ impl DedicatedWorkerGlobalScope {
insecure_requests_policy: InsecureRequestsPolicy,
) -> JoinHandle<()> {
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 origin = current_global.origin().immutable().clone();
let referrer = current_global.get_referrer();
@ -361,8 +361,8 @@ impl DedicatedWorkerGlobalScope {
.spawn(move || {
thread_state::initialize(ThreadState::SCRIPT | ThreadState::IN_WORKER);
if let Some(top_level_browsing_context_id) = top_level_browsing_context_id {
TopLevelBrowsingContextId::install(top_level_browsing_context_id);
if let Some(webview_id) = webview_id {
WebViewId::install(webview_id);
}
let roots = RootCollection::new();
@ -376,21 +376,17 @@ impl DedicatedWorkerGlobalScope {
let referrer = referrer_url.map(Referrer::ReferrerUrl).unwrap_or(referrer);
let request = RequestBuilder::new(
top_level_browsing_context_id,
worker_url.clone(),
referrer,
)
.destination(Destination::Worker)
.mode(RequestMode::SameOrigin)
.credentials_mode(CredentialsMode::CredentialsSameOrigin)
.parser_metadata(ParserMetadata::NotParserInserted)
.use_url_credentials(true)
.pipeline_id(Some(pipeline_id))
.referrer_policy(referrer_policy)
.referrer_policy(referrer_policy)
.insecure_requests_policy(insecure_requests_policy)
.origin(origin);
let request = RequestBuilder::new(webview_id, worker_url.clone(), referrer)
.destination(Destination::Worker)
.mode(RequestMode::SameOrigin)
.credentials_mode(CredentialsMode::CredentialsSameOrigin)
.parser_metadata(ParserMetadata::NotParserInserted)
.use_url_credentials(true)
.pipeline_id(Some(pipeline_id))
.referrer_policy(referrer_policy)
.referrer_policy(referrer_policy)
.insecure_requests_policy(insecure_requests_policy)
.origin(origin);
let runtime = unsafe {
let task_source = SendableTaskSource {

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -32,8 +32,8 @@ use std::rc::{Rc, Weak};
use std::sync::{Arc, Mutex};
use std::thread;
pub use base::id::TopLevelBrowsingContextId;
use base::id::{PipelineNamespace, PipelineNamespaceId, WebViewId};
pub use base::id::WebViewId;
use base::id::{PipelineNamespace, PipelineNamespaceId};
#[cfg(feature = "bluetooth")]
use bluetooth::BluetoothThreadFactory;
#[cfg(feature = "bluetooth")]
@ -312,7 +312,7 @@ impl Servo {
}
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));
// 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) });
#[derive(
Clone, Copy, Deserialize, Eq, Hash, MallocSizeOf, Ord, PartialEq, PartialOrd, Serialize,
)]
pub struct TopLevelBrowsingContextId(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;
pub struct WebViewId(pub BrowsingContextId);
size_of_test!(TopLevelBrowsingContextId, 8);
size_of_test!(Option<TopLevelBrowsingContextId>, 8);
size_of_test!(WebViewId, 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 {
write!(f, "TopLevel{:?}", self.0)
}
}
impl fmt::Display for TopLevelBrowsingContextId {
impl fmt::Display for WebViewId {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "TopLevel{}", self.0)
}
}
impl TopLevelBrowsingContextId {
pub fn new() -> TopLevelBrowsingContextId {
TopLevelBrowsingContextId(BrowsingContextId::new())
impl WebViewId {
pub fn new() -> WebViewId {
WebViewId(BrowsingContextId::new())
}
/// Each script and layout thread should have the top-level browsing context id installed,
/// since it is used by crash reporting.
pub fn install(id: TopLevelBrowsingContextId) {
TOP_LEVEL_BROWSING_CONTEXT_ID.with(|tls| tls.set(Some(id)))
pub fn install(id: WebViewId) {
WEBVIEW_ID.with(|tls| tls.set(Some(id)))
}
pub fn installed() -> Option<TopLevelBrowsingContextId> {
TOP_LEVEL_BROWSING_CONTEXT_ID.with(|tls| tls.get())
pub fn installed() -> Option<WebViewId> {
WEBVIEW_ID.with(|tls| tls.get())
}
}
impl From<TopLevelBrowsingContextId> for BrowsingContextId {
fn from(id: TopLevelBrowsingContextId) -> BrowsingContextId {
impl From<WebViewId> for BrowsingContextId {
fn from(id: WebViewId) -> BrowsingContextId {
id.0
}
}
impl PartialEq<TopLevelBrowsingContextId> for BrowsingContextId {
fn eq(&self, rhs: &TopLevelBrowsingContextId) -> bool {
impl PartialEq<WebViewId> for BrowsingContextId {
fn eq(&self, rhs: &WebViewId) -> bool {
self.eq(&rhs.0)
}
}
impl PartialEq<BrowsingContextId> for TopLevelBrowsingContextId {
impl PartialEq<BrowsingContextId> for WebViewId {
fn eq(&self, rhs: &BrowsingContextId) -> bool {
self.0.eq(rhs)
}
@ -444,4 +441,4 @@ pub const TEST_BROWSING_CONTEXT_ID: BrowsingContextId = BrowsingContextId {
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 base::Epoch;
use base::id::{BrowsingContextId, PipelineId, TopLevelBrowsingContextId, WebViewId};
use base::id::{BrowsingContextId, PipelineId, WebViewId};
use embedder_traits::{
Cursor, InputEvent, MediaSessionActionType, Theme, TraversalDirection, WebDriverCommandMsg,
};
@ -28,19 +28,19 @@ pub enum ConstellationMsg {
GetPipeline(BrowsingContextId, IpcSender<Option<PipelineId>>),
/// Request that the constellation send the current focused top-level browsing context id,
/// over a provided channel.
GetFocusTopLevelBrowsingContext(IpcSender<Option<TopLevelBrowsingContextId>>),
GetFocusTopLevelBrowsingContext(IpcSender<Option<WebViewId>>),
/// Query the constellation to see if the current compositor output is stable
IsReadyToSaveImage(HashMap<PipelineId, Epoch>),
/// Whether to allow script to navigate.
AllowNavigationResponse(PipelineId, bool),
/// Request to load a page.
LoadUrl(TopLevelBrowsingContextId, ServoUrl),
LoadUrl(WebViewId, ServoUrl),
/// Clear the network cache.
ClearCache,
/// 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.
WindowSize(TopLevelBrowsingContextId, WindowSizeData, WindowSizeType),
WindowSize(WebViewId, WindowSizeData, WindowSizeType),
/// Inform the constellation of a theme change.
ThemeChange(Theme),
/// 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
WebDriverCommand(WebDriverCommandMsg),
/// Reload a top-level browsing context.
Reload(TopLevelBrowsingContextId),
Reload(WebViewId),
/// 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.
NewWebView(ServoUrl, TopLevelBrowsingContextId),
NewWebView(ServoUrl, WebViewId),
/// Close a top level browsing context.
CloseWebView(TopLevelBrowsingContextId),
CloseWebView(WebViewId),
/// Panic a top level browsing context.
SendError(Option<TopLevelBrowsingContextId>, String),
SendError(Option<WebViewId>, String),
/// Make a webview focused.
FocusWebView(TopLevelBrowsingContextId),
FocusWebView(WebViewId),
/// Make none of the webviews focused.
BlurWebView,
/// 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.
ToggleProfiler(Duration, Duration),
/// Request to exit from fullscreen mode
ExitFullScreen(TopLevelBrowsingContextId),
ExitFullScreen(WebViewId),
/// Media session action.
MediaSessionAction(MediaSessionActionType),
/// 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 {

View file

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

View file

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

View file

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

View file

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

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();