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 COMPONENTS_PASSWORD_MANAGER_CORE_BROWSER_PASSWORD_MANAGER_H_ | 5 #ifndef COMPONENTS_PASSWORD_MANAGER_CORE_BROWSER_PASSWORD_MANAGER_H_ |
6 #define COMPONENTS_PASSWORD_MANAGER_CORE_BROWSER_PASSWORD_MANAGER_H_ | 6 #define COMPONENTS_PASSWORD_MANAGER_CORE_BROWSER_PASSWORD_MANAGER_H_ |
7 | 7 |
8 #include <map> | 8 #include <map> |
9 #include <memory> | 9 #include <memory> |
10 #include <string> | 10 #include <string> |
11 #include <vector> | 11 #include <vector> |
12 | 12 |
13 #include "base/callback.h" | 13 #include "base/callback.h" |
14 #include "base/gtest_prod_util.h" | 14 #include "base/gtest_prod_util.h" |
15 #include "base/macros.h" | 15 #include "base/macros.h" |
| 16 #include "base/memory/ref_counted.h" |
16 #include "base/observer_list.h" | 17 #include "base/observer_list.h" |
17 #include "base/strings/string16.h" | 18 #include "base/strings/string16.h" |
18 #include "build/build_config.h" | 19 #include "build/build_config.h" |
19 #include "components/autofill/core/common/password_form.h" | 20 #include "components/autofill/core/common/password_form.h" |
20 #include "components/autofill/core/common/password_form_fill_data.h" | 21 #include "components/autofill/core/common/password_form_fill_data.h" |
21 #include "components/password_manager/core/browser/login_model.h" | 22 #include "components/password_manager/core/browser/login_model.h" |
22 #include "components/password_manager/core/browser/password_form_manager.h" | 23 #include "components/password_manager/core/browser/password_form_manager.h" |
23 | 24 |
24 class PrefRegistrySimple; | 25 class PrefRegistrySimple; |
25 | 26 |
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
177 void DropFormManagers(); | 178 void DropFormManagers(); |
178 | 179 |
179 // Returns true if password element is detected on the current page. | 180 // Returns true if password element is detected on the current page. |
180 bool IsPasswordFieldDetectedOnPage(); | 181 bool IsPasswordFieldDetectedOnPage(); |
181 | 182 |
182 PasswordManagerClient* client() { return client_; } | 183 PasswordManagerClient* client() { return client_; } |
183 | 184 |
184 #if defined(UNIT_TEST) | 185 #if defined(UNIT_TEST) |
185 // TODO(crbug.com/639786): Replace using this by quering the factory for | 186 // TODO(crbug.com/639786): Replace using this by quering the factory for |
186 // mocked PasswordFormManagers. | 187 // mocked PasswordFormManagers. |
187 const std::vector<std::unique_ptr<PasswordFormManager>>& | 188 const std::vector<scoped_refptr<PasswordFormManager>>& |
188 pending_login_managers() { | 189 pending_login_managers() { |
189 return pending_login_managers_; | 190 return pending_login_managers_; |
190 } | 191 } |
191 #endif | 192 #endif |
192 | 193 |
193 private: | 194 private: |
194 FRIEND_TEST_ALL_PREFIXES( | 195 FRIEND_TEST_ALL_PREFIXES( |
195 PasswordManagerTest, | 196 PasswordManagerTest, |
196 ShouldBlockPasswordForSameOriginButDifferentSchemeTest); | 197 ShouldBlockPasswordForSameOriginButDifferentSchemeTest); |
197 | 198 |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
259 // | new | 260 // | new |
260 // | ___ Infobar | 261 // | ___ Infobar |
261 // pending_login -- form submit --> provisional_save ___/ | 262 // pending_login -- form submit --> provisional_save ___/ |
262 // ^ | \___ (update DB) | 263 // ^ | \___ (update DB) |
263 // | fail | 264 // | fail |
264 // |-----------<------<---------| !new | 265 // |-----------<------<---------| !new |
265 // | 266 // |
266 // When a form is "seen" on a page, a PasswordFormManager is created | 267 // When a form is "seen" on a page, a PasswordFormManager is created |
267 // and stored in this collection until user navigates away from page. | 268 // and stored in this collection until user navigates away from page. |
268 | 269 |
269 std::vector<std::unique_ptr<PasswordFormManager>> pending_login_managers_; | 270 std::vector<scoped_refptr<PasswordFormManager>> pending_login_managers_; |
270 | 271 |
271 // When the user submits a password/credential, this contains the | 272 // When the user submits a password/credential, this contains the |
272 // PasswordFormManager for the form in question until we deem the login | 273 // PasswordFormManager for the form in question until we deem the login |
273 // attempt to have succeeded (as in valid credentials). If it fails, we | 274 // attempt to have succeeded (as in valid credentials). If it fails, we |
274 // send the PasswordFormManager back to the pending_login_managers_ set. | 275 // send the PasswordFormManager back to the pending_login_managers_ set. |
275 // Scoped in case PasswordManager gets deleted (e.g tab closes) between the | 276 // Scoped in case PasswordManager gets deleted (e.g tab closes) between the |
276 // time a user submits a login form and gets to the next page. | 277 // time a user submits a login form and gets to the next page. |
277 std::unique_ptr<PasswordFormManager> provisional_save_manager_; | 278 scoped_refptr<PasswordFormManager> provisional_save_manager_; |
278 | 279 |
279 // The embedder-level client. Must outlive this class. | 280 // The embedder-level client. Must outlive this class. |
280 PasswordManagerClient* const client_; | 281 PasswordManagerClient* const client_; |
281 | 282 |
282 // Observers to be notified of LoginModel events. This is mutable to allow | 283 // Observers to be notified of LoginModel events. This is mutable to allow |
283 // notification in const member functions. | 284 // notification in const member functions. |
284 mutable base::ObserverList<LoginModelObserver> observers_; | 285 mutable base::ObserverList<LoginModelObserver> observers_; |
285 | 286 |
286 // Callbacks to be notified when a password form has been submitted. | 287 // Callbacks to be notified when a password form has been submitted. |
287 std::vector<PasswordSubmittedCallback> submission_callbacks_; | 288 std::vector<PasswordSubmittedCallback> submission_callbacks_; |
288 | 289 |
289 // Records all visible forms seen during a page load, in all frames of the | 290 // Records all visible forms seen during a page load, in all frames of the |
290 // page. When the page stops loading, the password manager checks if one of | 291 // page. When the page stops loading, the password manager checks if one of |
291 // the recorded forms matches the login form from the previous page | 292 // the recorded forms matches the login form from the previous page |
292 // (to see if the login was a failure), and clears the vector. | 293 // (to see if the login was a failure), and clears the vector. |
293 std::vector<autofill::PasswordForm> all_visible_forms_; | 294 std::vector<autofill::PasswordForm> all_visible_forms_; |
294 | 295 |
295 // The user-visible URL from the last time a password was provisionally saved. | 296 // The user-visible URL from the last time a password was provisionally saved. |
296 GURL main_frame_url_; | 297 GURL main_frame_url_; |
297 | 298 |
298 DISALLOW_COPY_AND_ASSIGN(PasswordManager); | 299 DISALLOW_COPY_AND_ASSIGN(PasswordManager); |
299 }; | 300 }; |
300 | 301 |
301 } // namespace password_manager | 302 } // namespace password_manager |
302 | 303 |
303 #endif // COMPONENTS_PASSWORD_MANAGER_CORE_BROWSER_PASSWORD_MANAGER_H_ | 304 #endif // COMPONENTS_PASSWORD_MANAGER_CORE_BROWSER_PASSWORD_MANAGER_H_ |
OLD | NEW |