From 07b18265f3aaa55cc7ded68702a4cc0e00819534 Mon Sep 17 00:00:00 2001 From: Ms2ger Date: Tue, 20 Dec 2016 16:34:49 +0100 Subject: [PATCH 1/4] Update js. --- Cargo.lock | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.lock b/Cargo.lock index cce0a8e4bbc..f3f72b586e0 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1243,7 +1243,7 @@ dependencies = [ [[package]] name = "js" version = "0.1.3" -source = "git+https://github.com/servo/rust-mozjs#342f304a455080acf64f5ceb40a7f8059481ca01" +source = "git+https://github.com/servo/rust-mozjs#15ff1e83446e998112dcde731610e8b60cc32abf" dependencies = [ "cmake 0.1.17 (registry+https://github.com/rust-lang/crates.io-index)", "heapsize 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)", From 01e336f6912292b5ca4c7349846a5d100974d99e Mon Sep 17 00:00:00 2001 From: Ms2ger Date: Tue, 20 Dec 2016 17:00:57 +0100 Subject: [PATCH 2/4] Implement a getter for the 'current' global object. --- components/script/dom/globalscope.rs | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/components/script/dom/globalscope.rs b/components/script/dom/globalscope.rs index ae08bc0e5fd..d0976ec302c 100644 --- a/components/script/dom/globalscope.rs +++ b/components/script/dom/globalscope.rs @@ -27,7 +27,7 @@ use js::jsapi::{HandleValue, Evaluate2, JSAutoCompartment, JSContext}; use js::jsapi::{JSObject, JS_GetContext}; use js::jsapi::{JS_GetObjectRuntime, MutableHandleValue}; use js::panic::maybe_resume_unwind; -use js::rust::{CompileOptionsWrapper, get_object_class}; +use js::rust::{CompileOptionsWrapper, Runtime, get_object_class}; use libc; use msg::constellation_msg::PipelineId; use net_traits::{CoreResourceThread, ResourceThreads, IpcSend}; @@ -506,6 +506,19 @@ impl GlobalScope { } unreachable!(); } + + /// Returns the ["current"] global object. + /// + /// ["current"]: https://html.spec.whatwg.org/multipage/#current + #[allow(unsafe_code)] + pub fn current() -> Root { + 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 { From ec5d08c88730ac707368de03528744677a75231d Mon Sep 17 00:00:00 2001 From: Ms2ger Date: Mon, 28 Nov 2016 18:27:23 +0100 Subject: [PATCH 3/4] Pass the Document's origin to its constructor. CC #10963. --- components/script/dom/document.rs | 15 ++++++--------- components/script/dom/domimplementation.rs | 2 ++ components/script/dom/domparser.rs | 2 ++ components/script/dom/htmliframeelement.rs | 2 +- components/script/dom/node.rs | 2 ++ components/script/dom/servoparser/mod.rs | 1 + components/script/dom/xmldocument.rs | 5 +++++ components/script/dom/xmlhttprequest.rs | 1 + components/script/script_thread.rs | 21 ++++++++++++++------- 9 files changed, 34 insertions(+), 17 deletions(-) diff --git a/components/script/dom/document.rs b/components/script/dom/document.rs index 6f8f2435311..79acb69096d 100644 --- a/components/script/dom/document.rs +++ b/components/script/dom/document.rs @@ -1822,6 +1822,7 @@ impl Document { pub fn new_inherited(window: &Window, browsing_context: Option<&BrowsingContext>, url: Option, + origin: Origin, is_html_document: IsHTMLDocument, content_type: Option, last_modified: Option, @@ -1838,15 +1839,6 @@ impl Document { (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 { node: Node::new_document_node(), window: JS::from_ref(window), @@ -1932,6 +1924,7 @@ impl Document { Ok(Document::new(window, None, None, + doc.origin().alias(), IsHTMLDocument::NonHTMLDocument, None, None, @@ -1944,6 +1937,7 @@ impl Document { pub fn new(window: &Window, browsing_context: Option<&BrowsingContext>, url: Option, + origin: Origin, doctype: IsHTMLDocument, content_type: Option, last_modified: Option, @@ -1955,6 +1949,7 @@ impl Document { let document = reflect_dom_object(box Document::new_inherited(window, browsing_context, url, + origin, doctype, content_type, last_modified, @@ -2026,6 +2021,8 @@ impl Document { let new_doc = Document::new(self.window(), None, None, + // https://github.com/whatwg/html/issues/2109 + Origin::opaque_identifier(), doctype, None, None, diff --git a/components/script/dom/domimplementation.rs b/components/script/dom/domimplementation.rs index 7556e64d0a7..446eda7e6ce 100644 --- a/components/script/dom/domimplementation.rs +++ b/components/script/dom/domimplementation.rs @@ -79,6 +79,7 @@ impl DOMImplementationMethods for DOMImplementation { let doc = XMLDocument::new(win, None, None, + self.document.origin().alias(), IsHTMLDocument::NonHTMLDocument, Some(DOMString::from(content_type)), None, @@ -124,6 +125,7 @@ impl DOMImplementationMethods for DOMImplementation { let doc = Document::new(win, None, None, + self.document.origin().alias(), IsHTMLDocument::HTMLDocument, None, None, diff --git a/components/script/dom/domparser.rs b/components/script/dom/domparser.rs index 0ce2d50e09a..3f49712471a 100644 --- a/components/script/dom/domparser.rs +++ b/components/script/dom/domparser.rs @@ -61,6 +61,7 @@ impl DOMParserMethods for DOMParser { let document = Document::new(&self.window, None, Some(url.clone()), + doc.origin().alias(), IsHTMLDocument::HTMLDocument, Some(content_type), None, @@ -77,6 +78,7 @@ impl DOMParserMethods for DOMParser { let document = Document::new(&self.window, None, Some(url.clone()), + doc.origin().alias(), IsHTMLDocument::NonHTMLDocument, Some(content_type), None, diff --git a/components/script/dom/htmliframeelement.rs b/components/script/dom/htmliframeelement.rs index 53c7e34f94f..5bc1a514b81 100644 --- a/components/script/dom/htmliframeelement.rs +++ b/components/script/dom/htmliframeelement.rs @@ -168,7 +168,7 @@ impl HTMLIFrameElement { 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 { let load_info = IFrameLoadInfoWithData { info: load_info, diff --git a/components/script/dom/node.rs b/components/script/dom/node.rs index 6a2ccea832f..c335018aae5 100644 --- a/components/script/dom/node.rs +++ b/components/script/dom/node.rs @@ -1720,6 +1720,8 @@ impl Node { let loader = DocumentLoader::new(&*document.loader()); let document = Document::new(window, None, Some(document.url()), + // https://github.com/whatwg/dom/issues/378 + document.origin().alias(), is_html_doc, None, None, DocumentSource::NotFromParser, loader, None, None); diff --git a/components/script/dom/servoparser/mod.rs b/components/script/dom/servoparser/mod.rs index 2f4f485be12..51143ebdbad 100644 --- a/components/script/dom/servoparser/mod.rs +++ b/components/script/dom/servoparser/mod.rs @@ -106,6 +106,7 @@ impl ServoParser { // Step 1. let loader = DocumentLoader::new(&*context_document.loader()); let document = Document::new(window, None, Some(url.clone()), + context_document.origin().alias(), IsHTMLDocument::HTMLDocument, None, None, DocumentSource::FromParser, diff --git a/components/script/dom/xmldocument.rs b/components/script/dom/xmldocument.rs index 191b142dbea..87c639742f6 100644 --- a/components/script/dom/xmldocument.rs +++ b/components/script/dom/xmldocument.rs @@ -16,6 +16,7 @@ use dom::location::Location; use dom::node::Node; use dom::window::Window; use js::jsapi::{JSContext, JSObject}; +use origin::Origin; use servo_url::ServoUrl; // https://dom.spec.whatwg.org/#xmldocument @@ -28,6 +29,7 @@ impl XMLDocument { fn new_inherited(window: &Window, browsing_context: Option<&BrowsingContext>, url: Option, + origin: Origin, is_html_document: IsHTMLDocument, content_type: Option, last_modified: Option, @@ -37,6 +39,7 @@ impl XMLDocument { document: Document::new_inherited(window, browsing_context, url, + origin, is_html_document, content_type, last_modified, @@ -50,6 +53,7 @@ impl XMLDocument { pub fn new(window: &Window, browsing_context: Option<&BrowsingContext>, url: Option, + origin: Origin, doctype: IsHTMLDocument, content_type: Option, last_modified: Option, @@ -60,6 +64,7 @@ impl XMLDocument { box XMLDocument::new_inherited(window, browsing_context, url, + origin, doctype, content_type, last_modified, diff --git a/components/script/dom/xmlhttprequest.rs b/components/script/dom/xmlhttprequest.rs index f676eac3b64..218efbbf1ab 100644 --- a/components/script/dom/xmlhttprequest.rs +++ b/components/script/dom/xmlhttprequest.rs @@ -1204,6 +1204,7 @@ impl XMLHttpRequest { Document::new(win, None, parsed_url, + doc.origin().alias(), is_html_document, content_type, None, diff --git a/components/script/script_thread.rs b/components/script/script_thread.rs index 538ce0b5f8c..130c9787a6d 100644 --- a/components/script/script_thread.rs +++ b/components/script/script_thread.rs @@ -77,6 +77,7 @@ use net_traits::image_cache_thread::{ImageCacheChan, ImageCacheResult, ImageCach use net_traits::request::{CredentialsMode, Destination, RequestInit}; use net_traits::storage_thread::StorageType; use network_listener::NetworkListener; +use origin::Origin; use profile_traits::mem::{self, OpaqueSender, Report, ReportKind, ReportsChan}; use profile_traits::time::{self, ProfilerCategory, profile}; use script_layout_interface::message::{self, NewLayoutThreadInfo, ReflowQueryType}; @@ -152,6 +153,7 @@ struct InProgressLoad { is_visible: bool, /// The requested URL of the load. url: ServoUrl, + origin: Origin, } impl InProgressLoad { @@ -161,7 +163,8 @@ impl InProgressLoad { parent_info: Option<(PipelineId, FrameType)>, layout_chan: Sender, window_size: Option, - url: ServoUrl) -> InProgressLoad { + url: ServoUrl, + origin: Origin) -> InProgressLoad { InProgressLoad { pipeline_id: id, frame_id: frame_id, @@ -172,6 +175,7 @@ impl InProgressLoad { is_frozen: false, is_visible: true, url: url, + origin: origin, } } } @@ -540,8 +544,9 @@ impl ScriptThreadFactory for ScriptThread { 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, - load_data.url.clone()); + load_data.url.clone(), origin); script_thread.start_page_load(new_load, load_data); let reporter_name = format!("script-reporter-{}", id); @@ -605,12 +610,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| { if let Some(script_thread) = root.get() { let script_thread = unsafe { &*script_thread }; script_thread.profile_event(ScriptThreadEventCategory::AttachLayout, || { - script_thread.handle_new_layout(new_layout_info); + script_thread.handle_new_layout(new_layout_info, origin); }) } }); @@ -783,7 +788,8 @@ impl ScriptThread { FromConstellation(ConstellationControlMsg::AttachLayout( new_layout_info)) => { 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)) => { @@ -1194,7 +1200,7 @@ impl ScriptThread { 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 { parent_info, new_pipeline_id, @@ -1236,7 +1242,7 @@ impl ScriptThread { // Kick off the fetch for the new resource. let new_load = InProgressLoad::new(new_pipeline_id, frame_id, parent_info, layout_chan, window_size, - load_data.url.clone()); + load_data.url.clone(), origin); if load_data.url.as_str() == "about:blank" { self.start_page_load_about_blank(new_load); } else { @@ -1808,6 +1814,7 @@ impl ScriptThread { let document = Document::new(&window, Some(&browsing_context), Some(final_url.clone()), + incomplete.origin, is_html_document, content_type, last_modified, From d49e34c1b1e6e3759633c9315a3e02dde091546c Mon Sep 17 00:00:00 2001 From: Ms2ger Date: Mon, 28 Nov 2016 18:36:45 +0100 Subject: [PATCH 4/4] Implement correct security checks for HTMLIFrameElement::contentDocument. Fixes #10964. --- components/script/dom/htmliframeelement.rs | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/components/script/dom/htmliframeelement.rs b/components/script/dom/htmliframeelement.rs index 5bc1a514b81..692598d5339 100644 --- a/components/script/dom/htmliframeelement.rs +++ b/components/script/dom/htmliframeelement.rs @@ -332,11 +332,9 @@ impl HTMLIFrameElement { self.pipeline_id.get() .and_then(|pipeline_id| ScriptThread::find_document(pipeline_id)) .and_then(|document| { - // FIXME(#10964): this should use the Document's origin and the - // origin of the incumbent settings object. - let contained_url = document.global().get_url(); - if self.global().get_url().origin() == contained_url.origin() || - contained_url.as_str() == "about:blank" { + let current_global = GlobalScope::current(); + let current_document = current_global.as_window().Document(); + if document.origin().same_origin(current_document.origin()) { Some(Root::from_ref(document.window())) } else { None