[email protected] | 44e329a | 2012-07-14 01:13:06 | [diff] [blame] | 1 | // Copyright (c) 2012 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] | 811bfe37 | 2009-07-01 08:46:25 | [diff] [blame] | 7 | |
dcheng | c963c714 | 2016-04-08 03:55:22 | [diff] [blame] | 8 | #include <memory> |
[email protected] | b2725756 | 2009-11-16 23:28:26 | [diff] [blame] | 9 | #include <string> |
| 10 | |
xidachen | 2f98b6b | 2016-10-31 21:18:06 | [diff] [blame] | 11 | #include "base/macros.h" |
rockot | 3b99b8e | 2014-10-14 21:54:35 | [diff] [blame] | 12 | #include "chrome/common/extensions/chrome_manifest_url_handlers.h" |
[email protected] | 8823c50 | 2014-05-22 03:11:16 | [diff] [blame] | 13 | #include "components/favicon_base/favicon_callback.h" |
[email protected] | e14c95912 | 2012-01-13 16:58:25 | [diff] [blame] | 14 | #include "content/public/browser/web_ui_controller.h" |
[email protected] | 811bfe37 | 2009-07-01 08:46:25 | [diff] [blame] | 15 | |
[email protected] | 443e931 | 2013-05-06 06:17:34 | [diff] [blame] | 16 | class Profile; |
| 17 | |
[email protected] | 44e329a | 2012-07-14 01:13:06 | [diff] [blame] | 18 | namespace content { |
[email protected] | 7048264 | 2012-12-19 22:25:24 | [diff] [blame] | 19 | class BrowserContext; |
[email protected] | 44e329a | 2012-07-14 01:13:06 | [diff] [blame] | 20 | } |
| 21 | |
[email protected] | 443e931 | 2013-05-06 06:17:34 | [diff] [blame] | 22 | namespace user_prefs { |
[email protected] | c753f14 | 2013-02-10 13:14:04 | [diff] [blame] | 23 | class PrefRegistrySyncable; |
[email protected] | 443e931 | 2013-05-06 06:17:34 | [diff] [blame] | 24 | } |
[email protected] | 86c008e8 | 2009-08-28 20:26:05 | [diff] [blame] | 25 | |
rdevlin.cronin | a32a090 | 2016-11-09 15:50:20 | [diff] [blame] | 26 | // A collection of methods to handle Chrome URL overrides that are managed by |
| 27 | // extensions (such as overriding the new tab page). |
| 28 | // TODO(devlin): Rename this class to ExtensionURLOverrides. |
| 29 | class ExtensionWebUI { |
[email protected] | 811bfe37 | 2009-07-01 08:46:25 | [diff] [blame] | 30 | public: |
[email protected] | e219474 | 2010-08-12 05:54:34 | [diff] [blame] | 31 | static const char kExtensionURLOverrides[]; |
[email protected] | c5b8ab4 | 2010-04-14 22:06:50 | [diff] [blame] | 32 | |
[email protected] | 3d7474ff | 2011-07-27 17:47:37 | [diff] [blame] | 33 | static bool HandleChromeURLOverride(GURL* url, |
| 34 | content::BrowserContext* browser_context); |
| 35 | static bool HandleChromeURLOverrideReverse( |
| 36 | GURL* url, content::BrowserContext* browser_context); |
[email protected] | 86c008e8 | 2009-08-28 20:26:05 | [diff] [blame] | 37 | |
rdevlin.cronin | 5fafa5a | 2015-12-30 03:42:02 | [diff] [blame] | 38 | // Initialize the Chrome URL overrides. This must happen *before* any further |
| 39 | // calls for URL overrides! |
| 40 | static void InitializeChromeURLOverrides(Profile* profile); |
| 41 | |
| 42 | // Validate the Chrome URL overrides, ensuring that each is valid and points |
| 43 | // to an existing extension. To be called once all extensions are loaded. |
| 44 | static void ValidateChromeURLOverrides(Profile* profile); |
| 45 | |
| 46 | // Add new Chrome URL overrides. If an entry exists, it is marked as active. |
| 47 | // If one doesn't exist, it is added at the beginning of the list of |
| 48 | // overrides (meaning it has priority). |
| 49 | static void RegisterOrActivateChromeURLOverrides( |
| 50 | Profile* profile, |
[email protected] | 636ee4328 | 2013-01-12 15:58:00 | [diff] [blame] | 51 | const extensions::URLOverrides::URLOverrideMap& overrides); |
rdevlin.cronin | 5fafa5a | 2015-12-30 03:42:02 | [diff] [blame] | 52 | |
| 53 | // Deactivate overrides without removing them from the list or modifying their |
| 54 | // positions in the list. |
| 55 | static void DeactivateChromeURLOverrides( |
| 56 | Profile* profile, |
[email protected] | 636ee4328 | 2013-01-12 15:58:00 | [diff] [blame] | 57 | const extensions::URLOverrides::URLOverrideMap& overrides); |
rdevlin.cronin | 5fafa5a | 2015-12-30 03:42:02 | [diff] [blame] | 58 | |
| 59 | // Completely unregister overrides, removing them from the list. |
| 60 | static void UnregisterChromeURLOverrides( |
| 61 | Profile* profile, |
| 62 | const extensions::URLOverrides::URLOverrideMap& overrides); |
[email protected] | 86c008e8 | 2009-08-28 20:26:05 | [diff] [blame] | 63 | |
| 64 | // Called from BrowserPrefs |
[email protected] | 37ca3fe0 | 2013-07-05 15:32:44 | [diff] [blame] | 65 | static void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry); |
[email protected] | 86c008e8 | 2009-08-28 20:26:05 | [diff] [blame] | 66 | |
[email protected] | 4b91f1f | 2010-07-14 20:01:04 | [diff] [blame] | 67 | // Get the favicon for the extension by getting an icon from the manifest. |
[email protected] | 0ea3db5 | 2012-12-07 01:32:01 | [diff] [blame] | 68 | // Note. |callback| is always run asynchronously. |
Sylvain Defresne | 6de2926e | 2019-05-21 14:15:10 | [diff] [blame] | 69 | static void GetFaviconForURL(Profile* profile, |
| 70 | const GURL& page_url, |
| 71 | favicon_base::FaviconResultsCallback callback); |
[email protected] | 59194896 | 2010-03-12 19:37:52 | [diff] [blame] | 72 | |
[email protected] | 811bfe37 | 2009-07-01 08:46:25 | [diff] [blame] | 73 | private: |
[email protected] | 86c008e8 | 2009-08-28 20:26:05 | [diff] [blame] | 74 | // Unregister the specified override, and if it's the currently active one, |
| 75 | // ensure that something takes its place. |
| 76 | static void UnregisterAndReplaceOverride(const std::string& page, |
| 77 | Profile* profile, |
[email protected] | f3a1c64 | 2011-07-12 19:15:03 | [diff] [blame] | 78 | base::ListValue* list, |
[email protected] | 5d30f92bf | 2012-08-03 08:43:37 | [diff] [blame] | 79 | const base::Value* override); |
[email protected] | 811bfe37 | 2009-07-01 08:46:25 | [diff] [blame] | 80 | }; |
| 81 | |
[email protected] | 8f9d4eb | 2011-02-05 01:39:10 | [diff] [blame] | 82 | #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_WEB_UI_H_ |