script/dom/
trustedtypepolicy.rs
use dom_struct::dom_struct;
use js::rust::HandleValue;
use crate::dom::bindings::codegen::Bindings::TrustedTypePolicyBinding::TrustedTypePolicyMethods;
use crate::dom::bindings::reflector::{DomGlobal, Reflector, reflect_dom_object};
use crate::dom::bindings::root::DomRoot;
use crate::dom::bindings::str::DOMString;
use crate::dom::globalscope::GlobalScope;
use crate::dom::trustedhtml::TrustedHTML;
use crate::dom::trustedscript::TrustedScript;
use crate::dom::trustedscripturl::TrustedScriptURL;
use crate::script_runtime::{CanGc, JSContext};
#[dom_struct]
pub struct TrustedTypePolicy {
reflector_: Reflector,
name: String,
}
impl TrustedTypePolicy {
fn new_inherited(name: String) -> Self {
Self {
reflector_: Reflector::new(),
name,
}
}
#[cfg_attr(crown, allow(crown::unrooted_must_root))]
pub(crate) fn new(name: String, global: &GlobalScope, can_gc: CanGc) -> DomRoot<Self> {
reflect_dom_object(Box::new(Self::new_inherited(name)), global, can_gc)
}
}
impl TrustedTypePolicyMethods<crate::DomTypeHolder> for TrustedTypePolicy {
fn Name(&self) -> DOMString {
DOMString::from(&*self.name)
}
fn CreateHTML(
&self,
_: JSContext,
data: DOMString,
_: Vec<HandleValue>,
can_gc: CanGc,
) -> DomRoot<TrustedHTML> {
TrustedHTML::new(data.to_string(), &self.global(), can_gc)
}
fn CreateScript(
&self,
_: JSContext,
data: DOMString,
_: Vec<HandleValue>,
can_gc: CanGc,
) -> DomRoot<TrustedScript> {
TrustedScript::new(data.to_string(), &self.global(), can_gc)
}
fn CreateScriptURL(
&self,
_: JSContext,
data: DOMString,
_: Vec<HandleValue>,
can_gc: CanGc,
) -> DomRoot<TrustedScriptURL> {
TrustedScriptURL::new(data.to_string(), &self.global(), can_gc)
}
}