1 // Copyright (c) 2018 Marshall A. Greenblatt. All rights reserved. 2 // 3 // Redistribution and use in source and binary forms, with or without 4 // modification, are permitted provided that the following conditions are 5 // met: 6 // 7 // * Redistributions of source code must retain the above copyright 8 // notice, this list of conditions and the following disclaimer. 9 // * Redistributions in binary form must reproduce the above 10 // copyright notice, this list of conditions and the following disclaimer 11 // in the documentation and/or other materials provided with the 12 // distribution. 13 // * Neither the name of Google Inc. nor the name Chromium Embedded 14 // Framework nor the names of its contributors may be used to endorse 15 // or promote products derived from this software without specific prior 16 // written permission. 17 // 18 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 30 #ifndef CEF_INCLUDE_WRAPPER_CEF_LIBRARY_LOADER_H_ 31 #define CEF_INCLUDE_WRAPPER_CEF_LIBRARY_LOADER_H_ 32 #pragma once 33 34 #include "include/base/cef_build.h" 35 36 #ifdef __cplusplus 37 #include <string> 38 39 #include "include/base/cef_macros.h" 40 41 extern "C" { 42 #endif // __cplusplus 43 44 /// 45 // Load the CEF library at the specified |path|. Returns true (1) on 46 // success and false (0) on failure. 47 /// 48 int cef_load_library(const char* path); 49 50 /// 51 // Unload the CEF library that was previously loaded. Returns true (1) 52 // on success and false (0) on failure. 53 /// 54 int cef_unload_library(); 55 56 #ifdef __cplusplus 57 } 58 59 #if defined(OS_MAC) 60 61 /// 62 // Scoped helper for loading and unloading the CEF framework library at 63 // runtime from the expected location in the app bundle. Loading at runtime 64 // instead of linking directly is a requirement of the macOS sandbox 65 // implementation. 66 // 67 // Example usage in the main process: 68 // 69 // #include "include/wrapper/cef_library_loader.h" 70 // 71 // int main(int argc, char* argv[]) { 72 // // Dynamically load the CEF framework library. 73 // CefScopedLibraryLoader library_loader; 74 // if (!library_loader.LoadInMain()) 75 // return 1; 76 // 77 // // Continue with CEF initialization... 78 // } 79 // 80 // Example usage in the helper process: 81 // 82 // #include "include/cef_sandbox_mac.h" 83 // #include "include/wrapper/cef_library_loader.h" 84 // 85 // int main(int argc, char* argv[]) { 86 // // Initialize the macOS sandbox for this helper process. 87 // CefScopedSandboxContext sandbox_context; 88 // if (!sandbox_context.Initialize(argc, argv)) 89 // return 1; 90 // 91 // // Dynamically load the CEF framework library. 92 // CefScopedLibraryLoader library_loader; 93 // if (!library_loader.LoadInHelper()) 94 // return 1; 95 // 96 // // Continue with CEF initialization... 97 // } 98 /// 99 class CefScopedLibraryLoader { 100 public: 101 CefScopedLibraryLoader(); 102 ~CefScopedLibraryLoader(); 103 104 /// 105 // Load the CEF framework in the main process from the expected app 106 // bundle location relative to the executable. Returns true if the 107 // load succeeds. 108 /// LoadInMain()109 bool LoadInMain() { return Load(false); } 110 111 /// 112 // Load the CEF framework in the helper process from the expected app 113 // bundle location relative to the executable. Returns true if the 114 // load succeeds. 115 /// LoadInHelper()116 bool LoadInHelper() { return Load(true); } 117 118 private: 119 bool Load(bool helper); 120 121 bool loaded_; 122 DISALLOW_COPY_AND_ASSIGN(CefScopedLibraryLoader); 123 }; 124 125 #endif // defined(OS_MAC) 126 #endif // __cplusplus 127 128 #endif // CEF_INCLUDE_WRAPPER_CEF_LIBRARY_LOADER_H_ 129