| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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_DOM_UI_OPTIONS_OPTIONS_UI_H_ | 5 #ifndef CHROME_BROWSER_DOM_UI_OPTIONS_OPTIONS_UI_H_ |
| 6 #define CHROME_BROWSER_DOM_UI_OPTIONS_OPTIONS_UI_H_ | 6 #define CHROME_BROWSER_DOM_UI_OPTIONS_OPTIONS_UI_H_ |
| 7 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include <string> | 9 #include "chrome/browser/webui/options/options_ui.h" |
| 10 | 10 // TODO(tfarina): remove this file once all includes have been updated. |
| 11 #include "base/scoped_ptr.h" | |
| 12 #include "chrome/browser/webui/chrome_url_data_manager.h" | |
| 13 #include "chrome/browser/webui/web_ui.h" | |
| 14 #include "chrome/common/notification_observer.h" | |
| 15 #include "chrome/common/notification_registrar.h" | |
| 16 #include "chrome/common/notification_type.h" | |
| 17 | |
| 18 class GURL; | |
| 19 class PrefService; | |
| 20 struct UserMetricsAction; | |
| 21 | |
| 22 class OptionsUIHTMLSource : public ChromeURLDataManager::DataSource { | |
| 23 public: | |
| 24 // The constructor takes over ownership of |localized_strings|. | |
| 25 explicit OptionsUIHTMLSource(DictionaryValue* localized_strings); | |
| 26 virtual ~OptionsUIHTMLSource(); | |
| 27 | |
| 28 // Called when the network layer has requested a resource underneath | |
| 29 // the path we registered. | |
| 30 virtual void StartDataRequest(const std::string& path, | |
| 31 bool is_off_the_record, | |
| 32 int request_id); | |
| 33 virtual std::string GetMimeType(const std::string&) const; | |
| 34 | |
| 35 private: | |
| 36 // Localized strings collection. | |
| 37 scoped_ptr<DictionaryValue> localized_strings_; | |
| 38 | |
| 39 DISALLOW_COPY_AND_ASSIGN(OptionsUIHTMLSource); | |
| 40 }; | |
| 41 | |
| 42 // The base class handler of Javascript messages of options pages. | |
| 43 class OptionsPageUIHandler : public WebUIMessageHandler, | |
| 44 public NotificationObserver { | |
| 45 public: | |
| 46 OptionsPageUIHandler(); | |
| 47 virtual ~OptionsPageUIHandler(); | |
| 48 | |
| 49 // Is this handler enabled? | |
| 50 virtual bool IsEnabled(); | |
| 51 | |
| 52 // Collects localized strings for options page. | |
| 53 virtual void GetLocalizedValues(DictionaryValue* localized_strings) = 0; | |
| 54 | |
| 55 // Initialize the page. Called once the DOM is available for manipulation. | |
| 56 // This will be called only once. | |
| 57 virtual void Initialize() {} | |
| 58 | |
| 59 // Uninitializes the page. Called just before the object is destructed. | |
| 60 virtual void Uninitialize() {} | |
| 61 | |
| 62 // WebUIMessageHandler implementation. | |
| 63 virtual void RegisterMessages() {} | |
| 64 | |
| 65 // NotificationObserver implementation. | |
| 66 virtual void Observe(NotificationType type, | |
| 67 const NotificationSource& source, | |
| 68 const NotificationDetails& details) {} | |
| 69 | |
| 70 void UserMetricsRecordAction(const UserMetricsAction& action); | |
| 71 | |
| 72 protected: | |
| 73 struct OptionsStringResource { | |
| 74 // The name of the resource in templateData. | |
| 75 const char* name; | |
| 76 // The .grd ID for the resource (IDS_*). | |
| 77 int id; | |
| 78 // True if the trailing colon should be stripped on platforms that | |
| 79 // don't want trailing colons. | |
| 80 bool strip_colon; | |
| 81 }; | |
| 82 // A helper for simplifying the process of registering strings in WebUI. | |
| 83 static void RegisterStrings(DictionaryValue* localized_strings, | |
| 84 const OptionsStringResource* resources, | |
| 85 size_t length); | |
| 86 | |
| 87 // Registers string resources for a page's header and tab title. | |
| 88 static void RegisterTitle(DictionaryValue* localized_strings, | |
| 89 const std::string& variable_name, | |
| 90 int title_id); | |
| 91 | |
| 92 NotificationRegistrar registrar_; | |
| 93 | |
| 94 private: | |
| 95 DISALLOW_COPY_AND_ASSIGN(OptionsPageUIHandler); | |
| 96 }; | |
| 97 | |
| 98 class OptionsUI : public WebUI { | |
| 99 public: | |
| 100 explicit OptionsUI(TabContents* contents); | |
| 101 virtual ~OptionsUI(); | |
| 102 | |
| 103 static RefCountedMemory* GetFaviconResourceBytes(); | |
| 104 virtual void RenderViewCreated(RenderViewHost* render_view_host); | |
| 105 virtual void DidBecomeActiveForReusedRenderView(); | |
| 106 | |
| 107 void InitializeHandlers(); | |
| 108 | |
| 109 private: | |
| 110 // Adds OptionsPageUiHandler to the handlers list if handler is enabled. | |
| 111 void AddOptionsPageUIHandler(DictionaryValue* localized_strings, | |
| 112 OptionsPageUIHandler* handler); | |
| 113 | |
| 114 bool initialized_handlers_; | |
| 115 | |
| 116 DISALLOW_COPY_AND_ASSIGN(OptionsUI); | |
| 117 }; | |
| 118 | 11 |
| 119 #endif // CHROME_BROWSER_DOM_UI_OPTIONS_OPTIONS_UI_H_ | 12 #endif // CHROME_BROWSER_DOM_UI_OPTIONS_OPTIONS_UI_H_ |
| OLD | NEW |