Source code

Revision control

Other Tools

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 "mozilla/dom/WebAuthnTransactionChild.h"
8
9
namespace mozilla {
10
namespace dom {
11
12
WebAuthnTransactionChild::WebAuthnTransactionChild(
13
WebAuthnManagerBase* aManager)
14
: mManager(aManager) {
15
MOZ_ASSERT(aManager);
16
17
// Retain a reference so the task object isn't deleted without IPDL's
18
// knowledge. The reference will be released by
19
// mozilla::ipc::BackgroundChildImpl::DeallocPWebAuthnTransactionChild.
20
NS_ADDREF_THIS();
21
}
22
23
mozilla::ipc::IPCResult WebAuthnTransactionChild::RecvConfirmRegister(
24
const uint64_t& aTransactionId,
25
const WebAuthnMakeCredentialResult& aResult) {
26
if (NS_WARN_IF(!mManager)) {
27
return IPC_FAIL_NO_REASON(this);
28
}
29
30
// We don't own the reference to mManager. We need to prevent its refcount
31
// going to 0 while we call anything that can reach the call to
32
// StopListeningForVisibilityEvents in WebAuthnManager::ClearTransaction
33
// (often via WebAuthnManager::RejectTransaction).
34
RefPtr<WebAuthnManagerBase> kungFuDeathGrip(mManager);
35
kungFuDeathGrip->FinishMakeCredential(aTransactionId, aResult);
36
return IPC_OK();
37
}
38
39
mozilla::ipc::IPCResult WebAuthnTransactionChild::RecvConfirmSign(
40
const uint64_t& aTransactionId, const WebAuthnGetAssertionResult& aResult) {
41
if (NS_WARN_IF(!mManager)) {
42
return IPC_FAIL_NO_REASON(this);
43
}
44
45
// We don't own the reference to mManager. We need to prevent its refcount
46
// going to 0 while we call anything that can reach the call to
47
// StopListeningForVisibilityEvents in WebAuthnManager::ClearTransaction
48
// (often via WebAuthnManager::RejectTransaction).
49
RefPtr<WebAuthnManagerBase> kungFuDeathGrip(mManager);
50
kungFuDeathGrip->FinishGetAssertion(aTransactionId, aResult);
51
return IPC_OK();
52
}
53
54
mozilla::ipc::IPCResult WebAuthnTransactionChild::RecvAbort(
55
const uint64_t& aTransactionId, const nsresult& aError) {
56
if (NS_WARN_IF(!mManager)) {
57
return IPC_FAIL_NO_REASON(this);
58
}
59
60
// We don't own the reference to mManager. We need to prevent its refcount
61
// going to 0 while we call anything that can reach the call to
62
// StopListeningForVisibilityEvents in WebAuthnManager::ClearTransaction
63
// (often via WebAuthnManager::RejectTransaction).
64
RefPtr<WebAuthnManagerBase> kungFuDeathGrip(mManager);
65
kungFuDeathGrip->RequestAborted(aTransactionId, aError);
66
return IPC_OK();
67
}
68
69
void WebAuthnTransactionChild::ActorDestroy(ActorDestroyReason why) {
70
// Called by either a __delete__ message from the parent, or when the
71
// channel disconnects. Clear out the child actor reference to be sure.
72
if (mManager) {
73
mManager->ActorDestroyed();
74
mManager = nullptr;
75
}
76
}
77
78
void WebAuthnTransactionChild::Disconnect() {
79
mManager = nullptr;
80
81
// The WebAuthnManager released us, but we're going to be held alive by the
82
// IPC layer. The parent will explicitly destroy us via Send__delete__(),
83
// after receiving the DestroyMe message.
84
85
SendDestroyMe();
86
}
87
88
} // namespace dom
89
} // namespace mozilla