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_event_histogram_value.h"
13 #include "extensions/browser/extension_prefs_observer.h"
15 class ExtensionFunctionRegistry
;
26 class RenderFrameHost
;
32 class NetworkDelegate
;
37 namespace extensions
{
39 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 // Return true if the system is run in forced app mode.
164 virtual bool IsRunningInForcedAppMode() = 0;
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;
171 // Returns the factory that provides an ExtensionSystem to be returned from
172 // ExtensionSystem::Get.
173 virtual ExtensionSystemProvider
* GetExtensionSystemFactory() = 0;
175 // Registers extension functions not belonging to the core extensions APIs.
176 virtual void RegisterExtensionFunctions(
177 ExtensionFunctionRegistry
* registry
) const = 0;
179 // Registers Mojo services for a RenderFrame.
180 virtual void RegisterMojoServices(content::RenderFrameHost
* render_frame_host
,
181 const Extension
* extension
) const = 0;
183 // Creates a RuntimeAPIDelegate responsible for handling extensions
184 // management-related events such as update and installation on behalf of the
185 // core runtime API implementation.
186 virtual scoped_ptr
<RuntimeAPIDelegate
> CreateRuntimeAPIDelegate(
187 content::BrowserContext
* context
) const = 0;
189 // Returns the manager of resource bundles used in extensions. Returns NULL if
190 // the manager doesn't exist.
191 virtual const ComponentExtensionResourceManager
*
192 GetComponentExtensionResourceManager() = 0;
194 // Propagate a event to all the renderers in every browser context. The
195 // implementation must be safe to call from any thread.
196 virtual void BroadcastEventToRenderers(events::HistogramValue histogram_value
,
197 const std::string
& event_name
,
198 scoped_ptr
<base::ListValue
> args
) = 0;
200 // Returns the embedder's net::NetLog.
201 virtual net::NetLog
* GetNetLog() = 0;
203 // Gets the single ExtensionCache instance shared across the browser process.
204 virtual ExtensionCache
* GetExtensionCache() = 0;
206 // Indicates whether extension update checks should be allowed.
207 virtual bool IsBackgroundUpdateAllowed() = 0;
209 // Indicates whether an extension update which specifies its minimum browser
210 // version as |min_version| can be installed by the client. Not all extensions
211 // embedders share the same versioning model, so interpretation of the string
212 // is left up to the embedder.
213 virtual bool IsMinBrowserVersionSupported(const std::string
& min_version
) = 0;
215 // Embedders can override this function to handle extension errors.
216 virtual void ReportError(content::BrowserContext
* context
,
217 scoped_ptr
<ExtensionError
> error
);
219 // Returns the ExtensionWebContentsObserver for the given |web_contents|.
220 virtual ExtensionWebContentsObserver
* GetExtensionWebContentsObserver(
221 content::WebContents
* web_contents
) = 0;
223 // Cleans up browser-side state associated with a WebView that is being
225 virtual void CleanUpWebView(content::BrowserContext
* browser_context
,
226 int embedder_process_id
,
227 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_