diff --git a/components/script/dom/bindings/interface.rs b/components/script/dom/bindings/interface.rs index 517adbde425..6d63e09ed14 100644 --- a/components/script/dom/bindings/interface.rs +++ b/components/script/dom/bindings/interface.rs @@ -10,8 +10,9 @@ use dom::bindings::constant::{ConstantSpec, define_constants}; use dom::bindings::conversions::{DOM_OBJECT_SLOT, get_dom_class}; use dom::bindings::guard::Guard; use dom::bindings::utils::{DOM_PROTOTYPE_SLOT, ProtoOrIfaceArray, get_proto_or_iface_array}; +use dom::window::Window; use js::error::throw_type_error; -use js::glue::{RUST_SYMBOL_TO_JSID, UncheckedUnwrapObject}; +use js::glue::{CreateServoJSPrincipal, RUST_SYMBOL_TO_JSID, UncheckedUnwrapObject}; use js::jsapi::{Class, ClassOps, CompartmentOptions, GetGlobalForObjectCrossCompartment}; use js::jsapi::{GetWellKnownSymbol, HandleObject, HandleValue, JSAutoCompartment}; use js::jsapi::{JSClass, JSContext, JSFUN_CONSTRUCTOR, JSFunctionSpec, JSObject}; @@ -138,9 +139,13 @@ pub unsafe fn create_global_object( options.creationOptions_.traceGlobal_ = Some(trace); options.creationOptions_.sharedMemoryAndAtomics_ = true; + let x = private.clone() as *const Window; + let obj = &*x; + let mut principal = CreateServoJSPrincipal(Box::into_raw(obj.origin()) as *const ::libc::c_void); + rval.set(JS_NewGlobalObject(cx, class, - ptr::null_mut(), + principal, OnNewGlobalHookOption::DontFireOnNewGlobalHook, &options)); assert!(!rval.is_null()); diff --git a/components/script/dom/bindings/utils.rs b/components/script/dom/bindings/utils.rs index c7039fd168c..35e00e510a4 100644 --- a/components/script/dom/bindings/utils.rs +++ b/components/script/dom/bindings/utils.rs @@ -18,6 +18,7 @@ use js; use js::JS_CALLEE; use js::glue::{CallJitGetterOp, CallJitMethodOp, CallJitSetterOp, IsWrapper}; use js::glue::{GetCrossCompartmentWrapper, WrapperNew}; +use js::glue::getPrincipalOrigin; use js::glue::{RUST_FUNCTION_VALUE_TO_JITINFO, RUST_JSID_IS_INT, RUST_JSID_IS_STRING}; use js::glue::{RUST_JSID_TO_INT, RUST_JSID_TO_STRING, UnwrapObject}; use js::jsapi::{CallArgs, DOMCallbacks, GetGlobalForObjectCrossCompartment}; @@ -29,9 +30,11 @@ use js::jsapi::{JS_GetProperty, JS_GetPrototype, JS_GetReservedSlot, JS_HasPrope use js::jsapi::{JS_HasPropertyById, JS_IsExceptionPending, JS_IsGlobalObject}; use js::jsapi::{JS_ResolveStandardClass, JS_SetProperty, ToWindowProxyIfWindow}; use js::jsapi::{JS_StringHasLatin1Chars, MutableHandleValue, ObjectOpResult}; +use js::jsapi::JSPrincipals; use js::jsval::{JSVal, UndefinedValue}; use js::rust::{GCMethods, ToString, get_object_class, is_dom_class}; use libc; +use servo_url::MutableOrigin; use std::ffi::CString; use std::os::raw::{c_char, c_void}; use std::ptr; @@ -47,6 +50,15 @@ impl HeapSizeOf for WindowProxyHandler { } } +struct ServoJSPrincipal(*mut JSPrincipals); + +impl ServoJSPrincipal { + pub unsafe fn origin(&self) -> MutableOrigin { + let origin = getPrincipalOrigin(self.0) as *mut MutableOrigin; + (*origin).clone() + } +} + #[derive(JSTraceable, HeapSizeOf)] /// Static data associated with a global object. pub struct GlobalStaticData { diff --git a/components/script/dom/window.rs b/components/script/dom/window.rs index eaba1ded928..7f1521b0029 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, MutableOrigin, ImmutableOrigin, ServoUrl}; +use servo_url::{Host, ImmutableOrigin, MutableOrigin, ServoUrl}; use std::ascii::AsciiExt; use std::borrow::ToOwned; use std::cell::Cell; @@ -273,6 +273,9 @@ pub struct Window { /// Directory to store unminified scripts for this window if unminify-js /// opt is enabled. unminified_js_dir: DOMRefCell>, + + /// origin for cross origin wrappers + origin: Box } impl Window { @@ -294,6 +297,10 @@ impl Window { self.js_runtime.borrow().as_ref().unwrap().cx() } + pub fn get_origin(&self) -> Box { + self.origin.clone() + } + pub fn dom_manipulation_task_source(&self) -> DOMManipulationTaskSource { self.dom_manipulation_task_source.clone() } @@ -1824,12 +1831,17 @@ impl Window { permission_state_invocation_results: DOMRefCell::new(HashMap::new()), pending_layout_images: DOMRefCell::new(HashMap::new()), unminified_js_dir: DOMRefCell::new(None), + origin: Box::new(origin), }; unsafe { WindowBinding::Wrap(runtime.cx(), win) } } + + pub fn origin(&self) -> Box { + self.origin.clone() + } } fn should_move_clip_rect(clip_rect: Rect, new_viewport: Rect) -> bool {