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_AUTOFILL_OPTIONS_HANDLER_H_ 6 #define CHROME_BROWSER_UI_WEBUI_OPTIONS_AUTOFILL_OPTIONS_HANDLER_H_ 7 8 #include <string> 9 10 #include "base/compiler_specific.h" 11 #include "chrome/browser/ui/webui/options/options_ui.h" 12 #include "components/autofill/core/browser/personal_data_manager_observer.h" 13 14 namespace autofill { 15 class PersonalDataManager; 16 } // namespace autofill 17 18 namespace base { 19 class DictionaryValue; 20 class ListValue; 21 } 22 23 namespace options { 24 25 class AutofillOptionsHandler : public OptionsPageUIHandler, 26 public autofill::PersonalDataManagerObserver { 27 public: 28 AutofillOptionsHandler(); 29 virtual ~AutofillOptionsHandler(); 30 31 // OptionsPageUIHandler implementation. 32 virtual void GetLocalizedValues( 33 base::DictionaryValue* localized_strings) OVERRIDE; 34 virtual void InitializeHandler() OVERRIDE; 35 virtual void InitializePage() OVERRIDE; 36 virtual void RegisterMessages() OVERRIDE; 37 38 // PersonalDataManagerObserver implementation. 39 virtual void OnPersonalDataChanged() OVERRIDE; 40 41 private: 42 // Loads the strings for the address and credit card overlays. 43 void SetAddressOverlayStrings(base::DictionaryValue* localized_strings); 44 void SetCreditCardOverlayStrings(base::DictionaryValue* localized_strings); 45 46 // Loads Autofill addresses and credit cards using the PersonalDataManager. 47 void LoadAutofillData(); 48 49 // Removes data from the PersonalDataManager. 50 // |args| - A string, the GUID of the address or credit card to remove. 51 void RemoveData(const base::ListValue* args); 52 53 // Requests profile data for a specific address. Calls into WebUI with the 54 // loaded profile data to open the address editor. 55 // |args| - A string, the GUID of the address to load. 56 void LoadAddressEditor(const base::ListValue* args); 57 58 // Requests profile data for a specific credit card. Calls into WebUI with the 59 // loaded profile data to open the credit card editor. 60 // |args| - A string, the GUID of the credit card to load. 61 void LoadCreditCardEditor(const base::ListValue* args); 62 63 // Adds or updates an address, depending on the GUID of the profile. If the 64 // GUID is empty, a new address is added to the WebDatabase; otherwise, the 65 // address with the matching GUID is updated. Called from WebUI. 66 // |args| - an array containing the GUID of the address followed by the 67 // address data. 68 void SetAddress(const base::ListValue* args); 69 70 // Adds or updates a credit card, depending on the GUID of the profile. If the 71 // GUID is empty, a new credit card is added to the WebDatabase; otherwise, 72 // the credit card with the matching GUID is updated. Called from WebUI. 73 // |args| - an array containing the GUID of the credit card followed by the 74 // credit card data. 75 void SetCreditCard(const base::ListValue* args); 76 77 // Validates a list of phone numbers. The resulting validated list of 78 // numbers is then sent back to the WebUI. 79 // |args| - an array containing the index of the modified or added number, the 80 // array of numbers, and the country code string set on the profile. 81 void ValidatePhoneNumbers(const base::ListValue* args); 82 83 // Returns true if |personal_data_| is non-null and loaded. 84 bool IsPersonalDataLoaded() const; 85 86 // The personal data manager, used to load Autofill profiles and credit cards. 87 // Unowned pointer, may not be NULL. 88 autofill::PersonalDataManager* personal_data_; 89 90 DISALLOW_COPY_AND_ASSIGN(AutofillOptionsHandler); 91 }; 92 93 } // namespace options 94 95 #endif // CHROME_BROWSER_UI_WEBUI_OPTIONS_AUTOFILL_OPTIONS_HANDLER_H_ 96