diff options
author | Simon Hausmann <simon.hausmann@digia.com> | 2012-11-22 09:09:45 +0100 |
---|---|---|
committer | Simon Hausmann <simon.hausmann@digia.com> | 2012-11-22 09:10:13 +0100 |
commit | 470286ecfe79d59df14944e5b5d34630fc739391 (patch) | |
tree | 43983212872e06cebefd2ae474418fa2908ca54c /Source/WebCore/platform/network/qt/QNetworkReplyHandler.cpp | |
parent | 23037105e948c2065da5a937d3a2396b0ff45c1e (diff) |
Imported WebKit commit e89504fa9195b2063b2530961d4b73dd08de3242 (http://svn.webkit.org/repository/webkit/trunk@135485)
Change-Id: I03774e5ac79721c13ffa30d152537a74d0b12e66
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
Diffstat (limited to 'Source/WebCore/platform/network/qt/QNetworkReplyHandler.cpp')
-rw-r--r-- | Source/WebCore/platform/network/qt/QNetworkReplyHandler.cpp | 97 |
1 files changed, 43 insertions, 54 deletions
diff --git a/Source/WebCore/platform/network/qt/QNetworkReplyHandler.cpp b/Source/WebCore/platform/network/qt/QNetworkReplyHandler.cpp index 8abcf8c07..b83f2ba08 100644 --- a/Source/WebCore/platform/network/qt/QNetworkReplyHandler.cpp +++ b/Source/WebCore/platform/network/qt/QNetworkReplyHandler.cpp @@ -21,7 +21,7 @@ #include "config.h" #include "QNetworkReplyHandler.h" -#include "BlobRegistryImpl.h" +#include "BlobData.h" #include "HTTPParsers.h" #include "MIMETypeRegistry.h" #include "ResourceHandle.h" @@ -61,68 +61,19 @@ FormDataIODevice::~FormDataIODevice() delete m_currentFile; } -#if ENABLE(BLOB) -static void appendBlobResolved(FormData* formData, const KURL& url) -{ - RefPtr<BlobStorageData> blobData = static_cast<BlobRegistryImpl&>(blobRegistry()).getBlobDataFromURL(KURL(ParsedURLString, url)); - if (blobData) { - BlobDataItemList::const_iterator it = blobData->items().begin(); - const BlobDataItemList::const_iterator itend = blobData->items().end(); - for (; it != itend; ++it) { - const BlobDataItem& blobItem = *it; - if (blobItem.type == BlobDataItem::Data) - formData->appendData(blobItem.data->data() + static_cast<int>(blobItem.offset), static_cast<int>(blobItem.length)); - else if (blobItem.type == BlobDataItem::File) - formData->appendFileRange(blobItem.path, blobItem.offset, blobItem.length, blobItem.expectedModificationTime); - else if (blobItem.type == BlobDataItem::Blob) - appendBlobResolved(formData, blobItem.url); - else - ASSERT_NOT_REACHED(); - } - } -} -#endif - void FormDataIODevice::prepareFormElements(FormData* formData) { if (!formData) return; -#if ENABLE(BLOB) - bool hasBlob = false; - Vector<FormDataElement>::const_iterator it = formData->elements().begin(); - const Vector<FormDataElement>::const_iterator itend = formData->elements().end(); - for (; it != itend; ++it) { - if (it->m_type == FormDataElement::encodedBlob) { - hasBlob = true; - break; - } - } + RefPtr<FormData> formDataRef(formData); - // Resolve all blobs so we only have file and data. - if (hasBlob) { - RefPtr<FormData> newFormData = FormData::create(); - newFormData->setAlwaysStream(formData->alwaysStream()); - newFormData->setIdentifier(formData->identifier()); - it = formData->elements().begin(); - for (; it != itend; ++it) { - const FormDataElement& element = *it; - if (element.m_type == FormDataElement::data) - newFormData->appendData(element.m_data.data(), element.m_data.size()); - else if (element.m_type == FormDataElement::encodedFile) - newFormData->appendFileRange(element.m_filename, element.m_fileStart, element.m_fileLength, element.m_expectedFileModificationTime, element.m_shouldGenerateFile); - else if (element.m_type == FormDataElement::encodedBlob) - appendBlobResolved(newFormData.get(), element.m_url); - else - ASSERT_NOT_REACHED(); - } - m_formElements = newFormData->elements(); - return; - } +#if ENABLE(BLOB) + formDataRef = formDataRef->resolveBlobReferences(); #endif // Take a deep copy of the FormDataElements - m_formElements = formData->elements(); + m_formElements = formDataRef->elements(); } @@ -514,6 +465,7 @@ QNetworkReply* QNetworkReplyHandler::release() if (!m_replyWrapper) return 0; + m_timeoutTimer.stop(); QNetworkReply* reply = m_replyWrapper->release(); m_replyWrapper = nullptr; return reply; @@ -539,6 +491,7 @@ static bool shouldIgnoreHttpError(QNetworkReply* reply, bool receivedData) void QNetworkReplyHandler::finish() { ASSERT(m_replyWrapper && m_replyWrapper->reply() && !wasAborted()); + m_timeoutTimer.stop(); ResourceHandleClient* client = m_resourceHandle->client(); if (!client) { @@ -560,6 +513,38 @@ void QNetworkReplyHandler::finish() m_replyWrapper = nullptr; } +void QNetworkReplyHandler::timeout() +{ + if (!m_replyWrapper || wasAborted()) + return; + + // The request is already finished, but is probably just waiting in the queue to get processed. + // In this case we ignore the timeout and proceed as normal. + if (m_replyWrapper->isFinished()) + return; + + ResourceHandleClient* client = m_resourceHandle->client(); + if (!client) { + m_replyWrapper.clear(); + return; + } + + ASSERT(m_replyWrapper->reply()); + + ResourceError timeoutError("QtNetwork", QNetworkReply::TimeoutError, m_replyWrapper->reply()->url().toString(), "Request timed out"); + timeoutError.setIsTimeout(true); + client->didFail(m_resourceHandle, timeoutError); + + m_replyWrapper.clear(); +} + +void QNetworkReplyHandler::timerEvent(QTimerEvent* timerEvent) +{ + ASSERT_UNUSED(timerEvent, timerEvent->timerId()== m_timeoutTimer.timerId()); + m_timeoutTimer.stop(); + timeout(); +} + void QNetworkReplyHandler::sendResponseIfNeeded() { ASSERT(m_replyWrapper && m_replyWrapper->reply() && !wasAborted()); @@ -781,6 +766,10 @@ void QNetworkReplyHandler::start() return; } + double timeoutInSeconds = d->m_firstRequest.timeoutInterval(); + if (timeoutInSeconds > 0 && timeoutInSeconds < (INT_MAX / 1000)) + m_timeoutTimer.start(timeoutInSeconds * 1000, this); + if (m_resourceHandle->firstRequest().reportUploadProgress()) connect(m_replyWrapper->reply(), SIGNAL(uploadProgress(qint64, qint64)), this, SLOT(uploadProgress(qint64, qint64))); } |