summaryrefslogtreecommitdiffstats
path: root/src/webengine/api
diff options
context:
space:
mode:
authorAllan Sandfeld Jensen <allan.jensen@theqtcompany.com>2016-01-12 11:32:02 +0100
committerAllan Sandfeld Jensen <allan.jensen@theqtcompany.com>2016-01-12 11:35:45 +0100
commita077399f4c17f57e911334867c918cc6ddeb15fc (patch)
treec8e4d326d7a074e9d16b68399ecc5f728f8533fe /src/webengine/api
parent3d698f5de377bde2293e222536bc50171cfdf1b8 (diff)
parent12dd6ff845656eb625e2ee3d0e73392bc2c61983 (diff)
Merge branch '5.6' into dev
Diffstat (limited to 'src/webengine/api')
-rw-r--r--src/webengine/api/qquickwebenginecertificateerror.cpp22
-rw-r--r--src/webengine/api/qquickwebenginedownloaditem.cpp16
-rw-r--r--src/webengine/api/qquickwebenginedownloaditem_p.h3
-rw-r--r--src/webengine/api/qquickwebenginedownloaditem_p_p.h3
-rw-r--r--src/webengine/api/qquickwebenginehistory.cpp4
-rw-r--r--src/webengine/api/qquickwebengineloadrequest.cpp2
-rw-r--r--src/webengine/api/qquickwebenginenewviewrequest.cpp2
-rw-r--r--src/webengine/api/qquickwebengineprofile.cpp277
-rw-r--r--src/webengine/api/qquickwebengineprofile.h161
-rw-r--r--src/webengine/api/qquickwebengineprofile_p.h108
-rw-r--r--src/webengine/api/qquickwebengineprofile_p_p.h88
-rw-r--r--src/webengine/api/qquickwebenginescript.cpp1
-rw-r--r--src/webengine/api/qquickwebenginesettings.cpp2
-rw-r--r--src/webengine/api/qquickwebenginesingleton.cpp4
-rw-r--r--src/webengine/api/qquickwebengineview.cpp112
-rw-r--r--src/webengine/api/qquickwebengineview_p.h5
-rw-r--r--src/webengine/api/qquickwebengineview_p_p.h5
-rw-r--r--src/webengine/api/qtwebengineglobal.cpp52
18 files changed, 568 insertions, 299 deletions
diff --git a/src/webengine/api/qquickwebenginecertificateerror.cpp b/src/webengine/api/qquickwebenginecertificateerror.cpp
index 202d201b3..ea9b2bc11 100644
--- a/src/webengine/api/qquickwebenginecertificateerror.cpp
+++ b/src/webengine/api/qquickwebenginecertificateerror.cpp
@@ -61,13 +61,13 @@ public:
/*!
\qmltype WebEngineCertificateError
\instantiates QQuickWebEngineCertificateError
- \inqmlmodule QtWebEngine 1.1
+ \inqmlmodule QtWebEngine
\since QtWebEngine 1.1
- \brief A utility class for accepting or denying certificate exceptions when a certificate error occurs.
+ \brief A utility type for ignoring certificate errors or rejecting erroneous certificates.
- This class contains information about a certificate error that happened and provides a way to accept or
- deny a certificate exception.
+ This QML type contains information about a certificate error that occurred and provides a way
+ to ignore the error or reject the certificate.
\sa WebEngineView::certificateError
*/
@@ -86,8 +86,9 @@ QQuickWebEngineCertificateError::~QQuickWebEngineCertificateError()
/*!
\qmlmethod void WebEngineCertificateError::defer()
- This function should be called when there is a need to postpone the decision to ignore or not the certificate error. This is useful to
- wait for user input. When called it will pause the url request until WebEngineCertificateError::ignoreCertificateError() or
+ This function should be called when there is a need to postpone the decision whether to ignore a
+ certificate error, for example, while waiting for user input. When called, the function pauses the
+ URL request until WebEngineCertificateError::ignoreCertificateError() or
WebEngineCertificateError::rejectCertificate() is called.
*/
void QQuickWebEngineCertificateError::defer()
@@ -98,7 +99,7 @@ void QQuickWebEngineCertificateError::defer()
/*!
\qmlmethod void WebEngineCertificateError::ignoreCertificateError()
- The certificate error is ignored and the WebEngineView continues to load the requested url.
+ The certificate error is ignored, and the web engine view continues to load the requested URL.
*/
void QQuickWebEngineCertificateError::ignoreCertificateError()
{
@@ -114,7 +115,7 @@ void QQuickWebEngineCertificateError::ignoreCertificateError()
/*!
\qmlmethod void WebEngineCertificateError::rejectCertificate()
- The WebEngineView stops loading the requested url.
+ The certificate is rejected, and the web engine view stops loading the requested URL.
*/
void QQuickWebEngineCertificateError::rejectCertificate()
{
@@ -148,7 +149,8 @@ QUrl QQuickWebEngineCertificateError::url() const
The type of the error.
- \value SslPinnedKeyNotInCertificateChain The certificate did not match the built-in public key pins for the host name.
+ \value SslPinnedKeyNotInCertificateChain The certificate did not match the built-in public keys
+ pinned for the host name.
\value CertificateCommonNameInvalid The certificate's common name did not match the host name.
\value CertificateDateInvalid The certificate is not valid at the current date and time.
\value CertificateAuthorityInvalid The certificate is not signed by a trusted authority.
@@ -184,7 +186,7 @@ QString QQuickWebEngineCertificateError::description() const
\qmlproperty bool WebEngineCertificateError::overridable
\readonly
- A boolean that indicates if the certificate error can be overridden and accepted.
+ A boolean that indicates whether the certificate error can be overridden and ignored.
*/
bool QQuickWebEngineCertificateError::overridable() const
{
diff --git a/src/webengine/api/qquickwebenginedownloaditem.cpp b/src/webengine/api/qquickwebenginedownloaditem.cpp
index 6efa45e43..0dbbb05fd 100644
--- a/src/webengine/api/qquickwebenginedownloaditem.cpp
+++ b/src/webengine/api/qquickwebenginedownloaditem.cpp
@@ -36,7 +36,7 @@
#include "qquickwebenginedownloaditem_p.h"
#include "qquickwebenginedownloaditem_p_p.h"
-#include "qquickwebengineprofile_p_p.h"
+#include "qquickwebengineprofile_p.h"
using QtWebEngineCore::BrowserContextAdapterClient;
@@ -77,7 +77,7 @@ QQuickWebEngineDownloadItemPrivate::~QQuickWebEngineDownloadItemPrivate()
/*!
\qmltype WebEngineDownloadItem
\instantiates QQuickWebEngineDownloadItem
- \inqmlmodule QtWebEngine 1.1
+ \inqmlmodule QtWebEngine
\since QtWebEngine 1.1
\brief Provides information about a download.
@@ -218,6 +218,18 @@ qint64 QQuickWebEngineDownloadItem::receivedBytes() const
}
/*!
+ \qmlproperty QString WebEngineDownloadItem::mimeType
+
+ Holds the MIME type of the download.
+*/
+
+QString QQuickWebEngineDownloadItem::mimeType() const
+{
+ Q_D(const QQuickWebEngineDownloadItem);
+ return d->mimeType;
+}
+
+/*!
\qmlproperty QString WebEngineDownloadItem::path
Holds the full target path where data is being downloaded to.
diff --git a/src/webengine/api/qquickwebenginedownloaditem_p.h b/src/webengine/api/qquickwebenginedownloaditem_p.h
index 9d1a5a211..46b39fe0a 100644
--- a/src/webengine/api/qquickwebenginedownloaditem_p.h
+++ b/src/webengine/api/qquickwebenginedownloaditem_p.h
@@ -84,6 +84,7 @@ public:
Q_PROPERTY(SavePageFormat savePageFormat READ savePageFormat WRITE setSavePageFormat NOTIFY savePageFormatChanged)
Q_PROPERTY(qint64 totalBytes READ totalBytes NOTIFY totalBytesChanged)
Q_PROPERTY(qint64 receivedBytes READ receivedBytes NOTIFY receivedBytesChanged)
+ Q_PROPERTY(QString mimeType READ mimeType NOTIFY mimeTypeChanged REVISION 1)
Q_PROPERTY(QString path READ path WRITE setPath NOTIFY pathChanged)
Q_INVOKABLE void accept();
@@ -93,6 +94,7 @@ public:
DownloadState state() const;
qint64 totalBytes() const;
qint64 receivedBytes() const;
+ QString mimeType() const;
QString path() const;
void setPath(QString path);
SavePageFormat savePageFormat() const;
@@ -103,6 +105,7 @@ Q_SIGNALS:
void savePageFormatChanged();
void receivedBytesChanged();
void totalBytesChanged();
+ void mimeTypeChanged();
void pathChanged();
private:
diff --git a/src/webengine/api/qquickwebenginedownloaditem_p_p.h b/src/webengine/api/qquickwebenginedownloaditem_p_p.h
index 36b9eb349..a85e4e6c4 100644
--- a/src/webengine/api/qquickwebenginedownloaditem_p_p.h
+++ b/src/webengine/api/qquickwebenginedownloaditem_p_p.h
@@ -50,7 +50,7 @@
#include "browser_context_adapter_client.h"
#include "qquickwebenginedownloaditem_p.h"
-#include "qquickwebengineprofile_p.h"
+#include "qquickwebengineprofile.h"
#include <private/qtwebengineglobal_p.h>
#include <QString>
#include <QPointer>
@@ -72,6 +72,7 @@ public:
QQuickWebEngineDownloadItem::SavePageFormat savePageFormat;
qint64 totalBytes;
qint64 receivedBytes;
+ QString mimeType;
QString downloadPath;
void update(const QtWebEngineCore::BrowserContextAdapterClient::DownloadItemInfo &info);
diff --git a/src/webengine/api/qquickwebenginehistory.cpp b/src/webengine/api/qquickwebenginehistory.cpp
index 175b52248..d790093a4 100644
--- a/src/webengine/api/qquickwebenginehistory.cpp
+++ b/src/webengine/api/qquickwebenginehistory.cpp
@@ -121,7 +121,7 @@ int QQuickWebEngineForwardHistoryListModelPrivate::offsetForIndex(int index) con
/*!
\qmltype WebEngineHistoryListModel
\instantiates QQuickWebEngineHistoryListModel
- \inqmlmodule QtWebEngine 1.1
+ \inqmlmodule QtWebEngine
\since QtWebEngine 1.1
\brief A data model that represents the history of a web engine page.
@@ -208,7 +208,7 @@ QQuickWebEngineHistoryPrivate::~QQuickWebEngineHistoryPrivate()
/*!
\qmltype WebEngineHistory
\instantiates QQuickWebEngineHistory
- \inqmlmodule QtWebEngine 1.1
+ \inqmlmodule QtWebEngine
\since QtWebEngine 1.1
\brief Provides data models that represent the history of a web engine page.
diff --git a/src/webengine/api/qquickwebengineloadrequest.cpp b/src/webengine/api/qquickwebengineloadrequest.cpp
index e94fa7eb9..e39d7b4d1 100644
--- a/src/webengine/api/qquickwebengineloadrequest.cpp
+++ b/src/webengine/api/qquickwebengineloadrequest.cpp
@@ -59,7 +59,7 @@ public:
/*!
\qmltype WebEngineLoadRequest
\instantiates QQuickWebEngineLoadRequest
- \inqmlmodule QtWebEngine 1.0
+ \inqmlmodule QtWebEngine
\since QtWebEngine 1.0
\brief A utility type for the WebEngineView::loadingChanged signal.
diff --git a/src/webengine/api/qquickwebenginenewviewrequest.cpp b/src/webengine/api/qquickwebenginenewviewrequest.cpp
index 6e20c0a46..74729ddf1 100644
--- a/src/webengine/api/qquickwebenginenewviewrequest.cpp
+++ b/src/webengine/api/qquickwebenginenewviewrequest.cpp
@@ -42,7 +42,7 @@
/*!
\qmltype WebEngineNewViewRequest
\instantiates QQuickWebEngineNewViewRequest
- \inqmlmodule QtWebEngine 1.1
+ \inqmlmodule QtWebEngine
\since QtWebEngine 1.1
\brief A utility type for the WebEngineView::newViewRequested signal.
diff --git a/src/webengine/api/qquickwebengineprofile.cpp b/src/webengine/api/qquickwebengineprofile.cpp
index 6df16bf54..523121b6f 100644
--- a/src/webengine/api/qquickwebengineprofile.cpp
+++ b/src/webengine/api/qquickwebengineprofile.cpp
@@ -34,11 +34,11 @@
**
****************************************************************************/
-#include "qquickwebengineprofile_p.h"
+#include "qquickwebengineprofile.h"
#include "qquickwebenginedownloaditem_p.h"
#include "qquickwebenginedownloaditem_p_p.h"
-#include "qquickwebengineprofile_p_p.h"
+#include "qquickwebengineprofile_p.h"
#include "qquickwebenginesettings_p.h"
#include "qwebenginecookiestore.h"
@@ -57,6 +57,67 @@ ASSERT_ENUMS_MATCH(QQuickWebEngineDownloadItem::SingleHtmlSaveFormat, QtWebEngin
ASSERT_ENUMS_MATCH(QQuickWebEngineDownloadItem::CompleteHtmlSaveFormat, QtWebEngineCore::BrowserContextAdapterClient::CompleteHtmlSaveFormat)
ASSERT_ENUMS_MATCH(QQuickWebEngineDownloadItem::MimeHtmlSaveFormat, QtWebEngineCore::BrowserContextAdapterClient::MimeHtmlSaveFormat)
+/*!
+ \class QQuickWebEngineProfile
+ \brief The QQuickWebEngineProfile class provides a web-engine profile shared by multiple pages.
+ \since 5.6
+
+ \inmodule QtWebEngine
+
+ QQuickWebEngineProfile contains settings, scripts, and the list of visited links shared by all
+ web engine pages that belong to the profile. As such, profiles can be used to isolate pages
+ from each other. A typical use case is a dedicated profile for a 'private browsing' mode.
+
+ The default profile is a built-in profile that all web pages not specifically created with
+ another profile belong to.
+*/
+
+/*!
+ \enum QQuickWebEngineProfile::HttpCacheType
+
+ This enum describes the HTTP cache type:
+
+ \value MemoryHttpCache Use an in-memory cache. This is the only setting possible if
+ \c off-the-record is set or no cache path is available.
+ \value DiskHttpCache Use a disk cache. This is the default.
+*/
+
+/*!
+ \enum QQuickWebEngineProfile::PersistentCookiesPolicy
+
+ This enum describes policy for cookie persistency:
+
+ \value NoPersistentCookies
+ Both session and persistent cookies are stored in memory. This is the only setting
+ possible if \c off-the-record is set or no persistent data path is available.
+ \value AllowPersistentCookies
+ Cookies marked persistent are saved to and restored from disk, whereas session cookies
+ are only stored to disk for crash recovery. This is the default setting.
+ \value ForcePersistentCookies
+ Both session and persistent cookies are saved to and restored from disk.
+*/
+
+/*!
+ \fn QQuickWebEngineProfile::downloadRequested(QQuickWebEngineDownloadItem *download)
+
+ This signal is emitted whenever a download has been triggered.
+ The \a download argument holds the state of the download.
+ The download has to be explicitly accepted with
+ \c{QQuickWebEngineDownloadItem::accept()} or it will be
+ cancelled by default.
+ The download item is parented by the profile. If it is not accepted, it
+ will be deleted immediately after the signal emission.
+ This signal cannot be used with a queued connection.
+*/
+
+/*!
+ \fn QQuickWebEngineProfile::downloadFinished(QQuickWebEngineDownloadItem *download)
+
+ This signal is emitted whenever downloading stops, because it finished successfully, was
+ cancelled, or was interrupted (for example, because connectivity was lost).
+ The \a download argument holds the state of the finished download instance.
+*/
+
QQuickWebEngineProfilePrivate::QQuickWebEngineProfilePrivate(BrowserContextAdapter* browserContext)
: m_settings(new QQuickWebEngineSettings())
, m_browserContextRef(browserContext)
@@ -99,6 +160,7 @@ void QQuickWebEngineProfilePrivate::downloadRequested(DownloadItemInfo &info)
itemPrivate->downloadId = info.id;
itemPrivate->downloadState = QQuickWebEngineDownloadItem::DownloadRequested;
itemPrivate->totalBytes = info.totalBytes;
+ itemPrivate->mimeType = info.mimeType;
itemPrivate->downloadPath = info.path;
itemPrivate->savePageFormat = static_cast<QQuickWebEngineDownloadItem::SavePageFormat>(
info.savePageFormat);
@@ -142,7 +204,7 @@ void QQuickWebEngineProfilePrivate::downloadUpdated(const DownloadItemInfo &info
/*!
\qmltype WebEngineProfile
\instantiates QQuickWebEngineProfile
- \inqmlmodule QtWebEngine 1.1
+ \inqmlmodule QtWebEngine
\since QtWebEngine 1.1
\brief Contains settings, scripts, and visited links common to multiple web engine views.
@@ -171,8 +233,12 @@ void QQuickWebEngineProfilePrivate::downloadUpdated(const DownloadItemInfo &info
The \a download argument holds the state of the finished download instance.
*/
-QQuickWebEngineProfile::QQuickWebEngineProfile()
- : d_ptr(new QQuickWebEngineProfilePrivate(new BrowserContextAdapter(false)))
+/*!
+ Constructs a new profile with the parent \a parent.
+*/
+QQuickWebEngineProfile::QQuickWebEngineProfile(QObject *parent)
+ : QObject(parent),
+ d_ptr(new QQuickWebEngineProfilePrivate(new BrowserContextAdapter(false)))
{
// Sets up the global WebEngineContext
QQuickWebEngineProfile::defaultProfile();
@@ -186,6 +252,9 @@ QQuickWebEngineProfile::QQuickWebEngineProfile(QQuickWebEngineProfilePrivate *pr
d_ptr->q_ptr = this;
}
+/*!
+ \internal
+*/
QQuickWebEngineProfile::~QQuickWebEngineProfile()
{
}
@@ -199,6 +268,15 @@ QQuickWebEngineProfile::~QQuickWebEngineProfile()
\sa WebEngineProfile::persistentStoragePath, WebEngineProfile::cachePath
*/
+/*!
+ \property QQuickWebEngineProfile::storageName
+
+ The storage name that is used to create separate subdirectories for each profile that uses
+ the disk for storing persistent data and cache.
+
+ \sa QQuickWebEngineProfile::persistentStoragePath, QQuickWebEngineProfile::cachePath
+*/
+
QString QQuickWebEngineProfile::storageName() const
{
const Q_D(QQuickWebEngineProfile);
@@ -229,6 +307,16 @@ void QQuickWebEngineProfile::setStorageName(const QString &name)
An off-the-record profile forces cookies, the HTTP cache, and other normally persistent data
to be stored only in memory.
*/
+
+
+/*!
+ \property QQuickWebEngineProfile::offTheRecord
+
+ Whether the web engine profile is \e off-the-record.
+ An off-the-record profile forces cookies, the HTTP cache, and other normally persistent data
+ to be stored only in memory.
+*/
+
bool QQuickWebEngineProfile::isOffTheRecord() const
{
const Q_D(QQuickWebEngineProfile);
@@ -260,6 +348,18 @@ void QQuickWebEngineProfile::setOffTheRecord(bool offTheRecord)
QStandardPaths::writableLocation(QStandardPaths::DataLocation) in a directory named using
storageName.
*/
+
+/*!
+ \property QQuickWebEngineProfile::persistentStoragePath
+
+ The path to the location where the persistent data for the browser and web content are
+ stored. Persistent data includes persistent cookies, HTML5 local storage, and visited links.
+
+ By default, the storage is located below
+ QStandardPaths::writableLocation(QStandardPaths::DataLocation) in a directory named using
+ storageName.
+*/
+
QString QQuickWebEngineProfile::persistentStoragePath() const
{
const Q_D(QQuickWebEngineProfile);
@@ -284,6 +384,17 @@ void QQuickWebEngineProfile::setPersistentStoragePath(const QString &path)
below QStandardPaths::writableLocation(QStandardPaths::CacheLocation) in a directory named using
storageName.
*/
+
+/*!
+ \property QQuickWebEngineProfile::cachePath
+
+ The path to the location where the profile's caches are stored, in particular the HTTP cache.
+
+ By default, the caches are stored
+ below QStandardPaths::writableLocation(QStandardPaths::CacheLocation) in a directory named using
+ storageName.
+*/
+
QString QQuickWebEngineProfile::cachePath() const
{
const Q_D(QQuickWebEngineProfile);
@@ -304,6 +415,13 @@ void QQuickWebEngineProfile::setCachePath(const QString &path)
The user-agent string sent with HTTP to identify the browser.
*/
+
+/*!
+ \property QQuickWebEngineProfile::httpUserAgent
+
+ The user-agent string sent with HTTP to identify the browser.
+*/
+
QString QQuickWebEngineProfile::httpUserAgent() const
{
const Q_D(QQuickWebEngineProfile);
@@ -332,6 +450,14 @@ void QQuickWebEngineProfile::setHttpUserAgent(const QString &userAgent)
Uses a disk cache. This is the default value.
*/
+/*!
+ \property QQuickWebEngineProfile::httpCacheType
+
+ This enumeration describes the type of the HTTP cache.
+
+ If the profile is off-the-record, MemoryHttpCache is returned.
+*/
+
QQuickWebEngineProfile::HttpCacheType QQuickWebEngineProfile::httpCacheType() const
{
const Q_D(QQuickWebEngineProfile);
@@ -362,6 +488,13 @@ void QQuickWebEngineProfile::setHttpCacheType(QQuickWebEngineProfile::HttpCacheT
Both session and persistent cookies are saved to and restored from disk.
*/
+/*!
+ \property QQuickWebEngineProfile::persistentCookiesPolicy
+
+ This enumeration describes the policy of cookie persistency.
+ If the profile is off-the-record, NoPersistentCookies is returned.
+*/
+
QQuickWebEngineProfile::PersistentCookiesPolicy QQuickWebEngineProfile::persistentCookiesPolicy() const
{
const Q_D(QQuickWebEngineProfile);
@@ -385,6 +518,16 @@ void QQuickWebEngineProfile::setPersistentCookiesPolicy(QQuickWebEngineProfile::
\sa httpCacheType
*/
+
+/*!
+ \property QQuickWebEngineProfile::httpCacheMaximumSize
+
+ The maximum size of the HTTP cache. If \c 0, the size will be controlled automatically by
+ QtWebEngine. The default value is \c 0.
+
+ \sa httpCacheType
+*/
+
int QQuickWebEngineProfile::httpCacheMaximumSize() const
{
const Q_D(QQuickWebEngineProfile);
@@ -407,6 +550,13 @@ void QQuickWebEngineProfile::setHttpCacheMaximumSize(int maximumSize)
\since QtWebEngine 1.2
*/
+
+/*!
+ \property QQuickWebEngineProfile::httpAcceptLanguage
+
+ The value of the Accept-Language HTTP request-header field.
+*/
+
QString QQuickWebEngineProfile::httpAcceptLanguage() const
{
Q_D(const QQuickWebEngineProfile);
@@ -422,6 +572,13 @@ void QQuickWebEngineProfile::setHttpAcceptLanguage(const QString &httpAcceptLang
emit httpAcceptLanguageChanged();
}
+/*!
+ Returns the default profile.
+
+ The default profile uses the storage name "Default".
+
+ \sa storageName()
+*/
QQuickWebEngineProfile *QQuickWebEngineProfile::defaultProfile()
{
static QQuickWebEngineProfile *profile = new QQuickWebEngineProfile(
@@ -430,6 +587,9 @@ QQuickWebEngineProfile *QQuickWebEngineProfile::defaultProfile()
return profile;
}
+/*!
+ Returns the cookie store singleton, if one has been set.
+*/
QWebEngineCookieStore *QQuickWebEngineProfile::cookieStore() const
{
const Q_D(QQuickWebEngineProfile);
@@ -444,12 +604,119 @@ QWebEngineCookieStore *QQuickWebEngineProfile::cookieStore() const
\sa WebEngineProfile::cachePath
*/
+
+/*!
+ \since 5.7
+
+ Removes the profile's cache entries.
+
+ \sa WebEngineProfile::clearHttpCache
+*/
void QQuickWebEngineProfile::clearHttpCache()
{
Q_D(QQuickWebEngineProfile);
d->browserContext()->clearHttpCache();
}
+
+/*!
+ Registers a request interceptor singleton \a interceptor to intercept URL requests.
+
+ The profile does not take ownership of the pointer.
+
+ \sa QWebEngineUrlRequestInterceptor
+*/
+void QQuickWebEngineProfile::setRequestInterceptor(QWebEngineUrlRequestInterceptor *interceptor)
+{
+ Q_D(QQuickWebEngineProfile);
+ d->browserContext()->setRequestInterceptor(interceptor);
+}
+
+/*!
+ Returns the custom URL scheme handler register for the URL scheme \a scheme.
+*/
+const QWebEngineUrlSchemeHandler *QQuickWebEngineProfile::urlSchemeHandler(const QByteArray &scheme) const
+{
+ const Q_D(QQuickWebEngineProfile);
+ if (d->browserContext()->customUrlSchemeHandlers().contains(scheme))
+ return d->browserContext()->customUrlSchemeHandlers().value(scheme);
+ return 0;
+}
+
+static bool checkInternalScheme(const QByteArray &scheme)
+{
+ static QSet<QByteArray> internalSchemes;
+ if (internalSchemes.isEmpty()) {
+ internalSchemes << QByteArrayLiteral("qrc") << QByteArrayLiteral("data") << QByteArrayLiteral("blob")
+ << QByteArrayLiteral("http") << QByteArrayLiteral("ftp") << QByteArrayLiteral("javascript");
+ }
+ return internalSchemes.contains(scheme);
+}
+
+/*!
+ Registers a handler \a handler for custom URL scheme \a scheme in the profile.
+*/
+void QQuickWebEngineProfile::installUrlSchemeHandler(const QByteArray &scheme, QWebEngineUrlSchemeHandler *handler)
+{
+ Q_D(QQuickWebEngineProfile);
+ Q_ASSERT(handler);
+ if (checkInternalScheme(scheme)) {
+ qWarning("Cannot install a URL scheme handler overriding internal scheme: %s", scheme.constData());
+ return;
+ }
+
+ if (d->browserContext()->customUrlSchemeHandlers().contains(scheme)) {
+ if (d->browserContext()->customUrlSchemeHandlers().value(scheme) != handler)
+ qWarning("URL scheme handler already installed for the scheme: %s", scheme.constData());
+ return;
+ }
+ d->browserContext()->addCustomUrlSchemeHandler(scheme, handler);
+ connect(handler, SIGNAL(_q_destroyedUrlSchemeHandler(QWebEngineUrlSchemeHandler*)), this, SLOT(destroyedUrlSchemeHandler(QWebEngineUrlSchemeHandler*)));
+}
+
+/*!
+ Removes the custom URL scheme handler \a handler from the profile.
+
+ \sa removeUrlScheme()
+*/
+void QQuickWebEngineProfile::removeUrlSchemeHandler(QWebEngineUrlSchemeHandler *handler)
+{
+ Q_D(QQuickWebEngineProfile);
+ Q_ASSERT(handler);
+ if (!d->browserContext()->removeCustomUrlSchemeHandler(handler))
+ return;
+ disconnect(handler, SIGNAL(_q_destroyedUrlSchemeHandler(QWebEngineUrlSchemeHandler*)), this, SLOT(destroyedUrlSchemeHandler(QWebEngineUrlSchemeHandler*)));
+}
+
+/*!
+ Removes the custom URL scheme \a scheme from the profile.
+
+ \sa removeUrlSchemeHandler()
+*/
+void QQuickWebEngineProfile::removeUrlScheme(const QByteArray &scheme)
+{
+ Q_D(QQuickWebEngineProfile);
+ QWebEngineUrlSchemeHandler *handler = d->browserContext()->takeCustomUrlSchemeHandler(scheme);
+ if (!handler)
+ return;
+ disconnect(handler, SIGNAL(_q_destroyedUrlSchemeHandler(QWebEngineUrlSchemeHandler*)), this, SLOT(destroyedUrlSchemeHandler(QWebEngineUrlSchemeHandler*)));
+}
+
+/*!
+ Removes all custom URL scheme handlers installed in the profile.
+*/
+void QQuickWebEngineProfile::removeAllUrlSchemeHandlers()
+{
+ Q_D(QQuickWebEngineProfile);
+ d->browserContext()->customUrlSchemeHandlers().clear();
+ d->browserContext()->updateCustomUrlSchemeHandlers();
+}
+
+void QQuickWebEngineProfile::destroyedUrlSchemeHandler(QWebEngineUrlSchemeHandler *obj)
+{
+ removeUrlSchemeHandler(obj);
+}
+
QQuickWebEngineSettings *QQuickWebEngineProfile::settings() const
{
const Q_D(QQuickWebEngineProfile);
diff --git a/src/webengine/api/qquickwebengineprofile.h b/src/webengine/api/qquickwebengineprofile.h
new file mode 100644
index 000000000..7905e5d29
--- /dev/null
+++ b/src/webengine/api/qquickwebengineprofile.h
@@ -0,0 +1,161 @@
+/****************************************************************************
+**
+** Copyright (C) 2015 The Qt Company Ltd.
+** Contact: http://www.qt.io/licensing/
+**
+** This file is part of the QtWebEngine module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see http://www.qt.io/terms-conditions. For further
+** information use the contact form at http://www.qt.io/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 3 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPLv3 included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 3 requirements
+** will be met: https://www.gnu.org/licenses/lgpl.html.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 2.0 or later as published by the Free
+** Software Foundation and appearing in the file LICENSE.GPL included in
+** the packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 2.0 requirements will be
+** met: http://www.gnu.org/licenses/gpl-2.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QQUICKWEBENGINEPROFILE_H
+#define QQUICKWEBENGINEPROFILE_H
+
+
+#include <QtWebEngine/qtwebengineglobal.h>
+
+#include <QtCore/QObject>
+#include <QtCore/QScopedPointer>
+#include <QtCore/QString>
+
+namespace QtWebEngineCore {
+class BrowserContextAdapter;
+}
+
+QT_BEGIN_NAMESPACE
+
+class QQuickWebEngineDownloadItem;
+class QQuickWebEngineProfilePrivate;
+class QQuickWebEngineSettings;
+class QWebEngineCookieStore;
+class QWebEngineUrlRequestInterceptor;
+class QWebEngineUrlSchemeHandler;
+
+class Q_WEBENGINE_EXPORT QQuickWebEngineProfile : public QObject {
+ Q_OBJECT
+ Q_PROPERTY(QString storageName READ storageName WRITE setStorageName NOTIFY storageNameChanged FINAL)
+ Q_PROPERTY(bool offTheRecord READ isOffTheRecord WRITE setOffTheRecord NOTIFY offTheRecordChanged FINAL)
+ Q_PROPERTY(QString persistentStoragePath READ persistentStoragePath WRITE setPersistentStoragePath NOTIFY persistentStoragePathChanged FINAL)
+ Q_PROPERTY(QString cachePath READ cachePath WRITE setCachePath NOTIFY cachePathChanged FINAL)
+ Q_PROPERTY(QString httpUserAgent READ httpUserAgent WRITE setHttpUserAgent NOTIFY httpUserAgentChanged FINAL)
+ Q_PROPERTY(HttpCacheType httpCacheType READ httpCacheType WRITE setHttpCacheType NOTIFY httpCacheTypeChanged FINAL)
+ Q_PROPERTY(QString httpAcceptLanguage READ httpAcceptLanguage WRITE setHttpAcceptLanguage NOTIFY httpAcceptLanguageChanged FINAL REVISION 1)
+ Q_PROPERTY(PersistentCookiesPolicy persistentCookiesPolicy READ persistentCookiesPolicy WRITE setPersistentCookiesPolicy NOTIFY persistentCookiesPolicyChanged FINAL)
+ Q_PROPERTY(int httpCacheMaximumSize READ httpCacheMaximumSize WRITE setHttpCacheMaximumSize NOTIFY httpCacheMaximumSizeChanged FINAL)
+public:
+ QQuickWebEngineProfile(QObject *parent = Q_NULLPTR);
+ ~QQuickWebEngineProfile();
+
+ enum HttpCacheType {
+ MemoryHttpCache,
+ DiskHttpCache
+ };
+ Q_ENUM(HttpCacheType)
+
+ enum PersistentCookiesPolicy {
+ NoPersistentCookies,
+ AllowPersistentCookies,
+ ForcePersistentCookies
+ };
+ Q_ENUM(PersistentCookiesPolicy)
+
+ QString storageName() const;
+ void setStorageName(const QString &name);
+
+ bool isOffTheRecord() const;
+ void setOffTheRecord(bool offTheRecord);
+
+ QString persistentStoragePath() const;
+ void setPersistentStoragePath(const QString &path);
+
+ QString cachePath() const;
+ void setCachePath(const QString &path);
+
+ QString httpUserAgent() const;
+ void setHttpUserAgent(const QString &userAgent);
+
+ HttpCacheType httpCacheType() const;
+ void setHttpCacheType(QQuickWebEngineProfile::HttpCacheType);
+
+ PersistentCookiesPolicy persistentCookiesPolicy() const;
+ void setPersistentCookiesPolicy(QQuickWebEngineProfile::PersistentCookiesPolicy);
+
+ int httpCacheMaximumSize() const;
+ void setHttpCacheMaximumSize(int maxSize);
+
+ QString httpAcceptLanguage() const;
+ void setHttpAcceptLanguage(const QString &httpAcceptLanguage);
+
+ QWebEngineCookieStore *cookieStore() const;
+
+ void setRequestInterceptor(QWebEngineUrlRequestInterceptor *interceptor);
+
+ const QWebEngineUrlSchemeHandler *urlSchemeHandler(const QByteArray &) const;
+ void installUrlSchemeHandler(const QByteArray &scheme, QWebEngineUrlSchemeHandler *);
+ void removeUrlScheme(const QByteArray &scheme);
+ void removeUrlSchemeHandler(QWebEngineUrlSchemeHandler *);
+ void removeAllUrlSchemeHandlers();
+
+ void clearHttpCache();
+
+ static QQuickWebEngineProfile *defaultProfile();
+
+Q_SIGNALS:
+ void storageNameChanged();
+ void offTheRecordChanged();
+ void persistentStoragePathChanged();
+ void cachePathChanged();
+ void httpUserAgentChanged();
+ void httpCacheTypeChanged();
+ void persistentCookiesPolicyChanged();
+ void httpCacheMaximumSizeChanged();
+ Q_REVISION(1) void httpAcceptLanguageChanged();
+
+ void downloadRequested(QQuickWebEngineDownloadItem *download);
+ void downloadFinished(QQuickWebEngineDownloadItem *download);
+
+private Q_SLOTS:
+ void destroyedUrlSchemeHandler(QWebEngineUrlSchemeHandler *obj);
+
+private:
+ Q_DECLARE_PRIVATE(QQuickWebEngineProfile)
+ QQuickWebEngineProfile(QQuickWebEngineProfilePrivate *, QObject *parent = 0);
+ QQuickWebEngineSettings *settings() const;
+
+ friend class QQuickWebEngineSettings;
+ friend class QQuickWebEngineSingleton;
+ friend class QQuickWebEngineViewPrivate;
+ friend class QQuickWebEngineDownloadItem;
+ friend class QQuickWebEngineDownloadItemPrivate;
+ QScopedPointer<QQuickWebEngineProfilePrivate> d_ptr;
+};
+
+QT_END_NAMESPACE
+
+#endif // QQUICKWEBENGINEPROFILE_H
diff --git a/src/webengine/api/qquickwebengineprofile_p.h b/src/webengine/api/qquickwebengineprofile_p.h
index 2744ed0ec..8fb56a616 100644
--- a/src/webengine/api/qquickwebengineprofile_p.h
+++ b/src/webengine/api/qquickwebengineprofile_p.h
@@ -48,108 +48,40 @@
// We mean it.
//
-#include <private/qtwebengineglobal_p.h>
+#include "browser_context_adapter_client.h"
+#include "qquickwebengineprofile_p.h"
+#include "browser_context_adapter.h"
-#include <QObject>
-#include <QScopedPointer>
-#include <QString>
-
-namespace QtWebEngineCore {
-class BrowserContextAdapter;
-}
+#include <QExplicitlySharedDataPointer>
+#include <QMap>
+#include <QPointer>
QT_BEGIN_NAMESPACE
class QQuickWebEngineDownloadItem;
-class QQuickWebEngineProfilePrivate;
class QQuickWebEngineSettings;
-class QWebEngineCookieStore;
-class Q_WEBENGINE_PRIVATE_EXPORT QQuickWebEngineProfile : public QObject {
- Q_OBJECT
- Q_PROPERTY(QString storageName READ storageName WRITE setStorageName NOTIFY storageNameChanged FINAL)
- Q_PROPERTY(bool offTheRecord READ isOffTheRecord WRITE setOffTheRecord NOTIFY offTheRecordChanged FINAL)
- Q_PROPERTY(QString persistentStoragePath READ persistentStoragePath WRITE setPersistentStoragePath NOTIFY persistentStoragePathChanged FINAL)
- Q_PROPERTY(QString cachePath READ cachePath WRITE setCachePath NOTIFY cachePathChanged FINAL)
- Q_PROPERTY(QString httpUserAgent READ httpUserAgent WRITE setHttpUserAgent NOTIFY httpUserAgentChanged FINAL)
- Q_PROPERTY(HttpCacheType httpCacheType READ httpCacheType WRITE setHttpCacheType NOTIFY httpCacheTypeChanged FINAL)
- Q_PROPERTY(QString httpAcceptLanguage READ httpAcceptLanguage WRITE setHttpAcceptLanguage NOTIFY httpAcceptLanguageChanged FINAL REVISION 1)
- Q_PROPERTY(PersistentCookiesPolicy persistentCookiesPolicy READ persistentCookiesPolicy WRITE setPersistentCookiesPolicy NOTIFY persistentCookiesPolicyChanged FINAL)
- Q_PROPERTY(int httpCacheMaximumSize READ httpCacheMaximumSize WRITE setHttpCacheMaximumSize NOTIFY httpCacheMaximumSizeChanged FINAL)
+class QQuickWebEngineProfilePrivate : public QtWebEngineCore::BrowserContextAdapterClient {
public:
- QQuickWebEngineProfile();
- ~QQuickWebEngineProfile();
-
- enum HttpCacheType {
- MemoryHttpCache,
- DiskHttpCache
- };
- Q_ENUM(HttpCacheType)
-
- enum PersistentCookiesPolicy {
- NoPersistentCookies,
- AllowPersistentCookies,
- ForcePersistentCookies
- };
- Q_ENUM(PersistentCookiesPolicy)
-
- QString storageName() const;
- void setStorageName(const QString &name);
-
- bool isOffTheRecord() const;
- void setOffTheRecord(bool offTheRecord);
-
- QString persistentStoragePath() const;
- void setPersistentStoragePath(const QString &path);
-
- QString cachePath() const;
- void setCachePath(const QString &path);
+ Q_DECLARE_PUBLIC(QQuickWebEngineProfile)
+ QQuickWebEngineProfilePrivate(QtWebEngineCore::BrowserContextAdapter* browserContext);
+ ~QQuickWebEngineProfilePrivate();
- QString httpUserAgent() const;
- void setHttpUserAgent(const QString &userAgent);
+ QtWebEngineCore::BrowserContextAdapter *browserContext() const { return m_browserContextRef.data(); }
+ QQuickWebEngineSettings *settings() const { return m_settings.data(); }
- HttpCacheType httpCacheType() const;
- void setHttpCacheType(QQuickWebEngineProfile::HttpCacheType);
+ void cancelDownload(quint32 downloadId);
+ void downloadDestroyed(quint32 downloadId);
- PersistentCookiesPolicy persistentCookiesPolicy() const;
- void setPersistentCookiesPolicy(QQuickWebEngineProfile::PersistentCookiesPolicy);
-
- int httpCacheMaximumSize() const;
- void setHttpCacheMaximumSize(int maxSize);
-
- QString httpAcceptLanguage() const;
- void setHttpAcceptLanguage(const QString &httpAcceptLanguage);
-
- static QQuickWebEngineProfile *defaultProfile();
-
- Q_REVISION(1) Q_INVOKABLE QWebEngineCookieStore *cookieStore() const;
- Q_REVISION(2) Q_INVOKABLE void clearHttpCache();
-
-signals:
- void storageNameChanged();
- void offTheRecordChanged();
- void persistentStoragePathChanged();
- void cachePathChanged();
- void httpUserAgentChanged();
- void httpCacheTypeChanged();
- void persistentCookiesPolicyChanged();
- void httpCacheMaximumSizeChanged();
- Q_REVISION(1) void httpAcceptLanguageChanged();
-
- void downloadRequested(QQuickWebEngineDownloadItem *download);
- void downloadFinished(QQuickWebEngineDownloadItem *download);
+ void downloadRequested(DownloadItemInfo &info) Q_DECL_OVERRIDE;
+ void downloadUpdated(const DownloadItemInfo &info) Q_DECL_OVERRIDE;
private:
- Q_DECLARE_PRIVATE(QQuickWebEngineProfile)
- QQuickWebEngineProfile(QQuickWebEngineProfilePrivate *, QObject *parent = 0);
- QQuickWebEngineSettings *settings() const;
-
- friend class QQuickWebEngineSettings;
- friend class QQuickWebEngineSingleton;
friend class QQuickWebEngineViewPrivate;
- friend class QQuickWebEngineDownloadItem;
- friend class QQuickWebEngineDownloadItemPrivate;
- QScopedPointer<QQuickWebEngineProfilePrivate> d_ptr;
+ QQuickWebEngineProfile *q_ptr;
+ QScopedPointer<QQuickWebEngineSettings> m_settings;
+ QExplicitlySharedDataPointer<QtWebEngineCore::BrowserContextAdapter> m_browserContextRef;
+ QMap<quint32, QPointer<QQuickWebEngineDownloadItem> > m_ongoingDownloads;
};
QT_END_NAMESPACE
diff --git a/src/webengine/api/qquickwebengineprofile_p_p.h b/src/webengine/api/qquickwebengineprofile_p_p.h
deleted file mode 100644
index 4df5f1934..000000000
--- a/src/webengine/api/qquickwebengineprofile_p_p.h
+++ /dev/null
@@ -1,88 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2015 The Qt Company Ltd.
-** Contact: http://www.qt.io/licensing/
-**
-** This file is part of the QtWebEngine module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see http://www.qt.io/terms-conditions. For further
-** information use the contact form at http://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPLv3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or later as published by the Free
-** Software Foundation and appearing in the file LICENSE.GPL included in
-** the packaging of this file. Please review the following information to
-** ensure the GNU General Public License version 2.0 requirements will be
-** met: http://www.gnu.org/licenses/gpl-2.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef QQUICKWEBENGINEPROFILE_P_P_H
-#define QQUICKWEBENGINEPROFILE_P_P_H
-
-//
-// W A R N I N G
-// -------------
-//
-// This file is not part of the Qt API. It exists purely as an
-// implementation detail. This header file may change from version to
-// version without notice, or even be removed.
-//
-// We mean it.
-//
-
-#include "browser_context_adapter_client.h"
-#include "qquickwebengineprofile_p.h"
-
-#include <QExplicitlySharedDataPointer>
-#include <QMap>
-#include <QPointer>
-
-QT_BEGIN_NAMESPACE
-
-class QQuickWebEngineDownloadItem;
-class QQuickWebEngineSettings;
-
-class QQuickWebEngineProfilePrivate : public QtWebEngineCore::BrowserContextAdapterClient {
-public:
- Q_DECLARE_PUBLIC(QQuickWebEngineProfile)
- QQuickWebEngineProfilePrivate(QtWebEngineCore::BrowserContextAdapter* browserContext);
- ~QQuickWebEngineProfilePrivate();
-
- QtWebEngineCore::BrowserContextAdapter *browserContext() const { return m_browserContextRef.data(); }
- QQuickWebEngineSettings *settings() const { return m_settings.data(); }
-
- void cancelDownload(quint32 downloadId);
- void downloadDestroyed(quint32 downloadId);
-
- void downloadRequested(DownloadItemInfo &info) Q_DECL_OVERRIDE;
- void downloadUpdated(const DownloadItemInfo &info) Q_DECL_OVERRIDE;
-
-private:
- friend class QQuickWebEngineViewPrivate;
- QQuickWebEngineProfile *q_ptr;
- QScopedPointer<QQuickWebEngineSettings> m_settings;
- QExplicitlySharedDataPointer<QtWebEngineCore::BrowserContextAdapter> m_browserContextRef;
- QMap<quint32, QPointer<QQuickWebEngineDownloadItem> > m_ongoingDownloads;
-};
-
-QT_END_NAMESPACE
-
-#endif // QQUICKWEBENGINEPROFILE_P_P_H
diff --git a/src/webengine/api/qquickwebenginescript.cpp b/src/webengine/api/qquickwebenginescript.cpp
index 71dad701f..a19ec1534 100644
--- a/src/webengine/api/qquickwebenginescript.cpp
+++ b/src/webengine/api/qquickwebenginescript.cpp
@@ -40,7 +40,6 @@
#include <QQmlFile>
#include <QtCore/QDebug>
#include <QtCore/QFile>
-#include <QtCore/QStringBuilder>
#include <QtCore/QTimerEvent>
#include "user_script_controller_host.h"
diff --git a/src/webengine/api/qquickwebenginesettings.cpp b/src/webengine/api/qquickwebenginesettings.cpp
index 79819efc3..5bbca191d 100644
--- a/src/webengine/api/qquickwebenginesettings.cpp
+++ b/src/webengine/api/qquickwebenginesettings.cpp
@@ -36,9 +36,9 @@
#include "qquickwebenginesettings_p.h"
-#include "qquickwebengineprofile_p.h"
#include "web_engine_settings.h"
+#include <QtWebEngine/QQuickWebEngineProfile>
#include <QtCore/QList>
QT_BEGIN_NAMESPACE
diff --git a/src/webengine/api/qquickwebenginesingleton.cpp b/src/webengine/api/qquickwebenginesingleton.cpp
index 7ff974eb4..b7a8c3b69 100644
--- a/src/webengine/api/qquickwebenginesingleton.cpp
+++ b/src/webengine/api/qquickwebenginesingleton.cpp
@@ -37,14 +37,14 @@
#include "qquickwebenginesingleton_p.h"
#include "qquickwebenginesettings_p.h"
-#include "qquickwebengineprofile_p.h"
+#include <QtWebEngine/QQuickWebEngineProfile>
QT_BEGIN_NAMESPACE
/*!
\qmltype WebEngine
\instantiates QQuickWebEngineSingleton
- \inqmlmodule QtWebEngine 1.1
+ \inqmlmodule QtWebEngine
\since QtWebEngine 1.1
\brief Provides access to the default settings and profiles shared by all web engine views.
diff --git a/src/webengine/api/qquickwebengineview.cpp b/src/webengine/api/qquickwebengineview.cpp
index 4cff0fc8c..61a19faa5 100644
--- a/src/webengine/api/qquickwebengineview.cpp
+++ b/src/webengine/api/qquickwebengineview.cpp
@@ -48,7 +48,6 @@
#include "qquickwebenginenavigationrequest_p.h"
#include "qquickwebenginenewviewrequest_p.h"
#include "qquickwebengineprofile_p.h"
-#include "qquickwebengineprofile_p_p.h"
#include "qquickwebenginesettings_p.h"
#include "qquickwebenginescript_p_p.h"
@@ -74,9 +73,10 @@
#include <QQmlEngine>
#include <QQmlProperty>
#include <QQmlWebChannel>
+#include <QQuickWebEngineProfile>
#include <QScreen>
-#include <QStringBuilder>
#include <QUrl>
+#include <QTimer>
#ifndef QT_NO_ACCESSIBILITY
#include <private/qquickaccessibleattached_p.h>
#endif // QT_NO_ACCESSIBILITY
@@ -105,12 +105,13 @@ QQuickWebEngineViewPrivate::QQuickWebEngineViewPrivate()
#endif
, contextMenuExtraItems(0)
, loadProgress(0)
- , m_isFullScreen(false)
+ , m_fullscreenMode(false)
, isLoading(false)
, m_activeFocusOnPress(true)
, devicePixelRatio(QGuiApplication::primaryScreen()->devicePixelRatio())
, m_dpiScale(1.0)
, m_backgroundColor(Qt::white)
+ , m_webChannel(0)
{
// The gold standard for mobile web content is 160 dpi, and the devicePixelRatio expected
// is the (possibly quantized) ratio of device dpi to 160 dpi.
@@ -178,7 +179,9 @@ bool QQuickWebEngineViewPrivate::contextMenuRequested(const WebEngineContextMenu
{
Q_Q(QQuickWebEngineView);
- QObject *menu = ui()->addMenu(0, QString(), data.pos);
+ // Assign the WebEngineView as the parent of the menu, so mouse events are properly propagated
+ // on OSX.
+ QObject *menu = ui()->addMenu(q, QString(), data.pos);
if (!menu)
return false;
@@ -525,6 +528,11 @@ void QQuickWebEngineViewPrivate::adoptNewWindow(WebContentsAdapter *newWebConten
Q_EMIT q->newViewRequested(&request);
}
+bool QQuickWebEngineViewPrivate::isBeingAdopted()
+{
+ return false;
+}
+
void QQuickWebEngineViewPrivate::close()
{
Q_Q(QQuickWebEngineView);
@@ -548,7 +556,7 @@ void QQuickWebEngineViewPrivate::requestFullScreenMode(const QUrl &origin, bool
bool QQuickWebEngineViewPrivate::isFullScreenMode() const
{
- return m_isFullScreen;
+ return m_fullscreenMode;
}
void QQuickWebEngineViewPrivate::javaScriptConsoleMessage(JavaScriptConsoleMessageLevel level, const QString& message, int lineNumber, const QString& sourceID)
@@ -716,11 +724,6 @@ void QQuickWebEngineViewPrivate::adoptWebContents(WebContentsAdapter *webContent
Q_Q(QQuickWebEngineView);
- // memorize what webChannel we had for the previous adapter
- QQmlWebChannel *qmlWebChannel = NULL;
- if (adapter)
- qmlWebChannel = qobject_cast<QQmlWebChannel *>(adapter->webChannel());
-
// This throws away the WebContentsAdapter that has been used until now.
// All its states, particularly the loading URL, are replaced by the adopted WebContentsAdapter.
WebContentsAdapterOwner *adapterOwner = new WebContentsAdapterOwner(adapter);
@@ -729,8 +732,12 @@ void QQuickWebEngineViewPrivate::adoptWebContents(WebContentsAdapter *webContent
adapter->initialize(this);
// associate the webChannel with the new adapter
- if (qmlWebChannel)
- adapter->setWebChannel(qmlWebChannel);
+ if (m_webChannel)
+ adapter->setWebChannel(m_webChannel);
+
+ // set initial background color if non-default
+ if (m_backgroundColor != Qt::white)
+ adapter->backgroundColorChanged();
// re-bind the userscrips to the new adapter
Q_FOREACH (QQuickWebEngineScript *script, m_userScripts)
@@ -772,6 +779,10 @@ void QQuickWebEngineViewPrivate::ensureContentsAdapter()
if (!adapter) {
adapter = new WebContentsAdapter();
adapter->initialize(this);
+ if (m_backgroundColor != Qt::white)
+ adapter->backgroundColorChanged();
+ if (m_webChannel)
+ adapter->setWebChannel(m_webChannel);
if (explicitUrl.isValid())
adapter->load(explicitUrl);
// push down the page's user scripts
@@ -780,6 +791,16 @@ void QQuickWebEngineViewPrivate::ensureContentsAdapter()
}
}
+void QQuickWebEngineViewPrivate::setFullScreenMode(bool fullscreen)
+{
+ Q_Q(QQuickWebEngineView);
+ if (m_fullscreenMode != fullscreen) {
+ m_fullscreenMode = fullscreen;
+ adapter->changedFullScreen();
+ Q_EMIT q->isFullScreenChanged();
+ }
+}
+
QUrl QQuickWebEngineView::url() const
{
Q_D(const QQuickWebEngineView);
@@ -795,7 +816,7 @@ void QQuickWebEngineView::setUrl(const QUrl& url)
d->explicitUrl = url;
if (d->adapter)
d->adapter->load(url);
- if (!qmlEngine(this))
+ if (!qmlEngine(this) || isComponentComplete())
d->ensureContentsAdapter();
}
@@ -809,7 +830,7 @@ void QQuickWebEngineView::loadHtml(const QString &html, const QUrl &baseUrl)
{
Q_D(QQuickWebEngineView);
d->explicitUrl = QUrl();
- if (!qmlEngine(this))
+ if (!qmlEngine(this) || isComponentComplete())
d->ensureContentsAdapter();
if (d->adapter)
d->adapter->setContent(html.toUtf8(), QStringLiteral("text/html;charset=UTF-8"), baseUrl);
@@ -909,11 +930,8 @@ void QQuickWebEngineViewPrivate::setProfile(QQuickWebEngineProfile *profile)
if (adapter && adapter->browserContext() != browserContextAdapter()->browserContext()) {
// When the profile changes we need to create a new WebContentAdapter and reload the active URL.
QUrl activeUrl = adapter->activeUrl();
- QQmlWebChannel *qmlWebChannel = qobject_cast<QQmlWebChannel *>(adapter->webChannel());
adapter = 0;
ensureContentsAdapter();
- if (qmlWebChannel)
- adapter->setWebChannel(qmlWebChannel);
if (!explicitUrl.isValid() && activeUrl.isValid())
adapter->load(activeUrl);
@@ -1051,8 +1069,7 @@ bool QQuickWebEngineView::canGoForward() const
void QQuickWebEngineView::runJavaScript(const QString &script, const QJSValue &callback)
{
Q_D(QQuickWebEngineView);
- if (!d->adapter)
- return;
+ d->ensureContentsAdapter();
if (!callback.isUndefined()) {
quint64 requestId = d_ptr->adapter->runJavaScriptCallbackResult(script, QQuickWebEngineScript::MainWorld);
d->m_callbacks.insert(requestId, callback);
@@ -1110,8 +1127,8 @@ void QQuickWebEngineView::setBackgroundColor(const QColor &color)
if (color == d->m_backgroundColor)
return;
d->m_backgroundColor = color;
- d->ensureContentsAdapter();
- d->adapter->backgroundColorChanged();
+ if (d->adapter)
+ d->adapter->backgroundColorChanged();
emit backgroundColorChanged();
}
@@ -1145,7 +1162,7 @@ bool QQuickWebEngineView::wasRecentlyAudible()
bool QQuickWebEngineView::isFullScreen() const
{
Q_D(const QQuickWebEngineView);
- return d->m_isFullScreen;
+ return d->m_fullscreenMode;
}
void QQuickWebEngineViewExperimental::setExtraContextMenuEntriesComponent(QQmlComponent *contextMenuExtras)
@@ -1189,23 +1206,24 @@ QQuickWebEngineHistory *QQuickWebEngineView::navigationHistory() const
QQmlWebChannel *QQuickWebEngineView::webChannel()
{
Q_D(QQuickWebEngineView);
- d->ensureContentsAdapter();
- QQmlWebChannel *qmlWebChannel = qobject_cast<QQmlWebChannel *>(d->adapter->webChannel());
- Q_ASSERT(!d->adapter->webChannel() || qmlWebChannel);
- if (!qmlWebChannel) {
- qmlWebChannel = new QQmlWebChannel(this);
- d->adapter->setWebChannel(qmlWebChannel);
+ if (!d->m_webChannel) {
+ d->m_webChannel = new QQmlWebChannel(this);
+ if (d->adapter)
+ d->adapter->setWebChannel(d->m_webChannel);
}
- return qmlWebChannel;
+
+ return d->m_webChannel;
}
void QQuickWebEngineView::setWebChannel(QQmlWebChannel *webChannel)
{
Q_D(QQuickWebEngineView);
- bool notify = (d->adapter->webChannel() == webChannel);
- d->adapter->setWebChannel(webChannel);
- if (notify)
- Q_EMIT webChannelChanged();
+ if (d->m_webChannel == webChannel)
+ return;
+ d->m_webChannel = webChannel;
+ if (d->adapter)
+ d->adapter->setWebChannel(webChannel);
+ Q_EMIT webChannelChanged();
}
void QQuickWebEngineView::grantFeaturePermission(const QUrl &securityOrigin, QQuickWebEngineView::Feature feature, bool granted)
@@ -1263,10 +1281,7 @@ void QQuickWebEngineView::goBackOrForward(int offset)
void QQuickWebEngineView::fullScreenCancelled()
{
Q_D(QQuickWebEngineView);
- if (d->m_isFullScreen) {
- d->m_isFullScreen = false;
- Q_EMIT isFullScreenChanged();
- }
+ d->adapter->exitFullScreen();
}
void QQuickWebEngineView::geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry)
@@ -1543,19 +1558,24 @@ void QQuickWebEngineViewPrivate::userScripts_clear(QQmlListProperty<QQuickWebEng
void QQuickWebEngineView::componentComplete()
{
- Q_D(QQuickWebEngineView);
QQuickItem::componentComplete();
+ QTimer::singleShot(0, this, &QQuickWebEngineView::lazyInitialize);
+}
+
+void QQuickWebEngineView::lazyInitialize()
+{
+ Q_D(QQuickWebEngineView);
d->ensureContentsAdapter();
}
QQuickWebEngineFullScreenRequest::QQuickWebEngineFullScreenRequest()
- : viewPrivate(0)
+ : m_viewPrivate(0)
, m_toggleOn(false)
{
}
QQuickWebEngineFullScreenRequest::QQuickWebEngineFullScreenRequest(QQuickWebEngineViewPrivate *viewPrivate, const QUrl &origin, bool toggleOn)
- : viewPrivate(viewPrivate)
+ : m_viewPrivate(viewPrivate)
, m_origin(origin)
, m_toggleOn(toggleOn)
{
@@ -1563,18 +1583,14 @@ QQuickWebEngineFullScreenRequest::QQuickWebEngineFullScreenRequest(QQuickWebEngi
void QQuickWebEngineFullScreenRequest::accept()
{
- if (viewPrivate && viewPrivate->m_isFullScreen != m_toggleOn) {
- viewPrivate->m_isFullScreen = m_toggleOn;
- viewPrivate->adapter->changedFullScreen();
- Q_EMIT viewPrivate->q_ptr->isFullScreenChanged();
- }
+ if (m_viewPrivate)
+ m_viewPrivate->setFullScreenMode(m_toggleOn);
}
void QQuickWebEngineFullScreenRequest::reject()
{
- if (viewPrivate) {
- viewPrivate->adapter->changedFullScreen();
- }
+ if (m_viewPrivate)
+ m_viewPrivate->setFullScreenMode(!m_toggleOn);
}
QQuickWebEngineViewExperimental::QQuickWebEngineViewExperimental(QQuickWebEngineViewPrivate *viewPrivate)
diff --git a/src/webengine/api/qquickwebengineview_p.h b/src/webengine/api/qquickwebengineview_p.h
index 093b82c60..43cdcb73e 100644
--- a/src/webengine/api/qquickwebengineview_p.h
+++ b/src/webengine/api/qquickwebengineview_p.h
@@ -83,7 +83,7 @@ public:
bool toggleOn() const { return m_toggleOn; }
private:
- QQuickWebEngineViewPrivate *viewPrivate;
+ QQuickWebEngineViewPrivate *m_viewPrivate;
const QUrl m_origin;
const bool m_toggleOn;
};
@@ -301,6 +301,9 @@ public Q_SLOTS:
Q_REVISION(3) void setAudioMuted(bool muted);
Q_REVISION(3) bool wasRecentlyAudible();
+private Q_SLOTS:
+ void lazyInitialize();
+
Q_SIGNALS:
void titleChanged();
void urlChanged();
diff --git a/src/webengine/api/qquickwebengineview_p_p.h b/src/webengine/api/qquickwebengineview_p_p.h
index beb5b49bc..dd20c8972 100644
--- a/src/webengine/api/qquickwebengineview_p_p.h
+++ b/src/webengine/api/qquickwebengineview_p_p.h
@@ -143,6 +143,7 @@ public:
virtual void focusContainer() Q_DECL_OVERRIDE;
virtual void unhandledKeyEvent(QKeyEvent *event) Q_DECL_OVERRIDE;
virtual void adoptNewWindow(QtWebEngineCore::WebContentsAdapter *newWebContents, WindowOpenDisposition disposition, bool userGesture, const QRect &) Q_DECL_OVERRIDE;
+ virtual bool isBeingAdopted() Q_DECL_OVERRIDE;
virtual void close() Q_DECL_OVERRIDE;
virtual void windowCloseRejected() Q_DECL_OVERRIDE;
virtual void requestFullScreenMode(const QUrl &origin, bool fullscreen) Q_DECL_OVERRIDE;
@@ -184,6 +185,7 @@ public:
void adoptWebContents(QtWebEngineCore::WebContentsAdapter *webContents);
void setProfile(QQuickWebEngineProfile *profile);
void ensureContentsAdapter();
+ void setFullScreenMode(bool);
// QQmlListPropertyHelpers
static void userScripts_append(QQmlListProperty<QQuickWebEngineScript> *p, QQuickWebEngineScript *script);
@@ -205,12 +207,13 @@ public:
QUrl explicitUrl;
QUrl icon;
int loadProgress;
- bool m_isFullScreen;
+ bool m_fullscreenMode;
bool isLoading;
bool m_activeFocusOnPress;
qreal devicePixelRatio;
QMap<quint64, QJSValue> m_callbacks;
QList<QSharedPointer<CertificateErrorController> > m_certificateErrorControllers;
+ QQmlWebChannel *m_webChannel;
private:
QScopedPointer<QtWebEngineCore::UIDelegatesManager> m_uIDelegatesManager;
diff --git a/src/webengine/api/qtwebengineglobal.cpp b/src/webengine/api/qtwebengineglobal.cpp
index 07561be6e..8efbc3799 100644
--- a/src/webengine/api/qtwebengineglobal.cpp
+++ b/src/webengine/api/qtwebengineglobal.cpp
@@ -36,15 +36,13 @@
#include "qtwebengineglobal.h"
-#include <QGuiApplication>
-#include <QOpenGLContext>
-#include <QThread>
+namespace QtWebEngineCore
+{
+ extern void initialize();
+}
QT_BEGIN_NAMESPACE
-Q_GUI_EXPORT void qt_gl_set_global_share_context(QOpenGLContext *context);
-Q_GUI_EXPORT QOpenGLContext *qt_gl_global_share_context();
-
namespace QtWebEngine {
/*!
@@ -58,19 +56,6 @@ namespace QtWebEngine {
The \l[CPP]{QtWebEngine} namespace is part of the Qt WebEngine module.
*/
-static QOpenGLContext *shareContext;
-
-static void deleteShareContext()
-{
- delete shareContext;
- shareContext = 0;
-}
-
-// ### Qt 6: unify this logic and Qt::AA_ShareOpenGLContexts.
-// QtWebEngine::initialize was introduced first and meant to be called
-// after the QGuiApplication creation, when AA_ShareOpenGLContexts fills
-// the same need but the flag has to be set earlier.
-
/*!
\fn QtWebEngine::initialize()
@@ -82,34 +67,7 @@ static void deleteShareContext()
*/
void initialize()
{
-#ifdef Q_OS_WIN32
- qputenv("QT_D3DCREATE_MULTITHREADED", "1");
-#endif
-
- // No need to override the shared context if QApplication already set one (e.g with Qt::AA_ShareOpenGLContexts).
- if (qt_gl_global_share_context())
- return;
-
- QCoreApplication *app = QCoreApplication::instance();
- if (!app) {
- qFatal("QtWebEngine::initialize() must be called after the construction of the application object.");
- return;
- }
- if (app->thread() != QThread::currentThread()) {
- qFatal("QtWebEngine::initialize() must be called from the Qt gui thread.");
- return;
- }
-
- if (shareContext)
- return;
-
- shareContext = new QOpenGLContext;
- shareContext->create();
- qAddPostRoutine(deleteShareContext);
- qt_gl_set_global_share_context(shareContext);
-
- // Classes like QOpenGLWidget check for the attribute
- app->setAttribute(Qt::AA_ShareOpenGLContexts);
+ QtWebEngineCore::initialize();
}
} // namespace QtWebEngine