diff options
author | Allan Sandfeld Jensen <allan.jensen@digia.com> | 2013-09-26 13:34:48 +0200 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2013-09-26 13:35:54 +0200 |
commit | 102ad5434962aac394add4ea1e7c0c21465b8250 (patch) | |
tree | f842a389c70e36a2eb7d9734af23a08d5e3b07ea /Source/WebCore/platform | |
parent | 6704d913bde48a666f8e8a8a0cb737c0c49f581c (diff) |
[Qt] Crash when trying to download blob url
https://bugs.webkit.org/show_bug.cgi?id=121681
Reviewed by Simon Hausmann.
Source/WebCore:
Resolve any blob URLs before creating a QUrl.
* platform/network/qt/ResourceRequestQt.cpp:
(WebCore::appendBlobResolved):
(WebCore::resolveBlobUrl):
(WebCore::ResourceRequest::toNetworkRequest):
Source/WebKit/qt:
Do not crash if a download was triggered on a resource WebCore handles internally.
* WebCoreSupport/FrameLoaderClientQt.cpp:
(WebCore::FrameLoaderClientQt::convertMainResourceLoadToDownload):
Change-Id: I9191eb991be81f69df4328ab54132da3dde15241
git-svn-id: http://svn.webkit.org/repository/webkit/trunk@156330 268f45cc-cd09-0410-ab3c-d52691b4dbfc
Reviewed-by: Allan Sandfeld Jensen <allan.jensen@digia.com>
Diffstat (limited to 'Source/WebCore/platform')
-rw-r--r-- | Source/WebCore/platform/network/qt/ResourceRequestQt.cpp | 58 |
1 files changed, 57 insertions, 1 deletions
diff --git a/Source/WebCore/platform/network/qt/ResourceRequestQt.cpp b/Source/WebCore/platform/network/qt/ResourceRequestQt.cpp index e84e677a5..46229027e 100644 --- a/Source/WebCore/platform/network/qt/ResourceRequestQt.cpp +++ b/Source/WebCore/platform/network/qt/ResourceRequestQt.cpp @@ -22,6 +22,12 @@ #include "ResourceRequest.h" #include "ThirdPartyCookiesQt.h" +#if ENABLE(BLOB) +#include "BlobData.h" +#include "BlobRegistryImpl.h" +#include "BlobStorageData.h" +#endif + #include <qglobal.h> #include <QNetworkRequest> @@ -40,10 +46,60 @@ unsigned initializeMaximumHTTPConnectionCountPerHost() return 6 * (1 + 3 + 2); } +#if ENABLE(BLOB) +static void appendBlobResolved(QByteArray& data, const QUrl& url, QString* contentType = 0) +{ + RefPtr<BlobStorageData> blobData = static_cast<BlobRegistryImpl&>(blobRegistry()).getBlobDataFromURL(url); + if (!blobData) + return; + + if (contentType) + *contentType = blobData->contentType(); + + 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) + data.append(blobItem.data->data() + static_cast<int>(blobItem.offset), static_cast<int>(blobItem.length)); + else if (blobItem.type == BlobDataItem::Blob) + appendBlobResolved(data, blobItem.url); + else if (blobItem.type == BlobDataItem::File) { + // File types are not allowed here, so just ignore it. + } else + ASSERT_NOT_REACHED(); + } +} + +static void resolveBlobUrl(const QUrl& url, QUrl& resolvedUrl) +{ + RefPtr<BlobStorageData> blobData = static_cast<BlobRegistryImpl&>(blobRegistry()).getBlobDataFromURL(url); + if (!blobData) + return; + + QByteArray data; + QString contentType; + appendBlobResolved(data, url, &contentType); + + QString dataUri(QStringLiteral("data:")); + dataUri.append(contentType); + dataUri.append(QStringLiteral(";base64,")); + dataUri.append(QString::fromLatin1(data.toBase64())); + resolvedUrl = QUrl(dataUri); +} +#endif + QNetworkRequest ResourceRequest::toNetworkRequest(NetworkingContext *context) const { QNetworkRequest request; - request.setUrl(url()); + QUrl newurl = url(); + +#if ENABLE(BLOB) + if (newurl.scheme() == QLatin1String("blob")) + resolveBlobUrl(url(), newurl); +#endif + + request.setUrl(newurl); request.setOriginatingObject(context ? context->originatingObject() : 0); const HTTPHeaderMap &headers = httpHeaderFields(); |