Revert 264226 "Reduce dependency of TiclInvalidationService on P..."
[chromium-blink-merge.git] / extensions / browser / extensions_browser_client.h
blobd7c02d95a38f57fc2d8a17bc816430fcce7ff931
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;
22 namespace content {
23 class BrowserContext;
24 class WebContents;
27 namespace net {
28 class NetworkDelegate;
29 class URLRequest;
30 class URLRequestJob;
33 namespace extensions {
35 class ApiActivityMonitor;
36 class AppSorting;
37 class Extension;
38 class ExtensionHostDelegate;
39 class ExtensionPrefsObserver;
40 class ExtensionSystem;
41 class ExtensionSystemProvider;
42 class InfoMap;
44 // Interface to allow the extensions module to make browser-process-specific
45 // queries of the embedder. Should be Set() once in the browser process.
47 // NOTE: Methods that do not require knowledge of browser concepts should be
48 // added in ExtensionsClient (extensions/common/extensions_client.h) even if
49 // they are only used in the browser process.
50 class ExtensionsBrowserClient {
51 public:
52 virtual ~ExtensionsBrowserClient() {}
54 // Returns true if the embedder has started shutting down.
55 virtual bool IsShuttingDown() = 0;
57 // Returns true if extensions have been disabled (e.g. via a command-line flag
58 // or preference).
59 virtual bool AreExtensionsDisabled(const base::CommandLine& command_line,
60 content::BrowserContext* context) = 0;
62 // Returns true if the |context| is known to the embedder.
63 virtual bool IsValidContext(content::BrowserContext* context) = 0;
65 // Returns true if the BrowserContexts could be considered equivalent, for
66 // example, if one is an off-the-record context owned by the other.
67 virtual bool IsSameContext(content::BrowserContext* first,
68 content::BrowserContext* second) = 0;
70 // Returns true if |context| has an off-the-record context associated with it.
71 virtual bool HasOffTheRecordContext(content::BrowserContext* context) = 0;
73 // Returns the off-the-record context associated with |context|. If |context|
74 // is already off-the-record, returns |context|.
75 // WARNING: This may create a new off-the-record context. To avoid creating
76 // another context, check HasOffTheRecordContext() first.
77 virtual content::BrowserContext* GetOffTheRecordContext(
78 content::BrowserContext* context) = 0;
80 // Returns the original "recording" context. This method returns |context| if
81 // |context| is not incognito.
82 virtual content::BrowserContext* GetOriginalContext(
83 content::BrowserContext* context) = 0;
85 // Returns true if |context| corresponds to a guest session.
86 virtual bool IsGuestSession(content::BrowserContext* context) const = 0;
88 // Returns true if |extension_id| can run in an incognito window.
89 virtual bool IsExtensionIncognitoEnabled(
90 const std::string& extension_id,
91 content::BrowserContext* context) const = 0;
93 // Returns true if |extension| can see events and data from another
94 // sub-profile (incognito to original profile, or vice versa).
95 virtual bool CanExtensionCrossIncognito(
96 const extensions::Extension* extension,
97 content::BrowserContext* context) const = 0;
99 // Returns an URLRequestJob to load an extension resource from the embedder's
100 // resource bundle (.pak) files. Returns NULL if the request is not for a
101 // resource bundle resource or if the embedder does not support this feature.
102 // Used for component extensions. Called on the IO thread.
103 virtual net::URLRequestJob* MaybeCreateResourceBundleRequestJob(
104 net::URLRequest* request,
105 net::NetworkDelegate* network_delegate,
106 const base::FilePath& directory_path,
107 const std::string& content_security_policy,
108 bool send_cors_header) = 0;
110 // Returns true if the embedder wants to allow a chrome-extension:// resource
111 // request coming from renderer A to access a resource in an extension running
112 // in renderer B. For example, Chrome overrides this to provide support for
113 // webview and dev tools. Called on the IO thread.
114 virtual bool AllowCrossRendererResourceLoad(net::URLRequest* request,
115 bool is_incognito,
116 const Extension* extension,
117 InfoMap* extension_info_map) = 0;
119 // Returns the PrefService associated with |context|.
120 virtual PrefService* GetPrefServiceForContext(
121 content::BrowserContext* context) = 0;
123 // Populates a list of ExtensionPrefs observers to be attached to each
124 // BrowserContext's ExtensionPrefs upon construction. These observers
125 // are not owned by ExtensionPrefs.
126 virtual void GetEarlyExtensionPrefsObservers(
127 content::BrowserContext* context,
128 std::vector<ExtensionPrefsObserver*>* observers) const = 0;
130 // Returns true if loading background pages should be deferred.
131 virtual bool DeferLoadingBackgroundHosts(
132 content::BrowserContext* context) const = 0;
134 virtual bool IsBackgroundPageAllowed(
135 content::BrowserContext* context) const = 0;
137 // Creates a new ExtensionHostDelegate instance.
138 virtual scoped_ptr<ExtensionHostDelegate> CreateExtensionHostDelegate() = 0;
140 // Returns true if the client version has updated since the last run. Called
141 // once each time the extensions system is loaded per browser_context. The
142 // implementation may wish to use the BrowserContext to record the current
143 // version for later comparison.
144 virtual bool DidVersionUpdate(content::BrowserContext* context) = 0;
146 // Creates a new AppSorting instance.
147 virtual scoped_ptr<AppSorting> CreateAppSorting() = 0;
149 // Return true if the system is run in forced app mode.
150 virtual bool IsRunningInForcedAppMode() = 0;
152 // Returns the embedder's ApiActivityMonitor for |context|. Returns NULL if
153 // the embedder does not monitor extension API activity.
154 virtual ApiActivityMonitor* GetApiActivityMonitor(
155 content::BrowserContext* context) = 0;
157 // Returns the factory that provides an ExtensionSystem to be returned from
158 // ExtensionSystem::Get.
159 virtual ExtensionSystemProvider* GetExtensionSystemFactory() = 0;
161 // Registers extension functions not belonging to the core extensions APIs.
162 virtual void RegisterExtensionFunctions(
163 ExtensionFunctionRegistry* registry) const = 0;
165 // Returns the single instance of |this|.
166 static ExtensionsBrowserClient* Get();
168 // Initialize the single instance.
169 static void Set(ExtensionsBrowserClient* client);
172 } // namespace extensions
174 #endif // EXTENSIONS_BROWSER_EXTENSIONS_BROWSER_CLIENT_H_