NaCl: Update revision in DEPS, r12770 -> r12773
[chromium-blink-merge.git] / chrome / browser / ui / webui / options / options_ui.h
blob609eb336652380b524631a80603019ffe93f88fc
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.
5 #ifndef CHROME_BROWSER_UI_WEBUI_OPTIONS_OPTIONS_UI_H_
6 #define CHROME_BROWSER_UI_WEBUI_OPTIONS_OPTIONS_UI_H_
8 #include <string>
9 #include <vector>
11 #include "base/compiler_specific.h"
12 #include "base/memory/scoped_ptr.h"
13 #include "content/public/browser/notification_registrar.h"
14 #include "content/public/browser/web_contents_observer.h"
15 #include "content/public/browser/web_ui_controller.h"
16 #include "content/public/browser/web_ui_message_handler.h"
17 #include "ui/base/layout.h"
19 class AutocompleteResult;
21 namespace base {
22 class DictionaryValue;
23 class ListValue;
24 class RefCountedMemory;
27 #if defined(OS_CHROMEOS)
28 namespace chromeos {
29 namespace system {
30 class PointerDeviceObserver;
31 } // namespace system
32 } // namespace chromeos
33 #endif
35 namespace options {
37 // The base class handler of Javascript messages of options pages.
38 class OptionsPageUIHandler : public content::WebUIMessageHandler {
39 public:
40 // Key for identifying the Settings App localized_strings in loadTimeData.
41 static const char kSettingsAppKey[];
43 OptionsPageUIHandler();
44 virtual ~OptionsPageUIHandler();
46 // Is this handler enabled?
47 virtual bool IsEnabled();
49 // Collects localized strings for options page.
50 virtual void GetLocalizedValues(base::DictionaryValue* localized_strings) = 0;
52 virtual void PageLoadStarted() {}
54 // Will be called only once in the life time of the handler. Generally used to
55 // add observers, initializes preferences, or start asynchronous calls from
56 // various services.
57 virtual void InitializeHandler() {}
59 // Initialize the page. Called once the DOM is available for manipulation.
60 // This will be called when a RenderView is re-used (when navigated to with
61 // back/forward or session restored in some cases) or when created.
62 virtual void InitializePage() {}
64 // Uninitializes the page. Called just before the object is destructed.
65 virtual void Uninitialize() {}
67 // WebUIMessageHandler implementation.
68 virtual void RegisterMessages() OVERRIDE {}
70 protected:
71 struct OptionsStringResource {
72 // The name of the resource in templateData.
73 const char* name;
74 // The .grd ID for the resource (IDS_*).
75 int id;
76 // The .grd ID of the string to replace $1 in |id|'s string. If zero or
77 // omitted (default initialized), no substitution is attempted.
78 int substitution_id;
81 // A helper to simplify string registration in WebUI for strings which do not
82 // change at runtime and optionally contain a single substitution.
83 static void RegisterStrings(base::DictionaryValue* localized_strings,
84 const OptionsStringResource* resources,
85 size_t length);
87 // Registers string resources for a page's header and tab title.
88 static void RegisterTitle(base::DictionaryValue* localized_strings,
89 const std::string& variable_name,
90 int title_id);
92 content::NotificationRegistrar registrar_;
94 private:
95 DISALLOW_COPY_AND_ASSIGN(OptionsPageUIHandler);
98 // An interface for common operations that a host of OptionsPageUIHandlers
99 // should provide.
100 class OptionsPageUIHandlerHost {
101 public:
102 virtual void InitializeHandlers() = 0;
104 protected:
105 virtual ~OptionsPageUIHandlerHost() {}
108 // The WebUI for chrome:settings-frame.
109 class OptionsUI : public content::WebUIController,
110 public content::WebContentsObserver,
111 public OptionsPageUIHandlerHost {
112 public:
113 explicit OptionsUI(content::WebUI* web_ui);
114 virtual ~OptionsUI();
116 // Takes the suggestions from |result| and adds them to |suggestions| so that
117 // they can be passed to a JavaScript function.
118 static void ProcessAutocompleteSuggestions(
119 const AutocompleteResult& result,
120 base::ListValue* const suggestions);
122 static base::RefCountedMemory* GetFaviconResourceBytes(
123 ui::ScaleFactor scale_factor);
125 // Overridden from content::WebContentsObserver:
126 virtual void DidStartProvisionalLoadForFrame(
127 int64 frame_id,
128 int64 parent_frame_id,
129 bool is_main_frame,
130 const GURL& validated_url,
131 bool is_error_page,
132 bool is_iframe_srcdoc,
133 content::RenderViewHost* render_view_host) OVERRIDE;
135 // Overridden from OptionsPageUIHandlerHost:
136 virtual void InitializeHandlers() OVERRIDE;
138 private:
139 // Adds OptionsPageUiHandler to the handlers list if handler is enabled.
140 void AddOptionsPageUIHandler(base::DictionaryValue* localized_strings,
141 OptionsPageUIHandler* handler);
143 bool initialized_handlers_;
145 std::vector<OptionsPageUIHandler*> handlers_;
147 #if defined(OS_CHROMEOS)
148 scoped_ptr<chromeos::system::PointerDeviceObserver>
149 pointer_device_observer_;
150 #endif
152 DISALLOW_COPY_AND_ASSIGN(OptionsUI);
155 } // namespace options
157 #endif // CHROME_BROWSER_UI_WEBUI_OPTIONS_OPTIONS_UI_H_