Skip to content

Commit

Permalink
feat: adapt to core: ca2625196e55e31fb576616340b07a426f3bdba5
Browse files Browse the repository at this point in the history
1. adapt to core: ca2625196e55e31fb576616340b07a426f3bdba5
2. move CefVeiwCore to thirdparty
  • Loading branch information
tishion committed Dec 14, 2024
1 parent 3a1bd3c commit 98c4ae3
Show file tree
Hide file tree
Showing 17 changed files with 105 additions and 174 deletions.
63 changes: 4 additions & 59 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
cmake_minimum_required(VERSION 3.18)
project(QCefView)

set(CMAKE_FOLDER "QCefView")

# arguments:
# CEF_SDK_VERSION:
# - specify the CEF version to be used,
Expand Down Expand Up @@ -148,65 +150,8 @@ include(QtConfig)
set(Qt_VERSION ${Qt${QT_VERSION_MAJOR}Core_VERSION})

# ##############################################################

# Config the CEF
# ##############################################################
# Fetch CefViewCore
include(CefViewCoreConfig)

# read CEF version from cef_version.h
# set need configure QCefView_global to false
set(NEED_CONFIGURE_QCefView_global FALSE)

message(STATUS "${CefViewCore_CEF_INCLUDE_DIR}/cef_version.h")
file(READ "${CefViewCore_CEF_INCLUDE_DIR}/cef_version.h" cef_version_content)
string(REGEX MATCH "#define CEF_VERSION_MAJOR ([0-9]+)" _ ${cef_version_content})

# check CEF_VERSION_MAJOR
if(NOT "${CMAKE_MATCH_1}" STREQUAL "${CEF_VERSION_MAJOR}")
set(CEF_VERSION_MAJOR ${CMAKE_MATCH_1} CACHE STRING "CEF Major Version" FORCE)
set(NEED_CONFIGURE_QCefView_global TRUE)
message(STATUS "CEF_VERSION_MAJOR: ${CEF_VERSION_MAJOR} - Updated!")
else()
message(STATUS "CEF_VERSION_MAJOR: ${CEF_VERSION_MAJOR} - No Change!")
endif()

# check CEF_VERSION_MAJOR
string(REGEX MATCH "#define CEF_VERSION_MINOR ([0-9]+)" _ ${cef_version_content})

if(NOT "${CMAKE_MATCH_1}" STREQUAL "${CEF_VERSION_MINOR}")
set(CEF_VERSION_MINOR ${CMAKE_MATCH_1} CACHE STRING "CEF Minor Version" FORCE)
set(NEED_CONFIGURE_QCefView_global TRUE)
message(STATUS "CEF_VERSION_MINOR: ${CEF_VERSION_MINOR} - Updated!")
else()
message(STATUS "CEF_VERSION_MINOR: ${CEF_VERSION_MINOR} - No Change!")
endif()

string(REGEX MATCH "#define CEF_VERSION_PATCH ([0-9]+)" _ ${cef_version_content})

if(NOT "${CMAKE_MATCH_1}" STREQUAL "${CEF_VERSION_PATCH}")
set(CEF_VERSION_PATCH ${CMAKE_MATCH_1} CACHE STRING "CEF Patch Version" FORCE)
set(NEED_CONFIGURE_QCefView_global TRUE)
message(STATUS "CEF_VERSION_PATCH: ${CEF_VERSION_PATCH} - Updated!")
else()
message(STATUS "CEF_VERSION_PATCH: ${CEF_VERSION_PATCH} - No Change!")
endif()

if(NOT EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/include/QCefView_global.h")
set(NEED_CONFIGURE_QCefView_global TRUE)
endif()

if(${NEED_CONFIGURE_QCefView_global})
message(STATUS "Need to configure QCefView_global.h file")
configure_file(
"${CMAKE_CURRENT_SOURCE_DIR}/include/QCefView_global.h.in"
"${CMAKE_CURRENT_SOURCE_DIR}/include/QCefView_global.h"
@ONLY
NEWLINE_STYLE UNIX
)
else()
message(STATUS "No need to configure QCefView_global.h file")
endif()
# thirdparty CefViewCore
add_subdirectory(thirdparty)

if(OS_MACOS)
# detect minimum deployment target by Qt
Expand Down
2 changes: 1 addition & 1 deletion cmake/QtConfig.cmake
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# ################################################################################
#
# The Qt SDK path
# You can set the evnironment varibale via
# You can set the environment variable via
# 1. command line
# Windows: SET QTDIR=PATH/TO/QT
# Non-Windows: export QTDIR=PATH/TO/QT
Expand Down
3 changes: 2 additions & 1 deletion example/QCefViewTest/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
cmake_minimum_required(VERSION 3.18)
project(QCefViewTest)

set(CMAKE_FOLDER "Example")

set(CMAKE_INCLUDE_CURRENT_DIR ON)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTOUIC ON)
Expand Down Expand Up @@ -256,7 +258,6 @@ endif()

set_target_properties(${PROJECT_NAME}
PROPERTIES
FOLDER example
RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/output/$<CONFIG>/bin
ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/output/$<CONFIG>/lib
LIBRARY_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/output/$<CONFIG>/lib
Expand Down
2 changes: 1 addition & 1 deletion example/QCefViewTest/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ main(int argc, char* argv[])

// WindowlessRenderingEnabled is set to true by default,
// set to false to disable the OSR mode
config.setWindowlessRenderingEnabled(true);
config.setWindowlessRenderingEnabled(false);

// add command line args, you can any cef supported switches or parameters
config.addCommandLineSwitch("use-mock-keychain");
Expand Down
4 changes: 2 additions & 2 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ target_include_directories(QCefView PRIVATE
)

add_dependencies(QCefView
CefViewCore
CefViewCore::CefViewCore
)

target_link_libraries(QCefView
Expand All @@ -215,7 +215,7 @@ target_link_libraries(QCefView
Qt${QT_VERSION_MAJOR}::Core
Qt${QT_VERSION_MAJOR}::Widgets
PRIVATE
CefViewCore
CefViewCore::CefViewCore
)

# install QCefView files
Expand Down
2 changes: 1 addition & 1 deletion src/details/CCefAppDelegate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ CCefAppDelegate::onBeforeCommandLineProcessing(const CefString& process_type, Ce
}

void
CCefAppDelegate::OnBeforeChildProcessLaunch(CefRefPtr<CefCommandLine> command_line)
CCefAppDelegate::onBeforeChildProcessLaunch(CefRefPtr<CefCommandLine> command_line)
{
for (auto& kv : commandLineArgs_) {
if (!kv.first.empty()) {
Expand Down
2 changes: 1 addition & 1 deletion src/details/CCefAppDelegate.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class CCefAppDelegate : public CefViewBrowserAppDelegateInterface
virtual void onBeforeCommandLineProcessing(const CefString& process_type,
CefRefPtr<CefCommandLine> command_line) override;

virtual void OnBeforeChildProcessLaunch(CefRefPtr<CefCommandLine> command_line) override;
virtual void onBeforeChildProcessLaunch(CefRefPtr<CefCommandLine> command_line) override;

void onScheduleMessageLoopWork(int64_t delay_ms) override;

Expand Down
8 changes: 4 additions & 4 deletions src/details/CCefClientDelegate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ CCefClientDelegate::~CCefClientDelegate()
}

void
CCefClientDelegate::processUrlRequest(CefRefPtr<CefBrowser>& browser, const CefFrameId& frameId, const std::string& url)
CCefClientDelegate::processUrlRequest(CefRefPtr<CefBrowser>& browser, const CefFrameId& frameId, const CefString& url)
{
if (!IsValidBrowser(browser))
return;
Expand All @@ -33,7 +33,7 @@ CCefClientDelegate::processUrlRequest(CefRefPtr<CefBrowser>& browser, const CefF
void
CCefClientDelegate::processQueryRequest(CefRefPtr<CefBrowser>& browser,
const CefFrameId& frameId,
const std::string& request,
const CefString& request,
const int64_t query_id)
{
if (!IsValidBrowser(browser))
Expand Down Expand Up @@ -64,7 +64,7 @@ CCefClientDelegate::focusedEditableNodeChanged(CefRefPtr<CefBrowser>& browser,
void
CCefClientDelegate::invokeMethodNotify(CefRefPtr<CefBrowser>& browser,
const CefFrameId& frameId,
const std::string& method,
const CefString& method,
const CefRefPtr<CefListValue>& arguments)
{
if (!IsValidBrowser(browser))
Expand All @@ -86,7 +86,7 @@ CCefClientDelegate::invokeMethodNotify(CefRefPtr<CefBrowser>& browser,
void
CCefClientDelegate::reportJSResult(CefRefPtr<CefBrowser>& browser,
const CefFrameId& frameId,
const std::string& context,
const CefString& context,
const CefRefPtr<CefValue>& result)
{
if (!IsValidBrowser(browser))
Expand Down
34 changes: 16 additions & 18 deletions src/details/CCefClientDelegate.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@
#pragma region stl_headers
#include <string>
#include <vector>
#pragma endregion
#pragma endregion

#pragma region cef_headers
#include <include/cef_app.h>
#pragma endregion
#pragma endregion

#pragma region qt_headers
#include <QMap>
#pragma endregion
#pragma endregion

#include <CefViewBrowserClientDelegate.h>

Expand Down Expand Up @@ -45,11 +45,11 @@ class CCefClientDelegate

virtual void processUrlRequest(CefRefPtr<CefBrowser>& browser,
const CefFrameId& frameId,
const std::string& url) override;
const CefString& url) override;

virtual void processQueryRequest(CefRefPtr<CefBrowser>& browser,
const CefFrameId& frameId,
const std::string& query,
const CefString& query,
const int64_t query_id) override;

virtual void focusedEditableNodeChanged(CefRefPtr<CefBrowser>& browser,
Expand All @@ -58,11 +58,11 @@ class CCefClientDelegate

virtual void invokeMethodNotify(CefRefPtr<CefBrowser>& browser,
const CefFrameId& frameId,
const std::string& method,
const CefString& method,
const CefRefPtr<CefListValue>& arguments) override;
virtual void reportJSResult(CefRefPtr<CefBrowser>& browser,
const CefFrameId& frameId,
const std::string& context,
const CefString& context,
const CefRefPtr<CefValue>& result) override;

// ContextMenuHandler
Expand Down Expand Up @@ -97,15 +97,13 @@ class CCefClientDelegate
CefRefPtr<CefFileDialogCallback> callback) override;

// DisplayHandler
virtual void addressChanged(CefRefPtr<CefBrowser>& browser,
const CefFrameId& frameId,
const std::string& url) override;
virtual void titleChanged(CefRefPtr<CefBrowser>& browser, const std::string& title) override;
virtual void addressChanged(CefRefPtr<CefBrowser>& browser, const CefFrameId& frameId, const CefString& url) override;
virtual void titleChanged(CefRefPtr<CefBrowser>& browser, const CefString& title) override;
virtual void faviconURLChanged(CefRefPtr<CefBrowser> browser, const std::vector<CefString>& icon_urls) override;
virtual void fullscreenModeChanged(CefRefPtr<CefBrowser>& browser, bool fullscreen) override;
virtual bool tooltipMessage(CefRefPtr<CefBrowser>& browser, const std::string& text) override;
virtual void statusMessage(CefRefPtr<CefBrowser>& browser, const std::string& value) override;
virtual void consoleMessage(CefRefPtr<CefBrowser>& browser, const std::string& message, int level) override;
virtual bool tooltipMessage(CefRefPtr<CefBrowser>& browser, const CefString& text) override;
virtual void statusMessage(CefRefPtr<CefBrowser>& browser, const CefString& value) override;
virtual void consoleMessage(CefRefPtr<CefBrowser>& browser, const CefString& message, int level) override;
virtual void loadingProgressChanged(CefRefPtr<CefBrowser>& browser, double progress) override;
virtual bool cursorChanged(CefRefPtr<CefBrowser> browser,
CefCursorHandle cursor,
Expand Down Expand Up @@ -143,8 +141,8 @@ class CCefClientDelegate
// LifSpanHandler
virtual bool onBeforePopup(CefRefPtr<CefBrowser>& browser,
const CefFrameId& frameId,
const std::string& targetUrl,
const std::string& targetFrameName,
const CefString& targetUrl,
const CefString& targetFrameName,
CefLifeSpanHandler::WindowOpenDisposition targetDisposition,
CefWindowInfo& windowInfo,
CefBrowserSettings& settings,
Expand All @@ -164,8 +162,8 @@ class CCefClientDelegate
virtual void loadError(CefRefPtr<CefBrowser>& browser,
CefRefPtr<CefFrame>& frame,
int errorCode,
const std::string& errorMsg,
const std::string& failedUrl,
const CefString& errorMsg,
const CefString& failedUrl,
bool& handled) override;

// RenderHandler
Expand Down
20 changes: 4 additions & 16 deletions src/details/QCefContextPrivate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@

#pragma region qt_headers
#include <QThread>
#pragma endregion
#pragma endregion

#pragma region cef_headers
#include <include/cef_origin_whitelist.h>
#pragma endregion
#pragma endregion

#include <QCefContext.h>

Expand Down Expand Up @@ -61,13 +61,7 @@ QCefContextPrivate::cefConfig() const
void
QCefContextPrivate::addLocalFolderResource(const QString& path, const QString& url, int priority /*= 0*/)
{
folderResourceMappingList_.append({ path, url, priority });
}

const QList<FolderResourceMapping>&
QCefContextPrivate::folderResourceMappingList()
{
return folderResourceMappingList_;
pApp_->AddLocalFolderResource(path.toStdString(), url.toStdString(), priority);
}

void
Expand All @@ -76,13 +70,7 @@ QCefContextPrivate::addArchiveResource(const QString& path,
const QString& password /*= ""*/,
int priority /*= 0*/)
{
archiveResourceMappingList_.append({ path, url, password, priority });
}

const QList<ArchiveResourceMapping>&
QCefContextPrivate::archiveResourceMappingList()
{
return archiveResourceMappingList_;
pApp_->AddArchiveResource(path.toStdString(), url.toStdString(), password.toStdString(), priority);
}

bool
Expand Down
31 changes: 2 additions & 29 deletions src/details/QCefContextPrivate.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,36 +5,21 @@
#include <memory>
#include <mutex>
#include <string>
#pragma endregion
#pragma endregion

#pragma region qt_headers
#include <QCoreApplication>
#include <QList>
#include <QObject>
#include <QTimer>
#pragma endregion
#pragma endregion

#include <CefViewBrowserApp.h>
#include <CefViewBrowserClient.h>

#include "CCefAppDelegate.h"
#include "QCefConfigPrivate.h"

typedef struct FolderResourceMapping
{
QString path;
QString url;
int priority;
} FolderResourceMapping;

typedef struct ArchiveResourceMapping
{
QString path;
QString url;
QString password;
int priority;
} ArchiveResourceMapping;

/// <summary>
///
/// </summary>
Expand All @@ -58,16 +43,6 @@ class QCefContextPrivate : public QObject
/// </summary>
const QCefConfig* config_;

/// <summary>
///
/// </summary>
QList<FolderResourceMapping> folderResourceMappingList_;

/// <summary>
///
/// </summary>
QList<ArchiveResourceMapping> archiveResourceMappingList_;

#if defined(Q_OS_MACOS) || defined(CEF_USE_QT_EVENT_LOOP)
/// <summary>
///
Expand Down Expand Up @@ -134,7 +109,6 @@ class QCefContextPrivate : public QObject
/// <param name="url">The url to be mapped to</param>
/// <param name="priority">The priority</param>
void addLocalFolderResource(const QString& path, const QString& url, int priority = 0);
const QList<FolderResourceMapping>& folderResourceMappingList();

/// <summary>
/// Adds a url mapping item with local archive (.zip) file which contains the web resource
Expand All @@ -144,7 +118,6 @@ class QCefContextPrivate : public QObject
/// <param name="password">The password of the archive</param>
/// <param name="priority">The priority</param>
void addArchiveResource(const QString& path, const QString& url, const QString& password = "", int priority = 0);
const QList<ArchiveResourceMapping>& archiveResourceMappingList();

/// <summary>
///
Expand Down
Loading

0 comments on commit 98c4ae3

Please sign in to comment.