diff options
author | Ms2ger <ms2ger@gmail.com> | 2016-02-09 14:00:39 +0100 |
---|---|---|
committer | Ms2ger <ms2ger@gmail.com> | 2016-02-11 13:08:11 +0100 |
commit | 152cec69eb20f52217aa1905255e4d439a7119b6 (patch) | |
tree | 80057589f009fb4138dfa431db2bf4ec62ec2772 /components/script/dom/document.rs | |
parent | 0b27807ad4229a07ba6e04aa59798af50da60c14 (diff) | |
download | servo-152cec69eb20f52217aa1905255e4d439a7119b6.tar.gz servo-152cec69eb20f52217aa1905255e4d439a7119b6.zip |
Store a pointer to the browsing context in the Document.
Diffstat (limited to 'components/script/dom/document.rs')
-rw-r--r-- | components/script/dom/document.rs | 19 |
1 files changed, 17 insertions, 2 deletions
diff --git a/components/script/dom/document.rs b/components/script/dom/document.rs index 99a61d2f981..e81800529d6 100644 --- a/components/script/dom/document.rs +++ b/components/script/dom/document.rs @@ -30,6 +30,7 @@ use dom::bindings::reflector::{Reflectable, reflect_dom_object}; use dom::bindings::trace::RootedVec; use dom::bindings::xmlname::XMLName::InvalidXMLName; use dom::bindings::xmlname::{validate_and_extract, namespace_from_domstring, xml_name_type}; +use dom::browsingcontext::BrowsingContext; use dom::comment::Comment; use dom::customevent::CustomEvent; use dom::documentfragment::DocumentFragment; @@ -127,6 +128,8 @@ enum ParserBlockedByScript { pub struct Document { node: Node, window: JS<Window>, + /// https://html.spec.whatwg.org/multipage/#concept-document-bc + browsing_context: Option<JS<BrowsingContext>>, implementation: MutNullableHeap<JS<DOMImplementation>>, location: MutNullableHeap<JS<Location>>, content_type: DOMString, @@ -277,6 +280,12 @@ impl Document { self.loader.borrow_mut() } + /// https://html.spec.whatwg.org/multipage/#concept-document-bc + #[inline] + pub fn browsing_context(&self) -> Option<&BrowsingContext> { + self.browsing_context.as_ref().map(|browsing_context| &**browsing_context) + } + #[inline] pub fn window(&self) -> &Window { &*self.window @@ -307,7 +316,7 @@ impl Document { let browsing_context = browsing_context.as_ref().unwrap(); let active_document = browsing_context.active_document(); - if self != active_document { + if self != &*active_document { return false; } // FIXME: It should also check whether the browser context is top-level or not @@ -1462,6 +1471,7 @@ impl LayoutDocumentHelpers for LayoutJS<Document> { impl Document { pub fn new_inherited(window: &Window, + browsing_context: Option<&BrowsingContext>, url: Option<Url>, is_html_document: IsHTMLDocument, content_type: Option<DOMString>, @@ -1480,6 +1490,7 @@ impl Document { Document { node: Node::new_document_node(), window: JS::from_ref(window), + browsing_context: browsing_context.map(JS::from_ref), implementation: Default::default(), location: Default::default(), content_type: match content_type { @@ -1549,6 +1560,7 @@ impl Document { let docloader = DocumentLoader::new(&*doc.loader()); Ok(Document::new(win, None, + None, IsHTMLDocument::NonHTMLDocument, None, None, @@ -1557,6 +1569,7 @@ impl Document { } pub fn new(window: &Window, + browsing_context: Option<&BrowsingContext>, url: Option<Url>, doctype: IsHTMLDocument, content_type: Option<DOMString>, @@ -1565,6 +1578,7 @@ impl Document { doc_loader: DocumentLoader) -> Root<Document> { let document = reflect_dom_object(box Document::new_inherited(window, + browsing_context, url, doctype, content_type, @@ -1628,6 +1642,7 @@ impl Document { }; let new_doc = Document::new(self.window(), None, + None, doctype, None, None, @@ -1716,7 +1731,7 @@ impl DocumentMethods for Document { // Step 2. let candidate = browsing_context.active_document(); // Step 3. - if candidate == target { + if &*candidate == target { true } else { false //TODO Step 4. |