Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(486)

Side by Side Diff: chrome/browser/password_manager/password_form_manager.h

Issue 23742004: Move PasswordForm from //content to //autofill. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@move_password_form_conversion_utils
Patch Set: Rebase Created 7 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 "content/public/common/password_form.h" 15 #include "components/autofill/core/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 content::PasswordForm& observed_form, 38 const autofill::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 enum OtherPossibleUsernamesAction { 47 enum OtherPossibleUsernamesAction {
48 ALLOW_OTHER_POSSIBLE_USERNAMES, 48 ALLOW_OTHER_POSSIBLE_USERNAMES,
49 IGNORE_OTHER_POSSIBLE_USERNAMES 49 IGNORE_OTHER_POSSIBLE_USERNAMES
50 }; 50 };
51 51
52 // Compare basic data of observed_form_ with argument. Only check the action 52 // Compare basic data of observed_form_ with argument. Only check the action
53 // URL when action match is required. 53 // URL when action match is required.
54 bool DoesManage(const content::PasswordForm& form, 54 bool DoesManage(const autofill::PasswordForm& form,
55 ActionMatch action_match) const; 55 ActionMatch action_match) const;
56 56
57 // Retrieves potential matching logins from the database. 57 // Retrieves potential matching logins from the database.
58 void FetchMatchingLoginsFromPasswordStore(); 58 void FetchMatchingLoginsFromPasswordStore();
59 59
60 // Simple state-check to verify whether this object as received a callback 60 // Simple state-check to verify whether this object as received a callback
61 // from the PasswordStore and completed its matching phase. Note that the 61 // from the PasswordStore and completed its matching phase. Note that the
62 // callback in question occurs on the same (and only) main thread from which 62 // callback in question occurs on the same (and only) main thread from which
63 // instances of this class are ever used, but it is required since it is 63 // instances of this class are ever used, but it is required since it is
64 // conceivable that a user (or ui test) could attempt to submit a login 64 // conceivable that a user (or ui test) could attempt to submit a login
(...skipping 22 matching lines...) Expand all
87 // Checks if the form is a valid password form. Forms which lack either 87 // Checks if the form is a valid password form. Forms which lack either
88 // login or password field are not considered valid. 88 // login or password field are not considered valid.
89 bool HasValidPasswordForm(); 89 bool HasValidPasswordForm();
90 90
91 // These functions are used to determine if this form has had it's password 91 // These functions are used to determine if this form has had it's password
92 // auto generated by the browser. 92 // auto generated by the browser.
93 bool HasGeneratedPassword(); 93 bool HasGeneratedPassword();
94 void SetHasGeneratedPassword(); 94 void SetHasGeneratedPassword();
95 95
96 // Determines if we need to autofill given the results of the query. 96 // Determines if we need to autofill given the results of the query.
97 void OnRequestDone(const std::vector<content::PasswordForm*>& result); 97 void OnRequestDone(const std::vector<autofill::PasswordForm*>& result);
98 98
99 // PasswordStoreConsumer implementation. 99 // PasswordStoreConsumer implementation.
100 virtual void OnPasswordStoreRequestDone( 100 virtual void OnPasswordStoreRequestDone(
101 CancelableRequestProvider::Handle handle, 101 CancelableRequestProvider::Handle handle,
102 const std::vector<content::PasswordForm*>& result) OVERRIDE; 102 const std::vector<autofill::PasswordForm*>& result) OVERRIDE;
103 virtual void OnGetPasswordStoreResults( 103 virtual void OnGetPasswordStoreResults(
104 const std::vector<content::PasswordForm*>& results) OVERRIDE; 104 const std::vector<autofill::PasswordForm*>& results) OVERRIDE;
105 105
106 // A user opted to 'never remember' passwords for this form. 106 // A user opted to 'never remember' passwords for this form.
107 // Blacklist it so that from now on when it is seen we ignore it. 107 // Blacklist it so that from now on when it is seen we ignore it.
108 void PermanentlyBlacklist(); 108 void PermanentlyBlacklist();
109 109
110 // If the user has submitted observed_form_, provisionally hold on to 110 // If the user has submitted observed_form_, provisionally hold on to
111 // the submitted credentials until we are told by PasswordManager whether 111 // the submitted credentials until we are told by PasswordManager whether
112 // or not the login was successful. |action| describes how we deal with 112 // or not the login was successful. |action| describes how we deal with
113 // possible usernames. If |action| is ALLOW_OTHER_POSSIBLE_USERNAMES we will 113 // possible usernames. If |action| is ALLOW_OTHER_POSSIBLE_USERNAMES we will
114 // treat a possible usernames match as a sign that our original heuristics 114 // treat a possible usernames match as a sign that our original heuristics
115 // were wrong and that the user selected the correct username from the 115 // were wrong and that the user selected the correct username from the
116 // Autofill UI. 116 // Autofill UI.
117 void ProvisionallySave(const content::PasswordForm& credentials, 117 void ProvisionallySave(const autofill::PasswordForm& credentials,
118 OtherPossibleUsernamesAction action); 118 OtherPossibleUsernamesAction action);
119 119
120 // Handles save-as-new or update of the form managed by this manager. 120 // Handles save-as-new or update of the form managed by this manager.
121 // Note the basic data of updated_credentials must match that of 121 // Note the basic data of updated_credentials must match that of
122 // observed_form_ (e.g DoesManage(pending_credentials_) == true). 122 // observed_form_ (e.g DoesManage(pending_credentials_) == true).
123 void Save(); 123 void Save();
124 124
125 // Call these if/when we know the form submission worked or failed. 125 // Call these if/when we know the form submission worked or failed.
126 // These routines are used to update internal statistics ("ActionsTaken"). 126 // These routines are used to update internal statistics ("ActionsTaken").
127 void SubmitPassed(); 127 void SubmitPassed();
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
175 kSubmitResultMax 175 kSubmitResultMax
176 }; 176 };
177 177
178 // The maximum number of combinations of the three preceding enums. 178 // The maximum number of combinations of the three preceding enums.
179 // This is used when recording the actions taken by the form in UMA. 179 // This is used when recording the actions taken by the form in UMA.
180 static const int kMaxNumActionsTaken = kManagerActionMax * kUserActionMax * 180 static const int kMaxNumActionsTaken = kManagerActionMax * kUserActionMax *
181 kSubmitResultMax; 181 kSubmitResultMax;
182 182
183 // Helper for OnPasswordStoreRequestDone to determine whether or not 183 // Helper for OnPasswordStoreRequestDone to determine whether or not
184 // the given result form is worth scoring. 184 // the given result form is worth scoring.
185 bool IgnoreResult(const content::PasswordForm& form) const; 185 bool IgnoreResult(const autofill::PasswordForm& form) const;
186 186
187 // Helper for Save in the case that best_matches.size() == 0, meaning 187 // Helper for Save in the case that best_matches.size() == 0, meaning
188 // we have no prior record of this form/username/password and the user 188 // we have no prior record of this form/username/password and the user
189 // has opted to 'Save Password'. If |reset_preferred_login| is set, 189 // has opted to 'Save Password'. If |reset_preferred_login| is set,
190 // the previously preferred login from |best_matches_| will be reset. 190 // the previously preferred login from |best_matches_| will be reset.
191 void SaveAsNewLogin(bool reset_preferred_login); 191 void SaveAsNewLogin(bool reset_preferred_login);
192 192
193 // Helper for OnPasswordStoreRequestDone to score an individual result 193 // Helper for OnPasswordStoreRequestDone to score an individual result
194 // against the observed_form_. 194 // against the observed_form_.
195 int ScoreResult(const content::PasswordForm& form) const; 195 int ScoreResult(const autofill::PasswordForm& form) const;
196 196
197 // Helper for Save in the case that best_matches.size() > 0, meaning 197 // Helper for Save in the case that best_matches.size() > 0, meaning
198 // we have at least one match for this form/username/password. This 198 // we have at least one match for this form/username/password. This
199 // Updates the form managed by this object, as well as any matching forms 199 // Updates the form managed by this object, as well as any matching forms
200 // that now need to have preferred bit changed, since updated_credentials 200 // that now need to have preferred bit changed, since updated_credentials
201 // is now implicitly 'preferred'. 201 // is now implicitly 'preferred'.
202 void UpdateLogin(); 202 void UpdateLogin();
203 203
204 // Update all login matches to reflect new preferred state - preferred flag 204 // Update all login matches to reflect new preferred state - preferred flag
205 // will be reset on all matched logins that different than the current 205 // will be reset on all matched logins that different than the current
(...skipping 10 matching lines...) Expand all
216 // UMA. 216 // UMA.
217 int GetActionsTaken(); 217 int GetActionsTaken();
218 218
219 // Informs the renderer that the user has not blacklisted observed_form_ by 219 // Informs the renderer that the user has not blacklisted observed_form_ by
220 // choosing "never save passwords for this site". This is used by the password 220 // choosing "never save passwords for this site". This is used by the password
221 // generation manager to deside whether to show the password generation icon. 221 // generation manager to deside whether to show the password generation icon.
222 virtual void SendNotBlacklistedToRenderer(); 222 virtual void SendNotBlacklistedToRenderer();
223 223
224 // Remove possible_usernames that may contains sensitive information and 224 // Remove possible_usernames that may contains sensitive information and
225 // duplicates. 225 // duplicates.
226 void SanitizePossibleUsernames(content::PasswordForm* form); 226 void SanitizePossibleUsernames(autofill::PasswordForm* form);
227 227
228 // Set of PasswordForms from the DB that best match the form 228 // Set of PasswordForms from the DB that best match the form
229 // being managed by this. Use a map instead of vector, because we most 229 // being managed by this. Use a map instead of vector, because we most
230 // frequently require lookups by username value in IsNewLogin. 230 // frequently require lookups by username value in IsNewLogin.
231 content::PasswordFormMap best_matches_; 231 autofill::PasswordFormMap best_matches_;
232 232
233 // Cleans up when best_matches_ goes out of scope. 233 // Cleans up when best_matches_ goes out of scope.
234 STLValueDeleter<content::PasswordFormMap> best_matches_deleter_; 234 STLValueDeleter<autofill::PasswordFormMap> best_matches_deleter_;
235 235
236 // The PasswordForm from the page or dialog managed by this. 236 // The PasswordForm from the page or dialog managed by this.
237 content::PasswordForm observed_form_; 237 autofill::PasswordForm observed_form_;
238 238
239 // The origin url path of observed_form_ tokenized, for convenience when 239 // The origin url path of observed_form_ tokenized, for convenience when
240 // scoring. 240 // scoring.
241 std::vector<std::string> form_path_tokens_; 241 std::vector<std::string> form_path_tokens_;
242 242
243 // Stores updated credentials when the form was submitted but success is 243 // Stores updated credentials when the form was submitted but success is
244 // still unknown. 244 // still unknown.
245 content::PasswordForm pending_credentials_; 245 autofill::PasswordForm pending_credentials_;
246 246
247 // Whether pending_credentials_ stores a new login or is an update 247 // Whether pending_credentials_ stores a new login or is an update
248 // to an existing one. 248 // to an existing one.
249 bool is_new_login_; 249 bool is_new_login_;
250 250
251 // Whether this form has an auto generated password. 251 // Whether this form has an auto generated password.
252 bool has_generated_password_; 252 bool has_generated_password_;
253 253
254 // Set if the user has selected one of the other possible usernames in 254 // Set if the user has selected one of the other possible usernames in
255 // |pending_credentials_|. 255 // |pending_credentials_|.
256 string16 selected_username_; 256 string16 selected_username_;
257 257
258 // PasswordManager owning this. 258 // PasswordManager owning this.
259 const PasswordManager* const password_manager_; 259 const PasswordManager* const password_manager_;
260 260
261 // Convenience pointer to entry in best_matches_ that is marked 261 // Convenience pointer to entry in best_matches_ that is marked
262 // as preferred. This is only allowed to be null if there are no best matches 262 // as preferred. This is only allowed to be null if there are no best matches
263 // at all, since there will always be one preferred login when there are 263 // at all, since there will always be one preferred login when there are
264 // multiple matches (when first saved, a login is marked preferred). 264 // multiple matches (when first saved, a login is marked preferred).
265 const content::PasswordForm* preferred_match_; 265 const autofill::PasswordForm* preferred_match_;
266 266
267 typedef enum { 267 typedef enum {
268 PRE_MATCHING_PHASE, // Have not yet invoked a GetLogins query to find 268 PRE_MATCHING_PHASE, // Have not yet invoked a GetLogins query to find
269 // matching login information from password store. 269 // matching login information from password store.
270 MATCHING_PHASE, // We've made a GetLogins request, but 270 MATCHING_PHASE, // We've made a GetLogins request, but
271 // haven't received or finished processing result. 271 // haven't received or finished processing result.
272 POST_MATCHING_PHASE // We've queried the DB and processed matching 272 POST_MATCHING_PHASE // We've queried the DB and processed matching
273 // login results. 273 // login results.
274 } PasswordFormManagerState; 274 } PasswordFormManagerState;
275 275
(...skipping 12 matching lines...) Expand all
288 // These three fields record the "ActionsTaken" by the browser and 288 // These three fields record the "ActionsTaken" by the browser and
289 // the user with this form, and the result. They are combined and 289 // the user with this form, and the result. They are combined and
290 // recorded in UMA when the manager is destroyed. 290 // recorded in UMA when the manager is destroyed.
291 ManagerAction manager_action_; 291 ManagerAction manager_action_;
292 UserAction user_action_; 292 UserAction user_action_;
293 SubmitResult submit_result_; 293 SubmitResult submit_result_;
294 294
295 DISALLOW_COPY_AND_ASSIGN(PasswordFormManager); 295 DISALLOW_COPY_AND_ASSIGN(PasswordFormManager);
296 }; 296 };
297 #endif // CHROME_BROWSER_PASSWORD_MANAGER_PASSWORD_FORM_MANAGER_H_ 297 #endif // CHROME_BROWSER_PASSWORD_MANAGER_PASSWORD_FORM_MANAGER_H_
OLDNEW
« no previous file with comments | « chrome/browser/password_manager/password_form_data.cc ('k') | chrome/browser/password_manager/password_form_manager.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698