summaryrefslogtreecommitdiffstats
path: root/src/core/url_request_custom_job.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/core/url_request_custom_job.cpp')
-rw-r--r--src/core/url_request_custom_job.cpp36
1 files changed, 22 insertions, 14 deletions
diff --git a/src/core/url_request_custom_job.cpp b/src/core/url_request_custom_job.cpp
index afdcecdfe..907f71c2e 100644
--- a/src/core/url_request_custom_job.cpp
+++ b/src/core/url_request_custom_job.cpp
@@ -37,7 +37,8 @@
#include "url_request_custom_job.h"
#include "url_request_custom_job_delegate.h"
-#include "custom_url_scheme_handler.h"
+#include "api/qwebengineurlrequestjob.h"
+#include "api/qwebengineurlschemehandler.h"
#include "type_conversion.h"
#include "content/public/browser/browser_thread.h"
@@ -53,13 +54,14 @@ using namespace net;
namespace QtWebEngineCore {
-URLRequestCustomJob::URLRequestCustomJob(URLRequest *request, NetworkDelegate *networkDelegate, CustomUrlSchemeHandler *schemeHandler)
+URLRequestCustomJob::URLRequestCustomJob(URLRequest *request, NetworkDelegate *networkDelegate, QWebEngineUrlSchemeHandler *schemeHandler)
: URLRequestJob(request, networkDelegate)
, m_device(0)
, m_schemeHandler(schemeHandler)
, m_error(0)
, m_started(false)
- , m_weakFactory(this)
+ , m_weakFactoryIO(this)
+ , m_weakFactoryUI(this)
{
}
@@ -77,7 +79,7 @@ URLRequestCustomJob::~URLRequestCustomJob()
void URLRequestCustomJob::Start()
{
DCHECK_CURRENTLY_ON(content::BrowserThread::IO);
- content::BrowserThread::PostTask(content::BrowserThread::UI, FROM_HERE, base::Bind(&URLRequestCustomJob::startAsync, m_weakFactory.GetWeakPtr()));
+ content::BrowserThread::PostTask(content::BrowserThread::UI, FROM_HERE, base::Bind(&URLRequestCustomJob::startAsync, m_weakFactoryIO.GetWeakPtr()));
}
void URLRequestCustomJob::Kill()
@@ -92,7 +94,8 @@ void URLRequestCustomJob::Kill()
if (m_device && m_device->isOpen())
m_device->close();
m_device = 0;
- m_weakFactory.InvalidateWeakPtrs();
+ m_weakFactoryIO.InvalidateWeakPtrs();
+ m_weakFactoryUI.InvalidateWeakPtrs();
URLRequestJob::Kill();
}
@@ -150,7 +153,7 @@ void URLRequestCustomJob::setReplyDevice(QIODevice *device)
m_device->open(QIODevice::ReadOnly);
if (m_device && m_device->isReadable())
- content::BrowserThread::PostTask(content::BrowserThread::IO, FROM_HERE, base::Bind(&URLRequestCustomJob::notifyStarted, m_weakFactory.GetWeakPtr()));
+ content::BrowserThread::PostTask(content::BrowserThread::IO, FROM_HERE, base::Bind(&URLRequestCustomJob::notifyStarted, m_weakFactoryUI.GetWeakPtr()));
else
fail(ERR_INVALID_URL);
}
@@ -178,7 +181,7 @@ void URLRequestCustomJob::redirect(const GURL &url)
QMutexLocker lock(&m_mutex);
m_redirect = url;
- content::BrowserThread::PostTask(content::BrowserThread::IO, FROM_HERE, base::Bind(&URLRequestCustomJob::notifyStarted, m_weakFactory.GetWeakPtr()));
+ content::BrowserThread::PostTask(content::BrowserThread::IO, FROM_HERE, base::Bind(&URLRequestCustomJob::notifyStarted, m_weakFactoryUI.GetWeakPtr()));
}
void URLRequestCustomJob::abort()
@@ -188,7 +191,7 @@ void URLRequestCustomJob::abort()
if (m_device && m_device->isOpen())
m_device->close();
m_device = 0;
- content::BrowserThread::PostTask(content::BrowserThread::IO, FROM_HERE, base::Bind(&URLRequestCustomJob::notifyCanceled, m_weakFactory.GetWeakPtr()));
+ content::BrowserThread::PostTask(content::BrowserThread::IO, FROM_HERE, base::Bind(&URLRequestCustomJob::notifyCanceled, m_weakFactoryUI.GetWeakPtr()));
}
void URLRequestCustomJob::notifyCanceled()
@@ -213,19 +216,23 @@ void URLRequestCustomJob::fail(int error)
DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
QMutexLocker lock(&m_mutex);
m_error = error;
- content::BrowserThread::PostTask(content::BrowserThread::IO, FROM_HERE, base::Bind(&URLRequestCustomJob::notifyFailure, m_weakFactory.GetWeakPtr()));
+ content::BrowserThread::PostTask(content::BrowserThread::IO, FROM_HERE, base::Bind(&URLRequestCustomJob::notifyFailure, m_weakFactoryUI.GetWeakPtr()));
}
void URLRequestCustomJob::notifyFailure()
{
DCHECK_CURRENTLY_ON(content::BrowserThread::IO);
- QMutexLocker lock(&m_mutex);
+ m_mutex.lock();
if (m_device)
m_device->close();
- if (m_started)
- NotifyDone(URLRequestStatus(URLRequestStatus::FAILED, m_error));
+ const URLRequestStatus status(URLRequestStatus::FAILED, m_error);
+ const bool started = m_started;
+ m_mutex.unlock();
+
+ if (started)
+ NotifyDone(status);
else
- NotifyStartError(URLRequestStatus(URLRequestStatus::FAILED, m_error));
+ NotifyStartError(status);
}
void URLRequestCustomJob::startAsync()
@@ -236,7 +243,8 @@ void URLRequestCustomJob::startAsync()
QMutexLocker lock(&m_mutex);
m_delegate = new URLRequestCustomJobDelegate(this);
lock.unlock();
- m_schemeHandler->handleJob(m_delegate);
+ QWebEngineUrlRequestJob *requestJob = new QWebEngineUrlRequestJob(m_delegate);
+ m_schemeHandler->requestStarted(requestJob);
}
} // namespace