Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Cross origin wrappers #16501

Closed
wants to merge 13 commits into from

changed to use globalscope origin

  • Loading branch information
avadacatavra committed Apr 25, 2017
commit aa7b4f61622e7d96cca29e5c8680dc7b1af31353
@@ -2597,6 +2597,7 @@ def definition_body(self):
values["members"] = "\n".join(members)

return CGGeneric("""\
let origin = object.origin().clone();

This comment has been minimized.

Copy link
@jdm

jdm May 1, 2017

Member

Do we need this clone if we pass a reference to create_global_object?

let raw = Box::into_raw(object);
let _rt = RootedTraceable::new(&*raw);
@@ -2606,7 +2607,8 @@ def definition_body(self):
&Class.base,
raw as *const libc::c_void,
_trace,
obj.handle_mut());
obj.handle_mut(),
&origin);
assert!(!obj.is_null());
(*raw).init_reflector(obj.get());
@@ -12,7 +12,7 @@ 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::{CreateServoJSPrincipal, RUST_SYMBOL_TO_JSID, UncheckedUnwrapObject};
use js::glue::{CreateRustJSPrincipal, 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};
@@ -29,6 +29,7 @@ use js::jsapi::{TrueHandleValue, Value};
use js::jsval::{JSVal, PrivateValue};
use js::rust::{define_methods, define_properties, get_object_class};
use libc;
use servo_url::MutableOrigin;
use std::ptr;

/// The class of a non-callback interface object.
@@ -131,17 +132,17 @@ pub unsafe fn create_global_object(
class: &'static JSClass,
private: *const libc::c_void,
trace: TraceHook,
rval: MutableHandleObject) {
rval: MutableHandleObject,
origin: &MutableOrigin) {
assert!(rval.is_null());

let mut options = CompartmentOptions::default();
options.behaviors_.version_ = JSVersion::JSVERSION_ECMA_5;
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,
let origin = Box::new(origin.clone());
let mut principal = CreateRustJSPrincipal(Box::into_raw(origin) as *const ::libc::c_void,
None,
None);

@@ -34,7 +34,7 @@ use script_runtime::{CommonScriptMsg, ScriptChan, ScriptPort, StackRootTLS, get_
use script_runtime::ScriptThreadEventCategory::WorkerEvent;
use script_traits::{TimerEvent, TimerSource, WorkerGlobalScopeInit, WorkerScriptLoadOrigin};
use servo_rand::random;
use servo_url::ServoUrl;
use servo_url::{MutableOrigin, ServoUrl};
use std::mem::replace;
use std::sync::{Arc, Mutex};
use std::sync::atomic::AtomicBool;
@@ -146,6 +146,10 @@ impl DedicatedWorkerGlobalScope {
}
}

pub fn origin(&self) -> MutableOrigin {
MutableOrigin::new(self.workerglobalscope.get_url().origin())
}

#[allow(unsafe_code)]
pub fn run_worker_scope(init: WorkerGlobalScopeInit,
worker_url: ServoUrl,
@@ -30,7 +30,7 @@ use script_runtime::{CommonScriptMsg, StackRootTLS, get_reports, new_rt_and_cx,
use script_traits::{TimerEvent, WorkerGlobalScopeInit, ScopeThings, ServiceWorkerMsg, WorkerScriptLoadOrigin};
use servo_config::prefs::PREFS;
use servo_rand::random;
use servo_url::ServoUrl;
use servo_url::{MutableOrigin, ServoUrl};
use std::sync::mpsc::{Receiver, RecvError, Select, Sender, channel};
use std::thread;
use std::time::Duration;
@@ -138,6 +138,10 @@ impl ServiceWorkerGlobalScope {
}
}

pub fn origin(&self) -> MutableOrigin {
MutableOrigin::new(self.scope_url.origin())
}

#[allow(unsafe_code)]
pub fn run_serviceworker_scope(scope_things: ScopeThings,
own_sender: Sender<ServiceWorkerScriptMsg>,
@@ -273,9 +273,6 @@ pub struct Window {
/// Directory to store unminified scripts for this window if unminify-js
/// opt is enabled.
unminified_js_dir: DOMRefCell<Option<String>>,

/// origin for cross origin wrappers
origin: Box<MutableOrigin>
}

impl Window {
@@ -297,10 +294,6 @@ impl Window {
self.js_runtime.borrow().as_ref().unwrap().cx()
}

pub fn get_origin(&self) -> Box<MutableOrigin> {
self.origin.clone()
}

pub fn dom_manipulation_task_source(&self) -> DOMManipulationTaskSource {
self.dom_manipulation_task_source.clone()
}
@@ -1818,7 +1811,6 @@ impl Window {
suppress_reflow: Cell::new(true),
pending_reflow_count: Cell::new(0),
current_state: Cell::new(WindowState::Alive),

devtools_marker_sender: DOMRefCell::new(None),
devtools_markers: DOMRefCell::new(HashSet::new()),
webdriver_script_chan: DOMRefCell::new(None),
@@ -1831,17 +1823,12 @@ 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<MutableOrigin> {
self.origin.clone()
}
}

fn should_move_clip_rect(clip_rect: Rect<Au>, new_viewport: Rect<f32>) -> bool {
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.