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
5  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 
7 #ifndef mozilla_dom_WebAuthnManagerBase_h
8 #define mozilla_dom_WebAuthnManagerBase_h
9 
10 #include "nsIDOMEventListener.h"
11 #include "nsCycleCollectionParticipant.h"
12 #include "nsCOMPtr.h"
13 
14 /*
15  * A base class used by WebAuthn and U2F implementations, providing shared
16  * functionality and requiring an interface used by the IPC child actors.
17  */
18 
19 class nsPIDOMWindowInner;
20 
21 namespace mozilla {
22 namespace dom {
23 
24 class WebAuthnTransactionChild;
25 class WebAuthnMakeCredentialResult;
26 class WebAuthnGetAssertionResult;
27 
28 class WebAuthnManagerBase : public nsIDOMEventListener {
29  public:
30   NS_DECL_NSIDOMEVENTLISTENER
31 
32   NS_DECL_CYCLE_COLLECTING_ISUPPORTS
33   NS_DECL_CYCLE_COLLECTION_CLASS(WebAuthnManagerBase)
34 
35   explicit WebAuthnManagerBase(nsPIDOMWindowInner* aParent);
36 
37   MOZ_CAN_RUN_SCRIPT
38   virtual void FinishMakeCredential(
39       const uint64_t& aTransactionId,
40       const WebAuthnMakeCredentialResult& aResult) = 0;
41 
42   MOZ_CAN_RUN_SCRIPT
43   virtual void FinishGetAssertion(
44       const uint64_t& aTransactionId,
45       const WebAuthnGetAssertionResult& aResult) = 0;
46 
47   MOZ_CAN_RUN_SCRIPT
48   virtual void RequestAborted(const uint64_t& aTransactionId,
49                               const nsresult& aError) = 0;
50 
51   void ActorDestroyed();
52 
53  protected:
54   MOZ_CAN_RUN_SCRIPT virtual ~WebAuthnManagerBase();
55 
56   // Needed by HandleEvent() to track visibilty changes.
57   MOZ_CAN_RUN_SCRIPT virtual void HandleVisibilityChange() = 0;
58 
59   // Visibility event handling.
60   void ListenForVisibilityEvents();
61   void StopListeningForVisibilityEvents();
62 
63   bool MaybeCreateBackgroundActor();
64 
65   // The parent window.
66   nsCOMPtr<nsPIDOMWindowInner> mParent;
67 
68   // IPC Channel to the parent process.
69   RefPtr<WebAuthnTransactionChild> mChild;
70 };
71 
72 }  // namespace dom
73 }  // namespace mozilla
74 
75 #endif  // mozilla_dom_WebAuthnManagerBase_h
76