| 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 COMPONENTS_PASSWORD_MANAGER_CORE_BROWSER_PASSWORD_MANAGER_H_ | 5 #ifndef COMPONENTS_PASSWORD_MANAGER_CORE_BROWSER_PASSWORD_MANAGER_H_ |
| 6 #define COMPONENTS_PASSWORD_MANAGER_CORE_BROWSER_PASSWORD_MANAGER_H_ | 6 #define COMPONENTS_PASSWORD_MANAGER_CORE_BROWSER_PASSWORD_MANAGER_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 56 void AddSubmissionCallback(const PasswordSubmittedCallback& callback); | 56 void AddSubmissionCallback(const PasswordSubmittedCallback& callback); |
| 57 | 57 |
| 58 // Is saving new data for password autofill enabled for the current profile | 58 // Is saving new data for password autofill enabled for the current profile |
| 59 // and page? For example, saving new data is disabled in Incognito mode, | 59 // and page? For example, saving new data is disabled in Incognito mode, |
| 60 // whereas filling data is not. Also, saving data is disabled in the presence | 60 // whereas filling data is not. Also, saving data is disabled in the presence |
| 61 // of SSL errors on a page. | 61 // of SSL errors on a page. |
| 62 bool IsSavingEnabledForCurrentPage() const; | 62 bool IsSavingEnabledForCurrentPage() const; |
| 63 | 63 |
| 64 // Called by a PasswordFormManager when it decides a form can be autofilled | 64 // Called by a PasswordFormManager when it decides a form can be autofilled |
| 65 // on the page. | 65 // on the page. |
| 66 virtual void Autofill(const autofill::PasswordForm& form_for_autofill, | 66 virtual void Autofill(password_manager::PasswordManagerDriver* driver, |
| 67 const autofill::PasswordForm& form_for_autofill, |
| 67 const autofill::PasswordFormMap& best_matches, | 68 const autofill::PasswordFormMap& best_matches, |
| 68 const autofill::PasswordForm& preferred_match, | 69 const autofill::PasswordForm& preferred_match, |
| 69 bool wait_for_username) const; | 70 bool wait_for_username) const; |
| 70 | 71 |
| 71 // LoginModel implementation. | 72 // LoginModel implementation. |
| 72 void AddObserver(LoginModelObserver* observer) override; | 73 void AddObserver(LoginModelObserver* observer) override; |
| 73 void RemoveObserver(LoginModelObserver* observer) override; | 74 void RemoveObserver(LoginModelObserver* observer) override; |
| 74 | 75 |
| 75 // Mark this form as having a generated password. | 76 // Mark this form as having a generated password. |
| 76 void SetFormHasGeneratedPassword(const autofill::PasswordForm& form); | 77 void SetFormHasGeneratedPassword( |
| 78 password_manager::PasswordManagerDriver* driver, |
| 79 const autofill::PasswordForm& form); |
| 77 | 80 |
| 78 // TODO(isherman): This should not be public, but is currently being used by | 81 // TODO(isherman): This should not be public, but is currently being used by |
| 79 // the LoginPrompt code. | 82 // the LoginPrompt code. |
| 80 // When a form is submitted, we prepare to save the password but wait | 83 // When a form is submitted, we prepare to save the password but wait |
| 81 // until we decide the user has successfully logged in. This is step 1 | 84 // until we decide the user has successfully logged in. This is step 1 |
| 82 // of 2 (see SavePassword). | 85 // of 2 (see SavePassword). |
| 83 void ProvisionallySavePassword(const autofill::PasswordForm& form); | 86 void ProvisionallySavePassword(const autofill::PasswordForm& form); |
| 84 | 87 |
| 85 // Should be called when the user navigates the main frame. | 88 // Should be called when the user navigates the main frame. |
| 86 void DidNavigateMainFrame(bool is_in_page); | 89 void DidNavigateMainFrame(bool is_in_page); |
| 87 | 90 |
| 88 // Handles password forms being parsed. | 91 // Handles password forms being parsed. |
| 89 void OnPasswordFormsParsed( | 92 void OnPasswordFormsParsed(password_manager::PasswordManagerDriver* driver, |
| 90 const std::vector<autofill::PasswordForm>& forms); | 93 const std::vector<autofill::PasswordForm>& forms); |
| 91 | 94 |
| 92 // Handles password forms being rendered. | 95 // Handles password forms being rendered. |
| 93 void OnPasswordFormsRendered( | 96 void OnPasswordFormsRendered( |
| 97 password_manager::PasswordManagerDriver* driver, |
| 94 const std::vector<autofill::PasswordForm>& visible_forms, | 98 const std::vector<autofill::PasswordForm>& visible_forms, |
| 95 bool did_stop_loading); | 99 bool did_stop_loading); |
| 96 | 100 |
| 97 // Handles a password form being submitted. | 101 // Handles a password form being submitted. |
| 98 virtual void OnPasswordFormSubmitted( | 102 virtual void OnPasswordFormSubmitted( |
| 103 password_manager::PasswordManagerDriver* driver, |
| 99 const autofill::PasswordForm& password_form); | 104 const autofill::PasswordForm& password_form); |
| 100 | 105 |
| 101 PasswordManagerClient* client() { return client_; } | 106 PasswordManagerClient* client() { return client_; } |
| 102 | 107 |
| 103 private: | 108 private: |
| 104 enum ProvisionalSaveFailure { | 109 enum ProvisionalSaveFailure { |
| 105 SAVING_DISABLED, | 110 SAVING_DISABLED, |
| 106 EMPTY_PASSWORD, | 111 EMPTY_PASSWORD, |
| 107 NO_MATCHING_FORM, | 112 NO_MATCHING_FORM, |
| 108 MATCHING_NOT_COMPLETE, | 113 MATCHING_NOT_COMPLETE, |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 140 | 145 |
| 141 // Returns true if the user needs to be prompted before a password can be | 146 // Returns true if the user needs to be prompted before a password can be |
| 142 // saved (instead of automatically saving | 147 // saved (instead of automatically saving |
| 143 // the password), based on inspecting the state of | 148 // the password), based on inspecting the state of |
| 144 // |provisional_save_manager_|. | 149 // |provisional_save_manager_|. |
| 145 bool ShouldPromptUserToSavePassword() const; | 150 bool ShouldPromptUserToSavePassword() const; |
| 146 | 151 |
| 147 // Checks for every from in |forms| whether |pending_login_managers_| already | 152 // Checks for every from in |forms| whether |pending_login_managers_| already |
| 148 // contain a manager for that form. If not, adds a manager for each such form. | 153 // contain a manager for that form. If not, adds a manager for each such form. |
| 149 void CreatePendingLoginManagers( | 154 void CreatePendingLoginManagers( |
| 155 password_manager::PasswordManagerDriver* driver, |
| 150 const std::vector<autofill::PasswordForm>& forms); | 156 const std::vector<autofill::PasswordForm>& forms); |
| 151 | 157 |
| 152 // Note about how a PasswordFormManager can transition from | 158 // Note about how a PasswordFormManager can transition from |
| 153 // pending_login_managers_ to provisional_save_manager_ and the infobar. | 159 // pending_login_managers_ to provisional_save_manager_ and the infobar. |
| 154 // | 160 // |
| 155 // 1. form "seen" | 161 // 1. form "seen" |
| 156 // | new | 162 // | new |
| 157 // | ___ Infobar | 163 // | ___ Infobar |
| 158 // pending_login -- form submit --> provisional_save ___/ | 164 // pending_login -- form submit --> provisional_save ___/ |
| 159 // ^ | \___ (update DB) | 165 // ^ | \___ (update DB) |
| 160 // | fail | 166 // | fail |
| 161 // |-----------<------<---------| !new | 167 // |-----------<------<---------| !new |
| 162 // | 168 // |
| 163 // When a form is "seen" on a page, a PasswordFormManager is created | 169 // When a form is "seen" on a page, a PasswordFormManager is created |
| 164 // and stored in this collection until user navigates away from page. | 170 // and stored in this collection until user navigates away from page. |
| 165 | 171 |
| 166 ScopedVector<PasswordFormManager> pending_login_managers_; | 172 ScopedVector<PasswordFormManager> pending_login_managers_; |
| 167 | 173 |
| 168 // When the user submits a password/credential, this contains the | 174 // When the user submits a password/credential, this contains the |
| 169 // PasswordFormManager for the form in question until we deem the login | 175 // PasswordFormManager for the form in question until we deem the login |
| 170 // attempt to have succeeded (as in valid credentials). If it fails, we | 176 // attempt to have succeeded (as in valid credentials). If it fails, we |
| 171 // send the PasswordFormManager back to the pending_login_managers_ set. | 177 // send the PasswordFormManager back to the pending_login_managers_ set. |
| 172 // Scoped in case PasswordManager gets deleted (e.g tab closes) between the | 178 // Scoped in case PasswordManager gets deleted (e.g tab closes) between the |
| 173 // time a user submits a login form and gets to the next page. | 179 // time a user submits a login form and gets to the next page. |
| 174 scoped_ptr<PasswordFormManager> provisional_save_manager_; | 180 scoped_ptr<PasswordFormManager> provisional_save_manager_; |
| 175 | 181 |
| 176 // The embedder-level client. Must outlive this class. | 182 // The embedder-level client. Must outlive this class. |
| 177 PasswordManagerClient* const client_; | 183 PasswordManagerClient* const client_; |
| 178 | 184 |
| 179 // The platform-level driver. Must outlive this class. | |
| 180 PasswordManagerDriver* const driver_; | |
| 181 | |
| 182 // Set to false to disable password saving (will no longer ask if you | 185 // Set to false to disable password saving (will no longer ask if you |
| 183 // want to save passwords but will continue to fill passwords). | 186 // want to save passwords but will continue to fill passwords). |
| 184 BooleanPrefMember saving_passwords_enabled_; | 187 BooleanPrefMember saving_passwords_enabled_; |
| 185 | 188 |
| 186 // Observers to be notified of LoginModel events. This is mutable to allow | 189 // Observers to be notified of LoginModel events. This is mutable to allow |
| 187 // notification in const member functions. | 190 // notification in const member functions. |
| 188 mutable ObserverList<LoginModelObserver> observers_; | 191 mutable ObserverList<LoginModelObserver> observers_; |
| 189 | 192 |
| 190 // Callbacks to be notified when a password form has been submitted. | 193 // Callbacks to be notified when a password form has been submitted. |
| 191 std::vector<PasswordSubmittedCallback> submission_callbacks_; | 194 std::vector<PasswordSubmittedCallback> submission_callbacks_; |
| 192 | 195 |
| 193 // Records all visible forms seen during a page load, in all frames of the | 196 // Records all visible forms seen during a page load, in all frames of the |
| 194 // page. When the page stops loading, the password manager checks if one of | 197 // page. When the page stops loading, the password manager checks if one of |
| 195 // the recorded forms matches the login form from the previous page | 198 // the recorded forms matches the login form from the previous page |
| 196 // (to see if the login was a failure), and clears the vector. | 199 // (to see if the login was a failure), and clears the vector. |
| 197 std::vector<autofill::PasswordForm> all_visible_forms_; | 200 std::vector<autofill::PasswordForm> all_visible_forms_; |
| 198 | 201 |
| 199 DISALLOW_COPY_AND_ASSIGN(PasswordManager); | 202 DISALLOW_COPY_AND_ASSIGN(PasswordManager); |
| 200 }; | 203 }; |
| 201 | 204 |
| 202 } // namespace password_manager | 205 } // namespace password_manager |
| 203 | 206 |
| 204 #endif // COMPONENTS_PASSWORD_MANAGER_CORE_BROWSER_PASSWORD_MANAGER_H_ | 207 #endif // COMPONENTS_PASSWORD_MANAGER_CORE_BROWSER_PASSWORD_MANAGER_H_ |
| OLD | NEW |