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 class ListValue; 21 } 22 23 namespace content { 24 class BrowserContext; 25 class WebContents; 26 } 27 28 namespace net { 29 class NetLog; 30 class NetworkDelegate; 31 class URLRequest; 32 class URLRequestJob; 33 } 34 35 namespace extensions { 36 37 class ApiActivityMonitor; 38 class AppSorting; 39 class ComponentExtensionResourceManager; 40 class Extension; 41 class ExtensionHostDelegate; 42 class ExtensionPrefsObserver; 43 class ExtensionSystem; 44 class ExtensionSystemProvider; 45 class InfoMap; 46 class ProcessManagerDelegate; 47 class RuntimeAPIDelegate; 48 49 // Interface to allow the extensions module to make browser-process-specific 50 // queries of the embedder. Should be Set() once in the browser process. 51 // 52 // NOTE: Methods that do not require knowledge of browser concepts should be 53 // added in ExtensionsClient (extensions/common/extensions_client.h) even if 54 // they are only used in the browser process. 55 class ExtensionsBrowserClient { 56 public: ~ExtensionsBrowserClient()57 virtual ~ExtensionsBrowserClient() {} 58 59 // Returns true if the embedder has started shutting down. 60 virtual bool IsShuttingDown() = 0; 61 62 // Returns true if extensions have been disabled (e.g. via a command-line flag 63 // or preference). 64 virtual bool AreExtensionsDisabled(const base::CommandLine& command_line, 65 content::BrowserContext* context) = 0; 66 67 // Returns true if the |context| is known to the embedder. 68 virtual bool IsValidContext(content::BrowserContext* context) = 0; 69 70 // Returns true if the BrowserContexts could be considered equivalent, for 71 // example, if one is an off-the-record context owned by the other. 72 virtual bool IsSameContext(content::BrowserContext* first, 73 content::BrowserContext* second) = 0; 74 75 // Returns true if |context| has an off-the-record context associated with it. 76 virtual bool HasOffTheRecordContext(content::BrowserContext* context) = 0; 77 78 // Returns the off-the-record context associated with |context|. If |context| 79 // is already off-the-record, returns |context|. 80 // WARNING: This may create a new off-the-record context. To avoid creating 81 // another context, check HasOffTheRecordContext() first. 82 virtual content::BrowserContext* GetOffTheRecordContext( 83 content::BrowserContext* context) = 0; 84 85 // Returns the original "recording" context. This method returns |context| if 86 // |context| is not incognito. 87 virtual content::BrowserContext* GetOriginalContext( 88 content::BrowserContext* context) = 0; 89 90 // Returns true if |context| corresponds to a guest session. 91 virtual bool IsGuestSession(content::BrowserContext* context) const = 0; 92 93 // Returns true if |extension_id| can run in an incognito window. 94 virtual bool IsExtensionIncognitoEnabled( 95 const std::string& extension_id, 96 content::BrowserContext* context) const = 0; 97 98 // Returns true if |extension| can see events and data from another 99 // sub-profile (incognito to original profile, or vice versa). 100 virtual bool CanExtensionCrossIncognito( 101 const extensions::Extension* extension, 102 content::BrowserContext* context) const = 0; 103 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; 114 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, 120 bool is_incognito, 121 const Extension* extension, 122 InfoMap* extension_info_map) = 0; 123 124 // Returns the PrefService associated with |context|. 125 virtual PrefService* GetPrefServiceForContext( 126 content::BrowserContext* context) = 0; 127 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; 134 135 // Returns the ProcessManagerDelegate shared across all BrowserContexts. May 136 // return NULL in tests or for simple embedders. 137 virtual ProcessManagerDelegate* GetProcessManagerDelegate() const = 0; 138 139 // Creates a new ExtensionHostDelegate instance. 140 virtual scoped_ptr<ExtensionHostDelegate> CreateExtensionHostDelegate() = 0; 141 142 // Returns true if the client version has updated since the last run. Called 143 // once each time the extensions system is loaded per browser_context. The 144 // implementation may wish to use the BrowserContext to record the current 145 // version for later comparison. 146 virtual bool DidVersionUpdate(content::BrowserContext* context) = 0; 147 148 // Permits an external protocol handler to be launched. See 149 // ExternalProtocolHandler::PermitLaunchUrl() in Chrome. 150 virtual void PermitExternalProtocolHandler() = 0; 151 152 // Creates a new AppSorting instance. 153 virtual scoped_ptr<AppSorting> CreateAppSorting() = 0; 154 155 // Return true if the system is run in forced app mode. 156 virtual bool IsRunningInForcedAppMode() = 0; 157 158 // Returns the embedder's ApiActivityMonitor for |context|. Returns NULL if 159 // the embedder does not monitor extension API activity. 160 virtual ApiActivityMonitor* GetApiActivityMonitor( 161 content::BrowserContext* context) = 0; 162 163 // Returns the factory that provides an ExtensionSystem to be returned from 164 // ExtensionSystem::Get. 165 virtual ExtensionSystemProvider* GetExtensionSystemFactory() = 0; 166 167 // Registers extension functions not belonging to the core extensions APIs. 168 virtual void RegisterExtensionFunctions( 169 ExtensionFunctionRegistry* registry) const = 0; 170 171 // Creates a RuntimeAPIDelegate responsible for handling extensions 172 // management-related events such as update and installation on behalf of the 173 // core runtime API implementation. 174 virtual scoped_ptr<RuntimeAPIDelegate> CreateRuntimeAPIDelegate( 175 content::BrowserContext* context) const = 0; 176 177 // Returns the manager of resource bundles used in extensions. Returns NULL if 178 // the manager doesn't exist. 179 virtual ComponentExtensionResourceManager* 180 GetComponentExtensionResourceManager() = 0; 181 182 // Propagate a event to all the renderers in every browser context. The 183 // implementation must be safe to call from any thread. 184 virtual void BroadcastEventToRenderers(const std::string& event_name, 185 scoped_ptr<base::ListValue> args) = 0; 186 187 // Returns the embedder's net::NetLog. 188 virtual net::NetLog* GetNetLog() = 0; 189 190 // Returns the single instance of |this|. 191 static ExtensionsBrowserClient* Get(); 192 193 // Initialize the single instance. 194 static void Set(ExtensionsBrowserClient* client); 195 }; 196 197 } // namespace extensions 198 199 #endif // EXTENSIONS_BROWSER_EXTENSIONS_BROWSER_CLIENT_H_ 200