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
3 // found in the LICENSE file.
5 #ifndef CHROME_BROWSER_UI_WEBUI_OPTIONS_PASSWORD_MANAGER_HANDLER_H_
6 #define CHROME_BROWSER_UI_WEBUI_OPTIONS_PASSWORD_MANAGER_HANDLER_H_
11 #include "base/memory/scoped_vector.h"
12 #include "base/prefs/pref_member.h"
13 #include "chrome/browser/password_manager/password_store.h"
14 #include "chrome/browser/password_manager/password_store_consumer.h"
15 #include "chrome/browser/ui/webui/options/options_ui.h"
23 class PasswordManagerHandler : public OptionsPageUIHandler,
24 public PasswordStore::Observer {
26 PasswordManagerHandler();
27 virtual ~PasswordManagerHandler();
29 // OptionsPageUIHandler implementation.
30 virtual void GetLocalizedValues(DictionaryValue* localized_strings) OVERRIDE;
31 virtual void InitializeHandler() OVERRIDE;
32 virtual void RegisterMessages() OVERRIDE;
34 // PasswordStore::Observer implementation.
35 virtual void OnLoginsChanged() OVERRIDE;
38 // The password store associated with the currently active profile.
39 PasswordStore* GetPasswordStore();
41 // Called when the JS PasswordManager object is initialized.
42 void UpdatePasswordLists(const ListValue* args);
45 // @param value the entry index to be removed.
46 void RemoveSavedPassword(const ListValue* args);
48 // Remove an password exception.
49 // @param value the entry index to be removed.
50 void RemovePasswordException(const ListValue* args);
52 // Remove all saved passwords
53 void RemoveAllSavedPasswords(const ListValue* args);
55 // Remove All password exceptions
56 void RemoveAllPasswordExceptions(const ListValue* args);
58 // Request the plain text password for an entry to be revealed.
59 // @param index The index of the entry.
60 void RequestShowPassword(const ListValue* args);
62 // Sets the password and exception list contents to the given data.
63 // We take ownership of the PasswordForms in the vector.
64 void SetPasswordList();
65 void SetPasswordExceptionList();
67 // Returns true if the user needs to be authenticated before a plaintext
68 // password is revealed.
69 bool IsAuthenticationRequired();
71 // A short class to mediate requests to the password store.
72 class ListPopulater : public PasswordStoreConsumer {
74 explicit ListPopulater(PasswordManagerHandler* page);
75 virtual ~ListPopulater();
77 // Send a query to the password store to populate a list.
78 virtual void Populate() = 0;
81 PasswordManagerHandler* page_;
82 CancelableRequestProvider::Handle pending_login_query_;
85 // A short class to mediate requests to the password store for passwordlist.
86 class PasswordListPopulater : public ListPopulater {
88 explicit PasswordListPopulater(PasswordManagerHandler* page);
90 // Send a query to the password store to populate a password list.
91 virtual void Populate() OVERRIDE;
93 // Send the password store's reply back to the handler.
94 virtual void OnPasswordStoreRequestDone(
95 CancelableRequestProvider::Handle handle,
96 const std::vector<autofill::PasswordForm*>& result) OVERRIDE;
97 virtual void OnGetPasswordStoreResults(
98 const std::vector<autofill::PasswordForm*>& results) OVERRIDE;
101 // A short class to mediate requests to the password store for exceptions.
102 class PasswordExceptionListPopulater : public ListPopulater {
104 explicit PasswordExceptionListPopulater(PasswordManagerHandler* page);
106 // Send a query to the password store to populate a passwordException list.
107 virtual void Populate() OVERRIDE;
109 // Send the password store's reply back to the handler.
110 virtual void OnPasswordStoreRequestDone(
111 CancelableRequestProvider::Handle handle,
112 const std::vector<autofill::PasswordForm*>& result) OVERRIDE;
113 virtual void OnGetPasswordStoreResults(
114 const std::vector<autofill::PasswordForm*>& results) OVERRIDE;
117 // Password store consumer for populating the password list and exceptions.
118 PasswordListPopulater populater_;
119 PasswordExceptionListPopulater exception_populater_;
121 ScopedVector<autofill::PasswordForm> password_list_;
122 ScopedVector<autofill::PasswordForm> password_exception_list_;
125 std::string languages_;
127 // Whether to show stored passwords or not.
128 BooleanPrefMember show_passwords_;
130 // Indicates whether or not the password manager should require the user to
131 // reauthenticate before revealing plaintext passwords.
132 bool require_reauthentication_;
134 // The last time the user was successfully authenticated.
135 // Used to determine whether or not to reveal plaintext passwords.
136 base::TimeTicks last_authentication_time_;
138 DISALLOW_COPY_AND_ASSIGN(PasswordManagerHandler);
141 } // namespace options
143 #endif // CHROME_BROWSER_UI_WEBUI_OPTIONS_PASSWORD_MANAGER_HANDLER_H_