mirror of
https://github.com/servo/servo.git
synced 2025-08-03 04:30:10 +01:00
refactor(script): move crate::dom::bindings::{utils → principals)::ServoJSPrincipal
This commit is contained in:
parent
dfb4a0c844
commit
320965bfb9
5 changed files with 51 additions and 49 deletions
|
@ -9,7 +9,8 @@ use crate::dom::bindings::codegen::PrototypeList;
|
||||||
use crate::dom::bindings::constant::{define_constants, ConstantSpec};
|
use crate::dom::bindings::constant::{define_constants, ConstantSpec};
|
||||||
use crate::dom::bindings::conversions::{get_dom_class, DOM_OBJECT_SLOT};
|
use crate::dom::bindings::conversions::{get_dom_class, DOM_OBJECT_SLOT};
|
||||||
use crate::dom::bindings::guard::Guard;
|
use crate::dom::bindings::guard::Guard;
|
||||||
use crate::dom::bindings::utils::{ProtoOrIfaceArray, ServoJSPrincipal, DOM_PROTOTYPE_SLOT};
|
use crate::dom::bindings::principals::ServoJSPrincipal;
|
||||||
|
use crate::dom::bindings::utils::{ProtoOrIfaceArray, DOM_PROTOTYPE_SLOT};
|
||||||
use crate::dom::window::Window;
|
use crate::dom::window::Window;
|
||||||
use crate::script_runtime::JSContext as SafeJSContext;
|
use crate::script_runtime::JSContext as SafeJSContext;
|
||||||
use js::error::throw_type_error;
|
use js::error::throw_type_error;
|
||||||
|
|
|
@ -145,6 +145,7 @@ pub mod interface;
|
||||||
pub mod iterable;
|
pub mod iterable;
|
||||||
pub mod namespace;
|
pub mod namespace;
|
||||||
pub mod num;
|
pub mod num;
|
||||||
|
pub mod principals;
|
||||||
pub mod proxyhandler;
|
pub mod proxyhandler;
|
||||||
pub mod record;
|
pub mod record;
|
||||||
pub mod refcounted;
|
pub mod refcounted;
|
||||||
|
|
44
components/script/dom/bindings/principals.rs
Normal file
44
components/script/dom/bindings/principals.rs
Normal file
|
@ -0,0 +1,44 @@
|
||||||
|
use js::glue::{
|
||||||
|
CreateRustJSPrincipals, DestroyRustJSPrincipals, GetRustJSPrincipalsPrivate,
|
||||||
|
JSPrincipalsCallbacks,
|
||||||
|
};
|
||||||
|
use js::jsapi::JSPrincipals;
|
||||||
|
use servo_url::MutableOrigin;
|
||||||
|
|
||||||
|
// TODO: RAII ref-counting
|
||||||
|
pub struct ServoJSPrincipal(pub *mut JSPrincipals);
|
||||||
|
|
||||||
|
impl ServoJSPrincipal {
|
||||||
|
pub fn new(origin: &MutableOrigin) -> Self {
|
||||||
|
let private: Box<MutableOrigin> = Box::new(origin.clone());
|
||||||
|
Self(unsafe { CreateRustJSPrincipals(&PRINCIPALS_CALLBACKS, Box::into_raw(private) as _) })
|
||||||
|
}
|
||||||
|
|
||||||
|
pub unsafe fn origin(&self) -> MutableOrigin {
|
||||||
|
let origin = GetRustJSPrincipalsPrivate(self.0) as *mut MutableOrigin;
|
||||||
|
(*origin).clone()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub unsafe extern "C" fn destroy_servo_jsprincipal(principals: *mut JSPrincipals) {
|
||||||
|
Box::from_raw(GetRustJSPrincipalsPrivate(principals) as *mut MutableOrigin);
|
||||||
|
DestroyRustJSPrincipals(principals);
|
||||||
|
}
|
||||||
|
|
||||||
|
const PRINCIPALS_CALLBACKS: JSPrincipalsCallbacks = JSPrincipalsCallbacks {
|
||||||
|
write: None,
|
||||||
|
isSystemOrAddonPrincipal: Some(principals_is_system_or_addon_principal),
|
||||||
|
};
|
||||||
|
|
||||||
|
unsafe extern "C" fn principals_is_system_or_addon_principal(_: *mut JSPrincipals) -> bool {
|
||||||
|
false
|
||||||
|
}
|
||||||
|
|
||||||
|
//TODO is same_origin_domain equivalent to subsumes for our purposes
|
||||||
|
pub unsafe extern "C" fn subsumes(obj: *mut JSPrincipals, other: *mut JSPrincipals) -> bool {
|
||||||
|
let obj = ServoJSPrincipal(obj);
|
||||||
|
let other = ServoJSPrincipal(other);
|
||||||
|
let obj_origin = obj.origin();
|
||||||
|
let other_origin = other.origin();
|
||||||
|
obj_origin.same_origin_domain(&other_origin)
|
||||||
|
}
|
|
@ -19,17 +19,12 @@ use crate::script_runtime::JSContext as SafeJSContext;
|
||||||
use js::conversions::ToJSValConvertible;
|
use js::conversions::ToJSValConvertible;
|
||||||
use js::glue::JS_GetReservedSlot;
|
use js::glue::JS_GetReservedSlot;
|
||||||
use js::glue::{CallJitGetterOp, CallJitMethodOp, CallJitSetterOp, IsWrapper};
|
use js::glue::{CallJitGetterOp, CallJitMethodOp, CallJitSetterOp, IsWrapper};
|
||||||
use js::glue::{
|
|
||||||
CreateRustJSPrincipals, DestroyRustJSPrincipals, GetRustJSPrincipalsPrivate,
|
|
||||||
JSPrincipalsCallbacks,
|
|
||||||
};
|
|
||||||
use js::glue::{UnwrapObjectDynamic, UnwrapObjectStatic, RUST_JSID_TO_INT, RUST_JSID_TO_STRING};
|
use js::glue::{UnwrapObjectDynamic, UnwrapObjectStatic, RUST_JSID_TO_INT, RUST_JSID_TO_STRING};
|
||||||
use js::glue::{
|
use js::glue::{
|
||||||
RUST_FUNCTION_VALUE_TO_JITINFO, RUST_JSID_IS_INT, RUST_JSID_IS_STRING, RUST_JSID_IS_VOID,
|
RUST_FUNCTION_VALUE_TO_JITINFO, RUST_JSID_IS_INT, RUST_JSID_IS_STRING, RUST_JSID_IS_VOID,
|
||||||
};
|
};
|
||||||
use js::jsapi::HandleId as RawHandleId;
|
use js::jsapi::HandleId as RawHandleId;
|
||||||
use js::jsapi::HandleObject as RawHandleObject;
|
use js::jsapi::HandleObject as RawHandleObject;
|
||||||
use js::jsapi::JSPrincipals;
|
|
||||||
use js::jsapi::MutableHandleIdVector as RawMutableHandleIdVector;
|
use js::jsapi::MutableHandleIdVector as RawMutableHandleIdVector;
|
||||||
use js::jsapi::{AtomToLinearString, GetLinearStringCharAt, GetLinearStringLength};
|
use js::jsapi::{AtomToLinearString, GetLinearStringCharAt, GetLinearStringLength};
|
||||||
use js::jsapi::{CallArgs, DOMCallbacks, GetNonCCWObjectGlobal};
|
use js::jsapi::{CallArgs, DOMCallbacks, GetNonCCWObjectGlobal};
|
||||||
|
@ -53,7 +48,6 @@ use js::rust::{Handle, HandleId, HandleObject, HandleValue, MutableHandleValue};
|
||||||
use js::typedarray::{CreateWith, Float32Array};
|
use js::typedarray::{CreateWith, Float32Array};
|
||||||
use js::JS_CALLEE;
|
use js::JS_CALLEE;
|
||||||
use malloc_size_of::{MallocSizeOf, MallocSizeOfOps};
|
use malloc_size_of::{MallocSizeOf, MallocSizeOfOps};
|
||||||
use servo_url::MutableOrigin;
|
|
||||||
use std::ffi::CString;
|
use std::ffi::CString;
|
||||||
use std::os::raw::{c_char, c_void};
|
use std::os::raw::{c_char, c_void};
|
||||||
use std::ptr;
|
use std::ptr;
|
||||||
|
@ -70,45 +64,6 @@ impl MallocSizeOf for WindowProxyHandler {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//TODO make principal.rs
|
|
||||||
// TODO: RAII ref-counting
|
|
||||||
pub struct ServoJSPrincipal(pub *mut JSPrincipals);
|
|
||||||
|
|
||||||
impl ServoJSPrincipal {
|
|
||||||
pub fn new(origin: &MutableOrigin) -> Self {
|
|
||||||
let private: Box<MutableOrigin> = Box::new(origin.clone());
|
|
||||||
Self(unsafe { CreateRustJSPrincipals(&PRINCIPALS_CALLBACKS, Box::into_raw(private) as _) })
|
|
||||||
}
|
|
||||||
|
|
||||||
pub unsafe fn origin(&self) -> MutableOrigin {
|
|
||||||
let origin = GetRustJSPrincipalsPrivate(self.0) as *mut MutableOrigin;
|
|
||||||
(*origin).clone()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub unsafe extern "C" fn destroy_servo_jsprincipal(principals: *mut JSPrincipals) {
|
|
||||||
Box::from_raw(GetRustJSPrincipalsPrivate(principals) as *mut MutableOrigin);
|
|
||||||
DestroyRustJSPrincipals(principals);
|
|
||||||
}
|
|
||||||
|
|
||||||
const PRINCIPALS_CALLBACKS: JSPrincipalsCallbacks = JSPrincipalsCallbacks {
|
|
||||||
write: None,
|
|
||||||
isSystemOrAddonPrincipal: Some(principals_is_system_or_addon_principal),
|
|
||||||
};
|
|
||||||
|
|
||||||
unsafe extern "C" fn principals_is_system_or_addon_principal(_: *mut JSPrincipals) -> bool {
|
|
||||||
false
|
|
||||||
}
|
|
||||||
|
|
||||||
//TODO is same_origin_domain equivalent to subsumes for our purposes
|
|
||||||
pub unsafe extern "C" fn subsumes(obj: *mut JSPrincipals, other: *mut JSPrincipals) -> bool {
|
|
||||||
let obj = ServoJSPrincipal(obj);
|
|
||||||
let other = ServoJSPrincipal(other);
|
|
||||||
let obj_origin = obj.origin();
|
|
||||||
let other_origin = other.origin();
|
|
||||||
obj_origin.same_origin_domain(&other_origin)
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(JSTraceable, MallocSizeOf)]
|
#[derive(JSTraceable, MallocSizeOf)]
|
||||||
/// Static data associated with a global object.
|
/// Static data associated with a global object.
|
||||||
pub struct GlobalStaticData {
|
pub struct GlobalStaticData {
|
||||||
|
|
|
@ -16,13 +16,14 @@ use crate::dom::bindings::conversions::private_from_object;
|
||||||
use crate::dom::bindings::conversions::root_from_handleobject;
|
use crate::dom::bindings::conversions::root_from_handleobject;
|
||||||
use crate::dom::bindings::error::{throw_dom_exception, Error};
|
use crate::dom::bindings::error::{throw_dom_exception, Error};
|
||||||
use crate::dom::bindings::inheritance::Castable;
|
use crate::dom::bindings::inheritance::Castable;
|
||||||
|
use crate::dom::bindings::principals;
|
||||||
use crate::dom::bindings::refcounted::{trace_refcounted_objects, LiveDOMReferences};
|
use crate::dom::bindings::refcounted::{trace_refcounted_objects, LiveDOMReferences};
|
||||||
use crate::dom::bindings::refcounted::{Trusted, TrustedPromise};
|
use crate::dom::bindings::refcounted::{Trusted, TrustedPromise};
|
||||||
use crate::dom::bindings::reflector::DomObject;
|
use crate::dom::bindings::reflector::DomObject;
|
||||||
use crate::dom::bindings::root::trace_roots;
|
use crate::dom::bindings::root::trace_roots;
|
||||||
use crate::dom::bindings::settings_stack;
|
use crate::dom::bindings::settings_stack;
|
||||||
use crate::dom::bindings::trace::{trace_traceables, JSTraceable};
|
use crate::dom::bindings::trace::{trace_traceables, JSTraceable};
|
||||||
use crate::dom::bindings::utils::{self, DOM_CALLBACKS};
|
use crate::dom::bindings::utils::DOM_CALLBACKS;
|
||||||
use crate::dom::event::{Event, EventBubbles, EventCancelable, EventStatus};
|
use crate::dom::event::{Event, EventBubbles, EventCancelable, EventStatus};
|
||||||
use crate::dom::eventtarget::EventTarget;
|
use crate::dom::eventtarget::EventTarget;
|
||||||
use crate::dom::globalscope::GlobalScope;
|
use crate::dom::globalscope::GlobalScope;
|
||||||
|
@ -101,7 +102,7 @@ static JOB_QUEUE_TRAPS: JobQueueTraps = JobQueueTraps {
|
||||||
static SECURITY_CALLBACKS: JSSecurityCallbacks = JSSecurityCallbacks {
|
static SECURITY_CALLBACKS: JSSecurityCallbacks = JSSecurityCallbacks {
|
||||||
// TODO: Content Security Policy <https://developer.mozilla.org/en-US/docs/Web/HTTP/CSP>
|
// TODO: Content Security Policy <https://developer.mozilla.org/en-US/docs/Web/HTTP/CSP>
|
||||||
contentSecurityPolicyAllows: None,
|
contentSecurityPolicyAllows: None,
|
||||||
subsumes: Some(utils::subsumes),
|
subsumes: Some(principals::subsumes),
|
||||||
};
|
};
|
||||||
|
|
||||||
/// Common messages used to control the event loops in both the script and the worker
|
/// Common messages used to control the event loops in both the script and the worker
|
||||||
|
@ -475,7 +476,7 @@ unsafe fn new_rt_and_cx_with_parent(
|
||||||
|
|
||||||
JS_SetSecurityCallbacks(cx, &SECURITY_CALLBACKS);
|
JS_SetSecurityCallbacks(cx, &SECURITY_CALLBACKS);
|
||||||
|
|
||||||
JS_InitDestroyPrincipalsCallback(cx, Some(utils::destroy_servo_jsprincipal));
|
JS_InitDestroyPrincipalsCallback(cx, Some(principals::destroy_servo_jsprincipal));
|
||||||
|
|
||||||
// Needed for debug assertions about whether GC is running.
|
// Needed for debug assertions about whether GC is running.
|
||||||
if cfg!(debug_assertions) {
|
if cfg!(debug_assertions) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue