| 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; |
| 48 |
| 49 // There is no corresponding remove function as currently all of the |
| 50 // owners of these callbacks have sufficient lifetimes so that the callbacks |
| 51 // should always be valid when called. |
| 52 void AddSubmissionCallback(const PasswordSubmittedCallback& callback); |
| 53 |
| 45 // Is saving new data for password autofill enabled for the current profile? | 54 // 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 | 55 // For example, saving new data is disabled in Incognito mode, whereas filling |
| 47 // data is not. | 56 // data is not. |
| 48 bool IsSavingEnabled() const; | 57 bool IsSavingEnabled() const; |
| 49 | 58 |
| 50 // Called by a PasswordFormManager when it decides a form can be autofilled | 59 // Called by a PasswordFormManager when it decides a form can be autofilled |
| 51 // on the page. | 60 // on the page. |
| 52 virtual void Autofill(const content::PasswordForm& form_for_autofill, | 61 virtual void Autofill(const content::PasswordForm& form_for_autofill, |
| 53 const content::PasswordFormMap& best_matches, | 62 const content::PasswordFormMap& best_matches, |
| 54 const content::PasswordForm& preferred_match, | 63 const content::PasswordForm& preferred_match, |
| 55 bool wait_for_username) const; | 64 bool wait_for_username) const; |
| 56 | 65 |
| 57 // LoginModel implementation. | 66 // LoginModel implementation. |
| 58 virtual void AddObserver(LoginModelObserver* observer) OVERRIDE; | 67 virtual void AddObserver(LoginModelObserver* observer) OVERRIDE; |
| 59 virtual void RemoveObserver(LoginModelObserver* observer) OVERRIDE; | 68 virtual void RemoveObserver(LoginModelObserver* observer) OVERRIDE; |
| 60 | 69 |
| 61 // Mark this form as having a generated password. | 70 // Mark this form as having a generated password. |
| 62 void SetFormHasGeneratedPassword(const content::PasswordForm& form); | 71 void SetFormHasGeneratedPassword(const content::PasswordForm& form); |
| 63 | 72 |
| 64 // TODO(isherman): This should not be public, but is currently being used by | 73 // TODO(isherman): This should not be public, but is currently being used by |
| 65 // the LoginPrompt code. | 74 // the LoginPrompt code. |
| 66 // When a form is submitted, we prepare to save the password but wait | 75 // 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 | 76 // until we decide the user has successfully logged in. This is step 1 |
| 68 // of 2 (see SavePassword). | 77 // of 2 (see SavePassword). |
| 69 void ProvisionallySavePassword(const content::PasswordForm& form); | 78 void ProvisionallySavePassword(const content::PasswordForm& form); |
| 70 | 79 |
| 71 // content::WebContentsObserver overrides. | 80 // content::WebContentsObserver overrides. |
| 72 virtual void DidNavigateAnyFrame( | 81 virtual void DidNavigateMainFrame( |
| 73 const content::LoadCommittedDetails& details, | 82 const content::LoadCommittedDetails& details, |
| 74 const content::FrameNavigateParams& params) OVERRIDE; | 83 const content::FrameNavigateParams& params) OVERRIDE; |
| 75 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; | 84 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; |
| 76 | 85 |
| 77 // TODO(isherman): This should not be public, but is currently being used by | 86 // TODO(isherman): This should not be public, but is currently being used by |
| 78 // the LoginPrompt code. | 87 // the LoginPrompt code. |
| 79 void OnPasswordFormsParsed( | 88 void OnPasswordFormsParsed( |
| 80 const std::vector<content::PasswordForm>& forms); | 89 const std::vector<content::PasswordForm>& forms); |
| 81 void OnPasswordFormsRendered( | 90 void OnPasswordFormsRendered( |
| 82 const std::vector<content::PasswordForm>& visible_forms); | 91 const std::vector<content::PasswordForm>& visible_forms); |
| 83 | 92 |
| 84 protected: | 93 protected: |
| 85 // Subclassed for unit tests. | 94 // Subclassed for unit tests. |
| 86 PasswordManager(content::WebContents* web_contents, | 95 PasswordManager(content::WebContents* web_contents, |
| 87 PasswordManagerDelegate* delegate); | 96 PasswordManagerDelegate* delegate); |
| 88 | 97 |
| 98 // Handle notification that a password form was submitted. |
| 99 virtual void OnPasswordFormSubmitted( |
| 100 const content::PasswordForm& password_form); |
| 101 |
| 89 private: | 102 private: |
| 90 friend class content::WebContentsUserData<PasswordManager>; | 103 friend class content::WebContentsUserData<PasswordManager>; |
| 91 | 104 |
| 92 // Possibly set up FieldTrial for testing other possible usernames. This only | 105 // Possibly set up FieldTrial for testing other possible usernames. This only |
| 93 // happens if there are other_possible_usernames to be shown and the | 106 // happens if there are other_possible_usernames to be shown and the |
| 94 // experiment hasn't already been initialized. We setup the experiment at | 107 // 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 | 108 // 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 | 109 // of users so we want to include a larger fraction of these users than the |
| 97 // normal 10%. | 110 // normal 10%. |
| 98 void PossiblyInitializeUsernamesExperiment( | 111 void PossiblyInitializeUsernamesExperiment( |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 135 PasswordManagerDelegate* const delegate_; | 148 PasswordManagerDelegate* const delegate_; |
| 136 | 149 |
| 137 // Set to false to disable the password manager (will no longer ask if you | 150 // Set to false to disable the password manager (will no longer ask if you |
| 138 // want to save passwords but will continue to fill passwords). | 151 // want to save passwords but will continue to fill passwords). |
| 139 BooleanPrefMember password_manager_enabled_; | 152 BooleanPrefMember password_manager_enabled_; |
| 140 | 153 |
| 141 // Observers to be notified of LoginModel events. This is mutable to allow | 154 // Observers to be notified of LoginModel events. This is mutable to allow |
| 142 // notification in const member functions. | 155 // notification in const member functions. |
| 143 mutable ObserverList<LoginModelObserver> observers_; | 156 mutable ObserverList<LoginModelObserver> observers_; |
| 144 | 157 |
| 158 // Callbacks to be notified when a password form has been submitted. |
| 159 std::vector<PasswordSubmittedCallback> submission_callbacks_; |
| 160 |
| 145 DISALLOW_COPY_AND_ASSIGN(PasswordManager); | 161 DISALLOW_COPY_AND_ASSIGN(PasswordManager); |
| 146 }; | 162 }; |
| 147 | 163 |
| 148 #endif // CHROME_BROWSER_PASSWORD_MANAGER_PASSWORD_MANAGER_H_ | 164 #endif // CHROME_BROWSER_PASSWORD_MANAGER_PASSWORD_MANAGER_H_ |
| OLD | NEW |