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