/* This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at https://mozilla.org/MPL/2.0/. */ 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 { reflect_dom_object(Box::new(Self::new_inherited(name)), global, can_gc) } } impl TrustedTypePolicyMethods for TrustedTypePolicy { /// fn Name(&self) -> DOMString { DOMString::from(&*self.name) } /// fn CreateHTML( &self, _: JSContext, data: DOMString, _: Vec, can_gc: CanGc, ) -> DomRoot { // TODO(36258): handle arguments TrustedHTML::new(data.to_string(), &self.global(), can_gc) } /// fn CreateScript( &self, _: JSContext, data: DOMString, _: Vec, can_gc: CanGc, ) -> DomRoot { // TODO(36258): handle arguments TrustedScript::new(data.to_string(), &self.global(), can_gc) } /// fn CreateScriptURL( &self, _: JSContext, data: DOMString, _: Vec, can_gc: CanGc, ) -> DomRoot { // TODO(36258): handle arguments TrustedScriptURL::new(data.to_string(), &self.global(), can_gc) } }