Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / chrome / browser / ui / webui / options / startup_pages_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_STARTUP_PAGES_HANDLER_H_
6 #define CHROME_BROWSER_UI_WEBUI_OPTIONS_STARTUP_PAGES_HANDLER_H_
7
8 #include "base/memory/ref_counted.h"
9 #include "base/memory/scoped_ptr.h"
10 #include "base/memory/weak_ptr.h"
11 #include "base/prefs/pref_change_registrar.h"
12 #include "base/prefs/pref_member.h"
13 #include "chrome/browser/autocomplete/autocomplete_controller_delegate.h"
14 #include "chrome/browser/ui/webui/options/options_ui.h"
15 #include "ui/base/models/table_model_observer.h"
16
17 class AutocompleteController;
18 class CustomHomePagesTableModel;
19 class TemplateURLService;
20
21 namespace options {
22
23 // Chrome browser options page UI handler.
24 class StartupPagesHandler : public OptionsPageUIHandler,
25                             public AutocompleteControllerDelegate,
26                             public ui::TableModelObserver {
27  public:
28   StartupPagesHandler();
29   ~StartupPagesHandler() override;
30
31   // OptionsPageUIHandler implementation.
32   void GetLocalizedValues(base::DictionaryValue* localized_strings) override;
33   void InitializeHandler() override;
34   void InitializePage() override;
35   void RegisterMessages() override;
36
37   // AutocompleteControllerDelegate implementation.
38   void OnResultChanged(bool default_match_changed) override;
39
40   // ui::TableModelObserver implementation.
41   void OnModelChanged() override;
42   void OnItemsChanged(int start, int length) override;
43   void OnItemsAdded(int start, int length) override;
44   void OnItemsRemoved(int start, int length) override;
45
46  private:
47   // Saves the changes that have been made. Called from WebUI.
48   void CommitChanges(const base::ListValue* args);
49
50   // Cancels the changes that have been made. Called from WebUI.
51   void CancelChanges(const base::ListValue* args);
52
53   // Removes the startup page at the given indexes. Called from WebUI.
54   void RemoveStartupPages(const base::ListValue* args);
55
56   // Adds a startup page with the given URL after the given index.
57   // Called from WebUI.
58   void AddStartupPage(const base::ListValue* args);
59
60   // Changes the startup page at the given index to the given URL.
61   // Called from WebUI.
62   void EditStartupPage(const base::ListValue* args);
63
64   // Sets the startup page set to the current pages. Called from WebUI.
65   void SetStartupPagesToCurrentPages(const base::ListValue* args);
66
67   // Writes the current set of startup pages to prefs. Called from WebUI.
68   void DragDropStartupPage(const base::ListValue* args);
69
70   // Gets autocomplete suggestions asychronously for the given string.
71   // Called from WebUI.
72   void RequestAutocompleteSuggestions(const base::ListValue* args);
73
74   // Loads the current set of custom startup pages and reports it to the WebUI.
75   void UpdateStartupPages();
76
77   // Writes the current set of startup pages to prefs.
78   void SaveStartupPagesPref();
79
80   scoped_ptr<AutocompleteController> autocomplete_controller_;
81
82   // Used to observe updates to the preference of the list of URLs to load
83   // on startup, which can be updated via sync.
84   PrefChangeRegistrar pref_change_registrar_;
85
86   // TODO(stuartmorgan): Once there are no other clients of
87   // CustomHomePagesTableModel, consider changing it to something more like
88   // TemplateURLService.
89   scoped_ptr<CustomHomePagesTableModel> startup_custom_pages_table_model_;
90
91   DISALLOW_COPY_AND_ASSIGN(StartupPagesHandler);
92 };
93
94 }  // namespace options
95
96 #endif  // CHROME_BROWSER_UI_WEBUI_OPTIONS_STARTUP_PAGES_HANDLER_H_