OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 #pragma once | 7 #pragma once |
8 | 8 |
9 #include "base/scoped_ptr.h" | 9 #include "base/scoped_ptr.h" |
10 #include "base/stl_util-inl.h" | 10 #include "base/stl_util-inl.h" |
11 #include "chrome/browser/login_model.h" | 11 #include "chrome/browser/login_model.h" |
12 #include "chrome/browser/password_manager/password_form_manager.h" | 12 #include "chrome/browser/password_manager/password_form_manager.h" |
13 #include "chrome/browser/prefs/pref_member.h" | 13 #include "chrome/browser/prefs/pref_member.h" |
| 14 #include "chrome/browser/tab_contents/web_navigation_observer.h" |
14 #include "webkit/glue/password_form.h" | 15 #include "webkit/glue/password_form.h" |
15 #include "webkit/glue/password_form_dom_manager.h" | 16 #include "webkit/glue/password_form_dom_manager.h" |
16 | 17 |
17 class PasswordManagerDelegate; | 18 class PasswordManagerDelegate; |
| 19 class PasswordManagerTest; |
18 class PasswordFormManager; | 20 class PasswordFormManager; |
19 class PrefService; | 21 class PrefService; |
20 | 22 |
21 // Per-tab password manager. Handles creation and management of UI elements, | 23 // Per-tab password manager. Handles creation and management of UI elements, |
22 // receiving password form data from the renderer and managing the password | 24 // receiving password form data from the renderer and managing the password |
23 // database through the WebDataService. The PasswordManager is a LoginModel | 25 // database through the WebDataService. The PasswordManager is a LoginModel |
24 // for purposes of supporting HTTP authentication dialogs. | 26 // for purposes of supporting HTTP authentication dialogs. |
25 class PasswordManager : public LoginModel { | 27 class PasswordManager : public LoginModel, |
| 28 public WebNavigationObserver { |
26 public: | 29 public: |
27 static void RegisterUserPrefs(PrefService* prefs); | 30 static void RegisterUserPrefs(PrefService* prefs); |
28 | 31 |
29 // The delegate passed in is required to outlive the PasswordManager. | 32 // The delegate passed in is required to outlive the PasswordManager. |
30 explicit PasswordManager(PasswordManagerDelegate* delegate); | 33 explicit PasswordManager(PasswordManagerDelegate* delegate); |
31 ~PasswordManager(); | 34 virtual ~PasswordManager(); |
32 | 35 |
33 // Called by a PasswordFormManager when it decides a form can be autofilled | 36 // Called by a PasswordFormManager when it decides a form can be autofilled |
34 // on the page. | 37 // on the page. |
35 void Autofill(const webkit_glue::PasswordForm& form_for_autofill, | 38 void Autofill(const webkit_glue::PasswordForm& form_for_autofill, |
36 const webkit_glue::PasswordFormMap& best_matches, | 39 const webkit_glue::PasswordFormMap& best_matches, |
37 const webkit_glue::PasswordForm* const preferred_match, | 40 const webkit_glue::PasswordForm* const preferred_match, |
38 bool wait_for_username) const; | 41 bool wait_for_username) const; |
39 | 42 |
40 // Notification that the user navigated away from the current page. | 43 // LoginModel implementation. |
41 // Unless this is a password form submission, for our purposes this | 44 virtual void SetObserver(LoginModelObserver* observer); |
42 // means we're done with the current page, so we can clean-up. | |
43 void DidNavigate(); | |
44 | |
45 // Show a prompt to save submitted password if it is a new username for | |
46 // the form, or else just update the stored value. | |
47 void DidStopLoading(); | |
48 | |
49 // Notifies the password manager that password forms were parsed on the page. | |
50 void PasswordFormsFound(const std::vector<webkit_glue::PasswordForm>& forms); | |
51 | |
52 // Notifies the password manager which password forms are initially visible. | |
53 void PasswordFormsVisible( | |
54 const std::vector<webkit_glue::PasswordForm>& visible_forms); | |
55 | 45 |
56 // When a form is submitted, we prepare to save the password but wait | 46 // When a form is submitted, we prepare to save the password but wait |
57 // until we decide the user has successfully logged in. This is step 1 | 47 // until we decide the user has successfully logged in. This is step 1 |
58 // of 2 (see SavePassword). | 48 // of 2 (see SavePassword). |
59 void ProvisionallySavePassword(webkit_glue::PasswordForm form); | 49 void ProvisionallySavePassword(webkit_glue::PasswordForm form); |
60 | 50 |
61 // Clear any pending saves | 51 // WebNavigationObserver overrides. |
62 void ClearProvisionalSave(); | 52 virtual void DidStopLoading(); |
63 | 53 virtual void PasswordFormsFound( |
64 // LoginModel implementation. | 54 const std::vector<webkit_glue::PasswordForm>& forms); |
65 virtual void SetObserver(LoginModelObserver* observer); | 55 virtual void PasswordFormsVisible( |
| 56 const std::vector<webkit_glue::PasswordForm>& visible_forms); |
66 | 57 |
67 private: | 58 private: |
| 59 FRIEND_TEST_ALL_PREFIXES(PasswordManagerTest, FormSeenThenLeftPage); |
| 60 |
68 // Note about how a PasswordFormManager can transition from | 61 // Note about how a PasswordFormManager can transition from |
69 // pending_login_managers_ to provisional_save_manager_ and the infobar. | 62 // pending_login_managers_ to provisional_save_manager_ and the infobar. |
70 // | 63 // |
71 // 1. form "seen" | 64 // 1. form "seen" |
72 // | new | 65 // | new |
73 // | ___ Infobar | 66 // | ___ Infobar |
74 // pending_login -- form submit --> provisional_save ___/ | 67 // pending_login -- form submit --> provisional_save ___/ |
75 // ^ | \___ (update DB) | 68 // ^ | \___ (update DB) |
76 // | fail | 69 // | fail |
77 // |-----------<------<---------| !new | 70 // |-----------<------<---------| !new |
78 // | 71 // |
79 // When a form is "seen" on a page, a PasswordFormManager is created | 72 // When a form is "seen" on a page, a PasswordFormManager is created |
80 // and stored in this collection until user navigates away from page. | 73 // and stored in this collection until user navigates away from page. |
| 74 |
| 75 // Clear any pending saves |
| 76 void ClearProvisionalSave(); |
| 77 |
| 78 // Notification that the user navigated away from the current page. |
| 79 // Unless this is a password form submission, for our purposes this |
| 80 // means we're done with the current page, so we can clean-up. |
| 81 void DidNavigate(); |
| 82 |
81 typedef std::vector<PasswordFormManager*> LoginManagers; | 83 typedef std::vector<PasswordFormManager*> LoginManagers; |
82 LoginManagers pending_login_managers_; | 84 LoginManagers pending_login_managers_; |
83 | 85 |
84 // Deleter for pending_login_managers_ when PasswordManager is deleted (e.g | 86 // Deleter for pending_login_managers_ when PasswordManager is deleted (e.g |
85 // tab closes) on a page with a password form, thus containing login managers. | 87 // tab closes) on a page with a password form, thus containing login managers. |
86 STLElementDeleter<LoginManagers> login_managers_deleter_; | 88 STLElementDeleter<LoginManagers> login_managers_deleter_; |
87 | 89 |
88 // When the user submits a password/credential, this contains the | 90 // When the user submits a password/credential, this contains the |
89 // PasswordFormManager for the form in question until we deem the login | 91 // PasswordFormManager for the form in question until we deem the login |
90 // attempt to have succeeded (as in valid credentials). If it fails, we | 92 // attempt to have succeeded (as in valid credentials). If it fails, we |
(...skipping 10 matching lines...) Expand all Loading... |
101 LoginModelObserver* observer_; | 103 LoginModelObserver* observer_; |
102 | 104 |
103 // Set to false to disable the password manager (will no longer fill | 105 // Set to false to disable the password manager (will no longer fill |
104 // passwords or ask you if you want to save passwords). | 106 // passwords or ask you if you want to save passwords). |
105 BooleanPrefMember password_manager_enabled_; | 107 BooleanPrefMember password_manager_enabled_; |
106 | 108 |
107 DISALLOW_COPY_AND_ASSIGN(PasswordManager); | 109 DISALLOW_COPY_AND_ASSIGN(PasswordManager); |
108 }; | 110 }; |
109 | 111 |
110 #endif // CHROME_BROWSER_PASSWORD_MANAGER_PASSWORD_MANAGER_H_ | 112 #endif // CHROME_BROWSER_PASSWORD_MANAGER_PASSWORD_MANAGER_H_ |
OLD | NEW |