Commit e2e61521 authored by Michael Bruning's avatar Michael Bruning Committed by Joerg Bornemann
Browse files

Change QWebEngineUrlRequestInterceptor::interceptRequest to void.


Now uses a flag in QWebEngineUrlRequestInfoPrivate to store if
the interceptor actually changed the request.

Change-Id: Idccbd1c15696e577ee69248e53b75ba6ec1c571c
Reviewed-by: default avatarJoerg Bornemann <joerg.bornemann@theqtcompany.com>
Showing with 18 additions and 7 deletions
......@@ -126,6 +126,7 @@ QWebEngineUrlRequestInfoPrivate::QWebEngineUrlRequestInfoPrivate(QWebEngineUrlRe
, url(u)
, firstPartyUrl(fpu)
, method(m)
, changed(false)
{
}
......@@ -241,6 +242,12 @@ QByteArray QWebEngineUrlRequestInfo::requestMethod() const
return d->method;
}
bool QWebEngineUrlRequestInfo::changed() const
{
Q_D(const QWebEngineUrlRequestInfo);
return d->changed;
}
/*!
Redirects this request to \a url.
It is only possible to redirect requests that do not have payload data, such as GET requests.
......@@ -249,6 +256,7 @@ QByteArray QWebEngineUrlRequestInfo::requestMethod() const
void QWebEngineUrlRequestInfo::redirect(const QUrl &url)
{
Q_D(QWebEngineUrlRequestInfo);
d->changed = true;
d->url = url;
}
......@@ -261,6 +269,7 @@ void QWebEngineUrlRequestInfo::redirect(const QUrl &url)
void QWebEngineUrlRequestInfo::block(bool shouldBlock)
{
Q_D(QWebEngineUrlRequestInfo);
d->changed = true;
d->shouldBlockRequest = shouldBlock;
}
......@@ -271,6 +280,7 @@ void QWebEngineUrlRequestInfo::block(bool shouldBlock)
void QWebEngineUrlRequestInfo::setExtraHeader(const QByteArray &name, const QByteArray &value)
{
Q_D(QWebEngineUrlRequestInfo);
d->changed = true;
d->extraHeaders.insert(name, value);
}
......
......@@ -88,6 +88,7 @@ public:
QUrl requestUrl() const;
QUrl firstPartyUrl() const;
QByteArray requestMethod() const;
bool changed() const;
void block(bool shouldBlock);
void redirect(const QUrl &url);
......
......@@ -68,6 +68,7 @@ public:
QUrl url;
QUrl firstPartyUrl;
const QByteArray method;
bool changed;
QHash<QByteArray, QByteArray> extraHeaders;
QWebEngineUrlRequestInfo *q_ptr;
......
......@@ -57,7 +57,7 @@ public:
{
}
virtual bool interceptRequest(QWebEngineUrlRequestInfo &info) = 0;
virtual void interceptRequest(QWebEngineUrlRequestInfo &info) = 0;
};
QT_END_NAMESPACE
......
......@@ -109,7 +109,8 @@ int NetworkDelegateQt::OnBeforeURLRequest(net::URLRequest *request, const net::C
, toQt(request->first_party_for_cookies())
, QByteArray::fromStdString(request->method()));
QWebEngineUrlRequestInfo requestInfo(infoPrivate);
if (interceptor->interceptRequest(requestInfo)) {
interceptor->interceptRequest(requestInfo);
if (requestInfo.changed()) {
int result = infoPrivate->shouldBlockRequest ? net::ERR_ABORTED : net::OK;
if (qUrl != infoPrivate->url)
......
......@@ -100,15 +100,14 @@ public:
QList<QUrl> firstPartyUrls;
bool shouldIntercept;
bool interceptRequest(QWebEngineUrlRequestInfo &info) override
void interceptRequest(QWebEngineUrlRequestInfo &info) override
{
info.block(info.requestMethod() != QByteArrayLiteral("GET"));
if (info.requestUrl().toString().endsWith(QLatin1String("__placeholder__")))
if (shouldIntercept && info.requestUrl().toString().endsWith(QLatin1String("__placeholder__")))
info.redirect(QUrl("qrc:///resources/content.html"));
observedUrls.append(info.requestUrl());
firstPartyUrls.append(info.firstPartyUrl());
return shouldIntercept;
}
TestRequestInterceptor(bool intercept)
: shouldIntercept(intercept)
......@@ -162,11 +161,10 @@ class LocalhostContentProvider : public QWebEngineUrlRequestInterceptor
public:
LocalhostContentProvider() { }
bool interceptRequest(QWebEngineUrlRequestInfo &info) override
void interceptRequest(QWebEngineUrlRequestInfo &info) override
{
requestedUrls.append(info.requestUrl());
info.redirect(QUrl("data:text/html,<p>hello"));
return true;
}
QList<QUrl> requestedUrls;
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment