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/callback.h" | |
| 10 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
| 11 #include "base/memory/scoped_vector.h" | 12 #include "base/memory/scoped_vector.h" |
| 12 #include "base/observer_list.h" | 13 #include "base/observer_list.h" |
| 13 #include "base/prefs/pref_member.h" | 14 #include "base/prefs/pref_member.h" |
| 14 #include "base/stl_util.h" | 15 #include "base/stl_util.h" |
| 15 #include "chrome/browser/password_manager/password_form_manager.h" | 16 #include "chrome/browser/password_manager/password_form_manager.h" |
| 16 #include "chrome/browser/ui/login/login_model.h" | 17 #include "chrome/browser/ui/login/login_model.h" |
| 17 #include "components/autofill/core/common/password_form_fill_data.h" | 18 #include "components/autofill/core/common/password_form_fill_data.h" |
| 18 #include "content/public/browser/web_contents_observer.h" | 19 #include "content/public/browser/web_contents_observer.h" |
| 19 #include "content/public/browser/web_contents_user_data.h" | 20 #include "content/public/browser/web_contents_user_data.h" |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 35 public content::WebContentsObserver, | 36 public content::WebContentsObserver, |
| 36 public content::WebContentsUserData<PasswordManager> { | 37 public content::WebContentsUserData<PasswordManager> { |
| 37 public: | 38 public: |
| 38 static void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry); | 39 static void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry); |
| 39 | 40 |
| 40 static void CreateForWebContentsAndDelegate( | 41 static void CreateForWebContentsAndDelegate( |
| 41 content::WebContents* contents, | 42 content::WebContents* contents, |
| 42 PasswordManagerDelegate* delegate); | 43 PasswordManagerDelegate* delegate); |
| 43 virtual ~PasswordManager(); | 44 virtual ~PasswordManager(); |
| 44 | 45 |
| 46 typedef base::Callback<void(const content::PasswordForm&)> | |
| 47 PasswordSubmittedCallback; | |
|
Ilya Sherman
2013/07/27 01:09:48
nit: Please indent four more spaces.
Garrett Casto
2013/08/03 00:38:42
Done.
| |
| 48 | |
| 49 // There is no corresponding remove function as currently all of the | |
| 50 // owners of these callbacks have the same lifetime as the PasswordManager. | |
|
Ilya Sherman
2013/07/27 01:09:48
That's not entirely accurate -- there is some orde
Garrett Casto
2013/08/03 00:38:42
I tried to clear this comment up a bit. Not sure i
| |
| 51 void AddSubmissionCallback(const PasswordSubmittedCallback& callback); | |
|
Ilya Sherman
2013/07/27 01:09:48
Could you add some test coverage for these callbac
Garrett Casto
2013/08/03 00:38:42
Done.
| |
| 52 | |
| 45 // Is saving new data for password autofill enabled for the current profile? | 53 // 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 | 54 // For example, saving new data is disabled in Incognito mode, whereas filling |
| 47 // data is not. | 55 // data is not. |
| 48 bool IsSavingEnabled() const; | 56 bool IsSavingEnabled() const; |
| 49 | 57 |
| 50 // Called by a PasswordFormManager when it decides a form can be autofilled | 58 // Called by a PasswordFormManager when it decides a form can be autofilled |
| 51 // on the page. | 59 // on the page. |
| 52 virtual void Autofill(const content::PasswordForm& form_for_autofill, | 60 virtual void Autofill(const content::PasswordForm& form_for_autofill, |
| 53 const content::PasswordFormMap& best_matches, | 61 const content::PasswordFormMap& best_matches, |
| 54 const content::PasswordForm& preferred_match, | 62 const content::PasswordForm& preferred_match, |
| 55 bool wait_for_username) const; | 63 bool wait_for_username) const; |
| 56 | 64 |
| 57 // LoginModel implementation. | 65 // LoginModel implementation. |
| 58 virtual void AddObserver(LoginModelObserver* observer) OVERRIDE; | 66 virtual void AddObserver(LoginModelObserver* observer) OVERRIDE; |
| 59 virtual void RemoveObserver(LoginModelObserver* observer) OVERRIDE; | 67 virtual void RemoveObserver(LoginModelObserver* observer) OVERRIDE; |
| 60 | 68 |
| 61 // Mark this form as having a generated password. | 69 // Mark this form as having a generated password. |
| 62 void SetFormHasGeneratedPassword(const content::PasswordForm& form); | 70 void SetFormHasGeneratedPassword(const content::PasswordForm& form); |
| 63 | 71 |
| 64 // TODO(isherman): This should not be public, but is currently being used by | 72 // TODO(isherman): This should not be public, but is currently being used by |
| 65 // the LoginPrompt code. | 73 // the LoginPrompt code. |
| 66 // When a form is submitted, we prepare to save the password but wait | 74 // 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 | 75 // until we decide the user has successfully logged in. This is step 1 |
| 68 // of 2 (see SavePassword). | 76 // of 2 (see SavePassword). |
| 69 void ProvisionallySavePassword(const content::PasswordForm& form); | 77 void ProvisionallySavePassword(const content::PasswordForm& form); |
| 70 | 78 |
| 71 // content::WebContentsObserver overrides. | 79 // content::WebContentsObserver overrides. |
| 72 virtual void DidNavigateAnyFrame( | 80 virtual void DidNavigateMainFrame( |
| 73 const content::LoadCommittedDetails& details, | 81 const content::LoadCommittedDetails& details, |
| 74 const content::FrameNavigateParams& params) OVERRIDE; | 82 const content::FrameNavigateParams& params) OVERRIDE; |
| 75 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; | 83 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; |
| 76 | 84 |
| 77 // TODO(isherman): This should not be public, but is currently being used by | 85 // TODO(isherman): This should not be public, but is currently being used by |
| 78 // the LoginPrompt code. | 86 // the LoginPrompt code. |
| 79 void OnPasswordFormsParsed( | 87 void OnPasswordFormsParsed( |
| 80 const std::vector<content::PasswordForm>& forms); | 88 const std::vector<content::PasswordForm>& forms); |
| 81 void OnPasswordFormsRendered( | 89 void OnPasswordFormsRendered( |
| 82 const std::vector<content::PasswordForm>& visible_forms); | 90 const std::vector<content::PasswordForm>& visible_forms); |
| 83 | 91 |
| 84 protected: | 92 protected: |
| 85 // Subclassed for unit tests. | 93 // Subclassed for unit tests. |
| 86 PasswordManager(content::WebContents* web_contents, | 94 PasswordManager(content::WebContents* web_contents, |
| 87 PasswordManagerDelegate* delegate); | 95 PasswordManagerDelegate* delegate); |
| 88 | 96 |
| 89 private: | 97 private: |
| 90 friend class content::WebContentsUserData<PasswordManager>; | 98 friend class content::WebContentsUserData<PasswordManager>; |
| 99 friend class PasswordManagerTest; | |
|
Ilya Sherman
2013/07/27 01:09:48
Rather than friending the test class -- which allo
Garrett Casto
2013/08/03 00:38:42
As you wish. I personally don't have a problem wit
| |
| 100 | |
| 101 // Handle notification that a password form was submitted. | |
| 102 void OnPasswordFormSubmitted(const content::PasswordForm& password_form); | |
| 91 | 103 |
| 92 // Possibly set up FieldTrial for testing other possible usernames. This only | 104 // Possibly set up FieldTrial for testing other possible usernames. This only |
| 93 // happens if there are other_possible_usernames to be shown and the | 105 // happens if there are other_possible_usernames to be shown and the |
| 94 // experiment hasn't already been initialized. We setup the experiment at | 106 // 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 | 107 // 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 | 108 // of users so we want to include a larger fraction of these users than the |
| 97 // normal 10%. | 109 // normal 10%. |
| 98 void PossiblyInitializeUsernamesExperiment( | 110 void PossiblyInitializeUsernamesExperiment( |
| 99 const content::PasswordFormMap& matches) const; | 111 const content::PasswordFormMap& matches) const; |
| 100 | 112 |
| (...skipping 26 matching lines...) Expand all Loading... | |
| 127 // attempt to have succeeded (as in valid credentials). If it fails, we | 139 // attempt to have succeeded (as in valid credentials). If it fails, we |
| 128 // send the PasswordFormManager back to the pending_login_managers_ set. | 140 // send the PasswordFormManager back to the pending_login_managers_ set. |
| 129 // Scoped in case PasswordManager gets deleted (e.g tab closes) between the | 141 // 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. | 142 // time a user submits a login form and gets to the next page. |
| 131 scoped_ptr<PasswordFormManager> provisional_save_manager_; | 143 scoped_ptr<PasswordFormManager> provisional_save_manager_; |
| 132 | 144 |
| 133 // Our delegate for carrying out external operations. This is typically the | 145 // Our delegate for carrying out external operations. This is typically the |
| 134 // containing WebContents. | 146 // containing WebContents. |
| 135 PasswordManagerDelegate* const delegate_; | 147 PasswordManagerDelegate* const delegate_; |
| 136 | 148 |
| 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 | 149 // 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). | 150 // want to save passwords but will continue to fill passwords). |
| 142 BooleanPrefMember password_manager_enabled_; | 151 BooleanPrefMember password_manager_enabled_; |
| 143 | 152 |
| 144 // Observers to be notified of LoginModel events. This is mutable to allow | 153 // Observers to be notified of LoginModel events. This is mutable to allow |
| 145 // notification in const member functions. | 154 // notification in const member functions. |
| 146 mutable ObserverList<LoginModelObserver> observers_; | 155 mutable ObserverList<LoginModelObserver> observers_; |
| 147 | 156 |
| 157 // Callbacks to be notified when a password form has been submitted. | |
| 158 std::vector<PasswordSubmittedCallback> submission_callbacks_; | |
| 159 | |
| 148 DISALLOW_COPY_AND_ASSIGN(PasswordManager); | 160 DISALLOW_COPY_AND_ASSIGN(PasswordManager); |
| 149 }; | 161 }; |
| 150 | 162 |
| 151 #endif // CHROME_BROWSER_PASSWORD_MANAGER_PASSWORD_MANAGER_H_ | 163 #endif // CHROME_BROWSER_PASSWORD_MANAGER_PASSWORD_MANAGER_H_ |
| OLD | NEW |