Unregister from GCM when the only GCM app is removed
[chromium-blink-merge.git] / extensions / browser / extensions_browser_client.h
blob0cf646682a22887639c40acf6f03296fff3b8497
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_prefs_observer.h"
14 class ExtensionFunctionRegistry;
15 class PrefService;
17 namespace base {
18 class CommandLine;
19 class FilePath;
20 class ListValue;
23 namespace content {
24 class BrowserContext;
25 class WebContents;
28 namespace net {
29 class NetLog;
30 class NetworkDelegate;
31 class URLRequest;
32 class URLRequestJob;
35 namespace extensions {
37 class ApiActivityMonitor;
38 class AppSorting;
39 class ComponentExtensionResourceManager;
40 class Extension;
41 class ExtensionCache;
42 class ExtensionHostDelegate;
43 class ExtensionPrefsObserver;
44 class ExtensionSystem;
45 class ExtensionSystemProvider;
46 class InfoMap;
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 {
57 public:
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
64 // or preference).
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 #if defined(OS_CHROMEOS)
92 // Returns a user id hash from |context| or an empty string if no hash could
93 // be extracted.
94 virtual std::string GetUserIdHashFromContext(
95 content::BrowserContext* context) = 0;
96 #endif
98 // Returns true if |context| corresponds to a guest session.
99 virtual bool IsGuestSession(content::BrowserContext* context) const = 0;
101 // Returns true if |extension_id| can run in an incognito window.
102 virtual bool IsExtensionIncognitoEnabled(
103 const std::string& extension_id,
104 content::BrowserContext* context) const = 0;
106 // Returns true if |extension| can see events and data from another
107 // sub-profile (incognito to original profile, or vice versa).
108 virtual bool CanExtensionCrossIncognito(
109 const extensions::Extension* extension,
110 content::BrowserContext* context) const = 0;
112 // Returns an URLRequestJob to load an extension resource from the embedder's
113 // resource bundle (.pak) files. Returns NULL if the request is not for a
114 // resource bundle resource or if the embedder does not support this feature.
115 // Used for component extensions. Called on the IO thread.
116 virtual net::URLRequestJob* MaybeCreateResourceBundleRequestJob(
117 net::URLRequest* request,
118 net::NetworkDelegate* network_delegate,
119 const base::FilePath& directory_path,
120 const std::string& content_security_policy,
121 bool send_cors_header) = 0;
123 // Returns true if the embedder wants to allow a chrome-extension:// resource
124 // request coming from renderer A to access a resource in an extension running
125 // in renderer B. For example, Chrome overrides this to provide support for
126 // webview and dev tools. Called on the IO thread.
127 virtual bool AllowCrossRendererResourceLoad(net::URLRequest* request,
128 bool is_incognito,
129 const Extension* extension,
130 InfoMap* extension_info_map) = 0;
132 // Returns the PrefService associated with |context|.
133 virtual PrefService* GetPrefServiceForContext(
134 content::BrowserContext* context) = 0;
136 // Populates a list of ExtensionPrefs observers to be attached to each
137 // BrowserContext's ExtensionPrefs upon construction. These observers
138 // are not owned by ExtensionPrefs.
139 virtual void GetEarlyExtensionPrefsObservers(
140 content::BrowserContext* context,
141 std::vector<ExtensionPrefsObserver*>* observers) const = 0;
143 // Returns the ProcessManagerDelegate shared across all BrowserContexts. May
144 // return NULL in tests or for simple embedders.
145 virtual ProcessManagerDelegate* GetProcessManagerDelegate() const = 0;
147 // Creates a new ExtensionHostDelegate instance.
148 virtual scoped_ptr<ExtensionHostDelegate> CreateExtensionHostDelegate() = 0;
150 // Returns true if the client version has updated since the last run. Called
151 // once each time the extensions system is loaded per browser_context. The
152 // implementation may wish to use the BrowserContext to record the current
153 // version for later comparison.
154 virtual bool DidVersionUpdate(content::BrowserContext* context) = 0;
156 // Permits an external protocol handler to be launched. See
157 // ExternalProtocolHandler::PermitLaunchUrl() in Chrome.
158 virtual void PermitExternalProtocolHandler() = 0;
160 // Creates a new AppSorting instance.
161 virtual scoped_ptr<AppSorting> CreateAppSorting() = 0;
163 // Return true if the system is run in forced app mode.
164 virtual bool IsRunningInForcedAppMode() = 0;
166 // Returns the embedder's ApiActivityMonitor for |context|. Returns NULL if
167 // the embedder does not monitor extension API activity.
168 virtual ApiActivityMonitor* GetApiActivityMonitor(
169 content::BrowserContext* context) = 0;
171 // Returns the factory that provides an ExtensionSystem to be returned from
172 // ExtensionSystem::Get.
173 virtual ExtensionSystemProvider* GetExtensionSystemFactory() = 0;
175 // Registers extension functions not belonging to the core extensions APIs.
176 virtual void RegisterExtensionFunctions(
177 ExtensionFunctionRegistry* registry) const = 0;
179 // Creates a RuntimeAPIDelegate responsible for handling extensions
180 // management-related events such as update and installation on behalf of the
181 // core runtime API implementation.
182 virtual scoped_ptr<RuntimeAPIDelegate> CreateRuntimeAPIDelegate(
183 content::BrowserContext* context) const = 0;
185 // Returns the manager of resource bundles used in extensions. Returns NULL if
186 // the manager doesn't exist.
187 virtual const ComponentExtensionResourceManager*
188 GetComponentExtensionResourceManager() = 0;
190 // Propagate a event to all the renderers in every browser context. The
191 // implementation must be safe to call from any thread.
192 virtual void BroadcastEventToRenderers(const std::string& event_name,
193 scoped_ptr<base::ListValue> args) = 0;
195 // Returns the embedder's net::NetLog.
196 virtual net::NetLog* GetNetLog() = 0;
198 // Gets the single ExtensionCache instance shared across the browser process.
199 virtual ExtensionCache* GetExtensionCache() = 0;
201 // Indicates whether extension update checks should be allowed.
202 virtual bool IsBackgroundUpdateAllowed() = 0;
204 // Indicates whether an extension update which specifies its minimum browser
205 // version as |min_version| can be installed by the client. Not all extensions
206 // embedders share the same versioning model, so interpretation of the string
207 // is left up to the embedder.
208 virtual bool IsMinBrowserVersionSupported(const std::string& min_version) = 0;
210 // Returns the single instance of |this|.
211 static ExtensionsBrowserClient* Get();
213 // Initialize the single instance.
214 static void Set(ExtensionsBrowserClient* client);
217 } // namespace extensions
219 #endif // EXTENSIONS_BROWSER_EXTENSIONS_BROWSER_CLIENT_H_