Bug 1245527 - Use PWebAuthnTransactionParent superclass for U2FTokenManager r?keeler draft
authorJ.C. Jones <jjones@mozilla.com>
Fri, 25 Aug 2017 18:37:17 -0700
changeset 663072 9455755e101b0a6cffe0c22f0eec184f8e653ea1
parent 663071 b805cc36637b7fbd97daf258bbfb4961bacb4e69
child 663073 8c0fa3b4675d355a651531290e72e7e3444d2fcf
push id79302
push userbmo:jjones@mozilla.com
push dateTue, 12 Sep 2017 14:54:04 +0000
reviewerskeeler
bugs1245527
milestone57.0a1
Bug 1245527 - Use PWebAuthnTransactionParent superclass for U2FTokenManager r?keeler This is a change to permit interacting with the U2FTokenManager from the dom/U2F context in addition to the dom/WebAuthn one. MozReview-Commit-ID: BvP5BY2wVYi
dom/webauthn/U2FTokenManager.cpp
dom/webauthn/U2FTokenManager.h
--- a/dom/webauthn/U2FTokenManager.cpp
+++ b/dom/webauthn/U2FTokenManager.cpp
@@ -3,17 +3,17 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this file,
  * You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "mozilla/dom/U2FTokenManager.h"
 #include "mozilla/dom/U2FTokenTransport.h"
 #include "mozilla/dom/U2FHIDTokenManager.h"
 #include "mozilla/dom/U2FSoftTokenManager.h"
-#include "mozilla/dom/WebAuthnTransactionParent.h"
+#include "mozilla/dom/PWebAuthnTransactionParent.h"
 #include "mozilla/MozPromise.h"
 #include "mozilla/dom/WebAuthnUtil.h"
 #include "mozilla/ClearOnShutdown.h"
 #include "mozilla/Unused.h"
 #include "hasht.h"
 #include "nsICryptoHash.h"
 #include "pkix/Input.h"
 #include "pkixutil.h"
@@ -160,17 +160,17 @@ U2FTokenManager::Get()
 void
 U2FTokenManager::AbortTransaction(const nsresult& aError)
 {
   Unused << mTransactionParent->SendCancel(aError);
   ClearTransaction();
 }
 
 void
-U2FTokenManager::MaybeClearTransaction(WebAuthnTransactionParent* aParent)
+U2FTokenManager::MaybeClearTransaction(PWebAuthnTransactionParent* aParent)
 {
   // Only clear if we've been requested to do so by our current transaction
   // parent.
   if (mTransactionParent == aParent) {
     ClearTransaction();
   }
 }
 
@@ -213,17 +213,17 @@ U2FTokenManager::GetTokenManagerImpl()
   }
 
   // TODO Use WebAuthnRequest to aggregate results from all transports,
   //      once we have multiple HW transport types.
   return new U2FHIDTokenManager();
 }
 
 void
-U2FTokenManager::Register(WebAuthnTransactionParent* aTransactionParent,
+U2FTokenManager::Register(PWebAuthnTransactionParent* aTransactionParent,
                           const WebAuthnTransactionInfo& aTransactionInfo)
 {
   MOZ_LOG(gU2FTokenManagerLog, LogLevel::Debug, ("U2FAuthRegister"));
 
   ClearTransaction();
   mTransactionParent = aTransactionParent;
   mTokenManagerImpl = GetTokenManagerImpl();
 
@@ -295,17 +295,17 @@ U2FTokenManager::MaybeAbortRegister(uint
     return;
   }
 
   mRegisterPromise.Complete();
   AbortTransaction(aError);
 }
 
 void
-U2FTokenManager::Sign(WebAuthnTransactionParent* aTransactionParent,
+U2FTokenManager::Sign(PWebAuthnTransactionParent* aTransactionParent,
                       const WebAuthnTransactionInfo& aTransactionInfo)
 {
   MOZ_LOG(gU2FTokenManagerLog, LogLevel::Debug, ("U2FAuthSign"));
 
   ClearTransaction();
   mTransactionParent = aTransactionParent;
   mTokenManagerImpl = GetTokenManagerImpl();
 
@@ -374,17 +374,17 @@ U2FTokenManager::MaybeAbortSign(uint64_t
     return;
   }
 
   mSignPromise.Complete();
   AbortTransaction(aError);
 }
 
 void
-U2FTokenManager::Cancel(WebAuthnTransactionParent* aParent)
+U2FTokenManager::Cancel(PWebAuthnTransactionParent* aParent)
 {
   if (mTransactionParent != aParent) {
     return;
   }
 
   mTokenManagerImpl->Cancel();
   ClearTransaction();
 }
--- a/dom/webauthn/U2FTokenManager.h
+++ b/dom/webauthn/U2FTokenManager.h
@@ -31,38 +31,38 @@ public:
   enum TransactionType
   {
     RegisterTransaction = 0,
     SignTransaction,
     NumTransactionTypes
   };
   NS_INLINE_DECL_REFCOUNTING(U2FTokenManager)
   static U2FTokenManager* Get();
-  void Register(WebAuthnTransactionParent* aTransactionParent,
+  void Register(PWebAuthnTransactionParent* aTransactionParent,
                 const WebAuthnTransactionInfo& aTransactionInfo);
-  void Sign(WebAuthnTransactionParent* aTransactionParent,
+  void Sign(PWebAuthnTransactionParent* aTransactionParent,
             const WebAuthnTransactionInfo& aTransactionInfo);
-  void Cancel(WebAuthnTransactionParent* aTransactionParent);
-  void MaybeClearTransaction(WebAuthnTransactionParent* aParent);
+  void Cancel(PWebAuthnTransactionParent* aTransactionParent);
+  void MaybeClearTransaction(PWebAuthnTransactionParent* aParent);
   static void Initialize();
 private:
   U2FTokenManager();
   ~U2FTokenManager();
   RefPtr<U2FTokenTransport> GetTokenManagerImpl();
   void AbortTransaction(const nsresult& aError);
   void ClearTransaction();
   void MaybeConfirmRegister(uint64_t aTransactionId,
                             U2FRegisterResult& aResult);
   void MaybeAbortRegister(uint64_t aTransactionId, const nsresult& aError);
   void MaybeConfirmSign(uint64_t aTransactionId, U2FSignResult& aResult);
   void MaybeAbortSign(uint64_t aTransactionId, const nsresult& aError);
   // Using a raw pointer here, as the lifetime of the IPC object is managed by
   // the PBackground protocol code. This means we cannot be left holding an
   // invalid IPC protocol object after the transaction is finished.
-  WebAuthnTransactionParent* mTransactionParent;
+  PWebAuthnTransactionParent* mTransactionParent;
   RefPtr<U2FTokenTransport> mTokenManagerImpl;
   MozPromiseRequestHolder<U2FRegisterPromise> mRegisterPromise;
   MozPromiseRequestHolder<U2FSignPromise> mSignPromise;
   // Guards the asynchronous promise resolution of token manager impls.
   // We don't need to protect this with a lock as it will only be modified
   // and checked on the PBackground thread in the parent process.
   uint64_t mTransactionId;
 };