| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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_EXTENSIONS_EXTENSION_DOM_UI_H_ | 5 #ifndef CHROME_BROWSER_EXTENSIONS_EXTENSION_DOM_UI_H_ |
| 6 #define CHROME_BROWSER_EXTENSIONS_EXTENSION_DOM_UI_H_ | 6 #define CHROME_BROWSER_EXTENSIONS_EXTENSION_DOM_UI_H_ |
| 7 | 7 |
| 8 #include "base/scoped_ptr.h" | 8 #include "base/scoped_ptr.h" |
| 9 #include "chrome/browser/dom_ui/dom_ui.h" | 9 #include "chrome/browser/dom_ui/dom_ui.h" |
| 10 #include "chrome/browser/extensions/extension_function_dispatcher.h" | 10 #include "chrome/browser/extensions/extension_function_dispatcher.h" |
| 11 #include "chrome/common/extensions/extension.h" |
| 11 | 12 |
| 12 class ListValue; | 13 class ListValue; |
| 13 class PrefService; | 14 class PrefService; |
| 14 class TabContents; | 15 class TabContents; |
| 15 | 16 |
| 16 // This class implements DOMUI for extensions and allows extensions to put UI in | 17 // This class implements DOMUI for extensions and allows extensions to put UI in |
| 17 // the main tab contents area. | 18 // the main tab contents area. |
| 18 class ExtensionDOMUI | 19 class ExtensionDOMUI |
| 19 : public DOMUI, | 20 : public DOMUI, |
| 20 public ExtensionFunctionDispatcher::Delegate { | 21 public ExtensionFunctionDispatcher::Delegate { |
| 21 public: | 22 public: |
| 22 explicit ExtensionDOMUI(TabContents* tab_contents); | 23 explicit ExtensionDOMUI(TabContents* tab_contents); |
| 23 | 24 |
| 24 ExtensionFunctionDispatcher* extension_function_dispatcher() const { | 25 ExtensionFunctionDispatcher* extension_function_dispatcher() const { |
| 25 return extension_function_dispatcher_.get(); | 26 return extension_function_dispatcher_.get(); |
| 26 } | 27 } |
| 27 | 28 |
| 28 // DOMUI | 29 // DOMUI |
| 29 virtual void RenderViewCreated(RenderViewHost* render_view_host); | 30 virtual void RenderViewCreated(RenderViewHost* render_view_host); |
| 30 virtual void RenderViewReused(RenderViewHost* render_view_host); | 31 virtual void RenderViewReused(RenderViewHost* render_view_host); |
| 31 virtual void ProcessDOMUIMessage(const std::string& message, | 32 virtual void ProcessDOMUIMessage(const std::string& message, |
| 32 const Value* content, | 33 const Value* content, |
| 33 int request_id, | 34 int request_id, |
| 34 bool has_callback); | 35 bool has_callback); |
| 35 | 36 |
| 36 // ExtensionFunctionDispatcher::Delegate | 37 // ExtensionFunctionDispatcher::Delegate |
| 37 virtual Browser* GetBrowser(); | 38 virtual Browser* GetBrowser(); |
| 38 | 39 |
| 39 // BrowserURLHandler | 40 // BrowserURLHandler |
| 40 static bool HandleChromeURLOverride(GURL* url, Profile* profile); | 41 static bool HandleChromeURLOverride(GURL* url, Profile* profile); |
| 41 | 42 |
| 42 // Register and unregister a dictionary of one or more overrides. | 43 // Register and unregister a dictionary of one or more overrides. |
| 43 // Page names are the keys, and chrome-extension: URLs are the values. | 44 // Page names are the keys, and chrome-extension: URLs are the values. |
| 44 // (e.g. { "newtab": "chrome-extension://<id>/my_new_tab.html" } | 45 // (e.g. { "newtab": "chrome-extension://<id>/my_new_tab.html" } |
| 45 static void RegisterChromeURLOverrides(Profile* profile, | 46 static void RegisterChromeURLOverrides(Profile* profile, |
| 46 const DictionaryValue* overrides); | 47 const Extension::URLOverrideMap& overrides); |
| 47 static void UnregisterChromeURLOverrides(Profile* profile, | 48 static void UnregisterChromeURLOverrides(Profile* profile, |
| 48 const DictionaryValue* overrides); | 49 const Extension::URLOverrideMap& overrides); |
| 49 static void UnregisterChromeURLOverride(const std::string& page, | 50 static void UnregisterChromeURLOverride(const std::string& page, |
| 50 Profile* profile, | 51 Profile* profile, |
| 51 Value* override); | 52 Value* override); |
| 52 | 53 |
| 53 // Called from BrowserPrefs | 54 // Called from BrowserPrefs |
| 54 static void RegisterUserPrefs(PrefService* prefs); | 55 static void RegisterUserPrefs(PrefService* prefs); |
| 55 | 56 |
| 56 private: | 57 private: |
| 57 // Unregister the specified override, and if it's the currently active one, | 58 // Unregister the specified override, and if it's the currently active one, |
| 58 // ensure that something takes its place. | 59 // ensure that something takes its place. |
| 59 static void UnregisterAndReplaceOverride(const std::string& page, | 60 static void UnregisterAndReplaceOverride(const std::string& page, |
| 60 Profile* profile, | 61 Profile* profile, |
| 61 ListValue* list, | 62 ListValue* list, |
| 62 Value* override); | 63 Value* override); |
| 63 | 64 |
| 64 // When the RenderViewHost changes (RenderViewCreated and RenderViewReused), | 65 // When the RenderViewHost changes (RenderViewCreated and RenderViewReused), |
| 65 // we need to reset the ExtensionFunctionDispatcher so it's talking to the | 66 // we need to reset the ExtensionFunctionDispatcher so it's talking to the |
| 66 // right one, as well as being linked to the correct URL. | 67 // right one, as well as being linked to the correct URL. |
| 67 void ResetExtensionFunctionDispatcher(RenderViewHost* render_view_host); | 68 void ResetExtensionFunctionDispatcher(RenderViewHost* render_view_host); |
| 68 | 69 |
| 69 scoped_ptr<ExtensionFunctionDispatcher> extension_function_dispatcher_; | 70 scoped_ptr<ExtensionFunctionDispatcher> extension_function_dispatcher_; |
| 70 }; | 71 }; |
| 71 | 72 |
| 72 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_DOM_UI_H_ | 73 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_DOM_UI_H_ |
| OLD | NEW |