Line data Source code
1 : /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 : /* vim:set ts=2 sw=2 sts=2 et cindent: */
3 : /* This Source Code Form is subject to the terms of the Mozilla Public
4 : * License, v. 2.0. If a copy of the MPL was not distributed with this
5 : * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 :
7 : #include "mozilla/dom/CredentialsContainer.h"
8 : #include "mozilla/dom/Promise.h"
9 : #include "mozilla/dom/WebAuthnManager.h"
10 :
11 : namespace mozilla {
12 : namespace dom {
13 :
14 0 : NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE(CredentialsContainer, mParent)
15 0 : NS_IMPL_CYCLE_COLLECTING_ADDREF(CredentialsContainer)
16 0 : NS_IMPL_CYCLE_COLLECTING_RELEASE(CredentialsContainer)
17 0 : NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(CredentialsContainer)
18 0 : NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY
19 0 : NS_INTERFACE_MAP_ENTRY(nsISupports)
20 0 : NS_INTERFACE_MAP_END
21 :
22 0 : CredentialsContainer::CredentialsContainer(nsPIDOMWindowInner* aParent) :
23 0 : mParent(aParent)
24 : {
25 0 : MOZ_ASSERT(aParent);
26 0 : }
27 :
28 0 : CredentialsContainer::~CredentialsContainer()
29 0 : {}
30 :
31 : JSObject*
32 0 : CredentialsContainer::WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto)
33 : {
34 0 : return CredentialsContainerBinding::Wrap(aCx, this, aGivenProto);
35 : }
36 :
37 : already_AddRefed<Promise>
38 0 : CredentialsContainer::Get(const CredentialRequestOptions& aOptions)
39 : {
40 0 : RefPtr<WebAuthnManager> mgr = WebAuthnManager::GetOrCreate();
41 0 : MOZ_ASSERT(mgr);
42 0 : return mgr->GetAssertion(mParent, aOptions.mPublicKey);
43 : }
44 :
45 : already_AddRefed<Promise>
46 0 : CredentialsContainer::Create(const CredentialCreationOptions& aOptions)
47 : {
48 0 : RefPtr<WebAuthnManager> mgr = WebAuthnManager::GetOrCreate();
49 0 : MOZ_ASSERT(mgr);
50 0 : return mgr->MakeCredential(mParent, aOptions.mPublicKey);
51 : }
52 :
53 : } // namespace dom
54 : } // namespace mozilla
|