OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CHROME_BROWSER_PASSWORD_MANAGER_PASSWORD_FORM_MANAGER_H_ | 5 #ifndef CHROME_BROWSER_PASSWORD_MANAGER_PASSWORD_FORM_MANAGER_H_ |
6 #define CHROME_BROWSER_PASSWORD_MANAGER_PASSWORD_FORM_MANAGER_H_ | 6 #define CHROME_BROWSER_PASSWORD_MANAGER_PASSWORD_FORM_MANAGER_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
11 #include "build/build_config.h" | 11 #include "build/build_config.h" |
12 | 12 |
13 #include "base/stl_util.h" | 13 #include "base/stl_util.h" |
14 #include "chrome/browser/password_manager/password_store_consumer.h" | 14 #include "chrome/browser/password_manager/password_store_consumer.h" |
15 #include "webkit/forms/password_form.h" | 15 #include "content/public/common/password_form.h" |
16 | 16 |
17 namespace content { | 17 namespace content { |
18 class WebContents; | 18 class WebContents; |
19 } // namespace content | 19 } // namespace content |
20 | 20 |
21 class PasswordManager; | 21 class PasswordManager; |
22 class PasswordStore; | 22 class PasswordStore; |
23 class Profile; | 23 class Profile; |
24 | 24 |
25 // Per-password-form-{on-page, dialog} class responsible for interactions | 25 // Per-password-form-{on-page, dialog} class responsible for interactions |
26 // between a given form, the per-tab PasswordManager, and the PasswordStore. | 26 // between a given form, the per-tab PasswordManager, and the PasswordStore. |
27 class PasswordFormManager : public PasswordStoreConsumer { | 27 class PasswordFormManager : public PasswordStoreConsumer { |
28 public: | 28 public: |
29 // profile contains the link to the PasswordStore and whether we're off | 29 // profile contains the link to the PasswordStore and whether we're off |
30 // the record | 30 // the record |
31 // password_manager owns this object | 31 // password_manager owns this object |
32 // form_on_page is the form that may be submitted and could need login data. | 32 // form_on_page is the form that may be submitted and could need login data. |
33 // ssl_valid represents the security of the page containing observed_form, | 33 // ssl_valid represents the security of the page containing observed_form, |
34 // used to filter login results from database. | 34 // used to filter login results from database. |
35 PasswordFormManager(Profile* profile, | 35 PasswordFormManager(Profile* profile, |
36 PasswordManager* password_manager, | 36 PasswordManager* password_manager, |
37 content::WebContents* web_contents, | 37 content::WebContents* web_contents, |
38 const webkit::forms::PasswordForm& observed_form, | 38 const content::PasswordForm& observed_form, |
39 bool ssl_valid); | 39 bool ssl_valid); |
40 virtual ~PasswordFormManager(); | 40 virtual ~PasswordFormManager(); |
41 | 41 |
42 enum ActionMatch { | 42 enum ActionMatch { |
43 ACTION_MATCH_REQUIRED, | 43 ACTION_MATCH_REQUIRED, |
44 ACTION_MATCH_NOT_REQUIRED | 44 ACTION_MATCH_NOT_REQUIRED |
45 }; | 45 }; |
46 | 46 |
47 // Compare basic data of observed_form_ with argument. Only check the action | 47 // Compare basic data of observed_form_ with argument. Only check the action |
48 // URL when action match is required. | 48 // URL when action match is required. |
49 bool DoesManage(const webkit::forms::PasswordForm& form, | 49 bool DoesManage(const content::PasswordForm& form, |
50 ActionMatch action_match) const; | 50 ActionMatch action_match) const; |
51 | 51 |
52 // Retrieves potential matching logins from the database. | 52 // Retrieves potential matching logins from the database. |
53 void FetchMatchingLoginsFromPasswordStore(); | 53 void FetchMatchingLoginsFromPasswordStore(); |
54 | 54 |
55 // Simple state-check to verify whether this object as received a callback | 55 // Simple state-check to verify whether this object as received a callback |
56 // from the PasswordStore and completed its matching phase. Note that the | 56 // from the PasswordStore and completed its matching phase. Note that the |
57 // callback in question occurs on the same (and only) main thread from which | 57 // callback in question occurs on the same (and only) main thread from which |
58 // instances of this class are ever used, but it is required since it is | 58 // instances of this class are ever used, but it is required since it is |
59 // conceivable that a user (or ui test) could attempt to submit a login | 59 // conceivable that a user (or ui test) could attempt to submit a login |
(...skipping 18 matching lines...) Expand all Loading... |
78 // login or password field are not considered valid. | 78 // login or password field are not considered valid. |
79 bool HasValidPasswordForm(); | 79 bool HasValidPasswordForm(); |
80 | 80 |
81 // These functions are used to determine if this form has had it's password | 81 // These functions are used to determine if this form has had it's password |
82 // auto generated by the browser. | 82 // auto generated by the browser. |
83 bool HasGeneratedPassword(); | 83 bool HasGeneratedPassword(); |
84 void SetHasGeneratedPassword(); | 84 void SetHasGeneratedPassword(); |
85 | 85 |
86 // Determines if we need to autofill given the results of the query. | 86 // Determines if we need to autofill given the results of the query. |
87 void OnRequestDone( | 87 void OnRequestDone( |
88 int handle, const std::vector<webkit::forms::PasswordForm*>& result); | 88 int handle, const std::vector<content::PasswordForm*>& result); |
89 | 89 |
90 // PasswordStoreConsumer implementation. | 90 // PasswordStoreConsumer implementation. |
91 virtual void OnPasswordStoreRequestDone( | 91 virtual void OnPasswordStoreRequestDone( |
92 CancelableRequestProvider::Handle handle, | 92 CancelableRequestProvider::Handle handle, |
93 const std::vector<webkit::forms::PasswordForm*>& result) OVERRIDE; | 93 const std::vector<content::PasswordForm*>& result) OVERRIDE; |
94 | 94 |
95 // A user opted to 'never remember' passwords for this form. | 95 // A user opted to 'never remember' passwords for this form. |
96 // Blacklist it so that from now on when it is seen we ignore it. | 96 // Blacklist it so that from now on when it is seen we ignore it. |
97 void PermanentlyBlacklist(); | 97 void PermanentlyBlacklist(); |
98 | 98 |
99 // If the user has submitted observed_form_, provisionally hold on to | 99 // If the user has submitted observed_form_, provisionally hold on to |
100 // the submitted credentials until we are told by PasswordManager whether | 100 // the submitted credentials until we are told by PasswordManager whether |
101 // or not the login was successful. | 101 // or not the login was successful. |
102 void ProvisionallySave(const webkit::forms::PasswordForm& credentials); | 102 void ProvisionallySave(const content::PasswordForm& credentials); |
103 | 103 |
104 // Handles save-as-new or update of the form managed by this manager. | 104 // Handles save-as-new or update of the form managed by this manager. |
105 // Note the basic data of updated_credentials must match that of | 105 // Note the basic data of updated_credentials must match that of |
106 // observed_form_ (e.g DoesManage(pending_credentials_) == true). | 106 // observed_form_ (e.g DoesManage(pending_credentials_) == true). |
107 void Save(); | 107 void Save(); |
108 | 108 |
109 // Call these if/when we know the form submission worked or failed. | 109 // Call these if/when we know the form submission worked or failed. |
110 // These routines are used to update internal statistics ("ActionsTaken"). | 110 // These routines are used to update internal statistics ("ActionsTaken"). |
111 void SubmitPassed(); | 111 void SubmitPassed(); |
112 void SubmitFailed(); | 112 void SubmitFailed(); |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
159 kSubmitResultMax | 159 kSubmitResultMax |
160 }; | 160 }; |
161 | 161 |
162 // The maximum number of combinations of the three preceding enums. | 162 // The maximum number of combinations of the three preceding enums. |
163 // This is used when recording the actions taken by the form in UMA. | 163 // This is used when recording the actions taken by the form in UMA. |
164 static const int kMaxNumActionsTaken = kManagerActionMax * kUserActionMax * | 164 static const int kMaxNumActionsTaken = kManagerActionMax * kUserActionMax * |
165 kSubmitResultMax; | 165 kSubmitResultMax; |
166 | 166 |
167 // Helper for OnPasswordStoreRequestDone to determine whether or not | 167 // Helper for OnPasswordStoreRequestDone to determine whether or not |
168 // the given result form is worth scoring. | 168 // the given result form is worth scoring. |
169 bool IgnoreResult(const webkit::forms::PasswordForm& form) const; | 169 bool IgnoreResult(const content::PasswordForm& form) const; |
170 | 170 |
171 // Helper for Save in the case that best_matches.size() == 0, meaning | 171 // Helper for Save in the case that best_matches.size() == 0, meaning |
172 // we have no prior record of this form/username/password and the user | 172 // we have no prior record of this form/username/password and the user |
173 // has opted to 'Save Password'. If |reset_preferred_login| is set, | 173 // has opted to 'Save Password'. If |reset_preferred_login| is set, |
174 // the previously preferred login from |best_matches_| will be reset. | 174 // the previously preferred login from |best_matches_| will be reset. |
175 void SaveAsNewLogin(bool reset_preferred_login); | 175 void SaveAsNewLogin(bool reset_preferred_login); |
176 | 176 |
177 // Helper for OnPasswordStoreRequestDone to score an individual result | 177 // Helper for OnPasswordStoreRequestDone to score an individual result |
178 // against the observed_form_. | 178 // against the observed_form_. |
179 int ScoreResult(const webkit::forms::PasswordForm& form) const; | 179 int ScoreResult(const content::PasswordForm& form) const; |
180 | 180 |
181 // Helper for Save in the case that best_matches.size() > 0, meaning | 181 // Helper for Save in the case that best_matches.size() > 0, meaning |
182 // we have at least one match for this form/username/password. This | 182 // we have at least one match for this form/username/password. This |
183 // Updates the form managed by this object, as well as any matching forms | 183 // Updates the form managed by this object, as well as any matching forms |
184 // that now need to have preferred bit changed, since updated_credentials | 184 // that now need to have preferred bit changed, since updated_credentials |
185 // is now implicitly 'preferred'. | 185 // is now implicitly 'preferred'. |
186 void UpdateLogin(); | 186 void UpdateLogin(); |
187 | 187 |
188 // Update all login matches to reflect new preferred state - preferred flag | 188 // Update all login matches to reflect new preferred state - preferred flag |
189 // will be reset on all matched logins that different than the current | 189 // will be reset on all matched logins that different than the current |
190 // |pending_credentials_|. | 190 // |pending_credentials_|. |
191 void UpdatePreferredLoginState(PasswordStore* password_store); | 191 void UpdatePreferredLoginState(PasswordStore* password_store); |
192 | 192 |
193 // Converts the "ActionsTaken" fields into an int so they can be logged to | 193 // Converts the "ActionsTaken" fields into an int so they can be logged to |
194 // UMA. | 194 // UMA. |
195 int GetActionsTaken(); | 195 int GetActionsTaken(); |
196 | 196 |
197 // Informs the renderer that the user has not blacklisted observed_form_ by | 197 // Informs the renderer that the user has not blacklisted observed_form_ by |
198 // choosing "never save passwords for this site". This is used by the password | 198 // choosing "never save passwords for this site". This is used by the password |
199 // generation manager to deside whether to show the password generation icon. | 199 // generation manager to deside whether to show the password generation icon. |
200 virtual void SendNotBlacklistedToRenderer(); | 200 virtual void SendNotBlacklistedToRenderer(); |
201 | 201 |
202 // Set of PasswordForms from the DB that best match the form | 202 // Set of PasswordForms from the DB that best match the form |
203 // being managed by this. Use a map instead of vector, because we most | 203 // being managed by this. Use a map instead of vector, because we most |
204 // frequently require lookups by username value in IsNewLogin. | 204 // frequently require lookups by username value in IsNewLogin. |
205 webkit::forms::PasswordFormMap best_matches_; | 205 content::PasswordFormMap best_matches_; |
206 | 206 |
207 // Cleans up when best_matches_ goes out of scope. | 207 // Cleans up when best_matches_ goes out of scope. |
208 STLValueDeleter<webkit::forms::PasswordFormMap> best_matches_deleter_; | 208 STLValueDeleter<content::PasswordFormMap> best_matches_deleter_; |
209 | 209 |
210 // The PasswordForm from the page or dialog managed by this. | 210 // The PasswordForm from the page or dialog managed by this. |
211 webkit::forms::PasswordForm observed_form_; | 211 content::PasswordForm observed_form_; |
212 | 212 |
213 // The origin url path of observed_form_ tokenized, for convenience when | 213 // The origin url path of observed_form_ tokenized, for convenience when |
214 // scoring. | 214 // scoring. |
215 std::vector<std::string> form_path_tokens_; | 215 std::vector<std::string> form_path_tokens_; |
216 | 216 |
217 // Stores updated credentials when the form was submitted but success is | 217 // Stores updated credentials when the form was submitted but success is |
218 // still unknown. | 218 // still unknown. |
219 webkit::forms::PasswordForm pending_credentials_; | 219 content::PasswordForm pending_credentials_; |
220 | 220 |
221 // Whether pending_credentials_ stores a new login or is an update | 221 // Whether pending_credentials_ stores a new login or is an update |
222 // to an existing one. | 222 // to an existing one. |
223 bool is_new_login_; | 223 bool is_new_login_; |
224 | 224 |
225 // Whether this form has an auto generated password. | 225 // Whether this form has an auto generated password. |
226 bool has_generated_password_; | 226 bool has_generated_password_; |
227 | 227 |
228 // PasswordManager owning this. | 228 // PasswordManager owning this. |
229 const PasswordManager* const password_manager_; | 229 const PasswordManager* const password_manager_; |
230 | 230 |
231 // Handle to any pending PasswordStore::GetLogins query. | 231 // Handle to any pending PasswordStore::GetLogins query. |
232 CancelableRequestProvider::Handle pending_login_query_; | 232 CancelableRequestProvider::Handle pending_login_query_; |
233 | 233 |
234 // Convenience pointer to entry in best_matches_ that is marked | 234 // Convenience pointer to entry in best_matches_ that is marked |
235 // as preferred. This is only allowed to be null if there are no best matches | 235 // as preferred. This is only allowed to be null if there are no best matches |
236 // at all, since there will always be one preferred login when there are | 236 // at all, since there will always be one preferred login when there are |
237 // multiple matches (when first saved, a login is marked preferred). | 237 // multiple matches (when first saved, a login is marked preferred). |
238 const webkit::forms::PasswordForm* preferred_match_; | 238 const content::PasswordForm* preferred_match_; |
239 | 239 |
240 typedef enum { | 240 typedef enum { |
241 PRE_MATCHING_PHASE, // Have not yet invoked a GetLogins query to find | 241 PRE_MATCHING_PHASE, // Have not yet invoked a GetLogins query to find |
242 // matching login information from password store. | 242 // matching login information from password store. |
243 MATCHING_PHASE, // We've made a GetLogins request, but | 243 MATCHING_PHASE, // We've made a GetLogins request, but |
244 // haven't received or finished processing result. | 244 // haven't received or finished processing result. |
245 POST_MATCHING_PHASE // We've queried the DB and processed matching | 245 POST_MATCHING_PHASE // We've queried the DB and processed matching |
246 // login results. | 246 // login results. |
247 } PasswordFormManagerState; | 247 } PasswordFormManagerState; |
248 | 248 |
(...skipping 12 matching lines...) Expand all Loading... |
261 // These three fields record the "ActionsTaken" by the browser and | 261 // These three fields record the "ActionsTaken" by the browser and |
262 // the user with this form, and the result. They are combined and | 262 // the user with this form, and the result. They are combined and |
263 // recorded in UMA when the manager is destroyed. | 263 // recorded in UMA when the manager is destroyed. |
264 ManagerAction manager_action_; | 264 ManagerAction manager_action_; |
265 UserAction user_action_; | 265 UserAction user_action_; |
266 SubmitResult submit_result_; | 266 SubmitResult submit_result_; |
267 | 267 |
268 DISALLOW_COPY_AND_ASSIGN(PasswordFormManager); | 268 DISALLOW_COPY_AND_ASSIGN(PasswordFormManager); |
269 }; | 269 }; |
270 #endif // CHROME_BROWSER_PASSWORD_MANAGER_PASSWORD_FORM_MANAGER_H_ | 270 #endif // CHROME_BROWSER_PASSWORD_MANAGER_PASSWORD_FORM_MANAGER_H_ |
OLD | NEW |