Files
tubestation/servo/components/script/dom/xmldocument.rs
Alan Jeffrey c1586c2a52 servo: Merge #14971 - Constellation informs script about documents becoming inactive, active or fully active (from asajeffrey:script-track-active-documents); r=cbrewster
<!-- Please describe your changes on the following line: -->

This PR replaces the current freeze/thaw mechanism by messages from the constellation to script informing it about when documents become inactive, active or fully active.

This means we can now implement |Document::is_active()| which is used in |document.write|.

This PR also changes how timers work: previously they were initialized running, and were then frozen/thawed. This means there was a transitory period when timers were running even though the document was not fully active. With this PR, timers are initially suspended, and are only resumed when the document is made fully active.

---
<!-- 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 #14876
- [X] These changes do not require tests because it's an interal refactoring.

<!-- 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: b5c94bad371114ab9f03e910f66c00a042997fc2
2017-01-27 16:30:37 -08:00

105 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::browsingcontext::BrowsingContext;
use dom::document::{Document, DocumentSource, 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,
browsing_context: Option<&BrowsingContext>,
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,
browsing_context,
url,
origin,
is_html_document,
content_type,
last_modified,
activity,
source,
doc_loader,
None,
None),
}
}
pub fn new(window: &Window,
browsing_context: Option<&BrowsingContext>,
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,
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)
}
}