From 002e47692b071400e8917a1604b37039860f86c2 Mon Sep 17 00:00:00 2001 From: Leena Miettinen Date: Thu, 11 Jul 2019 11:47:30 +0200 Subject: Doc: Edit docs on script injection MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Task-number: QTBUG-76489 Change-Id: If489ebed802d273b0015bc6cfc190d948c4896e3 Reviewed-by: Jüri Valdmann --- src/webenginewidgets/api/qwebenginepage.cpp | 2 +- src/webenginewidgets/api/qwebengineprofile.cpp | 3 ++- src/webenginewidgets/api/qwebenginescript.cpp | 2 ++ .../api/qwebenginescriptcollection.cpp | 2 ++ src/webenginewidgets/doc/src/qwebenginepage_lgpl.qdoc | 19 +++++++++++-------- 5 files changed, 18 insertions(+), 10 deletions(-) (limited to 'src/webenginewidgets') diff --git a/src/webenginewidgets/api/qwebenginepage.cpp b/src/webenginewidgets/api/qwebenginepage.cpp index 78b89a53c..055047341 100644 --- a/src/webenginewidgets/api/qwebenginepage.cpp +++ b/src/webenginewidgets/api/qwebenginepage.cpp @@ -2183,7 +2183,7 @@ void QWebEnginePage::runJavaScript(const QString& scriptSource, quint32 worldId, In addition, a page might also execute scripts added through QWebEngineProfile::scripts(). - \sa QWebEngineScriptCollection, QWebEngineScript + \sa QWebEngineScriptCollection, QWebEngineScript, {Script Injection} */ QWebEngineScriptCollection &QWebEnginePage::scripts() diff --git a/src/webenginewidgets/api/qwebengineprofile.cpp b/src/webenginewidgets/api/qwebengineprofile.cpp index c8aafa0e8..6644af3ff 100644 --- a/src/webenginewidgets/api/qwebengineprofile.cpp +++ b/src/webenginewidgets/api/qwebengineprofile.cpp @@ -593,7 +593,8 @@ bool QWebEngineProfile::visitedLinksContainsUrl(const QUrl &url) const Returns the collection of scripts that are injected into all pages that share this profile. - \sa QWebEngineScriptCollection, QWebEngineScript, QWebEnginePage::scripts() + \sa QWebEngineScriptCollection, QWebEngineScript, QWebEnginePage::scripts(), + {Script Injection} */ QWebEngineScriptCollection *QWebEngineProfile::scripts() const { diff --git a/src/webenginewidgets/api/qwebenginescript.cpp b/src/webenginewidgets/api/qwebenginescript.cpp index d1e996b3a..af6b9aa8d 100644 --- a/src/webenginewidgets/api/qwebenginescript.cpp +++ b/src/webenginewidgets/api/qwebenginescript.cpp @@ -67,6 +67,8 @@ using QtWebEngineCore::UserScript; Use QWebEnginePage::scripts() and QWebEngineProfile::scripts() to access the collection of scripts associated with a single page or a number of pages sharing the same profile. + + \sa {Script Injection} */ /*! \enum QWebEngineScript::InjectionPoint diff --git a/src/webenginewidgets/api/qwebenginescriptcollection.cpp b/src/webenginewidgets/api/qwebenginescriptcollection.cpp index 5ef0ffd44..8cbeeb804 100644 --- a/src/webenginewidgets/api/qwebenginescriptcollection.cpp +++ b/src/webenginewidgets/api/qwebenginescriptcollection.cpp @@ -55,6 +55,8 @@ using QtWebEngineCore::UserScript; Use QWebEnginePage::scripts() and QWebEngineProfile::scripts() to access the collection of scripts associated with a single page or a number of pages sharing the same profile. + + \sa {Script Injection} */ /*! diff --git a/src/webenginewidgets/doc/src/qwebenginepage_lgpl.qdoc b/src/webenginewidgets/doc/src/qwebenginepage_lgpl.qdoc index 15e57e904..2bf4d0413 100644 --- a/src/webenginewidgets/doc/src/qwebenginepage_lgpl.qdoc +++ b/src/webenginewidgets/doc/src/qwebenginepage_lgpl.qdoc @@ -759,10 +759,15 @@ \fn void QWebEnginePage::runJavaScript(const QString &scriptSource, const QWebEngineCallback &resultCallback) \since 5.7 - Runs the JavaScript code contained in \a scriptSource in the world specified by \a worldId. - The world ID values are the same as provided by QWebEngineScript::ScriptWorldId, and between \c 0 - and \c 256. Using the \e runJavaScript() versions without the world ID is the same as running the - script in the \c MainWorld. + Runs the JavaScript code contained in \a scriptSource without checking + whether the DOM of the page has been constructed. If you need more + control over how the script is run, consider using \l scripts() instead. + + To avoid conflicts with other scripts executed on the page, the world in + which the script is run is specified by \a worldId. The world ID values are + the same as provided by QWebEngineScript::ScriptWorldId, and between \c 0 + and \c 256. If you leave out the \c world ID, the script is run in the + \c MainWorld. When the script has been executed, \a resultCallback is called with the result of the last executed statement. \c resultCallback can be any of a function pointer, a functor or a lambda, @@ -772,7 +777,7 @@ page.runJavaScript("document.title", [](const QVariant &v) { qDebug() << v.toString(); }); \endcode - Only "plain data" can be returned from JavaScript as the result value. + Only plain data can be returned from JavaScript as the result value. Supported data types include all of the JSON data types as well as, for example, \c{Date} and \c{ArrayBuffer}. Unsupported data types include, for example, \c{Function} and \c{Promise}. @@ -784,9 +789,7 @@ during page destruction. When QWebEnginePage is deleted, the callback is triggered with an invalid value and it is not safe to use the corresponding QWebEnginePage or QWebEngineView instance inside it. - See scripts() for an alternative API to inject scripts. - - \sa QWebEngineScript::ScriptWorldId + \sa scripts(), QWebEngineScript::ScriptWorldId, {Script Injection} */ /*! -- cgit v1.2.3 From 08053c0a8a2cfc01c4d92155342a98d610e12473 Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Wed, 24 Jul 2019 15:01:47 +0300 Subject: Fix compilation with C++20 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Implicit capture of this in [=] is deprecated. Fix by using explicit captures. Change-Id: Ia4344c4a15669f5076ad848626278a57cbe6767a Reviewed-by: Mårten Nordheim Reviewed-by: Allan Sandfeld Jensen --- src/webenginewidgets/api/qwebenginepage.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/webenginewidgets') diff --git a/src/webenginewidgets/api/qwebenginepage.cpp b/src/webenginewidgets/api/qwebenginepage.cpp index a350433b8..7e6265fda 100644 --- a/src/webenginewidgets/api/qwebenginepage.cpp +++ b/src/webenginewidgets/api/qwebenginepage.cpp @@ -438,7 +438,7 @@ void QWebEnginePagePrivate::didPrintPage(quint64 requestId, QSharedPointerstart(); PrinterWorker *printerWorker = new PrinterWorker(result, currentPrinter); - QObject::connect(printerWorker, &PrinterWorker::resultReady, q, [=](bool success) { + QObject::connect(printerWorker, &PrinterWorker::resultReady, q, [requestId, this](bool success) { currentPrinter = nullptr; m_callbacks.invoke(requestId, success); }); -- cgit v1.2.3 From c3c37b4e93a26748497bec1a0dc29b8358408157 Mon Sep 17 00:00:00 2001 From: Tamas Zakor Date: Thu, 11 Jul 2019 10:44:05 +0200 Subject: Fix tooltip text wrapping Also set the hiding delay to a reasonable time. Fixes: QTBUG-76122 Change-Id: Id971edbd9fb87cc96df53f73f2e7c61bde5855ef Reviewed-by: Allan Sandfeld Jensen --- src/webenginewidgets/api/qwebenginepage.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/webenginewidgets') diff --git a/src/webenginewidgets/api/qwebenginepage.cpp b/src/webenginewidgets/api/qwebenginepage.cpp index 055047341..35fe542e8 100644 --- a/src/webenginewidgets/api/qwebenginepage.cpp +++ b/src/webenginewidgets/api/qwebenginepage.cpp @@ -1887,7 +1887,7 @@ void QWebEnginePagePrivate::setToolTip(const QString &toolTipText) } // Update tooltip if text was changed. - QString wrappedTip = QLatin1String("

") + QString wrappedTip = QLatin1String("

") % toolTipText.toHtmlEscaped().left(MaxTooltipLength) % QLatin1String("

"); if (view->toolTip() != wrappedTip) -- cgit v1.2.3 From 1c33a4a6ae07106513a8105ebbc2d0c65363b333 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=BCri=20Valdmann?= Date: Mon, 29 Jul 2019 13:10:14 +0200 Subject: Fix QWebEnginePage visibility state Calling view.show(); view.load(...); view.hide(); results in a WebContents in visible state because the first call to show() is delayed via a timer and never canceled so it takes effect after the hide(). Also, the page's visibility state is not updated when changing views, so that a visible QWebEngineView can be set to display a hidden QWebEnginePage. Fixes: QTBUG-77209 Change-Id: I0243c659f4039a35c36e04ea55c5972666170fd0 Reviewed-by: Allan Sandfeld Jensen --- src/webenginewidgets/api/qwebenginepage.cpp | 4 +++- src/webenginewidgets/api/qwebengineview.cpp | 3 +++ 2 files changed, 6 insertions(+), 1 deletion(-) (limited to 'src/webenginewidgets') diff --git a/src/webenginewidgets/api/qwebenginepage.cpp b/src/webenginewidgets/api/qwebenginepage.cpp index f252137ae..8451bab1a 100644 --- a/src/webenginewidgets/api/qwebenginepage.cpp +++ b/src/webenginewidgets/api/qwebenginepage.cpp @@ -175,7 +175,6 @@ QWebEnginePagePrivate::QWebEnginePagePrivate(QWebEngineProfile *_profile) wasShownTimer.setSingleShot(true); QObject::connect(&wasShownTimer, &QTimer::timeout, [this](){ ensureInitialized(); - wasShown(); }); profile->d_ptr->addWebContentsAdapterClient(this); @@ -215,6 +214,9 @@ void QWebEnginePagePrivate::initializationFinished() if (!qFuzzyCompare(adapter->currentZoomFactor(), defaultZoomFactor)) adapter->setZoomFactor(defaultZoomFactor); + if (view && view->isVisible()) + adapter->wasShown(); + scriptCollection.d->initializationFinished(adapter); m_isBeingAdopted = false; diff --git a/src/webenginewidgets/api/qwebengineview.cpp b/src/webenginewidgets/api/qwebengineview.cpp index 6c08df343..6e1138522 100644 --- a/src/webenginewidgets/api/qwebengineview.cpp +++ b/src/webenginewidgets/api/qwebengineview.cpp @@ -61,6 +61,7 @@ void QWebEngineViewPrivate::pageChanged(QWebEnginePage *oldPage, QWebEnginePage Q_Q(QWebEngineView); if (oldPage) { + oldPage->d_ptr->wasHidden(); oldPage->disconnect(q); } @@ -74,6 +75,8 @@ void QWebEngineViewPrivate::pageChanged(QWebEnginePage *oldPage, QWebEnginePage QObject::connect(newPage, &QWebEnginePage::loadFinished, q, &QWebEngineView::loadFinished); QObject::connect(newPage, &QWebEnginePage::selectionChanged, q, &QWebEngineView::selectionChanged); QObject::connect(newPage, &QWebEnginePage::renderProcessTerminated, q, &QWebEngineView::renderProcessTerminated); + if (q->isVisible()) + newPage->d_ptr->wasShown(); } auto oldUrl = oldPage ? oldPage->url() : QUrl(); -- cgit v1.2.3 From 83c5182c998b74858c5c28fcf2feb1d4e07754bb Mon Sep 17 00:00:00 2001 From: Kirill Burtsev Date: Wed, 14 Aug 2019 18:37:35 +0200 Subject: Fix reporting overridable flag for QML WebEngineCertificateError type MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Also remove confusion inside CertificateErrorController constructor and overridable method by matching documentation for AllowCertificateError method of ContentBrowserClient api. Change-Id: I7e10ef71a4429dcf5acc4b714a8a45f67a2ec684 Reviewed-by: Jüri Valdmann --- src/webenginewidgets/api/qwebenginepage.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/webenginewidgets') diff --git a/src/webenginewidgets/api/qwebenginepage.cpp b/src/webenginewidgets/api/qwebenginepage.cpp index 35fe542e8..d7f65c23b 100644 --- a/src/webenginewidgets/api/qwebenginepage.cpp +++ b/src/webenginewidgets/api/qwebenginepage.cpp @@ -1787,7 +1787,7 @@ void QWebEnginePagePrivate::allowCertificateError(const QSharedPointererror(), controller->url(), controller->overridable() && !controller->strictEnforcement(), controller->errorString()); + QWebEngineCertificateError error(controller->error(), controller->url(), controller->overridable(), controller->errorString()); accepted = q->certificateError(error); if (error.isOverridable()) -- cgit v1.2.3 From d5d0cd81cc770d696b19305717cc827ec1a89bd4 Mon Sep 17 00:00:00 2001 From: Kirill Burtsev Date: Wed, 14 Aug 2019 18:45:36 +0200 Subject: Reject certificate error for non-overridable errors MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit On certificate validation error page load is just halted meaning that no progress or load result are reported and no default error page for certificate errors is shown. Even though documentation states that 'By default, an invalid certificate will be automatically rejected' and that aligns with default implementation of certificateError method within Page and non-deferred errors in quick View, page or view silently stays in an intermediate state for non-overridable errors. Fix this inconsistent behavior by automatically rejecting certificate for every invalid case (non-overridable error, not deferred or not implemented overridable method). Change-Id: Id1cee2ee5cc45bdcb5f262a6c99c84274e6ca374 Reviewed-by: Jüri Valdmann --- src/webenginewidgets/api/qwebenginepage.cpp | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'src/webenginewidgets') diff --git a/src/webenginewidgets/api/qwebenginepage.cpp b/src/webenginewidgets/api/qwebenginepage.cpp index d7f65c23b..aeed6ce85 100644 --- a/src/webenginewidgets/api/qwebenginepage.cpp +++ b/src/webenginewidgets/api/qwebenginepage.cpp @@ -1789,9 +1789,7 @@ void QWebEnginePagePrivate::allowCertificateError(const QSharedPointererror(), controller->url(), controller->overridable(), controller->errorString()); accepted = q->certificateError(error); - - if (error.isOverridable()) - controller->accept(accepted); + controller->accept(error.isOverridable() && accepted); } void QWebEnginePagePrivate::selectClientCert(const QSharedPointer &controller) -- cgit v1.2.3