mirror of
https://github.com/servo/servo.git
synced 2025-08-02 20:20:14 +01:00
Privatize Document
This commit is contained in:
parent
d0addd36bb
commit
8825296869
8 changed files with 38 additions and 22 deletions
|
@ -39,7 +39,7 @@ impl BrowserContext {
|
|||
|
||||
pub fn active_window(&self) -> Temporary<Window> {
|
||||
let doc = self.active_document().root();
|
||||
Temporary::new(doc.window.clone())
|
||||
Temporary::new(doc.window().clone())
|
||||
}
|
||||
|
||||
pub fn window_proxy(&self) -> *mut JSObject {
|
||||
|
|
|
@ -62,7 +62,7 @@ use url::Url;
|
|||
|
||||
use std::collections::hashmap::HashMap;
|
||||
use std::ascii::StrAsciiExt;
|
||||
use std::cell::{Cell, RefCell};
|
||||
use std::cell::{Cell, Ref, RefCell};
|
||||
use std::default::Default;
|
||||
use time;
|
||||
|
||||
|
@ -75,16 +75,17 @@ pub enum IsHTMLDocument {
|
|||
|
||||
#[jstraceable]
|
||||
#[must_root]
|
||||
#[privatize]
|
||||
pub struct Document {
|
||||
pub node: Node,
|
||||
node: Node,
|
||||
reflector_: Reflector,
|
||||
pub window: JS<Window>,
|
||||
window: JS<Window>,
|
||||
idmap: RefCell<HashMap<Atom, Vec<JS<Element>>>>,
|
||||
implementation: MutNullableJS<DOMImplementation>,
|
||||
content_type: DOMString,
|
||||
last_modified: RefCell<Option<DOMString>>,
|
||||
pub encoding_name: RefCell<DOMString>,
|
||||
pub is_html_document: bool,
|
||||
encoding_name: RefCell<DOMString>,
|
||||
is_html_document: bool,
|
||||
url: Url,
|
||||
quirks_mode: Cell<QuirksMode>,
|
||||
images: MutNullableJS<HTMLCollection>,
|
||||
|
@ -343,6 +344,21 @@ impl Document {
|
|||
node.set_owner_doc(*document);
|
||||
Temporary::from_rooted(*document)
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn window<'a>(&'a self) -> &'a JS<Window> {
|
||||
&self.window
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn encoding_name(&self) -> Ref<DOMString> {
|
||||
self.encoding_name.borrow()
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn is_html_document(&self) -> bool {
|
||||
self.is_html_document
|
||||
}
|
||||
}
|
||||
|
||||
impl Reflectable for Document {
|
||||
|
|
|
@ -39,7 +39,7 @@ impl DOMImplementation {
|
|||
}
|
||||
|
||||
pub fn new(document: JSRef<Document>) -> Temporary<DOMImplementation> {
|
||||
let window = document.window.root();
|
||||
let window = document.window().root();
|
||||
reflect_dom_object(box DOMImplementation::new_inherited(document),
|
||||
&Window(*window),
|
||||
DOMImplementationBinding::Wrap)
|
||||
|
@ -73,7 +73,7 @@ impl<'a> DOMImplementationMethods for JSRef<'a, DOMImplementation> {
|
|||
fn CreateDocument(self, namespace: Option<DOMString>, qname: DOMString,
|
||||
maybe_doctype: Option<JSRef<DocumentType>>) -> Fallible<Temporary<Document>> {
|
||||
let doc = self.document.root();
|
||||
let win = doc.window.root();
|
||||
let win = doc.window().root();
|
||||
|
||||
// Step 1.
|
||||
let doc = Document::new(*win, None, NonHTMLDocument, None).root();
|
||||
|
@ -118,7 +118,7 @@ impl<'a> DOMImplementationMethods for JSRef<'a, DOMImplementation> {
|
|||
// http://dom.spec.whatwg.org/#dom-domimplementation-createhtmldocument
|
||||
fn CreateHTMLDocument(self, title: Option<DOMString>) -> Temporary<Document> {
|
||||
let document = self.document.root();
|
||||
let win = document.window.root();
|
||||
let win = document.window().root();
|
||||
|
||||
// Step 1-2.
|
||||
let doc = Document::new(*win, None, HTMLDocument, None).root();
|
||||
|
|
|
@ -268,7 +268,7 @@ impl LayoutElementHelpers for JS<Element> {
|
|||
}
|
||||
let node: JS<Node> = self.transmute_copy();
|
||||
let owner_doc = node.owner_doc_for_layout().unsafe_get();
|
||||
(*owner_doc).is_html_document
|
||||
(*owner_doc).is_html_document()
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -631,7 +631,7 @@ impl<'a> ElementMethods for JSRef<'a, Element> {
|
|||
let node: JSRef<Node> = NodeCast::from_ref(self);
|
||||
node.owner_doc().root()
|
||||
};
|
||||
let window = doc.window.root();
|
||||
let window = doc.window().root();
|
||||
let list = NamedNodeMap::new(*window, self);
|
||||
self.attr_list.assign(Some(list));
|
||||
}
|
||||
|
|
|
@ -48,7 +48,7 @@ impl<'a> PrivateHTMLImageElementHelpers for JSRef<'a, HTMLImageElement> {
|
|||
fn update_image(self, value: Option<(DOMString, &Url)>) {
|
||||
let node: JSRef<Node> = NodeCast::from_ref(self);
|
||||
let document = node.owner_doc().root();
|
||||
let window = document.window.root();
|
||||
let window = document.window().root();
|
||||
let image_cache = &window.image_cache_task;
|
||||
match value {
|
||||
None => {
|
||||
|
|
|
@ -741,7 +741,7 @@ impl<'a> NodeHelpers<'a> for JSRef<'a, Node> {
|
|||
}
|
||||
|
||||
fn is_in_html_doc(self) -> bool {
|
||||
self.owner_doc().root().is_html_document
|
||||
self.owner_doc().root().is_html_document()
|
||||
}
|
||||
|
||||
fn children(self) -> AbstractNodeChildrenIterator<'a> {
|
||||
|
@ -1112,7 +1112,7 @@ impl Node {
|
|||
document: JSRef<Document>,
|
||||
wrap_fn: extern "Rust" fn(*mut JSContext, &GlobalRef, Box<N>) -> Temporary<N>)
|
||||
-> Temporary<N> {
|
||||
let window = document.window.root();
|
||||
let window = document.window().root();
|
||||
reflect_dom_object(node, &global::Window(*window), wrap_fn)
|
||||
}
|
||||
|
||||
|
@ -1474,11 +1474,11 @@ impl Node {
|
|||
},
|
||||
DocumentNodeTypeId => {
|
||||
let document: JSRef<Document> = DocumentCast::to_ref(node).unwrap();
|
||||
let is_html_doc = match document.is_html_document {
|
||||
let is_html_doc = match document.is_html_document() {
|
||||
true => HTMLDocument,
|
||||
false => NonHTMLDocument
|
||||
};
|
||||
let window = document.window.root();
|
||||
let window = document.window().root();
|
||||
let document = Document::new(*window, Some(document.url().clone()),
|
||||
is_html_doc, None);
|
||||
NodeCast::from_temporary(document)
|
||||
|
@ -1516,7 +1516,7 @@ impl Node {
|
|||
DocumentNodeTypeId => {
|
||||
let node_doc: JSRef<Document> = DocumentCast::to_ref(node).unwrap();
|
||||
let copy_doc: JSRef<Document> = DocumentCast::to_ref(*copy).unwrap();
|
||||
copy_doc.set_encoding_name(node_doc.encoding_name.borrow().clone());
|
||||
copy_doc.set_encoding_name(node_doc.encoding_name().clone());
|
||||
copy_doc.set_quirks_mode(node_doc.quirks_mode());
|
||||
},
|
||||
ElementNodeTypeId(..) => {
|
||||
|
@ -1524,7 +1524,7 @@ impl Node {
|
|||
let copy_elem: JSRef<Element> = ElementCast::to_ref(*copy).unwrap();
|
||||
|
||||
// FIXME: https://github.com/mozilla/servo/issues/1737
|
||||
let window = document.window.root();
|
||||
let window = document.window().root();
|
||||
for attr in node_elem.attrs.borrow().iter().map(|attr| attr.root()) {
|
||||
copy_elem.attrs.borrow_mut().push_unrooted(
|
||||
&Attr::new(*window,
|
||||
|
@ -1667,7 +1667,7 @@ impl<'a> NodeMethods for JSRef<'a, Node> {
|
|||
}
|
||||
|
||||
let doc = self.owner_doc().root();
|
||||
let window = doc.window.root();
|
||||
let window = doc.window().root();
|
||||
let child_list = NodeList::new_child_list(*window, self);
|
||||
self.child_list.assign(Some(child_list));
|
||||
self.child_list.get().unwrap()
|
||||
|
@ -2125,7 +2125,7 @@ pub fn document_from_node<T: NodeBase+Reflectable>(derived: JSRef<T>) -> Tempora
|
|||
|
||||
pub fn window_from_node<T: NodeBase+Reflectable>(derived: JSRef<T>) -> Temporary<Window> {
|
||||
let document = document_from_node(derived).root();
|
||||
Temporary::new(document.window.clone())
|
||||
Temporary::new(document.window().clone())
|
||||
}
|
||||
|
||||
impl<'a> VirtualMethods for JSRef<'a, Node> {
|
||||
|
|
|
@ -26,7 +26,7 @@ impl Range {
|
|||
}
|
||||
|
||||
pub fn new(document: JSRef<Document>) -> Temporary<Range> {
|
||||
let window = document.window.root();
|
||||
let window = document.window().root();
|
||||
reflect_dom_object(box Range::new_inherited(),
|
||||
&Window(*window),
|
||||
RangeBinding::Wrap)
|
||||
|
|
|
@ -49,7 +49,7 @@ impl TreeWalker {
|
|||
root_node: JSRef<Node>,
|
||||
what_to_show: u32,
|
||||
filter: Filter) -> Temporary<TreeWalker> {
|
||||
let window = document.window.root();
|
||||
let window = document.window().root();
|
||||
reflect_dom_object(box TreeWalker::new_inherited(root_node, what_to_show, filter),
|
||||
&Window(*window),
|
||||
TreeWalkerBinding::Wrap)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue