- add sources.
[platform/framework/web/crosswalk.git] / src / chrome / browser / ui / webui / options / password_manager_handler.h
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_OPTIONS_PASSWORD_MANAGER_HANDLER_H_
6 #define CHROME_BROWSER_UI_WEBUI_OPTIONS_PASSWORD_MANAGER_HANDLER_H_
7
8 #include <string>
9 #include <vector>
10
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"
16
17 namespace autofill {
18 struct PasswordForm;
19 }
20
21 namespace options {
22
23 class PasswordManagerHandler : public OptionsPageUIHandler,
24                                public PasswordStore::Observer {
25  public:
26   PasswordManagerHandler();
27   virtual ~PasswordManagerHandler();
28
29   // OptionsPageUIHandler implementation.
30   virtual void GetLocalizedValues(DictionaryValue* localized_strings) OVERRIDE;
31   virtual void InitializeHandler() OVERRIDE;
32   virtual void RegisterMessages() OVERRIDE;
33
34   // PasswordStore::Observer implementation.
35   virtual void OnLoginsChanged() OVERRIDE;
36
37  private:
38   // The password store associated with the currently active profile.
39   PasswordStore* GetPasswordStore();
40
41   // Called when the JS PasswordManager object is initialized.
42   void UpdatePasswordLists(const ListValue* args);
43
44   // Remove an entry.
45   // @param value the entry index to be removed.
46   void RemoveSavedPassword(const ListValue* args);
47
48   // Remove an password exception.
49   // @param value the entry index to be removed.
50   void RemovePasswordException(const ListValue* args);
51
52   // Remove all saved passwords
53   void RemoveAllSavedPasswords(const ListValue* args);
54
55   // Remove All password exceptions
56   void RemoveAllPasswordExceptions(const ListValue* args);
57
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);
61
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();
66
67   // Returns true if the user needs to be authenticated before a plaintext
68   // password is revealed.
69   bool IsAuthenticationRequired();
70
71   // A short class to mediate requests to the password store.
72   class ListPopulater : public PasswordStoreConsumer {
73    public:
74     explicit ListPopulater(PasswordManagerHandler* page);
75     virtual ~ListPopulater();
76
77     // Send a query to the password store to populate a list.
78     virtual void Populate() = 0;
79
80    protected:
81     PasswordManagerHandler* page_;
82     CancelableRequestProvider::Handle pending_login_query_;
83   };
84
85   // A short class to mediate requests to the password store for passwordlist.
86   class PasswordListPopulater : public ListPopulater {
87    public:
88     explicit PasswordListPopulater(PasswordManagerHandler* page);
89
90     // Send a query to the password store to populate a password list.
91     virtual void Populate() OVERRIDE;
92
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;
99   };
100
101   // A short class to mediate requests to the password store for exceptions.
102   class PasswordExceptionListPopulater : public ListPopulater {
103    public:
104     explicit PasswordExceptionListPopulater(PasswordManagerHandler* page);
105
106     // Send a query to the password store to populate a passwordException list.
107     virtual void Populate() OVERRIDE;
108
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;
115   };
116
117   // Password store consumer for populating the password list and exceptions.
118   PasswordListPopulater populater_;
119   PasswordExceptionListPopulater exception_populater_;
120
121   ScopedVector<autofill::PasswordForm> password_list_;
122   ScopedVector<autofill::PasswordForm> password_exception_list_;
123
124   // User's pref
125   std::string languages_;
126
127   // Whether to show stored passwords or not.
128   BooleanPrefMember show_passwords_;
129
130   // Indicates whether or not the password manager should require the user to
131   // reauthenticate before revealing plaintext passwords.
132   bool require_reauthentication_;
133
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_;
137
138   DISALLOW_COPY_AND_ASSIGN(PasswordManagerHandler);
139 };
140
141 }  // namespace options
142
143 #endif  // CHROME_BROWSER_UI_WEBUI_OPTIONS_PASSWORD_MANAGER_HANDLER_H_