| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include <string> | 9 #include <string> |
| 10 #include <vector> | 10 #include <vector> |
| 11 | 11 |
| 12 #include "build/build_config.h" | 12 #include "build/build_config.h" |
| 13 | 13 |
| 14 #include "base/stl_util.h" | 14 #include "base/stl_util.h" |
| 15 #include "chrome/browser/password_manager/password_store_consumer.h" | 15 #include "chrome/browser/password_manager/password_store_consumer.h" |
| 16 #include "webkit/glue/password_form.h" | 16 #include "webkit/forms/password_form.h" |
| 17 | 17 |
| 18 class PasswordManager; | 18 class PasswordManager; |
| 19 class PasswordStore; | 19 class PasswordStore; |
| 20 class Profile; | 20 class Profile; |
| 21 | 21 |
| 22 // Per-password-form-{on-page, dialog} class responsible for interactions | 22 // Per-password-form-{on-page, dialog} class responsible for interactions |
| 23 // between a given form, the per-tab PasswordManager, and the PasswordStore. | 23 // between a given form, the per-tab PasswordManager, and the PasswordStore. |
| 24 class PasswordFormManager : public PasswordStoreConsumer { | 24 class PasswordFormManager : public PasswordStoreConsumer { |
| 25 public: | 25 public: |
| 26 // profile contains the link to the PasswordStore and whether we're off | 26 // profile contains the link to the PasswordStore and whether we're off |
| 27 // the record | 27 // the record |
| 28 // password_manager owns this object | 28 // password_manager owns this object |
| 29 // form_on_page is the form that may be submitted and could need login data. | 29 // form_on_page is the form that may be submitted and could need login data. |
| 30 // ssl_valid represents the security of the page containing observed_form, | 30 // ssl_valid represents the security of the page containing observed_form, |
| 31 // used to filter login results from database. | 31 // used to filter login results from database. |
| 32 PasswordFormManager(Profile* profile, | 32 PasswordFormManager(Profile* profile, |
| 33 PasswordManager* password_manager, | 33 PasswordManager* password_manager, |
| 34 const webkit_glue::PasswordForm& observed_form, | 34 const webkit::forms::PasswordForm& observed_form, |
| 35 bool ssl_valid); | 35 bool ssl_valid); |
| 36 virtual ~PasswordFormManager(); | 36 virtual ~PasswordFormManager(); |
| 37 | 37 |
| 38 // Compare basic data of observed_form_ with argument. | 38 // Compare basic data of observed_form_ with argument. |
| 39 bool DoesManage(const webkit_glue::PasswordForm& form) const; | 39 bool DoesManage(const webkit::forms::PasswordForm& form) const; |
| 40 | 40 |
| 41 // Retrieves potential matching logins from the database. | 41 // Retrieves potential matching logins from the database. |
| 42 void FetchMatchingLoginsFromPasswordStore(); | 42 void FetchMatchingLoginsFromPasswordStore(); |
| 43 | 43 |
| 44 // Simple state-check to verify whether this object as received a callback | 44 // Simple state-check to verify whether this object as received a callback |
| 45 // from the PasswordStore and completed its matching phase. Note that the | 45 // from the PasswordStore and completed its matching phase. Note that the |
| 46 // callback in question occurs on the same (and only) main thread from which | 46 // callback in question occurs on the same (and only) main thread from which |
| 47 // instances of this class are ever used, but it is required since it is | 47 // instances of this class are ever used, but it is required since it is |
| 48 // conceivable that a user (or ui test) could attempt to submit a login | 48 // conceivable that a user (or ui test) could attempt to submit a login |
| 49 // prompt before the callback has occured, which would InvokeLater a call to | 49 // prompt before the callback has occured, which would InvokeLater a call to |
| (...skipping 12 matching lines...) Expand all Loading... |
| 62 // a SavePasswordBar when given the green light to save the PasswordForm | 62 // a SavePasswordBar when given the green light to save the PasswordForm |
| 63 // managed by this. | 63 // managed by this. |
| 64 bool IsNewLogin(); | 64 bool IsNewLogin(); |
| 65 | 65 |
| 66 // Checks if the form is a valid password form. Forms which lack either | 66 // Checks if the form is a valid password form. Forms which lack either |
| 67 // login or password field are not considered valid. | 67 // login or password field are not considered valid. |
| 68 bool HasValidPasswordForm(); | 68 bool HasValidPasswordForm(); |
| 69 | 69 |
| 70 // Determines if we need to autofill given the results of the query. | 70 // Determines if we need to autofill given the results of the query. |
| 71 void OnRequestDone( | 71 void OnRequestDone( |
| 72 int handle, const std::vector<webkit_glue::PasswordForm*>& result); | 72 int handle, const std::vector<webkit::forms::PasswordForm*>& result); |
| 73 | 73 |
| 74 // PasswordStoreConsumer implementation. | 74 // PasswordStoreConsumer implementation. |
| 75 virtual void OnPasswordStoreRequestDone( | 75 virtual void OnPasswordStoreRequestDone( |
| 76 CancelableRequestProvider::Handle handle, | 76 CancelableRequestProvider::Handle handle, |
| 77 const std::vector<webkit_glue::PasswordForm*>& result) OVERRIDE; | 77 const std::vector<webkit::forms::PasswordForm*>& result) OVERRIDE; |
| 78 | 78 |
| 79 // A user opted to 'never remember' passwords for this form. | 79 // A user opted to 'never remember' passwords for this form. |
| 80 // Blacklist it so that from now on when it is seen we ignore it. | 80 // Blacklist it so that from now on when it is seen we ignore it. |
| 81 void PermanentlyBlacklist(); | 81 void PermanentlyBlacklist(); |
| 82 | 82 |
| 83 // If the user has submitted observed_form_, provisionally hold on to | 83 // If the user has submitted observed_form_, provisionally hold on to |
| 84 // the submitted credentials until we are told by PasswordManager whether | 84 // the submitted credentials until we are told by PasswordManager whether |
| 85 // or not the login was successful. | 85 // or not the login was successful. |
| 86 void ProvisionallySave(const webkit_glue::PasswordForm& credentials); | 86 void ProvisionallySave(const webkit::forms::PasswordForm& credentials); |
| 87 | 87 |
| 88 // Handles save-as-new or update of the form managed by this manager. | 88 // Handles save-as-new or update of the form managed by this manager. |
| 89 // Note the basic data of updated_credentials must match that of | 89 // Note the basic data of updated_credentials must match that of |
| 90 // observed_form_ (e.g DoesManage(pending_credentials_) == true). | 90 // observed_form_ (e.g DoesManage(pending_credentials_) == true). |
| 91 void Save(); | 91 void Save(); |
| 92 | 92 |
| 93 // Call these if/when we know the form submission worked or failed. | 93 // Call these if/when we know the form submission worked or failed. |
| 94 // These routines are used to update internal statistics ("ActionsTaken"). | 94 // These routines are used to update internal statistics ("ActionsTaken"). |
| 95 void SubmitPassed(); | 95 void SubmitPassed(); |
| 96 void SubmitFailed(); | 96 void SubmitFailed(); |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 133 kSubmitResultMax | 133 kSubmitResultMax |
| 134 }; | 134 }; |
| 135 | 135 |
| 136 // The maximum number of combinations of the three preceding enums. | 136 // The maximum number of combinations of the three preceding enums. |
| 137 // This is used when recording the actions taken by the form in UMA. | 137 // This is used when recording the actions taken by the form in UMA. |
| 138 static const int kMaxNumActionsTaken = kManagerActionMax * kUserActionMax * | 138 static const int kMaxNumActionsTaken = kManagerActionMax * kUserActionMax * |
| 139 kSubmitResultMax; | 139 kSubmitResultMax; |
| 140 | 140 |
| 141 // Helper for OnPasswordStoreRequestDone to determine whether or not | 141 // Helper for OnPasswordStoreRequestDone to determine whether or not |
| 142 // the given result form is worth scoring. | 142 // the given result form is worth scoring. |
| 143 bool IgnoreResult(const webkit_glue::PasswordForm& form) const; | 143 bool IgnoreResult(const webkit::forms::PasswordForm& form) const; |
| 144 | 144 |
| 145 // Helper for Save in the case that best_matches.size() == 0, meaning | 145 // Helper for Save in the case that best_matches.size() == 0, meaning |
| 146 // we have no prior record of this form/username/password and the user | 146 // we have no prior record of this form/username/password and the user |
| 147 // has opted to 'Save Password'. If |reset_preferred_login| is set, | 147 // has opted to 'Save Password'. If |reset_preferred_login| is set, |
| 148 // the previously preferred login from |best_matches_| will be reset. | 148 // the previously preferred login from |best_matches_| will be reset. |
| 149 void SaveAsNewLogin(bool reset_preferred_login); | 149 void SaveAsNewLogin(bool reset_preferred_login); |
| 150 | 150 |
| 151 // Helper for OnPasswordStoreRequestDone to score an individual result | 151 // Helper for OnPasswordStoreRequestDone to score an individual result |
| 152 // against the observed_form_. | 152 // against the observed_form_. |
| 153 int ScoreResult(const webkit_glue::PasswordForm& form) const; | 153 int ScoreResult(const webkit::forms::PasswordForm& form) const; |
| 154 | 154 |
| 155 // Helper for Save in the case that best_matches.size() > 0, meaning | 155 // Helper for Save in the case that best_matches.size() > 0, meaning |
| 156 // we have at least one match for this form/username/password. This | 156 // we have at least one match for this form/username/password. This |
| 157 // Updates the form managed by this object, as well as any matching forms | 157 // Updates the form managed by this object, as well as any matching forms |
| 158 // that now need to have preferred bit changed, since updated_credentials | 158 // that now need to have preferred bit changed, since updated_credentials |
| 159 // is now implicitly 'preferred'. | 159 // is now implicitly 'preferred'. |
| 160 void UpdateLogin(); | 160 void UpdateLogin(); |
| 161 | 161 |
| 162 // Update all login matches to reflect new preferred state - preferred flag | 162 // Update all login matches to reflect new preferred state - preferred flag |
| 163 // will be reset on all matched logins that different than the current | 163 // will be reset on all matched logins that different than the current |
| 164 // |pending_credentials_|. | 164 // |pending_credentials_|. |
| 165 void UpdatePreferredLoginState(PasswordStore* password_store); | 165 void UpdatePreferredLoginState(PasswordStore* password_store); |
| 166 | 166 |
| 167 // Converts the "ActionsTaken" fields into an int so they can be logged to | 167 // Converts the "ActionsTaken" fields into an int so they can be logged to |
| 168 // UMA. | 168 // UMA. |
| 169 int GetActionsTaken(); | 169 int GetActionsTaken(); |
| 170 | 170 |
| 171 // Set of PasswordForms from the DB that best match the form | 171 // Set of PasswordForms from the DB that best match the form |
| 172 // being managed by this. Use a map instead of vector, because we most | 172 // being managed by this. Use a map instead of vector, because we most |
| 173 // frequently require lookups by username value in IsNewLogin. | 173 // frequently require lookups by username value in IsNewLogin. |
| 174 webkit_glue::PasswordFormMap best_matches_; | 174 webkit::forms::PasswordFormMap best_matches_; |
| 175 | 175 |
| 176 // Cleans up when best_matches_ goes out of scope. | 176 // Cleans up when best_matches_ goes out of scope. |
| 177 STLValueDeleter<webkit_glue::PasswordFormMap> best_matches_deleter_; | 177 STLValueDeleter<webkit::forms::PasswordFormMap> best_matches_deleter_; |
| 178 | 178 |
| 179 // The PasswordForm from the page or dialog managed by this. | 179 // The PasswordForm from the page or dialog managed by this. |
| 180 webkit_glue::PasswordForm observed_form_; | 180 webkit::forms::PasswordForm observed_form_; |
| 181 | 181 |
| 182 // The origin url path of observed_form_ tokenized, for convenience when | 182 // The origin url path of observed_form_ tokenized, for convenience when |
| 183 // scoring. | 183 // scoring. |
| 184 std::vector<std::string> form_path_tokens_; | 184 std::vector<std::string> form_path_tokens_; |
| 185 | 185 |
| 186 // Stores updated credentials when the form was submitted but success is | 186 // Stores updated credentials when the form was submitted but success is |
| 187 // still unknown. | 187 // still unknown. |
| 188 webkit_glue::PasswordForm pending_credentials_; | 188 webkit::forms::PasswordForm pending_credentials_; |
| 189 | 189 |
| 190 // Whether pending_credentials_ stores a new login or is an update | 190 // Whether pending_credentials_ stores a new login or is an update |
| 191 // to an existing one. | 191 // to an existing one. |
| 192 bool is_new_login_; | 192 bool is_new_login_; |
| 193 | 193 |
| 194 // PasswordManager owning this. | 194 // PasswordManager owning this. |
| 195 const PasswordManager* const password_manager_; | 195 const PasswordManager* const password_manager_; |
| 196 | 196 |
| 197 // Handle to any pending PasswordStore::GetLogins query. | 197 // Handle to any pending PasswordStore::GetLogins query. |
| 198 CancelableRequestProvider::Handle pending_login_query_; | 198 CancelableRequestProvider::Handle pending_login_query_; |
| 199 | 199 |
| 200 // Convenience pointer to entry in best_matches_ that is marked | 200 // Convenience pointer to entry in best_matches_ that is marked |
| 201 // as preferred. This is only allowed to be null if there are no best matches | 201 // as preferred. This is only allowed to be null if there are no best matches |
| 202 // at all, since there will always be one preferred login when there are | 202 // at all, since there will always be one preferred login when there are |
| 203 // multiple matches (when first saved, a login is marked preferred). | 203 // multiple matches (when first saved, a login is marked preferred). |
| 204 const webkit_glue::PasswordForm* preferred_match_; | 204 const webkit::forms::PasswordForm* preferred_match_; |
| 205 | 205 |
| 206 typedef enum { | 206 typedef enum { |
| 207 PRE_MATCHING_PHASE, // Have not yet invoked a GetLogins query to find | 207 PRE_MATCHING_PHASE, // Have not yet invoked a GetLogins query to find |
| 208 // matching login information from password store. | 208 // matching login information from password store. |
| 209 MATCHING_PHASE, // We've made a GetLogins request, but | 209 MATCHING_PHASE, // We've made a GetLogins request, but |
| 210 // haven't received or finished processing result. | 210 // haven't received or finished processing result. |
| 211 POST_MATCHING_PHASE // We've queried the DB and processed matching | 211 POST_MATCHING_PHASE // We've queried the DB and processed matching |
| 212 // login results. | 212 // login results. |
| 213 } PasswordFormManagerState; | 213 } PasswordFormManagerState; |
| 214 | 214 |
| 215 // State of matching process, used to verify that we don't call methods | 215 // State of matching process, used to verify that we don't call methods |
| 216 // assuming we've already processed the request for matching logins, | 216 // assuming we've already processed the request for matching logins, |
| 217 // when we actually haven't. | 217 // when we actually haven't. |
| 218 PasswordFormManagerState state_; | 218 PasswordFormManagerState state_; |
| 219 | 219 |
| 220 // The profile from which we get the PasswordStore. | 220 // The profile from which we get the PasswordStore. |
| 221 Profile* profile_; | 221 Profile* profile_; |
| 222 | 222 |
| 223 // These three fields record the "ActionsTaken" by the browser and | 223 // These three fields record the "ActionsTaken" by the browser and |
| 224 // the user with this form, and the result. They are combined and | 224 // the user with this form, and the result. They are combined and |
| 225 // recorded in UMA when the manager is destroyed. | 225 // recorded in UMA when the manager is destroyed. |
| 226 ManagerAction manager_action_; | 226 ManagerAction manager_action_; |
| 227 UserAction user_action_; | 227 UserAction user_action_; |
| 228 SubmitResult submit_result_; | 228 SubmitResult submit_result_; |
| 229 | 229 |
| 230 DISALLOW_COPY_AND_ASSIGN(PasswordFormManager); | 230 DISALLOW_COPY_AND_ASSIGN(PasswordFormManager); |
| 231 }; | 231 }; |
| 232 #endif // CHROME_BROWSER_PASSWORD_MANAGER_PASSWORD_FORM_MANAGER_H_ | 232 #endif // CHROME_BROWSER_PASSWORD_MANAGER_PASSWORD_FORM_MANAGER_H_ |
| OLD | NEW |