[email protected] | 9fe4204 | 2013-10-29 21:13:33 | [diff] [blame] | 1 | // Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #ifndef EXTENSIONS_BROWSER_EXTENSIONS_BROWSER_CLIENT_H_ |
| 6 | #define EXTENSIONS_BROWSER_EXTENSIONS_BROWSER_CLIENT_H_ |
| 7 | |
[email protected] | 6a3d8ce4 | 2014-02-07 00:42:37 | [diff] [blame] | 8 | #include <string> |
[email protected] | 8172a9d | 2014-01-09 23:18:30 | [diff] [blame] | 9 | #include <vector> |
| 10 | |
[email protected] | bf5ee7cc | 2013-11-23 20:48:44 | [diff] [blame] | 11 | #include "base/memory/scoped_ptr.h" |
[email protected] | d31e248 | 2014-04-02 22:52:20 | [diff] [blame] | 12 | #include "extensions/browser/extension_prefs_observer.h" |
[email protected] | bf5ee7cc | 2013-11-23 20:48:44 | [diff] [blame] | 13 | |
[email protected] | 21c6c43 | 2014-03-05 18:47:31 | [diff] [blame] | 14 | class ExtensionFunctionRegistry; |
[email protected] | 367d9b17 | 2013-12-03 00:31:02 | [diff] [blame] | 15 | class PrefService; |
| 16 | |
[email protected] | 2f3b1cc | 2014-03-17 23:07:15 | [diff] [blame] | 17 | namespace base { |
| 18 | class CommandLine; |
[email protected] | 1791e6c9 | 2014-04-11 08:29:01 | [diff] [blame] | 19 | class FilePath; |
thiago.santos | 89e236b | 2014-09-05 13:29:49 | [diff] [blame] | 20 | class ListValue; |
[email protected] | 2f3b1cc | 2014-03-17 23:07:15 | [diff] [blame] | 21 | } |
| 22 | |
[email protected] | 9fe4204 | 2013-10-29 21:13:33 | [diff] [blame] | 23 | namespace content { |
| 24 | class BrowserContext; |
[email protected] | 9be525e | 2014-01-10 20:52:40 | [diff] [blame] | 25 | class WebContents; |
[email protected] | 9fe4204 | 2013-10-29 21:13:33 | [diff] [blame] | 26 | } |
| 27 | |
[email protected] | 1791e6c9 | 2014-04-11 08:29:01 | [diff] [blame] | 28 | namespace net { |
[email protected] | 4d166378 | 2014-07-25 21:44:36 | [diff] [blame] | 29 | class NetLog; |
[email protected] | 1791e6c9 | 2014-04-11 08:29:01 | [diff] [blame] | 30 | class NetworkDelegate; |
| 31 | class URLRequest; |
| 32 | class URLRequestJob; |
| 33 | } |
| 34 | |
[email protected] | 9fe4204 | 2013-10-29 21:13:33 | [diff] [blame] | 35 | namespace extensions { |
| 36 | |
[email protected] | b32260f | 2014-02-06 10:03:41 | [diff] [blame] | 37 | class ApiActivityMonitor; |
[email protected] | bf5ee7cc | 2013-11-23 20:48:44 | [diff] [blame] | 38 | class AppSorting; |
[email protected] | 326e6f0 | 2014-06-20 04:53:37 | [diff] [blame] | 39 | class ComponentExtensionResourceManager; |
[email protected] | 6a3d8ce4 | 2014-02-07 00:42:37 | [diff] [blame] | 40 | class Extension; |
rockot | ffa65b1 | 2014-10-14 17:19:06 | [diff] [blame] | 41 | class ExtensionCache; |
[email protected] | 6c0f179f | 2014-03-19 11:04:41 | [diff] [blame] | 42 | class ExtensionHostDelegate; |
[email protected] | d31e248 | 2014-04-02 22:52:20 | [diff] [blame] | 43 | class ExtensionPrefsObserver; |
[email protected] | 8172a9d | 2014-01-09 23:18:30 | [diff] [blame] | 44 | class ExtensionSystem; |
[email protected] | 7048930 | 2014-02-13 15:15:48 | [diff] [blame] | 45 | class ExtensionSystemProvider; |
[email protected] | 1791e6c9 | 2014-04-11 08:29:01 | [diff] [blame] | 46 | class InfoMap; |
[email protected] | 6b54fda | 2014-07-22 02:13:47 | [diff] [blame] | 47 | class ProcessManagerDelegate; |
[email protected] | f0e9ac55 | 2014-05-07 14:26:50 | [diff] [blame] | 48 | class RuntimeAPIDelegate; |
[email protected] | bf5ee7cc | 2013-11-23 20:48:44 | [diff] [blame] | 49 | |
[email protected] | 9fe4204 | 2013-10-29 21:13:33 | [diff] [blame] | 50 | // Interface to allow the extensions module to make browser-process-specific |
| 51 | // queries of the embedder. Should be Set() once in the browser process. |
| 52 | // |
| 53 | // NOTE: Methods that do not require knowledge of browser concepts should be |
| 54 | // added in ExtensionsClient (extensions/common/extensions_client.h) even if |
| 55 | // they are only used in the browser process. |
| 56 | class ExtensionsBrowserClient { |
| 57 | public: |
| 58 | virtual ~ExtensionsBrowserClient() {} |
| 59 | |
| 60 | // Returns true if the embedder has started shutting down. |
| 61 | virtual bool IsShuttingDown() = 0; |
| 62 | |
[email protected] | 367d9b17 | 2013-12-03 00:31:02 | [diff] [blame] | 63 | // Returns true if extensions have been disabled (e.g. via a command-line flag |
| 64 | // or preference). |
[email protected] | 2f3b1cc | 2014-03-17 23:07:15 | [diff] [blame] | 65 | virtual bool AreExtensionsDisabled(const base::CommandLine& command_line, |
[email protected] | 367d9b17 | 2013-12-03 00:31:02 | [diff] [blame] | 66 | content::BrowserContext* context) = 0; |
| 67 | |
[email protected] | 45fd9417 | 2013-11-13 03:29:52 | [diff] [blame] | 68 | // Returns true if the |context| is known to the embedder. |
| 69 | virtual bool IsValidContext(content::BrowserContext* context) = 0; |
| 70 | |
[email protected] | 9fe4204 | 2013-10-29 21:13:33 | [diff] [blame] | 71 | // Returns true if the BrowserContexts could be considered equivalent, for |
| 72 | // example, if one is an off-the-record context owned by the other. |
| 73 | virtual bool IsSameContext(content::BrowserContext* first, |
| 74 | content::BrowserContext* second) = 0; |
| 75 | |
[email protected] | 7f47421 | 2013-11-05 04:26:16 | [diff] [blame] | 76 | // Returns true if |context| has an off-the-record context associated with it. |
[email protected] | 9fe4204 | 2013-10-29 21:13:33 | [diff] [blame] | 77 | virtual bool HasOffTheRecordContext(content::BrowserContext* context) = 0; |
| 78 | |
| 79 | // Returns the off-the-record context associated with |context|. If |context| |
| 80 | // is already off-the-record, returns |context|. |
| 81 | // WARNING: This may create a new off-the-record context. To avoid creating |
| 82 | // another context, check HasOffTheRecordContext() first. |
| 83 | virtual content::BrowserContext* GetOffTheRecordContext( |
| 84 | content::BrowserContext* context) = 0; |
| 85 | |
[email protected] | 489db084 | 2014-01-22 18:20:03 | [diff] [blame] | 86 | // Returns the original "recording" context. This method returns |context| if |
[email protected] | 7f47421 | 2013-11-05 04:26:16 | [diff] [blame] | 87 | // |context| is not incognito. |
| 88 | virtual content::BrowserContext* GetOriginalContext( |
| 89 | content::BrowserContext* context) = 0; |
| 90 | |
stevenjb | d194dd136 | 2015-01-28 17:30:08 | [diff] [blame] | 91 | #if defined(OS_CHROMEOS) |
| 92 | // Returns a user id hash from |context| or an empty string if no hash could |
| 93 | // be extracted. |
| 94 | virtual std::string GetUserIdHashFromContext( |
| 95 | content::BrowserContext* context) = 0; |
| 96 | #endif |
| 97 | |
[email protected] | a5fc73e | 2014-02-13 20:26:47 | [diff] [blame] | 98 | // Returns true if |context| corresponds to a guest session. |
[email protected] | d012be2b | 2014-03-03 17:02:47 | [diff] [blame] | 99 | virtual bool IsGuestSession(content::BrowserContext* context) const = 0; |
[email protected] | a5fc73e | 2014-02-13 20:26:47 | [diff] [blame] | 100 | |
[email protected] | 6a3d8ce4 | 2014-02-07 00:42:37 | [diff] [blame] | 101 | // Returns true if |extension_id| can run in an incognito window. |
| 102 | virtual bool IsExtensionIncognitoEnabled( |
| 103 | const std::string& extension_id, |
| 104 | content::BrowserContext* context) const = 0; |
| 105 | |
| 106 | // Returns true if |extension| can see events and data from another |
| 107 | // sub-profile (incognito to original profile, or vice versa). |
| 108 | virtual bool CanExtensionCrossIncognito( |
| 109 | const extensions::Extension* extension, |
| 110 | content::BrowserContext* context) const = 0; |
| 111 | |
[email protected] | 1791e6c9 | 2014-04-11 08:29:01 | [diff] [blame] | 112 | // Returns an URLRequestJob to load an extension resource from the embedder's |
| 113 | // resource bundle (.pak) files. Returns NULL if the request is not for a |
| 114 | // resource bundle resource or if the embedder does not support this feature. |
| 115 | // Used for component extensions. Called on the IO thread. |
| 116 | virtual net::URLRequestJob* MaybeCreateResourceBundleRequestJob( |
| 117 | net::URLRequest* request, |
| 118 | net::NetworkDelegate* network_delegate, |
| 119 | const base::FilePath& directory_path, |
| 120 | const std::string& content_security_policy, |
| 121 | bool send_cors_header) = 0; |
| 122 | |
| 123 | // Returns true if the embedder wants to allow a chrome-extension:// resource |
| 124 | // request coming from renderer A to access a resource in an extension running |
| 125 | // in renderer B. For example, Chrome overrides this to provide support for |
| 126 | // webview and dev tools. Called on the IO thread. |
| 127 | virtual bool AllowCrossRendererResourceLoad(net::URLRequest* request, |
| 128 | bool is_incognito, |
| 129 | const Extension* extension, |
| 130 | InfoMap* extension_info_map) = 0; |
| 131 | |
[email protected] | 367d9b17 | 2013-12-03 00:31:02 | [diff] [blame] | 132 | // Returns the PrefService associated with |context|. |
| 133 | virtual PrefService* GetPrefServiceForContext( |
| 134 | content::BrowserContext* context) = 0; |
| 135 | |
[email protected] | d31e248 | 2014-04-02 22:52:20 | [diff] [blame] | 136 | // Populates a list of ExtensionPrefs observers to be attached to each |
| 137 | // BrowserContext's ExtensionPrefs upon construction. These observers |
| 138 | // are not owned by ExtensionPrefs. |
| 139 | virtual void GetEarlyExtensionPrefsObservers( |
| 140 | content::BrowserContext* context, |
| 141 | std::vector<ExtensionPrefsObserver*>* observers) const = 0; |
| 142 | |
[email protected] | 6b54fda | 2014-07-22 02:13:47 | [diff] [blame] | 143 | // Returns the ProcessManagerDelegate shared across all BrowserContexts. May |
| 144 | // return NULL in tests or for simple embedders. |
| 145 | virtual ProcessManagerDelegate* GetProcessManagerDelegate() const = 0; |
[email protected] | d0d1c05 | 2013-12-21 07:20:22 | [diff] [blame] | 146 | |
[email protected] | 6c0f179f | 2014-03-19 11:04:41 | [diff] [blame] | 147 | // Creates a new ExtensionHostDelegate instance. |
| 148 | virtual scoped_ptr<ExtensionHostDelegate> CreateExtensionHostDelegate() = 0; |
[email protected] | a36b5560 | 2014-02-08 02:32:32 | [diff] [blame] | 149 | |
[email protected] | 45fd9417 | 2013-11-13 03:29:52 | [diff] [blame] | 150 | // Returns true if the client version has updated since the last run. Called |
| 151 | // once each time the extensions system is loaded per browser_context. The |
[email protected] | 513b803 | 2013-11-18 07:47:49 | [diff] [blame] | 152 | // implementation may wish to use the BrowserContext to record the current |
| 153 | // version for later comparison. |
| 154 | virtual bool DidVersionUpdate(content::BrowserContext* context) = 0; |
[email protected] | 45fd9417 | 2013-11-13 03:29:52 | [diff] [blame] | 155 | |
[email protected] | 86fad30d | 2014-07-29 21:39:27 | [diff] [blame] | 156 | // Permits an external protocol handler to be launched. See |
| 157 | // ExternalProtocolHandler::PermitLaunchUrl() in Chrome. |
| 158 | virtual void PermitExternalProtocolHandler() = 0; |
| 159 | |
[email protected] | bf5ee7cc | 2013-11-23 20:48:44 | [diff] [blame] | 160 | // Creates a new AppSorting instance. |
| 161 | virtual scoped_ptr<AppSorting> CreateAppSorting() = 0; |
| 162 | |
[email protected] | 45928b68 | 2013-11-28 08:20:27 | [diff] [blame] | 163 | // Return true if the system is run in forced app mode. |
| 164 | virtual bool IsRunningInForcedAppMode() = 0; |
| 165 | |
[email protected] | b32260f | 2014-02-06 10:03:41 | [diff] [blame] | 166 | // Returns the embedder's ApiActivityMonitor for |context|. Returns NULL if |
| 167 | // the embedder does not monitor extension API activity. |
| 168 | virtual ApiActivityMonitor* GetApiActivityMonitor( |
| 169 | content::BrowserContext* context) = 0; |
| 170 | |
[email protected] | 7048930 | 2014-02-13 15:15:48 | [diff] [blame] | 171 | // Returns the factory that provides an ExtensionSystem to be returned from |
| 172 | // ExtensionSystem::Get. |
| 173 | virtual ExtensionSystemProvider* GetExtensionSystemFactory() = 0; |
[email protected] | 8172a9d | 2014-01-09 23:18:30 | [diff] [blame] | 174 | |
[email protected] | 21c6c43 | 2014-03-05 18:47:31 | [diff] [blame] | 175 | // Registers extension functions not belonging to the core extensions APIs. |
| 176 | virtual void RegisterExtensionFunctions( |
| 177 | ExtensionFunctionRegistry* registry) const = 0; |
| 178 | |
[email protected] | f0e9ac55 | 2014-05-07 14:26:50 | [diff] [blame] | 179 | // Creates a RuntimeAPIDelegate responsible for handling extensions |
| 180 | // management-related events such as update and installation on behalf of the |
| 181 | // core runtime API implementation. |
| 182 | virtual scoped_ptr<RuntimeAPIDelegate> CreateRuntimeAPIDelegate( |
| 183 | content::BrowserContext* context) const = 0; |
| 184 | |
[email protected] | 326e6f0 | 2014-06-20 04:53:37 | [diff] [blame] | 185 | // Returns the manager of resource bundles used in extensions. Returns NULL if |
| 186 | // the manager doesn't exist. |
mukai | ee458c9 | 2015-01-06 01:30:33 | [diff] [blame] | 187 | virtual const ComponentExtensionResourceManager* |
[email protected] | 326e6f0 | 2014-06-20 04:53:37 | [diff] [blame] | 188 | GetComponentExtensionResourceManager() = 0; |
| 189 | |
thiago.santos | 89e236b | 2014-09-05 13:29:49 | [diff] [blame] | 190 | // Propagate a event to all the renderers in every browser context. The |
| 191 | // implementation must be safe to call from any thread. |
| 192 | virtual void BroadcastEventToRenderers(const std::string& event_name, |
| 193 | scoped_ptr<base::ListValue> args) = 0; |
| 194 | |
[email protected] | 4d166378 | 2014-07-25 21:44:36 | [diff] [blame] | 195 | // Returns the embedder's net::NetLog. |
| 196 | virtual net::NetLog* GetNetLog() = 0; |
| 197 | |
rockot | ffa65b1 | 2014-10-14 17:19:06 | [diff] [blame] | 198 | // Gets the single ExtensionCache instance shared across the browser process. |
| 199 | virtual ExtensionCache* GetExtensionCache() = 0; |
| 200 | |
rockot | f2a6b62c | 2014-10-15 21:58:07 | [diff] [blame] | 201 | // Indicates whether extension update checks should be allowed. |
| 202 | virtual bool IsBackgroundUpdateAllowed() = 0; |
| 203 | |
| 204 | // Indicates whether an extension update which specifies its minimum browser |
| 205 | // version as |min_version| can be installed by the client. Not all extensions |
| 206 | // embedders share the same versioning model, so interpretation of the string |
| 207 | // is left up to the embedder. |
| 208 | virtual bool IsMinBrowserVersionSupported(const std::string& min_version) = 0; |
| 209 | |
[email protected] | 9fe4204 | 2013-10-29 21:13:33 | [diff] [blame] | 210 | // Returns the single instance of |this|. |
| 211 | static ExtensionsBrowserClient* Get(); |
| 212 | |
| 213 | // Initialize the single instance. |
| 214 | static void Set(ExtensionsBrowserClient* client); |
| 215 | }; |
| 216 | |
| 217 | } // namespace extensions |
| 218 | |
| 219 | #endif // EXTENSIONS_BROWSER_EXTENSIONS_BROWSER_CLIENT_H_ |