mirror of
https://github.com/servo/servo.git
synced 2025-08-03 04:30:10 +01:00
Add creation url and Secure Contexts
This commit is contained in:
parent
20ef49e035
commit
0e1479cc84
25 changed files with 207 additions and 9 deletions
|
@ -6,6 +6,9 @@
|
|||
|
||||
use crate::dom::bindings::codegen::InterfaceObjectMap;
|
||||
use crate::dom::bindings::interface::is_exposed_in;
|
||||
use crate::dom::globalscope::GlobalScope;
|
||||
use crate::realms::AlreadyInRealm;
|
||||
use crate::realms::InRealm;
|
||||
use crate::script_runtime::JSContext;
|
||||
use js::rust::HandleObject;
|
||||
use servo_config::prefs;
|
||||
|
@ -45,16 +48,25 @@ pub enum Condition {
|
|||
Pref(&'static str),
|
||||
// The condition is satisfied if the interface is exposed in the global.
|
||||
Exposed(InterfaceObjectMap::Globals),
|
||||
SecureContext(),
|
||||
/// The condition is always satisfied.
|
||||
Satisfied,
|
||||
}
|
||||
|
||||
fn is_secure_context(cx: JSContext) -> bool {
|
||||
unsafe {
|
||||
let in_realm_proof = AlreadyInRealm::assert_for_cx(JSContext::from_ptr(*cx));
|
||||
GlobalScope::from_context(*cx, InRealm::Already(&in_realm_proof)).is_secure_context()
|
||||
}
|
||||
}
|
||||
|
||||
impl Condition {
|
||||
pub fn is_satisfied(&self, cx: JSContext, obj: HandleObject, global: HandleObject) -> bool {
|
||||
match *self {
|
||||
Condition::Pref(name) => prefs::pref_map().get(name).as_bool().unwrap_or(false),
|
||||
Condition::Func(f) => f(cx, obj),
|
||||
Condition::Exposed(globals) => is_exposed_in(global, globals),
|
||||
Condition::SecureContext() => is_secure_context(cx),
|
||||
Condition::Satisfied => true,
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue