Skip to content

Commit

Permalink
Update macos CefManager
Browse files Browse the repository at this point in the history
  • Loading branch information
tishion committed Jan 4, 2022
1 parent 04a63b1 commit d918e4a
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 32 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,5 @@
.build.*
dep/cef
output
.DS_Store
CMakeLists.txt.user
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ else()
endif()

if (OS_MACOS)
set(CMAKE_OSX_DEPLOYMENT_TARGET 10.9)
set(CMAKE_OSX_DEPLOYMENT_TARGET 10.11)
endif()

set(CMAKE_SUPPRESS_REGENERATION TRUE)
Expand Down
13 changes: 8 additions & 5 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -130,16 +130,19 @@ if (OS_MACOS)
TARGET QCefView
PRE_BUILD

#sign the cef framework
COMMAND codesign --force --sign -
"$<TARGET_BUNDLE_DIR:QCefView>/../Chromium Embedded Framework.framework"

#copy the cef framework to resource directory
COMMAND ${CMAKE_COMMAND} -E copy_directory
"$<TARGET_BUNDLE_DIR:QCefView>/../Chromium Embedded Framework.framework"
"$<TARGET_FILE_DIR:QCefView>/Resources/Chromium Embedded Framework.framework"

#copy the cef framework to resource directory
COMMAND ${CMAKE_COMMAND} -E copy_directory
"$<TARGET_BUNDLE_DIR:QCefView>/../CefViewWing.app"
"$<TARGET_FILE_DIR:QCefView>/Resources/CefViewWing.app"
VERBATIM
#copy the CefViewWing*.app to resource directory
COMMAND cp -a
\"$<TARGET_BUNDLE_DIR:QCefView>/../CefViewWing\"*.app
"$<TARGET_FILE_DIR:QCefView>/Resources/"
)
endif() # OS_MACOS

Expand Down
84 changes: 58 additions & 26 deletions src/mac/details/CCefManager_mac.mm
Original file line number Diff line number Diff line change
@@ -1,33 +1,55 @@
#include "../../details/CCefManager.h"

#import <Cocoa/Cocoa.h>

#pragma region cef_headers
#include <include/cef_sandbox_mac.h>
#include <include/wrapper/cef_library_loader.h>
#pragma endregion cef_headers

#include "../../details/CCefSetting.h"

void
runMessageLoop()
{
CefRunMessageLoop();
#define CEF_BINARY_NAME "Chromium Embedded Framework"
#define CEF_FRAMEWORK_NAME "Chromium Embedded Framework.framework"
#define HELPER_BUNDLE_NAME "CefViewWing.app"
#define HELPER_BINARY_NAME "CefViewWing"

@interface PathFactory : NSObject
+ (NSString*) AppMainBundlePath;
+ (NSString*) CefFrameworkPath;
+ (NSString*) CefSubprocessPath;
@end

@implementation PathFactory
+ (NSString*) AppMainBundlePath {
return [[NSBundle mainBundle] bundlePath];
}

void
exitMessageLoop()
{
CefQuitMessageLoop();
+ (NSString*) CefFrameworkPath {
NSString* path = [[NSBundle bundleForClass:[PathFactory class]] resourcePath];
path = [path stringByAppendingPathComponent:@CEF_FRAMEWORK_NAME];
return path;
}

+ (NSString*) CefSubprocessPath {
NSString* path = [[NSBundle bundleForClass:[PathFactory class]] resourcePath];
path = [path stringByAppendingPathComponent:@HELPER_BUNDLE_NAME];
path = [path stringByAppendingPathComponent:@"Contents"];
path = [path stringByAppendingPathComponent:@"MacOS"];
path = [path stringByAppendingPathComponent:@HELPER_BINARY_NAME];
return path;
}
@end

const char*
cefSubprocessPath()
appMainBundlePath()
{
static std::string path;
if (!path.empty())
return path.c_str();

@autoreleasepool {
NSString* fxPath = [[NSBundle bundleForClass:CocoaCefSetting.class] resourcePath];
fxPath = [fxPath stringByAppendingPathComponent:@HELPER_BUNDLE_NAME];
fxPath = [fxPath stringByAppendingPathComponent:@"Contents"];
fxPath = [fxPath stringByAppendingPathComponent:@"MacOS"];
fxPath = [fxPath stringByAppendingPathComponent:@HELPER_BINARY_NAME];
path = fxPath.UTF8String;
path = [PathFactory AppMainBundlePath].UTF8String;
}
return path.c_str();
}
Expand All @@ -40,36 +62,34 @@
return path.c_str();

@autoreleasepool {
NSString* fxPath = [[NSBundle bundleForClass:CocoaCefSetting.class] resourcePath];
fxPath = [fxPath stringByAppendingPathComponent:@CEF_FRAMEWORK_NAME];
path = fxPath.UTF8String;
path = [PathFactory CefFrameworkPath].UTF8String;
}
return path.c_str();
}

const char*
cefLibraryPath()
cefSubprocessPath()
{
static std::string path;
if (!path.empty())
return path.c_str();

path = cefFrameworkPath();
path += "/";
path += CEF_BINARY_NAME;
@autoreleasepool {
path = [PathFactory CefSubprocessPath].UTF8String;
}
return path.c_str();
}

const char*
appMainBundlePath()
cefLibraryPath()
{
static std::string path;
if (!path.empty())
return path.c_str();

@autoreleasepool {
path = [[[NSBundle mainBundle] bundlePath] UTF8String];
}
path = cefFrameworkPath();
path += "/";
path += CEF_BINARY_NAME;
return path.c_str();
}

Expand All @@ -85,6 +105,18 @@
cef_unload_library();
}

void
runMessageLoop()
{
CefRunMessageLoop();
}

void
exitMessageLoop()
{
CefQuitMessageLoop();
}

bool
CCefManager::initializeCef(int argc, char* argv[], const QCefSetting& settings)
{
Expand Down

0 comments on commit d918e4a

Please sign in to comment.