summaryrefslogtreecommitdiffstats
path: root/src/core/authenticator_request_client_delegate_qt.h
blob: 05c6136bd161cf8139683d416666c072808fc0e3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
// Copyright (C) 2023 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only

#ifndef AUTHENTICATOR_REQUEST_CLIENT_DELEGATE_QT_H
#define AUTHENTICATOR_REQUEST_CLIENT_DELEGATE_QT_H

#include "qtwebenginecoreglobal_p.h"
#include "content/public/browser/authenticator_request_client_delegate.h"
#include <unordered_map>
#include <QSharedPointer>

namespace QtWebEngineCore {

class AuthenticatorRequestDialogController;

class WebAuthenticationDelegateQt : public content::WebAuthenticationDelegate
{
public:
    WebAuthenticationDelegateQt();
    virtual ~WebAuthenticationDelegateQt();

    bool SupportsResidentKeys(content::RenderFrameHost *render_frame_host) override;
};

class AuthenticatorRequestClientDelegateQt : public content::AuthenticatorRequestClientDelegate
{
public:
    explicit AuthenticatorRequestClientDelegateQt(content::RenderFrameHost *render_frame_host);
    AuthenticatorRequestClientDelegateQt(const AuthenticatorRequestClientDelegateQt &) = delete;
    AuthenticatorRequestClientDelegateQt &
    operator=(const AuthenticatorRequestClientDelegateQt &) = delete;
    ~AuthenticatorRequestClientDelegateQt();

    // content::AuthenticatorRequestClientDelegate ovverrides
    void SetRelyingPartyId(const std::string &rp_id) override;
    bool DoesBlockRequestOnFailure(InterestingFailureReason reason) override;
    void RegisterActionCallbacks(base::OnceClosure cancel_callback,
                            base::RepeatingClosure start_over_callback,
                            AccountPreselectedCallback account_preselected_callback,
                            device::FidoRequestHandlerBase::RequestCallback request_callback,
                            base::RepeatingClosure bluetooth_adapter_power_on_callback) override;
    void ShouldReturnAttestation(const std::string &relying_party_id,
                                 const device::FidoAuthenticator *authenticator,
                                 bool is_enterprise_attestation,
                                 base::OnceCallback<void(bool)> callback) override;
    void SelectAccount(
            std::vector<device::AuthenticatorGetAssertionResponse> responses,
            base::OnceCallback<void(device::AuthenticatorGetAssertionResponse)> callback) override;
    void DisableUI() override;
    bool IsWebAuthnUIEnabled() override;
    void SetConditionalRequest(bool is_conditional) override;

    // device::FidoRequestHandlerBase::Observer overrides:
    // This method will not be invoked until the observer is set.
    void OnTransportAvailabilityEnumerated(
            device::FidoRequestHandlerBase::TransportAvailabilityInfo data) override;

    bool SupportsPIN() const override;
    void CollectPIN(CollectPINOptions options,
                    base::OnceCallback<void(std::u16string)> provide_pin_cb) override;
    void FinishCollectToken() override;

    // Dialog helper
    void onCancelRequest();
    void onSelectAccount(const QString &selectedAccount);
    void onCollectPin(const QString &pin);
    void onRetryRequest();

private:
    content::RenderFrameHost *m_renderFrameHost;
    bool m_isUiDisabled = false;
    bool m_isConditionalRequest = false;

    base::OnceClosure m_cancelCallback;
    base::RepeatingClosure m_startOverCallback;
    AccountPreselectedCallback m_accountPreselectedCallback;
    device::FidoRequestHandlerBase::RequestCallback m_requestCallback;
    base::RepeatingClosure m_bluetoothAdapterPowerOnCallback;

    // Select account details;
    std::vector<device::AuthenticatorGetAssertionResponse> m_authenticatorGetAssertionResponse;
    std::unordered_map<QString, int> m_userMap;
    base::OnceCallback<void(device::AuthenticatorGetAssertionResponse)> m_selectAccountCallback;

    // collect pin
    base::OnceCallback<void(std::u16string)> m_providePinCallback;

    // This member is used to keep authenticator request dialog controller alive until
    // authenticator request is completed or cancelled.
    QSharedPointer<AuthenticatorRequestDialogController> m_dialogController;
    base::WeakPtrFactory<AuthenticatorRequestClientDelegateQt> m_weakFactory;
};

}

#endif // AUTHENTICATOR_REQUEST_CLIENT_DELEGATE_QT_H