diff options
author | Allan Sandfeld Jensen <allan.jensen@digia.com> | 2013-09-13 12:51:20 +0200 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2013-09-19 20:50:05 +0200 |
commit | d441d6f39bb846989d95bcf5caf387b42414718d (patch) | |
tree | e367e64a75991c554930278175d403c072de6bb8 /Source/WebCore/fileapi/Blob.cpp | |
parent | 0060b2994c07842f4c59de64b5e3e430525c4b90 (diff) | |
download | qtwebkit-d441d6f39bb846989d95bcf5caf387b42414718d.tar.gz |
Import Qt5x2 branch of QtWebkit for Qt 5.2
Importing a new snapshot of webkit.
Change-Id: I2d01ad12cdc8af8cb015387641120a9d7ea5f10c
Reviewed-by: Allan Sandfeld Jensen <allan.jensen@digia.com>
Diffstat (limited to 'Source/WebCore/fileapi/Blob.cpp')
-rw-r--r-- | Source/WebCore/fileapi/Blob.cpp | 73 |
1 files changed, 71 insertions, 2 deletions
diff --git a/Source/WebCore/fileapi/Blob.cpp b/Source/WebCore/fileapi/Blob.cpp index 291a22729..7640f5f50 100644 --- a/Source/WebCore/fileapi/Blob.cpp +++ b/Source/WebCore/fileapi/Blob.cpp @@ -37,6 +37,7 @@ #include "ScriptCallStack.h" #include "ScriptExecutionContext.h" #include "ThreadableBlobRegistry.h" +#include <wtf/text/CString.h> namespace WebCore { @@ -73,7 +74,7 @@ Blob::Blob(PassOwnPtr<BlobData> blobData, long long size) } Blob::Blob(const KURL& srcURL, const String& type, long long size) - : m_type(type) + : m_type(Blob::normalizedContentType(type)) , m_size(size) { // Create a new internal URL and register it with the same blob data as the source URL. @@ -86,6 +87,74 @@ Blob::~Blob() ThreadableBlobRegistry::unregisterBlobURL(m_internalURL); } +bool Blob::isValidContentType(const String& contentType) +{ + if (contentType.isNull()) + return true; + + size_t length = contentType.length(); + if (contentType.is8Bit()) { + const LChar* characters = contentType.characters8(); + for (size_t i = 0; i < length; ++i) { + if (characters[i] < 0x20 || characters[i] > 0x7e) + return false; + } + } else { + const UChar* characters = contentType.characters16(); + for (size_t i = 0; i < length; ++i) { + if (characters[i] < 0x20 || characters[i] > 0x7e) + return false; + } + } + return true; +} + +String Blob::normalizedContentType(const String& contentType) +{ + if (Blob::isValidContentType(contentType)) + return contentType.lower(); + return emptyString(); +} + +bool Blob::isNormalizedContentType(const String& contentType) +{ + if (contentType.isNull()) + return true; + + size_t length = contentType.length(); + if (contentType.is8Bit()) { + const LChar* characters = contentType.characters8(); + for (size_t i = 0; i < length; ++i) { + if (characters[i] < 0x20 || characters[i] > 0x7e) + return false; + if (characters[i] >= 'A' && characters[i] <= 'Z') + return false; + } + } else { + const UChar* characters = contentType.characters16(); + for (size_t i = 0; i < length; ++i) { + if (characters[i] < 0x20 || characters[i] > 0x7e) + return false; + if (characters[i] >= 'A' && characters[i] <= 'Z') + return false; + } + } + return true; +} + +bool Blob::isNormalizedContentType(const CString& contentType) +{ + size_t length = contentType.length(); + const char* characters = contentType.data(); + for (size_t i = 0; i < length; ++i) { + if (characters[i] < 0x20 || characters[i] > 0x7e) + return false; + if (characters[i] >= 'A' && characters[i] <= 'Z') + return false; + } + return true; +} + #if ENABLE(BLOB) PassRefPtr<Blob> Blob::slice(long long start, long long end, const String& contentType) const { @@ -122,7 +191,7 @@ PassRefPtr<Blob> Blob::slice(long long start, long long end, const String& conte long long length = end - start; OwnPtr<BlobData> blobData = BlobData::create(); - blobData->setContentType(contentType); + blobData->setContentType(Blob::normalizedContentType(contentType)); if (isFile()) { #if ENABLE(FILE_SYSTEM) if (!toFile(this)->fileSystemURL().isEmpty()) |