script/dom/credentialmanagement/
credential.rs1use dom_struct::dom_struct;
5use js::context::JSContext;
6use js::realm::CurrentRealm;
7use script_bindings::reflector::{Reflector, reflect_dom_object};
8use script_bindings::str::{DOMString, USVString};
9
10use crate::dom::bindings::codegen::Bindings::CredentialBinding::CredentialMethods;
11use crate::dom::bindings::codegen::DomTypeHolder::DomTypeHolder;
12use crate::dom::bindings::root::DomRoot;
13use crate::dom::globalscope::GlobalScope;
14use crate::dom::promise::{Promise, RootedPromise};
15use crate::dom::window::Window;
16
17#[dom_struct]
18pub(crate) struct Credential {
19 reflector_: Reflector,
20 id: USVString,
21 credential_type: DOMString,
22}
23
24impl Credential {
25 pub(crate) fn new_inherited(id: USVString, credential_type: DOMString) -> Credential {
26 Credential {
27 reflector_: Reflector::new(),
28 id,
29 credential_type,
30 }
31 }
32
33 #[expect(dead_code)]
34 pub(crate) fn new(
35 cx: &mut JSContext,
36 global: &GlobalScope,
37 id: USVString,
38 credential_type: DOMString,
39 ) -> DomRoot<Credential> {
40 reflect_dom_object(
41 cx,
42 Box::new(Credential::new_inherited(id, credential_type)),
43 global,
44 )
45 }
46}
47
48impl CredentialMethods<DomTypeHolder> for Credential {
49 fn Id(&self) -> USVString {
51 self.id.clone()
52 }
53
54 fn Type(&self) -> DOMString {
56 self.credential_type.clone()
57 }
58
59 fn IsConditionalMediationAvailable(cx: &mut CurrentRealm, _global: &Window) -> RootedPromise {
61 Promise::new_in_realm_rooted(cx)
62 }
63
64 fn WillRequestConditionalCreation(cx: &mut CurrentRealm, _global: &Window) -> RootedPromise {
66 Promise::new_in_realm_rooted(cx)
67 }
68}