summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorAllan Sandfeld Jensen <allan.jensen@qt.io>2018-01-19 13:30:51 +0100
committerAllan Sandfeld Jensen <allan.jensen@qt.io>2018-01-22 10:30:42 +0000
commit2daa4950118dd76d0d0bf15e347217740b0cb5c5 (patch)
treea3febba6aaef36f59295ac950757dfee21a5dd2d /src
parent86060ec61135cd30f9a8d8415784b767ce1f1252 (diff)
Add initiator to QWebEngineUrlRequestJob
Add a property that can be used to tell what is making the URL request. Change-Id: Ic7224382165e93d3c043c30e9a7cc5be9f29d9db Reviewed-by: Michal Klocek <michal.klocek@qt.io>
Diffstat (limited to 'src')
-rw-r--r--src/core/api/qwebengineurlrequestjob.cpp11
-rw-r--r--src/core/api/qwebengineurlrequestjob.h1
-rw-r--r--src/core/url_request_custom_job.cpp2
-rw-r--r--src/core/url_request_custom_job_delegate.cpp11
-rw-r--r--src/core/url_request_custom_job_delegate.h5
-rw-r--r--src/core/url_request_custom_job_proxy.cpp9
-rw-r--r--src/core/url_request_custom_job_proxy.h4
7 files changed, 36 insertions, 7 deletions
diff --git a/src/core/api/qwebengineurlrequestjob.cpp b/src/core/api/qwebengineurlrequestjob.cpp
index 47aab48a0..941c70b1d 100644
--- a/src/core/api/qwebengineurlrequestjob.cpp
+++ b/src/core/api/qwebengineurlrequestjob.cpp
@@ -114,6 +114,17 @@ QByteArray QWebEngineUrlRequestJob::requestMethod() const
}
/*!
+ \since 5.11
+ Returns the origin URL of the content that initiated the request. If the
+ request was not initiated by web content the function will return an
+ empty QUrl.
+*/
+QUrl QWebEngineUrlRequestJob::initiator() const
+{
+ return d_ptr->initiator();
+}
+
+/*!
Replies to the request with \a device and the MIME type \a contentType.
The user has to be aware that \a device will be used on another thread
diff --git a/src/core/api/qwebengineurlrequestjob.h b/src/core/api/qwebengineurlrequestjob.h
index 4f23ab401..7a7dbd83d 100644
--- a/src/core/api/qwebengineurlrequestjob.h
+++ b/src/core/api/qwebengineurlrequestjob.h
@@ -72,6 +72,7 @@ public:
QUrl requestUrl() const;
QByteArray requestMethod() const;
+ QUrl initiator() const;
void reply(const QByteArray &contentType, QIODevice *device);
void fail(Error error);
diff --git a/src/core/url_request_custom_job.cpp b/src/core/url_request_custom_job.cpp
index 070414b4b..cf96cd6d9 100644
--- a/src/core/url_request_custom_job.cpp
+++ b/src/core/url_request_custom_job.cpp
@@ -78,7 +78,7 @@ void URLRequestCustomJob::Start()
DCHECK_CURRENTLY_ON(content::BrowserThread::IO);
content::BrowserThread::PostTask(content::BrowserThread::UI, FROM_HERE,
base::Bind(&URLRequestCustomJobProxy::initialize,
- m_proxy, request()->url(), request()->method()));
+ m_proxy, request()->url(), request()->method(), request()->initiator()));
}
void URLRequestCustomJob::Kill()
diff --git a/src/core/url_request_custom_job_delegate.cpp b/src/core/url_request_custom_job_delegate.cpp
index 6b82cebb5..338bd7137 100644
--- a/src/core/url_request_custom_job_delegate.cpp
+++ b/src/core/url_request_custom_job_delegate.cpp
@@ -50,10 +50,12 @@ namespace QtWebEngineCore {
URLRequestCustomJobDelegate::URLRequestCustomJobDelegate(URLRequestCustomJobProxy *proxy,
const QUrl &url,
- const QByteArray &method)
+ const QByteArray &method,
+ const QUrl &initiatorOrigin)
: m_proxy(proxy),
m_request(url),
- m_method(method)
+ m_method(method),
+ m_initiatorOrigin(initiatorOrigin)
{
}
@@ -71,6 +73,11 @@ QByteArray URLRequestCustomJobDelegate::method() const
return m_method;
}
+QUrl URLRequestCustomJobDelegate::initiator() const
+{
+ return m_initiatorOrigin;
+}
+
void URLRequestCustomJobDelegate::reply(const QByteArray &contentType, QIODevice *device)
{
if (device)
diff --git a/src/core/url_request_custom_job_delegate.h b/src/core/url_request_custom_job_delegate.h
index 3f5e6d591..6bbd10909 100644
--- a/src/core/url_request_custom_job_delegate.h
+++ b/src/core/url_request_custom_job_delegate.h
@@ -68,6 +68,7 @@ public:
QUrl url() const;
QByteArray method() const;
+ QUrl initiator() const;
void reply(const QByteArray &contentType, QIODevice *device);
void redirect(const QUrl& url);
@@ -80,12 +81,14 @@ private Q_SLOTS:
private:
URLRequestCustomJobDelegate(URLRequestCustomJobProxy *proxy,
const QUrl &url,
- const QByteArray &method);
+ const QByteArray &method,
+ const QUrl &initiatorOrigin);
friend class URLRequestCustomJobProxy;
scoped_refptr<URLRequestCustomJobProxy> m_proxy;
QUrl m_request;
QByteArray m_method;
+ QUrl m_initiatorOrigin;
};
} // namespace
diff --git a/src/core/url_request_custom_job_proxy.cpp b/src/core/url_request_custom_job_proxy.cpp
index 832d3d11e..6c9824bb9 100644
--- a/src/core/url_request_custom_job_proxy.cpp
+++ b/src/core/url_request_custom_job_proxy.cpp
@@ -151,18 +151,23 @@ void URLRequestCustomJobProxy::readyRead()
m_job->notifyReadyRead();
}
-void URLRequestCustomJobProxy::initialize(GURL url, std::string method)
+void URLRequestCustomJobProxy::initialize(GURL url, std::string method, base::Optional<url::Origin> initiator)
{
DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
Q_ASSERT(!m_delegate);
+ QUrl initiatorOrigin;
+ if (initiator.has_value())
+ initiatorOrigin = toQt(initiator.value().GetURL());
+
QWebEngineUrlSchemeHandler *schemeHandler = 0;
QSharedPointer<const BrowserContextAdapter> browserContext = m_adapter.toStrongRef();
if (browserContext)
schemeHandler = browserContext->customUrlSchemeHandlers()[toQByteArray(m_scheme)];
if (schemeHandler) {
m_delegate = new URLRequestCustomJobDelegate(this, toQt(url),
- QByteArray::fromStdString(method));
+ QByteArray::fromStdString(method),
+ initiatorOrigin);
QWebEngineUrlRequestJob *requestJob = new QWebEngineUrlRequestJob(m_delegate);
schemeHandler->requestStarted(requestJob);
}
diff --git a/src/core/url_request_custom_job_proxy.h b/src/core/url_request_custom_job_proxy.h
index 3ea30a4e1..603ad5840 100644
--- a/src/core/url_request_custom_job_proxy.h
+++ b/src/core/url_request_custom_job_proxy.h
@@ -41,7 +41,9 @@
#define URL_REQUEST_CUSTOM_JOB_PROXY_H_
#include "base/memory/weak_ptr.h"
+#include "base/optional.h"
#include "url/gurl.h"
+#include "url/origin.h"
#include <QtCore/QWeakPointer>
QT_FORWARD_DECLARE_CLASS(QIODevice)
@@ -70,7 +72,7 @@ public:
void abort();
void fail(int error);
void release();
- void initialize(GURL url, std::string method);
+ void initialize(GURL url, std::string method, base::Optional<url::Origin> initiatorOrigin);
void readyRead();
// IO thread owned: