OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 <vector> |
| 10 |
9 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
| 12 #include "base/memory/scoped_vector.h" |
10 #include "base/stl_util.h" | 13 #include "base/stl_util.h" |
11 #include "chrome/browser/password_manager/password_form_manager.h" | 14 #include "chrome/browser/password_manager/password_form_manager.h" |
12 #include "chrome/browser/prefs/pref_member.h" | 15 #include "chrome/browser/prefs/pref_member.h" |
13 #include "chrome/browser/ui/login/login_model.h" | 16 #include "chrome/browser/ui/login/login_model.h" |
14 #include "content/public/browser/web_contents_observer.h" | 17 #include "content/public/browser/web_contents_observer.h" |
15 #include "webkit/forms/password_form.h" | 18 #include "webkit/forms/password_form.h" |
16 #include "webkit/forms/password_form_dom_manager.h" | 19 #include "webkit/forms/password_form_dom_manager.h" |
17 | 20 |
18 class PasswordManagerDelegate; | 21 class PasswordManagerDelegate; |
19 class PasswordManagerTest; | 22 class PasswordManagerTest; |
(...skipping 11 matching lines...) Expand all Loading... |
31 | 34 |
32 // The delegate passed in is required to outlive the PasswordManager. | 35 // The delegate passed in is required to outlive the PasswordManager. |
33 PasswordManager(content::WebContents* web_contents, | 36 PasswordManager(content::WebContents* web_contents, |
34 PasswordManagerDelegate* delegate); | 37 PasswordManagerDelegate* delegate); |
35 virtual ~PasswordManager(); | 38 virtual ~PasswordManager(); |
36 | 39 |
37 // Called by a PasswordFormManager when it decides a form can be autofilled | 40 // Called by a PasswordFormManager when it decides a form can be autofilled |
38 // on the page. | 41 // on the page. |
39 void Autofill(const webkit::forms::PasswordForm& form_for_autofill, | 42 void Autofill(const webkit::forms::PasswordForm& form_for_autofill, |
40 const webkit::forms::PasswordFormMap& best_matches, | 43 const webkit::forms::PasswordFormMap& best_matches, |
41 const webkit::forms::PasswordForm* const preferred_match, | 44 const webkit::forms::PasswordForm& preferred_match, |
42 bool wait_for_username) const; | 45 bool wait_for_username) const; |
43 | 46 |
44 // LoginModel implementation. | 47 // LoginModel implementation. |
45 virtual void SetObserver(LoginModelObserver* observer) OVERRIDE; | 48 virtual void SetObserver(LoginModelObserver* observer) OVERRIDE; |
46 | 49 |
47 // When a form is submitted, we prepare to save the password but wait | 50 // When a form is submitted, we prepare to save the password but wait |
48 // until we decide the user has successfully logged in. This is step 1 | 51 // until we decide the user has successfully logged in. This is step 1 |
49 // of 2 (see SavePassword). | 52 // of 2 (see SavePassword). |
50 void ProvisionallySavePassword(webkit::forms::PasswordForm form); | 53 void ProvisionallySavePassword(const webkit::forms::PasswordForm& form); |
51 | 54 |
52 // content::WebContentsObserver overrides. | 55 // content::WebContentsObserver overrides. |
53 virtual void DidStopLoading() OVERRIDE; | 56 virtual void DidStopLoading() OVERRIDE; |
54 virtual void DidNavigateAnyFrame( | 57 virtual void DidNavigateAnyFrame( |
55 const content::LoadCommittedDetails& details, | 58 const content::LoadCommittedDetails& details, |
56 const content::FrameNavigateParams& params) OVERRIDE; | 59 const content::FrameNavigateParams& params) OVERRIDE; |
57 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; | 60 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; |
58 | 61 |
59 void OnPasswordFormsFound( | 62 void OnPasswordFormsFound( |
60 const std::vector<webkit::forms::PasswordForm>& forms); | 63 const std::vector<webkit::forms::PasswordForm>& forms); |
61 void OnPasswordFormsVisible( | |
62 const std::vector<webkit::forms::PasswordForm>& visible_forms); | |
63 | 64 |
64 private: | 65 private: |
65 FRIEND_TEST_ALL_PREFIXES(PasswordManagerTest, FormSeenThenLeftPage); | 66 FRIEND_TEST_ALL_PREFIXES(PasswordManagerTest, FormSeenThenLeftPage); |
66 | 67 |
67 // Note about how a PasswordFormManager can transition from | 68 // Note about how a PasswordFormManager can transition from |
68 // pending_login_managers_ to provisional_save_manager_ and the infobar. | 69 // pending_login_managers_ to provisional_save_manager_ and the infobar. |
69 // | 70 // |
70 // 1. form "seen" | 71 // 1. form "seen" |
71 // | new | 72 // | new |
72 // | ___ Infobar | 73 // | ___ Infobar |
73 // pending_login -- form submit --> provisional_save ___/ | 74 // pending_login -- form submit --> provisional_save ___/ |
74 // ^ | \___ (update DB) | 75 // ^ | \___ (update DB) |
75 // | fail | 76 // | fail |
76 // |-----------<------<---------| !new | 77 // |-----------<------<---------| !new |
77 // | 78 // |
78 // When a form is "seen" on a page, a PasswordFormManager is created | 79 // When a form is "seen" on a page, a PasswordFormManager is created |
79 // and stored in this collection until user navigates away from page. | 80 // and stored in this collection until user navigates away from page. |
80 | 81 |
81 // Clear any pending saves | 82 void OnPasswordFormsVisible( |
82 void ClearProvisionalSave(); | 83 const std::vector<webkit::forms::PasswordForm>& visible_forms); |
83 | 84 |
84 // Notification that the user navigated away from the current page. | 85 // Is password autofill enabled for the current profile? |
85 // Unless this is a password form submission, for our purposes this | 86 bool IsEnabled() const; |
86 // means we're done with the current page, so we can clean-up. | |
87 void DidNavigate(); | |
88 | 87 |
89 typedef std::vector<PasswordFormManager*> LoginManagers; | 88 ScopedVector<PasswordFormManager> pending_login_managers_; |
90 LoginManagers pending_login_managers_; | |
91 | |
92 // Deleter for pending_login_managers_ when PasswordManager is deleted (e.g | |
93 // tab closes) on a page with a password form, thus containing login managers. | |
94 STLElementDeleter<LoginManagers> login_managers_deleter_; | |
95 | 89 |
96 // When the user submits a password/credential, this contains the | 90 // When the user submits a password/credential, this contains the |
97 // PasswordFormManager for the form in question until we deem the login | 91 // PasswordFormManager for the form in question until we deem the login |
98 // 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 |
99 // send the PasswordFormManager back to the pending_login_managers_ set. | 93 // send the PasswordFormManager back to the pending_login_managers_ set. |
100 // Scoped in case PasswordManager gets deleted (e.g tab closes) between the | 94 // Scoped in case PasswordManager gets deleted (e.g tab closes) between the |
101 // time a user submits a login form and gets to the next page. | 95 // time a user submits a login form and gets to the next page. |
102 scoped_ptr<PasswordFormManager> provisional_save_manager_; | 96 scoped_ptr<PasswordFormManager> provisional_save_manager_; |
103 | 97 |
104 // Our delegate for carrying out external operations. This is typically the | 98 // Our delegate for carrying out external operations. This is typically the |
105 // containing TabContents. | 99 // containing TabContents. |
106 PasswordManagerDelegate* delegate_; | 100 PasswordManagerDelegate* const delegate_; |
107 | 101 |
108 // The LoginModelObserver (i.e LoginView) requiring autofill. | 102 // The LoginModelObserver (i.e LoginView) requiring autofill. |
109 LoginModelObserver* observer_; | 103 LoginModelObserver* observer_; |
110 | 104 |
111 // 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 |
112 // passwords or ask you if you want to save passwords). | 106 // passwords or ask you if you want to save passwords). |
113 BooleanPrefMember password_manager_enabled_; | 107 BooleanPrefMember password_manager_enabled_; |
114 | 108 |
115 DISALLOW_COPY_AND_ASSIGN(PasswordManager); | 109 DISALLOW_COPY_AND_ASSIGN(PasswordManager); |
116 }; | 110 }; |
117 | 111 |
118 #endif // CHROME_BROWSER_PASSWORD_MANAGER_PASSWORD_MANAGER_H_ | 112 #endif // CHROME_BROWSER_PASSWORD_MANAGER_PASSWORD_MANAGER_H_ |
OLD | NEW |