Auto merge of #8886 - paulrouget:freeze-pipeline-iframe, r=mbrubeck,jdm

Freeze old pipeline in iframes

Fixes https://github.com/servo/servo/issues/8673 and part of https://github.com/servo/servo/issues/8674

<!-- Reviewable:start -->
[<img src="https://reviewable.io/review_button.png" height=40 alt="Review on Reviewable"/>](https://reviewable.io/reviews/servo/servo/8886)
<!-- Reviewable:end -->
This commit is contained in:
bors-servo 2015-12-18 13:37:25 +05:30
commit 2ef972b53b
4 changed files with 81 additions and 20 deletions

View file

@ -834,6 +834,10 @@ impl<LTF: LayoutTaskFactory, STF: ScriptTaskFactory> Constellation<LTF, STF> {
} }
}; };
if let Some(pipeline_id) = old_pipeline_id {
self.pipeline(pipeline_id).freeze();
}
// Create the new pipeline, attached to the parent and push to pending frames // Create the new pipeline, attached to the parent and push to pending frames
let window_size = old_pipeline_id.and_then(|old_pipeline_id| { let window_size = old_pipeline_id.and_then(|old_pipeline_id| {
self.pipeline(old_pipeline_id).size self.pipeline(old_pipeline_id).size

View file

@ -135,6 +135,8 @@ struct InProgressLoad {
layout_chan: LayoutChan, layout_chan: LayoutChan,
/// The current viewport clipping rectangle applying to this pipeline, if any. /// The current viewport clipping rectangle applying to this pipeline, if any.
clip_rect: Option<Rect<f32>>, clip_rect: Option<Rect<f32>>,
/// Window is frozen (navigated away while loading for example).
is_frozen: bool,
/// The requested URL of the load. /// The requested URL of the load.
url: Url, url: Url,
} }
@ -152,6 +154,7 @@ impl InProgressLoad {
layout_chan: layout_chan, layout_chan: layout_chan,
window_size: window_size, window_size: window_size,
clip_rect: None, clip_rect: None,
is_frozen: false,
url: url, url: url,
} }
} }
@ -1319,31 +1322,38 @@ impl ScriptTask {
/// Handles freeze message /// Handles freeze message
fn handle_freeze_msg(&self, id: PipelineId) { fn handle_freeze_msg(&self, id: PipelineId) {
// Workaround for a race condition when navigating before the initial page has if let Some(root_page) = self.page.borrow().as_ref() {
// been constructed c.f. https://github.com/servo/servo/issues/7677 if let Some(ref inner_page) = root_page.find(id) {
if self.page.borrow().is_none() { let window = inner_page.window();
return window.freeze();
}; return;
let page = self.root_page(); }
let page = page.find(id).expect("ScriptTask: received freeze msg for a }
pipeline ID not associated with this script task. This is a bug."); let mut loads = self.incomplete_loads.borrow_mut();
let window = page.window(); if let Some(ref mut load) = loads.iter_mut().find(|load| load.pipeline_id == id) {
window.freeze(); load.is_frozen = true;
return;
}
panic!("freeze sent to nonexistent pipeline");
} }
/// Handles thaw message /// Handles thaw message
fn handle_thaw_msg(&self, id: PipelineId) { fn handle_thaw_msg(&self, id: PipelineId) {
// We should only get this message when moving in history, so all pages requested if let Some(ref inner_page) = self.root_page().find(id) {
// should exist. let needed_reflow = inner_page.set_reflow_status(false);
let page = self.root_page().find(id).unwrap(); if needed_reflow {
self.rebuild_and_force_reflow(&*inner_page, ReflowReason::CachedPageNeededReflow);
let needed_reflow = page.set_reflow_status(false); }
if needed_reflow { let window = inner_page.window();
self.rebuild_and_force_reflow(&*page, ReflowReason::CachedPageNeededReflow); window.thaw();
return;
} }
let mut loads = self.incomplete_loads.borrow_mut();
let window = page.window(); if let Some(ref mut load) = loads.iter_mut().find(|load| load.pipeline_id == id) {
window.thaw(); load.is_frozen = false;
return;
}
panic!("thaw sent to nonexistent pipeline");
} }
fn handle_focus_iframe_msg(&self, fn handle_focus_iframe_msg(&self,
@ -1732,6 +1742,10 @@ impl ScriptTask {
} }
} }
if incomplete.is_frozen {
window.freeze();
}
page_remover.neuter(); page_remover.neuter();
document.get_current_parser().unwrap() document.get_current_parser().unwrap()

View file

@ -5679,6 +5679,12 @@
"url": "/_mozilla/mozilla/load_event.html" "url": "/_mozilla/mozilla/load_event.html"
} }
], ],
"mozilla/mozbrowser/iframe_goback.html": [
{
"path": "mozilla/mozbrowser/iframe_goback.html",
"url": "/_mozilla/mozilla/mozbrowser/iframe_goback.html"
}
],
"mozilla/mozbrowser/mozbrowsericonchange_event.html": [ "mozilla/mozbrowser/mozbrowsericonchange_event.html": [
{ {
"path": "mozilla/mozbrowser/mozbrowsericonchange_event.html", "path": "mozilla/mozbrowser/mozbrowsericonchange_event.html",

View file

@ -0,0 +1,37 @@
<head>
<title>iframe.goBack()</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
</head>
<body>
<script>
async_test(function(t) {
var url2 = "data:,a";
var url1 = `data:text/html,<script>setTimeout(() => location.assign("${url2}"), 0)</${"script"}>`;
var locations = []
var expected_locations = [url1, url2, url1];
var iframe = document.createElement("iframe");
iframe.mozbrowser = "true";
iframe.src = url1;
iframe.addEventListener("mozbrowserlocationchange", e => {
locations.push(e.detail);
if (e.detail == url2) {
iframe.goBack();
}
if (locations.length == expected_locations.length) {
assert_array_equals(locations, expected_locations);
t.done();
}
});
document.body.appendChild(iframe);
});
</script>
</body>