diff options
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()) |