diff options
Diffstat (limited to 'src/core/api')
-rw-r--r-- | src/core/api/core_api.pro | 16 | ||||
-rw-r--r-- | src/core/api/qtwebenginecoreglobal.cpp | 2 | ||||
-rw-r--r-- | src/core/api/qtwebenginecoreglobal.h | 5 | ||||
-rw-r--r-- | src/core/api/qtwebenginecoreglobal_p.h | 6 | ||||
-rw-r--r-- | src/core/api/qwebenginebrowsercontext.cpp | 73 | ||||
-rw-r--r-- | src/core/api/qwebenginecookiestore.cpp | 42 | ||||
-rw-r--r-- | src/core/api/qwebenginecookiestore.h | 6 | ||||
-rw-r--r-- | src/core/api/qwebenginecookiestore_p.h | 4 | ||||
-rw-r--r-- | src/core/api/qwebenginehttprequest.h | 2 | ||||
-rw-r--r-- | src/core/api/qwebenginequotarequest.h | 2 | ||||
-rw-r--r-- | src/core/api/qwebengineregisterprotocolhandlerrequest.h | 2 | ||||
-rw-r--r-- | src/core/api/qwebengineurlrequestinfo.cpp | 33 | ||||
-rw-r--r-- | src/core/api/qwebengineurlrequestinfo.h | 2 | ||||
-rw-r--r-- | src/core/api/qwebengineurlrequestinterceptor.h | 2 | ||||
-rw-r--r-- | src/core/api/qwebengineurlrequestjob.h | 2 | ||||
-rw-r--r-- | src/core/api/qwebengineurlscheme.cpp | 375 | ||||
-rw-r--r-- | src/core/api/qwebengineurlscheme.h (renamed from src/core/api/qwebenginebrowsercontext_p.h) | 98 | ||||
-rw-r--r-- | src/core/api/qwebengineurlschemehandler.h | 2 |
18 files changed, 500 insertions, 174 deletions
diff --git a/src/core/api/core_api.pro b/src/core/api/core_api.pro index 632034a9d..38dc6b39d 100644 --- a/src/core/api/core_api.pro +++ b/src/core/api/core_api.pro @@ -3,9 +3,8 @@ DESTDIR = $$OUT_PWD/$$getConfigDir() TEMPLATE = lib -CONFIG += staticlib c++14 -QT += network core-private -QT_PRIVATE += webenginecoreheaders-private +CONFIG += staticlib +QT += network core-private webenginecoreheaders-private # Don't create .prl file for this intermediate library because # their contents get used when linking against them, breaking @@ -23,17 +22,18 @@ DEFINES += \ NOMINMAX CHROMIUM_SRC_DIR = $$QTWEBENGINE_ROOT/$$getChromiumSrcDir() +CHROMIUM_GEN_DIR = $$OUT_PWD/../$$getConfigDir()/gen INCLUDEPATH += $$QTWEBENGINE_ROOT/src/core \ + $$CHROMIUM_GEN_DIR \ $$CHROMIUM_SRC_DIR -linux-g++*: QMAKE_CXXFLAGS += -Wno-unused-parameter +gcc: QMAKE_CXXFLAGS_WARN_ON = -Wno-unused-parameter HEADERS = \ qwebenginecallback.h \ qwebenginecallback_p.h \ qtwebenginecoreglobal.h \ qtwebenginecoreglobal_p.h \ - qwebenginebrowsercontext_p.h \ qwebenginecookiestore.h \ qwebenginecookiestore_p.h \ qwebenginehttprequest.h \ @@ -43,21 +43,23 @@ HEADERS = \ qwebengineurlrequestinfo.h \ qwebengineurlrequestinfo_p.h \ qwebengineurlrequestjob.h \ + qwebengineurlscheme.h \ qwebengineurlschemehandler.h SOURCES = \ qtwebenginecoreglobal.cpp \ - qwebenginebrowsercontext.cpp \ qwebenginecookiestore.cpp \ qwebenginehttprequest.cpp \ qwebenginequotarequest.cpp \ qwebengineregisterprotocolhandlerrequest.cpp \ qwebengineurlrequestinfo.cpp \ qwebengineurlrequestjob.cpp \ + qwebengineurlscheme.cpp \ qwebengineurlschemehandler.cpp ### Qt6 Remove this workaround unix:!isEmpty(QMAKE_LFLAGS_VERSION_SCRIPT):!static { + CONFIG -= warning_clean SOURCES += qtbug-60565.cpp \ qtbug-61521.cpp } @@ -69,3 +71,5 @@ msvc { "if exist $(DESTDIR_TARGET).objects del $(DESTDIR_TARGET).objects$$escape_expand(\\n\\t)" \ "for %%a in ($(OBJECTS)) do echo $$shell_quote($$shell_path($$OUT_PWD))\\%%a >> $(DESTDIR_TARGET).objects" } + +load(qt_common) diff --git a/src/core/api/qtwebenginecoreglobal.cpp b/src/core/api/qtwebenginecoreglobal.cpp index 4bb69ac21..a415ade92 100644 --- a/src/core/api/qtwebenginecoreglobal.cpp +++ b/src/core/api/qtwebenginecoreglobal.cpp @@ -89,7 +89,7 @@ static void deleteShareContext() // after the QGuiApplication creation, when AA_ShareOpenGLContexts fills // the same need but the flag has to be set earlier. -QWEBENGINE_PRIVATE_EXPORT void initialize() +QWEBENGINECORE_PRIVATE_EXPORT void initialize() { #ifndef QT_NO_OPENGL #ifdef Q_OS_WIN32 diff --git a/src/core/api/qtwebenginecoreglobal.h b/src/core/api/qtwebenginecoreglobal.h index 012c5d4f0..bcff622b7 100644 --- a/src/core/api/qtwebenginecoreglobal.h +++ b/src/core/api/qtwebenginecoreglobal.h @@ -41,13 +41,14 @@ #define QTWEBENGINECOREGLOBAL_H #include <QtCore/qglobal.h> +#include <QtWebEngineCore/qtwebenginecore-config.h> QT_BEGIN_NAMESPACE #if defined(BUILDING_CHROMIUM) -# define QWEBENGINE_EXPORT Q_DECL_EXPORT +# define QWEBENGINECORE_EXPORT Q_DECL_EXPORT #else -# define QWEBENGINE_EXPORT Q_DECL_IMPORT +# define QWEBENGINECORE_EXPORT Q_DECL_IMPORT #endif #define ASSERT_ENUMS_MATCH(A, B) Q_STATIC_ASSERT_X(static_cast<int>(A) == static_cast<int>(B), "The enum values must match"); diff --git a/src/core/api/qtwebenginecoreglobal_p.h b/src/core/api/qtwebenginecoreglobal_p.h index 0a6ae3f91..27bf2d9f9 100644 --- a/src/core/api/qtwebenginecoreglobal_p.h +++ b/src/core/api/qtwebenginecoreglobal_p.h @@ -51,7 +51,9 @@ // We mean it. // -#include "qtwebenginecoreglobal.h" +#include <QtWebEngineCore/qtwebenginecoreglobal.h> +#include <QtCore/private/qglobal_p.h> +#include <QtWebEngineCore/private/qtwebenginecore-config_p.h> #ifdef QT_WEBENGINE_LOGGING #define QT_NOT_YET_IMPLEMENTED fprintf(stderr, "function %s not implemented! - %s:%d\n", __func__, __FILE__, __LINE__); @@ -61,6 +63,6 @@ #define QT_NOT_USED Q_UNREACHABLE(); // This will assert in debug. #endif -#define QWEBENGINE_PRIVATE_EXPORT QWEBENGINE_EXPORT +#define QWEBENGINECORE_PRIVATE_EXPORT QWEBENGINECORE_EXPORT #endif // QTWEBENGINECOREGLOBAL_P_H diff --git a/src/core/api/qwebenginebrowsercontext.cpp b/src/core/api/qwebenginebrowsercontext.cpp deleted file mode 100644 index c3ab16460..000000000 --- a/src/core/api/qwebenginebrowsercontext.cpp +++ /dev/null @@ -1,73 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2018 The Qt Company Ltd. -** Contact: https://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 https://www.qt.io/terms-conditions. For further -** information use the contact form at https://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.LGPL3 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-3.0.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 (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "qwebenginebrowsercontext_p.h" - -#include "browser_context_adapter.h" -#include <qtwebenginecoreglobal.h> - -QT_BEGIN_NAMESPACE - -QWebEngineBrowserContext::QWebEngineBrowserContext(QSharedPointer<QtWebEngineCore::BrowserContextAdapter> browserContext, - QtWebEngineCore::BrowserContextAdapterClient *profile) - : QObject(QtWebEngineCore::BrowserContextAdapter::globalQObjectRoot()) - , browserContextRef(browserContext) - , m_profile(profile) -{ - browserContextRef->addClient(m_profile); -} - -QWebEngineBrowserContext::~QWebEngineBrowserContext() -{ - if (m_profile) - shutdown(); -} - -void QWebEngineBrowserContext::shutdown() -{ - Q_ASSERT(m_profile); - // 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. - browserContextRef->setRequestInterceptor(nullptr); - browserContextRef->removeClient(m_profile); - m_profile = 0; - deleteLater(); -} - -QT_END_NAMESPACE diff --git a/src/core/api/qwebenginecookiestore.cpp b/src/core/api/qwebenginecookiestore.cpp index fa72265dc..035c98342 100644 --- a/src/core/api/qwebenginecookiestore.cpp +++ b/src/core/api/qwebenginecookiestore.cpp @@ -94,7 +94,7 @@ void QWebEngineCookieStorePrivate::processPendingUserCookies() if (m_pendingUserCookies.isEmpty()) return; - Q_FOREACH (const auto &cookieData, m_pendingUserCookies) { + for (const CookieData &cookieData : qAsConst(m_pendingUserCookies)) { if (cookieData.callbackId == CallbackDirectory::DeleteCookieCallbackId) delegate->deleteCookie(cookieData.cookie, cookieData.origin); else @@ -184,14 +184,13 @@ void QWebEngineCookieStorePrivate::onDeleteCallbackResult(qint64 callbackId, int void QWebEngineCookieStorePrivate::onCookieChanged(const QNetworkCookie &cookie, bool removed) { - Q_Q(QWebEngineCookieStore); if (removed) - Q_EMIT q->cookieRemoved(cookie); + Q_EMIT q_ptr->cookieRemoved(cookie); else - Q_EMIT q->cookieAdded(cookie); + Q_EMIT q_ptr->cookieAdded(cookie); } -bool QWebEngineCookieStorePrivate::canAccessCookies(const QUrl &firstPartyUrl, const QUrl &url) +bool QWebEngineCookieStorePrivate::canAccessCookies(const QUrl &firstPartyUrl, const QUrl &url) const { if (!filterCallback) return true; @@ -269,8 +268,7 @@ QWebEngineCookieStore::~QWebEngineCookieStore() void QWebEngineCookieStore::setCookie(const QNetworkCookie &cookie, const QUrl &origin) { //TODO: use callbacks or delete dummy ones - Q_D(QWebEngineCookieStore); - d->setCookie(QWebEngineCallback<bool>(), cookie, origin); + d_ptr->setCookie(QWebEngineCallback<bool>(), cookie, origin); } /*! @@ -283,8 +281,7 @@ void QWebEngineCookieStore::setCookie(const QNetworkCookie &cookie, const QUrl & void QWebEngineCookieStore::deleteCookie(const QNetworkCookie &cookie, const QUrl &origin) { - Q_D(QWebEngineCookieStore); - d->deleteCookie(cookie, origin); + d_ptr->deleteCookie(cookie, origin); } /*! @@ -299,12 +296,11 @@ void QWebEngineCookieStore::deleteCookie(const QNetworkCookie &cookie, const QUr void QWebEngineCookieStore::loadAllCookies() { //TODO: use callbacks or delete dummy ones - Q_D(QWebEngineCookieStore); - if (d->m_getAllCookiesPending) + if (d_ptr->m_getAllCookiesPending) return; - d->callbackDirectory.registerCallback(CallbackDirectory::GetAllCookiesCallbackId, QWebEngineCallback<const QByteArray&>()); + d_ptr->callbackDirectory.registerCallback(CallbackDirectory::GetAllCookiesCallbackId, QWebEngineCallback<const QByteArray&>()); //this will trigger cookieAdded signal - d->getAllCookies(); + d_ptr->getAllCookies(); } /*! @@ -318,11 +314,10 @@ void QWebEngineCookieStore::loadAllCookies() void QWebEngineCookieStore::deleteSessionCookies() { //TODO: use callbacks or delete dummy ones - Q_D(QWebEngineCookieStore); - if (d->m_deleteAllCookiesPending || d->m_deleteSessionCookiesPending) + if (d_ptr->m_deleteAllCookiesPending || d_ptr->m_deleteSessionCookiesPending) return; - d->callbackDirectory.registerCallback(CallbackDirectory::DeleteSessionCookiesCallbackId, QWebEngineCallback<int>()); - d->deleteSessionCookies(); + d_ptr->callbackDirectory.registerCallback(CallbackDirectory::DeleteSessionCookiesCallbackId, QWebEngineCallback<int>()); + d_ptr->deleteSessionCookies(); } /*! @@ -334,11 +329,10 @@ void QWebEngineCookieStore::deleteSessionCookies() void QWebEngineCookieStore::deleteAllCookies() { //TODO: use callbacks or delete dummy ones - Q_D(QWebEngineCookieStore); - if (d->m_deleteAllCookiesPending) + if (d_ptr->m_deleteAllCookiesPending) return; - d->callbackDirectory.registerCallback(CallbackDirectory::DeleteAllCookiesCallbackId, QWebEngineCallback<int>()); - d->deleteAllCookies(); + d_ptr->callbackDirectory.registerCallback(CallbackDirectory::DeleteAllCookiesCallbackId, QWebEngineCallback<int>()); + d_ptr->deleteAllCookies(); } /*! @@ -371,8 +365,7 @@ void QWebEngineCookieStore::deleteAllCookies() */ void QWebEngineCookieStore::setCookieFilter(const std::function<bool(const FilterRequest &)> &filterCallback) { - Q_D(QWebEngineCookieStore); - d->filterCallback = filterCallback; + d_ptr->filterCallback = filterCallback; } /*! @@ -381,8 +374,7 @@ void QWebEngineCookieStore::setCookieFilter(const std::function<bool(const Filte */ void QWebEngineCookieStore::setCookieFilter(std::function<bool(const FilterRequest &)> &&filterCallback) { - Q_D(QWebEngineCookieStore); - d->filterCallback = std::move(filterCallback); + d_ptr->filterCallback = std::move(filterCallback); } /*! diff --git a/src/core/api/qwebenginecookiestore.h b/src/core/api/qwebenginecookiestore.h index 87d7390a3..89e72dfb0 100644 --- a/src/core/api/qwebenginecookiestore.h +++ b/src/core/api/qwebenginecookiestore.h @@ -50,14 +50,14 @@ #include <functional> namespace QtWebEngineCore { -class BrowserContextAdapter; +class ProfileAdapter; class CookieMonsterDelegateQt; } QT_BEGIN_NAMESPACE class QWebEngineCookieStorePrivate; -class QWEBENGINE_EXPORT QWebEngineCookieStore : public QObject { +class QWEBENGINECORE_EXPORT QWebEngineCookieStore : public QObject { Q_OBJECT public: @@ -84,7 +84,7 @@ Q_SIGNALS: private: explicit QWebEngineCookieStore(QObject *parent = Q_NULLPTR); - friend class QtWebEngineCore::BrowserContextAdapter; + friend class QtWebEngineCore::ProfileAdapter; friend class QtWebEngineCore::CookieMonsterDelegateQt; Q_DISABLE_COPY(QWebEngineCookieStore) Q_DECLARE_PRIVATE(QWebEngineCookieStore) diff --git a/src/core/api/qwebenginecookiestore_p.h b/src/core/api/qwebenginecookiestore_p.h index e44a80f53..93198d8ed 100644 --- a/src/core/api/qwebenginecookiestore_p.h +++ b/src/core/api/qwebenginecookiestore_p.h @@ -66,7 +66,7 @@ class CookieMonsterDelegateQt; QT_BEGIN_NAMESPACE -class QWEBENGINE_PRIVATE_EXPORT QWebEngineCookieStorePrivate +class QWEBENGINECORE_PRIVATE_EXPORT QWebEngineCookieStorePrivate { Q_DECLARE_PUBLIC(QWebEngineCookieStore) struct CookieData { @@ -97,7 +97,7 @@ public: void deleteAllCookies(); void getAllCookies(); - bool canAccessCookies(const QUrl &firstPartyUrl, const QUrl &url); + bool canAccessCookies(const QUrl &firstPartyUrl, const QUrl &url) const; void onGetAllCallbackResult(qint64 callbackId, const QByteArray &cookieList); void onSetCallbackResult(qint64 callbackId, bool success); diff --git a/src/core/api/qwebenginehttprequest.h b/src/core/api/qwebenginehttprequest.h index 5b5948ba1..c6b5a6b63 100644 --- a/src/core/api/qwebenginehttprequest.h +++ b/src/core/api/qwebenginehttprequest.h @@ -52,7 +52,7 @@ QT_BEGIN_NAMESPACE class QWebEngineHttpRequestPrivate; -class QWEBENGINE_EXPORT QWebEngineHttpRequest +class QWEBENGINECORE_EXPORT QWebEngineHttpRequest { public: enum Method { diff --git a/src/core/api/qwebenginequotarequest.h b/src/core/api/qwebenginequotarequest.h index be71635c1..a759f5bb6 100644 --- a/src/core/api/qwebenginequotarequest.h +++ b/src/core/api/qwebenginequotarequest.h @@ -51,7 +51,7 @@ class QuotaRequestController; QT_BEGIN_NAMESPACE -class QWEBENGINE_EXPORT QWebEngineQuotaRequest { +class QWEBENGINECORE_EXPORT QWebEngineQuotaRequest { Q_GADGET Q_PROPERTY(QUrl origin READ origin CONSTANT FINAL) Q_PROPERTY(qint64 requestedSize READ requestedSize CONSTANT FINAL) diff --git a/src/core/api/qwebengineregisterprotocolhandlerrequest.h b/src/core/api/qwebengineregisterprotocolhandlerrequest.h index b3707bc59..12b1d6edf 100644 --- a/src/core/api/qwebengineregisterprotocolhandlerrequest.h +++ b/src/core/api/qwebengineregisterprotocolhandlerrequest.h @@ -51,7 +51,7 @@ class WebContentsDelegateQt; QT_BEGIN_NAMESPACE -class QWEBENGINE_EXPORT QWebEngineRegisterProtocolHandlerRequest { +class QWEBENGINECORE_EXPORT QWebEngineRegisterProtocolHandlerRequest { Q_GADGET Q_PROPERTY(QUrl origin READ origin CONSTANT FINAL) Q_PROPERTY(QString scheme READ scheme CONSTANT FINAL) diff --git a/src/core/api/qwebengineurlrequestinfo.cpp b/src/core/api/qwebengineurlrequestinfo.cpp index e6972932e..2bb870071 100644 --- a/src/core/api/qwebengineurlrequestinfo.cpp +++ b/src/core/api/qwebengineurlrequestinfo.cpp @@ -192,8 +192,7 @@ QWebEngineUrlRequestInfo::QWebEngineUrlRequestInfo(QWebEngineUrlRequestInfoPriva QWebEngineUrlRequestInfo::ResourceType QWebEngineUrlRequestInfo::resourceType() const { - Q_D(const QWebEngineUrlRequestInfo); - return d->resourceType; + return d_ptr->resourceType; } /*! @@ -217,8 +216,7 @@ QWebEngineUrlRequestInfo::ResourceType QWebEngineUrlRequestInfo::resourceType() QWebEngineUrlRequestInfo::NavigationType QWebEngineUrlRequestInfo::navigationType() const { - Q_D(const QWebEngineUrlRequestInfo); - return d->navigationType; + return d_ptr->navigationType; } /*! @@ -227,8 +225,7 @@ QWebEngineUrlRequestInfo::NavigationType QWebEngineUrlRequestInfo::navigationTyp QUrl QWebEngineUrlRequestInfo::requestUrl() const { - Q_D(const QWebEngineUrlRequestInfo); - return d->url; + return d_ptr->url; } /*! @@ -238,8 +235,7 @@ QUrl QWebEngineUrlRequestInfo::requestUrl() const QUrl QWebEngineUrlRequestInfo::firstPartyUrl() const { - Q_D(const QWebEngineUrlRequestInfo); - return d->firstPartyUrl; + return d_ptr->firstPartyUrl; } @@ -249,8 +245,7 @@ QUrl QWebEngineUrlRequestInfo::firstPartyUrl() const QByteArray QWebEngineUrlRequestInfo::requestMethod() const { - Q_D(const QWebEngineUrlRequestInfo); - return d->method; + return d_ptr->method; } /*! @@ -258,8 +253,7 @@ QByteArray QWebEngineUrlRequestInfo::requestMethod() const */ bool QWebEngineUrlRequestInfo::changed() const { - Q_D(const QWebEngineUrlRequestInfo); - return d->changed; + return d_ptr->changed; } /*! @@ -269,9 +263,8 @@ bool QWebEngineUrlRequestInfo::changed() const void QWebEngineUrlRequestInfo::redirect(const QUrl &url) { - Q_D(QWebEngineUrlRequestInfo); - d->changed = true; - d->url = url; + d_ptr->changed = true; + d_ptr->url = url; } /*! @@ -282,9 +275,8 @@ void QWebEngineUrlRequestInfo::redirect(const QUrl &url) void QWebEngineUrlRequestInfo::block(bool shouldBlock) { - Q_D(QWebEngineUrlRequestInfo); - d->changed = true; - d->shouldBlockRequest = shouldBlock; + d_ptr->changed = true; + d_ptr->shouldBlockRequest = shouldBlock; } /*! @@ -293,9 +285,8 @@ void QWebEngineUrlRequestInfo::block(bool shouldBlock) void QWebEngineUrlRequestInfo::setHttpHeader(const QByteArray &name, const QByteArray &value) { - Q_D(QWebEngineUrlRequestInfo); - d->changed = true; - d->extraHeaders.insert(name, value); + d_ptr->changed = true; + d_ptr->extraHeaders.insert(name, value); } QT_END_NAMESPACE diff --git a/src/core/api/qwebengineurlrequestinfo.h b/src/core/api/qwebengineurlrequestinfo.h index 52463a1b3..68c46dcf4 100644 --- a/src/core/api/qwebengineurlrequestinfo.h +++ b/src/core/api/qwebengineurlrequestinfo.h @@ -53,7 +53,7 @@ QT_BEGIN_NAMESPACE class QWebEngineUrlRequestInfoPrivate; -class QWEBENGINE_EXPORT QWebEngineUrlRequestInfo { +class QWEBENGINECORE_EXPORT QWebEngineUrlRequestInfo { public: enum ResourceType { ResourceTypeMainFrame = 0, // top level page diff --git a/src/core/api/qwebengineurlrequestinterceptor.h b/src/core/api/qwebengineurlrequestinterceptor.h index 6e0f93e49..dc2a15ee3 100644 --- a/src/core/api/qwebengineurlrequestinterceptor.h +++ b/src/core/api/qwebengineurlrequestinterceptor.h @@ -50,7 +50,7 @@ QT_BEGIN_NAMESPACE -class QWEBENGINE_EXPORT QWebEngineUrlRequestInterceptor : public QObject +class QWEBENGINECORE_EXPORT QWebEngineUrlRequestInterceptor : public QObject { Q_OBJECT Q_DISABLE_COPY(QWebEngineUrlRequestInterceptor) diff --git a/src/core/api/qwebengineurlrequestjob.h b/src/core/api/qwebengineurlrequestjob.h index 7a7dbd83d..7ce8be7ec 100644 --- a/src/core/api/qwebengineurlrequestjob.h +++ b/src/core/api/qwebengineurlrequestjob.h @@ -55,7 +55,7 @@ QT_BEGIN_NAMESPACE class QIODevice; -class QWEBENGINE_EXPORT QWebEngineUrlRequestJob : public QObject { +class QWEBENGINECORE_EXPORT QWebEngineUrlRequestJob : public QObject { Q_OBJECT public: ~QWebEngineUrlRequestJob(); diff --git a/src/core/api/qwebengineurlscheme.cpp b/src/core/api/qwebengineurlscheme.cpp new file mode 100644 index 000000000..f36f3335b --- /dev/null +++ b/src/core/api/qwebengineurlscheme.cpp @@ -0,0 +1,375 @@ +/**************************************************************************** +** +** Copyright (C) 2018 The Qt Company Ltd. +** Contact: https://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 https://www.qt.io/terms-conditions. For further +** information use the contact form at https://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.LGPL3 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-3.0.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 (at your option) the GNU General +** Public license version 3 or any later version approved by the KDE Free +** Qt Foundation. The licenses are as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-2.0.html and +** https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qwebengineurlscheme.h" + +#include <url/url_util_qt.h> + +QT_BEGIN_NAMESPACE + +ASSERT_ENUMS_MATCH(QWebEngineUrlScheme::Syntax::Path, url::SCHEME_WITHOUT_AUTHORITY) +ASSERT_ENUMS_MATCH(QWebEngineUrlScheme::Syntax::Host, url::SCHEME_WITH_HOST) +ASSERT_ENUMS_MATCH(QWebEngineUrlScheme::Syntax::HostAndPort, url::SCHEME_WITH_HOST_AND_PORT) +ASSERT_ENUMS_MATCH(QWebEngineUrlScheme::Syntax::HostPortAndUserInformation, + url::SCHEME_WITH_HOST_PORT_AND_USER_INFORMATION) + +ASSERT_ENUMS_MATCH(QWebEngineUrlScheme::PortUnspecified, url::PORT_UNSPECIFIED) + +ASSERT_ENUMS_MATCH(QWebEngineUrlScheme::SecureScheme, url::CustomScheme::Secure) +ASSERT_ENUMS_MATCH(QWebEngineUrlScheme::LocalScheme, url::CustomScheme::Local) +ASSERT_ENUMS_MATCH(QWebEngineUrlScheme::LocalAccessAllowed, url::CustomScheme::LocalAccessAllowed) +ASSERT_ENUMS_MATCH(QWebEngineUrlScheme::NoAccessAllowed, url::CustomScheme::NoAccessAllowed) +ASSERT_ENUMS_MATCH(QWebEngineUrlScheme::ServiceWorkersAllowed, url::CustomScheme::ServiceWorkersAllowed) +ASSERT_ENUMS_MATCH(QWebEngineUrlScheme::ViewSourceAllowed, url::CustomScheme::ViewSourceAllowed) +ASSERT_ENUMS_MATCH(QWebEngineUrlScheme::ContentSecurityPolicyIgnored, url::CustomScheme::ContentSecurityPolicyIgnored) + +class QWebEngineUrlSchemePrivate : public QSharedData + , public url::CustomScheme +{ +public: + QWebEngineUrlSchemePrivate() {} + QWebEngineUrlSchemePrivate(const url::CustomScheme &cs) : url::CustomScheme(cs) {} + static QSharedDataPointer<QWebEngineUrlSchemePrivate> defaultConstructed() + { + static QSharedDataPointer<QWebEngineUrlSchemePrivate> instance(new QWebEngineUrlSchemePrivate); + return instance; + } +}; + +/*! + \class QWebEngineUrlScheme + \inmodule QtWebEngineCore + \since 5.12 + \brief The QWebEngineUrlScheme class configures a custom URL scheme. + + A web engine URL scheme describes a URL scheme from the web engine's + perspective, specifying how URLs of this scheme should be parsed, and which + security restrictions should be placed on resources originating from such + URLs. + + Custom URL schemes must be configured early at application startup, before + creating any Qt WebEngine classes. The configuration applies globally to all + profiles. + + \code + int main(int argc, char **argv) + { + QWebEngineUrlScheme scheme("myscheme"); + scheme.setSyntax(QWebEngineUrlScheme::Syntax::HostAndPort); + scheme.setDefaultPort(2345); + scheme.setFlags(QWebEngineUrlScheme::SecureScheme); + QWebEngineUrlScheme::registerScheme(scheme); + ... + } + \endcode + + To actually make use of the custom URL scheme, a \l QWebEngineUrlSchemeHandler + must be created and registered in a profile. + + \sa QWebEngineUrlSchemeHandler +*/ + +/*! + \enum QWebEngineUrlScheme::Syntax + + This enum type lists types of URL syntax. + + To apply the same-origin policy to a custom URL scheme, WebEngine must be able + to compute the origin (host and port combination) of a URL. The \c {Host...} + options indicate that the URL scheme conforms to the standard URL syntax (like + \c http) and automatically enable the same-origin policy. The \c {Path} + option indicates that the URL scheme uses a non-standard syntax and that the + same-origin policy cannot be applied. + + \value HostPortAndUserInformation + The authority component of a URL of this type has all of the standard + elements: host, port, user name, and password. A URL without a port will use + the \l defaultPort (which \e must not be \l PortUnspecified). + + \value HostAndPort + The authority component of a URL of this type has only the host and port + elements. A URL without a port will use the \l defaultPort (which \e must not + be \l PortUnspecified). + + \value Host + The authority component of a URL of this type has only the host part and no + port. The \l defaultPort \e must be set to \l PortUnspecified. + + \value Path + A URL of this type has no authority component at all. Everything after scheme + name and separator character (:) will be preserved as is without validation + or canonicalization. All URLs of such a scheme will be considered as having + the same origin (unless the \c NoAccessAllowed flag is used). +*/ + +/*! + \enum QWebEngineUrlScheme::SpecialPort + + This enum type defines special values for \l defaultPort. + + \value PortUnspecified + Indicates that the URL scheme does not have a port element. +*/ + +/*! + \enum QWebEngineUrlScheme::Flag + + This enum type specifies security options that should apply to a URL scheme. + + \value SecureScheme + Indicates that the URL scheme is + \l{https://www.w3.org/TR/powerful-features/#is-origin-trustworthy}{potentially + trustworthy}. This flag should only be applied to URL schemes which ensure + data authenticity, confidentiality, and integrity, either through encryption + or other means. Examples of secure builtin schemes include \c https + (authenticated and encrypted) and \c qrc (local resources only), whereas \c + http is an example of an insecure scheme. + + \value LocalScheme + Indicates that the URL scheme provides access to local resources. The purpose + of this flag is to prevent network content from accessing local resources. + Only schemes with the \c LocalAccessAllowed flag may load resources from a + scheme with the \c Local flag. The only builtin schemes with this flag are \c + file and \c qrc. + + \value LocalAccessAllowed + Indicates that content from this scheme should be allowed to load resources + from schemes with the \c Local flag. + + \value NoAccessAllowed + Indicates that all content from this scheme should be forced to have unique + opaque origins: no two resources will have the same origin. + + \value ServiceWorkersAllowed + Indicates that the Service Workers API should be enabled. + + \value ViewSourceAllowed + Indicates that the View Source feature should be enabled. + + \value ContentSecurityPolicyIgnored + Indicates that accesses to this scheme should bypass all + Content-Security-Policy checks. +*/ + +QWebEngineUrlScheme::QWebEngineUrlScheme(QWebEngineUrlSchemePrivate *d) + : d(d) +{ +} + +/*! + Constructs a web engine URL scheme with default values. +*/ +QWebEngineUrlScheme::QWebEngineUrlScheme() + : QWebEngineUrlScheme(QWebEngineUrlSchemePrivate::defaultConstructed()) +{ +} + +/*! + Constructs a web engine URL scheme with given \a name. +*/ +QWebEngineUrlScheme::QWebEngineUrlScheme(const QByteArray &name) + : QWebEngineUrlScheme() +{ + setName(name); +} + +/*! + Copies \a that. +*/ +QWebEngineUrlScheme::QWebEngineUrlScheme(const QWebEngineUrlScheme &that) = default; + +/*! + Copies \a that. +*/ +QWebEngineUrlScheme &QWebEngineUrlScheme::operator=(const QWebEngineUrlScheme &that) = default; + +/*! + Moves \a that. +*/ +QWebEngineUrlScheme::QWebEngineUrlScheme(QWebEngineUrlScheme &&that) = default; + +/*! + Moves \a that. +*/ +QWebEngineUrlScheme &QWebEngineUrlScheme::operator=(QWebEngineUrlScheme &&that) = default; + +/*! + Destructs this object. +*/ +QWebEngineUrlScheme::~QWebEngineUrlScheme() = default; + +/*! + Returns \c true if this and \a that object are equal. +*/ +bool QWebEngineUrlScheme::operator==(const QWebEngineUrlScheme &that) const +{ + return (d == that.d) + || (d->name == that.d->name + && d->type == that.d->type + && d->default_port == that.d->default_port + && d->flags == that.d->flags); +} + +/*! + \fn bool QWebEngineUrlScheme::operator!=(const QWebEngineUrlScheme &that) const + + Returns \c true if this and \a that object are not equal. +*/ + +/*! + Returns the name of this URL scheme. + + The default value is an empty string. + + \sa setName() +*/ +QByteArray QWebEngineUrlScheme::name() const +{ + return QByteArray::fromStdString(d->name); +} + +/*! + Sets the name of this URL scheme to \a newValue. + + \note The name is automatically converted to lower case. + + \sa name() +*/ +void QWebEngineUrlScheme::setName(const QByteArray &newValue) +{ + d->name = newValue.toLower().toStdString(); +} + +/*! + Returns the syntax type of this URL scheme. + + The default value is \c Path. + + \sa Syntax, setSyntax() +*/ +QWebEngineUrlScheme::Syntax QWebEngineUrlScheme::syntax() const +{ + return static_cast<Syntax>(d->type); +} + +/*! + Sets the syntax type of this URL scheme to \a newValue. + + \sa Syntax, syntax() +*/ +void QWebEngineUrlScheme::setSyntax(Syntax newValue) +{ + d->type = static_cast<url::SchemeType>(newValue); +} + +/*! + Returns the default port of this URL scheme. + + The default value is \c PortUnspecified. + + \sa setDefaultPort() +*/ +int QWebEngineUrlScheme::defaultPort() const +{ + return d->default_port; +} + +/*! + Sets the default port of this URL scheme to \a newValue. + + \sa defaultPort() +*/ +void QWebEngineUrlScheme::setDefaultPort(int newValue) +{ + d->default_port = newValue; +} + +/*! + Returns the flags for this URL scheme. + + The default value is an empty set of flags. + + \sa Flags, setFlags() +*/ +QWebEngineUrlScheme::Flags QWebEngineUrlScheme::flags() const +{ + return Flags(d->flags); +} + +/*! + Sets the flags for this URL scheme to \a newValue. + + \sa Flags, flags() +*/ +void QWebEngineUrlScheme::setFlags(Flags newValue) +{ + d->flags = newValue; +} + +/*! + Registers \a scheme with the web engine's URL parser and security model. + + It is recommended that all custom URL schemes are first registered with this + function at application startup, even if the default options are to be used. + + \warning This function must be called early at application startup, before + creating any WebEngine classes. Late calls will be ignored. + + \sa schemeByName() +*/ +void QWebEngineUrlScheme::registerScheme(const QWebEngineUrlScheme &scheme) +{ + url::CustomScheme::AddScheme(*scheme.d); +} + +/*! + Returns the web engine URL scheme with the given \a name or the + default-constructed scheme. + + \sa registerScheme() +*/ +QWebEngineUrlScheme QWebEngineUrlScheme::schemeByName(const QByteArray &name) +{ + base::StringPiece namePiece{name.data(), static_cast<size_t>(name.size())}; + if (const url::CustomScheme *cs = url::CustomScheme::FindScheme(namePiece)) + return QWebEngineUrlScheme(new QWebEngineUrlSchemePrivate(*cs)); + return QWebEngineUrlScheme(); +} + +QT_END_NAMESPACE diff --git a/src/core/api/qwebenginebrowsercontext_p.h b/src/core/api/qwebengineurlscheme.h index 713ab730e..88a8f5065 100644 --- a/src/core/api/qwebenginebrowsercontext_p.h +++ b/src/core/api/qwebengineurlscheme.h @@ -37,47 +37,81 @@ ** ****************************************************************************/ -#ifndef QWEBENGINEBROWSERCONTEXT_P_H -#define QWEBENGINEBROWSERCONTEXT_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 "qtwebenginecoreglobal_p.h" - -#include <QObject> -#include <QSharedPointer> - -namespace QtWebEngineCore { -class BrowserContextAdapter; -class BrowserContextAdapterClient; -} +#ifndef QWEBENGINEURLSCHEME_H +#define QWEBENGINEURLSCHEME_H + +#include <QtWebEngineCore/qtwebenginecoreglobal.h> + +#include <QtCore/qbytearray.h> +#include <QtCore/qobjectdefs.h> +#include <QtCore/qshareddata.h> QT_BEGIN_NAMESPACE -// This is a wrapper class for BrowserContextAdapter. BrowserContextAdapter must be destructed before WebEngineContext -// is destructed. Therefore access it via the QWebEngineBrowserContext which parent is the WebEngineContext::globalQObject. -// This guarantees the destruction together with the WebEngineContext. -class QWEBENGINE_PRIVATE_EXPORT QWebEngineBrowserContext : public QObject { +class QWebEngineUrlSchemePrivate; + +class QWEBENGINECORE_EXPORT QWebEngineUrlScheme { + Q_GADGET public: - QWebEngineBrowserContext(QSharedPointer<QtWebEngineCore::BrowserContextAdapter> browserContext, QtWebEngineCore::BrowserContextAdapterClient *profile); - ~QWebEngineBrowserContext(); + enum class Syntax { + HostPortAndUserInformation, + HostAndPort, + Host, + Path, + }; + + enum SpecialPort { + PortUnspecified = -1 + }; + + enum Flag { + SecureScheme = 0x1, + LocalScheme = 0x2, + LocalAccessAllowed = 0x4, + NoAccessAllowed = 0x8, + ServiceWorkersAllowed = 0x10, + ViewSourceAllowed = 0x20, + ContentSecurityPolicyIgnored = 0x40, + }; + Q_DECLARE_FLAGS(Flags, Flag) + Q_FLAG(Flags) + + QWebEngineUrlScheme(); + explicit QWebEngineUrlScheme(const QByteArray &name); + + QWebEngineUrlScheme(const QWebEngineUrlScheme &that); + QWebEngineUrlScheme &operator=(const QWebEngineUrlScheme &that); - void shutdown(); + QWebEngineUrlScheme(QWebEngineUrlScheme &&that); + QWebEngineUrlScheme &operator=(QWebEngineUrlScheme &&that); - QSharedPointer<QtWebEngineCore::BrowserContextAdapter> browserContextRef; + ~QWebEngineUrlScheme(); + + bool operator==(const QWebEngineUrlScheme &that) const; + bool operator!=(const QWebEngineUrlScheme &that) const { return !(*this == that); } + + QByteArray name() const; + void setName(const QByteArray &newValue); + + Syntax syntax() const; + void setSyntax(Syntax newValue); + + int defaultPort() const; + void setDefaultPort(int newValue); + + Flags flags() const; + void setFlags(Flags newValue); + + static void registerScheme(const QWebEngineUrlScheme &scheme); + static QWebEngineUrlScheme schemeByName(const QByteArray &name); private: - QtWebEngineCore::BrowserContextAdapterClient *m_profile; + QWebEngineUrlScheme(QWebEngineUrlSchemePrivate *d); + QSharedDataPointer<QWebEngineUrlSchemePrivate> d; }; +Q_DECLARE_OPERATORS_FOR_FLAGS(QWebEngineUrlScheme::Flags) + QT_END_NAMESPACE -#endif // QWEBENGINEBROWSERCONTEXT_P_H +#endif // !QWEBENGINEURLSCHEME_H diff --git a/src/core/api/qwebengineurlschemehandler.h b/src/core/api/qwebengineurlschemehandler.h index 757c461f4..23fee4b95 100644 --- a/src/core/api/qwebengineurlschemehandler.h +++ b/src/core/api/qwebengineurlschemehandler.h @@ -52,7 +52,7 @@ QT_BEGIN_NAMESPACE class QWebEngineUrlRequestJob; -class QWEBENGINE_EXPORT QWebEngineUrlSchemeHandler : public QObject { +class QWEBENGINECORE_EXPORT QWebEngineUrlSchemeHandler : public QObject { Q_OBJECT public: QWebEngineUrlSchemeHandler(QObject *parent = Q_NULLPTR); |