summaryrefslogtreecommitdiffstats
path: root/src/core/api/qwebengineurlrequestinfo.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/core/api/qwebengineurlrequestinfo.cpp')
-rw-r--r--src/core/api/qwebengineurlrequestinfo.cpp192
1 files changed, 117 insertions, 75 deletions
diff --git a/src/core/api/qwebengineurlrequestinfo.cpp b/src/core/api/qwebengineurlrequestinfo.cpp
index 2b8a69c9a..152cf4dd0 100644
--- a/src/core/api/qwebengineurlrequestinfo.cpp
+++ b/src/core/api/qwebengineurlrequestinfo.cpp
@@ -1,77 +1,30 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 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$
-**
-****************************************************************************/
+// Copyright (C) 2019 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#include "qwebengineurlrequestinfo.h"
#include "qwebengineurlrequestinfo_p.h"
-#include "content/public/common/resource_type.h"
-
#include "web_contents_adapter_client.h"
+#include "net/resource_request_body_qt.h"
+
+#include <memory>
+#include <utility>
QT_BEGIN_NAMESPACE
-ASSERT_ENUMS_MATCH(QWebEngineUrlRequestInfo::ResourceTypeMainFrame, content::RESOURCE_TYPE_MAIN_FRAME)
-ASSERT_ENUMS_MATCH(QWebEngineUrlRequestInfo::ResourceTypeSubFrame, content::RESOURCE_TYPE_SUB_FRAME)
-ASSERT_ENUMS_MATCH(QWebEngineUrlRequestInfo::ResourceTypeStylesheet, content::RESOURCE_TYPE_STYLESHEET)
-ASSERT_ENUMS_MATCH(QWebEngineUrlRequestInfo::ResourceTypeScript, content::RESOURCE_TYPE_SCRIPT)
-ASSERT_ENUMS_MATCH(QWebEngineUrlRequestInfo::ResourceTypeImage, content::RESOURCE_TYPE_IMAGE)
-ASSERT_ENUMS_MATCH(QWebEngineUrlRequestInfo::ResourceTypeFontResource, content::RESOURCE_TYPE_FONT_RESOURCE)
-ASSERT_ENUMS_MATCH(QWebEngineUrlRequestInfo::ResourceTypeSubResource, content::RESOURCE_TYPE_SUB_RESOURCE)
-ASSERT_ENUMS_MATCH(QWebEngineUrlRequestInfo::ResourceTypeObject, content::RESOURCE_TYPE_OBJECT)
-ASSERT_ENUMS_MATCH(QWebEngineUrlRequestInfo::ResourceTypeMedia, content::RESOURCE_TYPE_MEDIA)
-ASSERT_ENUMS_MATCH(QWebEngineUrlRequestInfo::ResourceTypeWorker, content::RESOURCE_TYPE_WORKER)
-ASSERT_ENUMS_MATCH(QWebEngineUrlRequestInfo::ResourceTypeSharedWorker, content::RESOURCE_TYPE_SHARED_WORKER)
-ASSERT_ENUMS_MATCH(QWebEngineUrlRequestInfo::ResourceTypePrefetch, content::RESOURCE_TYPE_PREFETCH)
-ASSERT_ENUMS_MATCH(QWebEngineUrlRequestInfo::ResourceTypeFavicon, content::RESOURCE_TYPE_FAVICON)
-ASSERT_ENUMS_MATCH(QWebEngineUrlRequestInfo::ResourceTypeXhr, content::RESOURCE_TYPE_XHR)
-ASSERT_ENUMS_MATCH(QWebEngineUrlRequestInfo::ResourceTypePing, content::RESOURCE_TYPE_PING)
-ASSERT_ENUMS_MATCH(QWebEngineUrlRequestInfo::ResourceTypeServiceWorker, content::RESOURCE_TYPE_SERVICE_WORKER)
-ASSERT_ENUMS_MATCH(QWebEngineUrlRequestInfo::ResourceTypeCspReport, content::RESOURCE_TYPE_CSP_REPORT)
-ASSERT_ENUMS_MATCH(QWebEngineUrlRequestInfo::ResourceTypePluginResource, content::RESOURCE_TYPE_PLUGIN_RESOURCE)
-ASSERT_ENUMS_MATCH(QWebEngineUrlRequestInfo::ResourceTypeLast, content::RESOURCE_TYPE_LAST_TYPE)
+// We changed the type from QScopedPointer to unique_ptr, make sure it's binary compatible:
+static_assert(sizeof(QScopedPointer<QWebEngineUrlRequestInfoPrivate>)
+ == sizeof(std::unique_ptr<QWebEngineUrlRequestInfoPrivate>));
ASSERT_ENUMS_MATCH(QtWebEngineCore::WebContentsAdapterClient::LinkNavigation, QWebEngineUrlRequestInfo::NavigationTypeLink)
ASSERT_ENUMS_MATCH(QtWebEngineCore::WebContentsAdapterClient::TypedNavigation, QWebEngineUrlRequestInfo::NavigationTypeTyped)
-ASSERT_ENUMS_MATCH(QtWebEngineCore::WebContentsAdapterClient::FormSubmittedNavigation, QWebEngineUrlRequestInfo::NavigationTypeFormSubmitted)
-ASSERT_ENUMS_MATCH(QtWebEngineCore::WebContentsAdapterClient::BackForwardNavigation, QWebEngineUrlRequestInfo::NavigationTypeBackForward)
+ASSERT_ENUMS_MATCH(QtWebEngineCore::WebContentsAdapterClient::FormSubmittedNavigation,
+ QWebEngineUrlRequestInfo::NavigationTypeFormSubmitted)
+ASSERT_ENUMS_MATCH(QtWebEngineCore::WebContentsAdapterClient::BackForwardNavigation,
+ QWebEngineUrlRequestInfo::NavigationTypeBackForward)
ASSERT_ENUMS_MATCH(QtWebEngineCore::WebContentsAdapterClient::ReloadNavigation, QWebEngineUrlRequestInfo::NavigationTypeReload)
ASSERT_ENUMS_MATCH(QtWebEngineCore::WebContentsAdapterClient::OtherNavigation, QWebEngineUrlRequestInfo::NavigationTypeOther)
+ASSERT_ENUMS_MATCH(QtWebEngineCore::WebContentsAdapterClient::RedirectNavigation, QWebEngineUrlRequestInfo::NavigationTypeRedirect)
/*!
\class QWebEngineUrlRequestInfo
@@ -96,8 +49,8 @@ ASSERT_ENUMS_MATCH(QtWebEngineCore::WebContentsAdapterClient::OtherNavigation, Q
interceptor on the profile enables intercepting, blocking, and modifying URL requests
before they reach the networking stack of Chromium.
- You can install the interceptor on a profile via QWebEngineProfile::setRequestInterceptor()
- or QQuickWebEngineProfile::setRequestInterceptor().
+ You can install the interceptor on a profile via QWebEngineProfile::setUrlRequestInterceptor()
+ or QQuickWebEngineProfile::setUrlRequestInterceptor().
When using the \l{Qt WebEngine Widgets Module}, \l{QWebEnginePage::acceptNavigationRequest()}
offers further options to accept or block requests.
@@ -106,7 +59,7 @@ ASSERT_ENUMS_MATCH(QtWebEngineCore::WebContentsAdapterClient::OtherNavigation, Q
*/
/*!
- \fn QWebEngineUrlRequestInterceptor::QWebEngineUrlRequestInterceptor(QObject * p = 0)
+ \fn QWebEngineUrlRequestInterceptor::QWebEngineUrlRequestInterceptor(QObject *p = nullptr)
Creates a new QWebEngineUrlRequestInterceptor object with \a p as parent.
*/
@@ -115,8 +68,7 @@ ASSERT_ENUMS_MATCH(QtWebEngineCore::WebContentsAdapterClient::OtherNavigation, Q
\fn void QWebEngineUrlRequestInterceptor::interceptRequest(QWebEngineUrlRequestInfo &info)
Reimplementing this virtual function makes it possible to intercept URL
- requests. This function is executed on the IO thread, and therefore running
- long tasks here will block networking.
+ requests. This method will be stalling the URL request until handled.
\a info contains the information about the URL request and will track internally
whether its members have been altered.
@@ -125,33 +77,57 @@ ASSERT_ENUMS_MATCH(QtWebEngineCore::WebContentsAdapterClient::OtherNavigation, Q
execution of this function is finished.
*/
-
-QWebEngineUrlRequestInfoPrivate::QWebEngineUrlRequestInfoPrivate(QWebEngineUrlRequestInfo::ResourceType resource, QWebEngineUrlRequestInfo::NavigationType navigation, const QUrl &u, const QUrl &fpu, const QByteArray &m)
+QWebEngineUrlRequestInfoPrivate::QWebEngineUrlRequestInfoPrivate(
+ QWebEngineUrlRequestInfo::ResourceType resource,
+ QWebEngineUrlRequestInfo::NavigationType navigation, const QUrl &u, const QUrl &fpu,
+ const QUrl &i, const QByteArray &m, QtWebEngineCore::ResourceRequestBody *const rb,
+ const QHash<QByteArray, QByteArray> &h)
: resourceType(resource)
, navigationType(navigation)
, shouldBlockRequest(false)
+ , shouldRedirectRequest(false)
, url(u)
, firstPartyUrl(fpu)
+ , initiator(i)
, method(m)
, changed(false)
-{
-}
+ , extraHeaders(h)
+ , resourceRequestBody(rb)
+{}
/*!
\internal
*/
+QWebEngineUrlRequestInfo::QWebEngineUrlRequestInfo() {}
-QWebEngineUrlRequestInfo::~QWebEngineUrlRequestInfo()
+/*!
+ \internal
+*/
+QWebEngineUrlRequestInfo::QWebEngineUrlRequestInfo(QWebEngineUrlRequestInfo &&p)
+ : d_ptr(std::move(p.d_ptr))
{
+}
+/*!
+ \internal
+*/
+QWebEngineUrlRequestInfo &QWebEngineUrlRequestInfo::operator=(QWebEngineUrlRequestInfo &&p)
+{
+ d_ptr = std::move(p.d_ptr);
+ return *this;
}
/*!
\internal
*/
-QWebEngineUrlRequestInfo::QWebEngineUrlRequestInfo(QWebEngineUrlRequestInfoPrivate *p)
- : d_ptr(p)
+QWebEngineUrlRequestInfo::~QWebEngineUrlRequestInfo() {}
+
+/*!
+ \internal
+*/
+
+QWebEngineUrlRequestInfo::QWebEngineUrlRequestInfo(QWebEngineUrlRequestInfoPrivate *p) : d_ptr(p)
{
d_ptr->q_ptr = this;
}
@@ -180,7 +156,10 @@ QWebEngineUrlRequestInfo::QWebEngineUrlRequestInfo(QWebEngineUrlRequestInfoPriva
\value ResourceTypeCspReport A report of Content Security Policy (CSP)
violations. CSP reports are in JSON format and they are delivered by
HTTP POST requests to specified servers. (Added in Qt 5.7)
- \value ResourceTypePluginResource A resource requested by a plugin. (Added in Qt 5.7)
+ \value ResourceTypePluginResource A resource requested by a plugin. (Added in Qt 5.7)
+ \value ResourceTypeNavigationPreloadMainFrame A main-frame service worker navigation preload request. (Added in Qt 5.14)
+ \value ResourceTypeNavigationPreloadSubFrame A sub-frame service worker navigation preload request. (Added in Qt 5.14)
+ \value ResourceTypeWebSocket A WebSocket request. (Added in Qt 6.4)
\value ResourceTypeUnknown Unknown request type.
\note For forward compatibility all values not matched should be treated as unknown,
@@ -208,6 +187,7 @@ QWebEngineUrlRequestInfo::ResourceType QWebEngineUrlRequestInfo::resourceType()
\value NavigationTypeFormSubmitted Navigation submits a form.
\value NavigationTypeBackForward Navigation initiated by a history action.
\value NavigationTypeReload Navigation initiated by refreshing the page.
+ \value NavigationTypeRedirect Navigation triggered automatically by page content or remote server. (Added in Qt 5.14)
\value NavigationTypeOther None of the above.
*/
@@ -241,6 +221,17 @@ QUrl QWebEngineUrlRequestInfo::firstPartyUrl() const
return d_ptr->firstPartyUrl;
}
+/*!
+ Returns the origin URL of the document that initiated
+ the navigation of a frame to another frame.
+
+ \since 5.14
+ */
+
+QUrl QWebEngineUrlRequestInfo::initiator() const
+{
+ return d_ptr->initiator;
+}
/*!
Returns the HTTP method of the request (for example, GET or POST).
@@ -252,6 +243,20 @@ QByteArray QWebEngineUrlRequestInfo::requestMethod() const
}
/*!
+ Returns a pointer to a QIODevice that gives access to the request body.
+ The request body can contain data for example when the request is
+ a POST request. If the request body is empty the QIODevice reflects this
+ and does not return any data when performing read operations on it.
+
+ \since 6.7
+*/
+
+QIODevice *QWebEngineUrlRequestInfo::requestBody() const
+{
+ return d_ptr->resourceRequestBody;
+}
+
+/*!
\internal
*/
bool QWebEngineUrlRequestInfo::changed() const
@@ -260,6 +265,14 @@ bool QWebEngineUrlRequestInfo::changed() const
}
/*!
+ \internal
+*/
+void QWebEngineUrlRequestInfo::resetChanged()
+{
+ d_ptr->changed = false;
+}
+
+/*!
Redirects this request to \a url.
It is only possible to redirect requests that do not have payload data, such as GET requests.
*/
@@ -268,6 +281,7 @@ void QWebEngineUrlRequestInfo::redirect(const QUrl &url)
{
d_ptr->changed = true;
d_ptr->url = url;
+ d_ptr->shouldRedirectRequest = true;
}
/*!
@@ -288,8 +302,36 @@ void QWebEngineUrlRequestInfo::block(bool shouldBlock)
void QWebEngineUrlRequestInfo::setHttpHeader(const QByteArray &name, const QByteArray &value)
{
- d_ptr->changed = true;
+ // Headers are case insentive, so we need to compare manually
+ for (auto it = d_ptr->extraHeaders.begin(); it != d_ptr->extraHeaders.end(); ++it) {
+ if (it.key().compare(name, Qt::CaseInsensitive) == 0) {
+ d_ptr->extraHeaders.erase(it);
+ break;
+ }
+ }
+
d_ptr->extraHeaders.insert(name, value);
}
+/*!
+ Returns the request headers.
+ \since 6.5
+ \note Not all headers are visible at this stage as Chromium will add
+ security and proxy headers at a later stage.
+*/
+
+QHash<QByteArray, QByteArray> QWebEngineUrlRequestInfo::httpHeaders() const
+{
+ return d_ptr->extraHeaders;
+}
+
+/*!
+ \internal
+*/
+void QWebEngineUrlRequestInfoPrivate::appendFileToResourceRequestBodyForTest(const QString &path)
+{
+ if (resourceRequestBody)
+ resourceRequestBody->appendFilesForTest(path);
+}
+
QT_END_NAMESPACE