diff --git a/components/script/dom/dissimilaroriginlocation.rs b/components/script/dom/dissimilaroriginlocation.rs index b4cd2d84e5d2..d3aec5c90ee3 100644 --- a/components/script/dom/dissimilaroriginlocation.rs +++ b/components/script/dom/dissimilaroriginlocation.rs @@ -12,6 +12,7 @@ use dom::bindings::str::DOMString; use dom::bindings::str::USVString; use dom::dissimilaroriginwindow::DissimilarOriginWindow; use dom_struct::dom_struct; +use servo_url::MutableOrigin; /// Represents a dissimilar-origin `Location` that exists in another script thread. /// @@ -43,6 +44,10 @@ impl DissimilarOriginLocation { window, DissimilarOriginLocationBinding::Wrap) } + + pub fn origin(&self) -> &MutableOrigin { + self.window.origin() + } } impl DissimilarOriginLocationMethods for DissimilarOriginLocation { diff --git a/components/script/dom/dissimilaroriginwindow.rs b/components/script/dom/dissimilaroriginwindow.rs index 0f3cbd06df0c..e4e8b0dad400 100644 --- a/components/script/dom/dissimilaroriginwindow.rs +++ b/components/script/dom/dissimilaroriginwindow.rs @@ -19,6 +19,7 @@ use js::jsval::{JSVal, UndefinedValue}; use msg::constellation_msg::PipelineId; use script_traits::ScriptMsg as ConstellationMsg; use servo_url::ImmutableOrigin; +use servo_url::MutableOrigin; use servo_url::ServoUrl; /// Represents a dissimilar-origin `Window` that exists in another script thread. @@ -56,12 +57,17 @@ impl DissimilarOriginWindow { global_to_clone_from.constellation_chan().clone(), global_to_clone_from.scheduler_chan().clone(), global_to_clone_from.resource_threads().clone(), - timer_event_chan), + timer_event_chan, + global_to_clone_from.origin().clone()), browsing_context: JS::from_ref(browsing_context), location: MutNullableJS::new(None), }; unsafe { DissimilarOriginWindowBinding::Wrap(cx, win) } } + + pub fn origin(&self) -> &MutableOrigin { + self.globalscope.origin() + } } impl DissimilarOriginWindowMethods for DissimilarOriginWindow { diff --git a/components/script/dom/globalscope.rs b/components/script/dom/globalscope.rs index 73ba61e4557d..931d1f576aa8 100644 --- a/components/script/dom/globalscope.rs +++ b/components/script/dom/globalscope.rs @@ -38,7 +38,7 @@ use script_runtime::{CommonScriptMsg, ScriptChan, ScriptPort}; use script_thread::{MainThreadScriptChan, RunnableWrapper, ScriptThread}; use script_traits::{MsDuration, ScriptMsg as ConstellationMsg, TimerEvent}; use script_traits::{TimerEventId, TimerSchedulerMsg, TimerSource}; -use servo_url::ServoUrl; +use servo_url::{MutableOrigin, ServoUrl}; use std::cell::Cell; use std::collections::HashMap; use std::collections::hash_map::Entry; @@ -92,6 +92,9 @@ pub struct GlobalScope { resource_threads: ResourceThreads, timers: OneshotTimers, + + /// The origin of the globalscope + origin: MutableOrigin, } impl GlobalScope { @@ -103,7 +106,8 @@ impl GlobalScope { constellation_chan: IpcSender, scheduler_chan: IpcSender, resource_threads: ResourceThreads, - timer_event_chan: IpcSender) + timer_event_chan: IpcSender, + origin: MutableOrigin) -> Self { GlobalScope { eventtarget: EventTarget::new_inherited(), @@ -120,6 +124,7 @@ impl GlobalScope { in_error_reporting_mode: Default::default(), resource_threads: resource_threads, timers: OneshotTimers::new(timer_event_chan, scheduler_chan), + origin: origin, } } @@ -238,6 +243,11 @@ impl GlobalScope { self.pipeline_id } + /// Get the origin for this global scope + pub fn origin(&self) -> &MutableOrigin { + &self.origin + } + /// Get the [base url](https://html.spec.whatwg.org/multipage/#api-base-url) /// for this global scope. pub fn api_base_url(&self) -> ServoUrl { diff --git a/components/script/dom/location.rs b/components/script/dom/location.rs index 399e37487220..854cdf424c2a 100644 --- a/components/script/dom/location.rs +++ b/components/script/dom/location.rs @@ -13,7 +13,7 @@ use dom::globalscope::GlobalScope; use dom::urlhelper::UrlHelper; use dom::window::Window; use dom_struct::dom_struct; -use servo_url::ServoUrl; +use servo_url::{MutableOrigin, ServoUrl}; #[dom_struct] pub struct Location { @@ -60,6 +60,10 @@ impl Location { pub fn reload_without_origin_check(&self) { self.window.load_url(self.get_url(), true, true, None); } + + pub fn origin(&self) -> &MutableOrigin { + self.window.origin() + } } impl LocationMethods for Location { diff --git a/components/script/dom/window.rs b/components/script/dom/window.rs index df7fe995c1fd..eaba1ded928e 100644 --- a/components/script/dom/window.rs +++ b/components/script/dom/window.rs @@ -85,7 +85,7 @@ use servo_atoms::Atom; use servo_config::opts; use servo_config::prefs::PREFS; use servo_geometry::{f32_rect_to_au_rect, max_rect}; -use servo_url::{Host, ImmutableOrigin, ServoUrl}; +use servo_url::{Host, MutableOrigin, ImmutableOrigin, ServoUrl}; use std::ascii::AsciiExt; use std::borrow::ToOwned; use std::cell::Cell; @@ -286,6 +286,10 @@ impl Window { } } + pub fn origin(&self) -> &MutableOrigin { + self.globalscope.origin() + } + pub fn get_cx(&self) -> *mut JSContext { self.js_runtime.borrow().as_ref().unwrap().cx() } @@ -1749,6 +1753,7 @@ impl Window { id: PipelineId, parent_info: Option<(PipelineId, FrameType)>, window_size: Option, + origin: MutableOrigin, webvr_thread: Option>) -> Root { let layout_rpc: Box = { @@ -1771,7 +1776,8 @@ impl Window { constellation_chan, scheduler_chan, resource_threads, - timer_event_chan), + timer_event_chan, + origin), script_chan: script_chan, dom_manipulation_task_source: dom_task_source, user_interaction_task_source: user_task_source, diff --git a/components/script/dom/workerglobalscope.rs b/components/script/dom/workerglobalscope.rs index 948d72c251b8..fd1f03db1e34 100644 --- a/components/script/dom/workerglobalscope.rs +++ b/components/script/dom/workerglobalscope.rs @@ -37,7 +37,7 @@ use script_runtime::{CommonScriptMsg, ScriptChan, ScriptPort}; use script_thread::RunnableWrapper; use script_traits::{TimerEvent, TimerEventId}; use script_traits::WorkerGlobalScopeInit; -use servo_url::ServoUrl; +use servo_url::{MutableOrigin, ServoUrl}; use std::default::Default; use std::rc::Rc; use std::sync::Arc; @@ -59,6 +59,7 @@ pub fn prepare_workerscope_init(global: &GlobalScope, scheduler_chan: global.scheduler_chan().clone(), worker_id: global.get_next_worker_id(), pipeline_id: global.pipeline_id(), + origin: global.origin().immutable().clone(), }; init @@ -109,7 +110,8 @@ impl WorkerGlobalScope { init.constellation_chan, init.scheduler_chan, init.resource_threads, - timer_event_chan), + timer_event_chan, + MutableOrigin::new(init.origin)), worker_id: init.worker_id, worker_url: worker_url, closing: closing, diff --git a/components/script/script_thread.rs b/components/script/script_thread.rs index 92537fa7abe5..96167cec236c 100644 --- a/components/script/script_thread.rs +++ b/components/script/script_thread.rs @@ -1784,6 +1784,7 @@ impl ScriptThread { incomplete.pipeline_id, incomplete.parent_info, incomplete.window_size, + incomplete.origin.clone(), self.webvr_thread.clone()); // Initialize the browsing context for the window. diff --git a/components/script_traits/lib.rs b/components/script_traits/lib.rs index da5191f73bdc..ed0e09468acc 100644 --- a/components/script_traits/lib.rs +++ b/components/script_traits/lib.rs @@ -777,6 +777,8 @@ pub struct WorkerGlobalScopeInit { pub worker_id: WorkerId, /// The pipeline id pub pipeline_id: PipelineId, + /// The origin + pub origin: ImmutableOrigin, } /// Common entities representing a network load origin