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.
5 #ifndef EXTENSIONS_BROWSER_EXTENSIONS_BROWSER_CLIENT_H_
6 #define EXTENSIONS_BROWSER_EXTENSIONS_BROWSER_CLIENT_H_
11 #include "base/memory/scoped_ptr.h"
12 #include "extensions/browser/extension_prefs_observer.h"
14 class ExtensionFunctionRegistry
;
25 class RenderFrameHost
;
31 class NetworkDelegate
;
36 namespace extensions
{
38 class ApiActivityMonitor
;
40 class ComponentExtensionResourceManager
;
44 class ExtensionHostDelegate
;
45 class ExtensionPrefsObserver
;
46 class ExtensionSystem
;
47 class ExtensionSystemProvider
;
48 class ExtensionWebContentsObserver
;
50 class ProcessManagerDelegate
;
51 class RuntimeAPIDelegate
;
53 // Interface to allow the extensions module to make browser-process-specific
54 // queries of the embedder. Should be Set() once in the browser process.
56 // NOTE: Methods that do not require knowledge of browser concepts should be
57 // added in ExtensionsClient (extensions/common/extensions_client.h) even if
58 // they are only used in the browser process.
59 class ExtensionsBrowserClient
{
61 virtual ~ExtensionsBrowserClient() {}
63 // Returns true if the embedder has started shutting down.
64 virtual bool IsShuttingDown() = 0;
66 // Returns true if extensions have been disabled (e.g. via a command-line flag
68 virtual bool AreExtensionsDisabled(const base::CommandLine
& command_line
,
69 content::BrowserContext
* context
) = 0;
71 // Returns true if the |context| is known to the embedder.
72 virtual bool IsValidContext(content::BrowserContext
* context
) = 0;
74 // Returns true if the BrowserContexts could be considered equivalent, for
75 // example, if one is an off-the-record context owned by the other.
76 virtual bool IsSameContext(content::BrowserContext
* first
,
77 content::BrowserContext
* second
) = 0;
79 // Returns true if |context| has an off-the-record context associated with it.
80 virtual bool HasOffTheRecordContext(content::BrowserContext
* context
) = 0;
82 // Returns the off-the-record context associated with |context|. If |context|
83 // is already off-the-record, returns |context|.
84 // WARNING: This may create a new off-the-record context. To avoid creating
85 // another context, check HasOffTheRecordContext() first.
86 virtual content::BrowserContext
* GetOffTheRecordContext(
87 content::BrowserContext
* context
) = 0;
89 // Returns the original "recording" context. This method returns |context| if
90 // |context| is not incognito.
91 virtual content::BrowserContext
* GetOriginalContext(
92 content::BrowserContext
* context
) = 0;
94 #if defined(OS_CHROMEOS)
95 // Returns a user id hash from |context| or an empty string if no hash could
97 virtual std::string
GetUserIdHashFromContext(
98 content::BrowserContext
* context
) = 0;
101 // Returns true if |context| corresponds to a guest session.
102 virtual bool IsGuestSession(content::BrowserContext
* context
) const = 0;
104 // Returns true if |extension_id| can run in an incognito window.
105 virtual bool IsExtensionIncognitoEnabled(
106 const std::string
& extension_id
,
107 content::BrowserContext
* context
) const = 0;
109 // Returns true if |extension| can see events and data from another
110 // sub-profile (incognito to original profile, or vice versa).
111 virtual bool CanExtensionCrossIncognito(
112 const extensions::Extension
* extension
,
113 content::BrowserContext
* context
) const = 0;
115 // Returns an URLRequestJob to load an extension resource from the embedder's
116 // resource bundle (.pak) files. Returns NULL if the request is not for a
117 // resource bundle resource or if the embedder does not support this feature.
118 // Used for component extensions. Called on the IO thread.
119 virtual net::URLRequestJob
* MaybeCreateResourceBundleRequestJob(
120 net::URLRequest
* request
,
121 net::NetworkDelegate
* network_delegate
,
122 const base::FilePath
& directory_path
,
123 const std::string
& content_security_policy
,
124 bool send_cors_header
) = 0;
126 // Returns true if the embedder wants to allow a chrome-extension:// resource
127 // request coming from renderer A to access a resource in an extension running
128 // in renderer B. For example, Chrome overrides this to provide support for
129 // webview and dev tools. Called on the IO thread.
130 virtual bool AllowCrossRendererResourceLoad(net::URLRequest
* request
,
132 const Extension
* extension
,
133 InfoMap
* extension_info_map
) = 0;
135 // Returns the PrefService associated with |context|.
136 virtual PrefService
* GetPrefServiceForContext(
137 content::BrowserContext
* context
) = 0;
139 // Populates a list of ExtensionPrefs observers to be attached to each
140 // BrowserContext's ExtensionPrefs upon construction. These observers
141 // are not owned by ExtensionPrefs.
142 virtual void GetEarlyExtensionPrefsObservers(
143 content::BrowserContext
* context
,
144 std::vector
<ExtensionPrefsObserver
*>* observers
) const = 0;
146 // Returns the ProcessManagerDelegate shared across all BrowserContexts. May
147 // return NULL in tests or for simple embedders.
148 virtual ProcessManagerDelegate
* GetProcessManagerDelegate() const = 0;
150 // Creates a new ExtensionHostDelegate instance.
151 virtual scoped_ptr
<ExtensionHostDelegate
> CreateExtensionHostDelegate() = 0;
153 // Returns true if the client version has updated since the last run. Called
154 // once each time the extensions system is loaded per browser_context. The
155 // implementation may wish to use the BrowserContext to record the current
156 // version for later comparison.
157 virtual bool DidVersionUpdate(content::BrowserContext
* context
) = 0;
159 // Permits an external protocol handler to be launched. See
160 // ExternalProtocolHandler::PermitLaunchUrl() in Chrome.
161 virtual void PermitExternalProtocolHandler() = 0;
163 // Creates a new AppSorting instance.
164 virtual scoped_ptr
<AppSorting
> CreateAppSorting() = 0;
166 // Return true if the system is run in forced app mode.
167 virtual bool IsRunningInForcedAppMode() = 0;
169 // Returns the embedder's ApiActivityMonitor for |context|. Returns NULL if
170 // the embedder does not monitor extension API activity.
171 virtual ApiActivityMonitor
* GetApiActivityMonitor(
172 content::BrowserContext
* context
) = 0;
174 // Returns the factory that provides an ExtensionSystem to be returned from
175 // ExtensionSystem::Get.
176 virtual ExtensionSystemProvider
* GetExtensionSystemFactory() = 0;
178 // Registers extension functions not belonging to the core extensions APIs.
179 virtual void RegisterExtensionFunctions(
180 ExtensionFunctionRegistry
* registry
) const = 0;
182 // Registers Mojo services for a RenderFrame.
183 virtual void RegisterMojoServices(content::RenderFrameHost
* render_frame_host
,
184 const Extension
* extension
) const = 0;
186 // Creates a RuntimeAPIDelegate responsible for handling extensions
187 // management-related events such as update and installation on behalf of the
188 // core runtime API implementation.
189 virtual scoped_ptr
<RuntimeAPIDelegate
> CreateRuntimeAPIDelegate(
190 content::BrowserContext
* context
) const = 0;
192 // Returns the manager of resource bundles used in extensions. Returns NULL if
193 // the manager doesn't exist.
194 virtual const ComponentExtensionResourceManager
*
195 GetComponentExtensionResourceManager() = 0;
197 // Propagate a event to all the renderers in every browser context. The
198 // implementation must be safe to call from any thread.
199 virtual void BroadcastEventToRenderers(const std::string
& event_name
,
200 scoped_ptr
<base::ListValue
> args
) = 0;
202 // Returns the embedder's net::NetLog.
203 virtual net::NetLog
* GetNetLog() = 0;
205 // Gets the single ExtensionCache instance shared across the browser process.
206 virtual ExtensionCache
* GetExtensionCache() = 0;
208 // Indicates whether extension update checks should be allowed.
209 virtual bool IsBackgroundUpdateAllowed() = 0;
211 // Indicates whether an extension update which specifies its minimum browser
212 // version as |min_version| can be installed by the client. Not all extensions
213 // embedders share the same versioning model, so interpretation of the string
214 // is left up to the embedder.
215 virtual bool IsMinBrowserVersionSupported(const std::string
& min_version
) = 0;
217 // Embedders can override this function to handle extension errors.
218 virtual void ReportError(content::BrowserContext
* context
,
219 scoped_ptr
<ExtensionError
> error
);
221 // Returns the ExtensionWebContentsObserver for the given |web_contents|.
222 virtual ExtensionWebContentsObserver
* GetExtensionWebContentsObserver(
223 content::WebContents
* web_contents
) = 0;
225 // Cleans up browser-side state associated with a WebView that is being
227 virtual void CleanUpWebView(int embedder_process_id
, int view_instance_id
) {}
229 // Returns the single instance of |this|.
230 static ExtensionsBrowserClient
* Get();
232 // Initialize the single instance.
233 static void Set(ExtensionsBrowserClient
* client
);
236 } // namespace extensions
238 #endif // EXTENSIONS_BROWSER_EXTENSIONS_BROWSER_CLIENT_H_