[email protected] | f4f50ef | 2011-01-21 19:01:19 | [diff] [blame] | 1 | // Copyright (c) 2011 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] | 8f9d4eb | 2011-02-05 01:39:10 | [diff] [blame] | 5 | #ifndef CHROME_BROWSER_EXTENSIONS_EXTENSION_WEB_UI_H_ |
| 6 | #define CHROME_BROWSER_EXTENSIONS_EXTENSION_WEB_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] | 3b63f8f4 | 2011-03-28 01:54:15 | [diff] [blame] | 11 | #include "base/memory/scoped_ptr.h" |
[email protected] | 23d5f17 | 2011-10-25 05:49:53 | [diff] [blame] | 12 | #include "chrome/browser/bookmarks/bookmark_manager_extension_api.h" |
[email protected] | ee2ed42c | 2011-04-28 22:19:14 | [diff] [blame] | 13 | #include "chrome/browser/favicon/favicon_service.h" |
[email protected] | d3cfa48 | 2009-10-17 13:54:57 | [diff] [blame] | 14 | #include "chrome/common/extensions/extension.h" |
[email protected] | 21e6caf8 | 2012-01-06 23:44:20 | [diff] [blame] | 15 | #include "content/browser/webui/web_ui.h" |
[email protected] | e14c95912 | 2012-01-13 16:58:25 | [diff] [blame^] | 16 | #include "content/public/browser/web_ui_controller.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 PrefService; |
[email protected] | 59194896 | 2010-03-12 19:37:52 | [diff] [blame] | 19 | class Profile; |
[email protected] | 86c008e8 | 2009-08-28 20:26:05 | [diff] [blame] | 20 | |
[email protected] | d21cdb1 | 2011-02-10 01:22:32 | [diff] [blame] | 21 | // This class implements WebUI for extensions and allows extensions to put UI in |
[email protected] | bad77bf | 2010-08-21 21:21:22 | [diff] [blame] | 22 | // the main tab contents area. For example, each extension can specify an |
| 23 | // "options_page", and that page is displayed in the tab contents area and is |
| 24 | // hosted by this class. |
[email protected] | e14c95912 | 2012-01-13 16:58:25 | [diff] [blame^] | 25 | class ExtensionWebUI : public WebUI, public content::WebUIController { |
[email protected] | 811bfe37 | 2009-07-01 08:46:25 | [diff] [blame] | 26 | public: |
[email protected] | e219474 | 2010-08-12 05:54:34 | [diff] [blame] | 27 | static const char kExtensionURLOverrides[]; |
[email protected] | c5b8ab4 | 2010-04-14 22:06:50 | [diff] [blame] | 28 | |
[email protected] | f3f3b72 | 2012-01-07 01:29:43 | [diff] [blame] | 29 | ExtensionWebUI(content::WebContents* web_contents, const GURL& url); |
[email protected] | 86c008e8 | 2009-08-28 20:26:05 | [diff] [blame] | 30 | |
[email protected] | 8f9d4eb | 2011-02-05 01:39:10 | [diff] [blame] | 31 | virtual ~ExtensionWebUI(); |
[email protected] | 8e38341 | 2010-10-19 16:57:03 | [diff] [blame] | 32 | |
[email protected] | fd8b39f | 2011-10-31 13:16:44 | [diff] [blame] | 33 | virtual BookmarkManagerExtensionEventRouter* |
| 34 | bookmark_manager_extension_event_router(); |
[email protected] | ced90ae1 | 2010-02-20 02:06:16 | [diff] [blame] | 35 | |
[email protected] | 86c008e8 | 2009-08-28 20:26:05 | [diff] [blame] | 36 | // BrowserURLHandler |
[email protected] | 3d7474ff | 2011-07-27 17:47:37 | [diff] [blame] | 37 | static bool HandleChromeURLOverride(GURL* url, |
| 38 | content::BrowserContext* browser_context); |
| 39 | static bool HandleChromeURLOverrideReverse( |
| 40 | GURL* url, content::BrowserContext* browser_context); |
[email protected] | 86c008e8 | 2009-08-28 20:26:05 | [diff] [blame] | 41 | |
| 42 | // Register and unregister a dictionary of one or more overrides. |
| 43 | // Page names are the keys, and chrome-extension: URLs are the values. |
| 44 | // (e.g. { "newtab": "chrome-extension://<id>/my_new_tab.html" } |
| 45 | static void RegisterChromeURLOverrides(Profile* profile, |
[email protected] | ced90ae1 | 2010-02-20 02:06:16 | [diff] [blame] | 46 | const Extension::URLOverrideMap& overrides); |
[email protected] | 86c008e8 | 2009-08-28 20:26:05 | [diff] [blame] | 47 | static void UnregisterChromeURLOverrides(Profile* profile, |
[email protected] | ced90ae1 | 2010-02-20 02:06:16 | [diff] [blame] | 48 | const Extension::URLOverrideMap& overrides); |
[email protected] | 86c008e8 | 2009-08-28 20:26:05 | [diff] [blame] | 49 | static void UnregisterChromeURLOverride(const std::string& page, |
| 50 | Profile* profile, |
[email protected] | f3a1c64 | 2011-07-12 19:15:03 | [diff] [blame] | 51 | base::Value* override); |
[email protected] | 86c008e8 | 2009-08-28 20:26:05 | [diff] [blame] | 52 | |
| 53 | // Called from BrowserPrefs |
| 54 | static void RegisterUserPrefs(PrefService* prefs); |
| 55 | |
[email protected] | 4b91f1f | 2010-07-14 20:01:04 | [diff] [blame] | 56 | // Get the favicon for the extension by getting an icon from the manifest. |
| 57 | static void GetFaviconForURL(Profile* profile, |
| 58 | FaviconService::GetFaviconRequest* request, |
| 59 | const GURL& page_url); |
[email protected] | 59194896 | 2010-03-12 19:37:52 | [diff] [blame] | 60 | |
[email protected] | 811bfe37 | 2009-07-01 08:46:25 | [diff] [blame] | 61 | private: |
[email protected] | 86c008e8 | 2009-08-28 20:26:05 | [diff] [blame] | 62 | // Unregister the specified override, and if it's the currently active one, |
| 63 | // ensure that something takes its place. |
| 64 | static void UnregisterAndReplaceOverride(const std::string& page, |
| 65 | Profile* profile, |
[email protected] | f3a1c64 | 2011-07-12 19:15:03 | [diff] [blame] | 66 | base::ListValue* list, |
| 67 | base::Value* override); |
[email protected] | 86c008e8 | 2009-08-28 20:26:05 | [diff] [blame] | 68 | |
[email protected] | bad77bf | 2010-08-21 21:21:22 | [diff] [blame] | 69 | // TODO(aa): This seems out of place. Why is it not with the event routers for |
| 70 | // the other extension APIs? |
[email protected] | fd8b39f | 2011-10-31 13:16:44 | [diff] [blame] | 71 | scoped_ptr<BookmarkManagerExtensionEventRouter> |
| 72 | bookmark_manager_extension_event_router_; |
[email protected] | 3efe14a6 | 2010-10-25 22:18:38 | [diff] [blame] | 73 | |
[email protected] | d21cdb1 | 2011-02-10 01:22:32 | [diff] [blame] | 74 | // The URL this WebUI was created for. |
[email protected] | 3efe14a6 | 2010-10-25 22:18:38 | [diff] [blame] | 75 | GURL url_; |
[email protected] | 811bfe37 | 2009-07-01 08:46:25 | [diff] [blame] | 76 | }; |
| 77 | |
[email protected] | 8f9d4eb | 2011-02-05 01:39:10 | [diff] [blame] | 78 | #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_WEB_UI_H_ |