Skip to content

Commit

Permalink
Auto merge of #14841 - jdm:stylesheet_document, r=emilio
Browse files Browse the repository at this point in the history
Track stylesheet load's document instead of using element's current document

For cases where a stylesheet load finishes in a different document than it started, we need to be more careful about which document we report the completion to. In this case we actually have separate requests for each document involved, but they previously used the same element to determine which document to interact with.

---
- [X] `./mach build -d` does not report any errors
- [X] `./mach test-tidy` does not report any errors
- [X] These changes fix #14641
- [X] There are tests for these changes OR

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/14841)
<!-- Reviewable:end -->
  • Loading branch information
bors-servo committed Jan 4, 2017
2 parents 1e927ca + 318a047 commit 384e905
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 3 deletions.
9 changes: 6 additions & 3 deletions components/script/stylesheet_loader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use document_loader::LoadType;
use dom::bindings::inheritance::Castable;
use dom::bindings::refcounted::Trusted;
use dom::bindings::reflector::DomObject;
use dom::document::Document;
use dom::element::Element;
use dom::eventtarget::EventTarget;
use dom::htmlelement::HTMLElement;
Expand Down Expand Up @@ -78,6 +79,8 @@ pub struct StylesheetContext {
metadata: Option<Metadata>,
/// The response body received to date.
data: Vec<u8>,
/// The node document for elem when the load was initiated.
document: Trusted<Document>,
}

impl PreInvoke for StylesheetContext {}
Expand All @@ -103,7 +106,7 @@ impl FetchResponseListener for StylesheetContext {

fn process_response_eof(&mut self, status: Result<(), NetworkError>) {
let elem = self.elem.root();
let document = document_from_node(&*elem);
let document = self.document.root();
let mut successful = false;

if status.is_ok() {
Expand Down Expand Up @@ -192,15 +195,15 @@ impl<'a> StylesheetLoader<'a> {
impl<'a> StylesheetLoader<'a> {
pub fn load(&self, source: StylesheetContextSource) {
let url = source.url();
let document = document_from_node(self.elem);
let context = Arc::new(Mutex::new(StylesheetContext {
elem: Trusted::new(&*self.elem),
source: source,
metadata: None,
data: vec![],
document: Trusted::new(&*document),
}));

let document = document_from_node(self.elem);

let (action_sender, action_receiver) = ipc::channel().unwrap();
let listener = NetworkListener {
context: context,
Expand Down
24 changes: 24 additions & 0 deletions tests/wpt/mozilla/meta/MANIFEST.json
Original file line number Diff line number Diff line change
Expand Up @@ -6474,6 +6474,18 @@
"url": "/_mozilla/mozilla/sslfail.html"
}
],
"mozilla/stylesheet-adopt-panic.html": [
{
"path": "mozilla/stylesheet-adopt-panic.html",
"references": [
[
"/_mozilla/mozilla/stylesheet-adopt-panic-ref.html",
"=="
]
],
"url": "/_mozilla/mozilla/stylesheet-adopt-panic.html"
}
],
"mozilla/svg/svg.html": [
{
"path": "mozilla/svg/svg.html",
Expand Down Expand Up @@ -21756,6 +21768,18 @@
"url": "/_mozilla/mozilla/sslfail.html"
}
],
"mozilla/stylesheet-adopt-panic.html": [
{
"path": "mozilla/stylesheet-adopt-panic.html",
"references": [
[
"/_mozilla/mozilla/stylesheet-adopt-panic-ref.html",
"=="
]
],
"url": "/_mozilla/mozilla/stylesheet-adopt-panic.html"
}
],
"mozilla/svg/svg.html": [
{
"path": "mozilla/svg/svg.html",
Expand Down
3 changes: 3 additions & 0 deletions tests/wpt/mozilla/tests/mozilla/adopt-panic.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
body {
background-color: green;
}
2 changes: 2 additions & 0 deletions tests/wpt/mozilla/tests/mozilla/blank.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<!doctype html>
<title>Blank document</title>
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<!doctype html>
<meta charset="utf-8">
<iframe src="blank.html"></iframe>
<style>
body {
background-color: green;
}
</style>
13 changes: 13 additions & 0 deletions tests/wpt/mozilla/tests/mozilla/stylesheet-adopt-panic.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!doctype html>
<meta charset="utf-8">
<title>Verify that adopting a stylesheet with an import applies its styles and doesn't panic</title>
<link rel="match" href="stylesheet-adopt-panic-ref.html">
<iframe src="blank.html" onload="foo()"></iframe>
<script>
function foo() {
var i = document.querySelector('iframe');
i.contentDocument.documentElement.innerHTML = "<style>@import 'adopt-panic.css';</style>";
var e = i.contentDocument.querySelector('style');
document.body.appendChild(e);
}
</script>

0 comments on commit 384e905

Please sign in to comment.