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
;
29 class NetworkDelegate
;
34 namespace extensions
{
36 class ApiActivityMonitor
;
38 class ComponentExtensionResourceManager
;
40 class ExtensionHostDelegate
;
41 class ExtensionPrefsObserver
;
42 class ExtensionSystem
;
43 class ExtensionSystemProvider
;
45 class ProcessManagerDelegate
;
46 class RuntimeAPIDelegate
;
48 // Interface to allow the extensions module to make browser-process-specific
49 // queries of the embedder. Should be Set() once in the browser process.
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.
54 class ExtensionsBrowserClient
{
56 virtual ~ExtensionsBrowserClient() {}
58 // Returns true if the embedder has started shutting down.
59 virtual bool IsShuttingDown() = 0;
61 // Returns true if extensions have been disabled (e.g. via a command-line flag
63 virtual bool AreExtensionsDisabled(const base::CommandLine
& command_line
,
64 content::BrowserContext
* context
) = 0;
66 // Returns true if the |context| is known to the embedder.
67 virtual bool IsValidContext(content::BrowserContext
* context
) = 0;
69 // 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;
74 // Returns true if |context| has an off-the-record context associated with it.
75 virtual bool HasOffTheRecordContext(content::BrowserContext
* context
) = 0;
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;
84 // Returns the original "recording" context. This method returns |context| if
85 // |context| is not incognito.
86 virtual content::BrowserContext
* GetOriginalContext(
87 content::BrowserContext
* context
) = 0;
89 // Returns true if |context| corresponds to a guest session.
90 virtual bool IsGuestSession(content::BrowserContext
* context
) const = 0;
92 // 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;
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;
103 // Returns true if |request| corresponds to a resource request from a
105 virtual bool IsWebViewRequest(net::URLRequest
* request
) const = 0;
107 // 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;
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
,
124 const Extension
* extension
,
125 InfoMap
* extension_info_map
) = 0;
127 // Returns the PrefService associated with |context|.
128 virtual PrefService
* GetPrefServiceForContext(
129 content::BrowserContext
* context
) = 0;
131 // 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;
138 // Returns the ProcessManagerDelegate shared across all BrowserContexts. May
139 // return NULL in tests or for simple embedders.
140 virtual ProcessManagerDelegate
* GetProcessManagerDelegate() const = 0;
142 // Creates a new ExtensionHostDelegate instance.
143 virtual scoped_ptr
<ExtensionHostDelegate
> CreateExtensionHostDelegate() = 0;
145 // 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
147 // implementation may wish to use the BrowserContext to record the current
148 // version for later comparison.
149 virtual bool DidVersionUpdate(content::BrowserContext
* context
) = 0;
151 // Permits an external protocol handler to be launched. See
152 // ExternalProtocolHandler::PermitLaunchUrl() in Chrome.
153 virtual void PermitExternalProtocolHandler() = 0;
155 // Creates a new AppSorting instance.
156 virtual scoped_ptr
<AppSorting
> CreateAppSorting() = 0;
158 // Return true if the system is run in forced app mode.
159 virtual bool IsRunningInForcedAppMode() = 0;
161 // Returns the embedder's ApiActivityMonitor for |context|. Returns NULL if
162 // the embedder does not monitor extension API activity.
163 virtual ApiActivityMonitor
* GetApiActivityMonitor(
164 content::BrowserContext
* context
) = 0;
166 // Returns the factory that provides an ExtensionSystem to be returned from
167 // ExtensionSystem::Get.
168 virtual ExtensionSystemProvider
* GetExtensionSystemFactory() = 0;
170 // Registers extension functions not belonging to the core extensions APIs.
171 virtual void RegisterExtensionFunctions(
172 ExtensionFunctionRegistry
* registry
) const = 0;
174 // Creates a RuntimeAPIDelegate responsible for handling extensions
175 // management-related events such as update and installation on behalf of the
176 // core runtime API implementation.
177 virtual scoped_ptr
<RuntimeAPIDelegate
> CreateRuntimeAPIDelegate(
178 content::BrowserContext
* context
) const = 0;
180 // Returns the manager of resource bundles used in extensions. Returns NULL if
181 // the manager doesn't exist.
182 virtual ComponentExtensionResourceManager
*
183 GetComponentExtensionResourceManager() = 0;
185 // Returns the embedder's net::NetLog.
186 virtual net::NetLog
* GetNetLog() = 0;
188 // Returns the single instance of |this|.
189 static ExtensionsBrowserClient
* Get();
191 // Initialize the single instance.
192 static void Set(ExtensionsBrowserClient
* client
);
195 } // namespace extensions
197 #endif // EXTENSIONS_BROWSER_EXTENSIONS_BROWSER_CLIENT_H_