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
;
43 class ExtensionHostDelegate
;
44 class ExtensionPrefsObserver
;
45 class ExtensionSystem
;
46 class ExtensionSystemProvider
;
48 class ProcessManagerDelegate
;
49 class RuntimeAPIDelegate
;
51 // Interface to allow the extensions module to make browser-process-specific
52 // queries of the embedder. Should be Set() once in the browser process.
54 // NOTE: Methods that do not require knowledge of browser concepts should be
55 // added in ExtensionsClient (extensions/common/extensions_client.h) even if
56 // they are only used in the browser process.
57 class ExtensionsBrowserClient
{
59 virtual ~ExtensionsBrowserClient() {}
61 // Returns true if the embedder has started shutting down.
62 virtual bool IsShuttingDown() = 0;
64 // Returns true if extensions have been disabled (e.g. via a command-line flag
66 virtual bool AreExtensionsDisabled(const base::CommandLine
& command_line
,
67 content::BrowserContext
* context
) = 0;
69 // Returns true if the |context| is known to the embedder.
70 virtual bool IsValidContext(content::BrowserContext
* context
) = 0;
72 // Returns true if the BrowserContexts could be considered equivalent, for
73 // example, if one is an off-the-record context owned by the other.
74 virtual bool IsSameContext(content::BrowserContext
* first
,
75 content::BrowserContext
* second
) = 0;
77 // Returns true if |context| has an off-the-record context associated with it.
78 virtual bool HasOffTheRecordContext(content::BrowserContext
* context
) = 0;
80 // Returns the off-the-record context associated with |context|. If |context|
81 // is already off-the-record, returns |context|.
82 // WARNING: This may create a new off-the-record context. To avoid creating
83 // another context, check HasOffTheRecordContext() first.
84 virtual content::BrowserContext
* GetOffTheRecordContext(
85 content::BrowserContext
* context
) = 0;
87 // Returns the original "recording" context. This method returns |context| if
88 // |context| is not incognito.
89 virtual content::BrowserContext
* GetOriginalContext(
90 content::BrowserContext
* context
) = 0;
92 #if defined(OS_CHROMEOS)
93 // Returns a user id hash from |context| or an empty string if no hash could
95 virtual std::string
GetUserIdHashFromContext(
96 content::BrowserContext
* context
) = 0;
99 // Returns true if |context| corresponds to a guest session.
100 virtual bool IsGuestSession(content::BrowserContext
* context
) const = 0;
102 // Returns true if |extension_id| can run in an incognito window.
103 virtual bool IsExtensionIncognitoEnabled(
104 const std::string
& extension_id
,
105 content::BrowserContext
* context
) const = 0;
107 // Returns true if |extension| can see events and data from another
108 // sub-profile (incognito to original profile, or vice versa).
109 virtual bool CanExtensionCrossIncognito(
110 const extensions::Extension
* extension
,
111 content::BrowserContext
* context
) const = 0;
113 // Returns an URLRequestJob to load an extension resource from the embedder's
114 // resource bundle (.pak) files. Returns NULL if the request is not for a
115 // resource bundle resource or if the embedder does not support this feature.
116 // Used for component extensions. Called on the IO thread.
117 virtual net::URLRequestJob
* MaybeCreateResourceBundleRequestJob(
118 net::URLRequest
* request
,
119 net::NetworkDelegate
* network_delegate
,
120 const base::FilePath
& directory_path
,
121 const std::string
& content_security_policy
,
122 bool send_cors_header
) = 0;
124 // Returns true if the embedder wants to allow a chrome-extension:// resource
125 // request coming from renderer A to access a resource in an extension running
126 // in renderer B. For example, Chrome overrides this to provide support for
127 // webview and dev tools. Called on the IO thread.
128 virtual bool AllowCrossRendererResourceLoad(net::URLRequest
* request
,
130 const Extension
* extension
,
131 InfoMap
* extension_info_map
) = 0;
133 // Returns the PrefService associated with |context|.
134 virtual PrefService
* GetPrefServiceForContext(
135 content::BrowserContext
* context
) = 0;
137 // Populates a list of ExtensionPrefs observers to be attached to each
138 // BrowserContext's ExtensionPrefs upon construction. These observers
139 // are not owned by ExtensionPrefs.
140 virtual void GetEarlyExtensionPrefsObservers(
141 content::BrowserContext
* context
,
142 std::vector
<ExtensionPrefsObserver
*>* observers
) const = 0;
144 // Returns the ProcessManagerDelegate shared across all BrowserContexts. May
145 // return NULL in tests or for simple embedders.
146 virtual ProcessManagerDelegate
* GetProcessManagerDelegate() const = 0;
148 // Creates a new ExtensionHostDelegate instance.
149 virtual scoped_ptr
<ExtensionHostDelegate
> CreateExtensionHostDelegate() = 0;
151 // Returns true if the client version has updated since the last run. Called
152 // once each time the extensions system is loaded per browser_context. The
153 // implementation may wish to use the BrowserContext to record the current
154 // version for later comparison.
155 virtual bool DidVersionUpdate(content::BrowserContext
* context
) = 0;
157 // Permits an external protocol handler to be launched. See
158 // ExternalProtocolHandler::PermitLaunchUrl() in Chrome.
159 virtual void PermitExternalProtocolHandler() = 0;
161 // Creates a new AppSorting instance.
162 virtual scoped_ptr
<AppSorting
> CreateAppSorting() = 0;
164 // Return true if the system is run in forced app mode.
165 virtual bool IsRunningInForcedAppMode() = 0;
167 // Returns the embedder's ApiActivityMonitor for |context|. Returns NULL if
168 // the embedder does not monitor extension API activity.
169 virtual ApiActivityMonitor
* GetApiActivityMonitor(
170 content::BrowserContext
* context
) = 0;
172 // Returns the factory that provides an ExtensionSystem to be returned from
173 // ExtensionSystem::Get.
174 virtual ExtensionSystemProvider
* GetExtensionSystemFactory() = 0;
176 // Registers extension functions not belonging to the core extensions APIs.
177 virtual void RegisterExtensionFunctions(
178 ExtensionFunctionRegistry
* registry
) const = 0;
180 // Registers Mojo services for a RenderFrame.
181 virtual void RegisterMojoServices(content::RenderFrameHost
* render_frame_host
,
182 const Extension
* extension
) const = 0;
184 // Creates a RuntimeAPIDelegate responsible for handling extensions
185 // management-related events such as update and installation on behalf of the
186 // core runtime API implementation.
187 virtual scoped_ptr
<RuntimeAPIDelegate
> CreateRuntimeAPIDelegate(
188 content::BrowserContext
* context
) const = 0;
190 // Returns the manager of resource bundles used in extensions. Returns NULL if
191 // the manager doesn't exist.
192 virtual const ComponentExtensionResourceManager
*
193 GetComponentExtensionResourceManager() = 0;
195 // Propagate a event to all the renderers in every browser context. The
196 // implementation must be safe to call from any thread.
197 virtual void BroadcastEventToRenderers(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 // Returns the single instance of |this|.
216 static ExtensionsBrowserClient
* Get();
218 // Initialize the single instance.
219 static void Set(ExtensionsBrowserClient
* client
);
222 } // namespace extensions
224 #endif // EXTENSIONS_BROWSER_EXTENSIONS_BROWSER_CLIENT_H_