Store a pointer to the browsing context in the Document.

This commit is contained in:
Ms2ger 2016-02-09 14:00:39 +01:00
parent 0b27807ad4
commit 152cec69eb
10 changed files with 53 additions and 23 deletions

View file

@ -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 {
@ -1548,6 +1559,7 @@ impl Document {
let doc = doc.r();
let docloader = DocumentLoader::new(&*doc.loader());
Ok(Document::new(win,
None,
None,
IsHTMLDocument::NonHTMLDocument,
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,
@ -1627,6 +1641,7 @@ impl Document {
IsHTMLDocument::NonHTMLDocument
};
let new_doc = Document::new(self.window(),
None,
None,
doctype,
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.