diff --git a/cmake/CefViewCoreConfig.cmake b/cmake/CefViewCoreConfig.cmake index 8116d061..73dfa16f 100644 --- a/cmake/CefViewCoreConfig.cmake +++ b/cmake/CefViewCoreConfig.cmake @@ -4,7 +4,7 @@ include(FetchContent) FetchContent_Declare( CefViewCore GIT_REPOSITORY https://github.com/CefView/CefViewCore.git - GIT_TAG 6bb08e71d610671f2b2c0080fb61bcf534e4dcb2 + GIT_TAG 1cc9a2a1085520bc31609c623ae338e699498bb7 ) # set CEF version to be used diff --git a/example/QCefViewTest/MainWindow.cpp b/example/QCefViewTest/MainWindow.cpp index 72638de8..17dae654 100644 --- a/example/QCefViewTest/MainWindow.cpp +++ b/example/QCefViewTest/MainWindow.cpp @@ -68,6 +68,7 @@ MainWindow::createLeftCefView() connect(m_pLeftCefViewWidget, &QCefView::invokeMethod, this, &MainWindow::onInvokeMethod); // connect the cefQueryRequest to the slot + connect(m_pLeftCefViewWidget, &QCefView::cefUrlRequest, this, &MainWindow::onQCefUrlRequest); connect(m_pLeftCefViewWidget, &QCefView::cefQueryRequest, this, &MainWindow::onQCefQueryRequest); connect(m_pLeftCefViewWidget, &QCefView::reportJavascriptResult, this, &MainWindow::onJavascriptResult); connect(m_pLeftCefViewWidget, &QCefView::loadStart, this, &MainWindow::onLoadStart); @@ -162,6 +163,17 @@ MainWindow::onInvokeMethod(const QCefBrowserId& browserId, } } +void +MainWindow::onQCefUrlRequest(const QCefBrowserId& browserId, const QCefFrameId& frameId, const QString& url) +{ + QString title("QCef URL Request"); + QString text = QString("Current Thread: QT_UI\r\n" + "URL: %1") + .arg(url); + + QMessageBox::information(this->window(), title, text); +} + void MainWindow::onQCefQueryRequest(const QCefBrowserId& browserId, const QCefFrameId& frameId, const QCefQuery& query) { diff --git a/example/QCefViewTest/MainWindow.h b/example/QCefViewTest/MainWindow.h index 2318e4c3..a365306d 100644 --- a/example/QCefViewTest/MainWindow.h +++ b/example/QCefViewTest/MainWindow.h @@ -29,6 +29,8 @@ protected slots: const QString& method, const QVariantList& arguments); + void onQCefUrlRequest(const QCefBrowserId& browserId, const QCefFrameId& frameId, const QString& url); + void onQCefQueryRequest(const QCefBrowserId& browserId, const QCefFrameId& frameId, const QCefQuery& query); void onJavascriptResult(const QCefBrowserId& browserId, diff --git a/example/QCefViewTest/index.in.html b/example/QCefViewTest/index.in.html index cb61d092..e37efade 100644 --- a/example/QCefViewTest/index.in.html +++ b/example/QCefViewTest/index.in.html @@ -1,129 +1,135 @@ - - + + -

Web Area

-
-
-

Dragging area

+

Web Area

+
+
+

Dragging area

+
+
+ + +
+ Built-in Scheme Handler (CefView://) +
+
+ + +
+ + +
+
+ + +
+ +
+
+ + +
+ +
+ +
+
+ + +
+ Popup Browser By HTML +
+ + Popup Browser By Script + + +
+ Close Current Window + + +

An iframe with default borders:

+
-
- - -
- - -
-
- - -
- -
-
- - -
- -
- -
-
- - -
- Popup Browser By HTML -
- Popup Browser By - Script - -
- Close Current Window - - -

An iframe with default borders:

- -
\ No newline at end of file diff --git a/example/QCefViewTest/main.cpp b/example/QCefViewTest/main.cpp index aa98dd06..42e2285e 100644 --- a/example/QCefViewTest/main.cpp +++ b/example/QCefViewTest/main.cpp @@ -28,8 +28,10 @@ main(int argc, char* argv[]) config.setUserAgent("QCefViewTest"); // set log level config.setLogLevel(QCefConfig::LOGSEVERITY_DEFAULT); - // set JSBridge object name (default value is QCefViewClient) + // set JSBridge object name (default value is CefViewClient) config.setBridgeObjectName("CallBridge"); + // set Built-in scheme name (default value is CefView) + config.setBuiltinSchemeName("CefView"); // port for remote debugging (default is 0 and means to disable remote debugging) config.setRemoteDebuggingPort(9000); // set background color for all browsers diff --git a/example/QCefViewTest/tutorial.in.html b/example/QCefViewTest/tutorial.in.html index b6e3207c..ca6baea6 100644 --- a/example/QCefViewTest/tutorial.in.html +++ b/example/QCefViewTest/tutorial.in.html @@ -1,95 +1,100 @@ - - + function onCallBridgeQueryClicked() { + var query = { + request: document.getElementById("message").value, + onSuccess: function (response) { + alert(response); + }, + onFailure: function (error_code, error_message) { + alert(error_message); + }, + }; + window.CefViewQuery(query); + } + + -

Web Area

-
- -
- - -
-
+

Web Area

+
+ +
+ + +
+
- -
- -
-
+ +
+ Built-in Scheme Handler (CefView://) +
+
- -
- -
- -
-
+ +
+ +
+
- -
+ +
+ +
+ +
+
+ + +
\ No newline at end of file diff --git a/include/QCefConfig.h b/include/QCefConfig.h index 157b5407..e3641d87 100644 --- a/include/QCefConfig.h +++ b/include/QCefConfig.h @@ -16,7 +16,7 @@ #include #include #include -#pragma endregion qt_headers +#pragma endregion class QCefConfigPrivate; @@ -232,6 +232,20 @@ class QCEFVIEW_EXPORT QCefConfig /// const QString bridgeObjectName() const; + /// + /// Sets the built-in scheme name + /// + /// The scheme name + /// + /// The default value is CefView + /// + void setBuiltinSchemeName(const QString& name); + + /// + /// Gets the built-in scheme object name + /// + const QString builtinSchemeName() const; + /// /// Sets the background color of the web page /// diff --git a/include/QCefContext.h b/include/QCefContext.h index 70b53e2c..8e0d45d2 100644 --- a/include/QCefContext.h +++ b/include/QCefContext.h @@ -14,7 +14,7 @@ #pragma region qt_headers #include #include -#pragma endregion qt_headers +#pragma endregion #include diff --git a/include/QCefDownloadItem.h b/include/QCefDownloadItem.h index 6ca7162f..c234db49 100644 --- a/include/QCefDownloadItem.h +++ b/include/QCefDownloadItem.h @@ -15,7 +15,7 @@ #include #include #include -#pragma endregion qt_headers +#pragma endregion class QCefDownloadItemPrivate; diff --git a/include/QCefEvent.h b/include/QCefEvent.h index 67f40227..4f64d0c1 100644 --- a/include/QCefEvent.h +++ b/include/QCefEvent.h @@ -15,7 +15,7 @@ #include #include #include -#pragma endregion qt_headers +#pragma endregion class QCefEventPrivate; diff --git a/include/QCefQuery.h b/include/QCefQuery.h index 69a307e0..b3833cb7 100644 --- a/include/QCefQuery.h +++ b/include/QCefQuery.h @@ -11,14 +11,14 @@ #pragma once #include -#pragma region std_headers +#pragma region stl_headers #include -#pragma endregion std_headers +#pragma endregion #pragma region qt_headers #include #include -#pragma endregion qt_headers +#pragma endregion class QCefQueryPrivate; class QCefViewPrivate; diff --git a/include/QCefSetting.h b/include/QCefSetting.h index c3c05abd..e0dfc4c7 100644 --- a/include/QCefSetting.h +++ b/include/QCefSetting.h @@ -16,7 +16,7 @@ #include #include #include -#pragma endregion qt_headers +#pragma endregion class QCefSettingPrivate; diff --git a/include/QCefView.h b/include/QCefView.h index a2491bf2..dd33ac4a 100644 --- a/include/QCefView.h +++ b/include/QCefView.h @@ -16,7 +16,7 @@ #include #include #include -#pragma endregion qt_headers +#pragma endregion #include #include @@ -384,6 +384,14 @@ class QCEFVIEW_EXPORT QCefView : public QWidget /// Current progress void loadingProgressChanged(double progress); + /// + /// Gets called on built-in scheme URL access + /// + /// The browser id + /// The frame id + /// The full url + void cefUrlRequest(const QCefBrowserId& browserId, const QCefFrameId& frameId, const QString& url); + /// /// Gets called on new request /// diff --git a/include/QCefView_global.h.in b/include/QCefView_global.h.in index b3e4348c..adf1eb09 100644 --- a/include/QCefView_global.h.in +++ b/include/QCefView_global.h.in @@ -14,7 +14,7 @@ #pragma region qt_headers #include #include -#pragma endregion qt_headers +#pragma endregion #ifdef QCEFVIEW_STATIC // Static library, no need export diff --git a/src/QCefConfig.cpp b/src/QCefConfig.cpp index ef3ea7a2..b01612a7 100644 --- a/src/QCefConfig.cpp +++ b/src/QCefConfig.cpp @@ -205,6 +205,20 @@ QCefConfig::bridgeObjectName() const return QString::fromStdString(d->bridgeObjectName_); } +void +QCefConfig::setBuiltinSchemeName(const QString& name) +{ + Q_D(QCefConfig); + d->builtinSchemeName_ = name.toStdString(); +} + +const QString +QCefConfig::builtinSchemeName() const +{ + Q_D(const QCefConfig); + return QString::fromStdString(d->builtinSchemeName_); +} + void QCefConfig::setBackgroundColor(const QColor& color) { diff --git a/src/QCefContext.cpp b/src/QCefContext.cpp index cd565949..36152216 100644 --- a/src/QCefContext.cpp +++ b/src/QCefContext.cpp @@ -2,7 +2,7 @@ #pragma region qt_headers #include -#pragma endregion qt_headers +#pragma endregion #include "details/QCefContextPrivate.h" diff --git a/src/QCefEvent.cpp b/src/QCefEvent.cpp index b271af44..8d204082 100644 --- a/src/QCefEvent.cpp +++ b/src/QCefEvent.cpp @@ -2,7 +2,7 @@ #pragma region cef_headers #include -#pragma endregion cef_headers +#pragma endregion #include "details/QCefEventPrivate.h" #include "details/utils/CommonUtils.h" diff --git a/src/QCefQuery.cpp b/src/QCefQuery.cpp index 285d719b..ffb42314 100644 --- a/src/QCefQuery.cpp +++ b/src/QCefQuery.cpp @@ -2,7 +2,7 @@ #pragma region cef_headers #include -#pragma endregion cef_headers +#pragma endregion #include diff --git a/src/QCefSetting.cpp b/src/QCefSetting.cpp index 9a6662d1..00e82f93 100644 --- a/src/QCefSetting.cpp +++ b/src/QCefSetting.cpp @@ -2,7 +2,7 @@ #pragma region cef_headers #include -#pragma endregion cef_headers +#pragma endregion #include "details/QCefSettingPrivate.h" #include "details/utils/CommonUtils.h" diff --git a/src/QCefView.cpp b/src/QCefView.cpp index ca5b6f30..75a0472c 100644 --- a/src/QCefView.cpp +++ b/src/QCefView.cpp @@ -6,7 +6,7 @@ #include #include #include -#pragma endregion qt_headers +#pragma endregion #include diff --git a/src/QCefView_global.h.in b/src/QCefView_global.h.in index e1f7f4bd..ded591b9 100644 --- a/src/QCefView_global.h.in +++ b/src/QCefView_global.h.in @@ -14,7 +14,7 @@ #pragma region qt_headers #include #include -#pragma endregion qt_headers +#pragma endregion #ifdef QCEFVIEW_STATIC // Static library, no need export diff --git a/src/details/CCefClientDelegate.cpp b/src/details/CCefClientDelegate.cpp index 99b4e448..ae5d0770 100644 --- a/src/details/CCefClientDelegate.cpp +++ b/src/details/CCefClientDelegate.cpp @@ -18,14 +18,16 @@ CCefClientDelegate::~CCefClientDelegate() } void -CCefClientDelegate::processUrlRequest(const std::string& url) +CCefClientDelegate::processUrlRequest(CefRefPtr& browser, const CefFrameId& frameId, const std::string& url) { - // deprecated feature - // auto view = take(browser); - // if (view) { - // auto u = QString::fromStdString(url); - // view->onQCefUrlRequest(u); - //} + if (!IsValidBrowser(browser)) + return; + + auto browserId = browser->GetIdentifier(); + auto u = QString::fromStdString(url); + auto source = pCefViewPrivate_->q_ptr; + + emit source->cefUrlRequest(browserId, ValueConvertor::FrameIdC2Q(frameId), u); } void diff --git a/src/details/CCefClientDelegate.h b/src/details/CCefClientDelegate.h index 88b7da95..39e4017d 100644 --- a/src/details/CCefClientDelegate.h +++ b/src/details/CCefClientDelegate.h @@ -1,17 +1,17 @@ #pragma once -#pragma region std_headers +#pragma region stl_headers #include #include -#pragma endregion std_headers +#pragma endregion #pragma region cef_headers #include -#pragma endregion cef_headers +#pragma endregion #pragma region qt_headers #include -#pragma endregion qt_headers +#pragma endregion #include @@ -43,7 +43,9 @@ class CCefClientDelegate ~CCefClientDelegate(); - virtual void processUrlRequest(const std::string& url) override; + virtual void processUrlRequest(CefRefPtr& browser, + const CefFrameId& frameId, + const std::string& url) override; virtual void processQueryRequest(CefRefPtr& browser, const CefFrameId& frameId, diff --git a/src/details/QCefConfigPrivate.cpp b/src/details/QCefConfigPrivate.cpp index 9424fbcd..c2fe26de 100644 --- a/src/details/QCefConfigPrivate.cpp +++ b/src/details/QCefConfigPrivate.cpp @@ -4,10 +4,9 @@ #include #include #include -#pragma endregion qt_headers +#pragma endregion #include -#include QCefConfigPrivate::QCefConfigPrivate() { diff --git a/src/details/QCefConfigPrivate.h b/src/details/QCefConfigPrivate.h index 5a92fa43..db9d8cdc 100644 --- a/src/details/QCefConfigPrivate.h +++ b/src/details/QCefConfigPrivate.h @@ -4,15 +4,15 @@ #include #include #include -#pragma endregion stl_headers +#pragma endregion #pragma region cef_headers #include -#pragma endregion cef_headers +#pragma endregion #pragma region qt_headers #include -#pragma endregion qt_headers +#pragma endregion #include @@ -39,6 +39,7 @@ class QCefConfigPrivate #endif std::string bridgeObjectName_; + std::string builtinSchemeName_; std::string acceptLanguageList_; #if !defined(Q_OS_MACOS) diff --git a/src/details/QCefContextPrivate.cpp b/src/details/QCefContextPrivate.cpp index 167f8dc6..b1344a0e 100644 --- a/src/details/QCefContextPrivate.cpp +++ b/src/details/QCefContextPrivate.cpp @@ -2,11 +2,11 @@ #pragma region qt_headers #include -#pragma endregion qt_headers +#pragma endregion #pragma region cef_headers #include -#pragma endregion cef_headers +#pragma endregion #include diff --git a/src/details/QCefContextPrivate.h b/src/details/QCefContextPrivate.h index ebb69d6a..46201ffa 100644 --- a/src/details/QCefContextPrivate.h +++ b/src/details/QCefContextPrivate.h @@ -1,18 +1,18 @@ #pragma once -#pragma region std_headers +#pragma region stl_headers #include #include #include #include -#pragma endregion std_headers +#pragma endregion #pragma region qt_headers #include #include #include #include -#pragma endregion qt_headers +#pragma endregion #include #include diff --git a/src/details/QCefDownloadItemPrivate.cpp b/src/details/QCefDownloadItemPrivate.cpp index 9b468b49..ec97e543 100644 --- a/src/details/QCefDownloadItemPrivate.cpp +++ b/src/details/QCefDownloadItemPrivate.cpp @@ -2,7 +2,7 @@ #pragma region cef_headers #include -#pragma endregion cef_headers +#pragma endregion QSharedPointer QCefDownloadItemPrivate::create(CCefClientDelegate::RefPtr handler) diff --git a/src/details/QCefEventPrivate.h b/src/details/QCefEventPrivate.h index 004926ea..0bb85b1c 100644 --- a/src/details/QCefEventPrivate.h +++ b/src/details/QCefEventPrivate.h @@ -3,7 +3,7 @@ #pragma region qt_headers #include #include -#pragma endregion qt_headers +#pragma endregion class QCefEventPrivate { diff --git a/src/details/QCefQueryPrivate.h b/src/details/QCefQueryPrivate.h index 4e1f8407..58f563d8 100644 --- a/src/details/QCefQueryPrivate.h +++ b/src/details/QCefQueryPrivate.h @@ -2,7 +2,7 @@ #pragma region qt_headers #include -#pragma endregion qt_headers +#pragma endregion #include diff --git a/src/details/QCefSettingPrivate.cpp b/src/details/QCefSettingPrivate.cpp index c6dc866b..ebb3c175 100644 --- a/src/details/QCefSettingPrivate.cpp +++ b/src/details/QCefSettingPrivate.cpp @@ -2,11 +2,11 @@ #pragma region qt_headers #include -#pragma endregion qt_headers +#pragma endregion #pragma region cef_headers #include -#pragma endregion cef_headers +#pragma endregion #include diff --git a/src/details/QCefSettingPrivate.h b/src/details/QCefSettingPrivate.h index cdf0dd22..9d483f29 100644 --- a/src/details/QCefSettingPrivate.h +++ b/src/details/QCefSettingPrivate.h @@ -3,15 +3,15 @@ #pragma region stl_headers #include #include -#pragma endregion stl_headers +#pragma endregion #pragma region cef_headers #include -#pragma endregion cef_headers +#pragma endregion #pragma region qt_headers #include -#pragma endregion qt_headers +#pragma endregion #include diff --git a/src/details/QCefViewPrivate.cpp b/src/details/QCefViewPrivate.cpp index 921e27d6..a5ce2c33 100644 --- a/src/details/QCefViewPrivate.cpp +++ b/src/details/QCefViewPrivate.cpp @@ -1,8 +1,8 @@ #include "QCefViewPrivate.h" -#pragma region std_headers +#pragma region stl_headers #include -#pragma endregion std_headers +#pragma endregion #pragma region qt_headers #include @@ -14,14 +14,14 @@ #include #include #include -#pragma endregion qt_headers +#pragma endregion #pragma region cef_headers #include #include #include #include -#pragma endregion cef_headers +#pragma endregion #include diff --git a/src/details/QCefViewPrivate.h b/src/details/QCefViewPrivate.h index c324d0cb..0152b624 100644 --- a/src/details/QCefViewPrivate.h +++ b/src/details/QCefViewPrivate.h @@ -8,7 +8,7 @@ #if defined(QT_DEBUG) #include #endif -#pragma endregion qt_headers +#pragma endregion #include #include diff --git a/src/details/QCefWindow.h b/src/details/QCefWindow.h index b89c69ce..3a5c12ea 100644 --- a/src/details/QCefWindow.h +++ b/src/details/QCefWindow.h @@ -6,7 +6,7 @@ #include #include #include -#pragma endregion qt_headers +#pragma endregion class QCefWindow : public QWindow { diff --git a/src/details/utils/ValueConvertor.cpp b/src/details/utils/ValueConvertor.cpp index 3a1a7558..10accc14 100644 --- a/src/details/utils/ValueConvertor.cpp +++ b/src/details/utils/ValueConvertor.cpp @@ -2,7 +2,7 @@ #pragma region qt_headers #include -#pragma endregion qt_headers +#pragma endregion void ValueConvertor::CefValueToQVariant(QVariant* qVariant, CefValue* cValue) diff --git a/src/details/utils/ValueConvertor.h b/src/details/utils/ValueConvertor.h index 9814c575..e94bf319 100644 --- a/src/details/utils/ValueConvertor.h +++ b/src/details/utils/ValueConvertor.h @@ -2,11 +2,11 @@ #pragma region qt_headers #include -#pragma endregion qt_headers +#pragma endregion #pragma region cef_headers #include -#pragma endregion cef_headers +#pragma endregion #include diff --git a/src/linux/details/QCefContextPrivate_linux.cpp b/src/linux/details/QCefContextPrivate_linux.cpp index bce57d32..0e0caea1 100644 --- a/src/linux/details/QCefContextPrivate_linux.cpp +++ b/src/linux/details/QCefContextPrivate_linux.cpp @@ -27,8 +27,10 @@ QCefContextPrivate::initializeCef(const QCefConfig* config) // Initialize CEF. auto cmdArgs = QCefConfigPrivate::GetCommandLineArgs(config); auto appDelegate = std::make_shared(this, cmdArgs); + auto builtinSchemeName = config ? config->builtinSchemeName().toStdString() : std::string(); auto bridgeObjectName = config ? config->bridgeObjectName().toStdString() : std::string(); - auto app = new CefViewBrowserApp(bridgeObjectName, appDelegate); + auto app = new CefViewBrowserApp(builtinSchemeName, bridgeObjectName, appDelegate); + CefMainArgs main_args(argc_, argv_); if (!CefInitialize(main_args, cef_settings, app, nullptr)) { assert(0); diff --git a/src/mac/details/QCefContextPrivate_mac.mm b/src/mac/details/QCefContextPrivate_mac.mm index 0b277ef0..449d4d26 100644 --- a/src/mac/details/QCefContextPrivate_mac.mm +++ b/src/mac/details/QCefContextPrivate_mac.mm @@ -7,7 +7,7 @@ #include #include #include -#pragma endregion cef_headers +#pragma endregion #include #include @@ -193,8 +193,10 @@ - (void)_swizzled_run { // Initialize CEF. auto cmdArgs = QCefConfigPrivate::GetCommandLineArgs(config); auto appDelegate = std::make_shared(this, cmdArgs); + auto builtinSchemeName = config ? config->builtinSchemeName().toStdString() : std::string(); auto bridgeObjectName = config ? config->bridgeObjectName().toStdString() : std::string(); - auto app = new CefViewBrowserApp(bridgeObjectName, appDelegate); + auto app = new CefViewBrowserApp(builtinSchemeName, bridgeObjectName, appDelegate); + CefMainArgs main_args(argc_, argv_); if (!CefInitialize(main_args, cef_settings, app, nullptr)) { assert(0); diff --git a/src/win/details/QCefContextPrivate_win.cpp b/src/win/details/QCefContextPrivate_win.cpp index 1847c03b..98e1097f 100644 --- a/src/win/details/QCefContextPrivate_win.cpp +++ b/src/win/details/QCefContextPrivate_win.cpp @@ -56,8 +56,9 @@ QCefContextPrivate::initializeCef(const QCefConfig* config) auto cmdArgs = QCefConfigPrivate::GetCommandLineArgs(config); cmdArgs[kCefViewWindowsJobNameKey] = windowsJobName_.toStdString(); auto appDelegate = std::make_shared(this, cmdArgs); + auto builtinSchemeName = config ? config->builtinSchemeName().toStdString() : std::string(); auto bridgeObjectName = config ? config->bridgeObjectName().toStdString() : std::string(); - auto app = new CefViewBrowserApp(bridgeObjectName, appDelegate); + auto app = new CefViewBrowserApp(builtinSchemeName, bridgeObjectName, appDelegate); void* sandboxInfo = nullptr; #if defined(CEF_USE_SANDBOX)