- add sources.
[platform/framework/web/crosswalk.git] / src / chrome / browser / ui / webui / options / browser_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_BROWSER_OPTIONS_HANDLER_H_
6 #define CHROME_BROWSER_UI_WEBUI_OPTIONS_BROWSER_OPTIONS_HANDLER_H_
7
8 #include <vector>
9
10 #include "base/memory/ref_counted.h"
11 #include "base/memory/scoped_ptr.h"
12 #include "base/memory/weak_ptr.h"
13 #include "base/prefs/pref_change_registrar.h"
14 #include "base/prefs/pref_member.h"
15 #include "chrome/browser/profiles/profile.h"
16 #include "chrome/browser/search_engines/template_url_service_observer.h"
17 #include "chrome/browser/shell_integration.h"
18 #include "chrome/browser/sync/profile_sync_service_observer.h"
19 #include "chrome/browser/ui/host_desktop.h"
20 #include "chrome/browser/ui/webui/options/options_ui.h"
21 #include "google_apis/gaia/google_service_auth_error.h"
22 #include "ui/base/models/table_model_observer.h"
23 #include "ui/shell_dialogs/select_file_dialog.h"
24
25 #if defined(OS_CHROMEOS)
26 #include "chrome/browser/chromeos/system/pointer_device_observer.h"
27 #endif  // defined(OS_CHROMEOS)
28
29 class AutocompleteController;
30 class CloudPrintSetupHandler;
31 class CustomHomePagesTableModel;
32 class TemplateURLService;
33
34 namespace options {
35
36 // Chrome browser options page UI handler.
37 class BrowserOptionsHandler
38     : public OptionsPageUIHandler,
39       public ProfileSyncServiceObserver,
40       public ui::SelectFileDialog::Listener,
41       public ShellIntegration::DefaultWebClientObserver,
42 #if defined(OS_CHROMEOS)
43       public chromeos::system::PointerDeviceObserver::Observer,
44 #endif
45       public TemplateURLServiceObserver {
46  public:
47   BrowserOptionsHandler();
48   virtual ~BrowserOptionsHandler();
49
50   // OptionsPageUIHandler implementation.
51   virtual void GetLocalizedValues(DictionaryValue* values) OVERRIDE;
52   virtual void PageLoadStarted() OVERRIDE;
53   virtual void InitializeHandler() OVERRIDE;
54   virtual void InitializePage() OVERRIDE;
55   virtual void RegisterMessages() OVERRIDE;
56   virtual void Uninitialize() OVERRIDE;
57
58   // ProfileSyncServiceObserver implementation.
59   virtual void OnStateChanged() OVERRIDE;
60
61   // ShellIntegration::DefaultWebClientObserver implementation.
62   virtual void SetDefaultWebClientUIState(
63       ShellIntegration::DefaultWebClientUIState state) OVERRIDE;
64   virtual bool IsInteractiveSetDefaultPermitted() OVERRIDE;
65
66   // TemplateURLServiceObserver implementation.
67   virtual void OnTemplateURLServiceChanged() OVERRIDE;
68
69  private:
70   // content::NotificationObserver implementation.
71   virtual void Observe(int type,
72                        const content::NotificationSource& source,
73                        const content::NotificationDetails& details) OVERRIDE;
74
75 #if defined(ENABLE_FULL_PRINTING) && !defined(OS_CHROMEOS)
76   void OnCloudPrintPrefsChanged();
77 #endif
78
79   // SelectFileDialog::Listener implementation
80   virtual void FileSelected(const base::FilePath& path,
81                             int index,
82                             void* params) OVERRIDE;
83
84 #if defined(OS_CHROMEOS)
85   // PointerDeviceObserver::Observer implementation.
86   virtual void TouchpadExists(bool exists) OVERRIDE;
87   virtual void MouseExists(bool exists) OVERRIDE;
88 #endif
89
90   void UpdateSyncState();
91
92   // Will be called when the kSigninAllowed pref has changed.
93   void OnSigninAllowedPrefChange();
94
95   // Makes this the default browser. Called from WebUI.
96   void BecomeDefaultBrowser(const base::ListValue* args);
97
98   // Sets the search engine at the given index to be default. Called from WebUI.
99   void SetDefaultSearchEngine(const base::ListValue* args);
100
101   // Enables/disables auto-launching of Chrome on computer startup.
102   void ToggleAutoLaunch(const base::ListValue* args);
103
104   // Checks (on the file thread) whether the user is in the auto-launch trial
105   // and whether Chrome is set to auto-launch at login. Gets a reply on the UI
106   // thread (see CheckAutoLaunchCallback). A weak pointer to this is passed in
107   // as a parameter to avoid the need to lock between this function and the
108   // destructor. |profile_path| is the full path to the current profile.
109   static void CheckAutoLaunch(base::WeakPtr<BrowserOptionsHandler> weak_this,
110                               const base::FilePath& profile_path);
111
112   // Sets up (on the UI thread) the necessary bindings for toggling auto-launch
113   // (if the user is part of the auto-launch and makes sure the HTML UI knows
114   // whether Chrome will auto-launch at login.
115   void CheckAutoLaunchCallback(bool is_in_auto_launch_group,
116                                bool will_launch_at_login);
117
118   // Returns the string ID for the given default browser state.
119   int StatusStringIdForState(ShellIntegration::DefaultWebClientState state);
120
121   // Gets the current default browser state, and asynchronously reports it to
122   // the WebUI page.
123   void UpdateDefaultBrowserState();
124
125   // Updates the UI with the given state for the default browser.
126   void SetDefaultBrowserUIString(int status_string_id);
127
128   // Loads the possible default search engine list and reports it to the WebUI.
129   void AddTemplateUrlServiceObserver();
130
131   // Creates a list of dictionaries where each dictionary is of the form:
132   //   profileInfo = {
133   //     name: "Profile Name",
134   //     iconURL: "chrome://path/to/icon/image",
135   //     filePath: "/path/to/profile/data/on/disk",
136   //     isCurrentProfile: false
137   //   };
138   scoped_ptr<ListValue> GetProfilesInfoList();
139
140   // Sends an array of Profile objects to javascript.
141   void SendProfilesInfo();
142
143   // Deletes the given profile. Expects one argument:
144   //   0: profile file path (string)
145   void DeleteProfile(const base::ListValue* args);
146
147   void ObserveThemeChanged();
148   void ThemesReset(const base::ListValue* args);
149 #if defined(OS_LINUX) && !defined(OS_CHROMEOS)
150   void ThemesSetNative(const base::ListValue* args);
151 #endif
152
153 #if defined(OS_CHROMEOS)
154   void UpdateAccountPicture();
155 #endif
156
157   // Callback for the "selectDownloadLocation" message. This will prompt the
158   // user for a destination folder using platform-specific APIs.
159   void HandleSelectDownloadLocation(const ListValue* args);
160
161   // Callback for the "autoOpenFileTypesResetToDefault" message. This will
162   // remove all auto-open file-type settings.
163   void HandleAutoOpenButton(const ListValue* args);
164
165   // Callback for the "defaultFontSizeAction" message. This is called if the
166   // user changes the default font size. |args| is an array that contains
167   // one item, the font size as a numeric value.
168   void HandleDefaultFontSize(const ListValue* args);
169
170   // Callback for the "defaultZoomFactorAction" message. This is called if the
171   // user changes the default zoom factor. |args| is an array that contains
172   // one item, the zoom factor as a numeric value.
173   void HandleDefaultZoomFactor(const ListValue* args);
174
175   // Callback for the "Use SSL 3.0" checkbox. This is called if the user toggles
176   // the "Use SSL 3.0" checkbox.
177   void HandleUseSSL3Checkbox(const ListValue* args);
178
179   // Callback for the "Use TLS 1.0" checkbox. This is called if the user toggles
180   // the "Use TLS 1.0" checkbox.
181   void HandleUseTLS1Checkbox(const ListValue* args);
182
183   // Callback for the "restartBrowser" message. Restores all tabs on restart.
184   void HandleRestartBrowser(const ListValue* args);
185
186   // Callback for "requestProfilesInfo" message.
187   void HandleRequestProfilesInfo(const ListValue* args);
188
189 #if !defined(OS_CHROMEOS)
190   // Callback for the "showNetworkProxySettings" message. This will invoke
191   // an appropriate dialog for configuring proxy settings.
192   void ShowNetworkProxySettings(const ListValue* args);
193 #endif
194
195 #if !defined(USE_NSS)
196   // Callback for the "showManageSSLCertificates" message. This will invoke
197   // an appropriate certificate management action based on the platform.
198   void ShowManageSSLCertificates(const ListValue* args);
199 #endif
200
201 #if defined(ENABLE_MDNS)
202   void ShowCloudPrintDevicesPage(const ListValue* args);
203 #endif
204
205 #if defined(ENABLE_FULL_PRINTING)
206   // Callback for the Cloud Print manage button. This will open a new
207   // tab pointed at the management URL.
208   void ShowCloudPrintManagePage(const ListValue* args);
209
210   // Register localized values used by Cloud Print
211   void RegisterCloudPrintValues(DictionaryValue* values);
212
213 #if !defined(OS_CHROMEOS)
214   // Callback for the Sign in to Cloud Print button. This will start
215   // the authentication process.
216   void ShowCloudPrintSetupDialog(const ListValue* args);
217
218   // Callback for the Disable Cloud Print button. This will sign out
219   // of cloud print.
220   void HandleDisableCloudPrintConnector(const ListValue* args);
221
222   // Pings the service to send us it's current notion of the enabled state.
223   void RefreshCloudPrintStatusFromService();
224
225   // Setup the enabled or disabled state of the cloud print connector
226   // management UI.
227   void SetupCloudPrintConnectorSection();
228
229   // Remove cloud print connector section if cloud print connector management
230   //  UI is disabled.
231   void RemoveCloudPrintConnectorSection();
232 #endif  // defined(OS_CHROMEOS)
233 #endif  // defined(ENABLE_FULL_PRINTING)
234
235 #if defined(OS_CHROMEOS)
236   // Opens the wallpaper manager component extension.
237   void HandleOpenWallpaperManager(const base::ListValue* args);
238
239   // Called when the accessibility checkbox values are changed.
240   // |args| will contain the checkbox checked state as a string
241   // ("true" or "false").
242   void VirtualKeyboardChangeCallback(const base::ListValue* args);
243
244   // Called when the user confirmed factory reset. Chrome will
245   // initiate asynchronous file operation and then log out.
246   void PerformFactoryResetRestart(const base::ListValue* args);
247 #endif
248
249   // Setup the visibility for the metrics reporting setting.
250   void SetupMetricsReportingSettingVisibility();
251
252   // Setup the visibility for the password generation setting.
253   void SetupPasswordGenerationSettingVisibility();
254
255   // Setup the font size selector control.
256   void SetupFontSizeSelector();
257
258   // Setup the page zoom selector control.
259   void SetupPageZoomSelector();
260
261   // Setup the visibility of the reset button.
262   void SetupAutoOpenFileTypes();
263
264   // Setup the proxy settings section UI.
265   void SetupProxySettingsSection();
266
267   // Setup the UI specific to managing supervised users.
268   void SetupManagingSupervisedUsers();
269
270 #if defined(OS_CHROMEOS)
271   // Setup the accessibility features for ChromeOS.
272   void SetupAccessibilityFeatures();
273 #endif
274
275   // Returns a newly created dictionary with a number of properties that
276   // correspond to the status of sync.
277   scoped_ptr<DictionaryValue> GetSyncStateDictionary();
278
279   scoped_refptr<ShellIntegration::DefaultBrowserWorker> default_browser_worker_;
280
281   bool page_initialized_;
282
283   StringPrefMember homepage_;
284   BooleanPrefMember default_browser_policy_;
285
286   TemplateURLService* template_url_service_;  // Weak.
287
288   scoped_refptr<ui::SelectFileDialog> select_folder_dialog_;
289
290 #if defined(ENABLE_FULL_PRINTING) && !defined(OS_CHROMEOS)
291   StringPrefMember cloud_print_connector_email_;
292   BooleanPrefMember cloud_print_connector_enabled_;
293   bool cloud_print_connector_ui_enabled_;
294 #endif
295
296   bool cloud_print_mdns_ui_enabled_;
297
298   StringPrefMember auto_open_files_;
299   DoublePrefMember default_zoom_level_;
300
301   PrefChangeRegistrar profile_pref_registrar_;
302
303   // Used to get WeakPtr to self for use on the UI thread.
304   base::WeakPtrFactory<BrowserOptionsHandler> weak_ptr_factory_;
305
306   DISALLOW_COPY_AND_ASSIGN(BrowserOptionsHandler);
307 };
308
309 }  // namespace options
310
311 #endif  // CHROME_BROWSER_UI_WEBUI_OPTIONS_BROWSER_OPTIONS_HANDLER_H_