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
;
30 class NetworkDelegate
;
35 namespace extensions
{
37 class ApiActivityMonitor
;
39 class ComponentExtensionResourceManager
;
42 class ExtensionHostDelegate
;
43 class ExtensionPrefsObserver
;
44 class ExtensionSystem
;
45 class ExtensionSystemProvider
;
47 class ProcessManagerDelegate
;
48 class RuntimeAPIDelegate
;
50 // Interface to allow the extensions module to make browser-process-specific
51 // queries of the embedder. Should be Set() once in the browser process.
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.
56 class ExtensionsBrowserClient
{
58 virtual ~ExtensionsBrowserClient() {}
60 // Returns true if the embedder has started shutting down.
61 virtual bool IsShuttingDown() = 0;
63 // Returns true if extensions have been disabled (e.g. via a command-line flag
65 virtual bool AreExtensionsDisabled(const base::CommandLine
& command_line
,
66 content::BrowserContext
* context
) = 0;
68 // Returns true if the |context| is known to the embedder.
69 virtual bool IsValidContext(content::BrowserContext
* context
) = 0;
71 // 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;
76 // Returns true if |context| has an off-the-record context associated with it.
77 virtual bool HasOffTheRecordContext(content::BrowserContext
* context
) = 0;
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;
86 // Returns the original "recording" context. This method returns |context| if
87 // |context| is not incognito.
88 virtual content::BrowserContext
* GetOriginalContext(
89 content::BrowserContext
* context
) = 0;
91 // Returns true if |context| corresponds to a guest session.
92 virtual bool IsGuestSession(content::BrowserContext
* context
) const = 0;
94 // Returns true if |extension_id| can run in an incognito window.
95 virtual bool IsExtensionIncognitoEnabled(
96 const std::string
& extension_id
,
97 content::BrowserContext
* context
) const = 0;
99 // Returns true if |extension| can see events and data from another
100 // sub-profile (incognito to original profile, or vice versa).
101 virtual bool CanExtensionCrossIncognito(
102 const extensions::Extension
* extension
,
103 content::BrowserContext
* context
) const = 0;
105 // Returns an URLRequestJob to load an extension resource from the embedder's
106 // resource bundle (.pak) files. Returns NULL if the request is not for a
107 // resource bundle resource or if the embedder does not support this feature.
108 // Used for component extensions. Called on the IO thread.
109 virtual net::URLRequestJob
* MaybeCreateResourceBundleRequestJob(
110 net::URLRequest
* request
,
111 net::NetworkDelegate
* network_delegate
,
112 const base::FilePath
& directory_path
,
113 const std::string
& content_security_policy
,
114 bool send_cors_header
) = 0;
116 // Returns true if the embedder wants to allow a chrome-extension:// resource
117 // request coming from renderer A to access a resource in an extension running
118 // in renderer B. For example, Chrome overrides this to provide support for
119 // webview and dev tools. Called on the IO thread.
120 virtual bool AllowCrossRendererResourceLoad(net::URLRequest
* request
,
122 const Extension
* extension
,
123 InfoMap
* extension_info_map
) = 0;
125 // Returns the PrefService associated with |context|.
126 virtual PrefService
* GetPrefServiceForContext(
127 content::BrowserContext
* context
) = 0;
129 // Populates a list of ExtensionPrefs observers to be attached to each
130 // BrowserContext's ExtensionPrefs upon construction. These observers
131 // are not owned by ExtensionPrefs.
132 virtual void GetEarlyExtensionPrefsObservers(
133 content::BrowserContext
* context
,
134 std::vector
<ExtensionPrefsObserver
*>* observers
) const = 0;
136 // Returns the ProcessManagerDelegate shared across all BrowserContexts. May
137 // return NULL in tests or for simple embedders.
138 virtual ProcessManagerDelegate
* GetProcessManagerDelegate() const = 0;
140 // Creates a new ExtensionHostDelegate instance.
141 virtual scoped_ptr
<ExtensionHostDelegate
> CreateExtensionHostDelegate() = 0;
143 // Returns true if the client version has updated since the last run. Called
144 // once each time the extensions system is loaded per browser_context. The
145 // implementation may wish to use the BrowserContext to record the current
146 // version for later comparison.
147 virtual bool DidVersionUpdate(content::BrowserContext
* context
) = 0;
149 // Permits an external protocol handler to be launched. See
150 // ExternalProtocolHandler::PermitLaunchUrl() in Chrome.
151 virtual void PermitExternalProtocolHandler() = 0;
153 // Creates a new AppSorting instance.
154 virtual scoped_ptr
<AppSorting
> CreateAppSorting() = 0;
156 // Return true if the system is run in forced app mode.
157 virtual bool IsRunningInForcedAppMode() = 0;
159 // Returns the embedder's ApiActivityMonitor for |context|. Returns NULL if
160 // the embedder does not monitor extension API activity.
161 virtual ApiActivityMonitor
* GetApiActivityMonitor(
162 content::BrowserContext
* context
) = 0;
164 // Returns the factory that provides an ExtensionSystem to be returned from
165 // ExtensionSystem::Get.
166 virtual ExtensionSystemProvider
* GetExtensionSystemFactory() = 0;
168 // Registers extension functions not belonging to the core extensions APIs.
169 virtual void RegisterExtensionFunctions(
170 ExtensionFunctionRegistry
* registry
) const = 0;
172 // Creates a RuntimeAPIDelegate responsible for handling extensions
173 // management-related events such as update and installation on behalf of the
174 // core runtime API implementation.
175 virtual scoped_ptr
<RuntimeAPIDelegate
> CreateRuntimeAPIDelegate(
176 content::BrowserContext
* context
) const = 0;
178 // Returns the manager of resource bundles used in extensions. Returns NULL if
179 // the manager doesn't exist.
180 virtual const ComponentExtensionResourceManager
*
181 GetComponentExtensionResourceManager() = 0;
183 // Propagate a event to all the renderers in every browser context. The
184 // implementation must be safe to call from any thread.
185 virtual void BroadcastEventToRenderers(const std::string
& event_name
,
186 scoped_ptr
<base::ListValue
> args
) = 0;
188 // Returns the embedder's net::NetLog.
189 virtual net::NetLog
* GetNetLog() = 0;
191 // Gets the single ExtensionCache instance shared across the browser process.
192 virtual ExtensionCache
* GetExtensionCache() = 0;
194 // Indicates whether extension update checks should be allowed.
195 virtual bool IsBackgroundUpdateAllowed() = 0;
197 // Indicates whether an extension update which specifies its minimum browser
198 // version as |min_version| can be installed by the client. Not all extensions
199 // embedders share the same versioning model, so interpretation of the string
200 // is left up to the embedder.
201 virtual bool IsMinBrowserVersionSupported(const std::string
& min_version
) = 0;
203 // Returns the single instance of |this|.
204 static ExtensionsBrowserClient
* Get();
206 // Initialize the single instance.
207 static void Set(ExtensionsBrowserClient
* client
);
210 } // namespace extensions
212 #endif // EXTENSIONS_BROWSER_EXTENSIONS_BROWSER_CLIENT_H_