Skip to main content

script/dom/credentialmanagement/
credential.rs

1/* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at https://mozilla.org/MPL/2.0/. */
4use dom_struct::dom_struct;
5use js::context::JSContext;
6use js::realm::CurrentRealm;
7use script_bindings::domstring::TracedDOMString;
8use script_bindings::reflector::{Reflector, reflect_dom_object};
9use script_bindings::str::{DOMString, USVString};
10
11use crate::dom::bindings::codegen::Bindings::CredentialBinding::CredentialMethods;
12use crate::dom::bindings::codegen::DomTypeHolder::DomTypeHolder;
13use crate::dom::bindings::root::DomRoot;
14use crate::dom::globalscope::GlobalScope;
15use crate::dom::promise::{Promise, RootedPromise};
16use crate::dom::window::Window;
17
18#[dom_struct]
19pub(crate) struct Credential {
20    reflector_: Reflector,
21    id: USVString,
22    credential_type: TracedDOMString,
23}
24
25impl Credential {
26    pub(crate) fn new_inherited(id: USVString, credential_type: DOMString) -> Credential {
27        Credential {
28            reflector_: Reflector::new(),
29            id,
30            credential_type: credential_type.traced(),
31        }
32    }
33
34    #[expect(dead_code)]
35    pub(crate) fn new(
36        cx: &mut JSContext,
37        global: &GlobalScope,
38        id: USVString,
39        credential_type: DOMString,
40    ) -> DomRoot<Credential> {
41        reflect_dom_object(
42            cx,
43            Box::new(Credential::new_inherited(id, credential_type)),
44            global,
45        )
46    }
47}
48
49impl CredentialMethods<DomTypeHolder> for Credential {
50    /// <https://www.w3.org/TR/credential-management-1/#dom-credential-id>
51    fn Id(&self) -> USVString {
52        self.id.clone()
53    }
54
55    /// <https://www.w3.org/TR/credential-management-1/#dom-credential-type>
56    fn Type(&self) -> DOMString {
57        self.credential_type.clone().root()
58    }
59
60    /// <https://www.w3.org/TR/credential-management-1/#dom-credential-isconditionalmediationavailable>
61    fn IsConditionalMediationAvailable(cx: &mut CurrentRealm, _global: &Window) -> RootedPromise {
62        Promise::new_in_realm(cx)
63    }
64
65    /// <https://www.w3.org/TR/credential-management-1/#dom-credential-willrequestconditionalcreation>
66    fn WillRequestConditionalCreation(cx: &mut CurrentRealm, _global: &Window) -> RootedPromise {
67        Promise::new_in_realm(cx)
68    }
69}