• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.
4 
5 #ifndef EXTENSIONS_BROWSER_EXTENSIONS_BROWSER_CLIENT_H_
6 #define EXTENSIONS_BROWSER_EXTENSIONS_BROWSER_CLIENT_H_
7 
8 #include <string>
9 #include <vector>
10 
11 #include "base/memory/scoped_ptr.h"
12 #include "extensions/browser/extension_prefs_observer.h"
13 
14 class ExtensionFunctionRegistry;
15 class PrefService;
16 
17 namespace base {
18 class CommandLine;
19 class FilePath;
20 }
21 
22 namespace content {
23 class BrowserContext;
24 class WebContents;
25 }
26 
27 namespace net {
28 class NetworkDelegate;
29 class URLRequest;
30 class URLRequestJob;
31 }
32 
33 namespace extensions {
34 
35 class ApiActivityMonitor;
36 class AppSorting;
37 class ComponentExtensionResourceManager;
38 class Extension;
39 class ExtensionHostDelegate;
40 class ExtensionPrefsObserver;
41 class ExtensionSystem;
42 class ExtensionSystemProvider;
43 class InfoMap;
44 class RuntimeAPIDelegate;
45 
46 // Interface to allow the extensions module to make browser-process-specific
47 // queries of the embedder. Should be Set() once in the browser process.
48 //
49 // NOTE: Methods that do not require knowledge of browser concepts should be
50 // added in ExtensionsClient (extensions/common/extensions_client.h) even if
51 // they are only used in the browser process.
52 class ExtensionsBrowserClient {
53  public:
~ExtensionsBrowserClient()54   virtual ~ExtensionsBrowserClient() {}
55 
56   // Returns true if the embedder has started shutting down.
57   virtual bool IsShuttingDown() = 0;
58 
59   // Returns true if extensions have been disabled (e.g. via a command-line flag
60   // or preference).
61   virtual bool AreExtensionsDisabled(const base::CommandLine& command_line,
62                                      content::BrowserContext* context) = 0;
63 
64   // Returns true if the |context| is known to the embedder.
65   virtual bool IsValidContext(content::BrowserContext* context) = 0;
66 
67   // Returns true if the BrowserContexts could be considered equivalent, for
68   // example, if one is an off-the-record context owned by the other.
69   virtual bool IsSameContext(content::BrowserContext* first,
70                              content::BrowserContext* second) = 0;
71 
72   // Returns true if |context| has an off-the-record context associated with it.
73   virtual bool HasOffTheRecordContext(content::BrowserContext* context) = 0;
74 
75   // Returns the off-the-record context associated with |context|. If |context|
76   // is already off-the-record, returns |context|.
77   // WARNING: This may create a new off-the-record context. To avoid creating
78   // another context, check HasOffTheRecordContext() first.
79   virtual content::BrowserContext* GetOffTheRecordContext(
80       content::BrowserContext* context) = 0;
81 
82   // Returns the original "recording" context. This method returns |context| if
83   // |context| is not incognito.
84   virtual content::BrowserContext* GetOriginalContext(
85       content::BrowserContext* context) = 0;
86 
87   // Returns true if |context| corresponds to a guest session.
88   virtual bool IsGuestSession(content::BrowserContext* context) const = 0;
89 
90   // Returns true if |extension_id| can run in an incognito window.
91   virtual bool IsExtensionIncognitoEnabled(
92       const std::string& extension_id,
93       content::BrowserContext* context) const = 0;
94 
95   // Returns true if |extension| can see events and data from another
96   // sub-profile (incognito to original profile, or vice versa).
97   virtual bool CanExtensionCrossIncognito(
98       const extensions::Extension* extension,
99       content::BrowserContext* context) const = 0;
100 
101   // Returns true if |request| corresponds to a resource request from a
102   // <webview>.
103   virtual bool IsWebViewRequest(net::URLRequest* request) const = 0;
104 
105   // Returns an URLRequestJob to load an extension resource from the embedder's
106   // resource bundle (.pak) files. Returns NULL if the request is not for a
107   // resource bundle resource or if the embedder does not support this feature.
108   // Used for component extensions. Called on the IO thread.
109   virtual net::URLRequestJob* MaybeCreateResourceBundleRequestJob(
110       net::URLRequest* request,
111       net::NetworkDelegate* network_delegate,
112       const base::FilePath& directory_path,
113       const std::string& content_security_policy,
114       bool send_cors_header) = 0;
115 
116   // Returns true if the embedder wants to allow a chrome-extension:// resource
117   // request coming from renderer A to access a resource in an extension running
118   // in renderer B. For example, Chrome overrides this to provide support for
119   // webview and dev tools. Called on the IO thread.
120   virtual bool AllowCrossRendererResourceLoad(net::URLRequest* request,
121                                               bool is_incognito,
122                                               const Extension* extension,
123                                               InfoMap* extension_info_map) = 0;
124 
125   // Returns the PrefService associated with |context|.
126   virtual PrefService* GetPrefServiceForContext(
127       content::BrowserContext* context) = 0;
128 
129   // Populates a list of ExtensionPrefs observers to be attached to each
130   // BrowserContext's ExtensionPrefs upon construction. These observers
131   // are not owned by ExtensionPrefs.
132   virtual void GetEarlyExtensionPrefsObservers(
133       content::BrowserContext* context,
134       std::vector<ExtensionPrefsObserver*>* observers) const = 0;
135 
136   // Returns true if loading background pages should be deferred.
137   virtual bool DeferLoadingBackgroundHosts(
138       content::BrowserContext* context) const = 0;
139 
140   virtual bool IsBackgroundPageAllowed(
141       content::BrowserContext* context) const = 0;
142 
143   // Creates a new ExtensionHostDelegate instance.
144   virtual scoped_ptr<ExtensionHostDelegate> CreateExtensionHostDelegate() = 0;
145 
146   // Returns true if the client version has updated since the last run. Called
147   // once each time the extensions system is loaded per browser_context. The
148   // implementation may wish to use the BrowserContext to record the current
149   // version for later comparison.
150   virtual bool DidVersionUpdate(content::BrowserContext* context) = 0;
151 
152   // Permits an external protocol handler to be launched. See
153   // ExternalProtocolHandler::PermitLaunchUrl() in Chrome.
154   virtual void PermitExternalProtocolHandler() = 0;
155 
156   // Creates a new AppSorting instance.
157   virtual scoped_ptr<AppSorting> CreateAppSorting() = 0;
158 
159   // Return true if the system is run in forced app mode.
160   virtual bool IsRunningInForcedAppMode() = 0;
161 
162   // Returns the embedder's ApiActivityMonitor for |context|. Returns NULL if
163   // the embedder does not monitor extension API activity.
164   virtual ApiActivityMonitor* GetApiActivityMonitor(
165       content::BrowserContext* context) = 0;
166 
167   // Returns the factory that provides an ExtensionSystem to be returned from
168   // ExtensionSystem::Get.
169   virtual ExtensionSystemProvider* GetExtensionSystemFactory() = 0;
170 
171   // Registers extension functions not belonging to the core extensions APIs.
172   virtual void RegisterExtensionFunctions(
173       ExtensionFunctionRegistry* registry) const = 0;
174 
175   // Creates a RuntimeAPIDelegate responsible for handling extensions
176   // management-related events such as update and installation on behalf of the
177   // core runtime API implementation.
178   virtual scoped_ptr<RuntimeAPIDelegate> CreateRuntimeAPIDelegate(
179       content::BrowserContext* context) const = 0;
180 
181   // Returns the manager of resource bundles used in extensions. Returns NULL if
182   // the manager doesn't exist.
183   virtual ComponentExtensionResourceManager*
184   GetComponentExtensionResourceManager() = 0;
185 
186   // Returns the single instance of |this|.
187   static ExtensionsBrowserClient* Get();
188 
189   // Initialize the single instance.
190   static void Set(ExtensionsBrowserClient* client);
191 };
192 
193 }  // namespace extensions
194 
195 #endif  // EXTENSIONS_BROWSER_EXTENSIONS_BROWSER_CLIENT_H_
196