blob: 0cf646682a22887639c40acf6f03296fff3b8497 [file] [log] [blame]
[email protected]9fe42042013-10-29 21:13:331// 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]6a3d8ce42014-02-07 00:42:378#include <string>
[email protected]8172a9d2014-01-09 23:18:309#include <vector>
10
[email protected]bf5ee7cc2013-11-23 20:48:4411#include "base/memory/scoped_ptr.h"
[email protected]d31e2482014-04-02 22:52:2012#include "extensions/browser/extension_prefs_observer.h"
[email protected]bf5ee7cc2013-11-23 20:48:4413
[email protected]21c6c432014-03-05 18:47:3114class ExtensionFunctionRegistry;
[email protected]367d9b172013-12-03 00:31:0215class PrefService;
16
[email protected]2f3b1cc2014-03-17 23:07:1517namespace base {
18class CommandLine;
[email protected]1791e6c92014-04-11 08:29:0119class FilePath;
thiago.santos89e236b2014-09-05 13:29:4920class ListValue;
[email protected]2f3b1cc2014-03-17 23:07:1521}
22
[email protected]9fe42042013-10-29 21:13:3323namespace content {
24class BrowserContext;
[email protected]9be525e2014-01-10 20:52:4025class WebContents;
[email protected]9fe42042013-10-29 21:13:3326}
27
[email protected]1791e6c92014-04-11 08:29:0128namespace net {
[email protected]4d1663782014-07-25 21:44:3629class NetLog;
[email protected]1791e6c92014-04-11 08:29:0130class NetworkDelegate;
31class URLRequest;
32class URLRequestJob;
33}
34
[email protected]9fe42042013-10-29 21:13:3335namespace extensions {
36
[email protected]b32260f2014-02-06 10:03:4137class ApiActivityMonitor;
[email protected]bf5ee7cc2013-11-23 20:48:4438class AppSorting;
[email protected]326e6f02014-06-20 04:53:3739class ComponentExtensionResourceManager;
[email protected]6a3d8ce42014-02-07 00:42:3740class Extension;
rockotffa65b12014-10-14 17:19:0641class ExtensionCache;
[email protected]6c0f179f2014-03-19 11:04:4142class ExtensionHostDelegate;
[email protected]d31e2482014-04-02 22:52:2043class ExtensionPrefsObserver;
[email protected]8172a9d2014-01-09 23:18:3044class ExtensionSystem;
[email protected]70489302014-02-13 15:15:4845class ExtensionSystemProvider;
[email protected]1791e6c92014-04-11 08:29:0146class InfoMap;
[email protected]6b54fda2014-07-22 02:13:4747class ProcessManagerDelegate;
[email protected]f0e9ac552014-05-07 14:26:5048class RuntimeAPIDelegate;
[email protected]bf5ee7cc2013-11-23 20:48:4449
[email protected]9fe42042013-10-29 21:13:3350// 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.
56class 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]367d9b172013-12-03 00:31:0263 // Returns true if extensions have been disabled (e.g. via a command-line flag
64 // or preference).
[email protected]2f3b1cc2014-03-17 23:07:1565 virtual bool AreExtensionsDisabled(const base::CommandLine& command_line,
[email protected]367d9b172013-12-03 00:31:0266 content::BrowserContext* context) = 0;
67
[email protected]45fd94172013-11-13 03:29:5268 // Returns true if the |context| is known to the embedder.
69 virtual bool IsValidContext(content::BrowserContext* context) = 0;
70
[email protected]9fe42042013-10-29 21:13:3371 // 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]7f474212013-11-05 04:26:1676 // Returns true if |context| has an off-the-record context associated with it.
[email protected]9fe42042013-10-29 21:13:3377 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]489db0842014-01-22 18:20:0386 // Returns the original "recording" context. This method returns |context| if
[email protected]7f474212013-11-05 04:26:1687 // |context| is not incognito.
88 virtual content::BrowserContext* GetOriginalContext(
89 content::BrowserContext* context) = 0;
90
stevenjbd194dd1362015-01-28 17:30:0891#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]a5fc73e2014-02-13 20:26:4798 // Returns true if |context| corresponds to a guest session.
[email protected]d012be2b2014-03-03 17:02:4799 virtual bool IsGuestSession(content::BrowserContext* context) const = 0;
[email protected]a5fc73e2014-02-13 20:26:47100
[email protected]6a3d8ce42014-02-07 00:42:37101 // 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]1791e6c92014-04-11 08:29:01112 // 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]367d9b172013-12-03 00:31:02132 // Returns the PrefService associated with |context|.
133 virtual PrefService* GetPrefServiceForContext(
134 content::BrowserContext* context) = 0;
135
[email protected]d31e2482014-04-02 22:52:20136 // 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]6b54fda2014-07-22 02:13:47143 // 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]d0d1c052013-12-21 07:20:22146
[email protected]6c0f179f2014-03-19 11:04:41147 // Creates a new ExtensionHostDelegate instance.
148 virtual scoped_ptr<ExtensionHostDelegate> CreateExtensionHostDelegate() = 0;
[email protected]a36b55602014-02-08 02:32:32149
[email protected]45fd94172013-11-13 03:29:52150 // 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]513b8032013-11-18 07:47:49152 // 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]45fd94172013-11-13 03:29:52155
[email protected]86fad30d2014-07-29 21:39:27156 // Permits an external protocol handler to be launched. See
157 // ExternalProtocolHandler::PermitLaunchUrl() in Chrome.
158 virtual void PermitExternalProtocolHandler() = 0;
159
[email protected]bf5ee7cc2013-11-23 20:48:44160 // Creates a new AppSorting instance.
161 virtual scoped_ptr<AppSorting> CreateAppSorting() = 0;
162
[email protected]45928b682013-11-28 08:20:27163 // Return true if the system is run in forced app mode.
164 virtual bool IsRunningInForcedAppMode() = 0;
165
[email protected]b32260f2014-02-06 10:03:41166 // 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]70489302014-02-13 15:15:48171 // Returns the factory that provides an ExtensionSystem to be returned from
172 // ExtensionSystem::Get.
173 virtual ExtensionSystemProvider* GetExtensionSystemFactory() = 0;
[email protected]8172a9d2014-01-09 23:18:30174
[email protected]21c6c432014-03-05 18:47:31175 // Registers extension functions not belonging to the core extensions APIs.
176 virtual void RegisterExtensionFunctions(
177 ExtensionFunctionRegistry* registry) const = 0;
178
[email protected]f0e9ac552014-05-07 14:26:50179 // 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]326e6f02014-06-20 04:53:37185 // Returns the manager of resource bundles used in extensions. Returns NULL if
186 // the manager doesn't exist.
mukaiee458c92015-01-06 01:30:33187 virtual const ComponentExtensionResourceManager*
[email protected]326e6f02014-06-20 04:53:37188 GetComponentExtensionResourceManager() = 0;
189
thiago.santos89e236b2014-09-05 13:29:49190 // 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]4d1663782014-07-25 21:44:36195 // Returns the embedder's net::NetLog.
196 virtual net::NetLog* GetNetLog() = 0;
197
rockotffa65b12014-10-14 17:19:06198 // Gets the single ExtensionCache instance shared across the browser process.
199 virtual ExtensionCache* GetExtensionCache() = 0;
200
rockotf2a6b62c2014-10-15 21:58:07201 // 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]9fe42042013-10-29 21:13:33210 // 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_