Home | History | Annotate | Download | only in options
      1 // Copyright (c) 2011 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 #pragma once
      8 
      9 #include "chrome/browser/autocomplete/autocomplete_controller_delegate.h"
     10 #include "chrome/browser/prefs/pref_member.h"
     11 #include "chrome/browser/search_engines/template_url_model_observer.h"
     12 #include "chrome/browser/shell_integration.h"
     13 #include "chrome/browser/ui/webui/options/options_ui.h"
     14 #include "ui/base/models/table_model_observer.h"
     15 
     16 class AutocompleteController;
     17 class CustomHomePagesTableModel;
     18 class OptionsManagedBannerHandler;
     19 class TemplateURLModel;
     20 
     21 // Chrome browser options page UI handler.
     22 class BrowserOptionsHandler : public OptionsPageUIHandler,
     23                               public AutocompleteControllerDelegate,
     24                               public ShellIntegration::DefaultBrowserObserver,
     25                               public TemplateURLModelObserver,
     26                               public ui::TableModelObserver {
     27  public:
     28   BrowserOptionsHandler();
     29   virtual ~BrowserOptionsHandler();
     30 
     31   virtual void Initialize();
     32 
     33   // OptionsPageUIHandler implementation.
     34   virtual void GetLocalizedValues(DictionaryValue* localized_strings);
     35   virtual void RegisterMessages();
     36 
     37   // AutocompleteControllerDelegate implementation.
     38   virtual void OnResultChanged(bool default_match_changed);
     39 
     40   // ShellIntegration::DefaultBrowserObserver implementation.
     41   virtual void SetDefaultBrowserUIState(
     42       ShellIntegration::DefaultBrowserUIState state);
     43 
     44   // TemplateURLModelObserver implementation.
     45   virtual void OnTemplateURLModelChanged();
     46 
     47   // ui::TableModelObserver implementation.
     48   virtual void OnModelChanged();
     49   virtual void OnItemsChanged(int start, int length);
     50   virtual void OnItemsAdded(int start, int length);
     51   virtual void OnItemsRemoved(int start, int length);
     52 
     53  private:
     54   // NotificationObserver implementation.
     55   virtual void Observe(NotificationType type,
     56                        const NotificationSource& source,
     57                        const NotificationDetails& details);
     58 
     59   // Sets the home page to the given string. Called from WebUI.
     60   void SetHomePage(const ListValue* args);
     61 
     62   // Makes this the default browser. Called from WebUI.
     63   void BecomeDefaultBrowser(const ListValue* args);
     64 
     65   // Sets the search engine at the given index to be default. Called from WebUI.
     66   void SetDefaultSearchEngine(const ListValue* args);
     67 
     68   // Removes the startup page at the given indexes. Called from WebUI.
     69   void RemoveStartupPages(const ListValue* args);
     70 
     71   // Adds a startup page with the given URL after the given index.
     72   // Called from WebUI.
     73   void AddStartupPage(const ListValue* args);
     74 
     75   // Changes the startup page at the given index to the given URL.
     76   // Called from WebUI.
     77   void EditStartupPage(const ListValue* args);
     78 
     79   // Sets the startup page set to the current pages. Called from WebUI.
     80   void SetStartupPagesToCurrentPages(const ListValue* args);
     81 
     82   // Gets autocomplete suggestions asychronously for the given string.
     83   // Called from WebUI.
     84   void RequestAutocompleteSuggestions(const ListValue* args);
     85 
     86   // Called when the 'Always show the bookmarks bar' checkbox is toggled.
     87   // Notifies any listeners interested in this event.  |args| is ignored.
     88   void ToggleShowBookmarksBar(const ListValue* args);
     89 
     90   // Returns the string ID for the given default browser state.
     91   int StatusStringIdForState(ShellIntegration::DefaultBrowserState state);
     92 
     93   // Gets the current default browser state, and asynchronously reports it to
     94   // the WebUI page.
     95   void UpdateDefaultBrowserState();
     96 
     97   // Updates the UI with the given state for the default browser.
     98   void SetDefaultBrowserUIString(int status_string_id);
     99 
    100   // Loads the current set of custom startup pages and reports it to the WebUI.
    101   void UpdateStartupPages();
    102 
    103   // Loads the possible default search engine list and reports it to the WebUI.
    104   void UpdateSearchEngines();
    105 
    106   // Writes the current set of startup pages to prefs.
    107   void SaveStartupPagesPref();
    108 
    109   scoped_refptr<ShellIntegration::DefaultBrowserWorker> default_browser_worker_;
    110 
    111   StringPrefMember homepage_;
    112   BooleanPrefMember default_browser_policy_;
    113 
    114   TemplateURLModel* template_url_model_;  // Weak.
    115 
    116   // TODO(stuartmorgan): Once there are no other clients of
    117   // CustomHomePagesTableModel, consider changing it to something more like
    118   // TemplateURLModel.
    119   scoped_ptr<CustomHomePagesTableModel> startup_custom_pages_table_model_;
    120   scoped_ptr<OptionsManagedBannerHandler> banner_handler_;
    121 
    122   scoped_ptr<AutocompleteController> autocomplete_controller_;
    123 
    124   DISALLOW_COPY_AND_ASSIGN(BrowserOptionsHandler);
    125 };
    126 
    127 #endif  // CHROME_BROWSER_UI_WEBUI_OPTIONS_BROWSER_OPTIONS_HANDLER_H_
    128