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

feat: adapt to Chromium version 122 #399

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
60 changes: 60 additions & 0 deletions include/QCefView.h
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,11 @@ class QCEFVIEW_EXPORT QCefView : public QWidget
/// the source of the error
/// </param>
/// <returns>True on successful; otherwise false</returns>
#if CEF_VERSION_MAJOR >= 122
bool executeJavascript(const QString& frameId, const QString& code, const QString& url);
#else
bool executeJavascript(qint64 frameId, const QString& code, const QString& url);
#endif

/// <summary>
/// Executes javascript code in specified frame and the result will be reported through <see
Expand All @@ -211,7 +215,11 @@ class QCEFVIEW_EXPORT QCefView : public QWidget
/// </param>
/// <param name="context">The context used to identify the one execution</param>
/// <returns>True on successful; otherwise false</returns>
#if CEF_VERSION_MAJOR >= 122
bool executeJavascriptWithResult(const QString& frameId, const QString& code, const QString& url, const QString& context);
#else
bool executeJavascriptWithResult(qint64 frameId, const QString& code, const QString& url, const QString& context);
#endif

/// <summary>
/// Sets the preference for this browser
Expand Down Expand Up @@ -286,7 +294,11 @@ class QCEFVIEW_EXPORT QCefView : public QWidget
/// <param name="frameId">Indicates the frame id</param>
/// <param name="isMainFrame">Indicates the whether this is the main frame</param>
/// <param name="transitionType">transition type</param>
#if CEF_VERSION_MAJOR >= 122
void loadStart(int browserId, const QString& frameId, bool isMainFrame, int transitionType);
#else
void loadStart(int browserId, qint64 frameId, bool isMainFrame, int transitionType);
#endif

/// <summary>
/// Gets called on loading ends
Expand All @@ -295,7 +307,11 @@ class QCEFVIEW_EXPORT QCefView : public QWidget
/// <param name="frameId">Indicates the frame id</param>
/// <param name="isMainFrame">Indicates the whether this is the main frame</param>
/// <param name="httpStatusCode">The HTTP status code</param>
#if CEF_VERSION_MAJOR >= 122
void loadEnd(int browserId, const QString& frameId, bool isMainFrame, int httpStatusCode);
#else
void loadEnd(int browserId, qint64 frameId, bool isMainFrame, int httpStatusCode);
#endif

/// <summary>
/// Gets called on loading failed due to error
Expand All @@ -306,12 +322,21 @@ class QCEFVIEW_EXPORT QCefView : public QWidget
/// <param name="errorCode">The error code</param>
/// <param name="errorMsg">The error message</param>
/// <param name="failedUrl">The url caused the failure</param>
#if CEF_VERSION_MAJOR >= 122
void loadError(int browserId,
const QString& frameId,
bool isMainFrame,
int errorCode,
const QString& errorMsg,
const QString& failedUrl);
#else
void loadError(int browserId,
qint64 frameId,
bool isMainFrame,
int errorCode,
const QString& errorMsg,
const QString& failedUrl);
#endif

/// <summary>
/// Gets called on draggable region changed
Expand All @@ -325,7 +350,11 @@ class QCEFVIEW_EXPORT QCefView : public QWidget
/// </summary>
/// <param name="frameId">The frame id</param>
/// <param name="url">The address</param>
#if CEF_VERSION_MAJOR >= 122
void addressChanged(const QString& frameId, const QString& url);
#else
void addressChanged(qint64 frameId, const QString& url);
#endif

/// <summary>
/// Gets called on title changed
Expand Down Expand Up @@ -370,7 +399,11 @@ class QCEFVIEW_EXPORT QCefView : public QWidget
/// <param name="browserId">The browser id</param>
/// <param name="frameId">The frame id</param>
/// <param name="query">The query request</param>
#if CEF_VERSION_MAJOR >= 122
void cefQueryRequest(int browserId, const QString& frameId, const QCefQuery& query);
#else
void cefQueryRequest(int browserId, qint64 frameId, const QCefQuery& query);
#endif

/// <summary>
/// Gets called on invoking method request from web content(Javascript)
Expand All @@ -379,7 +412,11 @@ class QCEFVIEW_EXPORT QCefView : public QWidget
/// <param name="frameId">The frame id</param>
/// <param name="method">The method name</param>
/// <param name="arguments">The arguments list</param>
#if CEF_VERSION_MAJOR >= 122
void invokeMethod(int browserId, const QString& frameId, const QString& method, const QVariantList& arguments);
#else
void invokeMethod(int browserId, qint64 frameId, const QString& method, const QVariantList& arguments);
#endif

/// <summary>
/// Gets called on the result of the javascript executed with <see cref="executeJavascriptWithResult"/> returned
Expand All @@ -388,7 +425,11 @@ class QCEFVIEW_EXPORT QCefView : public QWidget
/// <param name="frameId">The frame id</param>
/// <param name="context">The context</param>
/// <param name="result">The result</param>
#if CEF_VERSION_MAJOR >= 122
void reportJavascriptResult(int browserId, const QString& frameId, const QString& context, const QVariant& result);
#else
void reportJavascriptResult(int browserId, qint64 frameId, const QString& context, const QVariant& result);
#endif

/// <summary>
/// Gets called after the native browser window created. This slot does not work for OSR mode.
Expand All @@ -408,12 +449,21 @@ class QCEFVIEW_EXPORT QCefView : public QWidget
/// <param name="settings">Settings to be used for the popup</param>
/// <returns>True to cancel the popup; false to allow</returns>
/// <returns></returns>
#if CEF_VERSION_MAJOR >= 122
virtual QCefView* onNewBrowser(const QString& sourceFrameId,
const QString& url,
const QString& name,
QCefView::CefWindowOpenDisposition targetDisposition,
QRect& rect,
QCefSetting& settings);
#else
virtual QCefView* onNewBrowser(qint64 sourceFrameId,
const QString& url,
const QString& name,
QCefView::CefWindowOpenDisposition targetDisposition,
QRect& rect,
QCefSetting& settings);
#endif

/// <summary>
/// Gets called before the popup browser created (only for browser created by JavaScript)
Expand All @@ -425,13 +475,23 @@ class QCEFVIEW_EXPORT QCefView : public QWidget
/// <param name="rect">Rect to be used for the popup</param>
/// <param name="settings">Settings to be used for the popup</param>
/// <returns>True to cancel the popup; false to allow</returns>
#if CEF_VERSION_MAJOR >= 122
virtual bool onNewPopup(const QString& frameId,
const QString& targetUrl,
QString& targetFrameName,
QCefView::CefWindowOpenDisposition targetDisposition,
QRect& rect,
QCefSetting& settings,
bool& disableJavascriptAccess);
#else
virtual bool onNewPopup(qint64 frameId,
const QString& targetUrl,
QString& targetFrameName,
QCefView::CefWindowOpenDisposition targetDisposition,
QRect& rect,
QCefSetting& settings,
bool& disableJavascriptAccess);
#endif

/// <summary>
/// Gets called on new download item was required. Keep reference to the download item
Expand Down
31 changes: 31 additions & 0 deletions src/QCefView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -183,16 +183,26 @@ QCefView::responseQCefQuery(const QCefQuery& query)
return d->responseQCefQuery(query);
}

#if CEF_VERSION_MAJOR >= 122
bool
QCefView::executeJavascript(const QString& frameId, const QString& code, const QString& url)
#else
bool
QCefView::executeJavascript(qint64 frameId, const QString& code, const QString& url)
#endif
{
Q_D(QCefView);

return d->executeJavascript(frameId, code, url);
}

#if CEF_VERSION_MAJOR >= 122
bool
QCefView::executeJavascriptWithResult(const QString& frameId, const QString& code, const QString& url, const QString& context)
#else
bool
QCefView::executeJavascriptWithResult(qint64 frameId, const QString& code, const QString& url, const QString& context)
#endif
{
Q_D(QCefView);

Expand Down Expand Up @@ -271,13 +281,23 @@ QCefView::setFocus(Qt::FocusReason reason)
d->setCefWindowFocus(true);
}

#if CEF_VERSION_MAJOR >= 122
QCefView*
QCefView::onNewBrowser(const QString& sourceFrameId,
const QString& url,
const QString& name,
CefWindowOpenDisposition targetDisposition,
QRect& rect,
QCefSetting& settings)
#else
QCefView*
QCefView::onNewBrowser(qint64 sourceFrameId,
const QString& url,
const QString& name,
CefWindowOpenDisposition targetDisposition,
QRect& rect,
QCefSetting& settings)
#endif
{
QCefView* popup = new QCefView(url, &settings, nullptr, Qt::WindowFlags());
if (!popup) {
Expand All @@ -296,6 +316,16 @@ QCefView::onNewBrowser(qint64 sourceFrameId,
return popup;
}

#if CEF_VERSION_MAJOR >= 122
bool
QCefView::onNewPopup(const QString& frameId,
const QString& targetUrl,
QString& targetFrameName,
QCefView::CefWindowOpenDisposition targetDisposition,
QRect& rect,
QCefSetting& settings,
bool& disableJavascriptAccess)
#else
bool
QCefView::onNewPopup(qint64 frameId,
const QString& targetUrl,
Expand All @@ -304,6 +334,7 @@ QCefView::onNewPopup(qint64 frameId,
QRect& rect,
QCefSetting& settings,
bool& disableJavascriptAccess)
#endif
{
return false;
}
Expand Down
71 changes: 71 additions & 0 deletions src/details/CCefClientDelegate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,76 @@ CCefClientDelegate::processUrlRequest(const std::string& url)
//}
}

#if CEF_VERSION_MAJOR >= 122
void
CCefClientDelegate::processQueryRequest(CefRefPtr<CefBrowser>& browser,
const std::string& frameId,
const std::string& request,
const int64_t query_id)
{
if (!IsValidBrowser(browser))
return;

auto browserId = browser->GetIdentifier();
auto req = QString::fromStdString(request);
auto source = pCefViewPrivate_->q_ptr;
auto query = pCefViewPrivate_->createQuery(req, query_id);

emit source->cefQueryRequest(browserId, QString::fromStdString(frameId), query);
}

void
CCefClientDelegate::focusedEditableNodeChanged(CefRefPtr<CefBrowser>& browser,
const std::string& frameId,
bool focusOnEditableNode)
{
if (!IsValidBrowser(browser))
return;

QMetaObject::invokeMethod(pCefViewPrivate_, //
"onCefInputStateChanged", //
Q_ARG(bool, focusOnEditableNode) //
);
}

void
CCefClientDelegate::invokeMethodNotify(CefRefPtr<CefBrowser>& browser,
const std::string& frameId,
const std::string& method,
const CefRefPtr<CefListValue>& arguments)
{
if (!IsValidBrowser(browser))
return;

auto m = QString::fromStdString(method);
QVariantList args;
for (int i = 0; i < arguments->GetSize(); i++) {
QVariant qV;
auto cV = arguments->GetValue(i);
ValueConvertor::CefValueToQVariant(&qV, cV.get());
args.push_back(qV);
}

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

void
CCefClientDelegate::reportJSResult(CefRefPtr<CefBrowser>& browser,
const std::string& frameId,
const std::string& context,
const CefRefPtr<CefValue>& result)
{
if (!IsValidBrowser(browser))
return;

auto browserId = browser->GetIdentifier();
QVariant qV;
ValueConvertor::CefValueToQVariant(&qV, result.get());
auto c = QString::fromStdString(context);
emit pCefViewPrivate_->q_ptr->reportJavascriptResult(browserId, QString::fromStdString(frameId), c, qV);
}
#else
void
CCefClientDelegate::processQueryRequest(CefRefPtr<CefBrowser>& browser,
int64_t frameId,
Expand Down Expand Up @@ -96,3 +166,4 @@ CCefClientDelegate::reportJSResult(CefRefPtr<CefBrowser>& browser,
auto c = QString::fromStdString(context);
emit pCefViewPrivate_->q_ptr->reportJavascriptResult(browserId, frameId, c, qV);
}
#endif
Loading
Loading