1 // Copyright 2014 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_API_EXTENSIONS_API_CLIENT_H_ 6 #define EXTENSIONS_BROWSER_API_EXTENSIONS_API_CLIENT_H_ 7 8 #include <map> 9 #include <memory> 10 #include <string> 11 #include <vector> 12 13 #include "base/memory/ref_counted.h" 14 #include "build/chromeos_buildflags.h" 15 #include "extensions/browser/api/clipboard/clipboard_api.h" 16 #include "extensions/browser/api/declarative_content/content_rules_registry.h" 17 #include "extensions/browser/api/storage/settings_namespace.h" 18 #include "extensions/common/api/clipboard.h" 19 #include "extensions/common/extension.h" 20 #include "extensions/common/extension_id.h" 21 22 class GURL; 23 24 namespace base { 25 template <class T> 26 class ObserverListThreadSafe; 27 } 28 29 namespace content { 30 class BrowserContext; 31 class WebContents; 32 } 33 34 namespace guest_view { 35 class GuestViewManagerDelegate; 36 } // namespace guest_view 37 38 namespace extensions { 39 40 class AutomationInternalApiDelegate; 41 class AppViewGuestDelegate; 42 class ContentRulesRegistry; 43 class DevicePermissionsPrompt; 44 class DisplayInfoProvider; 45 class ExtensionOptionsGuest; 46 class ExtensionOptionsGuestDelegate; 47 class FeedbackPrivateDelegate; 48 class FileSystemDelegate; 49 class ManagementAPIDelegate; 50 class MediaPerceptionAPIDelegate; 51 class MessagingDelegate; 52 class MetricsPrivateDelegate; 53 class MimeHandlerViewGuest; 54 class MimeHandlerViewGuestDelegate; 55 class NetworkingCastPrivateDelegate; 56 class NonNativeFileSystemDelegate; 57 class RulesCacheDelegate; 58 class SettingsObserver; 59 class SupervisedUserExtensionsDelegate; 60 class ValueStoreCache; 61 class ValueStoreFactory; 62 class VirtualKeyboardDelegate; 63 struct WebRequestInfo; 64 class WebViewGuest; 65 class WebViewGuestDelegate; 66 class WebViewPermissionHelper; 67 class WebViewPermissionHelperDelegate; 68 69 // Allows the embedder of the extensions module to customize its support for 70 // API features. The embedder must create a single instance in the browser 71 // process. Provides a default implementation that does nothing. 72 class ExtensionsAPIClient { 73 public: 74 // Construction sets the single instance. 75 ExtensionsAPIClient(); 76 77 // Destruction clears the single instance. 78 virtual ~ExtensionsAPIClient(); 79 80 // Returns the single instance of |this|. 81 static ExtensionsAPIClient* Get(); 82 83 // Storage API support. 84 85 // Add any additional value store caches (e.g. for chrome.storage.managed) 86 // to |caches|. By default adds nothing. 87 virtual void AddAdditionalValueStoreCaches( 88 content::BrowserContext* context, 89 const scoped_refptr<ValueStoreFactory>& factory, 90 const scoped_refptr<base::ObserverListThreadSafe<SettingsObserver>>& 91 observers, 92 std::map<settings_namespace::Namespace, ValueStoreCache*>* caches); 93 94 // Attaches any extra web contents helpers (like ExtensionWebContentsObserver) 95 // to |web_contents|. 96 virtual void AttachWebContentsHelpers(content::WebContents* web_contents) 97 const; 98 99 // Returns true if the header should be hidden to extensions. 100 virtual bool ShouldHideResponseHeader(const GURL& url, 101 const std::string& header_name) const; 102 103 // Returns true if the given |request| should be hidden from extensions. This 104 // should be invoked on the UI thread. 105 virtual bool ShouldHideBrowserNetworkRequest( 106 content::BrowserContext* context, 107 const WebRequestInfo& request) const; 108 109 // Notifies that an extension failed to act on a network request because the 110 // access to request was withheld. 111 virtual void NotifyWebRequestWithheld(int render_process_id, 112 int render_frame_id, 113 const ExtensionId& extension_id); 114 115 // Updates an extension's matched action count stored in an ExtensionAction 116 // and optionally clears the extension's explicitly set badge text for the 117 // tab specified by |tab_id|. 118 virtual void UpdateActionCount(content::BrowserContext* context, 119 const ExtensionId& extension_id, 120 int tab_id, 121 int action_count, 122 bool clear_badge_text); 123 124 // Clears an extension's matched action count stored in an ExtensionAction. 125 virtual void ClearActionCount(content::BrowserContext* context, 126 const Extension& extension); 127 128 // Creates the AppViewGuestDelegate. 129 virtual AppViewGuestDelegate* CreateAppViewGuestDelegate() const; 130 131 // Returns a delegate for ExtensionOptionsGuest. The caller owns the returned 132 // ExtensionOptionsGuestDelegate. 133 virtual ExtensionOptionsGuestDelegate* CreateExtensionOptionsGuestDelegate( 134 ExtensionOptionsGuest* guest) const; 135 136 // Returns a delegate for GuestViewManagerDelegate. 137 virtual std::unique_ptr<guest_view::GuestViewManagerDelegate> 138 CreateGuestViewManagerDelegate(content::BrowserContext* context) const; 139 140 // Creates a delegate for MimeHandlerViewGuest. 141 virtual std::unique_ptr<MimeHandlerViewGuestDelegate> 142 CreateMimeHandlerViewGuestDelegate(MimeHandlerViewGuest* guest) const; 143 144 // Returns a delegate for some of WebViewGuest's behavior. The caller owns the 145 // returned WebViewGuestDelegate. 146 virtual WebViewGuestDelegate* CreateWebViewGuestDelegate( 147 WebViewGuest* web_view_guest) const; 148 149 // Returns a delegate for some of WebViewPermissionHelper's behavior. The 150 // caller owns the returned WebViewPermissionHelperDelegate. 151 virtual WebViewPermissionHelperDelegate* 152 CreateWebViewPermissionHelperDelegate( 153 WebViewPermissionHelper* web_view_permission_helper) const; 154 155 // TODO(wjmaclean): Remove this when (if) ContentRulesRegistry code moves 156 // to extensions/browser/api. 157 virtual scoped_refptr<ContentRulesRegistry> CreateContentRulesRegistry( 158 content::BrowserContext* browser_context, 159 RulesCacheDelegate* cache_delegate) const; 160 161 // Creates a DevicePermissionsPrompt appropriate for the embedder. 162 virtual std::unique_ptr<DevicePermissionsPrompt> 163 CreateDevicePermissionsPrompt(content::WebContents* web_contents) const; 164 165 // Returns a delegate for some of VirtualKeyboardAPI's behavior. 166 virtual std::unique_ptr<VirtualKeyboardDelegate> 167 CreateVirtualKeyboardDelegate(content::BrowserContext* browser_context) const; 168 169 // Creates a delegate for handling the management extension api. 170 virtual ManagementAPIDelegate* CreateManagementAPIDelegate() const; 171 172 // Creates a delegate for calling into the SupervisedUserService from the 173 // Management API. 174 virtual std::unique_ptr<SupervisedUserExtensionsDelegate> 175 CreateSupervisedUserExtensionsDelegate() const; 176 177 // Creates and returns the DisplayInfoProvider used by the 178 // chrome.system.display extension API. 179 virtual std::unique_ptr<DisplayInfoProvider> CreateDisplayInfoProvider() 180 const; 181 182 // If supported by the embedder, returns a delegate for embedder-dependent 183 // MetricsPrivateAPI behavior. 184 virtual MetricsPrivateDelegate* GetMetricsPrivateDelegate(); 185 186 // Creates a delegate for networking.castPrivate's API behavior. 187 virtual NetworkingCastPrivateDelegate* GetNetworkingCastPrivateDelegate(); 188 189 // Returns a delegate for embedder-specific chrome.fileSystem behavior. 190 virtual FileSystemDelegate* GetFileSystemDelegate(); 191 192 // Returns a delegate for embedder-specific extension messaging. 193 virtual MessagingDelegate* GetMessagingDelegate(); 194 195 // Returns a delegate for the chrome.feedbackPrivate API. 196 virtual FeedbackPrivateDelegate* GetFeedbackPrivateDelegate(); 197 198 #if BUILDFLAG(IS_CHROMEOS_ASH) 199 // If supported by the embedder, returns a delegate for querying non-native 200 // file systems. 201 virtual NonNativeFileSystemDelegate* GetNonNativeFileSystemDelegate(); 202 203 // Returns a delegate for embedder-specific chrome.mediaPerceptionPrivate API 204 // behavior. 205 virtual MediaPerceptionAPIDelegate* GetMediaPerceptionAPIDelegate(); 206 207 // Saves image data on clipboard. 208 virtual void SaveImageDataToClipboard( 209 const std::vector<char>& image_data, 210 api::clipboard::ImageType type, 211 AdditionalDataItemList additional_items, 212 base::OnceClosure success_callback, 213 base::OnceCallback<void(const std::string&)> error_callback); 214 #endif 215 216 virtual AutomationInternalApiDelegate* GetAutomationInternalApiDelegate(); 217 218 // Gets keyed service factories that are used in the other methods on this 219 // class. 220 virtual std::vector<KeyedServiceBaseFactory*> GetFactoryDependencies(); 221 222 // NOTE: If this interface gains too many methods (perhaps more than 20) it 223 // should be split into one interface per API. 224 }; 225 226 } // namespace extensions 227 228 #endif // EXTENSIONS_BROWSER_API_EXTENSIONS_API_CLIENT_H_ 229