forked from mirrors/gecko-dev
<!-- Please describe your changes on the following line: --> This PR allows different `Window` objects in the same browsing context to share a `BrowsingContext` object. SpiderMonkey requires a `WindowProxy` object to be in the same compartment as its `Window`, so when a `WindowProxy` changes `Window`, we have to brain-transplant it. In turn this requires the reflector of a `BrowsingContext` to be mutable. --- <!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `__` with appropriate data: --> - [X] `./mach build -d` does not report any errors - [X] `./mach test-tidy` does not report any errors - [X] These changes fix #13608 and #14843 - [X] These changes do not require tests because an existing test catches this (`/html/browsers/the-window-object/Window-document.html` is now `PASS`) <!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. --> Source-Repo: https://github.com/servo/servo Source-Revision: 67c182638253211553161495cd2e4570002fd5bc
103 lines
4.1 KiB
Rust
103 lines
4.1 KiB
Rust
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
use core::nonzero::NonZero;
|
|
use document_loader::DocumentLoader;
|
|
use dom::bindings::codegen::Bindings::DocumentBinding::DocumentMethods;
|
|
use dom::bindings::codegen::Bindings::XMLDocumentBinding::{self, XMLDocumentMethods};
|
|
use dom::bindings::inheritance::Castable;
|
|
use dom::bindings::js::Root;
|
|
use dom::bindings::reflector::reflect_dom_object;
|
|
use dom::bindings::str::DOMString;
|
|
use dom::document::{Document, DocumentSource, HasBrowsingContext, IsHTMLDocument};
|
|
use dom::location::Location;
|
|
use dom::node::Node;
|
|
use dom::window::Window;
|
|
use js::jsapi::{JSContext, JSObject};
|
|
use origin::Origin;
|
|
use script_traits::DocumentActivity;
|
|
use servo_url::ServoUrl;
|
|
|
|
// https://dom.spec.whatwg.org/#xmldocument
|
|
#[dom_struct]
|
|
pub struct XMLDocument {
|
|
document: Document,
|
|
}
|
|
|
|
impl XMLDocument {
|
|
fn new_inherited(window: &Window,
|
|
has_browsing_context: HasBrowsingContext,
|
|
url: Option<ServoUrl>,
|
|
origin: Origin,
|
|
is_html_document: IsHTMLDocument,
|
|
content_type: Option<DOMString>,
|
|
last_modified: Option<String>,
|
|
activity: DocumentActivity,
|
|
source: DocumentSource,
|
|
doc_loader: DocumentLoader) -> XMLDocument {
|
|
XMLDocument {
|
|
document: Document::new_inherited(window,
|
|
has_browsing_context,
|
|
url,
|
|
origin,
|
|
is_html_document,
|
|
content_type,
|
|
last_modified,
|
|
activity,
|
|
source,
|
|
doc_loader,
|
|
None,
|
|
None),
|
|
}
|
|
}
|
|
|
|
pub fn new(window: &Window,
|
|
has_browsing_context: HasBrowsingContext,
|
|
url: Option<ServoUrl>,
|
|
origin: Origin,
|
|
doctype: IsHTMLDocument,
|
|
content_type: Option<DOMString>,
|
|
last_modified: Option<String>,
|
|
activity: DocumentActivity,
|
|
source: DocumentSource,
|
|
doc_loader: DocumentLoader)
|
|
-> Root<XMLDocument> {
|
|
let doc = reflect_dom_object(
|
|
box XMLDocument::new_inherited(window,
|
|
has_browsing_context,
|
|
url,
|
|
origin,
|
|
doctype,
|
|
content_type,
|
|
last_modified,
|
|
activity,
|
|
source,
|
|
doc_loader),
|
|
window,
|
|
XMLDocumentBinding::Wrap);
|
|
{
|
|
let node = doc.upcast::<Node>();
|
|
node.set_owner_doc(&doc.document);
|
|
}
|
|
doc
|
|
}
|
|
}
|
|
|
|
impl XMLDocumentMethods for XMLDocument {
|
|
// https://html.spec.whatwg.org/multipage/#dom-document-location
|
|
fn GetLocation(&self) -> Option<Root<Location>> {
|
|
self.upcast::<Document>().GetLocation()
|
|
}
|
|
|
|
// https://html.spec.whatwg.org/multipage/#dom-tree-accessors:supported-property-names
|
|
fn SupportedPropertyNames(&self) -> Vec<DOMString> {
|
|
self.upcast::<Document>().SupportedPropertyNames()
|
|
}
|
|
|
|
#[allow(unsafe_code)]
|
|
// https://html.spec.whatwg.org/multipage/#dom-tree-accessors:dom-document-nameditem-filter
|
|
unsafe fn NamedGetter(&self, _cx: *mut JSContext, name: DOMString) -> Option<NonZero<*mut JSObject>> {
|
|
self.upcast::<Document>().NamedGetter(_cx, name)
|
|
}
|
|
}
|