2017-10-27 01:08:41 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
2017-04-20 03:46:08 +03:00
|
|
|
/* 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/WebAuthnTransactionChild.h"
|
|
|
|
|
2022-05-09 23:41:19 +03:00
|
|
|
namespace mozilla::dom {
|
2017-04-20 03:46:08 +03:00
|
|
|
|
2017-12-05 21:05:06 +03:00
|
|
|
WebAuthnTransactionChild::WebAuthnTransactionChild(
|
|
|
|
WebAuthnManagerBase* aManager)
|
|
|
|
: mManager(aManager) {
|
|
|
|
MOZ_ASSERT(aManager);
|
|
|
|
|
|
|
|
// Retain a reference so the task object isn't deleted without IPDL's
|
|
|
|
// knowledge. The reference will be released by
|
|
|
|
// mozilla::ipc::BackgroundChildImpl::DeallocPWebAuthnTransactionChild.
|
|
|
|
NS_ADDREF_THIS();
|
|
|
|
}
|
|
|
|
|
2017-10-25 16:59:53 +03:00
|
|
|
mozilla::ipc::IPCResult WebAuthnTransactionChild::RecvConfirmRegister(
|
|
|
|
const uint64_t& aTransactionId,
|
2018-02-12 23:08:54 +03:00
|
|
|
const WebAuthnMakeCredentialResult& aResult) {
|
2017-12-05 21:05:06 +03:00
|
|
|
if (NS_WARN_IF(!mManager)) {
|
|
|
|
return IPC_FAIL_NO_REASON(this);
|
|
|
|
}
|
|
|
|
|
2018-09-07 19:17:19 +03:00
|
|
|
// We don't own the reference to mManager. We need to prevent its refcount
|
|
|
|
// going to 0 while we call anything that can reach the call to
|
|
|
|
// StopListeningForVisibilityEvents in WebAuthnManager::ClearTransaction
|
|
|
|
// (often via WebAuthnManager::RejectTransaction).
|
|
|
|
RefPtr<WebAuthnManagerBase> kungFuDeathGrip(mManager);
|
|
|
|
kungFuDeathGrip->FinishMakeCredential(aTransactionId, aResult);
|
2017-04-20 03:46:08 +03:00
|
|
|
return IPC_OK();
|
|
|
|
}
|
|
|
|
|
2017-10-25 16:59:53 +03:00
|
|
|
mozilla::ipc::IPCResult WebAuthnTransactionChild::RecvConfirmSign(
|
2018-02-12 23:08:54 +03:00
|
|
|
const uint64_t& aTransactionId, const WebAuthnGetAssertionResult& aResult) {
|
2017-12-05 21:05:06 +03:00
|
|
|
if (NS_WARN_IF(!mManager)) {
|
|
|
|
return IPC_FAIL_NO_REASON(this);
|
|
|
|
}
|
|
|
|
|
2018-09-07 19:17:19 +03:00
|
|
|
// We don't own the reference to mManager. We need to prevent its refcount
|
|
|
|
// going to 0 while we call anything that can reach the call to
|
|
|
|
// StopListeningForVisibilityEvents in WebAuthnManager::ClearTransaction
|
|
|
|
// (often via WebAuthnManager::RejectTransaction).
|
|
|
|
RefPtr<WebAuthnManagerBase> kungFuDeathGrip(mManager);
|
|
|
|
kungFuDeathGrip->FinishGetAssertion(aTransactionId, aResult);
|
2017-04-20 03:46:08 +03:00
|
|
|
return IPC_OK();
|
|
|
|
}
|
|
|
|
|
2017-10-25 16:59:53 +03:00
|
|
|
mozilla::ipc::IPCResult WebAuthnTransactionChild::RecvAbort(
|
|
|
|
const uint64_t& aTransactionId, const nsresult& aError) {
|
2017-12-05 21:05:06 +03:00
|
|
|
if (NS_WARN_IF(!mManager)) {
|
|
|
|
return IPC_FAIL_NO_REASON(this);
|
|
|
|
}
|
|
|
|
|
2018-09-07 19:17:19 +03:00
|
|
|
// We don't own the reference to mManager. We need to prevent its refcount
|
|
|
|
// going to 0 while we call anything that can reach the call to
|
|
|
|
// StopListeningForVisibilityEvents in WebAuthnManager::ClearTransaction
|
|
|
|
// (often via WebAuthnManager::RejectTransaction).
|
|
|
|
RefPtr<WebAuthnManagerBase> kungFuDeathGrip(mManager);
|
|
|
|
kungFuDeathGrip->RequestAborted(aTransactionId, aError);
|
2017-04-20 03:46:08 +03:00
|
|
|
return IPC_OK();
|
|
|
|
}
|
|
|
|
|
|
|
|
void WebAuthnTransactionChild::ActorDestroy(ActorDestroyReason why) {
|
2017-12-05 21:05:06 +03:00
|
|
|
// Called by either a __delete__ message from the parent, or when the
|
|
|
|
// channel disconnects. Clear out the child actor reference to be sure.
|
|
|
|
if (mManager) {
|
|
|
|
mManager->ActorDestroyed();
|
|
|
|
mManager = nullptr;
|
2017-04-20 03:46:08 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-12-05 21:05:06 +03:00
|
|
|
void WebAuthnTransactionChild::Disconnect() {
|
|
|
|
mManager = nullptr;
|
|
|
|
|
|
|
|
// The WebAuthnManager released us, but we're going to be held alive by the
|
|
|
|
// IPC layer. The parent will explicitly destroy us via Send__delete__(),
|
|
|
|
// after receiving the DestroyMe message.
|
|
|
|
|
|
|
|
SendDestroyMe();
|
|
|
|
}
|
|
|
|
|
2022-05-09 23:41:19 +03:00
|
|
|
} // namespace mozilla::dom
|