Added condition that checks if ephemeral user has GAIA account (not a public session...
[chromium-blink-merge.git] / extensions / browser / extensions_browser_client.h
blob8b66051ead124e92fb10ffe09d1a5cd18b8cc03a
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_
8 #include <string>
9 #include <vector>
11 #include "base/memory/scoped_ptr.h"
12 #include "extensions/browser/extension_event_histogram_value.h"
13 #include "extensions/browser/extension_prefs_observer.h"
14 #include "extensions/common/view_type.h"
16 class ExtensionFunctionRegistry;
17 class PrefService;
19 namespace base {
20 class CommandLine;
21 class FilePath;
22 class ListValue;
25 namespace content {
26 class BrowserContext;
27 class RenderFrameHost;
28 class WebContents;
31 namespace net {
32 class NetLog;
33 class NetworkDelegate;
34 class URLRequest;
35 class URLRequestJob;
38 namespace extensions {
40 class ApiActivityMonitor;
41 class ComponentExtensionResourceManager;
42 class Extension;
43 class ExtensionCache;
44 class ExtensionError;
45 class ExtensionHostDelegate;
46 class ExtensionPrefsObserver;
47 class ExtensionSystem;
48 class ExtensionSystemProvider;
49 class ExtensionWebContentsObserver;
50 class InfoMap;
51 class ProcessManagerDelegate;
52 class RuntimeAPIDelegate;
54 // Interface to allow the extensions module to make browser-process-specific
55 // queries of the embedder. Should be Set() once in the browser process.
57 // NOTE: Methods that do not require knowledge of browser concepts should be
58 // added in ExtensionsClient (extensions/common/extensions_client.h) even if
59 // they are only used in the browser process.
60 class ExtensionsBrowserClient {
61 public:
62 virtual ~ExtensionsBrowserClient() {}
64 // Returns true if the embedder has started shutting down.
65 virtual bool IsShuttingDown() = 0;
67 // Returns true if extensions have been disabled (e.g. via a command-line flag
68 // or preference).
69 virtual bool AreExtensionsDisabled(const base::CommandLine& command_line,
70 content::BrowserContext* context) = 0;
72 // Returns true if the |context| is known to the embedder.
73 virtual bool IsValidContext(content::BrowserContext* context) = 0;
75 // Returns true if the BrowserContexts could be considered equivalent, for
76 // example, if one is an off-the-record context owned by the other.
77 virtual bool IsSameContext(content::BrowserContext* first,
78 content::BrowserContext* second) = 0;
80 // Returns true if |context| has an off-the-record context associated with it.
81 virtual bool HasOffTheRecordContext(content::BrowserContext* context) = 0;
83 // Returns the off-the-record context associated with |context|. If |context|
84 // is already off-the-record, returns |context|.
85 // WARNING: This may create a new off-the-record context. To avoid creating
86 // another context, check HasOffTheRecordContext() first.
87 virtual content::BrowserContext* GetOffTheRecordContext(
88 content::BrowserContext* context) = 0;
90 // Returns the original "recording" context. This method returns |context| if
91 // |context| is not incognito.
92 virtual content::BrowserContext* GetOriginalContext(
93 content::BrowserContext* context) = 0;
95 #if defined(OS_CHROMEOS)
96 // Returns a user id hash from |context| or an empty string if no hash could
97 // be extracted.
98 virtual std::string GetUserIdHashFromContext(
99 content::BrowserContext* context) = 0;
100 #endif
102 // Returns true if |context| corresponds to a guest session.
103 virtual bool IsGuestSession(content::BrowserContext* context) const = 0;
105 // Returns true if |extension_id| can run in an incognito window.
106 virtual bool IsExtensionIncognitoEnabled(
107 const std::string& extension_id,
108 content::BrowserContext* context) const = 0;
110 // Returns true if |extension| can see events and data from another
111 // sub-profile (incognito to original profile, or vice versa).
112 virtual bool CanExtensionCrossIncognito(
113 const extensions::Extension* extension,
114 content::BrowserContext* context) const = 0;
116 // Returns an URLRequestJob to load an extension resource from the embedder's
117 // resource bundle (.pak) files. Returns NULL if the request is not for a
118 // resource bundle resource or if the embedder does not support this feature.
119 // Used for component extensions. Called on the IO thread.
120 virtual net::URLRequestJob* MaybeCreateResourceBundleRequestJob(
121 net::URLRequest* request,
122 net::NetworkDelegate* network_delegate,
123 const base::FilePath& directory_path,
124 const std::string& content_security_policy,
125 bool send_cors_header) = 0;
127 // Returns true if the embedder wants to allow a chrome-extension:// resource
128 // request coming from renderer A to access a resource in an extension running
129 // in renderer B. For example, Chrome overrides this to provide support for
130 // webview and dev tools. Called on the IO thread.
131 virtual bool AllowCrossRendererResourceLoad(net::URLRequest* request,
132 bool is_incognito,
133 const Extension* extension,
134 InfoMap* extension_info_map) = 0;
136 // Returns the PrefService associated with |context|.
137 virtual PrefService* GetPrefServiceForContext(
138 content::BrowserContext* context) = 0;
140 // Populates a list of ExtensionPrefs observers to be attached to each
141 // BrowserContext's ExtensionPrefs upon construction. These observers
142 // are not owned by ExtensionPrefs.
143 virtual void GetEarlyExtensionPrefsObservers(
144 content::BrowserContext* context,
145 std::vector<ExtensionPrefsObserver*>* observers) const = 0;
147 // Returns the ProcessManagerDelegate shared across all BrowserContexts. May
148 // return NULL in tests or for simple embedders.
149 virtual ProcessManagerDelegate* GetProcessManagerDelegate() const = 0;
151 // Creates a new ExtensionHostDelegate instance.
152 virtual scoped_ptr<ExtensionHostDelegate> CreateExtensionHostDelegate() = 0;
154 // Returns true if the client version has updated since the last run. Called
155 // once each time the extensions system is loaded per browser_context. The
156 // implementation may wish to use the BrowserContext to record the current
157 // version for later comparison.
158 virtual bool DidVersionUpdate(content::BrowserContext* context) = 0;
160 // Permits an external protocol handler to be launched. See
161 // ExternalProtocolHandler::PermitLaunchUrl() in Chrome.
162 virtual void PermitExternalProtocolHandler() = 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(events::HistogramValue histogram_value,
198 const std::string& event_name,
199 scoped_ptr<base::ListValue> args) = 0;
201 // Returns the embedder's net::NetLog.
202 virtual net::NetLog* GetNetLog() = 0;
204 // Gets the single ExtensionCache instance shared across the browser process.
205 virtual ExtensionCache* GetExtensionCache() = 0;
207 // Indicates whether extension update checks should be allowed.
208 virtual bool IsBackgroundUpdateAllowed() = 0;
210 // Indicates whether an extension update which specifies its minimum browser
211 // version as |min_version| can be installed by the client. Not all extensions
212 // embedders share the same versioning model, so interpretation of the string
213 // is left up to the embedder.
214 virtual bool IsMinBrowserVersionSupported(const std::string& min_version) = 0;
216 // Embedders can override this function to handle extension errors.
217 virtual void ReportError(content::BrowserContext* context,
218 scoped_ptr<ExtensionError> error);
220 // Returns the ExtensionWebContentsObserver for the given |web_contents|.
221 virtual ExtensionWebContentsObserver* GetExtensionWebContentsObserver(
222 content::WebContents* web_contents) = 0;
224 // Cleans up browser-side state associated with a WebView that is being
225 // destroyed.
226 virtual void CleanUpWebView(content::BrowserContext* browser_context,
227 int embedder_process_id,
228 int view_instance_id) {}
230 // Attaches the task manager extension tag to |web_contents|, if needed based
231 // on |view_type|, so that its corresponding task shows up in the task
232 // manager.
233 virtual void AttachExtensionTaskManagerTag(content::WebContents* web_contents,
234 ViewType view_type) {}
236 // Returns the single instance of |this|.
237 static ExtensionsBrowserClient* Get();
239 // Initialize the single instance.
240 static void Set(ExtensionsBrowserClient* client);
243 } // namespace extensions
245 #endif // EXTENSIONS_BROWSER_EXTENSIONS_BROWSER_CLIENT_H_