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 std::rc::Rc;
5
6use dom_struct::dom_struct;
7use js::realm::CurrentRealm;
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;
16use crate::dom::window::Window;
17use crate::script_runtime::CanGc;
18
19#[dom_struct]
20pub(crate) struct Credential {
21    reflector_: Reflector,
22    id: USVString,
23    credential_type: DOMString,
24}
25
26impl Credential {
27    pub(crate) fn new_inherited(id: USVString, credential_type: DOMString) -> Credential {
28        Credential {
29            reflector_: Reflector::new(),
30            id,
31            credential_type,
32        }
33    }
34
35    #[expect(dead_code)]
36    pub(crate) fn new(
37        global: &GlobalScope,
38        id: USVString,
39        credential_type: DOMString,
40        can_gc: CanGc,
41    ) -> DomRoot<Credential> {
42        reflect_dom_object(
43            Box::new(Credential::new_inherited(id, credential_type)),
44            global,
45            can_gc,
46        )
47    }
48}
49
50impl CredentialMethods<DomTypeHolder> for Credential {
51    /// <https://www.w3.org/TR/credential-management-1/#dom-credential-id>
52    fn Id(&self) -> USVString {
53        self.id.clone()
54    }
55
56    /// <https://www.w3.org/TR/credential-management-1/#dom-credential-type>
57    fn Type(&self) -> DOMString {
58        self.credential_type.clone()
59    }
60
61    /// <https://www.w3.org/TR/credential-management-1/#dom-credential-isconditionalmediationavailable>
62    fn IsConditionalMediationAvailable(cx: &mut CurrentRealm, _global: &Window) -> Rc<Promise> {
63        Promise::new_in_realm(cx)
64    }
65
66    /// <https://www.w3.org/TR/credential-management-1/#dom-credential-willrequestconditionalcreation>
67    fn WillRequestConditionalCreation(cx: &mut CurrentRealm, _global: &Window) -> Rc<Promise> {
68        Promise::new_in_realm(cx)
69    }
70}