diff options
author | tfarina@chromium.org <tfarina@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-02-26 15:09:20 +0000 |
---|---|---|
committer | tfarina@chromium.org <tfarina@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-02-26 15:09:20 +0000 |
commit | 5c557f37629dc12dfd99e8fb55c235c8c46a8098 (patch) | |
tree | cdd8f07632d942f10f9b53e52420094e50d10edb /chrome/browser/ui/webui/options/options_ui.h | |
parent | 76433f24ac3a6b5fd09ad0fecfa71eedb253f95a (diff) | |
download | chromium_src-5c557f37629dc12dfd99e8fb55c235c8c46a8098.zip chromium_src-5c557f37629dc12dfd99e8fb55c235c8c46a8098.tar.gz chromium_src-5c557f37629dc12dfd99e8fb55c235c8c46a8098.tar.bz2 |
WebUI: Move chrome/browser/webui/options/ to chrome/browser/ui/webui/options
BUG=59946
TEST=trybots
Review URL: http://codereview.chromium.org/6588037
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@76164 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/ui/webui/options/options_ui.h')
-rw-r--r-- | chrome/browser/ui/webui/options/options_ui.h | 119 |
1 files changed, 119 insertions, 0 deletions
diff --git a/chrome/browser/ui/webui/options/options_ui.h b/chrome/browser/ui/webui/options/options_ui.h new file mode 100644 index 0000000..f912b6c --- /dev/null +++ b/chrome/browser/ui/webui/options/options_ui.h @@ -0,0 +1,119 @@ +// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef CHROME_BROWSER_UI_WEBUI_OPTIONS_OPTIONS_UI_H_ +#define CHROME_BROWSER_UI_WEBUI_OPTIONS_OPTIONS_UI_H_ +#pragma once + +#include <string> + +#include "base/scoped_ptr.h" +#include "chrome/browser/webui/chrome_url_data_manager.h" +#include "chrome/common/notification_observer.h" +#include "chrome/common/notification_registrar.h" +#include "chrome/common/notification_type.h" +#include "content/browser/webui/web_ui.h" + +class GURL; +class PrefService; +struct UserMetricsAction; + +class OptionsUIHTMLSource : public ChromeURLDataManager::DataSource { + public: + // The constructor takes over ownership of |localized_strings|. + explicit OptionsUIHTMLSource(DictionaryValue* localized_strings); + virtual ~OptionsUIHTMLSource(); + + // Called when the network layer has requested a resource underneath + // the path we registered. + virtual void StartDataRequest(const std::string& path, + bool is_off_the_record, + int request_id); + virtual std::string GetMimeType(const std::string&) const; + + private: + // Localized strings collection. + scoped_ptr<DictionaryValue> localized_strings_; + + DISALLOW_COPY_AND_ASSIGN(OptionsUIHTMLSource); +}; + +// The base class handler of Javascript messages of options pages. +class OptionsPageUIHandler : public WebUIMessageHandler, + public NotificationObserver { + public: + OptionsPageUIHandler(); + virtual ~OptionsPageUIHandler(); + + // Is this handler enabled? + virtual bool IsEnabled(); + + // Collects localized strings for options page. + virtual void GetLocalizedValues(DictionaryValue* localized_strings) = 0; + + // Initialize the page. Called once the DOM is available for manipulation. + // This will be called only once. + virtual void Initialize() {} + + // Uninitializes the page. Called just before the object is destructed. + virtual void Uninitialize() {} + + // WebUIMessageHandler implementation. + virtual void RegisterMessages() {} + + // NotificationObserver implementation. + virtual void Observe(NotificationType type, + const NotificationSource& source, + const NotificationDetails& details) {} + + void UserMetricsRecordAction(const UserMetricsAction& action); + + protected: + struct OptionsStringResource { + // The name of the resource in templateData. + const char* name; + // The .grd ID for the resource (IDS_*). + int id; + // True if the trailing colon should be stripped on platforms that + // don't want trailing colons. + bool strip_colon; + }; + // A helper for simplifying the process of registering strings in WebUI. + static void RegisterStrings(DictionaryValue* localized_strings, + const OptionsStringResource* resources, + size_t length); + + // Registers string resources for a page's header and tab title. + static void RegisterTitle(DictionaryValue* localized_strings, + const std::string& variable_name, + int title_id); + + NotificationRegistrar registrar_; + + private: + DISALLOW_COPY_AND_ASSIGN(OptionsPageUIHandler); +}; + +class OptionsUI : public WebUI { + public: + explicit OptionsUI(TabContents* contents); + virtual ~OptionsUI(); + + static RefCountedMemory* GetFaviconResourceBytes(); + virtual void RenderViewCreated(RenderViewHost* render_view_host); + virtual void DidBecomeActiveForReusedRenderView(); + + void InitializeHandlers(); + + private: + // Adds OptionsPageUiHandler to the handlers list if handler is enabled. + void AddOptionsPageUIHandler(DictionaryValue* localized_strings, + OptionsPageUIHandler* handler); + + bool initialized_handlers_; + + DISALLOW_COPY_AND_ASSIGN(OptionsUI); +}; + +#endif // CHROME_BROWSER_UI_WEBUI_OPTIONS_OPTIONS_UI_H_ |