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
;
75 // CredentialManagerPendingSignedOutTaskDelegate:
76 PasswordStore
* GetPasswordStore() override
;
77 void DoneRequiringUserMediation() override
;
79 // CredentialManagerPasswordFormManagerDelegate:
80 void OnProvisionalSaveComplete() override
;
83 // Returns the driver for the current main frame.
84 // Virtual for testing.
85 virtual base::WeakPtr
<PasswordManagerDriver
> GetDriver();
87 PasswordManagerClient
* client_
;
88 scoped_ptr
<CredentialManagerPasswordFormManager
> form_manager_
;
90 // Set to false to disable automatic signing in.
91 BooleanPrefMember auto_signin_enabled_
;
93 // When 'OnRequestCredential' is called, it in turn calls out to the
94 // PasswordStore; we push enough data into Pending*Task objects so that
95 // they can properly respond to the request once the PasswordStore gives
97 scoped_ptr
<CredentialManagerPendingRequestTask
> pending_request_
;
98 scoped_ptr
<CredentialManagerPendingRequireUserMediationTask
>
99 pending_require_user_mediation_
;
101 DISALLOW_COPY_AND_ASSIGN(CredentialManagerDispatcher
);
104 } // namespace password_manager
106 #endif // COMPONENTS_PASSWORD_MANAGER_CONTENT_BROWSER_CONTENT_CREDENTIAL_MANAGER_DISPATCHER_H_