[email protected] | c078968a | 2010-08-05 21:53:13 | [diff] [blame] | 1 | // Copyright (c) 2010 The Chromium Authors. All rights reserved. |
[email protected] | ea0f18b | 2009-07-27 22:16:11 | [diff] [blame] | 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_ |
[email protected] | 32b76ef | 2010-07-26 23:08:24 | [diff] [blame] | 7 | #pragma once |
[email protected] | 811bfe37 | 2009-07-01 08:46:25 | [diff] [blame] | 8 | |
[email protected] | b2725756 | 2009-11-16 23:28:26 | [diff] [blame] | 9 | #include <string> |
| 10 | |
[email protected] | 811bfe37 | 2009-07-01 08:46:25 | [diff] [blame] | 11 | #include "base/scoped_ptr.h" |
| 12 | #include "chrome/browser/dom_ui/dom_ui.h" |
[email protected] | ced90ae1 | 2010-02-20 02:06:16 | [diff] [blame] | 13 | #include "chrome/browser/extensions/extension_bookmark_manager_api.h" |
[email protected] | 811bfe37 | 2009-07-01 08:46:25 | [diff] [blame] | 14 | #include "chrome/browser/extensions/extension_function_dispatcher.h" |
[email protected] | 4b91f1f | 2010-07-14 20:01:04 | [diff] [blame] | 15 | #include "chrome/browser/favicon_service.h" |
[email protected] | d3cfa48 | 2009-10-17 13:54:57 | [diff] [blame] | 16 | #include "chrome/common/extensions/extension.h" |
[email protected] | 811bfe37 | 2009-07-01 08:46:25 | [diff] [blame] | 17 | |
[email protected] | 86c008e8 | 2009-08-28 20:26:05 | [diff] [blame] | 18 | class ListValue; |
| 19 | class PrefService; |
[email protected] | 59194896 | 2010-03-12 19:37:52 | [diff] [blame] | 20 | class Profile; |
[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, |
| 28 | public ExtensionFunctionDispatcher::Delegate { |
| 29 | public: |
[email protected] | e219474 | 2010-08-12 05:54:34 | [diff] [blame^] | 30 | static const char kExtensionURLOverrides[]; |
[email protected] | c5b8ab4 | 2010-04-14 22:06:50 | [diff] [blame] | 31 | |
[email protected] | 811bfe37 | 2009-07-01 08:46:25 | [diff] [blame] | 32 | explicit ExtensionDOMUI(TabContents* tab_contents); |
[email protected] | 86c008e8 | 2009-08-28 20:26:05 | [diff] [blame] | 33 | |
[email protected] | 811bfe37 | 2009-07-01 08:46:25 | [diff] [blame] | 34 | ExtensionFunctionDispatcher* extension_function_dispatcher() const { |
| 35 | return extension_function_dispatcher_.get(); |
| 36 | } |
| 37 | |
| 38 | // DOMUI |
| 39 | virtual void RenderViewCreated(RenderViewHost* render_view_host); |
[email protected] | cf430e2 | 2009-07-16 18:04:36 | [diff] [blame] | 40 | virtual void RenderViewReused(RenderViewHost* render_view_host); |
[email protected] | 811bfe37 | 2009-07-01 08:46:25 | [diff] [blame] | 41 | virtual void ProcessDOMUIMessage(const std::string& message, |
[email protected] | 438c97d | 2010-05-21 23:30:15 | [diff] [blame] | 42 | const ListValue* content, |
[email protected] | bb64b51 | 2010-04-02 21:01:39 | [diff] [blame] | 43 | const GURL& source_url, |
[email protected] | 811bfe37 | 2009-07-01 08:46:25 | [diff] [blame] | 44 | int request_id, |
| 45 | bool has_callback); |
| 46 | |
| 47 | // ExtensionFunctionDispatcher::Delegate |
[email protected] | 0ec9203 | 2010-03-24 19:59:41 | [diff] [blame] | 48 | virtual Browser* GetBrowser() const; |
[email protected] | 2db27be | 2010-02-10 22:46:47 | [diff] [blame] | 49 | virtual gfx::NativeView GetNativeViewOfHost(); |
[email protected] | 0ec9203 | 2010-03-24 19:59:41 | [diff] [blame] | 50 | virtual gfx::NativeWindow GetCustomFrameNativeWindow(); |
[email protected] | 9aa2eaa | 2010-04-15 19:05:07 | [diff] [blame] | 51 | virtual TabContents* associated_tab_contents() { return tab_contents(); } |
[email protected] | 0ec9203 | 2010-03-24 19:59:41 | [diff] [blame] | 52 | virtual Profile* GetProfile(); |
[email protected] | 811bfe37 | 2009-07-01 08:46:25 | [diff] [blame] | 53 | |
[email protected] | ced90ae1 | 2010-02-20 02:06:16 | [diff] [blame] | 54 | virtual ExtensionBookmarkManagerEventRouter* |
| 55 | extension_bookmark_manager_event_router() { |
| 56 | return extension_bookmark_manager_event_router_.get(); |
| 57 | } |
| 58 | |
[email protected] | 86c008e8 | 2009-08-28 20:26:05 | [diff] [blame] | 59 | // BrowserURLHandler |
| 60 | static bool HandleChromeURLOverride(GURL* url, Profile* profile); |
| 61 | |
| 62 | // Register and unregister a dictionary of one or more overrides. |
| 63 | // Page names are the keys, and chrome-extension: URLs are the values. |
| 64 | // (e.g. { "newtab": "chrome-extension://<id>/my_new_tab.html" } |
| 65 | static void RegisterChromeURLOverrides(Profile* profile, |
[email protected] | ced90ae1 | 2010-02-20 02:06:16 | [diff] [blame] | 66 | const Extension::URLOverrideMap& overrides); |
[email protected] | 86c008e8 | 2009-08-28 20:26:05 | [diff] [blame] | 67 | static void UnregisterChromeURLOverrides(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 UnregisterChromeURLOverride(const std::string& page, |
| 70 | Profile* profile, |
| 71 | Value* override); |
| 72 | |
| 73 | // Called from BrowserPrefs |
| 74 | static void RegisterUserPrefs(PrefService* prefs); |
| 75 | |
[email protected] | 4b91f1f | 2010-07-14 20:01:04 | [diff] [blame] | 76 | // Get the favicon for the extension by getting an icon from the manifest. |
| 77 | static void GetFaviconForURL(Profile* profile, |
| 78 | FaviconService::GetFaviconRequest* request, |
| 79 | const GURL& page_url); |
[email protected] | 59194896 | 2010-03-12 19:37:52 | [diff] [blame] | 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_ |