1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef CHROME_BROWSER_PASSWORD_MANAGER_H__
6 #define CHROME_BROWSER_PASSWORD_MANAGER_H__
8 #include "base/scoped_ptr.h"
9 #include "chrome/browser/views/info_bar_confirm_view.h"
10 #include "chrome/browser/password_form_manager.h"
11 #include "chrome/browser/views/login_view.h"
12 #include "chrome/common/pref_member.h"
13 #include "chrome/common/stl_util-inl.h"
14 #include "webkit/glue/password_form.h"
15 #include "webkit/glue/password_form_dom_manager.h"
20 // Per-tab password manager. Handles creation and management of UI elements,
21 // receiving password form data from the renderer and managing the password
22 // database through the WebDataService. The PasswordManager is a LoginModel
23 // for purposes of supporting HTTP authentication dialogs.
24 class PasswordManager
: public ChromeViews::LoginModel
{
26 static void RegisterUserPrefs(PrefService
* prefs
);
28 explicit PasswordManager(WebContents
* web_contents
);
31 // Called by a PasswordFormManager when it decides a form can be autofilled
33 void Autofill(const PasswordForm
& form_for_autofill
,
34 const PasswordFormMap
& best_matches
,
35 const PasswordForm
* const preferred_match
) const;
37 // Closes any visible password manager UI
40 // Notification that the user initiated a navigation away from the current
41 // page. Unless this is a password form submission, for our purposes this
42 // means we're done with the current page, so we can clean-up.
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();
49 // Notifies the password manager that password forms were parsed on the page.
50 void PasswordFormsSeen(const std::vector
<PasswordForm
>& forms
);
52 // When a form is submitted, we prepare to save the password but wait
53 // until we decide the user has successfully logged in. This is step 1
54 // of 2 (see SavePassword).
55 void ProvisionallySavePassword(PasswordForm form
);
57 // LoginModel implementation.
58 virtual void SetObserver(ChromeViews::LoginModelObserver
* observer
) {
63 // The Info Bar UI that prompts the user to save a password.
64 friend class SavePasswordBar
;
65 class SavePasswordBar
: public InfoBarConfirmView
{
67 SavePasswordBar(PasswordFormManager
* form_manager
,
68 PasswordManager
* password_manager
);
69 virtual ~SavePasswordBar();
71 // InfoBarConfirmView overrides.
72 virtual void OKButtonPressed();
73 virtual void CancelButtonPressed();
76 PasswordFormManager
* form_manager_
;
77 PasswordManager
* password_manager_
;
79 DISALLOW_EVIL_CONSTRUCTORS(SavePasswordBar
);
82 // Replace the current InfoBar with a new one. Just adds if there is no
84 void ReplaceInfoBar(InfoBarItemView
* view
);
86 // The currently visible InfoBar (NULL if none)
87 InfoBarItemView
* current_bar_
;
89 // When a form is "seen" on a page, a PasswordFormManager is created
90 // and stored in this collection until user navigates away from page.
91 typedef std::vector
<PasswordFormManager
*> LoginManagers
;
92 LoginManagers pending_login_managers_
;
94 // Deleter for pending_login_managers_ when PasswordManager is deleted (e.g
95 // tab closes) on a page with a password form, thus containing login managers.
96 STLElementDeleter
<LoginManagers
> login_managers_deleter_
;
98 // When the user opts to save a password, this contains the
99 // PasswordFormManager for the form in question.
100 // Scoped incase PasswordManager gets deleted (e.g tab closes) between the
101 // time a user submits a login form and gets to the next page.
102 scoped_ptr
<PasswordFormManager
> pending_save_manager_
;
104 // The containing WebContents
105 WebContents
* web_contents_
;
107 // The LoginModelObserver (i.e LoginView) requiring autofill.
108 ChromeViews::LoginModelObserver
* observer_
;
110 // Set to false to disable the password manager (will no longer fill
111 // passwords or ask you if you want to save passwords).
112 BooleanPrefMember password_manager_enabled_
;
114 DISALLOW_EVIL_CONSTRUCTORS(PasswordManager
);