Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow pass null value of QCefConfig and QCefSetting #103

Merged
merged 1 commit into from
May 26, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
99 changes: 63 additions & 36 deletions example/QCefViewTest/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,18 @@ elseif (OS_MACOS)
else()
endif()

# Create an empty source file as the rebuild trigger
# QCefView will update this file every time it gets built
file(WRITE ${CMAKE_BINARY_DIR}/auto_rebuild.cpp "/* Auto Rebuild Trigger */")

include_directories(
${CMAKE_SOURCE_DIR}/include
)

file(GLOB_RECURSE _SRC_FILES
"*.h"
"*.cpp"
${CMAKE_BINARY_DIR}/auto_rebuild.cpp
)

file(GLOB_RECURSE _UI_FILES
Expand Down Expand Up @@ -77,29 +82,40 @@ if (OS_WINDOWS)
VS_DEBUGGER_WORKING_DIRECTORY "$<TARGET_FILE_DIR:${PROJECT_NAME}>"
)

add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD
# Embed the manifest file into the target
COMMAND mt.exe
-manifest \"${CMAKE_CURRENT_SOURCE_DIR}\\${PROJECT_NAME}.manifest\"
-inputresource:\"$<TARGET_FILE:${PROJECT_NAME}>\"
-outputresource:\"$<TARGET_FILE:${PROJECT_NAME}>\"
add_custom_command(TARGET ${PROJECT_NAME}
PRE_BUILD

# Copy QCefView binary to output folder
COMMAND ${CMAKE_COMMAND} -E copy_directory
$<TARGET_FILE_DIR:QCefView>
$<TARGET_FILE_DIR:${PROJECT_NAME}>
)

add_custom_command(TARGET ${PROJECT_NAME}
POST_BUILD

# Copy QCefView binary to output folder
COMMAND ${CMAKE_COMMAND} -E copy_directory
$<TARGET_FILE_DIR:QCefView>
$<TARGET_FILE_DIR:${PROJECT_NAME}>
# Embed the manifest file into the target
COMMAND mt.exe
-manifest \"${CMAKE_CURRENT_SOURCE_DIR}\\${PROJECT_NAME}.manifest\"
-inputresource:\"$<TARGET_FILE:${PROJECT_NAME}>\"
-outputresource:\"$<TARGET_FILE:${PROJECT_NAME}>\"

# Copy QCefView binary to output folder
COMMAND ${CMAKE_COMMAND} -E copy_directory
$<TARGET_FILE_DIR:QCefView>
$<TARGET_FILE_DIR:${PROJECT_NAME}>

# Copy the webres directory to output folder
COMMAND ${CMAKE_COMMAND} -E copy_directory
${CMAKE_CURRENT_BINARY_DIR}/webres
$<TARGET_FILE_DIR:${PROJECT_NAME}>/webres

# Copy the webres directory to output folder
COMMAND ${CMAKE_COMMAND} -E copy_directory
${CMAKE_CURRENT_BINARY_DIR}/webres
$<TARGET_FILE_DIR:${PROJECT_NAME}>/webres

# Deploy the Qt Application
COMMAND ${DEPLOYQT_EXECUTABLE}
--no-svg
--no-translations
--no-compiler-runtime
$<TARGET_FILE:${PROJECT_NAME}>
# Deploy the Qt Application
COMMAND ${DEPLOYQT_EXECUTABLE}
--no-svg
--no-translations
--no-compiler-runtime
$<TARGET_FILE:${PROJECT_NAME}>
)
endif() # OS_WINDOWS

Expand Down Expand Up @@ -133,23 +149,34 @@ if (OS_LINUX)
QCefView
)

add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD
# Copy QCefView binary to output folder
COMMAND ${CMAKE_COMMAND} -E copy_directory
$<TARGET_FILE_DIR:QCefView>
$<TARGET_FILE_DIR:${PROJECT_NAME}>
add_custom_command(TARGET ${PROJECT_NAME}
PRE_BUILD

# Copy QCefView binary to output folder
COMMAND ${CMAKE_COMMAND} -E copy_directory
$<TARGET_FILE_DIR:QCefView>
$<TARGET_FILE_DIR:${PROJECT_NAME}>
)

# Copy the webres directory to output folder
COMMAND ${CMAKE_COMMAND} -E copy_directory
${CMAKE_CURRENT_BINARY_DIR}/webres
$<TARGET_FILE_DIR:${PROJECT_NAME}>/webres
add_custom_command(TARGET ${PROJECT_NAME}
POST_BUILD

# Deploy the Qt Application
# COMMAND ${DEPLOYQT_EXECUTABLE}
# --no-svg
# --no-translations
# --no-compiler-runtime
# $<TARGET_FILE:${PROJECT_NAME}>
# Copy QCefView binary to output folder
COMMAND ${CMAKE_COMMAND} -E copy_directory
$<TARGET_FILE_DIR:QCefView>
$<TARGET_FILE_DIR:${PROJECT_NAME}>

# Copy the webres directory to output folder
COMMAND ${CMAKE_COMMAND} -E copy_directory
${CMAKE_CURRENT_BINARY_DIR}/webres
$<TARGET_FILE_DIR:${PROJECT_NAME}>/webres

# Deploy the Qt Application
# COMMAND ${DEPLOYQT_EXECUTABLE}
# --no-svg
# --no-translations
# --no-compiler-runtime
# $<TARGET_FILE:${PROJECT_NAME}>
)
endif() # OS_LINUX

Expand Down
48 changes: 28 additions & 20 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,17 @@ if (OS_WINDOWS)
)

add_custom_command(TARGET QCefView
POST_BUILD
PRE_BUILD

# copy binary files of CefViewCore
COMMAND ${CMAKE_COMMAND}
-E copy_directory
"$<TARGET_FILE_DIR:CefViewWing>"
"$<TARGET_FILE_DIR:QCefView>"

# copy binary files of CefViewCore
COMMAND ${CMAKE_COMMAND} -E copy_directory
"$<TARGET_FILE_DIR:CefViewWing>"
"$<TARGET_FILE_DIR:QCefView>"
# gnerate a file contain timestamp
COMMAND ${CMAKE_COMMAND}
-E echo "/* Auto Build Trigger */" > "${CMAKE_BINARY_DIR}/auto_rebuild.cpp"
)
endif() # OS_WINDOWS

Expand Down Expand Up @@ -124,12 +129,13 @@ if (OS_LINUX)
)

add_custom_command(TARGET QCefView
POST_BUILD
PRE_BUILD

# copy binary files of CefViewCore
COMMAND ${CMAKE_COMMAND} -E copy_directory
"$<TARGET_FILE_DIR:CefViewWing>"
"$<TARGET_FILE_DIR:QCefView>"
# copy binary files of CefViewCore
COMMAND ${CMAKE_COMMAND}
-E copy_directory
"$<TARGET_FILE_DIR:CefViewWing>"
"$<TARGET_FILE_DIR:QCefView>"
)
endif() # OS_LINUX

Expand Down Expand Up @@ -188,18 +194,20 @@ if (OS_MACOS)
XCODE_ATTRIBUTE_GCC_C_LANGUAGE_STANDARD "c99" # -std=c99
)

add_custom_command(
TARGET QCefView
add_custom_command(TARGET QCefView
PRE_BUILD

#copy the CefViewWing*.app to resource directory
COMMAND cp -a
"$<TARGET_BUNDLE_DIR:CefViewWing>/../"
"$<TARGET_FILE_DIR:QCefView>/Resources/"

#sign the cef framework
COMMAND codesign --force --sign -
"$<TARGET_BUNDLE_DIR:QCefView>/Resources/Chromium Embedded Framework.framework"
#copy the CefViewWing*.app to resource directory
COMMAND cp
-a
"$<TARGET_BUNDLE_DIR:CefViewWing>/../"
"$<TARGET_FILE_DIR:QCefView>/Resources/"

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

Expand Down
17 changes: 16 additions & 1 deletion src/details/QCefConfigPrivate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,23 @@ QCefConfigPrivate::QCefConfigPrivate()
void
QCefConfigPrivate::CopyToCefSettings(const QCefConfig* config, CefSettings* settings)
{
if (!config || !settings)
// validate input target setting parameter
if (!settings) {
// nothing to do but return
return;
}

// validate the input source config parameter
if (!config) {
// just copy the mandatory fields
QCefConfigPrivate cfg;
#if !defined(Q_OS_MACOS)
CefString(&settings->browser_subprocess_path) = cfg.browserSubProcessPath_;
CefString(&settings->resources_dir_path) = cfg.resourceDirectoryPath_;
CefString(&settings->locales_dir_path) = cfg.localesDirectoryPath_;
#endif
return;
}

#if !defined(Q_OS_MACOS)
if (!config->d_ptr->browserSubProcessPath_.empty())
Expand Down
4 changes: 1 addition & 3 deletions src/details/QCefViewPrivate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -133,9 +133,7 @@ QCefViewPrivate::createCefBrowser(QCefView* view, const QString url, const QCefS

// create the browser settings
CefBrowserSettings browserSettings;
if (setting) {
QCefSettingPrivate::CopyToCefBrowserSettings(setting, &browserSettings);
}
QCefSettingPrivate::CopyToCefBrowserSettings(setting, &browserSettings);

// create browser object
bool success = CefBrowserHost::CreateBrowser(window_info, // window info
Expand Down
3 changes: 1 addition & 2 deletions src/linux/details/QCefContextPrivate_linux.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ QCefContextPrivate::initializeCef(const QCefConfig* config)
{
// Build CefSettings
CefSettings cef_settings;
if (config)
QCefConfigPrivate::CopyToCefSettings(config, &cef_settings);
QCefConfigPrivate::CopyToCefSettings(config, &cef_settings);

// fixed values
cef_settings.pack_loading_disabled = false;
Expand Down
3 changes: 1 addition & 2 deletions src/mac/details/QCefContextPrivate_mac.mm
Original file line number Diff line number Diff line change
Expand Up @@ -171,8 +171,7 @@ - (void)_swizzled_run {

// Build CefSettings
CefSettings cef_settings;
if (config)
QCefConfigPrivate::CopyToCefSettings(config, &cef_settings);
QCefConfigPrivate::CopyToCefSettings(config, &cef_settings);

// fixed values
CefString(&cef_settings.framework_dir_path) = cefFrameworkPath();
Expand Down
5 changes: 2 additions & 3 deletions src/win/details/QCefContextPrivate_win.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ QCefContextPrivate::initializeCef(const QCefConfig* config)

// Build CefSettings
CefSettings cef_settings;
if (config)
QCefConfigPrivate::CopyToCefSettings(config, &cef_settings);
QCefConfigPrivate::CopyToCefSettings(config, &cef_settings);

// fixed values
cef_settings.pack_loading_disabled = false;
Expand All @@ -26,7 +25,7 @@ QCefContextPrivate::initializeCef(const QCefConfig* config)
cef_settings.no_sandbox = true;
#endif

// Initialize CEF.
// Initialize CEF
auto cmdArgs = QCefConfigPrivate::GetCommandLineArgs(config);
auto appDelegate = std::make_shared<CCefAppDelegate>(this, cmdArgs);
auto bridgeObjectName = config ? config->bridgeObjectName().toStdString() : std::string();
Expand Down