diff options
author | Gregory Terzian <gterzian@users.noreply.github.com> | 2018-06-02 20:56:00 +0800 |
---|---|---|
committer | Gregory Terzian <gterzian@users.noreply.github.com> | 2018-08-11 01:13:11 +0200 |
commit | 21bf5a3a4b6398cd7c20449ba9110499feca7d6b (patch) | |
tree | 151b1df3f5dccc17b79a5feeb5a1f9bf35759123 /components/script/script_thread.rs | |
parent | f408b798c4666eddeb8b52d8965d7d4a6942e066 (diff) | |
download | servo-21bf5a3a4b6398cd7c20449ba9110499feca7d6b.tar.gz servo-21bf5a3a4b6398cd7c20449ba9110499feca7d6b.zip |
implement opener, disowning
Diffstat (limited to 'components/script/script_thread.rs')
-rw-r--r-- | components/script/script_thread.rs | 50 |
1 files changed, 41 insertions, 9 deletions
diff --git a/components/script/script_thread.rs b/components/script/script_thread.rs index 9e20a24e55b..8f4855c777b 100644 --- a/components/script/script_thread.rs +++ b/components/script/script_thread.rs @@ -157,6 +157,8 @@ struct InProgressLoad { top_level_browsing_context_id: TopLevelBrowsingContextId, /// The parent pipeline and frame type associated with this load, if any. parent_info: Option<PipelineId>, + /// The opener, if this is an auxiliary. + opener: Option<BrowsingContextId>, /// The current window size associated with this pipeline. window_size: Option<WindowSizeData>, /// Channel to the layout thread associated with this pipeline. @@ -183,6 +185,7 @@ impl InProgressLoad { browsing_context_id: BrowsingContextId, top_level_browsing_context_id: TopLevelBrowsingContextId, parent_info: Option<PipelineId>, + opener: Option<BrowsingContextId>, layout_chan: Sender<message::Msg>, window_size: Option<WindowSizeData>, url: ServoUrl, @@ -195,6 +198,7 @@ impl InProgressLoad { browsing_context_id: browsing_context_id, top_level_browsing_context_id: top_level_browsing_context_id, parent_info: parent_info, + opener: opener, layout_chan: layout_chan, window_size: window_size, activity: DocumentActivity::FullyActive, @@ -569,6 +573,7 @@ impl ScriptThreadFactory for ScriptThread { let browsing_context_id = state.browsing_context_id; let top_level_browsing_context_id = state.top_level_browsing_context_id; let parent_info = state.parent_info; + let opener = state.opener; let mem_profiler_chan = state.mem_profiler_chan.clone(); let window_size = state.window_size; let script_thread = ScriptThread::new(state, @@ -583,7 +588,7 @@ impl ScriptThreadFactory for ScriptThread { let origin = MutableOrigin::new(load_data.url.origin()); let new_load = InProgressLoad::new(id, browsing_context_id, top_level_browsing_context_id, parent_info, - layout_chan, window_size, load_data.url.clone(), origin); + opener, layout_chan, window_size, load_data.url.clone(), origin); script_thread.pre_page_load(new_load, load_data); let reporter_name = format!("script-reporter-{}", id); @@ -706,6 +711,15 @@ impl ScriptThread { }); } + pub fn get_top_level_for_browsing_context(sender_pipeline: PipelineId, + browsing_context_id: BrowsingContextId) + -> Option<TopLevelBrowsingContextId> { + SCRIPT_THREAD_ROOT.with(|root| root.get().and_then(|script_thread| { + let script_thread = unsafe { &*script_thread }; + script_thread.ask_constellation_for_top_level_info(sender_pipeline, browsing_context_id) + })) + } + pub fn find_document(id: PipelineId) -> Option<DomRoot<Document>> { SCRIPT_THREAD_ROOT.with(|root| root.get().and_then(|script_thread| { let script_thread = unsafe { &*script_thread }; @@ -1553,6 +1567,7 @@ impl ScriptThread { new_pipeline_id, browsing_context_id, top_level_browsing_context_id, + opener, load_data, window_size, pipeline_port, @@ -1597,6 +1612,7 @@ impl ScriptThread { browsing_context_id, top_level_browsing_context_id, parent_info, + opener, layout_chan, window_size, load_data.url.clone(), @@ -2025,6 +2041,16 @@ impl ScriptThread { result_receiver.recv().expect("Failed to get frame id from constellation.") } + fn ask_constellation_for_top_level_info(&self, + sender_pipeline: PipelineId, + browsing_context_id: BrowsingContextId) + -> Option<TopLevelBrowsingContextId> { + let (result_sender, result_receiver) = ipc::channel().unwrap(); + let msg = ScriptMsg::GetTopForBrowsingContext(browsing_context_id, result_sender); + self.script_sender.send((sender_pipeline, msg)).expect("Failed to send to constellation."); + result_receiver.recv().expect("Failed to get top-level id from constellation.") + } + // Get the browsing context for a pipeline that may exist in another // script thread. If the browsing context already exists in the // `window_proxies` map, we return it, otherwise we recursively @@ -2034,7 +2060,8 @@ impl ScriptThread { fn remote_window_proxy(&self, global_to_clone: &GlobalScope, top_level_browsing_context_id: TopLevelBrowsingContextId, - pipeline_id: PipelineId) + pipeline_id: PipelineId, + opener: Option<BrowsingContextId>) -> Option<DomRoot<WindowProxy>> { let browsing_context_id = self.ask_constellation_for_browsing_context_id(pipeline_id)?; @@ -2042,12 +2069,13 @@ impl ScriptThread { return Some(DomRoot::from_ref(window_proxy)); } let parent = self.ask_constellation_for_parent_info(pipeline_id).and_then(|parent_id| { - self.remote_window_proxy(global_to_clone, top_level_browsing_context_id, parent_id) + self.remote_window_proxy(global_to_clone, top_level_browsing_context_id, parent_id, opener) }); let window_proxy = WindowProxy::new_dissimilar_origin(global_to_clone, browsing_context_id, top_level_browsing_context_id, - parent.r()); + parent.r(), + opener); self.window_proxies.borrow_mut().insert(browsing_context_id, Dom::from_ref(&*window_proxy)); Some(window_proxy) } @@ -2062,7 +2090,8 @@ impl ScriptThread { window: &Window, browsing_context_id: BrowsingContextId, top_level_browsing_context_id: TopLevelBrowsingContextId, - parent_info: Option<PipelineId>) + parent_info: Option<PipelineId>, + opener: Option<BrowsingContextId>) -> DomRoot<WindowProxy> { if let Some(window_proxy) = self.window_proxies.borrow().get(&browsing_context_id) { @@ -2075,15 +2104,17 @@ impl ScriptThread { let parent = match (parent_info, iframe.as_ref()) { (_, Some(iframe)) => Some(window_from_node(&**iframe).window_proxy()), (Some(parent_id), _) => self.remote_window_proxy(window.upcast(), - top_level_browsing_context_id, - parent_id), + top_level_browsing_context_id, + parent_id, + opener), _ => None, }; let window_proxy = WindowProxy::new(&window, browsing_context_id, top_level_browsing_context_id, iframe.r().map(Castable::upcast), - parent.r()); + parent.r(), + opener); self.window_proxies.borrow_mut().insert(browsing_context_id, Dom::from_ref(&*window_proxy)); window_proxy } @@ -2162,7 +2193,8 @@ impl ScriptThread { let window_proxy = self.local_window_proxy(&window, incomplete.browsing_context_id, incomplete.top_level_browsing_context_id, - incomplete.parent_info); + incomplete.parent_info, + incomplete.opener); window.init_window_proxy(&window_proxy); let last_modified = metadata.headers.as_ref().and_then(|headers| { |