blob: c5e65ef5d6208c5a2cc170a34b20ab8fffd38e7a [file] [log] [blame]
Avi Drissman4e1b7bc32022-09-15 14:03:501// Copyright 2017 The Chromium Authors
kpaulhamus7c9f00942017-06-30 11:08:452// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#include "content/browser/webauth/authenticator_impl.h"
6
Martin Kreichgauer7d2b8dbb2021-04-01 16:03:457#include <memory>
Kim Paulhamusfbe092bf2017-11-21 16:46:088#include <utility>
kpaulhamus7c9f00942017-06-30 11:08:459
Amos Lim12696e5e32022-09-16 07:37:5810#include "content/browser/webauth/authenticator_common_impl.h"
Daniel Cheng9fb887ff2021-10-01 20:27:3811#include "content/public/browser/document_service.h"
kpaulhamus7c9f00942017-06-30 11:08:4512#include "content/public/browser/render_frame_host.h"
Martin Kreichgauer977c00472018-11-29 00:09:0413
kpaulhamus7c9f00942017-06-30 11:08:4514namespace content {
15
Martin Kreichgauer7d2b8dbb2021-04-01 16:03:4516void AuthenticatorImpl::Create(
17 RenderFrameHost* render_frame_host,
18 mojo::PendingReceiver<blink::mojom::Authenticator> receiver) {
danakjc70aec1f2022-07-07 15:48:1919 CHECK(render_frame_host);
Sreeja Kamishettye49854f82021-06-02 00:52:0320 // Avoid creating the service if the RenderFrameHost isn't active, e.g. if a
Martin Kreichgauer7d2b8dbb2021-04-01 16:03:4521 // request arrives during a navigation.
Sreeja Kamishettye49854f82021-06-02 00:52:0322 if (!render_frame_host->IsActive()) {
Martin Kreichgauer7d2b8dbb2021-04-01 16:03:4523 return;
24 }
Martin Kreichgauer7d2b8dbb2021-04-01 16:03:4525 // AuthenticatorImpl owns itself. It self-destructs when the RenderFrameHost
Daniel Cheng9fb887ff2021-10-01 20:27:3826 // navigates or is deleted. See DocumentService for details.
Martin Kreichgauer7d2b8dbb2021-04-01 16:03:4527 new AuthenticatorImpl(
danakjc70aec1f2022-07-07 15:48:1928 *render_frame_host, std::move(receiver),
Adam Langley3ec44c22023-08-10 01:04:0129 std::make_unique<AuthenticatorCommonImpl>(
30 render_frame_host,
31 AuthenticatorCommonImpl::ServingRequestsFor::kWebContents));
Martin Kreichgauer7d2b8dbb2021-04-01 16:03:4532}
Kim Paulhamus40de29e42017-12-07 04:14:0833
danakjc70aec1f2022-07-07 15:48:1934void AuthenticatorImpl::CreateForTesting(
35 RenderFrameHost& render_frame_host,
36 mojo::PendingReceiver<blink::mojom::Authenticator> receiver,
Amos Lim12696e5e32022-09-16 07:37:5837 std::unique_ptr<AuthenticatorCommonImpl> authenticator_common_impl) {
danakjc70aec1f2022-07-07 15:48:1938 new AuthenticatorImpl(render_frame_host, std::move(receiver),
Amos Lim12696e5e32022-09-16 07:37:5839 std::move(authenticator_common_impl));
danakjc70aec1f2022-07-07 15:48:1940}
41
Manas Verma9ba13692019-03-21 21:01:0042AuthenticatorImpl::AuthenticatorImpl(
danakjc70aec1f2022-07-07 15:48:1943 RenderFrameHost& render_frame_host,
Martin Kreichgauer7d2b8dbb2021-04-01 16:03:4544 mojo::PendingReceiver<blink::mojom::Authenticator> receiver,
Amos Lim12696e5e32022-09-16 07:37:5845 std::unique_ptr<AuthenticatorCommonImpl> authenticator_common_impl)
Daniel Cheng9fb887ff2021-10-01 20:27:3846 : DocumentService(render_frame_host, std::move(receiver)),
Amos Lim12696e5e32022-09-16 07:37:5847 authenticator_common_impl_(std::move(authenticator_common_impl)) {
48 authenticator_common_impl_->EnableRequestProxyExtensionsAPISupport();
49 DCHECK(authenticator_common_impl_);
kpaulhamus7c9f00942017-06-30 11:08:4550}
51
Adam Langleyb0385822021-03-19 23:34:0052AuthenticatorImpl::~AuthenticatorImpl() = default;
kpaulhamus7c9f00942017-06-30 11:08:4553
Kim Paulhamusfbe092bf2017-11-21 16:46:0854// mojom::Authenticator
kpaulhamus7c9f00942017-06-30 11:08:4555void AuthenticatorImpl::MakeCredential(
Amos Limdddb6992018-07-19 22:14:3256 blink::mojom::PublicKeyCredentialCreationOptionsPtr options,
kpaulhamus7c9f00942017-06-30 11:08:4557 MakeCredentialCallback callback) {
Amos Lim12696e5e32022-09-16 07:37:5858 authenticator_common_impl_->MakeCredential(origin(), std::move(options),
59 std::move(callback));
Kim Paulhamus021c3622017-08-28 18:35:1760}
Kim Paulhamusfbe092bf2017-11-21 16:46:0861
Amos Lim12696e5e32022-09-16 07:37:5862// mojom::Authenticator
Adem Derinel72e11db2025-02-11 15:58:0063void AuthenticatorImpl::GetCredential(
Amos Limdddb6992018-07-19 22:14:3264 blink::mojom::PublicKeyCredentialRequestOptionsPtr options,
Adem Derinel72e11db2025-02-11 15:58:0065 GetCredentialCallback callback) {
66 authenticator_common_impl_->GetCredential(origin(), std::move(options),
67 /*payment=*/nullptr,
68 std::move(callback));
Kim Paulhamus9d87fb0d2018-01-18 18:36:2269}
70
Gabriel Viera7bc08f212024-07-10 15:42:3371// mojom::Authenticator
72void AuthenticatorImpl::Report(
73 blink::mojom::PublicKeyCredentialReportOptionsPtr options,
74 ReportCallback callback) {
75 authenticator_common_impl_->Report(origin(), std::move(options),
76 std::move(callback));
77}
78
Andrii Natiahlyi1a4ab7d2024-08-23 22:16:5179// mojom::Authenticator
80void AuthenticatorImpl::GetClientCapabilities(
81 GetClientCapabilitiesCallback callback) {
Andrii Natiahlyi6b2f4b12024-09-03 14:58:4282 authenticator_common_impl_->GetClientCapabilities(origin(),
83 std::move(callback));
Andrii Natiahlyi1a4ab7d2024-08-23 22:16:5184}
85
Kim Paulhamus0112af72018-05-31 00:23:5986void AuthenticatorImpl::IsUserVerifyingPlatformAuthenticatorAvailable(
87 IsUserVerifyingPlatformAuthenticatorAvailableCallback callback) {
Amos Lim12696e5e32022-09-16 07:37:5888 authenticator_common_impl_->IsUserVerifyingPlatformAuthenticatorAvailable(
Martin Kreichgauer1f4aa592023-01-06 18:39:3789 origin(), std::move(callback));
Kim Paulhamus0112af72018-05-31 00:23:5990}
91
Nina Satragnoc3444e8f2022-08-04 22:43:0092void AuthenticatorImpl::IsConditionalMediationAvailable(
93 IsConditionalMediationAvailableCallback callback) {
Amos Lim12696e5e32022-09-16 07:37:5894 authenticator_common_impl_->IsConditionalMediationAvailable(
Martin Kreichgauer1f4aa592023-01-06 18:39:3795 origin(), std::move(callback));
Nina Satragnoc3444e8f2022-08-04 22:43:0096}
97
Suzy Lid4dda9c2019-05-10 17:36:4298void AuthenticatorImpl::Cancel() {
Amos Lim12696e5e32022-09-16 07:37:5899 authenticator_common_impl_->Cancel();
Suzy Lid4dda9c2019-05-10 17:36:42100}
101
Martin Kreichgauer2c9e5352018-10-30 23:28:53102} // namespace content