From 8d91a90a120dcead14ac853946d14d9f3ee248b6 Mon Sep 17 00:00:00 2001 From: Gabriel Poesia Date: Sat, 23 Sep 2017 11:32:23 -0300 Subject: [PATCH] Suppress second iframe about:blank load event in Document. --- components/script/dom/document.rs | 23 +++++++++++------- components/script/dom/htmliframeelement.rs | 2 +- components/script/script_thread.rs | 28 +++++++++++++++------- 3 files changed, 36 insertions(+), 17 deletions(-) diff --git a/components/script/dom/document.rs b/components/script/dom/document.rs index c5940f02b48d..221afab7da42 100644 --- a/components/script/dom/document.rs +++ b/components/script/dom/document.rs @@ -247,6 +247,7 @@ pub struct Document { scripts: MutNullableJS, anchors: MutNullableJS, applets: MutNullableJS, + source: DocumentSource, /// Lock use for style attributes and author-origin stylesheet objects in this document. /// Can be acquired once for accessing many objects. style_shared_lock: StyleSharedRwLock, @@ -1740,12 +1741,14 @@ impl Document { // http://w3c.github.io/navigation-timing/#widl-PerformanceNavigationTiming-loadEventStart update_with_current_time_ms(&document.load_event_start); - debug!("About to dispatch load for {:?}", document.url()); - // FIXME(nox): Why are errors silenced here? - let _ = window.upcast::().dispatch_event_with_target( - document.upcast(), - &event, - ); + if document.source != DocumentSource::InitialAboutBlank { + debug!("About to dispatch load for {:?}", document.url()); + // FIXME(nox): Why are errors silenced here? + let _ = window.upcast::().dispatch_event_with_target( + document.upcast(), + &event, + ); + } // http://w3c.github.io/navigation-timing/#widl-PerformanceNavigationTiming-loadEventEnd update_with_current_time_ms(&document.load_event_end); @@ -1756,7 +1759,9 @@ impl Document { ReflowReason::DocumentLoaded, ); - document.notify_constellation_load(); + if document.source != DocumentSource::InitialAboutBlank { + document.notify_constellation_load(); + } if let Some(fragment) = document.url().fragment() { document.check_and_scroll_fragment(fragment); @@ -2074,9 +2079,10 @@ impl Document { } } -#[derive(HeapSizeOf, PartialEq)] +#[derive(HeapSizeOf, JSTraceable, PartialEq)] pub enum DocumentSource { FromParser, + InitialAboutBlank, NotFromParser, } @@ -2307,6 +2313,7 @@ impl Document { dom_count: Cell::new(1), fullscreen_element: MutNullableJS::new(None), form_id_listener_map: Default::default(), + source: source, } } diff --git a/components/script/dom/htmliframeelement.rs b/components/script/dom/htmliframeelement.rs index 7f0b82fa2391..4601cd1e7895 100644 --- a/components/script/dom/htmliframeelement.rs +++ b/components/script/dom/htmliframeelement.rs @@ -202,7 +202,7 @@ impl HTMLIFrameElement { }; self.pipeline_id.set(Some(new_pipeline_id)); - ScriptThread::process_attach_layout(new_layout_info, document.origin().clone()); + ScriptThread::process_attach_layout(new_layout_info, document.origin().clone(), true); }, NavigationType::Regular => { let load_info = IFrameLoadInfoWithData { diff --git a/components/script/script_thread.rs b/components/script/script_thread.rs index 2fa0071ed659..4fb4bac7e758 100644 --- a/components/script/script_thread.rs +++ b/components/script/script_thread.rs @@ -171,6 +171,8 @@ struct InProgressLoad { navigation_start: u64, /// High res timestamp reporting the time when the browser started this load. navigation_start_precise: f64, + /// Whether the document being loaded is an iframe's initial about:blank. + initial_about_blank_load: bool, } impl InProgressLoad { @@ -182,7 +184,8 @@ impl InProgressLoad { layout_chan: Sender, window_size: Option, url: ServoUrl, - origin: MutableOrigin) -> InProgressLoad { + origin: MutableOrigin, + initial_about_blank_load: bool) -> InProgressLoad { let current_time = get_time(); let navigation_start_precise = precise_time_ns() as f64; layout_chan.send(message::Msg::SetNavigationStart(navigation_start_precise)).unwrap(); @@ -199,6 +202,7 @@ impl InProgressLoad { origin: origin, navigation_start: (current_time.sec * 1000 + current_time.nsec as i64 / 1000000) as u64, navigation_start_precise: navigation_start_precise, + initial_about_blank_load: initial_about_blank_load, } } } @@ -564,7 +568,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); + layout_chan, window_size, load_data.url.clone(), origin, false); script_thread.pre_page_load(new_load, load_data); let reporter_name = format!("script-reporter-{}", id); @@ -675,12 +679,13 @@ impl ScriptThread { }); } - pub fn process_attach_layout(new_layout_info: NewLayoutInfo, origin: MutableOrigin) { + pub fn process_attach_layout(new_layout_info: NewLayoutInfo, origin: MutableOrigin, + initial_about_blank_layout: bool) { SCRIPT_THREAD_ROOT.with(|root| { if let Some(script_thread) = root.get() { let script_thread = unsafe { &*script_thread }; script_thread.profile_event(ScriptThreadEventCategory::AttachLayout, || { - script_thread.handle_new_layout(new_layout_info, origin); + script_thread.handle_new_layout(new_layout_info, origin, initial_about_blank_layout); }) } }); @@ -977,7 +982,7 @@ impl ScriptThread { MutableOrigin::new(ImmutableOrigin::new_opaque()) }; - self.handle_new_layout(new_layout_info, origin); + self.handle_new_layout(new_layout_info, origin, false); }) } FromConstellation(ConstellationControlMsg::Resize(id, size, size_type)) => { @@ -1439,7 +1444,8 @@ impl ScriptThread { window.set_scroll_offsets(scroll_offsets) } - fn handle_new_layout(&self, new_layout_info: NewLayoutInfo, origin: MutableOrigin) { + fn handle_new_layout(&self, new_layout_info: NewLayoutInfo, origin: MutableOrigin, + initial_about_blank_layout: bool) { let NewLayoutInfo { parent_info, new_pipeline_id, @@ -1491,7 +1497,8 @@ impl ScriptThread { layout_chan, window_size, load_data.url.clone(), - origin); + origin, + initial_about_blank_layout); if load_data.url.as_str() == "about:blank" { self.start_page_load_about_blank(new_load, load_data.js_eval_result); } else { @@ -2091,6 +2098,11 @@ impl ScriptThread { .map(Serde::deref) .and_then(Headers::get::) .map(ReferrerPolicy::from); + let document_source = if incomplete.initial_about_blank_load { + DocumentSource::InitialAboutBlank + } else { + DocumentSource::FromParser + }; let document = Document::new(&window, HasBrowsingContext::Yes, @@ -2100,7 +2112,7 @@ impl ScriptThread { content_type, last_modified, incomplete.activity, - DocumentSource::FromParser, + document_source, loader, referrer, referrer_policy);