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