summaryrefslogtreecommitdiffstats
path: root/src/core
diff options
context:
space:
mode:
authorAllan Sandfeld Jensen <allan.jensen@theqtcompany.com>2016-05-12 14:35:34 +0200
committerAllan Sandfeld Jensen <allan.jensen@qt.io>2016-05-13 12:00:22 +0000
commitd1d64e6e66f53ccd4eb0a548e9ce726190ebae91 (patch)
tree19c25199910927ccb6535bf1be60b67e4d0ce02d /src/core
parent0f721b93f908828952b17f2f71a66c938f680fb1 (diff)
Better handle failure on read in custom url handlers
Chromium 49 expects url request failures to be reported as a response to either start or on read. So we should report failures during read and make sure we can handle QIODevice calling fail on the job. Change-Id: Id8f619d3cb6f187c99da580c6923130a95ca91ee Reviewed-by: Michael BrĂ¼ning <michael.bruning@theqtcompany.com>
Diffstat (limited to 'src/core')
-rw-r--r--src/core/url_request_custom_job.cpp18
-rw-r--r--src/core/url_request_custom_job.h2
2 files changed, 12 insertions, 8 deletions
diff --git a/src/core/url_request_custom_job.cpp b/src/core/url_request_custom_job.cpp
index 921be0b41..887222285 100644
--- a/src/core/url_request_custom_job.cpp
+++ b/src/core/url_request_custom_job.cpp
@@ -143,8 +143,12 @@ int URLRequestCustomJob::ReadRawData(IOBuffer *buf, int bufSize)
qint64 rv = m_shared->m_device ? m_shared->m_device->read(buf->data(), bufSize) : -1;
if (rv >= 0)
return static_cast<int>(rv);
- else
+ else {
+ // QIODevice::read might have called fail on us.
+ if (m_shared->m_error)
+ return m_shared->m_error;
return ERR_FAILED;
+ }
}
@@ -281,9 +285,11 @@ void URLRequestCustomJobShared::notifyStarted()
void URLRequestCustomJobShared::fail(int error)
{
- DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
QMutexLocker lock(&m_mutex);
m_error = error;
+ if (content::BrowserThread::CurrentlyOn(content::BrowserThread::IO))
+ return;
+ DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
if (!m_job)
return;
content::BrowserThread::PostTask(content::BrowserThread::IO, FROM_HERE, base::Bind(&URLRequestCustomJobShared::notifyFailure, m_weakFactory.GetWeakPtr()));
@@ -297,11 +303,9 @@ void URLRequestCustomJobShared::notifyFailure()
return;
if (m_device)
m_device->close();
- const URLRequestStatus status(URLRequestStatus::FAILED, m_error);
- if (m_started)
- m_job->SetStatus(status);
- else
- m_job->NotifyStartError(status);
+ if (!m_started)
+ m_job->NotifyStartError(URLRequestStatus::FromError(m_error));
+ // else we fail on the next read, or the read that might already be in progress
}
GURL URLRequestCustomJobShared::requestUrl()
diff --git a/src/core/url_request_custom_job.h b/src/core/url_request_custom_job.h
index 226c39e68..3fce76d36 100644
--- a/src/core/url_request_custom_job.h
+++ b/src/core/url_request_custom_job.h
@@ -61,7 +61,7 @@ public:
URLRequestCustomJob(net::URLRequest *request, net::NetworkDelegate *networkDelegate, const std::string &scheme, QWeakPointer<const BrowserContextAdapter> adapter);
virtual void Start() Q_DECL_OVERRIDE;
virtual void Kill() Q_DECL_OVERRIDE;
- virtual int ReadRawData(net::IOBuffer* buf, int buf_size) Q_DECL_OVERRIDE;;
+ virtual int ReadRawData(net::IOBuffer *buf, int buf_size) Q_DECL_OVERRIDE;
virtual bool GetMimeType(std::string *mimeType) const Q_DECL_OVERRIDE;
virtual bool GetCharset(std::string *charset) Q_DECL_OVERRIDE;
virtual bool IsRedirectResponse(GURL* location, int* http_status_code) Q_DECL_OVERRIDE;