Home | History | Annotate | Download | only in options
      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 "base/time/time.h"
     16 #include "chrome/browser/profiles/profile.h"
     17 #include "chrome/browser/profiles/profile_manager.h"
     18 #include "chrome/browser/search_engines/template_url_service_observer.h"
     19 #include "chrome/browser/shell_integration.h"
     20 #include "chrome/browser/sync/profile_sync_service_observer.h"
     21 #include "chrome/browser/ui/host_desktop.h"
     22 #include "chrome/browser/ui/webui/options/options_ui.h"
     23 #include "ui/base/models/table_model_observer.h"
     24 #include "ui/shell_dialogs/select_file_dialog.h"
     25 
     26 #if defined(OS_CHROMEOS)
     27 #include "chrome/browser/chromeos/system/pointer_device_observer.h"
     28 #endif  // defined(OS_CHROMEOS)
     29 
     30 class AutocompleteController;
     31 class CloudPrintSetupHandler;
     32 class CustomHomePagesTableModel;
     33 class ManagedUserRegistrationUtility;
     34 class TemplateURLService;
     35 
     36 namespace options {
     37 
     38 // Chrome browser options page UI handler.
     39 class BrowserOptionsHandler
     40     : public OptionsPageUIHandler,
     41       public ProfileSyncServiceObserver,
     42       public ui::SelectFileDialog::Listener,
     43       public ShellIntegration::DefaultWebClientObserver,
     44 #if defined(OS_CHROMEOS)
     45       public chromeos::system::PointerDeviceObserver::Observer,
     46 #endif
     47       public TemplateURLServiceObserver {
     48  public:
     49   BrowserOptionsHandler();
     50   virtual ~BrowserOptionsHandler();
     51 
     52   // OptionsPageUIHandler implementation.
     53   virtual void GetLocalizedValues(DictionaryValue* values) OVERRIDE;
     54   virtual void PageLoadStarted() OVERRIDE;
     55   virtual void InitializeHandler() OVERRIDE;
     56   virtual void InitializePage() OVERRIDE;
     57   virtual void RegisterMessages() OVERRIDE;
     58 
     59   // ProfileSyncServiceObserver implementation.
     60   virtual void OnStateChanged() OVERRIDE;
     61 
     62   // ShellIntegration::DefaultWebClientObserver implementation.
     63   virtual void SetDefaultWebClientUIState(
     64       ShellIntegration::DefaultWebClientUIState state) OVERRIDE;
     65   virtual bool IsInteractiveSetDefaultPermitted() OVERRIDE;
     66 
     67   // TemplateURLServiceObserver implementation.
     68   virtual void OnTemplateURLServiceChanged() OVERRIDE;
     69 
     70  private:
     71   // content::NotificationObserver implementation.
     72   virtual void Observe(int type,
     73                        const content::NotificationSource& source,
     74                        const content::NotificationDetails& details) OVERRIDE;
     75 
     76 #if defined(ENABLE_FULL_PRINTING) && !defined(OS_CHROMEOS)
     77   void OnCloudPrintPrefsChanged();
     78 #endif
     79 
     80   // SelectFileDialog::Listener implementation
     81   virtual void FileSelected(const base::FilePath& path,
     82                             int index,
     83                             void* params) OVERRIDE;
     84 
     85 #if defined(OS_CHROMEOS)
     86   // PointerDeviceObserver::Observer implementation.
     87   virtual void TouchpadExists(bool exists) OVERRIDE;
     88   virtual void MouseExists(bool exists) OVERRIDE;
     89 #endif
     90 
     91   void UpdateSyncState();
     92 
     93   // Will be called when the kSigninAllowed pref has changed.
     94   void OnSigninAllowedPrefChange();
     95 
     96   // Makes this the default browser. Called from WebUI.
     97   void BecomeDefaultBrowser(const base::ListValue* args);
     98 
     99   // Sets the search engine at the given index to be default. Called from WebUI.
    100   void SetDefaultSearchEngine(const base::ListValue* args);
    101 
    102   // Enables/disables auto-launching of Chrome on computer startup.
    103   void ToggleAutoLaunch(const base::ListValue* args);
    104 
    105   // Checks (on the file thread) whether the user is in the auto-launch trial
    106   // and whether Chrome is set to auto-launch at login. Gets a reply on the UI
    107   // thread (see CheckAutoLaunchCallback). A weak pointer to this is passed in
    108   // as a parameter to avoid the need to lock between this function and the
    109   // destructor. |profile_path| is the full path to the current profile.
    110   static void CheckAutoLaunch(base::WeakPtr<BrowserOptionsHandler> weak_this,
    111                               const base::FilePath& profile_path);
    112 
    113   // Sets up (on the UI thread) the necessary bindings for toggling auto-launch
    114   // (if the user is part of the auto-launch and makes sure the HTML UI knows
    115   // whether Chrome will auto-launch at login.
    116   void CheckAutoLaunchCallback(bool is_in_auto_launch_group,
    117                                bool will_launch_at_login);
    118 
    119   // Returns the string ID for the given default browser state.
    120   int StatusStringIdForState(ShellIntegration::DefaultWebClientState state);
    121 
    122   // Gets the current default browser state, and asynchronously reports it to
    123   // the WebUI page.
    124   void UpdateDefaultBrowserState();
    125 
    126   // Updates the UI with the given state for the default browser.
    127   void SetDefaultBrowserUIString(int status_string_id);
    128 
    129   // Loads the possible default search engine list and reports it to the WebUI.
    130   void AddTemplateUrlServiceObserver();
    131 
    132   // Creates a list of dictionaries where each dictionary is of the form:
    133   //   profileInfo = {
    134   //     name: "Profile Name",
    135   //     iconURL: "chrome://path/to/icon/image",
    136   //     filePath: "/path/to/profile/data/on/disk",
    137   //     isCurrentProfile: false
    138   //   };
    139   scoped_ptr<ListValue> GetProfilesInfoList();
    140 
    141   // Sends an array of Profile objects to javascript.
    142   void SendProfilesInfo();
    143 
    144   // Returns the current desktop type.
    145   chrome::HostDesktopType GetDesktopType();
    146 
    147   // Asynchronously creates and initializes a new profile.
    148   // The arguments are as follows:
    149   //   0: name (string)
    150   //   1: icon (string)
    151   //   2: a flag stating whether we should create a profile desktop shortcut
    152   //      (optional, boolean)
    153   //   3: a flag stating whether the user should be managed (optional, boolean)
    154   void CreateProfile(const base::ListValue* args);
    155 
    156   // After a new managed-user profile has been created, registers the user with
    157   // the management server.
    158   void RegisterManagedUser(const ProfileManager::CreateCallback& callback,
    159                            const std::string& managed_user_id,
    160                            Profile* new_profile,
    161                            Profile::CreateStatus status);
    162 
    163   // Records UMA histograms relevant to profile creation.
    164   void RecordProfileCreationMetrics(Profile::CreateStatus status);
    165 
    166   // Updates the UI as the final task after a new profile has been created.
    167   void ShowProfileCreationFeedback(
    168       chrome::HostDesktopType desktop_type,
    169       bool is_managed,
    170       Profile* profile,
    171       Profile::CreateStatus status);
    172 
    173   // Deletes the given profile. Expects one argument:
    174   //   0: profile file path (string)
    175   void DeleteProfile(const base::ListValue* args);
    176 
    177   // Deletes the profile at the given |file_path|.
    178   void DeleteProfileAtPath(base::FilePath file_path);
    179 
    180   // Cancels creation of a managed-user profile currently in progress, as
    181   // indicated by profile_path_being_created_, removing the object and files
    182   // and canceling managed-user registration. This is the handler for the
    183   // "cancelCreateProfile" message. |args| is not used.
    184   // TODO(pamg): Move all the profile-handling methods into a more appropriate
    185   // class.
    186   void HandleCancelProfileCreation(const base::ListValue* args);
    187 
    188   // Internal implementation. This may safely be called whether profile creation
    189   // or registration is in progress or not. |user_initiated| should be true if
    190   // the cancellation was deliberately requested by the user, and false if it
    191   // was caused implicitly, e.g. by shutting down the browser.
    192   void CancelProfileRegistration(bool user_initiated);
    193 
    194   void ObserveThemeChanged();
    195   void ThemesReset(const base::ListValue* args);
    196 #if defined(OS_LINUX) && !defined(OS_CHROMEOS)
    197   void ThemesSetNative(const base::ListValue* args);
    198 #endif
    199 
    200 #if defined(OS_CHROMEOS)
    201   void UpdateAccountPicture();
    202 #endif
    203 
    204   // Callback for the "selectDownloadLocation" message. This will prompt the
    205   // user for a destination folder using platform-specific APIs.
    206   void HandleSelectDownloadLocation(const ListValue* args);
    207 
    208   // Callback for the "autoOpenFileTypesResetToDefault" message. This will
    209   // remove all auto-open file-type settings.
    210   void HandleAutoOpenButton(const ListValue* args);
    211 
    212   // Callback for the "defaultFontSizeAction" message. This is called if the
    213   // user changes the default font size. |args| is an array that contains
    214   // one item, the font size as a numeric value.
    215   void HandleDefaultFontSize(const ListValue* args);
    216 
    217   // Callback for the "defaultZoomFactorAction" message. This is called if the
    218   // user changes the default zoom factor. |args| is an array that contains
    219   // one item, the zoom factor as a numeric value.
    220   void HandleDefaultZoomFactor(const ListValue* args);
    221 
    222   // Callback for the "Use SSL 3.0" checkbox. This is called if the user toggles
    223   // the "Use SSL 3.0" checkbox.
    224   void HandleUseSSL3Checkbox(const ListValue* args);
    225 
    226   // Callback for the "Use TLS 1.0" checkbox. This is called if the user toggles
    227   // the "Use TLS 1.0" checkbox.
    228   void HandleUseTLS1Checkbox(const ListValue* args);
    229 
    230   // Callback for the "restartBrowser" message. Restores all tabs on restart.
    231   void HandleRestartBrowser(const ListValue* args);
    232 
    233   // Callback for "requestProfilesInfo" message.
    234   void HandleRequestProfilesInfo(const ListValue* args);
    235 
    236 #if !defined(OS_CHROMEOS)
    237   // Callback for the "showNetworkProxySettings" message. This will invoke
    238   // an appropriate dialog for configuring proxy settings.
    239   void ShowNetworkProxySettings(const ListValue* args);
    240 #endif
    241 
    242 #if !defined(USE_NSS)
    243   // Callback for the "showManageSSLCertificates" message. This will invoke
    244   // an appropriate certificate management action based on the platform.
    245   void ShowManageSSLCertificates(const ListValue* args);
    246 #endif
    247 
    248 #if defined(ENABLE_FULL_PRINTING)
    249   // Callback for the Cloud Print manage button. This will open a new
    250   // tab pointed at the management URL.
    251   void ShowCloudPrintManagePage(const ListValue* args);
    252 
    253   // Register localized values used by Cloud Print
    254   void RegisterCloudPrintValues(DictionaryValue* values);
    255 
    256 #if !defined(OS_CHROMEOS)
    257   // Callback for the Sign in to Cloud Print button. This will start
    258   // the authentication process.
    259   void ShowCloudPrintSetupDialog(const ListValue* args);
    260 
    261   // Callback for the Disable Cloud Print button. This will sign out
    262   // of cloud print.
    263   void HandleDisableCloudPrintConnector(const ListValue* args);
    264 
    265   // Pings the service to send us it's current notion of the enabled state.
    266   void RefreshCloudPrintStatusFromService();
    267 
    268   // Setup the enabled or disabled state of the cloud print connector
    269   // management UI.
    270   void SetupCloudPrintConnectorSection();
    271 
    272   // Remove cloud print connector section if cloud print connector management
    273   //  UI is disabled.
    274   void RemoveCloudPrintConnectorSection();
    275 #endif  // defined(OS_CHROMEOS)
    276 #endif  // defined(ENABLE_FULL_PRINTING)
    277 
    278 #if defined(OS_CHROMEOS)
    279   // Opens the wallpaper manager component extension.
    280   void HandleOpenWallpaperManager(const base::ListValue* args);
    281 
    282   // Called when the accessibility checkbox values are changed.
    283   // |args| will contain the checkbox checked state as a string
    284   // ("true" or "false").
    285   void VirtualKeyboardChangeCallback(const base::ListValue* args);
    286 
    287   // Called when the user confirmed factory reset. Chrome will
    288   // initiate asynchronous file operation and then log out.
    289   void PerformFactoryResetRestart(const base::ListValue* args);
    290 #endif
    291 
    292   // Setup the visibility for the metrics reporting setting.
    293   void SetupMetricsReportingSettingVisibility();
    294 
    295   // Setup the visibility for the password generation setting.
    296   void SetupPasswordGenerationSettingVisibility();
    297 
    298   // Setup the font size selector control.
    299   void SetupFontSizeSelector();
    300 
    301   // Setup the page zoom selector control.
    302   void SetupPageZoomSelector();
    303 
    304   // Setup the visibility of the reset button.
    305   void SetupAutoOpenFileTypes();
    306 
    307   // Setup the proxy settings section UI.
    308   void SetupProxySettingsSection();
    309 
    310 #if defined(OS_CHROMEOS)
    311   // Setup the accessibility features for ChromeOS.
    312   void SetupAccessibilityFeatures();
    313 #endif
    314 
    315   bool IsValidExistingManagedUserId(
    316       const std::string& existing_managed_user_id) const;
    317 
    318   // Returns a newly created dictionary with a number of properties that
    319   // correspond to the status of sync.
    320   scoped_ptr<DictionaryValue> GetSyncStateDictionary();
    321 
    322   scoped_refptr<ShellIntegration::DefaultBrowserWorker> default_browser_worker_;
    323 
    324   bool page_initialized_;
    325 
    326   StringPrefMember homepage_;
    327   BooleanPrefMember default_browser_policy_;
    328 
    329   TemplateURLService* template_url_service_;  // Weak.
    330 
    331   // Used to allow cancelling a profile creation (particularly a managed-user
    332   // registration) in progress. Set when profile creation is begun, and
    333   // cleared when all the callbacks have been run and creation is complete.
    334   base::FilePath profile_path_being_created_;
    335 
    336   // Used to track how long profile creation takes.
    337   base::TimeTicks profile_creation_start_time_;
    338 
    339   // Used to get WeakPtr to self for use on the UI thread.
    340   base::WeakPtrFactory<BrowserOptionsHandler> weak_ptr_factory_;
    341 
    342   scoped_refptr<ui::SelectFileDialog> select_folder_dialog_;
    343 
    344 #if defined(ENABLE_FULL_PRINTING) && !defined(OS_CHROMEOS)
    345   StringPrefMember cloud_print_connector_email_;
    346   BooleanPrefMember cloud_print_connector_enabled_;
    347   bool cloud_print_connector_ui_enabled_;
    348 #endif
    349 
    350   StringPrefMember auto_open_files_;
    351   DoublePrefMember default_zoom_level_;
    352 
    353   PrefChangeRegistrar profile_pref_registrar_;
    354 
    355   scoped_ptr<ManagedUserRegistrationUtility> managed_user_registration_utility_;
    356 
    357   DISALLOW_COPY_AND_ASSIGN(BrowserOptionsHandler);
    358 };
    359 
    360 }  // namespace options
    361 
    362 #endif  // CHROME_BROWSER_UI_WEBUI_OPTIONS_BROWSER_OPTIONS_HANDLER_H_
    363