OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CHROME_BROWSER_UI_WEBUI_OPTIONS2_OPTIONS_UI2_H_ | 5 #ifndef CHROME_BROWSER_UI_WEBUI_OPTIONS2_OPTIONS_UI2_H_ |
6 #define CHROME_BROWSER_UI_WEBUI_OPTIONS2_OPTIONS_UI2_H_ | 6 #define CHROME_BROWSER_UI_WEBUI_OPTIONS2_OPTIONS_UI2_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include <string> | 9 #include <string> |
10 #include <vector> | 10 #include <vector> |
11 | 11 |
12 #include "base/compiler_specific.h" | 12 #include "base/compiler_specific.h" |
13 #include "base/memory/scoped_ptr.h" | 13 #include "base/memory/scoped_ptr.h" |
14 #include "base/values.h" | 14 #include "base/values.h" |
15 #include "chrome/browser/autocomplete/autocomplete.h" | 15 #include "chrome/browser/autocomplete/autocomplete.h" |
16 #include "chrome/browser/ui/webui/chrome_url_data_manager.h" | 16 #include "chrome/browser/ui/webui/chrome_url_data_manager.h" |
17 #include "chrome/browser/ui/webui/options/options_ui.h" | |
18 #include "content/public/browser/notification_observer.h" | 17 #include "content/public/browser/notification_observer.h" |
19 #include "content/public/browser/notification_registrar.h" | 18 #include "content/public/browser/notification_registrar.h" |
20 #include "content/public/browser/notification_types.h" | 19 #include "content/public/browser/notification_types.h" |
21 #include "content/public/browser/web_ui_controller.h" | 20 #include "content/public/browser/web_ui_controller.h" |
22 #include "content/public/browser/web_ui_message_handler.h" | 21 #include "content/public/browser/web_ui_message_handler.h" |
23 | 22 |
24 namespace options2 { | 23 namespace options2 { |
| 24 |
| 25 // The base class handler of Javascript messages of options pages. |
| 26 class OptionsPageUIHandler : public content::WebUIMessageHandler, |
| 27 public content::NotificationObserver { |
| 28 public: |
| 29 OptionsPageUIHandler(); |
| 30 virtual ~OptionsPageUIHandler(); |
| 31 |
| 32 // Is this handler enabled? |
| 33 virtual bool IsEnabled(); |
| 34 |
| 35 // Collects localized strings for options page. |
| 36 virtual void GetLocalizedValues(base::DictionaryValue* localized_strings) = 0; |
| 37 |
| 38 // Will be called only once in the life time of the handler. Generally used to |
| 39 // add observers, initializes preferences, or start asynchronous calls from |
| 40 // various services. |
| 41 virtual void InitializeHandler() {} |
| 42 |
| 43 // Initialize the page. Called once the DOM is available for manipulation. |
| 44 // This will be called when a RenderView is re-used (when navigated to with |
| 45 // back/forward or session restored in some cases) or when created. |
| 46 virtual void InitializePage() {} |
| 47 |
| 48 // Uninitializes the page. Called just before the object is destructed. |
| 49 virtual void Uninitialize() {} |
| 50 |
| 51 // WebUIMessageHandler implementation. |
| 52 virtual void RegisterMessages() OVERRIDE {} |
| 53 |
| 54 // content::NotificationObserver implementation. |
| 55 virtual void Observe(int type, |
| 56 const content::NotificationSource& source, |
| 57 const content::NotificationDetails& details) OVERRIDE {} |
| 58 |
| 59 protected: |
| 60 struct OptionsStringResource { |
| 61 // The name of the resource in templateData. |
| 62 const char* name; |
| 63 // The .grd ID for the resource (IDS_*). |
| 64 int id; |
| 65 }; |
| 66 // A helper for simplifying the process of registering strings in WebUI. |
| 67 static void RegisterStrings(base::DictionaryValue* localized_strings, |
| 68 const OptionsStringResource* resources, |
| 69 size_t length); |
| 70 |
| 71 // Registers string resources for a page's header and tab title. |
| 72 static void RegisterTitle(base::DictionaryValue* localized_strings, |
| 73 const std::string& variable_name, |
| 74 int title_id); |
| 75 |
| 76 content::NotificationRegistrar registrar_; |
| 77 |
| 78 private: |
| 79 DISALLOW_COPY_AND_ASSIGN(OptionsPageUIHandler); |
| 80 }; |
| 81 |
| 82 // An interface for common operations that a host of OptionsPageUIHandlers |
| 83 // should provide. |
| 84 class OptionsPageUIHandlerHost { |
| 85 public: |
| 86 virtual void InitializeHandlers() = 0; |
| 87 |
| 88 protected: |
| 89 virtual ~OptionsPageUIHandlerHost() {} |
| 90 }; |
| 91 |
25 // The WebUI for chrome:settings-frame. | 92 // The WebUI for chrome:settings-frame. |
26 class OptionsUI : public content::WebUIController, | 93 class OptionsUI : public content::WebUIController, |
27 public OptionsPageUIHandlerHost { | 94 public OptionsPageUIHandlerHost { |
28 public: | 95 public: |
29 explicit OptionsUI(content::WebUI* web_ui); | 96 explicit OptionsUI(content::WebUI* web_ui); |
30 virtual ~OptionsUI(); | 97 virtual ~OptionsUI(); |
31 | 98 |
32 // Takes the suggestions from |autocompleteResult| and adds them to | 99 // Takes the suggestions from |autocompleteResult| and adds them to |
33 // |suggestions| so that they can be passed to a JavaScript function. | 100 // |suggestions| so that they can be passed to a JavaScript function. |
34 static void ProcessAutocompleteSuggestions( | 101 static void ProcessAutocompleteSuggestions( |
(...skipping 24 matching lines...) Expand all Loading... |
59 bool initialized_handlers_; | 126 bool initialized_handlers_; |
60 | 127 |
61 std::vector<OptionsPageUIHandler*> handlers_; | 128 std::vector<OptionsPageUIHandler*> handlers_; |
62 | 129 |
63 DISALLOW_COPY_AND_ASSIGN(OptionsUI); | 130 DISALLOW_COPY_AND_ASSIGN(OptionsUI); |
64 }; | 131 }; |
65 | 132 |
66 } // namespace options2 | 133 } // namespace options2 |
67 | 134 |
68 #endif // CHROME_BROWSER_UI_WEBUI_OPTIONS2_OPTIONS_UI2_H_ | 135 #endif // CHROME_BROWSER_UI_WEBUI_OPTIONS2_OPTIONS_UI2_H_ |
OLD | NEW |