Chromium Code Reviews| 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_MANAGER_H_ | 5 #ifndef CHROME_BROWSER_PASSWORD_MANAGER_PASSWORD_MANAGER_H_ |
| 6 #define CHROME_BROWSER_PASSWORD_MANAGER_PASSWORD_MANAGER_H_ | 6 #define CHROME_BROWSER_PASSWORD_MANAGER_PASSWORD_MANAGER_H_ |
| 7 | 7 |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 35 public content::WebContentsObserver, | 35 public content::WebContentsObserver, |
| 36 public content::WebContentsUserData<PasswordManager> { | 36 public content::WebContentsUserData<PasswordManager> { |
| 37 public: | 37 public: |
| 38 static void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry); | 38 static void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry); |
| 39 | 39 |
| 40 static void CreateForWebContentsAndDelegate( | 40 static void CreateForWebContentsAndDelegate( |
| 41 content::WebContents* contents, | 41 content::WebContents* contents, |
| 42 PasswordManagerDelegate* delegate); | 42 PasswordManagerDelegate* delegate); |
| 43 virtual ~PasswordManager(); | 43 virtual ~PasswordManager(); |
| 44 | 44 |
| 45 // Class that will be notified when a password form has been submitted. | |
| 46 class SubmissionObserver { | |
| 47 public: | |
| 48 virtual void PasswordSubmitted(const content::PasswordForm& form) = 0; | |
|
jam
2013/07/25 17:31:33
it's best to avoid single-method interfaces, you c
Garrett Casto
2013/07/25 20:00:01
Done.
| |
| 49 | |
| 50 protected: | |
| 51 virtual ~SubmissionObserver() {} | |
| 52 }; | |
| 53 | |
| 54 // There is no corresponding remove function, as currently all of the | |
| 55 // SubmissionObservers have the same lifetime as the PasswordManager. | |
| 56 void AddSubmissionObserver(SubmissionObserver* observer); | |
| 57 | |
| 45 // 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? |
| 46 // For example, saving new data is disabled in Incognito mode, whereas filling | 59 // For example, saving new data is disabled in Incognito mode, whereas filling |
| 47 // data is not. | 60 // data is not. |
| 48 bool IsSavingEnabled() const; | 61 bool IsSavingEnabled() const; |
| 49 | 62 |
| 50 // Called by a PasswordFormManager when it decides a form can be autofilled | 63 // Called by a PasswordFormManager when it decides a form can be autofilled |
| 51 // on the page. | 64 // on the page. |
| 52 virtual void Autofill(const content::PasswordForm& form_for_autofill, | 65 virtual void Autofill(const content::PasswordForm& form_for_autofill, |
| 53 const content::PasswordFormMap& best_matches, | 66 const content::PasswordFormMap& best_matches, |
| 54 const content::PasswordForm& preferred_match, | 67 const content::PasswordForm& preferred_match, |
| 55 bool wait_for_username) const; | 68 bool wait_for_username) const; |
| 56 | 69 |
| 57 // LoginModel implementation. | 70 // LoginModel implementation. |
| 58 virtual void AddObserver(LoginModelObserver* observer) OVERRIDE; | 71 virtual void AddObserver(LoginModelObserver* observer) OVERRIDE; |
| 59 virtual void RemoveObserver(LoginModelObserver* observer) OVERRIDE; | 72 virtual void RemoveObserver(LoginModelObserver* observer) OVERRIDE; |
| 60 | 73 |
| 61 // Mark this form as having a generated password. | 74 // Mark this form as having a generated password. |
| 62 void SetFormHasGeneratedPassword(const content::PasswordForm& form); | 75 void SetFormHasGeneratedPassword(const content::PasswordForm& form); |
| 63 | 76 |
| 64 // TODO(isherman): This should not be public, but is currently being used by | 77 // TODO(isherman): This should not be public, but is currently being used by |
| 65 // the LoginPrompt code. | 78 // the LoginPrompt code. |
| 66 // When a form is submitted, we prepare to save the password but wait | 79 // When a form is submitted, we prepare to save the password but wait |
| 67 // until we decide the user has successfully logged in. This is step 1 | 80 // until we decide the user has successfully logged in. This is step 1 |
| 68 // of 2 (see SavePassword). | 81 // of 2 (see SavePassword). |
| 69 void ProvisionallySavePassword(const content::PasswordForm& form); | 82 void ProvisionallySavePassword(const content::PasswordForm& form); |
| 70 | 83 |
| 71 // content::WebContentsObserver overrides. | 84 // content::WebContentsObserver overrides. |
| 72 virtual void DidNavigateAnyFrame( | 85 virtual void DidNavigateMainFrame( |
| 73 const content::LoadCommittedDetails& details, | 86 const content::LoadCommittedDetails& details, |
| 74 const content::FrameNavigateParams& params) OVERRIDE; | 87 const content::FrameNavigateParams& params) OVERRIDE; |
| 75 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; | 88 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; |
| 76 | 89 |
| 77 // TODO(isherman): This should not be public, but is currently being used by | 90 // TODO(isherman): This should not be public, but is currently being used by |
| 78 // the LoginPrompt code. | 91 // the LoginPrompt code. |
| 79 void OnPasswordFormsParsed( | 92 void OnPasswordFormsParsed( |
| 80 const std::vector<content::PasswordForm>& forms); | 93 const std::vector<content::PasswordForm>& forms); |
| 81 void OnPasswordFormsRendered( | 94 void OnPasswordFormsRendered( |
| 82 const std::vector<content::PasswordForm>& visible_forms); | 95 const std::vector<content::PasswordForm>& visible_forms); |
| 83 | 96 |
| 84 protected: | 97 protected: |
| 85 // Subclassed for unit tests. | 98 // Subclassed for unit tests. |
| 86 PasswordManager(content::WebContents* web_contents, | 99 PasswordManager(content::WebContents* web_contents, |
| 87 PasswordManagerDelegate* delegate); | 100 PasswordManagerDelegate* delegate); |
| 88 | 101 |
| 89 private: | 102 private: |
| 90 friend class content::WebContentsUserData<PasswordManager>; | 103 friend class content::WebContentsUserData<PasswordManager>; |
| 104 friend class PasswordManagerTest; | |
| 105 | |
| 106 // Handle notification that a password form was submitted. | |
| 107 void OnPasswordFormSubmitted(const content::PasswordForm& password_form); | |
| 91 | 108 |
| 92 // Possibly set up FieldTrial for testing other possible usernames. This only | 109 // Possibly set up FieldTrial for testing other possible usernames. This only |
| 93 // happens if there are other_possible_usernames to be shown and the | 110 // happens if there are other_possible_usernames to be shown and the |
| 94 // experiment hasn't already been initialized. We setup the experiment at | 111 // experiment hasn't already been initialized. We setup the experiment at |
| 95 // such a late time because this experiment will only affect a small number | 112 // such a late time because this experiment will only affect a small number |
| 96 // of users so we want to include a larger fraction of these users than the | 113 // of users so we want to include a larger fraction of these users than the |
| 97 // normal 10%. | 114 // normal 10%. |
| 98 void PossiblyInitializeUsernamesExperiment( | 115 void PossiblyInitializeUsernamesExperiment( |
| 99 const content::PasswordFormMap& matches) const; | 116 const content::PasswordFormMap& matches) const; |
| 100 | 117 |
| (...skipping 26 matching lines...) Expand all Loading... | |
| 127 // attempt to have succeeded (as in valid credentials). If it fails, we | 144 // attempt to have succeeded (as in valid credentials). If it fails, we |
| 128 // send the PasswordFormManager back to the pending_login_managers_ set. | 145 // send the PasswordFormManager back to the pending_login_managers_ set. |
| 129 // Scoped in case PasswordManager gets deleted (e.g tab closes) between the | 146 // Scoped in case PasswordManager gets deleted (e.g tab closes) between the |
| 130 // time a user submits a login form and gets to the next page. | 147 // time a user submits a login form and gets to the next page. |
| 131 scoped_ptr<PasswordFormManager> provisional_save_manager_; | 148 scoped_ptr<PasswordFormManager> provisional_save_manager_; |
| 132 | 149 |
| 133 // Our delegate for carrying out external operations. This is typically the | 150 // Our delegate for carrying out external operations. This is typically the |
| 134 // containing WebContents. | 151 // containing WebContents. |
| 135 PasswordManagerDelegate* const delegate_; | 152 PasswordManagerDelegate* const delegate_; |
| 136 | 153 |
| 137 // The LoginModelObserver (i.e LoginView) requiring autofill. | |
| 138 LoginModelObserver* observer_; | |
| 139 | |
| 140 // Set to false to disable the password manager (will no longer ask if you | 154 // Set to false to disable the password manager (will no longer ask if you |
| 141 // want to save passwords but will continue to fill passwords). | 155 // want to save passwords but will continue to fill passwords). |
| 142 BooleanPrefMember password_manager_enabled_; | 156 BooleanPrefMember password_manager_enabled_; |
| 143 | 157 |
| 144 // Observers to be notified of LoginModel events. This is mutable to allow | 158 // Observers to be notified of LoginModel events. This is mutable to allow |
| 145 // notification in const member functions. | 159 // notification in const member functions. |
| 146 mutable ObserverList<LoginModelObserver> observers_; | 160 mutable ObserverList<LoginModelObserver> observers_; |
| 147 | 161 |
| 162 // Observers that wish to be notified when a password form has been submitted. | |
| 163 ObserverList<SubmissionObserver> submission_observers_; | |
| 164 | |
| 148 DISALLOW_COPY_AND_ASSIGN(PasswordManager); | 165 DISALLOW_COPY_AND_ASSIGN(PasswordManager); |
| 149 }; | 166 }; |
| 150 | 167 |
| 151 #endif // CHROME_BROWSER_PASSWORD_MANAGER_PASSWORD_MANAGER_H_ | 168 #endif // CHROME_BROWSER_PASSWORD_MANAGER_PASSWORD_MANAGER_H_ |
| OLD | NEW |