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