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