Skip to content

Commit 587ed9d

Browse files
author
Tim Taubert
committed
Backed out changeset bb739695f566 (bug 1421616)
1 parent 807339d commit 587ed9d

21 files changed

+397
-247
lines changed

dom/credentialmanagement/CredentialsContainer.cpp

Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,12 @@
66

77
#include "mozilla/dom/CredentialsContainer.h"
88
#include "mozilla/dom/Promise.h"
9+
#include "mozilla/dom/WebAuthnManager.h"
910

1011
namespace mozilla {
1112
namespace dom {
1213

13-
NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE(CredentialsContainer, mParent, mManager)
14+
NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE(CredentialsContainer, mParent)
1415
NS_IMPL_CYCLE_COLLECTING_ADDREF(CredentialsContainer)
1516
NS_IMPL_CYCLE_COLLECTING_RELEASE(CredentialsContainer)
1617
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(CredentialsContainer)
@@ -27,16 +28,6 @@ CredentialsContainer::CredentialsContainer(nsPIDOMWindowInner* aParent) :
2728
CredentialsContainer::~CredentialsContainer()
2829
{}
2930

30-
void
31-
CredentialsContainer::EnsureWebAuthnManager()
32-
{
33-
MOZ_ASSERT(NS_IsMainThread());
34-
35-
if (!mManager) {
36-
mManager = new WebAuthnManager(mParent);
37-
}
38-
}
39-
4031
JSObject*
4132
CredentialsContainer::WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto)
4233
{
@@ -46,22 +37,22 @@ CredentialsContainer::WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenPro
4637
already_AddRefed<Promise>
4738
CredentialsContainer::Get(const CredentialRequestOptions& aOptions)
4839
{
49-
EnsureWebAuthnManager();
50-
return mManager->GetAssertion(aOptions.mPublicKey, aOptions.mSignal);
40+
RefPtr<WebAuthnManager> mgr = WebAuthnManager::GetOrCreate();
41+
return mgr->GetAssertion(mParent, aOptions.mPublicKey, aOptions.mSignal);
5142
}
5243

5344
already_AddRefed<Promise>
5445
CredentialsContainer::Create(const CredentialCreationOptions& aOptions)
5546
{
56-
EnsureWebAuthnManager();
57-
return mManager->MakeCredential(aOptions.mPublicKey, aOptions.mSignal);
47+
RefPtr<WebAuthnManager> mgr = WebAuthnManager::GetOrCreate();
48+
return mgr->MakeCredential(mParent, aOptions.mPublicKey, aOptions.mSignal);
5849
}
5950

6051
already_AddRefed<Promise>
6152
CredentialsContainer::Store(const Credential& aCredential)
6253
{
63-
EnsureWebAuthnManager();
64-
return mManager->Store(aCredential);
54+
RefPtr<WebAuthnManager> mgr = WebAuthnManager::GetOrCreate();
55+
return mgr->Store(mParent, aCredential);
6556
}
6657

6758
} // namespace dom

dom/credentialmanagement/CredentialsContainer.h

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
#define mozilla_dom_CredentialsContainer_h
99

1010
#include "mozilla/dom/CredentialManagementBinding.h"
11-
#include "mozilla/dom/WebAuthnManager.h"
1211

1312
namespace mozilla {
1413
namespace dom {
@@ -33,20 +32,15 @@ class CredentialsContainer final : public nsISupports
3332

3433
already_AddRefed<Promise>
3534
Get(const CredentialRequestOptions& aOptions);
36-
3735
already_AddRefed<Promise>
3836
Create(const CredentialCreationOptions& aOptions);
39-
4037
already_AddRefed<Promise>
4138
Store(const Credential& aCredential);
4239

4340
private:
4441
~CredentialsContainer();
4542

46-
void EnsureWebAuthnManager();
47-
4843
nsCOMPtr<nsPIDOMWindowInner> mParent;
49-
RefPtr<WebAuthnManager> mManager;
5044
};
5145

5246
} // namespace dom

dom/u2f/U2F.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,13 @@
99
#include "mozilla/dom/WebCryptoCommon.h"
1010
#include "mozilla/ipc/PBackgroundChild.h"
1111
#include "mozilla/ipc/BackgroundChild.h"
12-
#include "mozilla/dom/WebAuthnTransactionChild.h"
1312
#include "nsContentUtils.h"
1413
#include "nsICryptoHash.h"
1514
#include "nsIEffectiveTLDService.h"
1615
#include "nsNetCID.h"
1716
#include "nsNetUtil.h"
1817
#include "nsURLParsers.h"
18+
#include "U2FTransactionChild.h"
1919
#include "U2FUtil.h"
2020
#include "hasht.h"
2121

@@ -293,9 +293,9 @@ U2F::~U2F()
293293
}
294294

295295
if (mChild) {
296-
RefPtr<WebAuthnTransactionChild> c;
296+
RefPtr<U2FTransactionChild> c;
297297
mChild.swap(c);
298-
c->Disconnect();
298+
c->Send__delete__(c);
299299
}
300300

301301
mRegisterCallback.reset();
@@ -437,8 +437,8 @@ U2F::Register(const nsAString& aAppId,
437437
}
438438

439439
void
440-
U2F::FinishMakeCredential(const uint64_t& aTransactionId,
441-
nsTArray<uint8_t>& aRegBuffer)
440+
U2F::FinishRegister(const uint64_t& aTransactionId,
441+
nsTArray<uint8_t>& aRegBuffer)
442442
{
443443
MOZ_ASSERT(NS_IsMainThread());
444444

@@ -566,9 +566,9 @@ U2F::Sign(const nsAString& aAppId,
566566
}
567567

568568
void
569-
U2F::FinishGetAssertion(const uint64_t& aTransactionId,
570-
nsTArray<uint8_t>& aCredentialId,
571-
nsTArray<uint8_t>& aSigBuffer)
569+
U2F::FinishSign(const uint64_t& aTransactionId,
570+
nsTArray<uint8_t>& aCredentialId,
571+
nsTArray<uint8_t>& aSigBuffer)
572572
{
573573
MOZ_ASSERT(NS_IsMainThread());
574574

@@ -749,7 +749,7 @@ U2F::MaybeCreateBackgroundActor()
749749
return false;
750750
}
751751

752-
RefPtr<WebAuthnTransactionChild> mgr(new WebAuthnTransactionChild(this));
752+
RefPtr<U2FTransactionChild> mgr(new U2FTransactionChild(this));
753753
PWebAuthnTransactionChild* constructedMgr =
754754
actorChild->SendPWebAuthnTransactionConstructor(mgr);
755755

dom/u2f/U2F.h

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
#include "mozilla/dom/BindingDeclarations.h"
1313
#include "mozilla/dom/Nullable.h"
1414
#include "mozilla/dom/U2FBinding.h"
15-
#include "mozilla/dom/WebAuthnManagerBase.h"
1615
#include "mozilla/ErrorResult.h"
1716
#include "mozilla/MozPromise.h"
1817
#include "nsProxyRelease.h"
@@ -25,7 +24,7 @@ class nsISerialEventTarget;
2524
namespace mozilla {
2625
namespace dom {
2726

28-
class WebAuthnTransactionChild;
27+
class U2FTransactionChild;
2928
class U2FRegisterCallback;
3029
class U2FSignCallback;
3130

@@ -60,7 +59,6 @@ class U2FTransaction
6059
};
6160

6261
class U2F final : public nsIDOMEventListener
63-
, public WebAuthnManagerBase
6462
, public nsWrapperCache
6563
{
6664
public:
@@ -99,22 +97,18 @@ class U2F final : public nsIDOMEventListener
9997
const Optional<Nullable<int32_t>>& opt_aTimeoutSeconds,
10098
ErrorResult& aRv);
10199

102-
// WebAuthnManagerBase
103-
104100
void
105-
FinishMakeCredential(const uint64_t& aTransactionId,
106-
nsTArray<uint8_t>& aRegBuffer) override;
101+
FinishRegister(const uint64_t& aTransactionId, nsTArray<uint8_t>& aRegBuffer);
107102

108103
void
109-
FinishGetAssertion(const uint64_t& aTransactionId,
110-
nsTArray<uint8_t>& aCredentialId,
111-
nsTArray<uint8_t>& aSigBuffer) override;
104+
FinishSign(const uint64_t& aTransactionId,
105+
nsTArray<uint8_t>& aCredentialId,
106+
nsTArray<uint8_t>& aSigBuffer);
112107

113108
void
114-
RequestAborted(const uint64_t& aTransactionId,
115-
const nsresult& aError) override;
109+
RequestAborted(const uint64_t& aTransactionId, const nsresult& aError);
116110

117-
void ActorDestroyed() override;
111+
void ActorDestroyed();
118112

119113
private:
120114
~U2F();
@@ -141,7 +135,7 @@ class U2F final : public nsIDOMEventListener
141135
Maybe<nsMainThreadPtrHandle<U2FSignCallback>> mSignCallback;
142136

143137
// IPC Channel to the parent process.
144-
RefPtr<WebAuthnTransactionChild> mChild;
138+
RefPtr<U2FTransactionChild> mChild;
145139

146140
// The current transaction, if any.
147141
Maybe<U2FTransaction> mTransaction;

dom/u2f/U2FTransactionChild.cpp

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
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+
#include "U2FTransactionChild.h"
8+
9+
namespace mozilla {
10+
namespace dom {
11+
12+
mozilla::ipc::IPCResult
13+
U2FTransactionChild::RecvConfirmRegister(const uint64_t& aTransactionId,
14+
nsTArray<uint8_t>&& aRegBuffer)
15+
{
16+
mU2F->FinishRegister(aTransactionId, aRegBuffer);
17+
return IPC_OK();
18+
}
19+
20+
mozilla::ipc::IPCResult
21+
U2FTransactionChild::RecvConfirmSign(const uint64_t& aTransactionId,
22+
nsTArray<uint8_t>&& aCredentialId,
23+
nsTArray<uint8_t>&& aBuffer)
24+
{
25+
mU2F->FinishSign(aTransactionId, aCredentialId, aBuffer);
26+
return IPC_OK();
27+
}
28+
29+
mozilla::ipc::IPCResult
30+
U2FTransactionChild::RecvAbort(const uint64_t& aTransactionId,
31+
const nsresult& aError)
32+
{
33+
mU2F->RequestAborted(aTransactionId, aError);
34+
return IPC_OK();
35+
}
36+
37+
void
38+
U2FTransactionChild::ActorDestroy(ActorDestroyReason why)
39+
{
40+
mU2F->ActorDestroyed();
41+
}
42+
43+
} // namespace dom
44+
} // namespace mozilla

dom/u2f/U2FTransactionChild.h

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
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_U2FTransactionChild_h
8+
#define mozilla_dom_U2FTransactionChild_h
9+
10+
#include "mozilla/dom/WebAuthnTransactionChildBase.h"
11+
12+
/*
13+
* Child process IPC implementation for U2F API. Receives results of U2F
14+
* transactions from the parent process, and sends them to the U2FManager
15+
* to either cancel the transaction, or be formatted and relayed to content.
16+
*/
17+
18+
namespace mozilla {
19+
namespace dom {
20+
21+
class U2FTransactionChild final : public WebAuthnTransactionChildBase
22+
{
23+
public:
24+
explicit U2FTransactionChild(U2F* aU2F) : mU2F(aU2F) {
25+
MOZ_ASSERT(mU2F);
26+
}
27+
28+
mozilla::ipc::IPCResult
29+
RecvConfirmRegister(const uint64_t& aTransactionId,
30+
nsTArray<uint8_t>&& aRegBuffer) override;
31+
32+
mozilla::ipc::IPCResult
33+
RecvConfirmSign(const uint64_t& aTransactionId,
34+
nsTArray<uint8_t>&& aCredentialId,
35+
nsTArray<uint8_t>&& aBuffer) override;
36+
37+
mozilla::ipc::IPCResult
38+
RecvAbort(const uint64_t& aTransactionId, const nsresult& aError) override;
39+
40+
void ActorDestroy(ActorDestroyReason why) override;
41+
42+
private:
43+
// ~U2F() will destroy child actors.
44+
U2F* mU2F;
45+
};
46+
47+
}
48+
}
49+
50+
#endif //mozilla_dom_U2FTransactionChild_h

dom/u2f/U2FTransactionParent.cpp

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
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+
#include "U2FTransactionParent.h"
8+
#include "mozilla/dom/U2FTokenManager.h"
9+
#include "mozilla/ipc/BackgroundParent.h"
10+
11+
namespace mozilla {
12+
namespace dom {
13+
14+
mozilla::ipc::IPCResult
15+
U2FTransactionParent::RecvRequestRegister(const uint64_t& aTransactionId,
16+
const WebAuthnMakeCredentialInfo& aTransactionInfo)
17+
{
18+
AssertIsOnBackgroundThread();
19+
U2FTokenManager* mgr = U2FTokenManager::Get();
20+
mgr->Register(this, aTransactionId, aTransactionInfo);
21+
return IPC_OK();
22+
}
23+
24+
mozilla::ipc::IPCResult
25+
U2FTransactionParent::RecvRequestSign(const uint64_t& aTransactionId,
26+
const WebAuthnGetAssertionInfo& aTransactionInfo)
27+
{
28+
AssertIsOnBackgroundThread();
29+
U2FTokenManager* mgr = U2FTokenManager::Get();
30+
mgr->Sign(this, aTransactionId, aTransactionInfo);
31+
return IPC_OK();
32+
}
33+
34+
mozilla::ipc::IPCResult
35+
U2FTransactionParent::RecvRequestCancel(const uint64_t& aTransactionId)
36+
{
37+
AssertIsOnBackgroundThread();
38+
U2FTokenManager* mgr = U2FTokenManager::Get();
39+
mgr->Cancel(this, aTransactionId);
40+
return IPC_OK();
41+
}
42+
43+
void
44+
U2FTransactionParent::ActorDestroy(ActorDestroyReason aWhy)
45+
{
46+
AssertIsOnBackgroundThread();
47+
U2FTokenManager* mgr = U2FTokenManager::Get();
48+
mgr->MaybeClearTransaction(this);
49+
}
50+
51+
} // namespace dom
52+
} // namespace mozilla

0 commit comments

Comments
 (0)