Don't show supervised user as "already on this device" while they're being imported.
[chromium-blink-merge.git] / chrome / browser / ui / webui / options / options_ui.h
blobb14a89d6d281eb6ca64ce82084f75c02d8854f6c
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/callback_list.h"
12 #include "base/compiler_specific.h"
13 #include "base/memory/scoped_ptr.h"
14 #include "content/public/browser/notification_registrar.h"
15 #include "content/public/browser/web_contents_observer.h"
16 #include "content/public/browser/web_ui_controller.h"
17 #include "content/public/browser/web_ui_message_handler.h"
18 #include "ui/base/layout.h"
20 class AutocompleteResult;
22 namespace base {
23 class DictionaryValue;
24 class ListValue;
25 class RefCountedMemory;
28 #if defined(OS_CHROMEOS)
29 namespace chromeos {
30 namespace system {
31 class PointerDeviceObserver;
32 } // namespace system
33 } // namespace chromeos
34 #endif
36 namespace options {
38 // The base class handler of Javascript messages of options pages.
39 class OptionsPageUIHandler : public content::WebUIMessageHandler {
40 public:
41 // Key for identifying the Settings App localized_strings in loadTimeData.
42 static const char kSettingsAppKey[];
44 OptionsPageUIHandler();
45 ~OptionsPageUIHandler() override;
47 // Is this handler enabled?
48 virtual bool IsEnabled();
50 // Collects localized strings for options page.
51 virtual void GetLocalizedValues(base::DictionaryValue* localized_strings) = 0;
53 virtual void PageLoadStarted() {}
55 // Will be called only once in the life time of the handler. Generally used to
56 // add observers, initializes preferences, or start asynchronous calls from
57 // various services.
58 virtual void InitializeHandler() {}
60 // Initialize the page. Called once the DOM is available for manipulation.
61 // This will be called when a RenderView is re-used (when navigated to with
62 // back/forward or session restored in some cases) or when created.
63 virtual void InitializePage() {}
65 // Uninitializes the page. Called just before the object is destructed.
66 virtual void Uninitialize() {}
68 // WebUIMessageHandler implementation.
69 void RegisterMessages() override {}
71 protected:
72 struct OptionsStringResource {
73 // The name of the resource in templateData.
74 const char* name;
75 // The .grd ID for the resource (IDS_*).
76 int id;
77 // The .grd ID of the string to replace $1 in |id|'s string. If zero or
78 // omitted (default initialized), no substitution is attempted.
79 int substitution_id;
82 // A helper to simplify string registration in WebUI for strings which do not
83 // change at runtime and optionally contain a single substitution.
84 static void RegisterStrings(base::DictionaryValue* localized_strings,
85 const OptionsStringResource* resources,
86 size_t length);
88 // Registers string resources for a page's header and tab title.
89 static void RegisterTitle(base::DictionaryValue* localized_strings,
90 const std::string& variable_name,
91 int title_id);
93 content::NotificationRegistrar registrar_;
95 private:
96 DISALLOW_COPY_AND_ASSIGN(OptionsPageUIHandler);
99 // An interface for common operations that a host of OptionsPageUIHandlers
100 // should provide.
101 class OptionsPageUIHandlerHost {
102 public:
103 virtual void InitializeHandlers() = 0;
104 virtual void OnFinishedLoading() {}
106 protected:
107 virtual ~OptionsPageUIHandlerHost() {}
110 // The WebUI for chrome:settings-frame.
111 class OptionsUI : public content::WebUIController,
112 public content::WebContentsObserver,
113 public OptionsPageUIHandlerHost {
114 public:
115 typedef base::CallbackList<void()> OnFinishedLoadingCallbackList;
117 explicit OptionsUI(content::WebUI* web_ui);
118 ~OptionsUI() override;
120 // Registers a callback to be called once the settings frame has finished
121 // loading on the HTML/JS side.
122 scoped_ptr<OnFinishedLoadingCallbackList::Subscription>
123 RegisterOnFinishedLoadingCallback(const base::Closure& callback);
125 // Takes the suggestions from |result| and adds them to |suggestions| so that
126 // they can be passed to a JavaScript function.
127 static void ProcessAutocompleteSuggestions(
128 const AutocompleteResult& result,
129 base::ListValue* const suggestions);
131 static base::RefCountedMemory* GetFaviconResourceBytes(
132 ui::ScaleFactor scale_factor);
134 // Overridden from content::WebContentsObserver:
135 void DidStartProvisionalLoadForFrame(
136 content::RenderFrameHost* render_frame_host,
137 const GURL& validated_url,
138 bool is_error_page,
139 bool is_iframe_srcdoc) override;
141 // Overridden from OptionsPageUIHandlerHost:
142 void InitializeHandlers() override;
143 void OnFinishedLoading() override;
145 private:
146 // Adds OptionsPageUiHandler to the handlers list if handler is enabled.
147 void AddOptionsPageUIHandler(base::DictionaryValue* localized_strings,
148 OptionsPageUIHandler* handler);
150 bool initialized_handlers_;
152 std::vector<OptionsPageUIHandler*> handlers_;
153 OnFinishedLoadingCallbackList on_finished_loading_callbacks_;
155 #if defined(OS_CHROMEOS)
156 scoped_ptr<chromeos::system::PointerDeviceObserver>
157 pointer_device_observer_;
158 #endif
160 DISALLOW_COPY_AND_ASSIGN(OptionsUI);
163 } // namespace options
165 #endif // CHROME_BROWSER_UI_WEBUI_OPTIONS_OPTIONS_UI_H_