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 content { 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 // Get password value for the selected entry. 59 // @param value the selected entry index. 60 void ShowSelectedPassword(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 // A short class to mediate requests to the password store. 68 class ListPopulater : public PasswordStoreConsumer { 69 public: 70 explicit ListPopulater(PasswordManagerHandler* page); 71 virtual ~ListPopulater(); 72 73 // Send a query to the password store to populate a list. 74 virtual void Populate() = 0; 75 76 protected: 77 PasswordManagerHandler* page_; 78 CancelableRequestProvider::Handle pending_login_query_; 79 }; 80 81 // A short class to mediate requests to the password store for passwordlist. 82 class PasswordListPopulater : public ListPopulater { 83 public: 84 explicit PasswordListPopulater(PasswordManagerHandler* page); 85 86 // Send a query to the password store to populate a password list. 87 virtual void Populate() OVERRIDE; 88 89 // Send the password store's reply back to the handler. 90 virtual void OnPasswordStoreRequestDone( 91 CancelableRequestProvider::Handle handle, 92 const std::vector<content::PasswordForm*>& result) OVERRIDE; 93 virtual void OnGetPasswordStoreResults( 94 const std::vector<content::PasswordForm*>& results) OVERRIDE; 95 }; 96 97 // A short class to mediate requests to the password store for exceptions. 98 class PasswordExceptionListPopulater : public ListPopulater { 99 public: 100 explicit PasswordExceptionListPopulater(PasswordManagerHandler* page); 101 102 // Send a query to the password store to populate a passwordException list. 103 virtual void Populate() OVERRIDE; 104 105 // Send the password store's reply back to the handler. 106 virtual void OnPasswordStoreRequestDone( 107 CancelableRequestProvider::Handle handle, 108 const std::vector<content::PasswordForm*>& result) OVERRIDE; 109 virtual void OnGetPasswordStoreResults( 110 const std::vector<content::PasswordForm*>& results) OVERRIDE; 111 }; 112 113 // Password store consumer for populating the password list and exceptions. 114 PasswordListPopulater populater_; 115 PasswordExceptionListPopulater exception_populater_; 116 117 ScopedVector<content::PasswordForm> password_list_; 118 ScopedVector<content::PasswordForm> password_exception_list_; 119 120 // User's pref 121 std::string languages_; 122 123 // Whether to show stored passwords or not. 124 BooleanPrefMember show_passwords_; 125 126 DISALLOW_COPY_AND_ASSIGN(PasswordManagerHandler); 127 }; 128 129 } // namespace options 130 131 #endif // CHROME_BROWSER_UI_WEBUI_OPTIONS_PASSWORD_MANAGER_HANDLER_H_ 132