1 // Copyright (c) 2017 The Chromium Embedded Framework Authors. All rights 2 // reserved. Use of this source code is governed by a BSD-style license that 3 // can be found in the LICENSE file. 4 5 #ifndef CEF_TESTS_CEFCLIENT_BROWSER_EXTENSION_UTIL_H_ 6 #define CEF_TESTS_CEFCLIENT_BROWSER_EXTENSION_UTIL_H_ 7 #pragma once 8 9 #include <string> 10 11 #include "include/cef_extension.h" 12 #include "include/cef_extension_handler.h" 13 #include "include/wrapper/cef_resource_manager.h" 14 15 namespace client { 16 namespace extension_util { 17 18 // Returns true if |extension_path| can be handled internally via 19 // LoadBinaryResource. This checks a hard-coded list of allowed extension path 20 // components. 21 bool IsInternalExtension(const std::string& extension_path); 22 23 // Returns the path relative to the resource directory after removing the 24 // PK_DIR_RESOURCES prefix. This will be the relative path expected by 25 // LoadBinaryResource (uses '/' as path separator on all platforms). Only call 26 // this method for internal extensions, either when IsInternalExtension returns 27 // true or when the extension is handled internally through some means other 28 // than LoadBinaryResource. Use GetExtensionResourcePath instead if you are 29 // unsure whether the extension is internal or external. 30 std::string GetInternalExtensionResourcePath(const std::string& extension_path); 31 32 // Returns the resource path for |extension_path|. For external extensions this 33 // will be the full file path on disk. For internal extensions this will be the 34 // relative path expected by LoadBinaryResource (uses '/' as path separator on 35 // all platforms). Internal extensions must be on the hard-coded list enforced 36 // by IsInternalExtension. If |internal| is non-nullptr it will be set to true 37 // if the extension is handled internally. 38 std::string GetExtensionResourcePath(const std::string& extension_path, 39 bool* internal); 40 41 // Read the contents of |extension_path| into |contents|. For external 42 // extensions this will read the file from disk. For internal extensions this 43 // will call LoadBinaryResource. Internal extensions must be on the hard-coded 44 // list enforced by IsInternalExtension. Returns true on success. Must be 45 // called on the FILE thread. 46 bool GetExtensionResourceContents(const std::string& extension_path, 47 std::string& contents); 48 49 // Load |extension_path| in |request_context|. May be an internal or external 50 // extension. Internal extensions must be on the hard-coded list enforced by 51 // IsInternalExtension. 52 void LoadExtension(CefRefPtr<CefRequestContext> request_context, 53 const std::string& extension_path, 54 CefRefPtr<CefExtensionHandler> handler); 55 56 // Register an internal handler for extension resources. Internal extensions 57 // must be on the hard-coded list enforced by IsInternalExtension. 58 void AddInternalExtensionToResourceManager( 59 CefRefPtr<CefExtension> extension, 60 CefRefPtr<CefResourceManager> resource_manager); 61 62 // Returns the URL origin for |extension_id|. 63 std::string GetExtensionOrigin(const std::string& extension_id); 64 65 // Parse browser_action manifest values as defined at 66 // https://developer.chrome.com/extensions/browserAction 67 68 // Look for a browser_action.default_popup manifest value. 69 std::string GetExtensionURL(CefRefPtr<CefExtension> extension); 70 71 // Look for a browser_action.default_icon manifest value and return the resource 72 // path. If |internal| is non-nullptr it will be set to true if the extension is 73 // handled internally. 74 std::string GetExtensionIconPath(CefRefPtr<CefExtension> extension, 75 bool* internal); 76 77 } // namespace extension_util 78 } // namespace client 79 80 #endif // CEF_TESTS_CEFCLIENT_BROWSER_EXTENSION_UTIL_H_ 81