1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef COMPONENTS_PASSWORD_MANAGER_CONTENT_BROWSER_CONTENT_CREDENTIAL_MANAGER_DISPATCHER_H_
6 #define COMPONENTS_PASSWORD_MANAGER_CONTENT_BROWSER_CONTENT_CREDENTIAL_MANAGER_DISPATCHER_H_
8 #include "base/callback.h"
9 #include "base/macros.h"
10 #include "base/memory/scoped_ptr.h"
11 #include "base/memory/weak_ptr.h"
12 #include "base/prefs/pref_member.h"
13 #include "components/password_manager/core/browser/credential_manager_password_form_manager.h"
14 #include "components/password_manager/core/browser/credential_manager_pending_request_task.h"
15 #include "components/password_manager/core/browser/credential_manager_pending_require_user_mediation_task.h"
16 #include "components/password_manager/core/browser/password_store_consumer.h"
17 #include "content/public/browser/web_contents_observer.h"
29 namespace password_manager
{
30 class CredentialManagerPasswordFormManager
;
31 class PasswordManagerClient
;
32 class PasswordManagerDriver
;
34 struct CredentialInfo
;
36 class CredentialManagerDispatcher
37 : public content::WebContentsObserver
,
38 public CredentialManagerPasswordFormManagerDelegate
,
39 public CredentialManagerPendingRequestTaskDelegate
,
40 public CredentialManagerPendingRequireUserMediationTaskDelegate
{
42 CredentialManagerDispatcher(content::WebContents
* web_contents
,
43 PasswordManagerClient
* client
);
44 ~CredentialManagerDispatcher() override
;
46 // Called in response to an IPC from the renderer, triggered by a page's call
47 // to 'navigator.credentials.store'.
48 virtual void OnStore(int request_id
, const password_manager::CredentialInfo
&);
50 // Called in response to an IPC from the renderer, triggered by a page's call
51 // to 'navigator.credentials.requireUserMediation'.
52 virtual void OnRequireUserMediation(int request_id
);
54 // Called in response to an IPC from the renderer, triggered by a page's call
55 // to 'navigator.credentials.request'.
57 // TODO(vabr): Determine if we can drop the `const` here to save some copies
58 // while processing the request.
59 virtual void OnRequestCredential(int request_id
,
61 const std::vector
<GURL
>& federations
);
63 // content::WebContentsObserver implementation.
64 bool OnMessageReceived(const IPC::Message
& message
) override
;
66 using CredentialCallback
=
67 base::Callback
<void(const autofill::PasswordForm
&)>;
69 // CredentialManagerPendingRequestTaskDelegate:
70 bool IsZeroClickAllowed() const override
;
71 GURL
GetOrigin() const override
;
72 void SendCredential(int request_id
, const CredentialInfo
& info
) override
;
73 PasswordManagerClient
* client() const override
;
74 autofill::PasswordForm
GetSynthesizedFormForOrigin() const override
;
76 // CredentialManagerPendingSignedOutTaskDelegate:
77 PasswordStore
* GetPasswordStore() override
;
78 void DoneRequiringUserMediation() override
;
80 // CredentialManagerPasswordFormManagerDelegate:
81 void OnProvisionalSaveComplete() override
;
84 // Returns the driver for the current main frame.
85 // Virtual for testing.
86 virtual base::WeakPtr
<PasswordManagerDriver
> GetDriver();
88 // Schedules a CredentiaManagerPendingRequestTask (during
89 // |OnRequestCredential()|) after the PasswordStore's AffiliationMatchHelper
90 // grabs a list of realms related to the current web origin.
91 void ScheduleRequestTask(int request_id
,
93 const std::vector
<GURL
>& federations
,
94 const std::vector
<std::string
>& android_realms
);
96 PasswordManagerClient
* client_
;
97 scoped_ptr
<CredentialManagerPasswordFormManager
> form_manager_
;
99 // Set to false to disable automatic signing in.
100 BooleanPrefMember auto_signin_enabled_
;
102 // When 'OnRequestCredential' is called, it in turn calls out to the
103 // PasswordStore; we push enough data into Pending*Task objects so that
104 // they can properly respond to the request once the PasswordStore gives
106 scoped_ptr
<CredentialManagerPendingRequestTask
> pending_request_
;
107 scoped_ptr
<CredentialManagerPendingRequireUserMediationTask
>
108 pending_require_user_mediation_
;
110 base::WeakPtrFactory
<CredentialManagerDispatcher
> weak_factory_
;
112 DISALLOW_COPY_AND_ASSIGN(CredentialManagerDispatcher
);
115 } // namespace password_manager
117 #endif // COMPONENTS_PASSWORD_MANAGER_CONTENT_BROWSER_CONTENT_CREDENTIAL_MANAGER_DISPATCHER_H_