Pin Chrome's shortcut to the Win10 Start menu on install and OS upgrade.
[chromium-blink-merge.git] / extensions / browser / extensions_browser_client.h
blob672b9251de9252174a0fd3767da28eea22112a8e
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"
15 class ExtensionFunctionRegistry;
16 class PrefService;
18 namespace base {
19 class CommandLine;
20 class FilePath;
21 class ListValue;
24 namespace content {
25 class BrowserContext;
26 class RenderFrameHost;
27 class WebContents;
30 namespace net {
31 class NetLog;
32 class NetworkDelegate;
33 class URLRequest;
34 class URLRequestJob;
37 namespace extensions {
39 class ApiActivityMonitor;
40 class AppSorting;
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 // Creates a new AppSorting instance.
165 virtual scoped_ptr<AppSorting> CreateAppSorting(
166 content::BrowserContext* context) = 0;
168 // Return true if the system is run in forced app mode.
169 virtual bool IsRunningInForcedAppMode() = 0;
171 // Returns the embedder's ApiActivityMonitor for |context|. Returns NULL if
172 // the embedder does not monitor extension API activity.
173 virtual ApiActivityMonitor* GetApiActivityMonitor(
174 content::BrowserContext* context) = 0;
176 // Returns the factory that provides an ExtensionSystem to be returned from
177 // ExtensionSystem::Get.
178 virtual ExtensionSystemProvider* GetExtensionSystemFactory() = 0;
180 // Registers extension functions not belonging to the core extensions APIs.
181 virtual void RegisterExtensionFunctions(
182 ExtensionFunctionRegistry* registry) const = 0;
184 // Registers Mojo services for a RenderFrame.
185 virtual void RegisterMojoServices(content::RenderFrameHost* render_frame_host,
186 const Extension* extension) const = 0;
188 // Creates a RuntimeAPIDelegate responsible for handling extensions
189 // management-related events such as update and installation on behalf of the
190 // core runtime API implementation.
191 virtual scoped_ptr<RuntimeAPIDelegate> CreateRuntimeAPIDelegate(
192 content::BrowserContext* context) const = 0;
194 // Returns the manager of resource bundles used in extensions. Returns NULL if
195 // the manager doesn't exist.
196 virtual const ComponentExtensionResourceManager*
197 GetComponentExtensionResourceManager() = 0;
199 // Propagate a event to all the renderers in every browser context. The
200 // implementation must be safe to call from any thread.
201 virtual void BroadcastEventToRenderers(events::HistogramValue histogram_value,
202 const std::string& event_name,
203 scoped_ptr<base::ListValue> args) = 0;
205 // Returns the embedder's net::NetLog.
206 virtual net::NetLog* GetNetLog() = 0;
208 // Gets the single ExtensionCache instance shared across the browser process.
209 virtual ExtensionCache* GetExtensionCache() = 0;
211 // Indicates whether extension update checks should be allowed.
212 virtual bool IsBackgroundUpdateAllowed() = 0;
214 // Indicates whether an extension update which specifies its minimum browser
215 // version as |min_version| can be installed by the client. Not all extensions
216 // embedders share the same versioning model, so interpretation of the string
217 // is left up to the embedder.
218 virtual bool IsMinBrowserVersionSupported(const std::string& min_version) = 0;
220 // Embedders can override this function to handle extension errors.
221 virtual void ReportError(content::BrowserContext* context,
222 scoped_ptr<ExtensionError> error);
224 // Returns the ExtensionWebContentsObserver for the given |web_contents|.
225 virtual ExtensionWebContentsObserver* GetExtensionWebContentsObserver(
226 content::WebContents* web_contents) = 0;
228 // Cleans up browser-side state associated with a WebView that is being
229 // destroyed.
230 virtual void CleanUpWebView(int embedder_process_id, int view_instance_id) {}
232 // Returns the single instance of |this|.
233 static ExtensionsBrowserClient* Get();
235 // Initialize the single instance.
236 static void Set(ExtensionsBrowserClient* client);
239 } // namespace extensions
241 #endif // EXTENSIONS_BROWSER_EXTENSIONS_BROWSER_CLIENT_H_