OLD | NEW |
| (Empty) |
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. | |
4 | |
5 #ifndef COMPONENTS_PASSWORD_MANAGER_CONTENT_BROWSER_CONTENT_CREDENTIAL_MANAGER_D
ISPATCHER_H_ | |
6 #define COMPONENTS_PASSWORD_MANAGER_CONTENT_BROWSER_CONTENT_CREDENTIAL_MANAGER_D
ISPATCHER_H_ | |
7 | |
8 #include <memory> | |
9 | |
10 #include "base/callback.h" | |
11 #include "base/macros.h" | |
12 #include "base/memory/weak_ptr.h" | |
13 #include "components/password_manager/core/browser/credential_manager_password_f
orm_manager.h" | |
14 #include "components/password_manager/core/browser/credential_manager_pending_re
quest_task.h" | |
15 #include "components/password_manager/core/browser/credential_manager_pending_re
quire_user_mediation_task.h" | |
16 #include "components/password_manager/core/browser/password_store_consumer.h" | |
17 #include "components/prefs/pref_member.h" | |
18 #include "content/public/browser/web_contents_observer.h" | |
19 | |
20 class GURL; | |
21 | |
22 namespace autofill { | |
23 struct PasswordForm; | |
24 } | |
25 | |
26 namespace content { | |
27 class WebContents; | |
28 } | |
29 | |
30 namespace password_manager { | |
31 class CredentialManagerPasswordFormManager; | |
32 class PasswordManagerClient; | |
33 class PasswordManagerDriver; | |
34 class PasswordStore; | |
35 struct CredentialInfo; | |
36 | |
37 class CredentialManagerDispatcher | |
38 : public content::WebContentsObserver, | |
39 public CredentialManagerPasswordFormManagerDelegate, | |
40 public CredentialManagerPendingRequestTaskDelegate, | |
41 public CredentialManagerPendingRequireUserMediationTaskDelegate { | |
42 public: | |
43 CredentialManagerDispatcher(content::WebContents* web_contents, | |
44 PasswordManagerClient* client); | |
45 ~CredentialManagerDispatcher() override; | |
46 | |
47 // Called in response to an IPC from the renderer, triggered by a page's call | |
48 // to 'navigator.credentials.store'. | |
49 virtual void OnStore(int request_id, const password_manager::CredentialInfo&); | |
50 | |
51 // Called in response to an IPC from the renderer, triggered by a page's call | |
52 // to 'navigator.credentials.requireUserMediation'. | |
53 virtual void OnRequireUserMediation(int request_id); | |
54 | |
55 // Called in response to an IPC from the renderer, triggered by a page's call | |
56 // to 'navigator.credentials.request'. | |
57 // | |
58 // TODO(vabr): Determine if we can drop the `const` here to save some copies | |
59 // while processing the request. | |
60 virtual void OnRequestCredential(int request_id, | |
61 bool zero_click_only, | |
62 bool include_passwords, | |
63 const std::vector<GURL>& federations); | |
64 | |
65 // content::WebContentsObserver implementation. | |
66 bool OnMessageReceived(const IPC::Message& message) override; | |
67 | |
68 // CredentialManagerPendingRequestTaskDelegate: | |
69 bool IsZeroClickAllowed() const override; | |
70 GURL GetOrigin() const override; | |
71 void SendCredential(int request_id, const CredentialInfo& info) override; | |
72 void SendPasswordForm(int request_id, | |
73 const autofill::PasswordForm* form) override; | |
74 PasswordManagerClient* client() const override; | |
75 autofill::PasswordForm GetSynthesizedFormForOrigin() const override; | |
76 | |
77 // CredentialManagerPendingSignedOutTaskDelegate: | |
78 PasswordStore* GetPasswordStore() override; | |
79 void DoneRequiringUserMediation() override; | |
80 | |
81 // CredentialManagerPasswordFormManagerDelegate: | |
82 void OnProvisionalSaveComplete() override; | |
83 | |
84 private: | |
85 // Returns the driver for the current main frame. | |
86 // Virtual for testing. | |
87 virtual base::WeakPtr<PasswordManagerDriver> GetDriver(); | |
88 | |
89 // Schedules a CredentiaManagerPendingRequestTask (during | |
90 // |OnRequestCredential()|) after the PasswordStore's AffiliationMatchHelper | |
91 // grabs a list of realms related to the current web origin. | |
92 void ScheduleRequestTask(int request_id, | |
93 bool zero_click_only, | |
94 bool include_passwords, | |
95 const std::vector<GURL>& federations, | |
96 const std::vector<std::string>& android_realms); | |
97 | |
98 // Schedules a CredentialManagerPendingRequireUserMediationTask after the | |
99 // AffiliationMatchHelper grabs a list of realms related to the current | |
100 // web origin. | |
101 void ScheduleRequireMediationTask( | |
102 int request_id, | |
103 const std::vector<std::string>& android_realms); | |
104 | |
105 // Returns true iff it's OK to update credentials in the password store. | |
106 bool IsUpdatingCredentialAllowed() const; | |
107 | |
108 PasswordManagerClient* client_; | |
109 std::unique_ptr<CredentialManagerPasswordFormManager> form_manager_; | |
110 | |
111 // Set to false to disable automatic signing in. | |
112 BooleanPrefMember auto_signin_enabled_; | |
113 | |
114 // When 'OnRequestCredential' is called, it in turn calls out to the | |
115 // PasswordStore; we push enough data into Pending*Task objects so that | |
116 // they can properly respond to the request once the PasswordStore gives | |
117 // us data. | |
118 std::unique_ptr<CredentialManagerPendingRequestTask> pending_request_; | |
119 std::unique_ptr<CredentialManagerPendingRequireUserMediationTask> | |
120 pending_require_user_mediation_; | |
121 | |
122 base::WeakPtrFactory<CredentialManagerDispatcher> weak_factory_; | |
123 | |
124 DISALLOW_COPY_AND_ASSIGN(CredentialManagerDispatcher); | |
125 }; | |
126 | |
127 } // namespace password_manager | |
128 | |
129 #endif // COMPONENTS_PASSWORD_MANAGER_CONTENT_BROWSER_CONTENT_CREDENTIAL_MANAGE
R_DISPATCHER_H_ | |
OLD | NEW |