mirror of
https://github.com/servo/servo.git
synced 2025-07-23 07:13:52 +01:00
Auto merge of #14647 - servo:current-global, r=jdm
Support the 'current' global object. <!-- Reviewable:start --> This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/14647) <!-- Reviewable:end -->
This commit is contained in:
commit
885d152e92
10 changed files with 51 additions and 23 deletions
|
@ -1822,6 +1822,7 @@ impl Document {
|
||||||
pub fn new_inherited(window: &Window,
|
pub fn new_inherited(window: &Window,
|
||||||
browsing_context: Option<&BrowsingContext>,
|
browsing_context: Option<&BrowsingContext>,
|
||||||
url: Option<ServoUrl>,
|
url: Option<ServoUrl>,
|
||||||
|
origin: Origin,
|
||||||
is_html_document: IsHTMLDocument,
|
is_html_document: IsHTMLDocument,
|
||||||
content_type: Option<DOMString>,
|
content_type: Option<DOMString>,
|
||||||
last_modified: Option<String>,
|
last_modified: Option<String>,
|
||||||
|
@ -1838,15 +1839,6 @@ impl Document {
|
||||||
(DocumentReadyState::Complete, true)
|
(DocumentReadyState::Complete, true)
|
||||||
};
|
};
|
||||||
|
|
||||||
// Incomplete implementation of Document origin specification at
|
|
||||||
// https://html.spec.whatwg.org/multipage/#origin:document
|
|
||||||
let origin = if url_has_network_scheme(&url) {
|
|
||||||
Origin::new(&url)
|
|
||||||
} else {
|
|
||||||
// Default to DOM standard behaviour
|
|
||||||
Origin::opaque_identifier()
|
|
||||||
};
|
|
||||||
|
|
||||||
Document {
|
Document {
|
||||||
node: Node::new_document_node(),
|
node: Node::new_document_node(),
|
||||||
window: JS::from_ref(window),
|
window: JS::from_ref(window),
|
||||||
|
@ -1932,6 +1924,7 @@ impl Document {
|
||||||
Ok(Document::new(window,
|
Ok(Document::new(window,
|
||||||
None,
|
None,
|
||||||
None,
|
None,
|
||||||
|
doc.origin().alias(),
|
||||||
IsHTMLDocument::NonHTMLDocument,
|
IsHTMLDocument::NonHTMLDocument,
|
||||||
None,
|
None,
|
||||||
None,
|
None,
|
||||||
|
@ -1944,6 +1937,7 @@ impl Document {
|
||||||
pub fn new(window: &Window,
|
pub fn new(window: &Window,
|
||||||
browsing_context: Option<&BrowsingContext>,
|
browsing_context: Option<&BrowsingContext>,
|
||||||
url: Option<ServoUrl>,
|
url: Option<ServoUrl>,
|
||||||
|
origin: Origin,
|
||||||
doctype: IsHTMLDocument,
|
doctype: IsHTMLDocument,
|
||||||
content_type: Option<DOMString>,
|
content_type: Option<DOMString>,
|
||||||
last_modified: Option<String>,
|
last_modified: Option<String>,
|
||||||
|
@ -1955,6 +1949,7 @@ impl Document {
|
||||||
let document = reflect_dom_object(box Document::new_inherited(window,
|
let document = reflect_dom_object(box Document::new_inherited(window,
|
||||||
browsing_context,
|
browsing_context,
|
||||||
url,
|
url,
|
||||||
|
origin,
|
||||||
doctype,
|
doctype,
|
||||||
content_type,
|
content_type,
|
||||||
last_modified,
|
last_modified,
|
||||||
|
@ -2026,6 +2021,8 @@ impl Document {
|
||||||
let new_doc = Document::new(self.window(),
|
let new_doc = Document::new(self.window(),
|
||||||
None,
|
None,
|
||||||
None,
|
None,
|
||||||
|
// https://github.com/whatwg/html/issues/2109
|
||||||
|
Origin::opaque_identifier(),
|
||||||
doctype,
|
doctype,
|
||||||
None,
|
None,
|
||||||
None,
|
None,
|
||||||
|
|
|
@ -79,6 +79,7 @@ impl DOMImplementationMethods for DOMImplementation {
|
||||||
let doc = XMLDocument::new(win,
|
let doc = XMLDocument::new(win,
|
||||||
None,
|
None,
|
||||||
None,
|
None,
|
||||||
|
self.document.origin().alias(),
|
||||||
IsHTMLDocument::NonHTMLDocument,
|
IsHTMLDocument::NonHTMLDocument,
|
||||||
Some(DOMString::from(content_type)),
|
Some(DOMString::from(content_type)),
|
||||||
None,
|
None,
|
||||||
|
@ -124,6 +125,7 @@ impl DOMImplementationMethods for DOMImplementation {
|
||||||
let doc = Document::new(win,
|
let doc = Document::new(win,
|
||||||
None,
|
None,
|
||||||
None,
|
None,
|
||||||
|
self.document.origin().alias(),
|
||||||
IsHTMLDocument::HTMLDocument,
|
IsHTMLDocument::HTMLDocument,
|
||||||
None,
|
None,
|
||||||
None,
|
None,
|
||||||
|
|
|
@ -61,6 +61,7 @@ impl DOMParserMethods for DOMParser {
|
||||||
let document = Document::new(&self.window,
|
let document = Document::new(&self.window,
|
||||||
None,
|
None,
|
||||||
Some(url.clone()),
|
Some(url.clone()),
|
||||||
|
doc.origin().alias(),
|
||||||
IsHTMLDocument::HTMLDocument,
|
IsHTMLDocument::HTMLDocument,
|
||||||
Some(content_type),
|
Some(content_type),
|
||||||
None,
|
None,
|
||||||
|
@ -77,6 +78,7 @@ impl DOMParserMethods for DOMParser {
|
||||||
let document = Document::new(&self.window,
|
let document = Document::new(&self.window,
|
||||||
None,
|
None,
|
||||||
Some(url.clone()),
|
Some(url.clone()),
|
||||||
|
doc.origin().alias(),
|
||||||
IsHTMLDocument::NonHTMLDocument,
|
IsHTMLDocument::NonHTMLDocument,
|
||||||
Some(content_type),
|
Some(content_type),
|
||||||
None,
|
None,
|
||||||
|
|
|
@ -27,7 +27,7 @@ use js::jsapi::{HandleValue, Evaluate2, JSAutoCompartment, JSContext};
|
||||||
use js::jsapi::{JSObject, JS_GetContext};
|
use js::jsapi::{JSObject, JS_GetContext};
|
||||||
use js::jsapi::{JS_GetObjectRuntime, MutableHandleValue};
|
use js::jsapi::{JS_GetObjectRuntime, MutableHandleValue};
|
||||||
use js::panic::maybe_resume_unwind;
|
use js::panic::maybe_resume_unwind;
|
||||||
use js::rust::{CompileOptionsWrapper, get_object_class};
|
use js::rust::{CompileOptionsWrapper, Runtime, get_object_class};
|
||||||
use libc;
|
use libc;
|
||||||
use msg::constellation_msg::PipelineId;
|
use msg::constellation_msg::PipelineId;
|
||||||
use net_traits::{CoreResourceThread, ResourceThreads, IpcSend};
|
use net_traits::{CoreResourceThread, ResourceThreads, IpcSend};
|
||||||
|
@ -506,6 +506,19 @@ impl GlobalScope {
|
||||||
}
|
}
|
||||||
unreachable!();
|
unreachable!();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Returns the ["current"] global object.
|
||||||
|
///
|
||||||
|
/// ["current"]: https://html.spec.whatwg.org/multipage/#current
|
||||||
|
#[allow(unsafe_code)]
|
||||||
|
pub fn current() -> Root<Self> {
|
||||||
|
unsafe {
|
||||||
|
let cx = Runtime::get();
|
||||||
|
assert!(!cx.is_null());
|
||||||
|
let global = CurrentGlobalOrNull(cx);
|
||||||
|
global_scope_from_global(global)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn timestamp_in_ms(time: Timespec) -> u64 {
|
fn timestamp_in_ms(time: Timespec) -> u64 {
|
||||||
|
|
|
@ -168,7 +168,7 @@ impl HTMLIFrameElement {
|
||||||
layout_threads: PREFS.get("layout.threads").as_u64().expect("count") as usize,
|
layout_threads: PREFS.get("layout.threads").as_u64().expect("count") as usize,
|
||||||
};
|
};
|
||||||
|
|
||||||
ScriptThread::process_attach_layout(new_layout_info);
|
ScriptThread::process_attach_layout(new_layout_info, document.origin().alias());
|
||||||
} else {
|
} else {
|
||||||
let load_info = IFrameLoadInfoWithData {
|
let load_info = IFrameLoadInfoWithData {
|
||||||
info: load_info,
|
info: load_info,
|
||||||
|
@ -332,11 +332,9 @@ impl HTMLIFrameElement {
|
||||||
self.pipeline_id.get()
|
self.pipeline_id.get()
|
||||||
.and_then(|pipeline_id| ScriptThread::find_document(pipeline_id))
|
.and_then(|pipeline_id| ScriptThread::find_document(pipeline_id))
|
||||||
.and_then(|document| {
|
.and_then(|document| {
|
||||||
// FIXME(#10964): this should use the Document's origin and the
|
let current_global = GlobalScope::current();
|
||||||
// origin of the incumbent settings object.
|
let current_document = current_global.as_window().Document();
|
||||||
let contained_url = document.global().get_url();
|
if document.origin().same_origin(current_document.origin()) {
|
||||||
if self.global().get_url().origin() == contained_url.origin() ||
|
|
||||||
contained_url.as_str() == "about:blank" {
|
|
||||||
Some(Root::from_ref(document.window()))
|
Some(Root::from_ref(document.window()))
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
|
|
|
@ -1720,6 +1720,8 @@ impl Node {
|
||||||
let loader = DocumentLoader::new(&*document.loader());
|
let loader = DocumentLoader::new(&*document.loader());
|
||||||
let document = Document::new(window, None,
|
let document = Document::new(window, None,
|
||||||
Some(document.url()),
|
Some(document.url()),
|
||||||
|
// https://github.com/whatwg/dom/issues/378
|
||||||
|
document.origin().alias(),
|
||||||
is_html_doc, None,
|
is_html_doc, None,
|
||||||
None, DocumentSource::NotFromParser, loader,
|
None, DocumentSource::NotFromParser, loader,
|
||||||
None, None);
|
None, None);
|
||||||
|
|
|
@ -106,6 +106,7 @@ impl ServoParser {
|
||||||
// Step 1.
|
// Step 1.
|
||||||
let loader = DocumentLoader::new(&*context_document.loader());
|
let loader = DocumentLoader::new(&*context_document.loader());
|
||||||
let document = Document::new(window, None, Some(url.clone()),
|
let document = Document::new(window, None, Some(url.clone()),
|
||||||
|
context_document.origin().alias(),
|
||||||
IsHTMLDocument::HTMLDocument,
|
IsHTMLDocument::HTMLDocument,
|
||||||
None, None,
|
None, None,
|
||||||
DocumentSource::FromParser,
|
DocumentSource::FromParser,
|
||||||
|
|
|
@ -16,6 +16,7 @@ use dom::location::Location;
|
||||||
use dom::node::Node;
|
use dom::node::Node;
|
||||||
use dom::window::Window;
|
use dom::window::Window;
|
||||||
use js::jsapi::{JSContext, JSObject};
|
use js::jsapi::{JSContext, JSObject};
|
||||||
|
use origin::Origin;
|
||||||
use servo_url::ServoUrl;
|
use servo_url::ServoUrl;
|
||||||
|
|
||||||
// https://dom.spec.whatwg.org/#xmldocument
|
// https://dom.spec.whatwg.org/#xmldocument
|
||||||
|
@ -28,6 +29,7 @@ impl XMLDocument {
|
||||||
fn new_inherited(window: &Window,
|
fn new_inherited(window: &Window,
|
||||||
browsing_context: Option<&BrowsingContext>,
|
browsing_context: Option<&BrowsingContext>,
|
||||||
url: Option<ServoUrl>,
|
url: Option<ServoUrl>,
|
||||||
|
origin: Origin,
|
||||||
is_html_document: IsHTMLDocument,
|
is_html_document: IsHTMLDocument,
|
||||||
content_type: Option<DOMString>,
|
content_type: Option<DOMString>,
|
||||||
last_modified: Option<String>,
|
last_modified: Option<String>,
|
||||||
|
@ -37,6 +39,7 @@ impl XMLDocument {
|
||||||
document: Document::new_inherited(window,
|
document: Document::new_inherited(window,
|
||||||
browsing_context,
|
browsing_context,
|
||||||
url,
|
url,
|
||||||
|
origin,
|
||||||
is_html_document,
|
is_html_document,
|
||||||
content_type,
|
content_type,
|
||||||
last_modified,
|
last_modified,
|
||||||
|
@ -50,6 +53,7 @@ impl XMLDocument {
|
||||||
pub fn new(window: &Window,
|
pub fn new(window: &Window,
|
||||||
browsing_context: Option<&BrowsingContext>,
|
browsing_context: Option<&BrowsingContext>,
|
||||||
url: Option<ServoUrl>,
|
url: Option<ServoUrl>,
|
||||||
|
origin: Origin,
|
||||||
doctype: IsHTMLDocument,
|
doctype: IsHTMLDocument,
|
||||||
content_type: Option<DOMString>,
|
content_type: Option<DOMString>,
|
||||||
last_modified: Option<String>,
|
last_modified: Option<String>,
|
||||||
|
@ -60,6 +64,7 @@ impl XMLDocument {
|
||||||
box XMLDocument::new_inherited(window,
|
box XMLDocument::new_inherited(window,
|
||||||
browsing_context,
|
browsing_context,
|
||||||
url,
|
url,
|
||||||
|
origin,
|
||||||
doctype,
|
doctype,
|
||||||
content_type,
|
content_type,
|
||||||
last_modified,
|
last_modified,
|
||||||
|
|
|
@ -1204,6 +1204,7 @@ impl XMLHttpRequest {
|
||||||
Document::new(win,
|
Document::new(win,
|
||||||
None,
|
None,
|
||||||
parsed_url,
|
parsed_url,
|
||||||
|
doc.origin().alias(),
|
||||||
is_html_document,
|
is_html_document,
|
||||||
content_type,
|
content_type,
|
||||||
None,
|
None,
|
||||||
|
|
|
@ -77,6 +77,7 @@ use net_traits::image_cache_thread::{ImageCacheChan, ImageCacheResult, ImageCach
|
||||||
use net_traits::request::{CredentialsMode, Destination, RequestInit};
|
use net_traits::request::{CredentialsMode, Destination, RequestInit};
|
||||||
use net_traits::storage_thread::StorageType;
|
use net_traits::storage_thread::StorageType;
|
||||||
use network_listener::NetworkListener;
|
use network_listener::NetworkListener;
|
||||||
|
use origin::Origin;
|
||||||
use profile_traits::mem::{self, OpaqueSender, Report, ReportKind, ReportsChan};
|
use profile_traits::mem::{self, OpaqueSender, Report, ReportKind, ReportsChan};
|
||||||
use profile_traits::time::{self, ProfilerCategory, profile};
|
use profile_traits::time::{self, ProfilerCategory, profile};
|
||||||
use script_layout_interface::message::{self, NewLayoutThreadInfo, ReflowQueryType};
|
use script_layout_interface::message::{self, NewLayoutThreadInfo, ReflowQueryType};
|
||||||
|
@ -152,6 +153,7 @@ struct InProgressLoad {
|
||||||
is_visible: bool,
|
is_visible: bool,
|
||||||
/// The requested URL of the load.
|
/// The requested URL of the load.
|
||||||
url: ServoUrl,
|
url: ServoUrl,
|
||||||
|
origin: Origin,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl InProgressLoad {
|
impl InProgressLoad {
|
||||||
|
@ -161,7 +163,8 @@ impl InProgressLoad {
|
||||||
parent_info: Option<(PipelineId, FrameType)>,
|
parent_info: Option<(PipelineId, FrameType)>,
|
||||||
layout_chan: Sender<message::Msg>,
|
layout_chan: Sender<message::Msg>,
|
||||||
window_size: Option<WindowSizeData>,
|
window_size: Option<WindowSizeData>,
|
||||||
url: ServoUrl) -> InProgressLoad {
|
url: ServoUrl,
|
||||||
|
origin: Origin) -> InProgressLoad {
|
||||||
InProgressLoad {
|
InProgressLoad {
|
||||||
pipeline_id: id,
|
pipeline_id: id,
|
||||||
frame_id: frame_id,
|
frame_id: frame_id,
|
||||||
|
@ -172,6 +175,7 @@ impl InProgressLoad {
|
||||||
is_frozen: false,
|
is_frozen: false,
|
||||||
is_visible: true,
|
is_visible: true,
|
||||||
url: url,
|
url: url,
|
||||||
|
origin: origin,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -537,8 +541,9 @@ impl ScriptThreadFactory for ScriptThread {
|
||||||
|
|
||||||
let mut failsafe = ScriptMemoryFailsafe::new(&script_thread);
|
let mut failsafe = ScriptMemoryFailsafe::new(&script_thread);
|
||||||
|
|
||||||
|
let origin = Origin::new(&load_data.url);
|
||||||
let new_load = InProgressLoad::new(id, frame_id, parent_info, layout_chan, window_size,
|
let new_load = InProgressLoad::new(id, frame_id, parent_info, layout_chan, window_size,
|
||||||
load_data.url.clone());
|
load_data.url.clone(), origin);
|
||||||
script_thread.start_page_load(new_load, load_data);
|
script_thread.start_page_load(new_load, load_data);
|
||||||
|
|
||||||
let reporter_name = format!("script-reporter-{}", id);
|
let reporter_name = format!("script-reporter-{}", id);
|
||||||
|
@ -602,12 +607,12 @@ impl ScriptThread {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn process_attach_layout(new_layout_info: NewLayoutInfo) {
|
pub fn process_attach_layout(new_layout_info: NewLayoutInfo, origin: Origin) {
|
||||||
SCRIPT_THREAD_ROOT.with(|root| {
|
SCRIPT_THREAD_ROOT.with(|root| {
|
||||||
if let Some(script_thread) = root.get() {
|
if let Some(script_thread) = root.get() {
|
||||||
let script_thread = unsafe { &*script_thread };
|
let script_thread = unsafe { &*script_thread };
|
||||||
script_thread.profile_event(ScriptThreadEventCategory::AttachLayout, || {
|
script_thread.profile_event(ScriptThreadEventCategory::AttachLayout, || {
|
||||||
script_thread.handle_new_layout(new_layout_info);
|
script_thread.handle_new_layout(new_layout_info, origin);
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -778,7 +783,8 @@ impl ScriptThread {
|
||||||
FromConstellation(ConstellationControlMsg::AttachLayout(
|
FromConstellation(ConstellationControlMsg::AttachLayout(
|
||||||
new_layout_info)) => {
|
new_layout_info)) => {
|
||||||
self.profile_event(ScriptThreadEventCategory::AttachLayout, || {
|
self.profile_event(ScriptThreadEventCategory::AttachLayout, || {
|
||||||
self.handle_new_layout(new_layout_info);
|
let origin = Origin::new(&new_layout_info.load_data.url);
|
||||||
|
self.handle_new_layout(new_layout_info, origin);
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
FromConstellation(ConstellationControlMsg::Resize(id, size, size_type)) => {
|
FromConstellation(ConstellationControlMsg::Resize(id, size, size_type)) => {
|
||||||
|
@ -1189,7 +1195,7 @@ impl ScriptThread {
|
||||||
window.set_scroll_offsets(scroll_offsets)
|
window.set_scroll_offsets(scroll_offsets)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn handle_new_layout(&self, new_layout_info: NewLayoutInfo) {
|
fn handle_new_layout(&self, new_layout_info: NewLayoutInfo, origin: Origin) {
|
||||||
let NewLayoutInfo {
|
let NewLayoutInfo {
|
||||||
parent_info,
|
parent_info,
|
||||||
new_pipeline_id,
|
new_pipeline_id,
|
||||||
|
@ -1231,7 +1237,7 @@ impl ScriptThread {
|
||||||
// Kick off the fetch for the new resource.
|
// Kick off the fetch for the new resource.
|
||||||
let new_load = InProgressLoad::new(new_pipeline_id, frame_id, parent_info,
|
let new_load = InProgressLoad::new(new_pipeline_id, frame_id, parent_info,
|
||||||
layout_chan, window_size,
|
layout_chan, window_size,
|
||||||
load_data.url.clone());
|
load_data.url.clone(), origin);
|
||||||
if load_data.url.as_str() == "about:blank" {
|
if load_data.url.as_str() == "about:blank" {
|
||||||
self.start_page_load_about_blank(new_load);
|
self.start_page_load_about_blank(new_load);
|
||||||
} else {
|
} else {
|
||||||
|
@ -1803,6 +1809,7 @@ impl ScriptThread {
|
||||||
let document = Document::new(&window,
|
let document = Document::new(&window,
|
||||||
Some(&browsing_context),
|
Some(&browsing_context),
|
||||||
Some(final_url.clone()),
|
Some(final_url.clone()),
|
||||||
|
incomplete.origin,
|
||||||
is_html_document,
|
is_html_document,
|
||||||
content_type,
|
content_type,
|
||||||
last_modified,
|
last_modified,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue