Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix iframe.onload being fired twice on about:blank. #16091

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter...
Filter file types
Jump to…
Jump to file
Failed to load files.

Always

Just for now

Suppress second iframe about:blank load event in Document.

  • Loading branch information
gpoesia committed Sep 23, 2017
commit 8d91a90a120dcead14ac853946d14d9f3ee248b6
@@ -247,6 +247,7 @@ pub struct Document {
scripts: MutNullableJS<HTMLCollection>,
anchors: MutNullableJS<HTMLCollection>,
applets: MutNullableJS<HTMLCollection>,
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::<EventTarget>().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::<EventTarget>().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,
}
}

@@ -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 {
@@ -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<message::Msg>,
window_size: Option<WindowSizeData>,
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::<ReferrerPolicyHeader>)
.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);
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.