Skip to content

Commit

Permalink
feat: optimize CEF version file generating and unify interface parame…
Browse files Browse the repository at this point in the history
…ter types
  • Loading branch information
tishion committed Jan 19, 2025
1 parent bc4f52a commit 53b9e2b
Show file tree
Hide file tree
Showing 10 changed files with 69 additions and 134 deletions.
24 changes: 24 additions & 0 deletions include/CefVersion.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
//
// CefVersion.h
// CefViewCore
//
// Created by Sheen Tian on 2025/1/19.
// This file was generated during CMake configuring.
// Do not edit this file directly by manual.
// Edit the CefVersion.h.in and then re-config project with CMake.
//

#ifndef CefVersion_h
#define CefVersion_h
#pragma once

// clang-format off
#define CEF_VERSION "127.3.5+g114ea2a+chromium-127.0.6533.120"
#define CEF_VERSION_MAJOR 127
#define CEF_VERSION_MINOR 3
#define CEF_VERSION_PATCH 5
#define CEF_COMMIT_NUMBER 3037
#define CEF_COMMIT_HASH "114ea2af1ba9da18c4ac5e599ccdbb17d01ba75a"
// clang-format on

#endif // CefVersion
4 changes: 1 addition & 3 deletions include/QCefView_global.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,6 @@
// clang-format on

// CEF version numbers
#define CEF_VERSION_MAJOR 127
#define CEF_VERSION_MINOR 3
#define CEF_VERSION_PATCH 5
#include <CefVersion.h>

#endif // QCEFEVIEW_GLOBAL_H
42 changes: 0 additions & 42 deletions include/QCefView_global.h.in

This file was deleted.

2 changes: 1 addition & 1 deletion src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ if(OS_LINUX)
# copy binary files of CefViewCore
COMMAND ${CMAKE_COMMAND}
-E copy_directory
"$<TARGET_FILE_DIR:CefViewWing>"
"$<TARGET_FILE_DIR:${CEFVIEW_WING_NAME}>"
"$<TARGET_FILE_DIR:QCefView>"
)
endif() # OS_LINUX
Expand Down
19 changes: 10 additions & 9 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 CefString& url)
CCefClientDelegate::processUrlRequest(CefRefPtr<CefBrowser>& browser, CefRefPtr<CefFrame>& frame, const CefString& url)
{
if (!IsValidBrowser(browser))
return;
Expand All @@ -27,12 +27,12 @@ CCefClientDelegate::processUrlRequest(CefRefPtr<CefBrowser>& browser, const CefF
auto u = QString::fromStdString(url);
auto source = pCefViewPrivate_->q_ptr;

emit source->cefUrlRequest(browserId, ValueConvertor::FrameIdC2Q(frameId), u);
emit source->cefUrlRequest(browserId, ValueConvertor::FrameIdC2Q(frame->GetIdentifier()), u);
}

void
CCefClientDelegate::processQueryRequest(CefRefPtr<CefBrowser>& browser,
const CefFrameId& frameId,
CefRefPtr<CefFrame>& frame,
const CefString& request,
const int64_t query_id)
{
Expand All @@ -44,12 +44,12 @@ CCefClientDelegate::processQueryRequest(CefRefPtr<CefBrowser>& browser,
auto source = pCefViewPrivate_->q_ptr;
auto query = pCefViewPrivate_->createQuery(req, query_id);

emit source->cefQueryRequest(browserId, ValueConvertor::FrameIdC2Q(frameId), query);
emit source->cefQueryRequest(browserId, ValueConvertor::FrameIdC2Q(frame->GetIdentifier()), query);
}

void
CCefClientDelegate::focusedEditableNodeChanged(CefRefPtr<CefBrowser>& browser,
const CefFrameId& frameId,
CefRefPtr<CefFrame>& frame,
bool focusOnEditableNode)
{
if (!IsValidBrowser(browser))
Expand All @@ -63,7 +63,7 @@ CCefClientDelegate::focusedEditableNodeChanged(CefRefPtr<CefBrowser>& browser,

void
CCefClientDelegate::invokeMethodNotify(CefRefPtr<CefBrowser>& browser,
const CefFrameId& frameId,
CefRefPtr<CefFrame>& frame,
const CefString& method,
const CefRefPtr<CefListValue>& arguments)
{
Expand All @@ -80,12 +80,12 @@ CCefClientDelegate::invokeMethodNotify(CefRefPtr<CefBrowser>& browser,
}

auto browserId = browser->GetIdentifier();
emit pCefViewPrivate_->q_ptr->invokeMethod(browserId, ValueConvertor::FrameIdC2Q(frameId), m, args);
emit pCefViewPrivate_->q_ptr->invokeMethod(browserId, ValueConvertor::FrameIdC2Q(frame->GetIdentifier()), m, args);
}

void
CCefClientDelegate::reportJSResult(CefRefPtr<CefBrowser>& browser,
const CefFrameId& frameId,
CefRefPtr<CefFrame>& frame,
const CefString& context,
const CefRefPtr<CefValue>& result)
{
Expand All @@ -96,5 +96,6 @@ CCefClientDelegate::reportJSResult(CefRefPtr<CefBrowser>& browser,
QVariant qV;
ValueConvertor::CefValueToQVariant(&qV, result.get());
auto c = QString::fromStdString(context);
emit pCefViewPrivate_->q_ptr->reportJavascriptResult(browserId, ValueConvertor::FrameIdC2Q(frameId), c, qV);
emit pCefViewPrivate_->q_ptr->reportJavascriptResult(
browserId, ValueConvertor::FrameIdC2Q(frame->GetIdentifier()), c, qV);
}
17 changes: 10 additions & 7 deletions src/details/CCefClientDelegate.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,24 +50,24 @@ class CCefClientDelegate
~CCefClientDelegate();

virtual void processUrlRequest(CefRefPtr<CefBrowser>& browser,
const CefFrameId& frameId,
CefRefPtr<CefFrame>& frame,
const CefString& url) override;

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

virtual void focusedEditableNodeChanged(CefRefPtr<CefBrowser>& browser,
const CefFrameId& frameId,
CefRefPtr<CefFrame>& frame,
bool focusOnEditableNode) override;

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

Expand Down Expand Up @@ -108,7 +108,9 @@ class CCefClientDelegate

// DisplayHandler
#pragma region DisplayHandler
virtual void addressChanged(CefRefPtr<CefBrowser>& browser, const CefFrameId& frameId, const CefString& url) override;
virtual void addressChanged(CefRefPtr<CefBrowser>& browser,
CefRefPtr<CefFrame>& frame,
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;
Expand Down Expand Up @@ -140,6 +142,7 @@ class CCefClientDelegate
CefRefPtr<CefDragData> dragData,
CefDragHandler::DragOperationsMask mask) override;
virtual void draggableRegionChanged(CefRefPtr<CefBrowser>& browser,
CefRefPtr<CefFrame>& frame,
const std::vector<CefDraggableRegion>& regions) override;
#pragma endregion

Expand Down Expand Up @@ -179,7 +182,7 @@ class CCefClientDelegate
// LifeSpanHandler
#pragma region LifeSpanHandler
virtual bool onBeforePopup(CefRefPtr<CefBrowser>& browser,
const CefFrameId& frameId,
CefRefPtr<CefFrame>& frame,
const CefString& targetUrl,
const CefString& targetFrameName,
CefLifeSpanHandler::WindowOpenDisposition targetDisposition,
Expand Down
4 changes: 2 additions & 2 deletions src/details/handler/CCefClientDelegate_DisplayHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,13 +66,13 @@ mapCursorShape(cef_cursor_type_t& type)
}

void
CCefClientDelegate::addressChanged(CefRefPtr<CefBrowser>& browser, const CefFrameId& frameId, const CefString& url)
CCefClientDelegate::addressChanged(CefRefPtr<CefBrowser>& browser, CefRefPtr<CefFrame>& frame, const CefString& url)
{
if (!IsValidBrowser(browser))
return;

auto u = QString::fromStdString(url);
emit pCefViewPrivate_->q_ptr->addressChanged(ValueConvertor::FrameIdC2Q(frameId), u);
emit pCefViewPrivate_->q_ptr->addressChanged(ValueConvertor::FrameIdC2Q(frame->GetIdentifier()), u);
}

void
Expand Down
1 change: 1 addition & 0 deletions src/details/handler/CCefClientDelegate_DragHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ CCefClientDelegate::onDragEnter(CefRefPtr<CefBrowser> browser,

void
CCefClientDelegate::draggableRegionChanged(CefRefPtr<CefBrowser>& browser,
CefRefPtr<CefFrame>& frame,
const std::vector<CefDraggableRegion>& regions)
{
if (!IsValidBrowser(browser))
Expand Down
30 changes: 14 additions & 16 deletions src/details/handler/CCefClientDelegate_LifeSpanHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

bool
CCefClientDelegate::onBeforePopup(CefRefPtr<CefBrowser>& browser,
const CefFrameId& frameId,
CefRefPtr<CefFrame>& frame,
const CefString& targetUrl,
const CefString& targetFrameName,
CefLifeSpanHandler::WindowOpenDisposition targetDisposition,
Expand Down Expand Up @@ -64,12 +64,12 @@ CCefClientDelegate::onBeforePopup(CefRefPtr<CefBrowser>& browser,
QMetaObject::invokeMethod(
pCefViewPrivate_,
[&]() {
cancel = pCefViewPrivate_->onBeforeNewPopupCreate(ValueConvertor::FrameIdC2Q(frameId), //
url, //
name, //
d, //
rc, //
s, //
cancel = pCefViewPrivate_->onBeforeNewPopupCreate(ValueConvertor::FrameIdC2Q(frame->GetIdentifier()), //
url, //
name, //
d, //
rc, //
s, //
disableJavascriptAccess);
if (!cancel) {
QCefSettingPrivate::CopyToCefBrowserSettings(&s, &settings);
Expand All @@ -92,11 +92,11 @@ CCefClientDelegate::onBeforePopup(CefRefPtr<CefBrowser>& browser,
QMetaObject::invokeMethod(
pCefViewPrivate_,
[=]() {
pCefViewPrivate_->onBeforeNewBrowserCreate(ValueConvertor::FrameIdC2Q(frameId), //
url, //
name, //
d, //
rc, //
pCefViewPrivate_->onBeforeNewBrowserCreate(ValueConvertor::FrameIdC2Q(frame->GetIdentifier()), //
url, //
name, //
d, //
rc, //
s);
},
Qt::QueuedConnection);
Expand Down Expand Up @@ -173,12 +173,10 @@ CCefClientDelegate::onAfterCreate(CefRefPtr<CefBrowser>& browser)

if (browser->IsPopup()) {
// pop-up window
QMetaObject::invokeMethod(
pCefViewPrivate_, [=]() { pCefViewPrivate_->onAfterCefPopupCreated(browser); }, c);
QMetaObject::invokeMethod(pCefViewPrivate_, [=]() { pCefViewPrivate_->onAfterCefPopupCreated(browser); }, c);
} else {
// new normal browser
QMetaObject::invokeMethod(
pCefViewPrivate_, [=]() { pCefViewPrivate_->onCefBrowserCreated(browser, w); }, c);
QMetaObject::invokeMethod(pCefViewPrivate_, [=]() { pCefViewPrivate_->onCefBrowserCreated(browser, w); }, c);
}
}

Expand Down
60 changes: 6 additions & 54 deletions thirdparty/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ include(FetchContent)
FetchContent_Declare(
CefViewCore
GIT_REPOSITORY https://github.com/CefView/CefViewCore.git
GIT_TAG 00e3899e8099e0491860319583274c3ea5ada806
GIT_TAG 4919e35e0b2330fc511ff3a1ebc3dbe71ad2702d
)

# set CEF version to be used
Expand Down Expand Up @@ -52,56 +52,8 @@ set(CMAKE_FOLDER "QCefView/Core")
# populate CefViewCore project
FetchContent_MakeAvailable(CefViewCore)

# 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_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_SOURCE_DIR}/include/QCefView_global.h.in"
"${CMAKE_SOURCE_DIR}/include/QCefView_global.h"
@ONLY
NEWLINE_STYLE UNIX
)
else()
message(STATUS "No need to configure QCefView_global.h file")
endif()
configure_file(
"${CefViewCore_SOURCE_DIR}/include/CefVersion.h"
"${CMAKE_SOURCE_DIR}/include/CefVersion.h"
COPYONLY
)

0 comments on commit 53b9e2b

Please sign in to comment.