Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / chrome / browser / ui / webui / options / autofill_options_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_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 AutofillProfile;
16 class PersonalDataManager;
17 }  // namespace autofill
18
19 namespace base {
20 class DictionaryValue;
21 class ListValue;
22 }
23
24 namespace options {
25
26 class AutofillOptionsHandler : public OptionsPageUIHandler,
27                                public autofill::PersonalDataManagerObserver {
28  public:
29   AutofillOptionsHandler();
30   ~AutofillOptionsHandler() override;
31
32   // OptionsPageUIHandler implementation.
33   void GetLocalizedValues(base::DictionaryValue* localized_strings) override;
34   void InitializeHandler() override;
35   void InitializePage() override;
36   void RegisterMessages() override;
37
38   // PersonalDataManagerObserver implementation.
39   void OnPersonalDataChanged() override;
40
41  private:
42   FRIEND_TEST_ALL_PREFIXES(AutofillOptionsHandlerTest, AddressToDictionary);
43
44   // Loads the strings for the address and credit card overlays.
45   void SetAddressOverlayStrings(base::DictionaryValue* localized_strings);
46   void SetCreditCardOverlayStrings(base::DictionaryValue* localized_strings);
47
48   // Loads Autofill addresses and credit cards using the PersonalDataManager.
49   void LoadAutofillData();
50
51 #if defined(OS_MACOSX) && !defined(OS_IOS)
52   // The user wants to grant Chrome access to the user's Address Book.
53   // Immediately try to access the Address Book so that the blocking dialog is
54   // shown in context, rather than at a later, surprising time.
55   void AccessAddressBook(const base::ListValue* args);
56 #endif  // defined(OS_MACOSX) && !defined(OS_IOS)
57
58   // Removes data from the PersonalDataManager.
59   // |args| - A string, the GUID of the address or credit card to remove.
60   void RemoveData(const base::ListValue* args);
61
62   // Requests profile data for a specific address. Calls into WebUI with the
63   // loaded profile data to open the address editor.
64   // |args| - A string, the GUID of the address to load.
65   void LoadAddressEditor(const base::ListValue* args);
66
67   // Requests input form layout information for a specific country code. Calls
68   // into WebUI with the layout information.
69   // |args| - A string, the country code to load.
70   void LoadAddressEditorComponents(const base::ListValue* args);
71
72   // Requests profile data for a specific credit card. Calls into WebUI with the
73   // loaded profile data to open the credit card editor.
74   // |args| - A string, the GUID of the credit card to load.
75   void LoadCreditCardEditor(const base::ListValue* args);
76
77   // Adds or updates an address, depending on the GUID of the profile. If the
78   // GUID is empty, a new address is added to the WebDatabase; otherwise, the
79   // address with the matching GUID is updated. Called from WebUI.
80   // |args| - an array containing the GUID of the address followed by the
81   // address data.
82   void SetAddress(const base::ListValue* args);
83
84   // Adds or updates a credit card, depending on the GUID of the profile. If the
85   // GUID is empty, a new credit card is added to the WebDatabase; otherwise,
86   // the credit card with the matching GUID is updated. Called from WebUI.
87   // |args| - an array containing the GUID of the credit card followed by the
88   // credit card data.
89   void SetCreditCard(const base::ListValue* args);
90
91   // Validates a list of phone numbers.  The resulting validated list of
92   // numbers is then sent back to the WebUI.
93   // |args| - an array containing the index of the modified or added number, the
94   // array of numbers, and the country code string set on the profile.
95   void ValidatePhoneNumbers(const base::ListValue* args);
96
97   // Returns true if |personal_data_| is non-null and loaded.
98   bool IsPersonalDataLoaded() const;
99
100   // Fills in |address| with the data format that the options js expects.
101   static void AutofillProfileToDictionary(
102       const autofill::AutofillProfile& profile,
103       base::DictionaryValue* address);
104
105   // The personal data manager, used to load Autofill profiles and credit cards.
106   // Unowned pointer, may not be NULL.
107   autofill::PersonalDataManager* personal_data_;
108
109   DISALLOW_COPY_AND_ASSIGN(AutofillOptionsHandler);
110 };
111
112 }  // namespace options
113
114 #endif  // CHROME_BROWSER_UI_WEBUI_OPTIONS_AUTOFILL_OPTIONS_HANDLER_H_