| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 | 7 |
| 8 #include <memory> | 8 #include <memory> |
| 9 #include <string> | 9 #include <string> |
| 10 | 10 |
| 11 #include "base/macros.h" | |
| 12 #include "chrome/common/extensions/chrome_manifest_url_handlers.h" | 11 #include "chrome/common/extensions/chrome_manifest_url_handlers.h" |
| 13 #include "components/favicon_base/favicon_callback.h" | 12 #include "components/favicon_base/favicon_callback.h" |
| 14 #include "content/public/browser/web_ui_controller.h" | 13 #include "content/public/browser/web_ui_controller.h" |
| 15 | 14 |
| 16 class Profile; | 15 class Profile; |
| 17 | 16 |
| 18 namespace content { | 17 namespace content { |
| 19 class BrowserContext; | 18 class BrowserContext; |
| 20 class WebContents; | 19 class WebContents; |
| 21 } | 20 } |
| 22 | 21 |
| 23 namespace extensions { | 22 namespace extensions { |
| 24 class BookmarkManagerPrivateDragEventRouter; | 23 class BookmarkManagerPrivateDragEventRouter; |
| 25 } | 24 } |
| 26 | 25 |
| 27 namespace user_prefs { | 26 namespace user_prefs { |
| 28 class PrefRegistrySyncable; | 27 class PrefRegistrySyncable; |
| 29 } | 28 } |
| 30 | 29 |
| 31 // This class implements WebUI for extensions and allows extensions to put UI in | 30 // This class implements WebUI for extensions and allows extensions to put UI in |
| 32 // the main tab contents area. For example, each extension can specify an | 31 // the main tab contents area. For example, each extension can specify an |
| 33 // "options_page", and that page is displayed in the tab contents area and is | 32 // "options_page", and that page is displayed in the tab contents area and is |
| 34 // hosted by this class. | 33 // hosted by this class. |
| 35 // TODO(devlin): The above description has nothing to do with this class as far | |
| 36 // as I can tell. | |
| 37 class ExtensionWebUI : public content::WebUIController { | 34 class ExtensionWebUI : public content::WebUIController { |
| 38 public: | 35 public: |
| 39 static const char kExtensionURLOverrides[]; | 36 static const char kExtensionURLOverrides[]; |
| 40 | 37 |
| 41 ExtensionWebUI(content::WebUI* web_ui, const GURL& url); | 38 ExtensionWebUI(content::WebUI* web_ui, const GURL& url); |
| 42 | 39 |
| 43 ~ExtensionWebUI() override; | 40 ~ExtensionWebUI() override; |
| 44 | 41 |
| 45 // Returns true if the given url requires WebUI bindings. | 42 virtual extensions::BookmarkManagerPrivateDragEventRouter* |
| 46 static bool NeedsExtensionWebUI(content::BrowserContext* browser_context, | 43 bookmark_manager_private_drag_event_router(); |
| 47 const GURL& url); | |
| 48 | 44 |
| 49 // TODO(devlin): The rest of this class is static methods dealing with | |
| 50 // chrome url overrides (e.g. changing chrome://newtab to go to an extension- | |
| 51 // provided new tab page). This should be in a separate class from the WebUI | |
| 52 // controller for the bookmark manager, and the WebUI controller should be | |
| 53 // renamed. | |
| 54 // BrowserURLHandler | 45 // BrowserURLHandler |
| 55 static bool HandleChromeURLOverride(GURL* url, | 46 static bool HandleChromeURLOverride(GURL* url, |
| 56 content::BrowserContext* browser_context); | 47 content::BrowserContext* browser_context); |
| 57 static bool HandleChromeURLOverrideReverse( | 48 static bool HandleChromeURLOverrideReverse( |
| 58 GURL* url, content::BrowserContext* browser_context); | 49 GURL* url, content::BrowserContext* browser_context); |
| 59 | 50 |
| 60 // Initialize the Chrome URL overrides. This must happen *before* any further | 51 // Initialize the Chrome URL overrides. This must happen *before* any further |
| 61 // calls for URL overrides! | 52 // calls for URL overrides! |
| 62 static void InitializeChromeURLOverrides(Profile* profile); | 53 static void InitializeChromeURLOverrides(Profile* profile); |
| 63 | 54 |
| (...skipping 22 matching lines...) Expand all Loading... |
| 86 // Called from BrowserPrefs | 77 // Called from BrowserPrefs |
| 87 static void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry); | 78 static void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry); |
| 88 | 79 |
| 89 // Get the favicon for the extension by getting an icon from the manifest. | 80 // Get the favicon for the extension by getting an icon from the manifest. |
| 90 // Note. |callback| is always run asynchronously. | 81 // Note. |callback| is always run asynchronously. |
| 91 static void GetFaviconForURL( | 82 static void GetFaviconForURL( |
| 92 Profile* profile, | 83 Profile* profile, |
| 93 const GURL& page_url, | 84 const GURL& page_url, |
| 94 const favicon_base::FaviconResultsCallback& callback); | 85 const favicon_base::FaviconResultsCallback& callback); |
| 95 | 86 |
| 96 extensions::BookmarkManagerPrivateDragEventRouter* | |
| 97 bookmark_manager_private_drag_event_router() { | |
| 98 return bookmark_manager_private_drag_event_router_.get(); | |
| 99 } | |
| 100 | |
| 101 private: | 87 private: |
| 102 // Unregister the specified override, and if it's the currently active one, | 88 // Unregister the specified override, and if it's the currently active one, |
| 103 // ensure that something takes its place. | 89 // ensure that something takes its place. |
| 104 static void UnregisterAndReplaceOverride(const std::string& page, | 90 static void UnregisterAndReplaceOverride(const std::string& page, |
| 105 Profile* profile, | 91 Profile* profile, |
| 106 base::ListValue* list, | 92 base::ListValue* list, |
| 107 const base::Value* override); | 93 const base::Value* override); |
| 108 | 94 |
| 109 // TODO(aa): This seems out of place. Why is it not with the event routers for | 95 // TODO(aa): This seems out of place. Why is it not with the event routers for |
| 110 // the other extension APIs? | 96 // the other extension APIs? |
| 111 std::unique_ptr<extensions::BookmarkManagerPrivateDragEventRouter> | 97 std::unique_ptr<extensions::BookmarkManagerPrivateDragEventRouter> |
| 112 bookmark_manager_private_drag_event_router_; | 98 bookmark_manager_private_drag_event_router_; |
| 113 | 99 |
| 114 DISALLOW_COPY_AND_ASSIGN(ExtensionWebUI); | 100 // The URL this WebUI was created for. |
| 101 GURL url_; |
| 115 }; | 102 }; |
| 116 | 103 |
| 117 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_WEB_UI_H_ | 104 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_WEB_UI_H_ |
| OLD | NEW |