OLD | NEW |
| (Empty) |
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. | |
4 | |
5 #ifndef CHROME_BROWSER_UI_WEBUI_OPTIONS2_PASSWORD_MANAGER_HANDLER_H_ | |
6 #define CHROME_BROWSER_UI_WEBUI_OPTIONS2_PASSWORD_MANAGER_HANDLER_H_ | |
7 | |
8 #include <string> | |
9 #include <vector> | |
10 | |
11 #include "base/memory/scoped_vector.h" | |
12 #include "chrome/browser/password_manager/password_store.h" | |
13 #include "chrome/browser/password_manager/password_store_consumer.h" | |
14 #include "chrome/browser/prefs/pref_member.h" | |
15 #include "chrome/browser/ui/webui/options2/options_ui.h" | |
16 | |
17 namespace webkit { | |
18 namespace forms { | |
19 struct PasswordForm; | |
20 } | |
21 } | |
22 | |
23 namespace options { | |
24 | |
25 class PasswordManagerHandler : public OptionsPageUIHandler, | |
26 public PasswordStore::Observer { | |
27 public: | |
28 PasswordManagerHandler(); | |
29 virtual ~PasswordManagerHandler(); | |
30 | |
31 // OptionsPageUIHandler implementation. | |
32 virtual void GetLocalizedValues(DictionaryValue* localized_strings) OVERRIDE; | |
33 virtual void InitializeHandler() OVERRIDE; | |
34 virtual void RegisterMessages() OVERRIDE; | |
35 | |
36 // PasswordStore::Observer implementation. | |
37 virtual void OnLoginsChanged() OVERRIDE; | |
38 | |
39 // content::NotificationObserver implementation. | |
40 virtual void Observe(int type, | |
41 const content::NotificationSource& source, | |
42 const content::NotificationDetails& details) OVERRIDE; | |
43 | |
44 private: | |
45 // The password store associated with the currently active profile. | |
46 PasswordStore* GetPasswordStore(); | |
47 | |
48 // Called when the JS PasswordManager object is initialized. | |
49 void UpdatePasswordLists(const ListValue* args); | |
50 | |
51 // Remove an entry. | |
52 // @param value the entry index to be removed. | |
53 void RemoveSavedPassword(const ListValue* args); | |
54 | |
55 // Remove an password exception. | |
56 // @param value the entry index to be removed. | |
57 void RemovePasswordException(const ListValue* args); | |
58 | |
59 // Remove all saved passwords | |
60 void RemoveAllSavedPasswords(const ListValue* args); | |
61 | |
62 // Remove All password exceptions | |
63 void RemoveAllPasswordExceptions(const ListValue* args); | |
64 | |
65 // Get password value for the selected entry. | |
66 // @param value the selected entry index. | |
67 void ShowSelectedPassword(const ListValue* args); | |
68 | |
69 // Sets the password and exception list contents to the given data. | |
70 // We take ownership of the PasswordForms in the vector. | |
71 void SetPasswordList(); | |
72 void SetPasswordExceptionList(); | |
73 | |
74 // A short class to mediate requests to the password store. | |
75 class ListPopulater : public PasswordStoreConsumer { | |
76 public: | |
77 explicit ListPopulater(PasswordManagerHandler* page); | |
78 virtual ~ListPopulater(); | |
79 | |
80 // Send a query to the password store to populate a list. | |
81 virtual void Populate() = 0; | |
82 | |
83 // Send the password store's reply back to the handler. | |
84 virtual void OnPasswordStoreRequestDone( | |
85 CancelableRequestProvider::Handle handle, | |
86 const std::vector<webkit::forms::PasswordForm*>& result) = 0; | |
87 | |
88 protected: | |
89 PasswordManagerHandler* page_; | |
90 CancelableRequestProvider::Handle pending_login_query_; | |
91 }; | |
92 | |
93 // A short class to mediate requests to the password store for passwordlist. | |
94 class PasswordListPopulater : public ListPopulater { | |
95 public: | |
96 explicit PasswordListPopulater(PasswordManagerHandler* page); | |
97 | |
98 // Send a query to the password store to populate a password list. | |
99 virtual void Populate() OVERRIDE; | |
100 | |
101 // Send the password store's reply back to the handler. | |
102 virtual void OnPasswordStoreRequestDone( | |
103 CancelableRequestProvider::Handle handle, | |
104 const std::vector<webkit::forms::PasswordForm*>& result) OVERRIDE; | |
105 }; | |
106 | |
107 // A short class to mediate requests to the password store for exceptions. | |
108 class PasswordExceptionListPopulater : public ListPopulater { | |
109 public: | |
110 explicit PasswordExceptionListPopulater(PasswordManagerHandler* page); | |
111 | |
112 // Send a query to the password store to populate a passwordException list. | |
113 virtual void Populate() OVERRIDE; | |
114 | |
115 // Send the password store's reply back to the handler. | |
116 virtual void OnPasswordStoreRequestDone( | |
117 CancelableRequestProvider::Handle handle, | |
118 const std::vector<webkit::forms::PasswordForm*>& result) OVERRIDE; | |
119 }; | |
120 | |
121 // Password store consumer for populating the password list and exceptions. | |
122 PasswordListPopulater populater_; | |
123 PasswordExceptionListPopulater exception_populater_; | |
124 | |
125 ScopedVector<webkit::forms::PasswordForm> password_list_; | |
126 ScopedVector<webkit::forms::PasswordForm> password_exception_list_; | |
127 | |
128 // User's pref | |
129 std::string languages_; | |
130 | |
131 // Whether to show stored passwords or not. | |
132 BooleanPrefMember show_passwords_; | |
133 | |
134 DISALLOW_COPY_AND_ASSIGN(PasswordManagerHandler); | |
135 }; | |
136 | |
137 } // namespace options | |
138 | |
139 #endif // CHROME_BROWSER_UI_WEBUI_OPTIONS2_PASSWORD_MANAGER_HANDLER_H_ | |
OLD | NEW |