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
;
28 class NetworkDelegate
;
33 namespace extensions
{
35 class ApiActivityMonitor
;
38 class ExtensionHostDelegate
;
39 class ExtensionPrefsObserver
;
40 class ExtensionSystem
;
41 class ExtensionSystemProvider
;
43 class RuntimeAPIDelegate
;
45 // Interface to allow the extensions module to make browser-process-specific
46 // queries of the embedder. Should be Set() once in the browser process.
48 // NOTE: Methods that do not require knowledge of browser concepts should be
49 // added in ExtensionsClient (extensions/common/extensions_client.h) even if
50 // they are only used in the browser process.
51 class ExtensionsBrowserClient
{
53 virtual ~ExtensionsBrowserClient() {}
55 // Returns true if the embedder has started shutting down.
56 virtual bool IsShuttingDown() = 0;
58 // Returns true if extensions have been disabled (e.g. via a command-line flag
60 virtual bool AreExtensionsDisabled(const base::CommandLine
& command_line
,
61 content::BrowserContext
* context
) = 0;
63 // Returns true if the |context| is known to the embedder.
64 virtual bool IsValidContext(content::BrowserContext
* context
) = 0;
66 // Returns true if the BrowserContexts could be considered equivalent, for
67 // example, if one is an off-the-record context owned by the other.
68 virtual bool IsSameContext(content::BrowserContext
* first
,
69 content::BrowserContext
* second
) = 0;
71 // Returns true if |context| has an off-the-record context associated with it.
72 virtual bool HasOffTheRecordContext(content::BrowserContext
* context
) = 0;
74 // Returns the off-the-record context associated with |context|. If |context|
75 // is already off-the-record, returns |context|.
76 // WARNING: This may create a new off-the-record context. To avoid creating
77 // another context, check HasOffTheRecordContext() first.
78 virtual content::BrowserContext
* GetOffTheRecordContext(
79 content::BrowserContext
* context
) = 0;
81 // Returns the original "recording" context. This method returns |context| if
82 // |context| is not incognito.
83 virtual content::BrowserContext
* GetOriginalContext(
84 content::BrowserContext
* context
) = 0;
86 // Returns true if |context| corresponds to a guest session.
87 virtual bool IsGuestSession(content::BrowserContext
* context
) const = 0;
89 // Returns true if |extension_id| can run in an incognito window.
90 virtual bool IsExtensionIncognitoEnabled(
91 const std::string
& extension_id
,
92 content::BrowserContext
* context
) const = 0;
94 // Returns true if |extension| can see events and data from another
95 // sub-profile (incognito to original profile, or vice versa).
96 virtual bool CanExtensionCrossIncognito(
97 const extensions::Extension
* extension
,
98 content::BrowserContext
* context
) const = 0;
100 // Returns true if |request| corresponds to a resource request from a
102 virtual bool IsWebViewRequest(net::URLRequest
* request
) const = 0;
104 // Returns an URLRequestJob to load an extension resource from the embedder's
105 // resource bundle (.pak) files. Returns NULL if the request is not for a
106 // resource bundle resource or if the embedder does not support this feature.
107 // Used for component extensions. Called on the IO thread.
108 virtual net::URLRequestJob
* MaybeCreateResourceBundleRequestJob(
109 net::URLRequest
* request
,
110 net::NetworkDelegate
* network_delegate
,
111 const base::FilePath
& directory_path
,
112 const std::string
& content_security_policy
,
113 bool send_cors_header
) = 0;
115 // Returns true if the embedder wants to allow a chrome-extension:// resource
116 // request coming from renderer A to access a resource in an extension running
117 // in renderer B. For example, Chrome overrides this to provide support for
118 // webview and dev tools. Called on the IO thread.
119 virtual bool AllowCrossRendererResourceLoad(net::URLRequest
* request
,
121 const Extension
* extension
,
122 InfoMap
* extension_info_map
) = 0;
124 // Returns the PrefService associated with |context|.
125 virtual PrefService
* GetPrefServiceForContext(
126 content::BrowserContext
* context
) = 0;
128 // Populates a list of ExtensionPrefs observers to be attached to each
129 // BrowserContext's ExtensionPrefs upon construction. These observers
130 // are not owned by ExtensionPrefs.
131 virtual void GetEarlyExtensionPrefsObservers(
132 content::BrowserContext
* context
,
133 std::vector
<ExtensionPrefsObserver
*>* observers
) const = 0;
135 // Returns true if loading background pages should be deferred.
136 virtual bool DeferLoadingBackgroundHosts(
137 content::BrowserContext
* context
) const = 0;
139 virtual bool IsBackgroundPageAllowed(
140 content::BrowserContext
* context
) 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 // Creates a new AppSorting instance.
152 virtual scoped_ptr
<AppSorting
> CreateAppSorting() = 0;
154 // Return true if the system is run in forced app mode.
155 virtual bool IsRunningInForcedAppMode() = 0;
157 // Returns the embedder's ApiActivityMonitor for |context|. Returns NULL if
158 // the embedder does not monitor extension API activity.
159 virtual ApiActivityMonitor
* GetApiActivityMonitor(
160 content::BrowserContext
* context
) = 0;
162 // Returns the factory that provides an ExtensionSystem to be returned from
163 // ExtensionSystem::Get.
164 virtual ExtensionSystemProvider
* GetExtensionSystemFactory() = 0;
166 // Registers extension functions not belonging to the core extensions APIs.
167 virtual void RegisterExtensionFunctions(
168 ExtensionFunctionRegistry
* registry
) const = 0;
170 // Creates a RuntimeAPIDelegate responsible for handling extensions
171 // management-related events such as update and installation on behalf of the
172 // core runtime API implementation.
173 virtual scoped_ptr
<RuntimeAPIDelegate
> CreateRuntimeAPIDelegate(
174 content::BrowserContext
* context
) const = 0;
176 // Returns the single instance of |this|.
177 static ExtensionsBrowserClient
* Get();
179 // Initialize the single instance.
180 static void Set(ExtensionsBrowserClient
* client
);
183 } // namespace extensions
185 #endif // EXTENSIONS_BROWSER_EXTENSIONS_BROWSER_CLIENT_H_