From 2464d0937ffbf7697ca2e1193a6d12c28be28b16 Mon Sep 17 00:00:00 2001 From: Martin Robinson Date: Tue, 11 Mar 2025 11:56:10 +0100 Subject: [PATCH] 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 --- components/compositing/compositor.rs | 21 +- components/compositing/webview.rs | 15 +- components/constellation/browsingcontext.rs | 6 +- components/constellation/constellation.rs | 451 ++++++++---------- components/constellation/logging.rs | 4 +- components/constellation/pipeline.rs | 27 +- components/constellation/session_history.rs | 4 +- components/constellation/webview.rs | 63 +-- .../script/dom/dedicatedworkerglobalscope.rs | 34 +- components/script/dom/htmliframeelement.rs | 23 +- components/script/dom/windowproxy.rs | 22 +- components/script/navigation.rs | 12 +- components/script/script_thread.rs | 65 ++- components/script/webdriver_handlers.rs | 4 +- components/servo/lib.rs | 6 +- components/shared/base/id.rs | 41 +- .../shared/compositing/constellation_msg.rs | 26 +- components/shared/compositing/lib.rs | 8 +- components/shared/script/lib.rs | 12 +- components/shared/script/script_msg.rs | 8 +- components/webdriver_server/actions.rs | 17 +- components/webdriver_server/lib.rs | 117 ++--- 22 files changed, 416 insertions(+), 570 deletions(-) diff --git a/components/compositing/compositor.rs b/components/compositing/compositor.rs index bb4bb416edd..ffc9f417384 100644 --- a/components/compositing/compositor.rs +++ b/components/compositing/compositor.rs @@ -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. diff --git a/components/compositing/webview.rs b/components/compositing/webview.rs index a4da68d8d52..a0989c24b0a 100644 --- a/components/compositing/webview.rs +++ b/components/compositing/webview.rs @@ -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( webviews: &WebViewManager, - ) -> Vec<(TopLevelBrowsingContextId, WebView)> { + ) -> Vec<(WebViewId, WebView)> { let mut keys = webviews.webviews.keys().collect::>(); 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![ diff --git a/components/constellation/browsingcontext.rs b/components/constellation/browsingcontext.rs index 9582d768d50..6f8b24dabcb 100644 --- a/components/constellation/browsingcontext.rs +++ b/components/constellation/browsingcontext.rs @@ -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, @@ -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, size: Size2D, diff --git a/components/constellation/constellation.rs b/components/constellation/constellation.rs index ed9e0face68..f8cedbd4ecd 100644 --- a/components/constellation/constellation.rs +++ b/components/constellation/constellation.rs @@ -101,7 +101,7 @@ use base::Epoch; use base::id::{ BroadcastChannelRouterId, BrowsingContextGroupId, BrowsingContextId, HistoryStateId, MessagePortId, MessagePortRouterId, PipelineId, PipelineNamespace, PipelineNamespaceId, - PipelineNamespaceRequest, TopLevelBrowsingContextId, WebViewId, + PipelineNamespaceRequest, WebViewId, }; #[cfg(feature = "bluetooth")] use bluetooth_traits::BluetoothRequest; @@ -243,7 +243,7 @@ struct WebView { #[derive(Clone, Default)] struct BrowsingContextGroup { /// A browsing context group holds a set of top-level browsing contexts. - top_level_browsing_context_set: HashSet, + top_level_browsing_context_set: HashSet, /// The set of all event loops in this BrowsingContextGroup. /// We store the event loops in a map @@ -787,7 +787,7 @@ where fn get_event_loop( &mut self, host: &Host, - top_level_browsing_context_id: &TopLevelBrowsingContextId, + webview_id: &WebViewId, opener: &Option, ) -> Result, &'static str> { let bc_group = match opener { @@ -806,7 +806,7 @@ where .filter_map(|(_, bc_group)| { if bc_group .top_level_browsing_context_set - .contains(top_level_browsing_context_id) + .contains(webview_id) { Some(bc_group) } else { @@ -829,7 +829,7 @@ where &mut self, event_loop: Weak, host: Host, - top_level_browsing_context_id: TopLevelBrowsingContextId, + webview_id: WebViewId, opener: Option, ) { let relevant_top_level = if let Some(opener) = opener { @@ -841,7 +841,7 @@ where }, } } else { - top_level_browsing_context_id + webview_id }; let maybe_bc_group_id = self .browsing_context_group_set @@ -849,7 +849,7 @@ where .filter_map(|(id, bc_group)| { if bc_group .top_level_browsing_context_set - .contains(&top_level_browsing_context_id) + .contains(&webview_id) { Some(*id) } else { @@ -884,7 +884,7 @@ where &mut self, pipeline_id: PipelineId, browsing_context_id: BrowsingContextId, - top_level_browsing_context_id: TopLevelBrowsingContextId, + webview_id: WebViewId, parent_pipeline_id: Option, opener: Option, initial_window_size: Size2D, @@ -916,24 +916,18 @@ where { match reg_host(&load_data.url) { None => (None, None), - Some(host) => { - match self.get_event_loop( - &host, - &top_level_browsing_context_id, - &opener, - ) { - Err(err) => { - warn!("{}", err); + Some(host) => match self.get_event_loop(&host, &webview_id, &opener) { + Err(err) => { + warn!("{}", err); + (None, Some(host)) + }, + Ok(event_loop) => { + if let Some(event_loop) = event_loop.upgrade() { + (Some(event_loop), None) + } else { (None, Some(host)) - }, - Ok(event_loop) => { - if let Some(event_loop) = event_loop.upgrade() { - (Some(event_loop), None) - } else { - (None, Some(host)) - } - }, - } + } + }, }, } } else if let Some(parent) = @@ -960,7 +954,7 @@ where let result = Pipeline::spawn::(InitialPipelineState { id: pipeline_id, browsing_context_id, - top_level_browsing_context_id, + webview_id, parent_pipeline_id, opener, script_to_constellation_chan: ScriptToConstellationChan { @@ -1012,14 +1006,11 @@ where } if let Some(host) = host { - debug!( - "{}: Adding new host entry {}", - top_level_browsing_context_id, host, - ); + debug!("{}: Adding new host entry {}", webview_id, host,); self.set_event_loop( Rc::downgrade(&pipeline.pipeline.event_loop), host, - top_level_browsing_context_id, + webview_id, opener, ); } @@ -1043,11 +1034,9 @@ where /// Get an iterator for the fully active browsing contexts in a tree. fn fully_active_browsing_contexts_iter( &self, - top_level_browsing_context_id: TopLevelBrowsingContextId, + webview_id: WebViewId, ) -> FullyActiveBrowsingContextsIterator { - self.fully_active_descendant_browsing_contexts_iter(BrowsingContextId::from( - top_level_browsing_context_id, - )) + self.fully_active_descendant_browsing_contexts_iter(BrowsingContextId::from(webview_id)) } /// Get an iterator for the browsing contexts in a subtree. @@ -1067,7 +1056,7 @@ where fn new_browsing_context( &mut self, browsing_context_id: BrowsingContextId, - top_level_id: TopLevelBrowsingContextId, + top_level_id: WebViewId, pipeline_id: PipelineId, parent_pipeline_id: Option, size: Size2D, @@ -1268,24 +1257,19 @@ where FromCompositorMsg::AllowNavigationResponse(pipeline_id, allowed) => { let pending = self.pending_approval_navigations.remove(&pipeline_id); - let top_level_browsing_context_id = match self.pipelines.get(&pipeline_id) { - Some(pipeline) => pipeline.top_level_browsing_context_id, + let webview_id = match self.pipelines.get(&pipeline_id) { + Some(pipeline) => pipeline.webview_id, None => return warn!("{}: Attempted to navigate after closure", pipeline_id), }; match pending { Some((load_data, history_handling)) => { if allowed { - self.load_url( - top_level_browsing_context_id, - pipeline_id, - load_data, - history_handling, - ); + self.load_url(webview_id, pipeline_id, load_data, history_handling); } else { let pipeline_is_top_level_pipeline = self .browsing_contexts - .get(&BrowsingContextId::from(top_level_browsing_context_id)) + .get(&BrowsingContextId::from(webview_id)) .map(|ctx| ctx.pipeline_id == pipeline_id) .unwrap_or(false); // If the navigation is refused, and this concerns an iframe, @@ -1324,7 +1308,7 @@ where // Load a new page from a typed url // If there is already a pending page (self.pending_changes), it will not be overridden; // However, if the id is not encompassed by another change, it will be. - FromCompositorMsg::LoadUrl(top_level_browsing_context_id, url) => { + FromCompositorMsg::LoadUrl(webview_id, url) => { let load_data = LoadData::new( LoadOrigin::Constellation, url, @@ -1334,20 +1318,17 @@ where None, None, ); - let ctx_id = BrowsingContextId::from(top_level_browsing_context_id); + let ctx_id = BrowsingContextId::from(webview_id); let pipeline_id = match self.browsing_contexts.get(&ctx_id) { Some(ctx) => ctx.pipeline_id, None => { - return warn!( - "{}: LoadUrl for unknown browsing context", - top_level_browsing_context_id - ); + return warn!("{}: LoadUrl for unknown browsing context", webview_id); }, }; // Since this is a top-level load, initiated by the embedder, go straight to load_url, // bypassing schedule_navigation. self.load_url( - top_level_browsing_context_id, + webview_id, pipeline_id, load_data, NavigationHistoryBehavior::Push, @@ -1363,38 +1344,34 @@ where }, // Create a new top level browsing context. Will use response_chan to return // the browsing context id. - FromCompositorMsg::NewWebView(url, top_level_browsing_context_id) => { - self.handle_new_top_level_browsing_context( - url, - top_level_browsing_context_id, - None, - ); + FromCompositorMsg::NewWebView(url, webview_id) => { + self.handle_new_top_level_browsing_context(url, webview_id, None); }, // Close a top level browsing context. - FromCompositorMsg::CloseWebView(top_level_browsing_context_id) => { - self.handle_close_top_level_browsing_context(top_level_browsing_context_id); + FromCompositorMsg::CloseWebView(webview_id) => { + self.handle_close_top_level_browsing_context(webview_id); }, // Panic a top level browsing context. - FromCompositorMsg::SendError(top_level_browsing_context_id, error) => { + FromCompositorMsg::SendError(webview_id, error) => { debug!("constellation got SendError message"); - if top_level_browsing_context_id.is_none() { + if webview_id.is_none() { warn!("constellation got a SendError message without top level id"); } - self.handle_panic(top_level_browsing_context_id, error, None); + self.handle_panic(webview_id, error, None); }, - FromCompositorMsg::FocusWebView(top_level_browsing_context_id) => { - self.handle_focus_web_view(top_level_browsing_context_id); + FromCompositorMsg::FocusWebView(webview_id) => { + self.handle_focus_web_view(webview_id); }, FromCompositorMsg::BlurWebView => { self.webviews.unfocus(); self.embedder_proxy.send(EmbedderMsg::WebViewBlurred); }, // Handle a forward or back request - FromCompositorMsg::TraverseHistory(top_level_browsing_context_id, direction) => { - self.handle_traverse_history_msg(top_level_browsing_context_id, direction); + FromCompositorMsg::TraverseHistory(webview_id, direction) => { + self.handle_traverse_history_msg(webview_id, direction); }, - FromCompositorMsg::WindowSize(top_level_browsing_context_id, new_size, size_type) => { - self.handle_window_size_msg(top_level_browsing_context_id, new_size, size_type); + FromCompositorMsg::WindowSize(webview_id, new_size, size_type) => { + self.handle_window_size_msg(webview_id, new_size, size_type); }, FromCompositorMsg::ThemeChange(theme) => { self.handle_theme_change(theme); @@ -1405,11 +1382,11 @@ where FromCompositorMsg::WebDriverCommand(command) => { self.handle_webdriver_msg(command); }, - FromCompositorMsg::Reload(top_level_browsing_context_id) => { - self.handle_reload_msg(top_level_browsing_context_id); + FromCompositorMsg::Reload(webview_id) => { + self.handle_reload_msg(webview_id); }, - FromCompositorMsg::LogEntry(top_level_browsing_context_id, thread_name, entry) => { - self.handle_log_entry(top_level_browsing_context_id, thread_name, entry); + FromCompositorMsg::LogEntry(webview_id, thread_name, entry) => { + self.handle_log_entry(webview_id, thread_name, entry); }, FromCompositorMsg::ForwardInputEvent(webview_id, event, hit_test) => { self.forward_input_event(webview_id, event, hit_test); @@ -1426,8 +1403,8 @@ where } } }, - FromCompositorMsg::ExitFullScreen(top_level_browsing_context_id) => { - self.handle_exit_fullscreen_msg(top_level_browsing_context_id); + FromCompositorMsg::ExitFullScreen(webview_id) => { + self.handle_exit_fullscreen_msg(webview_id); }, FromCompositorMsg::MediaSessionAction(action) => { self.handle_media_session_action_msg(action); @@ -1449,7 +1426,7 @@ where let webview_id = match self .pipelines .get(&source_pipeline_id) - .map(|pipeline| pipeline.top_level_browsing_context_id) + .map(|pipeline| pipeline.webview_id) { None => return warn!("{}: ScriptMsg from closed pipeline", source_pipeline_id), Some(ctx) => ctx, @@ -2719,12 +2696,12 @@ where fn handle_send_error(&mut self, pipeline_id: PipelineId, err: IpcError) { // Treat send error the same as receiving a panic message error!("{}: Send error ({})", pipeline_id, err); - let top_level_browsing_context_id = self + let webview_id = self .pipelines .get(&pipeline_id) - .map(|pipeline| pipeline.top_level_browsing_context_id); + .map(|pipeline| pipeline.webview_id); let reason = format!("Send failed ({})", err); - self.handle_panic(top_level_browsing_context_id, reason, None); + self.handle_panic(webview_id, reason, None); } #[cfg_attr( @@ -2733,7 +2710,7 @@ where )] fn handle_panic( &mut self, - top_level_browsing_context_id: Option, + webview_id: Option, reason: String, backtrace: Option, ) { @@ -2744,20 +2721,20 @@ where process::exit(1); } - let top_level_browsing_context_id = match top_level_browsing_context_id { + let webview_id = match webview_id { Some(id) => id, None => return, }; debug!( "{}: Panic handler for top-level browsing context: {}", - top_level_browsing_context_id, reason + webview_id, reason ); - let browsing_context_id = BrowsingContextId::from(top_level_browsing_context_id); + let browsing_context_id = BrowsingContextId::from(webview_id); self.embedder_proxy.send(EmbedderMsg::Panic( - top_level_browsing_context_id, + webview_id, reason.clone(), backtrace.clone(), )); @@ -2808,7 +2785,7 @@ where self.new_pipeline( new_pipeline_id, browsing_context_id, - top_level_browsing_context_id, + webview_id, None, opener, window_size, @@ -2818,7 +2795,7 @@ where throttled, ); self.add_pending_change(SessionHistoryChange { - top_level_browsing_context_id, + webview_id, browsing_context_id, new_pipeline_id, // Pipeline already closed by close_browsing_context_children, so we can pass Yes here @@ -2833,15 +2810,13 @@ where feature = "tracing", tracing::instrument(skip_all, fields(servo_profiling = true), level = "trace") )] - fn handle_focus_web_view(&mut self, top_level_browsing_context_id: TopLevelBrowsingContextId) { - if self.webviews.get(top_level_browsing_context_id).is_none() { - return warn!( - "{top_level_browsing_context_id}: FocusWebView on unknown top-level browsing context" - ); + fn handle_focus_web_view(&mut self, webview_id: WebViewId) { + if self.webviews.get(webview_id).is_none() { + return warn!("{webview_id}: FocusWebView on unknown top-level browsing context"); } - self.webviews.focus(top_level_browsing_context_id); + self.webviews.focus(webview_id); self.embedder_proxy - .send(EmbedderMsg::WebViewFocused(top_level_browsing_context_id)); + .send(EmbedderMsg::WebViewFocused(webview_id)); } #[cfg_attr( @@ -2850,16 +2825,12 @@ where )] fn handle_log_entry( &mut self, - top_level_browsing_context_id: Option, + webview_id: Option, thread_name: Option, entry: LogEntry, ) { if let LogEntry::Panic(ref reason, ref backtrace) = entry { - self.handle_panic( - top_level_browsing_context_id, - reason.clone(), - Some(backtrace.clone()), - ); + self.handle_panic(webview_id, reason.clone(), Some(backtrace.clone())); } match entry { @@ -2969,12 +2940,12 @@ where fn handle_new_top_level_browsing_context( &mut self, url: ServoUrl, - top_level_browsing_context_id: TopLevelBrowsingContextId, + webview_id: WebViewId, response_sender: Option>, ) { let window_size = self.window_size.initial_viewport; let pipeline_id = PipelineId::new(); - let browsing_context_id = BrowsingContextId::from(top_level_browsing_context_id); + let browsing_context_id = BrowsingContextId::from(webview_id); let load_data = LoadData::new( LoadOrigin::Constellation, url, @@ -2991,7 +2962,7 @@ where // Register this new top-level browsing context id as a webview and set // its focused browsing context to be itself. self.webviews.add( - top_level_browsing_context_id, + webview_id, WebView { focused_browsing_context_id: browsing_context_id, session_history: JointSessionHistory::new(), @@ -3003,14 +2974,14 @@ where let new_bc_group_id = self.next_browsing_context_group_id(); new_bc_group .top_level_browsing_context_set - .insert(top_level_browsing_context_id); + .insert(webview_id); self.browsing_context_group_set .insert(new_bc_group_id, new_bc_group); self.new_pipeline( pipeline_id, browsing_context_id, - top_level_browsing_context_id, + webview_id, None, None, window_size, @@ -3020,7 +2991,7 @@ where throttled, ); self.add_pending_change(SessionHistoryChange { - top_level_browsing_context_id, + webview_id, browsing_context_id, new_pipeline_id: pipeline_id, replace: None, @@ -3042,23 +3013,19 @@ where feature = "tracing", tracing::instrument(skip_all, fields(servo_profiling = true), level = "trace") )] - fn handle_close_top_level_browsing_context( - &mut self, - top_level_browsing_context_id: TopLevelBrowsingContextId, - ) { - debug!("{top_level_browsing_context_id}: Closing"); - let browsing_context_id = BrowsingContextId::from(top_level_browsing_context_id); + fn handle_close_top_level_browsing_context(&mut self, webview_id: WebViewId) { + debug!("{webview_id}: Closing"); + let browsing_context_id = BrowsingContextId::from(webview_id); let browsing_context = self.close_browsing_context(browsing_context_id, ExitPipelineMode::Normal); - if self.webviews.focused_webview().map(|(id, _)| id) == Some(top_level_browsing_context_id) - { + if self.webviews.focused_webview().map(|(id, _)| id) == Some(webview_id) { self.embedder_proxy.send(EmbedderMsg::WebViewBlurred); } - self.webviews.remove(top_level_browsing_context_id); + self.webviews.remove(webview_id); self.compositor_proxy - .send(CompositorMsg::RemoveWebView(top_level_browsing_context_id)); + .send(CompositorMsg::RemoveWebView(webview_id)); self.embedder_proxy - .send(EmbedderMsg::WebViewClosed(top_level_browsing_context_id)); + .send(EmbedderMsg::WebViewClosed(webview_id)); let Some(browsing_context) = browsing_context else { return; @@ -3069,20 +3036,15 @@ where warn!("{}: Browsing context group not found!", bc_group_id); return; }; - if !bc_group - .top_level_browsing_context_set - .remove(&top_level_browsing_context_id) - { - warn!( - "{top_level_browsing_context_id}: Top-level browsing context not found in {bc_group_id}", - ); + if !bc_group.top_level_browsing_context_set.remove(&webview_id) { + warn!("{webview_id}: Top-level browsing context not found in {bc_group_id}",); } if bc_group.top_level_browsing_context_set.is_empty() { self.browsing_context_group_set .remove(&browsing_context.bc_group_id); } - debug!("{top_level_browsing_context_id}: Closed"); + debug!("{webview_id}: Closed"); } #[cfg_attr( @@ -3161,7 +3123,7 @@ where let IFrameLoadInfo { parent_pipeline_id, browsing_context_id, - top_level_browsing_context_id, + webview_id, new_pipeline_id, is_private, mut history_handling, @@ -3244,7 +3206,7 @@ where self.new_pipeline( new_pipeline_id, browsing_context_id, - top_level_browsing_context_id, + webview_id, Some(parent_pipeline_id), None, browsing_context_size, @@ -3254,7 +3216,7 @@ where browsing_context_throttled, ); self.add_pending_change(SessionHistoryChange { - top_level_browsing_context_id, + webview_id, browsing_context_id, new_pipeline_id, replace, @@ -3273,7 +3235,7 @@ where parent_pipeline_id, new_pipeline_id, browsing_context_id, - top_level_browsing_context_id, + webview_id, is_private, .. } = load_info.info; @@ -3302,7 +3264,7 @@ where let pipeline = Pipeline::new( new_pipeline_id, browsing_context_id, - top_level_browsing_context_id, + webview_id, None, script_sender, self.compositor_proxy.clone(), @@ -3313,7 +3275,7 @@ where assert!(!self.pipelines.contains_key(&new_pipeline_id)); self.pipelines.insert(new_pipeline_id, pipeline); self.add_pending_change(SessionHistoryChange { - top_level_browsing_context_id, + webview_id, browsing_context_id, new_pipeline_id, replace: None, @@ -3427,7 +3389,7 @@ where .insert(new_webview_id); self.add_pending_change(SessionHistoryChange { - top_level_browsing_context_id: new_webview_id, + webview_id: new_webview_id, browsing_context_id: new_browsing_context_id, new_pipeline_id, replace: None, @@ -3483,7 +3445,7 @@ where pipeline.animation_state = animation_state; self.compositor_proxy .send(CompositorMsg::ChangeRunningAnimationsState( - pipeline.top_level_browsing_context_id, + pipeline.webview_id, pipeline_id, animation_state, )) @@ -3516,7 +3478,7 @@ where )] fn schedule_navigation( &mut self, - top_level_browsing_context_id: TopLevelBrowsingContextId, + webview_id: WebViewId, source_id: PipelineId, load_data: LoadData, history_handling: NavigationHistoryBehavior, @@ -3535,7 +3497,7 @@ where // Allow the embedder to handle the url itself self.embedder_proxy .send(EmbedderMsg::AllowNavigationRequest( - top_level_browsing_context_id, + webview_id, source_id, load_data.url.clone(), )); @@ -3547,7 +3509,7 @@ where )] fn load_url( &mut self, - top_level_browsing_context_id: TopLevelBrowsingContextId, + webview_id: WebViewId, source_id: PipelineId, load_data: LoadData, history_handling: NavigationHistoryBehavior, @@ -3652,7 +3614,7 @@ where self.new_pipeline( new_pipeline_id, browsing_context_id, - top_level_browsing_context_id, + webview_id, None, opener, window_size, @@ -3662,7 +3624,7 @@ where is_throttled, ); self.add_pending_change(SessionHistoryChange { - top_level_browsing_context_id, + webview_id, browsing_context_id, new_pipeline_id, replace, @@ -3700,11 +3662,7 @@ where feature = "tracing", tracing::instrument(skip_all, fields(servo_profiling = true), level = "trace") )] - fn handle_load_complete_msg( - &mut self, - top_level_browsing_context_id: TopLevelBrowsingContextId, - pipeline_id: PipelineId, - ) { + fn handle_load_complete_msg(&mut self, webview_id: WebViewId, pipeline_id: PipelineId) { let mut webdriver_reset = false; if let Some((expected_pipeline_id, ref reply_chan)) = self.webdriver.load_channel { debug!("Sending load for {:?} to WebDriver", expected_pipeline_id); @@ -3728,7 +3686,7 @@ where // pipeline and that no pending pipeline will replace the current one. let pipeline_is_top_level_pipeline = self .browsing_contexts - .get(&BrowsingContextId::from(top_level_browsing_context_id)) + .get(&BrowsingContextId::from(webview_id)) .map(|ctx| ctx.pipeline_id == pipeline_id) .unwrap_or(false); if pipeline_is_top_level_pipeline { @@ -3736,12 +3694,12 @@ where let current_top_level_pipeline_will_be_replaced = self .pending_changes .iter() - .any(|change| change.browsing_context_id == top_level_browsing_context_id); + .any(|change| change.browsing_context_id == webview_id); if !current_top_level_pipeline_will_be_replaced { // Notify embedder and compositor top level document finished loading. self.compositor_proxy - .send(CompositorMsg::LoadComplete(top_level_browsing_context_id)); + .send(CompositorMsg::LoadComplete(webview_id)); } } else { self.handle_subframe_loaded(pipeline_id); @@ -3758,10 +3716,10 @@ where new_url: ServoUrl, history_handling: NavigationHistoryBehavior, ) { - let (top_level_browsing_context_id, old_url) = match self.pipelines.get_mut(&pipeline_id) { + let (webview_id, old_url) = match self.pipelines.get_mut(&pipeline_id) { Some(pipeline) => { let old_url = replace(&mut pipeline.url, new_url.clone()); - (pipeline.top_level_browsing_context_id, old_url) + (pipeline.webview_id, old_url) }, None => { return warn!("{}: Navigated to fragment after closure", pipeline_id); @@ -3777,10 +3735,9 @@ where old_url, }; - self.get_joint_session_history(top_level_browsing_context_id) - .push_diff(diff); + self.get_joint_session_history(webview_id).push_diff(diff); - self.notify_history_changed(top_level_browsing_context_id); + self.notify_history_changed(webview_id); }, } } @@ -3791,14 +3748,14 @@ where )] fn handle_traverse_history_msg( &mut self, - top_level_browsing_context_id: TopLevelBrowsingContextId, + webview_id: WebViewId, direction: TraversalDirection, ) { let mut browsing_context_changes = HashMap::::new(); let mut pipeline_changes = HashMap::, ServoUrl)>::new(); let mut url_to_load = HashMap::::new(); { - let session_history = self.get_joint_session_history(top_level_browsing_context_id); + let session_history = self.get_joint_session_history(webview_id); match direction { TraversalDirection::Forward(forward) => { let future_length = session_history.future.len(); @@ -3924,10 +3881,10 @@ where self.update_pipeline(pipeline_id, history_state_id, url); } - self.notify_history_changed(top_level_browsing_context_id); + self.notify_history_changed(webview_id); - self.trim_history(top_level_browsing_context_id); - self.update_webview_in_compositor(top_level_browsing_context_id); + self.trim_history(webview_id); + self.update_webview_in_compositor(webview_id); } #[cfg_attr( @@ -3985,7 +3942,7 @@ where throttled, ); self.add_pending_change(SessionHistoryChange { - top_level_browsing_context_id: top_level_id, + webview_id: top_level_id, browsing_context_id, new_pipeline_id, replace: Some(NeedsToReload::Yes(pipeline_id, load_data)), @@ -4095,12 +4052,12 @@ where )] fn handle_joint_session_history_length( &self, - top_level_browsing_context_id: TopLevelBrowsingContextId, + webview_id: WebViewId, response_sender: IpcSender, ) { let length = self .webviews - .get(top_level_browsing_context_id) + .get(webview_id) .map(|webview| webview.session_history.history_length()) .unwrap_or(1); let _ = response_sender.send(length as u32); @@ -4116,26 +4073,21 @@ where history_state_id: HistoryStateId, url: ServoUrl, ) { - let (top_level_browsing_context_id, old_state_id, old_url) = - match self.pipelines.get_mut(&pipeline_id) { - Some(pipeline) => { - let old_history_state_id = pipeline.history_state_id; - let old_url = replace(&mut pipeline.url, url.clone()); - pipeline.history_state_id = Some(history_state_id); - pipeline.history_states.insert(history_state_id); - ( - pipeline.top_level_browsing_context_id, - old_history_state_id, - old_url, - ) - }, - None => { - return warn!( - "{}: Push history state {} for closed pipeline", - pipeline_id, history_state_id, - ); - }, - }; + let (webview_id, old_state_id, old_url) = match self.pipelines.get_mut(&pipeline_id) { + Some(pipeline) => { + let old_history_state_id = pipeline.history_state_id; + let old_url = replace(&mut pipeline.url, url.clone()); + pipeline.history_state_id = Some(history_state_id); + pipeline.history_states.insert(history_state_id); + (pipeline.webview_id, old_history_state_id, old_url) + }, + None => { + return warn!( + "{}: Push history state {} for closed pipeline", + pipeline_id, history_state_id, + ); + }, + }; let diff = SessionHistoryDiff::Pipeline { pipeline_reloader: NeedsToReload::No(pipeline_id), @@ -4144,9 +4096,8 @@ where old_history_state_id: old_state_id, old_url, }; - self.get_joint_session_history(top_level_browsing_context_id) - .push_diff(diff); - self.notify_history_changed(top_level_browsing_context_id); + self.get_joint_session_history(webview_id).push_diff(diff); + self.notify_history_changed(webview_id); } #[cfg_attr( @@ -4159,11 +4110,11 @@ where history_state_id: HistoryStateId, url: ServoUrl, ) { - let top_level_browsing_context_id = match self.pipelines.get_mut(&pipeline_id) { + let webview_id = match self.pipelines.get_mut(&pipeline_id) { Some(pipeline) => { pipeline.history_state_id = Some(history_state_id); pipeline.url = url.clone(); - pipeline.top_level_browsing_context_id + pipeline.webview_id }, None => { return warn!( @@ -4173,7 +4124,7 @@ where }, }; - let session_history = self.get_joint_session_history(top_level_browsing_context_id); + let session_history = self.get_joint_session_history(webview_id); session_history.replace_history_state(pipeline_id, history_state_id, url); } @@ -4181,8 +4132,8 @@ where feature = "tracing", tracing::instrument(skip_all, fields(servo_profiling = true), level = "trace") )] - fn handle_reload_msg(&mut self, top_level_browsing_context_id: TopLevelBrowsingContextId) { - let browsing_context_id = BrowsingContextId::from(top_level_browsing_context_id); + fn handle_reload_msg(&mut self, webview_id: WebViewId) { + let browsing_context_id = BrowsingContextId::from(webview_id); let pipeline_id = match self.browsing_contexts.get(&browsing_context_id) { Some(browsing_context) => browsing_context.pipeline_id, None => { @@ -4221,7 +4172,7 @@ where Some(browsing_context) => browsing_context.pipeline_id, }; let source_browsing_context = match self.pipelines.get(&source_pipeline) { - Some(pipeline) => pipeline.top_level_browsing_context_id, + Some(pipeline) => pipeline.webview_id, None => return warn!("{}: PostMessage from closed pipeline", source_pipeline), }; let msg = ScriptThreadMessage::PostMessage { @@ -4289,29 +4240,25 @@ where tracing::instrument(skip_all, fields(servo_profiling = true), level = "trace") )] fn handle_focus_msg(&mut self, pipeline_id: PipelineId) { - let (browsing_context_id, top_level_browsing_context_id) = - match self.pipelines.get(&pipeline_id) { - Some(pipeline) => ( - pipeline.browsing_context_id, - pipeline.top_level_browsing_context_id, - ), - None => return warn!("{}: Focus parent after closure", pipeline_id), - }; + let (browsing_context_id, webview_id) = match self.pipelines.get(&pipeline_id) { + Some(pipeline) => (pipeline.browsing_context_id, pipeline.webview_id), + None => return warn!("{}: Focus parent after closure", pipeline_id), + }; // Focus the top-level browsing context. - self.webviews.focus(top_level_browsing_context_id); + self.webviews.focus(webview_id); self.embedder_proxy - .send(EmbedderMsg::WebViewFocused(top_level_browsing_context_id)); + .send(EmbedderMsg::WebViewFocused(webview_id)); // Update the webview’s focused browsing context. - match self.webviews.get_mut(top_level_browsing_context_id) { + match self.webviews.get_mut(webview_id) { Some(webview) => { webview.focused_browsing_context_id = browsing_context_id; }, None => { return warn!( "{}: Browsing context for focus msg does not exist", - top_level_browsing_context_id + webview_id ); }, }; @@ -4442,8 +4389,8 @@ where // Find the script channel for the given parent pipeline, // and pass the event to that script thread. match msg { - WebDriverCommandMsg::CloseWebView(top_level_browsing_context_id) => { - self.handle_close_top_level_browsing_context(top_level_browsing_context_id); + WebDriverCommandMsg::CloseWebView(webview_id) => { + self.handle_close_top_level_browsing_context(webview_id); }, WebDriverCommandMsg::NewWebView(webview_id, sender, load_sender) => { let (chan, port) = match ipc::channel() { @@ -4464,22 +4411,18 @@ where ); let _ = sender.send(webview_id); }, - WebDriverCommandMsg::FocusWebView(top_level_browsing_context_id) => { - self.handle_focus_web_view(top_level_browsing_context_id); + WebDriverCommandMsg::FocusWebView(webview_id) => { + self.handle_focus_web_view(webview_id); }, WebDriverCommandMsg::GetWindowSize(_, response_sender) => { let _ = response_sender.send(self.window_size.initial_viewport); }, - WebDriverCommandMsg::SetWindowSize( - top_level_browsing_context_id, - size, - response_sender, - ) => { + WebDriverCommandMsg::SetWindowSize(webview_id, size, response_sender) => { self.webdriver.resize_channel = Some(response_sender); self.embedder_proxy - .send(EmbedderMsg::ResizeTo(top_level_browsing_context_id, size)); + .send(EmbedderMsg::ResizeTo(webview_id, size)); }, - WebDriverCommandMsg::LoadUrl(top_level_browsing_context_id, url, response_sender) => { + WebDriverCommandMsg::LoadUrl(webview_id, url, response_sender) => { let load_data = LoadData::new( LoadOrigin::WebDriver, url, @@ -4490,14 +4433,14 @@ where None, ); self.load_url_for_webdriver( - top_level_browsing_context_id, + webview_id, load_data, response_sender, NavigationHistoryBehavior::Push, ); }, - WebDriverCommandMsg::Refresh(top_level_browsing_context_id, response_sender) => { - let browsing_context_id = BrowsingContextId::from(top_level_browsing_context_id); + WebDriverCommandMsg::Refresh(webview_id, response_sender) => { + let browsing_context_id = BrowsingContextId::from(webview_id); let pipeline_id = match self.browsing_contexts.get(&browsing_context_id) { Some(browsing_context) => browsing_context.pipeline_id, None => { @@ -4509,7 +4452,7 @@ where None => return warn!("{}: Refresh after closure", pipeline_id), }; self.load_url_for_webdriver( - top_level_browsing_context_id, + webview_id, load_data, response_sender, NavigationHistoryBehavior::Replace, @@ -4633,24 +4576,24 @@ where feature = "tracing", tracing::instrument(skip_all, fields(servo_profiling = true), level = "trace") )] - fn notify_history_changed(&self, top_level_browsing_context_id: TopLevelBrowsingContextId) { + fn notify_history_changed(&self, webview_id: WebViewId) { // Send a flat projection of the history to embedder. // The final vector is a concatenation of the URLs of the past // entries, the current entry and the future entries. // URLs of inner frames are ignored and replaced with the URL // of the parent. - let session_history = match self.webviews.get(top_level_browsing_context_id) { + let session_history = match self.webviews.get(webview_id) { Some(webview) => &webview.session_history, None => { return warn!( "{}: Session history does not exist for browsing context", - top_level_browsing_context_id + webview_id ); }, }; - let browsing_context_id = BrowsingContextId::from(top_level_browsing_context_id); + let browsing_context_id = BrowsingContextId::from(webview_id); let browsing_context = match self.browsing_contexts.get(&browsing_context_id) { Some(browsing_context) => browsing_context, None => { @@ -4676,7 +4619,7 @@ where ref new_reloader, .. } => { - if browsing_context_id == top_level_browsing_context_id { + if browsing_context_id == webview_id { let url = match *new_reloader { NeedsToReload::No(pipeline_id) => { match self.pipelines.get(&pipeline_id) { @@ -4702,7 +4645,7 @@ where ref old_reloader, .. } => { - if browsing_context_id == top_level_browsing_context_id { + if browsing_context_id == webview_id { let url = match *old_reloader { NeedsToReload::No(pipeline_id) => match self.pipelines.get(&pipeline_id) { Some(pipeline) => pipeline.url.clone(), @@ -4740,7 +4683,7 @@ where .scan(current_url, &resolve_url_future), ); self.embedder_proxy.send(EmbedderMsg::HistoryChanged( - top_level_browsing_context_id, + webview_id, entries, current_index, )); @@ -4752,12 +4695,12 @@ where )] fn load_url_for_webdriver( &mut self, - top_level_browsing_context_id: TopLevelBrowsingContextId, + webview_id: WebViewId, load_data: LoadData, response_sender: IpcSender, history_handling: NavigationHistoryBehavior, ) { - let browsing_context_id = BrowsingContextId::from(top_level_browsing_context_id); + let browsing_context_id = BrowsingContextId::from(webview_id); let pipeline_id = match self.browsing_contexts.get(&browsing_context_id) { Some(browsing_context) => browsing_context.pipeline_id, None => { @@ -4768,12 +4711,9 @@ where }, }; - if let Some(new_pipeline_id) = self.load_url( - top_level_browsing_context_id, - pipeline_id, - load_data, - history_handling, - ) { + if let Some(new_pipeline_id) = + self.load_url(webview_id, pipeline_id, load_data, history_handling) + { debug!( "Setting up webdriver load notification for {:?}", new_pipeline_id @@ -4798,7 +4738,7 @@ where // context in which the page is being loaded, then update the focused // browsing context to be the one where the page is being loaded. if self.focused_browsing_context_is_descendant_of(change.browsing_context_id) { - if let Some(webview) = self.webviews.get_mut(change.top_level_browsing_context_id) { + if let Some(webview) = self.webviews.get_mut(change.webview_id) { webview.focused_browsing_context_id = change.browsing_context_id; } } @@ -4831,7 +4771,7 @@ where }; self.new_browsing_context( change.browsing_context_id, - change.top_level_browsing_context_id, + change.webview_id, change.new_pipeline_id, new_context_info.parent_pipeline_id, change.window_size, @@ -4852,7 +4792,7 @@ where let (pipelines_to_close, states_to_close) = if let Some(replace_reloader) = change.replace { - self.get_joint_session_history(change.top_level_browsing_context_id) + self.get_joint_session_history(change.webview_id) .replace_reloader( replace_reloader.clone(), NeedsToReload::No(change.new_pipeline_id), @@ -4873,7 +4813,7 @@ where let mut states_to_close = HashMap::new(); let diffs_to_close = self - .get_joint_session_history(change.top_level_browsing_context_id) + .get_joint_session_history(change.webview_id) .push_diff(diff); for diff in diffs_to_close { @@ -4938,8 +4878,8 @@ where self.trim_history(top_level_id); } - self.notify_history_changed(change.top_level_browsing_context_id); - self.update_webview_in_compositor(change.top_level_browsing_context_id); + self.notify_history_changed(change.webview_id); + self.update_webview_in_compositor(change.webview_id); } #[cfg_attr( @@ -4965,9 +4905,9 @@ where feature = "tracing", tracing::instrument(skip_all, fields(servo_profiling = true), level = "trace") )] - fn trim_history(&mut self, top_level_browsing_context_id: TopLevelBrowsingContextId) { + fn trim_history(&mut self, webview_id: WebViewId) { let pipelines_to_evict = { - let session_history = self.get_joint_session_history(top_level_browsing_context_id); + let session_history = self.get_joint_session_history(webview_id); let history_length = pref!(session_history_max_length) as usize; @@ -5017,7 +4957,7 @@ where ); } - let session_history = self.get_joint_session_history(top_level_browsing_context_id); + let session_history = self.get_joint_session_history(webview_id); for (alive_id, dead) in dead_pipelines { session_history.replace_reloader(NeedsToReload::No(alive_id), dead); @@ -5061,7 +5001,7 @@ where let msg = ScriptThreadMessage::UpdatePipelineId( parent_pipeline_id, change.browsing_context_id, - change.top_level_browsing_context_id, + change.webview_id, pipeline_id, UpdatePipelineIdReason::Navigation, ); @@ -5079,7 +5019,7 @@ where )] fn handle_window_size_msg( &mut self, - top_level_browsing_context_id: TopLevelBrowsingContextId, + webview_id: WebViewId, new_size: WindowSizeData, size_type: WindowSizeType, ) { @@ -5088,7 +5028,7 @@ where new_size.initial_viewport.to_untyped() ); - let browsing_context_id = BrowsingContextId::from(top_level_browsing_context_id); + let browsing_context_id = BrowsingContextId::from(webview_id); self.resize_browsing_context(new_size, size_type, browsing_context_id); if let Some(response_sender) = self.webdriver.resize_channel.take() { @@ -5103,11 +5043,8 @@ where feature = "tracing", tracing::instrument(skip_all, fields(servo_profiling = true), level = "trace") )] - fn handle_exit_fullscreen_msg( - &mut self, - top_level_browsing_context_id: TopLevelBrowsingContextId, - ) { - let browsing_context_id = BrowsingContextId::from(top_level_browsing_context_id); + fn handle_exit_fullscreen_msg(&mut self, webview_id: WebViewId) { + let browsing_context_id = BrowsingContextId::from(webview_id); self.switch_fullscreen_mode(browsing_context_id); } @@ -5130,8 +5067,7 @@ where // // If there is no focus browsing context yet, the initial page has // not loaded, so there is nothing to save yet. - let Some(top_level_browsing_context_id) = self.webviews.focused_webview().map(|(id, _)| id) - else { + let Some(webview_id) = self.webviews.focused_webview().map(|(id, _)| id) else { return ReadyToSave::NoTopLevelBrowsingContext; }; @@ -5144,9 +5080,7 @@ where // and that the current epoch of the layout matches what the compositor has painted. If all // these conditions are met, then the output image should not change and a reftest // screenshot can safely be written. - for browsing_context in - self.fully_active_browsing_contexts_iter(top_level_browsing_context_id) - { + for browsing_context in self.fully_active_browsing_contexts_iter(webview_id) { let pipeline_id = browsing_context.pipeline_id; trace!( "{}: Checking readiness of {}", @@ -5442,12 +5376,8 @@ where feature = "tracing", tracing::instrument(skip_all, fields(servo_profiling = true), level = "trace") )] - fn handle_discard_document( - &mut self, - top_level_browsing_context_id: TopLevelBrowsingContextId, - pipeline_id: PipelineId, - ) { - match self.webviews.get_mut(top_level_browsing_context_id) { + fn handle_discard_document(&mut self, webview_id: WebViewId, pipeline_id: PipelineId) { + match self.webviews.get_mut(webview_id) { Some(webview) => { let load_data = match self.pipelines.get(&pipeline_id) { Some(pipeline) => pipeline.load_data.clone(), @@ -5461,7 +5391,7 @@ where None => { return warn!( "{}: Discarding after closure of {}", - pipeline_id, top_level_browsing_context_id, + pipeline_id, webview_id, ); }, }; @@ -5597,10 +5527,7 @@ where feature = "tracing", tracing::instrument(skip_all, fields(servo_profiling = true), level = "trace") )] - fn get_joint_session_history( - &mut self, - top_level_id: TopLevelBrowsingContextId, - ) -> &mut JointSessionHistory { + fn get_joint_session_history(&mut self, top_level_id: WebViewId) -> &mut JointSessionHistory { self.webviews .get_mut(top_level_id) .map(|webview| &mut webview.session_history) diff --git a/components/constellation/logging.rs b/components/constellation/logging.rs index a64b291a045..b9c6ef155d5 100644 --- a/components/constellation/logging.rs +++ b/components/constellation/logging.rs @@ -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(); diff --git a/components/constellation/pipeline.rs b/components/constellation/pipeline.rs index 05c7829e49e..39b3fce26df 100644 --- a/components/constellation/pipeline.rs +++ b/components/constellation/pipeline.rs @@ -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, @@ -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, event_loop: Rc, 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, opener: Option, @@ -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(), diff --git a/components/constellation/session_history.rs b/components/constellation/session_history.rs index f948c48b999..a6c424357f1 100644 --- a/components/constellation/session_history.rs +++ b/components/constellation/session_history.rs @@ -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, diff --git a/components/constellation/webview.rs b/components/constellation/webview.rs index 31d7937f9e2..8b134b62f2e 100644 --- a/components/constellation/webview.rs +++ b/components/constellation/webview.rs @@ -4,16 +4,16 @@ use std::collections::HashMap; -use base::id::TopLevelBrowsingContextId; +use base::id::WebViewId; #[derive(Debug)] pub struct WebViewManager { /// 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, + webviews: HashMap, /// The order in which they were focused, latest last. - focus_order: Vec, + focus_order: Vec, /// Whether the latest webview in focus order is currently focused. is_focused: bool, @@ -30,63 +30,47 @@ impl Default for WebViewManager { } impl WebViewManager { - 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 { - if self.focus_order.last() == Some(&top_level_browsing_context_id) { + pub fn remove(&mut self, webview_id: WebViewId) -> Option { + 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")), }) diff --git a/components/script/dom/dedicatedworkerglobalscope.rs b/components/script/dom/dedicatedworkerglobalscope.rs index 4f013dbb6c0..ef8e59fc70e 100644 --- a/components/script/dom/dedicatedworkerglobalscope.rs +++ b/components/script/dom/dedicatedworkerglobalscope.rs @@ -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 { diff --git a/components/script/dom/htmliframeelement.rs b/components/script/dom/htmliframeelement.rs index 6f45814d031..e34a863b623 100644 --- a/components/script/dom/htmliframeelement.rs +++ b/components/script/dom/htmliframeelement.rs @@ -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>, + webview_id: Cell>, #[no_trace] browsing_context_id: Cell>, #[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 { - self.top_level_browsing_context_id.get() + pub(crate) fn webview_id(&self) -> Option { + self.webview_id.get() } pub(crate) fn set_throttled(&self, throttled: bool) { diff --git a/components/script/dom/windowproxy.rs b/components/script/dom/windowproxy.rs index 7c95d800fcf..acd96b4e55a 100644 --- a/components/script/dom/windowproxy.rs +++ b/components/script/dom/windowproxy.rs @@ -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, 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, @@ -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, 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> { diff --git a/components/script/navigation.rs b/components/script/navigation.rs index 160ce769ade..ea120e690c2 100644 --- a/components/script/navigation.rs +++ b/components/script/navigation.rs @@ -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, @@ -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, opener: Option, 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(), ) diff --git a/components/script/script_thread.rs b/components/script/script_thread.rs index 7b264919df8..669b08d2278 100644 --- a/components/script/script_thread.rs +++ b/components/script/script_thread.rs @@ -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 { + ) -> Option { 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, 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 { + ) -> Option { 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, ) -> Option> { @@ -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, opener: Option, ) -> DomRoot { @@ -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(), diff --git a/components/script/webdriver_handlers.rs b/components/script/webdriver_handlers.rs index c72dee18200..a9e9a6bc4a7 100644 --- a/components/script/webdriver_handlers.rs +++ b/components/script/webdriver_handlers.rs @@ -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::().unique_id(), ))) diff --git a/components/servo/lib.rs b/components/servo/lib.rs index a0d7253e687..78cf04f3d5f 100644 --- a/components/servo/lib.rs +++ b/components/servo/lib.rs @@ -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 diff --git a/components/shared/base/id.rs b/components/shared/base/id.rs index 071d7107b9c..bb4c5abb4cc 100644 --- a/components/shared/base/id.rs +++ b/components/shared/base/id.rs @@ -275,61 +275,58 @@ impl fmt::Display for BrowsingContextGroupId { } } -thread_local!(pub static TOP_LEVEL_BROWSING_CONTEXT_ID: Cell> = +thread_local!(pub static WEBVIEW_ID: Cell> = 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, 8); +size_of_test!(WebViewId, 8); +size_of_test!(Option, 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 { - TOP_LEVEL_BROWSING_CONTEXT_ID.with(|tls| tls.get()) + pub fn installed() -> Option { + WEBVIEW_ID.with(|tls| tls.get()) } } -impl From for BrowsingContextId { - fn from(id: TopLevelBrowsingContextId) -> BrowsingContextId { +impl From for BrowsingContextId { + fn from(id: WebViewId) -> BrowsingContextId { id.0 } } -impl PartialEq for BrowsingContextId { - fn eq(&self, rhs: &TopLevelBrowsingContextId) -> bool { +impl PartialEq for BrowsingContextId { + fn eq(&self, rhs: &WebViewId) -> bool { self.eq(&rhs.0) } } -impl PartialEq for TopLevelBrowsingContextId { +impl PartialEq 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); diff --git a/components/shared/compositing/constellation_msg.rs b/components/shared/compositing/constellation_msg.rs index 412cfcba32a..9bb93741eb9 100644 --- a/components/shared/compositing/constellation_msg.rs +++ b/components/shared/compositing/constellation_msg.rs @@ -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>), /// Request that the constellation send the current focused top-level browsing context id, /// over a provided channel. - GetFocusTopLevelBrowsingContext(IpcSender>), + GetFocusTopLevelBrowsingContext(IpcSender>), /// Query the constellation to see if the current compositor output is stable IsReadyToSaveImage(HashMap), /// 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, Option, LogEntry), + LogEntry(Option, Option, 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, String), + SendError(Option, 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 { diff --git a/components/shared/compositing/lib.rs b/components/shared/compositing/lib.rs index ddca92a3c57..0cf6d4496c4 100644 --- a/components/shared/compositing/lib.rs +++ b/components/shared/compositing/lib.rs @@ -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, } diff --git a/components/shared/script/lib.rs b/components/shared/script/lib.rs index eaf371f72ec..4ca8cff66ad 100644 --- a/components/shared/script/lib.rs +++ b/components/shared/script/lib.rs @@ -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, /// 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, /// 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, /// 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 diff --git a/components/shared/script/script_msg.rs b/components/shared/script/script_msg.rs index 21ddd4fce18..90e3bb8e6fd 100644 --- a/components/shared/script/script_msg.rs +++ b/components/shared/script/script_msg.rs @@ -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>, - ), + GetTopForBrowsingContext(BrowsingContextId, IpcSender>), /// Get the browsing context id of the browsing context in which pipeline is /// embedded and the parent pipeline id of that browsing context. GetBrowsingContextInfo( diff --git a/components/webdriver_server/actions.rs b/components/webdriver_server/actions.rs index 0c5f24cac85..757e3b8b190 100644 --- a/components/webdriver_server/actions.rs +++ b/components/webdriver_server/actions.rs @@ -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(); diff --git a/components/webdriver_server/lib.rs b/components/webdriver_server/lib.rs index aa106886d32..0e813584f35 100644 --- a/components/webdriver_server/lib.rs +++ b/components/webdriver_server/lib.rs @@ -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) { pub struct WebDriverSession { id: Uuid, browsing_context_id: BrowsingContextId, - top_level_browsing_context_id: TopLevelBrowsingContextId, + webview_id: WebViewId, - window_handles: HashMap, + window_handles: HashMap, /// 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 { + fn focus_webview_id(&self) -> WebDriverResult { 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 { 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 { - 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 { - 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 { - 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 { 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 { { 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();