Bug 1880216 - Migrate Fenix docs into Sphinx. r=owlish,geckoview-reviewers,android...
[gecko.git] / dom / webauthn / WebAuthnManagerBase.cpp
blob392be930768b76f4bf51ab4f6a8d8790c515d5e5
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
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 file,
5 * You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #include "mozilla/dom/WebAuthnManagerBase.h"
8 #include "mozilla/dom/WebAuthnTransactionChild.h"
9 #include "mozilla/ipc/BackgroundChild.h"
10 #include "mozilla/ipc/PBackgroundChild.h"
12 namespace mozilla::dom {
14 WebAuthnManagerBase::WebAuthnManagerBase(nsPIDOMWindowInner* aParent)
15 : mParent(aParent) {
16 MOZ_ASSERT(NS_IsMainThread());
17 MOZ_ASSERT(aParent);
20 WebAuthnManagerBase::~WebAuthnManagerBase() { MOZ_ASSERT(NS_IsMainThread()); }
22 NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(WebAuthnManagerBase)
23 NS_INTERFACE_MAP_ENTRY(nsISupports)
24 NS_INTERFACE_MAP_END
26 NS_IMPL_CYCLE_COLLECTION(WebAuthnManagerBase, mParent)
28 NS_IMPL_CYCLE_COLLECTING_ADDREF(WebAuthnManagerBase)
29 NS_IMPL_CYCLE_COLLECTING_RELEASE(WebAuthnManagerBase)
31 /***********************************************************************
32 * IPC Protocol Implementation
33 **********************************************************************/
35 bool WebAuthnManagerBase::MaybeCreateBackgroundActor() {
36 MOZ_ASSERT(NS_IsMainThread());
38 if (mChild) {
39 return true;
42 ::mozilla::ipc::PBackgroundChild* actorChild =
43 ::mozilla::ipc::BackgroundChild::GetOrCreateForCurrentThread();
44 if (NS_WARN_IF(!actorChild)) {
45 return false;
48 RefPtr<WebAuthnTransactionChild> mgr(new WebAuthnTransactionChild(this));
49 PWebAuthnTransactionChild* constructedMgr =
50 actorChild->SendPWebAuthnTransactionConstructor(mgr);
52 if (NS_WARN_IF(!constructedMgr)) {
53 return false;
56 MOZ_ASSERT(constructedMgr == mgr);
57 mChild = std::move(mgr);
59 return true;
62 void WebAuthnManagerBase::ActorDestroyed() {
63 MOZ_ASSERT(NS_IsMainThread());
64 mChild = nullptr;
67 } // namespace mozilla::dom