summaryrefslogtreecommitdiffstats
path: root/src/webenginewidgets/api/qwebengineprofile.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/webenginewidgets/api/qwebengineprofile.cpp')
-rw-r--r--src/webenginewidgets/api/qwebengineprofile.cpp137
1 files changed, 77 insertions, 60 deletions
diff --git a/src/webenginewidgets/api/qwebengineprofile.cpp b/src/webenginewidgets/api/qwebengineprofile.cpp
index 1885f2085..537cf41fd 100644
--- a/src/webenginewidgets/api/qwebengineprofile.cpp
+++ b/src/webenginewidgets/api/qwebengineprofile.cpp
@@ -38,29 +38,29 @@
****************************************************************************/
#include "qwebengineprofile.h"
+#include "qwebengineprofile_p.h"
#include "qwebenginecookiestore.h"
#include "qwebenginedownloaditem.h"
#include "qwebenginedownloaditem_p.h"
#include "qwebenginepage.h"
-#include "qwebengineprofile_p.h"
+#include "qwebenginepage_p.h"
#include "qwebenginesettings.h"
#include "qwebenginescriptcollection_p.h"
-
-#include "qwebenginebrowsercontext_p.h"
#include "qtwebenginecoreglobal.h"
-#include "browser_context_adapter.h"
+#include "profile_adapter.h"
#include "visited_links_manager_qt.h"
#include "web_engine_settings.h"
+
QT_BEGIN_NAMESPACE
-ASSERT_ENUMS_MATCH(QWebEngineDownloadItem::UnknownSaveFormat, QtWebEngineCore::BrowserContextAdapterClient::UnknownSavePageFormat)
-ASSERT_ENUMS_MATCH(QWebEngineDownloadItem::SingleHtmlSaveFormat, QtWebEngineCore::BrowserContextAdapterClient::SingleHtmlSaveFormat)
-ASSERT_ENUMS_MATCH(QWebEngineDownloadItem::CompleteHtmlSaveFormat, QtWebEngineCore::BrowserContextAdapterClient::CompleteHtmlSaveFormat)
-ASSERT_ENUMS_MATCH(QWebEngineDownloadItem::MimeHtmlSaveFormat, QtWebEngineCore::BrowserContextAdapterClient::MimeHtmlSaveFormat)
+ASSERT_ENUMS_MATCH(QWebEngineDownloadItem::UnknownSaveFormat, QtWebEngineCore::ProfileAdapterClient::UnknownSavePageFormat)
+ASSERT_ENUMS_MATCH(QWebEngineDownloadItem::SingleHtmlSaveFormat, QtWebEngineCore::ProfileAdapterClient::SingleHtmlSaveFormat)
+ASSERT_ENUMS_MATCH(QWebEngineDownloadItem::CompleteHtmlSaveFormat, QtWebEngineCore::ProfileAdapterClient::CompleteHtmlSaveFormat)
+ASSERT_ENUMS_MATCH(QWebEngineDownloadItem::MimeHtmlSaveFormat, QtWebEngineCore::ProfileAdapterClient::MimeHtmlSaveFormat)
-using QtWebEngineCore::BrowserContextAdapter;
+using QtWebEngineCore::ProfileAdapter;
/*!
\class QWebEngineProfile
@@ -155,32 +155,41 @@ using QtWebEngineCore::BrowserContextAdapter;
\sa QWebEngineDownloadItem, QWebEnginePage::download()
*/
-QWebEngineProfilePrivate::QWebEngineProfilePrivate(QSharedPointer<QtWebEngineCore::BrowserContextAdapter> browserContext)
- : m_settings(new QWebEngineSettings())
- , m_scriptCollection(new QWebEngineScriptCollection(new QWebEngineScriptCollectionPrivate(browserContext->userResourceController())))
- , m_browserContext(new QWebEngineBrowserContext(browserContext, this))
+QWebEngineProfilePrivate::QWebEngineProfilePrivate(ProfileAdapter* profileAdapter)
+ : m_settings(new QWebEngineSettings())
+ , m_profileAdapter(profileAdapter)
+ , m_scriptCollection(new QWebEngineScriptCollection(
+ new QWebEngineScriptCollectionPrivate(profileAdapter->userResourceController())))
{
+ m_profileAdapter->addClient(this);
m_settings->d_ptr->initDefaults();
}
QWebEngineProfilePrivate::~QWebEngineProfilePrivate()
{
- delete m_settings;
- m_settings = 0;
+ if (m_profileAdapter) {
+ // In the case the user sets this profile as the parent of the interceptor
+ // it can be deleted before the browser-context still referencing it is.
+ m_profileAdapter->setRequestInterceptor(nullptr);
+ m_profileAdapter->removeClient(this);
+ }
- Q_FOREACH (QWebEngineDownloadItem* download, m_ongoingDownloads) {
+ for (QWebEngineDownloadItem *download : qAsConst(m_ongoingDownloads)) {
if (download)
download->cancel();
}
m_ongoingDownloads.clear();
- if (m_browserContext)
- m_browserContext->shutdown();
+
+ if (m_profileAdapter != QtWebEngineCore::ProfileAdapter::defaultProfileAdapter())
+ delete m_profileAdapter;
+
+ delete m_settings;
}
-QSharedPointer<QtWebEngineCore::BrowserContextAdapter> QWebEngineProfilePrivate::browserContext() const
+ProfileAdapter* QWebEngineProfilePrivate::profileAdapter() const
{
- return m_browserContext ? m_browserContext->browserContextRef : nullptr;
+ return m_profileAdapter;
}
void QWebEngineProfilePrivate::downloadDestroyed(quint32 downloadId)
@@ -201,6 +210,10 @@ void QWebEngineProfilePrivate::downloadRequested(DownloadItemInfo &info)
itemPrivate->mimeType = info.mimeType;
itemPrivate->savePageFormat = static_cast<QWebEngineDownloadItem::SavePageFormat>(info.savePageFormat);
itemPrivate->type = static_cast<QWebEngineDownloadItem::DownloadType>(info.downloadType);
+ if (info.page && info.page->clientType() == QtWebEngineCore::WebContentsAdapterClient::WidgetsClient)
+ itemPrivate->page = static_cast<QWebEnginePagePrivate *>(info.page)->q_ptr;
+ else
+ itemPrivate->page = nullptr;
QWebEngineDownloadItem *download = new QWebEngineDownloadItem(itemPrivate, q);
@@ -211,7 +224,7 @@ void QWebEngineProfilePrivate::downloadRequested(DownloadItemInfo &info)
QWebEngineDownloadItem::DownloadState state = download->state();
info.path = download->path();
- info.savePageFormat = static_cast<QtWebEngineCore::BrowserContextAdapterClient::SavePageFormat>(
+ info.savePageFormat = static_cast<QtWebEngineCore::ProfileAdapterClient::SavePageFormat>(
download->savePageFormat());
info.accepted = state != QWebEngineDownloadItem::DownloadCancelled;
@@ -252,7 +265,7 @@ void QWebEngineProfilePrivate::downloadUpdated(const DownloadItemInfo &info)
*/
QWebEngineProfile::QWebEngineProfile(QObject *parent)
: QObject(parent)
- , d_ptr(new QWebEngineProfilePrivate(QSharedPointer<BrowserContextAdapter>::create(true)))
+ , d_ptr(new QWebEngineProfilePrivate(new QtWebEngineCore::ProfileAdapter()))
{
d_ptr->q_ptr = this;
}
@@ -269,7 +282,7 @@ QWebEngineProfile::QWebEngineProfile(QObject *parent)
*/
QWebEngineProfile::QWebEngineProfile(const QString &storageName, QObject *parent)
: QObject(parent)
- , d_ptr(new QWebEngineProfilePrivate(QSharedPointer<BrowserContextAdapter>::create(storageName)))
+ , d_ptr(new QWebEngineProfilePrivate(new QtWebEngineCore::ProfileAdapter(storageName)))
{
d_ptr->q_ptr = this;
}
@@ -297,7 +310,7 @@ QWebEngineProfile::~QWebEngineProfile()
QString QWebEngineProfile::storageName() const
{
const Q_D(QWebEngineProfile);
- return d->browserContext()->storageName();
+ return d->profileAdapter()->storageName();
}
/*!
@@ -309,7 +322,7 @@ QString QWebEngineProfile::storageName() const
bool QWebEngineProfile::isOffTheRecord() const
{
const Q_D(QWebEngineProfile);
- return d->browserContext()->isOffTheRecord();
+ return d->profileAdapter()->isOffTheRecord();
}
/*!
@@ -328,7 +341,7 @@ bool QWebEngineProfile::isOffTheRecord() const
QString QWebEngineProfile::persistentStoragePath() const
{
const Q_D(QWebEngineProfile);
- return d->browserContext()->dataPath();
+ return d->profileAdapter()->dataPath();
}
/*!
@@ -341,7 +354,7 @@ QString QWebEngineProfile::persistentStoragePath() const
void QWebEngineProfile::setPersistentStoragePath(const QString &path)
{
const Q_D(QWebEngineProfile);
- d->browserContext()->setDataPath(path);
+ d->profileAdapter()->setDataPath(path);
}
/*!
@@ -358,7 +371,7 @@ void QWebEngineProfile::setPersistentStoragePath(const QString &path)
QString QWebEngineProfile::cachePath() const
{
const Q_D(QWebEngineProfile);
- return d->browserContext()->cachePath();
+ return d->profileAdapter()->cachePath();
}
/*!
@@ -371,7 +384,7 @@ QString QWebEngineProfile::cachePath() const
void QWebEngineProfile::setCachePath(const QString &path)
{
Q_D(QWebEngineProfile);
- d->browserContext()->setCachePath(path);
+ d->profileAdapter()->setCachePath(path);
}
/*!
@@ -386,7 +399,7 @@ void QWebEngineProfile::setCachePath(const QString &path)
QString QWebEngineProfile::httpUserAgent() const
{
const Q_D(QWebEngineProfile);
- return d->browserContext()->httpUserAgent();
+ return d->profileAdapter()->httpUserAgent();
}
/*!
@@ -397,7 +410,7 @@ QString QWebEngineProfile::httpUserAgent() const
void QWebEngineProfile::setHttpUserAgent(const QString &userAgent)
{
Q_D(QWebEngineProfile);
- d->browserContext()->setHttpUserAgent(userAgent);
+ d->profileAdapter()->setHttpUserAgent(userAgent);
}
/*!
@@ -410,7 +423,7 @@ void QWebEngineProfile::setHttpUserAgent(const QString &userAgent)
QWebEngineProfile::HttpCacheType QWebEngineProfile::httpCacheType() const
{
const Q_D(QWebEngineProfile);
- return QWebEngineProfile::HttpCacheType(d->browserContext()->httpCacheType());
+ return QWebEngineProfile::HttpCacheType(d->profileAdapter()->httpCacheType());
}
/*!
@@ -421,7 +434,7 @@ QWebEngineProfile::HttpCacheType QWebEngineProfile::httpCacheType() const
void QWebEngineProfile::setHttpCacheType(QWebEngineProfile::HttpCacheType httpCacheType)
{
Q_D(QWebEngineProfile);
- d->browserContext()->setHttpCacheType(BrowserContextAdapter::HttpCacheType(httpCacheType));
+ d->profileAdapter()->setHttpCacheType(ProfileAdapter::HttpCacheType(httpCacheType));
}
/*!
@@ -432,7 +445,7 @@ void QWebEngineProfile::setHttpCacheType(QWebEngineProfile::HttpCacheType httpCa
void QWebEngineProfile::setHttpAcceptLanguage(const QString &httpAcceptLanguage)
{
Q_D(QWebEngineProfile);
- d->browserContext()->setHttpAcceptLanguage(httpAcceptLanguage);
+ d->profileAdapter()->setHttpAcceptLanguage(httpAcceptLanguage);
}
/*!
@@ -443,7 +456,7 @@ void QWebEngineProfile::setHttpAcceptLanguage(const QString &httpAcceptLanguage)
QString QWebEngineProfile::httpAcceptLanguage() const
{
Q_D(const QWebEngineProfile);
- return d->browserContext()->httpAcceptLanguage();
+ return d->profileAdapter()->httpAcceptLanguage();
}
/*!
@@ -456,7 +469,7 @@ QString QWebEngineProfile::httpAcceptLanguage() const
QWebEngineProfile::PersistentCookiesPolicy QWebEngineProfile::persistentCookiesPolicy() const
{
const Q_D(QWebEngineProfile);
- return QWebEngineProfile::PersistentCookiesPolicy(d->browserContext()->persistentCookiesPolicy());
+ return QWebEngineProfile::PersistentCookiesPolicy(d->profileAdapter()->persistentCookiesPolicy());
}
/*!
@@ -467,7 +480,7 @@ QWebEngineProfile::PersistentCookiesPolicy QWebEngineProfile::persistentCookiesP
void QWebEngineProfile::setPersistentCookiesPolicy(QWebEngineProfile::PersistentCookiesPolicy newPersistentCookiesPolicy)
{
Q_D(QWebEngineProfile);
- d->browserContext()->setPersistentCookiesPolicy(BrowserContextAdapter::PersistentCookiesPolicy(newPersistentCookiesPolicy));
+ d->profileAdapter()->setPersistentCookiesPolicy(ProfileAdapter::PersistentCookiesPolicy(newPersistentCookiesPolicy));
}
/*!
@@ -480,7 +493,7 @@ void QWebEngineProfile::setPersistentCookiesPolicy(QWebEngineProfile::Persistent
int QWebEngineProfile::httpCacheMaximumSize() const
{
const Q_D(QWebEngineProfile);
- return d->browserContext()->httpCacheMaxSize();
+ return d->profileAdapter()->httpCacheMaxSize();
}
/*!
@@ -493,7 +506,7 @@ int QWebEngineProfile::httpCacheMaximumSize() const
void QWebEngineProfile::setHttpCacheMaximumSize(int maxSize)
{
Q_D(QWebEngineProfile);
- d->browserContext()->setHttpCacheMaxSize(maxSize);
+ d->profileAdapter()->setHttpCacheMaxSize(maxSize);
}
/*!
@@ -505,7 +518,7 @@ void QWebEngineProfile::setHttpCacheMaximumSize(int maxSize)
QWebEngineCookieStore* QWebEngineProfile::cookieStore()
{
Q_D(QWebEngineProfile);
- return d->browserContext()->cookieStore();
+ return d->profileAdapter()->cookieStore();
}
@@ -521,7 +534,7 @@ QWebEngineCookieStore* QWebEngineProfile::cookieStore()
void QWebEngineProfile::setRequestInterceptor(QWebEngineUrlRequestInterceptor *interceptor)
{
Q_D(QWebEngineProfile);
- d->browserContext()->setRequestInterceptor(interceptor);
+ d->profileAdapter()->setRequestInterceptor(interceptor);
}
/*!
@@ -532,7 +545,7 @@ void QWebEngineProfile::setRequestInterceptor(QWebEngineUrlRequestInterceptor *i
void QWebEngineProfile::clearAllVisitedLinks()
{
Q_D(QWebEngineProfile);
- d->browserContext()->visitedLinksManager()->deleteAllVisitedLinkData();
+ d->profileAdapter()->visitedLinksManager()->deleteAllVisitedLinkData();
}
/*!
@@ -543,7 +556,7 @@ void QWebEngineProfile::clearAllVisitedLinks()
void QWebEngineProfile::clearVisitedLinks(const QList<QUrl> &urls)
{
Q_D(QWebEngineProfile);
- d->browserContext()->visitedLinksManager()->deleteVisitedLinkDataForUrls(urls);
+ d->profileAdapter()->visitedLinksManager()->deleteVisitedLinkDataForUrls(urls);
}
/*!
@@ -552,7 +565,7 @@ void QWebEngineProfile::clearVisitedLinks(const QList<QUrl> &urls)
bool QWebEngineProfile::visitedLinksContainsUrl(const QUrl &url) const
{
Q_D(const QWebEngineProfile);
- return d->browserContext()->visitedLinksManager()->containsUrl(url);
+ return d->profileAdapter()->visitedLinksManager()->containsUrl(url);
}
/*!
@@ -577,8 +590,8 @@ QWebEngineScriptCollection *QWebEngineProfile::scripts() const
QWebEngineProfile *QWebEngineProfile::defaultProfile()
{
static QWebEngineProfile* profile = new QWebEngineProfile(
- new QWebEngineProfilePrivate(BrowserContextAdapter::defaultContext()),
- BrowserContextAdapter::globalQObjectRoot());
+ new QWebEngineProfilePrivate(ProfileAdapter::createDefaultProfileAdapter()),
+ ProfileAdapter::globalQObjectRoot());
return profile;
}
@@ -600,7 +613,7 @@ QWebEngineProfile *QWebEngineProfile::defaultProfile()
void QWebEngineProfile::setSpellCheckLanguages(const QStringList &languages)
{
Q_D(QWebEngineProfile);
- d->browserContext()->setSpellCheckLanguages(languages);
+ d->profileAdapter()->setSpellCheckLanguages(languages);
}
/*!
@@ -611,7 +624,7 @@ void QWebEngineProfile::setSpellCheckLanguages(const QStringList &languages)
QStringList QWebEngineProfile::spellCheckLanguages() const
{
const Q_D(QWebEngineProfile);
- return d->browserContext()->spellCheckLanguages();
+ return d->profileAdapter()->spellCheckLanguages();
}
/*!
@@ -623,7 +636,7 @@ QStringList QWebEngineProfile::spellCheckLanguages() const
void QWebEngineProfile::setSpellCheckEnabled(bool enable)
{
Q_D(QWebEngineProfile);
- d->browserContext()->setSpellCheckEnabled(enable);
+ d->profileAdapter()->setSpellCheckEnabled(enable);
}
/*!
\since 5.8
@@ -634,7 +647,7 @@ void QWebEngineProfile::setSpellCheckEnabled(bool enable)
bool QWebEngineProfile::isSpellCheckEnabled() const
{
const Q_D(QWebEngineProfile);
- return d->browserContext()->isSpellCheckEnabled();
+ return d->profileAdapter()->isSpellCheckEnabled();
}
/*!
@@ -654,8 +667,8 @@ QWebEngineSettings *QWebEngineProfile::settings() const
const QWebEngineUrlSchemeHandler *QWebEngineProfile::urlSchemeHandler(const QByteArray &scheme) const
{
const Q_D(QWebEngineProfile);
- if (d->browserContext()->customUrlSchemeHandlers().contains(scheme))
- return d->browserContext()->customUrlSchemeHandlers().value(scheme);
+ if (d->profileAdapter()->customUrlSchemeHandlers().contains(scheme))
+ return d->profileAdapter()->customUrlSchemeHandlers().value(scheme);
return 0;
}
@@ -674,22 +687,26 @@ static bool checkInternalScheme(const QByteArray &scheme)
\since 5.6
Registers a handler \a handler for custom URL scheme \a scheme in the profile.
+
+ It is recommended to first register the scheme with \l
+ QWebEngineUrlScheme::registerScheme at application startup.
*/
void QWebEngineProfile::installUrlSchemeHandler(const QByteArray &scheme, QWebEngineUrlSchemeHandler *handler)
{
Q_D(QWebEngineProfile);
Q_ASSERT(handler);
- if (checkInternalScheme(scheme)) {
+ QByteArray canonicalScheme = scheme.toLower();
+ if (checkInternalScheme(canonicalScheme)) {
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)
+ if (d->profileAdapter()->customUrlSchemeHandlers().contains(canonicalScheme)) {
+ if (d->profileAdapter()->customUrlSchemeHandlers().value(canonicalScheme) != handler)
qWarning("URL scheme handler already installed for the scheme: %s", scheme.constData());
return;
}
- d->browserContext()->addCustomUrlSchemeHandler(scheme, handler);
+ d->profileAdapter()->addCustomUrlSchemeHandler(canonicalScheme, handler);
connect(handler, SIGNAL(_q_destroyedUrlSchemeHandler(QWebEngineUrlSchemeHandler*)), this, SLOT(destroyedUrlSchemeHandler(QWebEngineUrlSchemeHandler*)));
}
@@ -704,7 +721,7 @@ void QWebEngineProfile::removeUrlSchemeHandler(QWebEngineUrlSchemeHandler *handl
{
Q_D(QWebEngineProfile);
Q_ASSERT(handler);
- if (!d->browserContext()->removeCustomUrlSchemeHandler(handler))
+ if (!d->profileAdapter()->removeCustomUrlSchemeHandler(handler))
return;
disconnect(handler, SIGNAL(_q_destroyedUrlSchemeHandler(QWebEngineUrlSchemeHandler*)), this, SLOT(destroyedUrlSchemeHandler(QWebEngineUrlSchemeHandler*)));
}
@@ -719,7 +736,7 @@ void QWebEngineProfile::removeUrlSchemeHandler(QWebEngineUrlSchemeHandler *handl
void QWebEngineProfile::removeUrlScheme(const QByteArray &scheme)
{
Q_D(QWebEngineProfile);
- QWebEngineUrlSchemeHandler *handler = d->browserContext()->takeCustomUrlSchemeHandler(scheme);
+ QWebEngineUrlSchemeHandler *handler = d->profileAdapter()->takeCustomUrlSchemeHandler(scheme);
if (!handler)
return;
disconnect(handler, SIGNAL(_q_destroyedUrlSchemeHandler(QWebEngineUrlSchemeHandler*)), this, SLOT(destroyedUrlSchemeHandler(QWebEngineUrlSchemeHandler*)));
@@ -733,7 +750,7 @@ void QWebEngineProfile::removeUrlScheme(const QByteArray &scheme)
void QWebEngineProfile::removeAllUrlSchemeHandlers()
{
Q_D(QWebEngineProfile);
- d->browserContext()->clearCustomUrlSchemeHandlers();
+ d->profileAdapter()->clearCustomUrlSchemeHandlers();
}
void QWebEngineProfile::destroyedUrlSchemeHandler(QWebEngineUrlSchemeHandler *obj)
@@ -749,7 +766,7 @@ void QWebEngineProfile::destroyedUrlSchemeHandler(QWebEngineUrlSchemeHandler *ob
void QWebEngineProfile::clearHttpCache()
{
Q_D(QWebEngineProfile);
- d->browserContext()->clearHttpCache();
+ d->profileAdapter()->clearHttpCache();
}
QT_END_NAMESPACE