OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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_WEB_UI_H_ | 5 #ifndef CHROME_BROWSER_EXTENSIONS_EXTENSION_WEB_UI_H_ |
6 #define CHROME_BROWSER_EXTENSIONS_EXTENSION_WEB_UI_H_ | 6 #define CHROME_BROWSER_EXTENSIONS_EXTENSION_WEB_UI_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include <string> | 9 #include <string> |
10 | 10 |
11 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
12 #include "chrome/browser/extensions/extension_bookmark_manager_api.h" | 12 #include "chrome/browser/extensions/extension_bookmark_manager_api.h" |
13 #include "chrome/browser/favicon/favicon_service.h" | 13 #include "chrome/browser/favicon/favicon_service.h" |
14 #include "chrome/browser/ui/webui/chrome_web_ui.h" | 14 #include "chrome/browser/ui/webui/chrome_web_ui.h" |
15 #include "chrome/common/extensions/extension.h" | 15 #include "chrome/common/extensions/extension.h" |
16 | 16 |
17 class GURL; | 17 class GURL; |
18 class ListValue; | |
19 class PrefService; | 18 class PrefService; |
20 class Profile; | 19 class Profile; |
21 class RenderViewHost; | 20 class RenderViewHost; |
22 class TabContents; | 21 class TabContents; |
23 | 22 |
| 23 namespace base { |
| 24 class ListValue; |
| 25 class Value; |
| 26 } |
| 27 |
24 // This class implements WebUI for extensions and allows extensions to put UI in | 28 // This class implements WebUI for extensions and allows extensions to put UI in |
25 // the main tab contents area. For example, each extension can specify an | 29 // the main tab contents area. For example, each extension can specify an |
26 // "options_page", and that page is displayed in the tab contents area and is | 30 // "options_page", and that page is displayed in the tab contents area and is |
27 // hosted by this class. | 31 // hosted by this class. |
28 class ExtensionWebUI : public ChromeWebUI { | 32 class ExtensionWebUI : public ChromeWebUI { |
29 public: | 33 public: |
30 static const char kExtensionURLOverrides[]; | 34 static const char kExtensionURLOverrides[]; |
31 | 35 |
32 explicit ExtensionWebUI(TabContents* tab_contents, const GURL& url); | 36 explicit ExtensionWebUI(TabContents* tab_contents, const GURL& url); |
33 | 37 |
34 virtual ~ExtensionWebUI(); | 38 virtual ~ExtensionWebUI(); |
35 | 39 |
36 virtual ExtensionBookmarkManagerEventRouter* | 40 virtual ExtensionBookmarkManagerEventRouter* |
37 extension_bookmark_manager_event_router(); | 41 extension_bookmark_manager_event_router(); |
38 | 42 |
39 // BrowserURLHandler | 43 // BrowserURLHandler |
40 static bool HandleChromeURLOverride(GURL* url, Profile* profile); | 44 static bool HandleChromeURLOverride(GURL* url, Profile* profile); |
41 static bool HandleChromeURLOverrideReverse(GURL* url, Profile* profile); | 45 static bool HandleChromeURLOverrideReverse(GURL* url, Profile* profile); |
42 | 46 |
43 // Register and unregister a dictionary of one or more overrides. | 47 // Register and unregister a dictionary of one or more overrides. |
44 // Page names are the keys, and chrome-extension: URLs are the values. | 48 // Page names are the keys, and chrome-extension: URLs are the values. |
45 // (e.g. { "newtab": "chrome-extension://<id>/my_new_tab.html" } | 49 // (e.g. { "newtab": "chrome-extension://<id>/my_new_tab.html" } |
46 static void RegisterChromeURLOverrides(Profile* profile, | 50 static void RegisterChromeURLOverrides(Profile* profile, |
47 const Extension::URLOverrideMap& overrides); | 51 const Extension::URLOverrideMap& overrides); |
48 static void UnregisterChromeURLOverrides(Profile* profile, | 52 static void UnregisterChromeURLOverrides(Profile* profile, |
49 const Extension::URLOverrideMap& overrides); | 53 const Extension::URLOverrideMap& overrides); |
50 static void UnregisterChromeURLOverride(const std::string& page, | 54 static void UnregisterChromeURLOverride(const std::string& page, |
51 Profile* profile, | 55 Profile* profile, |
52 Value* override); | 56 base::Value* override); |
53 | 57 |
54 // Called from BrowserPrefs | 58 // Called from BrowserPrefs |
55 static void RegisterUserPrefs(PrefService* prefs); | 59 static void RegisterUserPrefs(PrefService* prefs); |
56 | 60 |
57 // Get the favicon for the extension by getting an icon from the manifest. | 61 // Get the favicon for the extension by getting an icon from the manifest. |
58 static void GetFaviconForURL(Profile* profile, | 62 static void GetFaviconForURL(Profile* profile, |
59 FaviconService::GetFaviconRequest* request, | 63 FaviconService::GetFaviconRequest* request, |
60 const GURL& page_url); | 64 const GURL& page_url); |
61 | 65 |
62 private: | 66 private: |
63 // Unregister the specified override, and if it's the currently active one, | 67 // Unregister the specified override, and if it's the currently active one, |
64 // ensure that something takes its place. | 68 // ensure that something takes its place. |
65 static void UnregisterAndReplaceOverride(const std::string& page, | 69 static void UnregisterAndReplaceOverride(const std::string& page, |
66 Profile* profile, | 70 Profile* profile, |
67 ListValue* list, | 71 base::ListValue* list, |
68 Value* override); | 72 base::Value* override); |
69 | 73 |
70 // TODO(aa): This seems out of place. Why is it not with the event routers for | 74 // TODO(aa): This seems out of place. Why is it not with the event routers for |
71 // the other extension APIs? | 75 // the other extension APIs? |
72 scoped_ptr<ExtensionBookmarkManagerEventRouter> | 76 scoped_ptr<ExtensionBookmarkManagerEventRouter> |
73 extension_bookmark_manager_event_router_; | 77 extension_bookmark_manager_event_router_; |
74 | 78 |
75 // The URL this WebUI was created for. | 79 // The URL this WebUI was created for. |
76 GURL url_; | 80 GURL url_; |
77 }; | 81 }; |
78 | 82 |
79 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_WEB_UI_H_ | 83 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_WEB_UI_H_ |
OLD | NEW |