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.notifyFailedSignIn'.
48 virtual void OnNotifyFailedSignIn(int request_id
,
49 const password_manager::CredentialInfo
&);
51 // Called in response to an IPC from the renderer, triggered by a page's call
52 // to 'navigator.credentials.notifySignedIn'.
53 virtual void OnNotifySignedIn(int request_id
,
54 const password_manager::CredentialInfo
&);
56 // Called in response to an IPC from the renderer, triggered by a page's call
57 // to 'navigator.credentials.requireUserMediation'.
58 virtual void OnRequireUserMediation(int request_id
);
60 // Called in response to an IPC from the renderer, triggered by a page's call
61 // to 'navigator.credentials.request'.
63 // TODO(vabr): Determine if we can drop the `const` here to save some copies
64 // while processing the request.
65 virtual void OnRequestCredential(int request_id
,
67 const std::vector
<GURL
>& federations
);
69 // content::WebContentsObserver implementation.
70 bool OnMessageReceived(const IPC::Message
& message
) override
;
72 using CredentialCallback
=
73 base::Callback
<void(const autofill::PasswordForm
&)>;
75 // CredentialManagerPendingRequestTaskDelegate:
76 bool IsZeroClickAllowed() const override
;
77 GURL
GetOrigin() const override
;
78 void SendCredential(int request_id
, const CredentialInfo
& info
) override
;
79 PasswordManagerClient
* client() const override
;
81 // CredentialManagerPendingSignedOutTaskDelegate:
82 PasswordStore
* GetPasswordStore() override
;
83 void DoneRequiringUserMediation() override
;
85 // CredentialManagerPasswordFormManagerDelegate:
86 void OnProvisionalSaveComplete() override
;
89 // Returns the driver for the current main frame.
90 // Virtual for testing.
91 virtual base::WeakPtr
<PasswordManagerDriver
> GetDriver();
93 PasswordManagerClient
* client_
;
94 scoped_ptr
<CredentialManagerPasswordFormManager
> form_manager_
;
96 // Set to false to disable automatic signing in.
97 BooleanPrefMember auto_signin_enabled_
;
99 // When 'OnRequestCredential' is called, it in turn calls out to the
100 // PasswordStore; we push enough data into Pending*Task objects so that
101 // they can properly respond to the request once the PasswordStore gives
103 scoped_ptr
<CredentialManagerPendingRequestTask
> pending_request_
;
104 scoped_ptr
<CredentialManagerPendingRequireUserMediationTask
>
105 pending_require_user_mediation_
;
107 DISALLOW_COPY_AND_ASSIGN(CredentialManagerDispatcher
);
110 } // namespace password_manager
112 #endif // COMPONENTS_PASSWORD_MANAGER_CONTENT_BROWSER_CONTENT_CREDENTIAL_MANAGER_DISPATCHER_H_