summaryrefslogtreecommitdiffstats
path: root/src/core/url_request_custom_job.cpp
diff options
context:
space:
mode:
authorAllan Sandfeld Jensen <allan.jensen@theqtcompany.com>2016-04-15 12:45:59 +0200
committerAllan Sandfeld Jensen <allan.jensen@theqtcompany.com>2016-04-20 14:32:58 +0000
commitd56128c315ad89dddf507b10dc4332d05cc42f91 (patch)
tree65a2b340c82350d95cb29a1576e1053d6ba84a0c /src/core/url_request_custom_job.cpp
parent5b8aad9fa24caeb50ff3640d01590a15ee4e23d8 (diff)
Improve thread-safety of custom scheme handlers
Avoids accessing the QWebEngineUrlSchemeHandler from any other thread than the UI thread, since it may be deleted at any time on the UI thread. Change-Id: Icb4331b3c36f6f619a9fd975d155a9fd608dc5e9 Reviewed-by: Kai Koehne <kai.koehne@qt.io>
Diffstat (limited to 'src/core/url_request_custom_job.cpp')
-rw-r--r--src/core/url_request_custom_job.cpp28
1 files changed, 21 insertions, 7 deletions
diff --git a/src/core/url_request_custom_job.cpp b/src/core/url_request_custom_job.cpp
index 07087c247..493bdb703 100644
--- a/src/core/url_request_custom_job.cpp
+++ b/src/core/url_request_custom_job.cpp
@@ -39,6 +39,7 @@
#include "api/qwebengineurlrequestjob.h"
#include "api/qwebengineurlschemehandler.h"
+#include "browser_context_adapter.h"
#include "type_conversion.h"
#include "content/public/browser/browser_thread.h"
@@ -54,9 +55,11 @@ using namespace net;
namespace QtWebEngineCore {
-URLRequestCustomJob::URLRequestCustomJob(URLRequest *request, NetworkDelegate *networkDelegate, QWebEngineUrlSchemeHandler *schemeHandler)
+URLRequestCustomJob::URLRequestCustomJob(URLRequest *request, NetworkDelegate *networkDelegate,
+ const std::string &scheme, QWeakPointer<const BrowserContextAdapter> adapter)
: URLRequestJob(request, networkDelegate)
- , m_schemeHandler(schemeHandler)
+ , m_scheme(scheme)
+ , m_adapter(adapter)
, m_shared(new URLRequestCustomJobShared(this))
{
}
@@ -328,11 +331,22 @@ void URLRequestCustomJobShared::startAsync()
delete this;
return;
}
- m_delegate = new URLRequestCustomJobDelegate(this);
- m_asyncInitialized = true;
- QWebEngineUrlRequestJob *requestJob = new QWebEngineUrlRequestJob(m_delegate);
- if (m_job)
- m_job->m_schemeHandler->requestStarted(requestJob);
+
+ QWebEngineUrlSchemeHandler *schemeHandler = 0;
+ QSharedPointer<const BrowserContextAdapter> browserContext = m_job->m_adapter.toStrongRef();
+ if (browserContext)
+ schemeHandler = browserContext->customUrlSchemeHandlers()[toQByteArray(m_job->m_scheme)];
+ if (schemeHandler) {
+ m_delegate = new URLRequestCustomJobDelegate(this);
+ m_asyncInitialized = true;
+ QWebEngineUrlRequestJob *requestJob = new QWebEngineUrlRequestJob(m_delegate);
+ schemeHandler->requestStarted(requestJob);
+ } else {
+ lock.unlock();
+ abort();
+ delete this;
+ return;
+ }
}
} // namespace