From e27ba16c3fda8a851b358b00852c2e0784649702 Mon Sep 17 00:00:00 2001 From: Gregory Terzian Date: Sun, 3 Jun 2018 17:31:11 +0800 Subject: [PATCH] share event-loops based on eTLD+1 --- components/constellation/constellation.rs | 37 +++++------------------ 1 file changed, 7 insertions(+), 30 deletions(-) diff --git a/components/constellation/constellation.rs b/components/constellation/constellation.rs index 6e1e2b87f30..c0c3bd566fa 100644 --- a/components/constellation/constellation.rs +++ b/components/constellation/constellation.rs @@ -264,18 +264,13 @@ pub struct Constellation { /// WebRender thread. webrender_api_sender: webrender_api::RenderApiSender, - /// The set of all event loops in the browser. We generate a new - /// event loop for each registered domain name (aka eTLD+1) in - /// each top-level browsing context. We store the event loops in a map - /// indexed by top-level browsing context id - /// (as a `TopLevelBrowsingContextId`) and registered - /// domain name (as a `Host`) to event loops. This double - /// indirection ensures that separate tabs do not share event - /// loops, even if the same domain is loaded in each. + /// The set of all event loops in the browser. + /// We store the event loops in a map + /// indexed by registered domain name (as a `Host`) to event loops. /// It is important that scripts with the same eTLD+1 /// share an event loop, since they can use `document.domain` /// to become same-origin, at which point they can share DOM objects. - event_loops: HashMap>>, + event_loops: HashMap>, joint_session_histories: HashMap, @@ -718,9 +713,7 @@ where None => (None, None), Some(host) => { let event_loop = self - .event_loops - .get(&top_level_browsing_context_id) - .and_then(|map| map.get(&host)) + .event_loops.get(&host) .and_then(|weak| weak.upgrade()); match event_loop { None => (None, Some(host)), @@ -806,9 +799,8 @@ where "Adding new host entry {} for top-level browsing context {}.", host, top_level_browsing_context_id ); - self.event_loops - .entry(top_level_browsing_context_id) - .or_insert_with(HashMap::new) + let _ = self + .event_loops .insert(host, Rc::downgrade(&pipeline.event_loop)); } @@ -1905,18 +1897,7 @@ where Some(opener_pipeline) => (opener_pipeline, opener_pipeline.browsing_context_id), None => return warn!("Auxiliary loaded url in closed pipeline {}.", opener_pipeline_id), }; - let opener_host = match reg_host(&opener_pipeline.url) { - Some(host) => host, - None => return warn!("Auxiliary loaded pipeline with no url {}.", opener_pipeline_id), - }; let script_sender = opener_pipeline.event_loop.clone(); - // https://html.spec.whatwg.org/multipage/#unit-of-related-similar-origin-browsing-contexts - // If the auxiliary shares the host/scheme with the creator, they share an event-loop. - // So the first entry for the auxiliary, itself currently "about:blank", - // is the event-loop for the current host of the creator. - self.event_loops.entry(new_top_level_browsing_context_id) - .or_insert_with(HashMap::new) - .insert(opener_host, Rc::downgrade(&script_sender)); Pipeline::new(new_pipeline_id, new_browsing_context_id, new_top_level_browsing_context_id, @@ -3565,10 +3546,6 @@ where session_history.remove_entries_for_browsing_context(browsing_context_id); } - if BrowsingContextId::from(browsing_context.top_level_id) == browsing_context_id { - self.event_loops.remove(&browsing_context.top_level_id); - } - let parent_info = self .pipelines .get(&browsing_context.pipeline_id)