Skip to content

Commit

Permalink
More flexible deployment outside of a common App Bundle on MacOS
Browse files Browse the repository at this point in the history
Generally, CEF/JCEF applications need to be deployed with the helper app and the framework inside an application bundle on MacOS. This strict directory structure is necessary because the dynamic CEF loading mechanism relies on it, and because the Mach IPC registration mechanism for IPC channels between the helper process and the master process uses the outer bundle ID for identification.
This patch implements fixes/workarounds for both of these problems, effectively relaxing the requirement and allowing effective wrapping of JCEF and CEF on MacOS within a JAR that extracts the files at runtime to a temporary location.
  • Loading branch information
S1artie committed Dec 7, 2018
1 parent 18d0cfb commit 8eadc14
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 14 deletions.
7 changes: 4 additions & 3 deletions include/wrapper/cef_library_loader.h
Expand Up @@ -106,17 +106,18 @@ class CefScopedLibraryLoader {
// bundle location relative to the executable. Returns true if the
// load succeeds.
///
bool LoadInMain() { return Load(false); }
bool LoadInMain() { return Load(false, NULL); }
bool LoadInMain(char * frameworkPath) { return Load(false, frameworkPath); }

///
// Load the CEF framework in the helper process from the expected app
// bundle location relative to the executable. Returns true if the
// load succeeds.
///
bool LoadInHelper() { return Load(true); }
bool LoadInHelper() { return Load(true, NULL); }

private:
bool Load(bool helper);
bool Load(bool helper, char * frameworkPath);

bool loaded_;
DISALLOW_COPY_AND_ASSIGN(CefScopedLibraryLoader);
Expand Down
30 changes: 19 additions & 11 deletions libcef_dll/wrapper/cef_library_loader_mac.mm
Expand Up @@ -48,21 +48,29 @@

CefScopedLibraryLoader::CefScopedLibraryLoader() : loaded_(false) {}

bool CefScopedLibraryLoader::Load(bool helper) {
bool CefScopedLibraryLoader::Load(bool helper, char * frameworkPath) {
if (loaded_) {
return false;
}

const std::string& framework_path = GetFrameworkPath(helper);
if (framework_path.empty()) {
fprintf(stderr, "App does not have the expected bundle structure.\n");
return false;
}

// Load the CEF framework library.
if (!cef_load_library(framework_path.c_str())) {
fprintf(stderr, "Failed to load the CEF framework.\n");
return false;
if (frameworkPath == NULL) {
const std::string& framework_path = GetFrameworkPath(helper);
if (framework_path.empty()) {
fprintf(stderr, "App does not have the expected bundle structure.\n");
return false;
}

// Load the CEF framework library.
if (!cef_load_library(framework_path.c_str())) {
fprintf(stderr, "Failed to load the CEF framework.\n");
return false;
}
} else {
// Load the CEF framework library.
if (!cef_load_library(frameworkPath)) {
fprintf(stderr, "Failed to load the CEF framework.\n");
return false;
}
}

loaded_ = true;
Expand Down
7 changes: 7 additions & 0 deletions patch/patch.cfg
Expand Up @@ -398,6 +398,13 @@ patches = [
# https://bitbucket.org/chromiumembedded/cef/issues/2507
'name': 'browser_child_frame_2507',
},
{
# macOS: Remove bundle name for Mach IPC registration.
# This is necessary to remove the requirement for a top-level App Bundle
# to exist, which makes it much easier to embed CEF & JCEF inside Java
# JARs alongside a self-extract mechanism.
'name': 'mach_port_broker_bundlename',
},
{
# macOS: Fix crash when showing a select popup with CefDoMessageLoopWork.
# https://bitbucket.org/chromiumembedded/cef/issues/2495
Expand Down
13 changes: 13 additions & 0 deletions patch/patches/mach_port_broker_bundlename.patch
@@ -0,0 +1,13 @@
diff --git base/mac/mach_port_broker.mm base/mac/mach_port_broker.mm
index 6d9fec5ab6ec..18e43e17b8c2 100644
--- base/mac/mach_port_broker.mm
+++ base/mac/mach_port_broker.mm
@@ -74,7 +74,7 @@
// In child processes, use the parent's pid.
const pid_t pid = is_child ? getppid() : getpid();
return base::StringPrintf(
- "%s.%s.%d", base::mac::BaseBundleID(), name.c_str(), pid);
+ "%s.%s.%d", "cef", name.c_str(), pid);
}

mach_port_t MachPortBroker::TaskForPid(base::ProcessHandle pid) const {

0 comments on commit 8eadc14

Please sign in to comment.