blob: 7616d5cb63f20e3f8772b45a96fa2ad849e83c59 [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;
[email protected]2f3b1cc2014-03-17 23:07:1520}
21
[email protected]9fe42042013-10-29 21:13:3322namespace content {
23class BrowserContext;
[email protected]9be525e2014-01-10 20:52:4024class WebContents;
[email protected]9fe42042013-10-29 21:13:3325}
26
[email protected]1791e6c92014-04-11 08:29:0127namespace net {
[email protected]4d1663782014-07-25 21:44:3628class NetLog;
[email protected]1791e6c92014-04-11 08:29:0129class NetworkDelegate;
30class URLRequest;
31class URLRequestJob;
32}
33
[email protected]9fe42042013-10-29 21:13:3334namespace extensions {
35
[email protected]b32260f2014-02-06 10:03:4136class ApiActivityMonitor;
[email protected]bf5ee7cc2013-11-23 20:48:4437class AppSorting;
[email protected]326e6f02014-06-20 04:53:3738class ComponentExtensionResourceManager;
[email protected]6a3d8ce42014-02-07 00:42:3739class Extension;
[email protected]6c0f179f2014-03-19 11:04:4140class ExtensionHostDelegate;
[email protected]d31e2482014-04-02 22:52:2041class ExtensionPrefsObserver;
[email protected]8172a9d2014-01-09 23:18:3042class ExtensionSystem;
[email protected]70489302014-02-13 15:15:4843class ExtensionSystemProvider;
[email protected]1791e6c92014-04-11 08:29:0144class InfoMap;
[email protected]6b54fda2014-07-22 02:13:4745class ProcessManagerDelegate;
[email protected]f0e9ac552014-05-07 14:26:5046class RuntimeAPIDelegate;
[email protected]bf5ee7cc2013-11-23 20:48:4447
[email protected]9fe42042013-10-29 21:13:3348// 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.
54class 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]367d9b172013-12-03 00:31:0261 // Returns true if extensions have been disabled (e.g. via a command-line flag
62 // or preference).
[email protected]2f3b1cc2014-03-17 23:07:1563 virtual bool AreExtensionsDisabled(const base::CommandLine& command_line,
[email protected]367d9b172013-12-03 00:31:0264 content::BrowserContext* context) = 0;
65
[email protected]45fd94172013-11-13 03:29:5266 // Returns true if the |context| is known to the embedder.
67 virtual bool IsValidContext(content::BrowserContext* context) = 0;
68
[email protected]9fe42042013-10-29 21:13:3369 // 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]7f474212013-11-05 04:26:1674 // Returns true if |context| has an off-the-record context associated with it.
[email protected]9fe42042013-10-29 21:13:3375 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]489db0842014-01-22 18:20:0384 // Returns the original "recording" context. This method returns |context| if
[email protected]7f474212013-11-05 04:26:1685 // |context| is not incognito.
86 virtual content::BrowserContext* GetOriginalContext(
87 content::BrowserContext* context) = 0;
88
[email protected]a5fc73e2014-02-13 20:26:4789 // Returns true if |context| corresponds to a guest session.
[email protected]d012be2b2014-03-03 17:02:4790 virtual bool IsGuestSession(content::BrowserContext* context) const = 0;
[email protected]a5fc73e2014-02-13 20:26:4791
[email protected]6a3d8ce42014-02-07 00:42:3792 // 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]b32f21732014-04-16 18:25:16103 // 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]1791e6c92014-04-11 08:29:01107 // 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]367d9b172013-12-03 00:31:02127 // Returns the PrefService associated with |context|.
128 virtual PrefService* GetPrefServiceForContext(
129 content::BrowserContext* context) = 0;
130
[email protected]d31e2482014-04-02 22:52:20131 // 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]6b54fda2014-07-22 02:13:47138 // 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]d0d1c052013-12-21 07:20:22141
[email protected]6c0f179f2014-03-19 11:04:41142 // Creates a new ExtensionHostDelegate instance.
143 virtual scoped_ptr<ExtensionHostDelegate> CreateExtensionHostDelegate() = 0;
[email protected]a36b55602014-02-08 02:32:32144
[email protected]45fd94172013-11-13 03:29:52145 // 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]513b8032013-11-18 07:47:49147 // 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]45fd94172013-11-13 03:29:52150
[email protected]bf5ee7cc2013-11-23 20:48:44151 // Creates a new AppSorting instance.
152 virtual scoped_ptr<AppSorting> CreateAppSorting() = 0;
153
[email protected]45928b682013-11-28 08:20:27154 // Return true if the system is run in forced app mode.
155 virtual bool IsRunningInForcedAppMode() = 0;
156
[email protected]b32260f2014-02-06 10:03:41157 // 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]70489302014-02-13 15:15:48162 // Returns the factory that provides an ExtensionSystem to be returned from
163 // ExtensionSystem::Get.
164 virtual ExtensionSystemProvider* GetExtensionSystemFactory() = 0;
[email protected]8172a9d2014-01-09 23:18:30165
[email protected]21c6c432014-03-05 18:47:31166 // Registers extension functions not belonging to the core extensions APIs.
167 virtual void RegisterExtensionFunctions(
168 ExtensionFunctionRegistry* registry) const = 0;
169
[email protected]f0e9ac552014-05-07 14:26:50170 // 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]326e6f02014-06-20 04:53:37176 // 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]4d1663782014-07-25 21:44:36181 // Returns the embedder's net::NetLog.
182 virtual net::NetLog* GetNetLog() = 0;
183
[email protected]9fe42042013-10-29 21:13:33184 // 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_