summaryrefslogtreecommitdiff
path: root/Source/WebKit2/NetworkProcess/Downloads/qt/QtFileDownloader.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'Source/WebKit2/NetworkProcess/Downloads/qt/QtFileDownloader.cpp')
-rw-r--r--Source/WebKit2/NetworkProcess/Downloads/qt/QtFileDownloader.cpp34
1 files changed, 24 insertions, 10 deletions
diff --git a/Source/WebKit2/NetworkProcess/Downloads/qt/QtFileDownloader.cpp b/Source/WebKit2/NetworkProcess/Downloads/qt/QtFileDownloader.cpp
index abed3cd34..2eaed702d 100644
--- a/Source/WebKit2/NetworkProcess/Downloads/qt/QtFileDownloader.cpp
+++ b/Source/WebKit2/NetworkProcess/Downloads/qt/QtFileDownloader.cpp
@@ -24,6 +24,7 @@
#include "Download.h"
#include "HTTPParsers.h"
#include "MIMETypeRegistry.h"
+#include "NetworkProcess.h"
#include <QCoreApplication>
#include <QFile>
#include <QFileInfo>
@@ -37,12 +38,25 @@ using namespace WTF;
namespace WebKit {
-QtFileDownloader::QtFileDownloader(Download* download, QNetworkReply* reply)
+QtFileDownloader::QtFileDownloader(Download& download, const QNetworkRequest& request)
: m_download(download)
- , m_reply(reply)
+ , m_reply(NetworkProcess::singleton().networkAccessManager().get(request))
, m_error(QNetworkReply::NoError)
- , m_headersRead(false)
{
+ makeConnections();
+}
+
+QtFileDownloader::QtFileDownloader(Download& download, QNetworkReply* reply)
+ : m_download(download)
+ , m_reply(reply)
+ , m_error(reply->error())
+{
+ makeConnections();
+
+ if (reply->isFinished())
+ onFinished();
+ else if (reply->isReadable())
+ onReadyRead();
}
QtFileDownloader::~QtFileDownloader()
@@ -53,7 +67,7 @@ QtFileDownloader::~QtFileDownloader()
abortDownloadWritingAndEmitError(QtFileDownloader::DownloadErrorAborted);
}
-void QtFileDownloader::init()
+void QtFileDownloader::makeConnections()
{
connect(m_reply.get(), SIGNAL(readyRead()), SLOT(onReadyRead()));
connect(m_reply.get(), SIGNAL(finished()), SLOT(onFinished()));
@@ -86,7 +100,7 @@ void QtFileDownloader::startTransfer(const QString& decidedFilePath)
// finished shall be called in the end.
m_destinationFile = WTFMove(downloadFile);
- m_download->didCreateDestination(m_destinationFile->fileName());
+ m_download.didCreateDestination(m_destinationFile->fileName());
// We might have gotten readyRead already even before this function
// was called.
@@ -105,7 +119,7 @@ void QtFileDownloader::abortDownloadWritingAndEmitError(QtFileDownloader::Downlo
// On network failures it's QNetworkReplyHandler::errorForReply who will handle errors.
if (errorCode == QtFileDownloader::DownloadErrorNetworkFailure) {
- m_download->didFail(QNetworkReplyHandler::errorForReply(m_reply.get()), IPC::DataReference(0, 0));
+ m_download.didFail(QNetworkReplyHandler::errorForReply(m_reply.get()), IPC::DataReference(0, 0));
return;
}
@@ -135,7 +149,7 @@ void QtFileDownloader::abortDownloadWritingAndEmitError(QtFileDownloader::Downlo
ResourceError downloadError("Download", errorCode, m_reply->url(), translatedErrorMessage);
- m_download->didFail(downloadError, IPC::DataReference(0, 0));
+ m_download.didFail(downloadError, IPC::DataReference(0, 0));
}
void QtFileDownloader::handleDownloadResponse()
@@ -151,7 +165,7 @@ void QtFileDownloader::handleDownloadResponse()
mimeType = MIMETypeRegistry::getMIMETypeForPath(m_reply->url().path());
ResourceResponse response(m_reply->url(), mimeType, m_reply->header(QNetworkRequest::ContentLengthHeader).toLongLong(), encoding);
- m_download->didReceiveResponse(response);
+ m_download.didReceiveResponse(response);
}
void QtFileDownloader::onReadyRead()
@@ -172,7 +186,7 @@ void QtFileDownloader::onReadyRead()
// does not actually represent an error.
ASSERT(bytesWritten == content.size());
- m_download->didReceiveData(bytesWritten);
+ m_download.didReceiveData(bytesWritten);
} else if (!m_headersRead) {
handleDownloadResponse();
m_headersRead = true;
@@ -195,7 +209,7 @@ void QtFileDownloader::onFinished()
m_destinationFile = nullptr;
if (m_error == QNetworkReply::NoError)
- m_download->didFinish();
+ m_download.didFinish();
else if (m_error == QNetworkReply::OperationCanceledError)
abortDownloadWritingAndEmitError(QtFileDownloader::DownloadErrorCancelled);
else