diff options
author | Simon Hausmann <simon.hausmann@nokia.com> | 2012-06-20 13:01:08 +0200 |
---|---|---|
committer | Simon Hausmann <simon.hausmann@nokia.com> | 2012-06-20 13:01:08 +0200 |
commit | 49233e234e5c787396cadb2cea33b31ae0cd65c1 (patch) | |
tree | 5410cb9a8fd53168bb60d62c54b654d86f03c38d /Source/WebCore/fileapi | |
parent | b211c645d8ab690f713515dfdc84d80b11c27d2c (diff) | |
download | qtwebkit-49233e234e5c787396cadb2cea33b31ae0cd65c1.tar.gz |
Imported WebKit commit 3a8c29f35d00659d2ce7a0ccdfa8304f14e82327 (http://svn.webkit.org/repository/webkit/trunk@120813)
New snapshot with Windows build fixes
Diffstat (limited to 'Source/WebCore/fileapi')
20 files changed, 152 insertions, 223 deletions
diff --git a/Source/WebCore/fileapi/Blob.cpp b/Source/WebCore/fileapi/Blob.cpp index 2385ec7d1..d1dcb51ab 100644 --- a/Source/WebCore/fileapi/Blob.cpp +++ b/Source/WebCore/fileapi/Blob.cpp @@ -33,10 +33,23 @@ #include "BlobURL.h" #include "File.h" +#include "HistogramSupport.h" +#include "ScriptExecutionContext.h" #include "ThreadableBlobRegistry.h" namespace WebCore { +namespace { + +// Used in histograms to see when we can actually deprecate the prefixed slice. +enum SliceHistogramEnum { + SliceWithoutPrefix, + SliceWithPrefix, + SliceHistogramEnumMax, +}; + +} // namespace + Blob::Blob() : m_size(0) { @@ -64,7 +77,7 @@ Blob::Blob(const KURL& srcURL, const String& type, long long size) { // Create a new internal URL and register it with the same blob data as the source URL. m_internalURL = BlobURL::createInternalURL(); - ThreadableBlobRegistry::registerBlobURL(m_internalURL, srcURL); + ThreadableBlobRegistry::registerBlobURL(0, m_internalURL, srcURL); } Blob::~Blob() @@ -73,7 +86,22 @@ Blob::~Blob() } #if ENABLE(BLOB) -PassRefPtr<Blob> Blob::webkitSlice(long long start, long long end, const String& contentType) const +PassRefPtr<Blob> Blob::slice(long long start, long long end, const String& contentType) const +{ + HistogramSupport::histogramEnumeration("WebCore.Blob.slice", SliceWithoutPrefix, SliceHistogramEnumMax); + return sliceInternal(start, end, contentType); +} + +PassRefPtr<Blob> Blob::webkitSlice(ScriptExecutionContext* context, long long start, long long end, const String& contentType) const +{ + String message("Blob.webkitSlice() is deprecated. Use Blob.slice() instead."); + context->addConsoleMessage(JSMessageSource, LogMessageType, WarningMessageLevel, message); + + HistogramSupport::histogramEnumeration("WebCore.Blob.slice", SliceWithPrefix, SliceHistogramEnumMax); + return sliceInternal(start, end, contentType); +} + +PassRefPtr<Blob> Blob::sliceInternal(long long start, long long end, const String& contentType) const { // When we slice a file for the first time, we obtain a snapshot of the file by capturing its current size and modification time. // The modification time will be used to verify if the file has been changed or not, when the underlying data are accessed. diff --git a/Source/WebCore/fileapi/Blob.h b/Source/WebCore/fileapi/Blob.h index 9bc6234ac..1ef30d972 100644 --- a/Source/WebCore/fileapi/Blob.h +++ b/Source/WebCore/fileapi/Blob.h @@ -41,6 +41,8 @@ namespace WebCore { +class ScriptExecutionContext; + class Blob : public RefCounted<Blob> { public: static PassRefPtr<Blob> create() @@ -68,7 +70,11 @@ public: virtual bool isFile() const { return false; } #if ENABLE(BLOB) - PassRefPtr<Blob> webkitSlice(long long start = 0, long long end = std::numeric_limits<long long>::max(), const String& contentType = String()) const; + PassRefPtr<Blob> slice(long long start = 0, long long end = std::numeric_limits<long long>::max(), const String& contentType = String()) const; + + // Prefixed version is deprecated. This internally calls sliceInternal() (as slice() does) after showing a deprecation message. + PassRefPtr<Blob> webkitSlice(ScriptExecutionContext*, long long start = 0, long long end = std::numeric_limits<long long>::max(), const String& contentType = String()) const; + #endif protected: @@ -78,6 +84,10 @@ protected: // For deserialization. Blob(const KURL& srcURL, const String& type, long long size); +#if ENABLE(BLOB) + PassRefPtr<Blob> sliceInternal(long long start, long long end, const String& contentType) const; +#endif + // This is an internal URL referring to the blob data associated with this object. It serves // as an identifier for this blob. The internal URL is never used to source the blob's content // into an HTML or for FileRead'ing, public blob URLs must be used for those purposes. diff --git a/Source/WebCore/fileapi/Blob.idl b/Source/WebCore/fileapi/Blob.idl index 6b7e59d22..b44eb4375 100644 --- a/Source/WebCore/fileapi/Blob.idl +++ b/Source/WebCore/fileapi/Blob.idl @@ -42,7 +42,11 @@ module html { #if !defined(LANGUAGE_OBJECTIVE_C) #if defined(ENABLE_BLOB) && ENABLE_BLOB - Blob webkitSlice(in [Optional] long long start, in [Optional] long long end, in [Optional, TreatNullAs=NullString, TreatUndefinedAs=NullString] DOMString contentType); + Blob slice(in [Optional] long long start, in [Optional] long long end, in [Optional, TreatNullAs=NullString, TreatUndefinedAs=NullString] DOMString contentType); +#if !defined(LANGUAGE_GOBJECT) || !LANGUAGE_GOBJECT + // Prefixed version is going to be deprecated. + [CallWith=ScriptExecutionContext] Blob webkitSlice(in [Optional] long long start, in [Optional] long long end, in [Optional, TreatNullAs=NullString, TreatUndefinedAs=NullString] DOMString contentType); +#endif #endif #endif }; diff --git a/Source/WebCore/fileapi/BlobURL.cpp b/Source/WebCore/fileapi/BlobURL.cpp index 5d79141a5..f7478534c 100644 --- a/Source/WebCore/fileapi/BlobURL.cpp +++ b/Source/WebCore/fileapi/BlobURL.cpp @@ -52,6 +52,15 @@ KURL BlobURL::createInternalURL() return createBlobURL("blobinternal://"); } +String BlobURL::getOrigin(const KURL& url) +{ + ASSERT(url.protocolIs(kBlobProtocol)); + + unsigned startIndex = url.pathStart(); + unsigned endIndex = url.pathAfterLastSlash(); + return url.string().substring(startIndex, endIndex - startIndex - 1); +} + String BlobURL::getIdentifier(const KURL& url) { ASSERT(url.protocolIs(kBlobProtocol)); @@ -63,8 +72,6 @@ String BlobURL::getIdentifier(const KURL& url) KURL BlobURL::createBlobURL(const String& originString) { ASSERT(!originString.isEmpty()); - if (originString == "null") - return KURL(); String urlString = kBlobProtocol; urlString += ":"; urlString += encodeWithURLEscapeSequences(originString); diff --git a/Source/WebCore/fileapi/BlobURL.h b/Source/WebCore/fileapi/BlobURL.h index 4ea59fefe..2caec2957 100644 --- a/Source/WebCore/fileapi/BlobURL.h +++ b/Source/WebCore/fileapi/BlobURL.h @@ -50,6 +50,7 @@ class BlobURL { public: static KURL createPublicURL(SecurityOrigin*); static KURL createInternalURL(); + static String getOrigin(const KURL&); static String getIdentifier(const KURL&); static const char* blobProtocol() { return kBlobProtocol; } diff --git a/Source/WebCore/fileapi/File.cpp b/Source/WebCore/fileapi/File.cpp index 86d59894f..5f8b93b78 100644 --- a/Source/WebCore/fileapi/File.cpp +++ b/Source/WebCore/fileapi/File.cpp @@ -86,7 +86,7 @@ File::File(const String& path) , m_name(pathGetFileName(path)) #if ENABLE(FILE_SYSTEM) , m_snapshotSize(-1) - , m_snapshotModificationTime(0) + , m_snapshotModificationTime(invalidFileTime()) #endif { } @@ -96,7 +96,7 @@ File::File(const String& path, const KURL& url, const String& type) , m_path(path) #if ENABLE(FILE_SYSTEM) , m_snapshotSize(-1) - , m_snapshotModificationTime(0) + , m_snapshotModificationTime(invalidFileTime()) #endif { m_name = pathGetFileName(path); @@ -111,7 +111,7 @@ File::File(const String& path, const String& name) , m_name(name) #if ENABLE(FILE_SYSTEM) , m_snapshotSize(-1) - , m_snapshotModificationTime(0) + , m_snapshotModificationTime(invalidFileTime()) #endif { } @@ -136,18 +136,12 @@ double File::lastModifiedDate() const time_t modificationTime; if (!getFileModificationTime(m_path, modificationTime)) - return 0; + return invalidFileTime(); // Needs to return epoch time in milliseconds for Date. return modificationTime * 1000.0; } -double File::lastModifiedDateForBinding() const -{ - double value = lastModifiedDate(); - return (!value) ? std::numeric_limits<double>::quiet_NaN() : value; -} - unsigned long long File::size() const { #if ENABLE(FILE_SYSTEM) @@ -178,7 +172,7 @@ void File::captureSnapshot(long long& snapshotSize, double& snapshotModification FileMetadata metadata; if (!getFileMetadata(m_path, metadata)) { snapshotSize = 0; - snapshotModificationTime = 0; + snapshotModificationTime = invalidFileTime(); return; } diff --git a/Source/WebCore/fileapi/File.h b/Source/WebCore/fileapi/File.h index 67f31f6a7..e3ca2a5a8 100644 --- a/Source/WebCore/fileapi/File.h +++ b/Source/WebCore/fileapi/File.h @@ -56,7 +56,7 @@ public: #if ENABLE(FILE_SYSTEM) // If filesystem files live in the remote filesystem, the port might pass the valid metadata (whose length field is non-negative) and cache in the File object. // - // Otherwise calling size(), lastModifiedTime() and webkitSlice() will synchronously query the file metadata. + // Otherwise calling size(), lastModifiedTime() and slice() will synchronously query the file metadata. static PassRefPtr<File> createForFileSystemFile(const String& name, const FileMetadata& metadata) { return adoptRef(new File(name, metadata)); @@ -77,12 +77,9 @@ public: const String& path() const { return m_path; } const String& name() const { return m_name; } - // This may return zero if getFileModificationTime() platform call has failed or zero snapshot lastModifiedTime is given at construction time. + // This may return NaN (which is converted to null Date in javascript layer) if getFileModificationTime() platform call has failed or the information is not available. double lastModifiedDate() const; - // For binding. We want to return null Date if we get the value 0 Date (which is used to indicate the information is unavailable). - double lastModifiedDateForBinding() const; - #if ENABLE(DIRECTORY_UPLOAD) // Returns the relative path of this file in the context of a directory selection. const String& webkitRelativePath() const { return m_relativePath; } diff --git a/Source/WebCore/fileapi/File.idl b/Source/WebCore/fileapi/File.idl index 00bdde6f5..7c0de4309 100644 --- a/Source/WebCore/fileapi/File.idl +++ b/Source/WebCore/fileapi/File.idl @@ -32,7 +32,7 @@ module html { ] File : Blob { readonly attribute DOMString name; #if !defined(LANGUAGE_GOBJECT) || !LANGUAGE_GOBJECT - readonly attribute [ImplementedAs=lastModifiedDateForBinding] Date lastModifiedDate; + readonly attribute Date lastModifiedDate; #endif #if defined(ENABLE_DIRECTORY_UPLOAD) && ENABLE_DIRECTORY_UPLOAD readonly attribute DOMString webkitRelativePath; diff --git a/Source/WebCore/fileapi/FileList.idl b/Source/WebCore/fileapi/FileList.idl index 0cdf86116..14139a763 100644 --- a/Source/WebCore/fileapi/FileList.idl +++ b/Source/WebCore/fileapi/FileList.idl @@ -30,7 +30,7 @@ module html { JSNoStaticTables ] FileList { readonly attribute unsigned long length; - File item(in [IsIndex] unsigned long index); + File item(in unsigned long index); }; } diff --git a/Source/WebCore/fileapi/FileReader.cpp b/Source/WebCore/fileapi/FileReader.cpp index bdae05942..0f245c211 100644 --- a/Source/WebCore/fileapi/FileReader.cpp +++ b/Source/WebCore/fileapi/FileReader.cpp @@ -35,9 +35,9 @@ #include "FileReader.h" #include "CrossThreadTask.h" +#include "ExceptionCode.h" #include "File.h" #include "Logging.h" -#include "OperationNotAllowedException.h" #include "ProgressEvent.h" #include "ScriptExecutionContext.h" #include <wtf/ArrayBuffer.h> @@ -133,9 +133,9 @@ void FileReader::readAsDataURL(Blob* blob, ExceptionCode& ec) void FileReader::readInternal(Blob* blob, FileReaderLoader::ReadType type, ExceptionCode& ec) { - // If multiple concurrent read methods are called on the same FileReader, OperationNotAllowedException should be thrown when the state is LOADING. + // If multiple concurrent read methods are called on the same FileReader, INVALID_STATE_ERR should be thrown when the state is LOADING. if (m_state == LOADING) { - ec = OperationNotAllowedException::NOT_ALLOWED_ERR; + ec = INVALID_STATE_ERR; return; } diff --git a/Source/WebCore/fileapi/FileReader.idl b/Source/WebCore/fileapi/FileReader.idl index 9a6440c30..51fe7128b 100644 --- a/Source/WebCore/fileapi/FileReader.idl +++ b/Source/WebCore/fileapi/FileReader.idl @@ -46,13 +46,13 @@ module html { // async read methods void readAsArrayBuffer(in Blob blob) - raises(OperationNotAllowedException); + raises(DOMException); void readAsBinaryString(in Blob blob) - raises(OperationNotAllowedException); + raises(DOMException); void readAsText(in Blob blob, in [Optional] DOMString encoding) - raises(OperationNotAllowedException); + raises(DOMException); void readAsDataURL(in Blob blob) - raises(OperationNotAllowedException); + raises(DOMException); void abort(); diff --git a/Source/WebCore/fileapi/FileReaderLoader.cpp b/Source/WebCore/fileapi/FileReaderLoader.cpp index e55149a31..46f04c44d 100644 --- a/Source/WebCore/fileapi/FileReaderLoader.cpp +++ b/Source/WebCore/fileapi/FileReaderLoader.cpp @@ -80,7 +80,7 @@ void FileReaderLoader::start(ScriptExecutionContext* scriptExecutionContext, Blo failed(FileError::SECURITY_ERR); return; } - ThreadableBlobRegistry::registerBlobURL(m_urlForReading, blob->url()); + ThreadableBlobRegistry::registerBlobURL(scriptExecutionContext->securityOrigin(), m_urlForReading, blob->url()); // Construct and load the request. ResourceRequest request(m_urlForReading); @@ -298,11 +298,8 @@ void FileReaderLoader::convertToDataURL() return; } - if (!m_dataType.isEmpty()) { - builder.append(m_dataType); - builder.append(";base64,"); - } else - builder.append("base64,"); + builder.append(m_dataType); + builder.append(";base64,"); Vector<char> out; base64Encode(static_cast<const char*>(m_rawData->data()), m_bytesLoaded, out); diff --git a/Source/WebCore/fileapi/OperationNotAllowedException.cpp b/Source/WebCore/fileapi/OperationNotAllowedException.cpp deleted file mode 100644 index 582176df7..000000000 --- a/Source/WebCore/fileapi/OperationNotAllowedException.cpp +++ /dev/null @@ -1,64 +0,0 @@ -/* - * Copyright (C) 2011 Google Inc. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of - * its contributors may be used to endorse or promote products derived - * from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY GOOGLE AND ITS CONTRIBUTORS "AS IS" AND ANY - * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY - * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#include "config.h" - -#if ENABLE(BLOB) - -#include "OperationNotAllowedException.h" - -namespace WebCore { - -static struct OperationNotAllowedExceptionNameDescription { - const char* const name; - const char* const description; -} operationNotAllowedExceptions[] = { - { "NOT_ALLOWED_ERR", "A read method was called while the object was in the LOADING state due to a previous read call." } -}; - -bool OperationNotAllowedException::initializeDescription(ExceptionCode ec, ExceptionCodeDescription* description) -{ - if (ec < OperationNotAllowedExceptionOffset || ec > OperationNotAllowedExceptionMax) - return false; - - description->typeName = "DOM OperationNotAllowed"; - description->code = ec - OperationNotAllowedExceptionOffset; - description->type = OperationNotAllowedExceptionType; - - size_t tableSize = WTF_ARRAY_LENGTH(operationNotAllowedExceptions); - size_t tableIndex = ec - NOT_ALLOWED_ERR; - - description->name = tableIndex < tableSize ? operationNotAllowedExceptions[tableIndex].name : 0; - description->description = tableIndex < tableSize ? operationNotAllowedExceptions[tableIndex].description : 0; - - return true; -} - -} // namespace WebCore - -#endif // ENABLE(BLOB) diff --git a/Source/WebCore/fileapi/OperationNotAllowedException.h b/Source/WebCore/fileapi/OperationNotAllowedException.h deleted file mode 100644 index 5a0e9a1c5..000000000 --- a/Source/WebCore/fileapi/OperationNotAllowedException.h +++ /dev/null @@ -1,67 +0,0 @@ -/* - * Copyright (C) 2011 Google Inc. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following disclaimer - * in the documentation and/or other materials provided with the - * distribution. - * * Neither the name of Google Inc. nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#ifndef OperationNotAllowedException_h -#define OperationNotAllowedException_h - -#if ENABLE(BLOB) - -#include "ExceptionBase.h" - -namespace WebCore { - -class OperationNotAllowedException : public ExceptionBase { -public: - static PassRefPtr<OperationNotAllowedException> create(const ExceptionCodeDescription& description) - { - return adoptRef(new OperationNotAllowedException(description)); - } - - static const int OperationNotAllowedExceptionOffset = 1300; - static const int OperationNotAllowedExceptionMax = 1399; - - enum OperationNotAllowedExceptionCode { - NOT_ALLOWED_ERR = OperationNotAllowedExceptionOffset + 1, - }; - - static bool initializeDescription(ExceptionCode, ExceptionCodeDescription*); - -private: - OperationNotAllowedException(const ExceptionCodeDescription& description) - : ExceptionBase(description) - { - } -}; - -} // namespace WebCore - -#endif // ENABLE(BLOB) - -#endif // OperationNotAllowedException_h diff --git a/Source/WebCore/fileapi/OperationNotAllowedException.idl b/Source/WebCore/fileapi/OperationNotAllowedException.idl deleted file mode 100644 index 50040df60..000000000 --- a/Source/WebCore/fileapi/OperationNotAllowedException.idl +++ /dev/null @@ -1,48 +0,0 @@ -/* - * Copyright (C) 2011 Google Inc. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following disclaimer - * in the documentation and/or other materials provided with the - * distribution. - * * Neither the name of Google Inc. nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -module html { - exception [ - Conditional=BLOB, - DoNotCheckConstants, - JSNoStaticTables - ] OperationNotAllowedException { - readonly attribute unsigned short code; - readonly attribute DOMString name; - readonly attribute DOMString message; - -#if defined(LANGUAGE_JAVASCRIPT) && LANGUAGE_JAVASCRIPT - // Override in a Mozilla compatible format - [NotEnumerable] DOMString toString(); -#endif - - const unsigned short NOT_ALLOWED_ERR = 1; - }; -} diff --git a/Source/WebCore/fileapi/ThreadableBlobRegistry.cpp b/Source/WebCore/fileapi/ThreadableBlobRegistry.cpp index 2ec421bac..8a41285fc 100644 --- a/Source/WebCore/fileapi/ThreadableBlobRegistry.cpp +++ b/Source/WebCore/fileapi/ThreadableBlobRegistry.cpp @@ -34,7 +34,15 @@ #include "BlobData.h" #include "BlobRegistry.h" +#include "BlobURL.h" +#include "SecurityOrigin.h" +#include <wtf/HashMap.h> #include <wtf/MainThread.h> +#include <wtf/RefPtr.h> +#include <wtf/ThreadSpecific.h> +#include <wtf/text/StringHash.h> + +using WTF::ThreadSpecific; namespace WebCore { @@ -64,6 +72,13 @@ struct BlobRegistryContext { #if ENABLE(BLOB) +typedef HashMap<String, RefPtr<SecurityOrigin> > BlobUrlOriginMap; +static ThreadSpecific<BlobUrlOriginMap>& originMap() +{ + AtomicallyInitializedStatic(ThreadSpecific<BlobUrlOriginMap>*, map = new ThreadSpecific<BlobUrlOriginMap>); + return *map; +} + static void registerBlobURLTask(void* context) { OwnPtr<BlobRegistryContext> blobRegistryContext = adoptPtr(static_cast<BlobRegistryContext*>(context)); @@ -86,8 +101,12 @@ static void registerBlobURLFromTask(void* context) blobRegistry().registerBlobURL(blobRegistryContext->url, blobRegistryContext->srcURL); } -void ThreadableBlobRegistry::registerBlobURL(const KURL& url, const KURL& srcURL) +void ThreadableBlobRegistry::registerBlobURL(SecurityOrigin* origin, const KURL& url, const KURL& srcURL) { + // If the blob URL contains null origin, as in the context with unique security origin or file URL, save the mapping between url and origin so that the origin can be retrived when doing security origin check. + if (origin && BlobURL::getOrigin(url) == "null") + originMap()->add(url.string(), origin); + if (isMainThread()) blobRegistry().registerBlobURL(url, srcURL); else { @@ -104,6 +123,9 @@ static void unregisterBlobURLTask(void* context) void ThreadableBlobRegistry::unregisterBlobURL(const KURL& url) { + if (BlobURL::getOrigin(url) == "null") + originMap()->remove(url.string()); + if (isMainThread()) blobRegistry().unregisterBlobURL(url); else { @@ -112,19 +134,30 @@ void ThreadableBlobRegistry::unregisterBlobURL(const KURL& url) } } +PassRefPtr<SecurityOrigin> ThreadableBlobRegistry::getCachedOrigin(const KURL& url) +{ + return originMap()->get(url.string()); +} + #else void ThreadableBlobRegistry::registerBlobURL(const KURL&, PassOwnPtr<BlobData>) { } -void ThreadableBlobRegistry::registerBlobURL(const KURL&, const KURL&) +void ThreadableBlobRegistry::registerBlobURL(SecurityOrigin*, const KURL&, const KURL&) { } void ThreadableBlobRegistry::unregisterBlobURL(const KURL&) { } + +PassRefPtr<SecurityOrigin> ThreadableBlobRegistry::getCachedOrigin(const KURL& url) +{ + return 0; +} + #endif // ENABL(BLOB) } // namespace WebCore diff --git a/Source/WebCore/fileapi/ThreadableBlobRegistry.h b/Source/WebCore/fileapi/ThreadableBlobRegistry.h index fe7df7f4f..f66bd10c4 100644 --- a/Source/WebCore/fileapi/ThreadableBlobRegistry.h +++ b/Source/WebCore/fileapi/ThreadableBlobRegistry.h @@ -32,17 +32,23 @@ #define ThreadableBlobRegistry_h #include <wtf/PassOwnPtr.h> +#include <wtf/PassRefPtr.h> namespace WebCore { class BlobData; class KURL; +class SecurityOrigin; class ThreadableBlobRegistry { public: static void registerBlobURL(const KURL&, PassOwnPtr<BlobData>); - static void registerBlobURL(const KURL&, const KURL& srcURL); + static void registerBlobURL(SecurityOrigin*, const KURL&, const KURL& srcURL); static void unregisterBlobURL(const KURL&); + + // Returns the origin for the given blob URL. This is because we are not able to embed the unique security origin or the origin of file URL + // in the blob URL. + static PassRefPtr<SecurityOrigin> getCachedOrigin(const KURL&); }; } // namespace WebCore diff --git a/Source/WebCore/fileapi/WebKitBlobBuilder.cpp b/Source/WebCore/fileapi/WebKitBlobBuilder.cpp index e87bfe555..5f7a858f4 100644 --- a/Source/WebCore/fileapi/WebKitBlobBuilder.cpp +++ b/Source/WebCore/fileapi/WebKitBlobBuilder.cpp @@ -36,8 +36,10 @@ #include "ExceptionCode.h" #include "File.h" #include "LineEnding.h" +#include "ScriptExecutionContext.h" #include "TextEncoding.h" #include <wtf/ArrayBuffer.h> +#include <wtf/ArrayBufferView.h> #include <wtf/PassRefPtr.h> #include <wtf/Vector.h> #include <wtf/text/AtomicString.h> @@ -45,6 +47,15 @@ namespace WebCore { +// static +PassRefPtr<WebKitBlobBuilder> WebKitBlobBuilder::create(ScriptExecutionContext* context) +{ + String message("BlobBuilder is deprecated. Use \"Blob\" constructor instead."); + context->addConsoleMessage(JSMessageSource, LogMessageType, WarningMessageLevel, message); + + return adoptRef(new WebKitBlobBuilder()); +} + WebKitBlobBuilder::WebKitBlobBuilder() : m_size(0) { @@ -86,8 +97,10 @@ void WebKitBlobBuilder::append(const String& text, ExceptionCode& ec) } #if ENABLE(BLOB) -void WebKitBlobBuilder::append(ArrayBuffer* arrayBuffer) +void WebKitBlobBuilder::append(ScriptExecutionContext* context, ArrayBuffer* arrayBuffer) { + String consoleMessage("ArrayBuffer values are deprecated in Blob Constructor. Use ArrayBufferView instead."); + context->addConsoleMessage(JSMessageSource, LogMessageType, WarningMessageLevel, consoleMessage); if (!arrayBuffer) return; Vector<char>& buffer = getBuffer(); @@ -95,6 +108,16 @@ void WebKitBlobBuilder::append(ArrayBuffer* arrayBuffer) buffer.append(static_cast<const char*>(arrayBuffer->data()), arrayBuffer->byteLength()); m_size += buffer.size() - oldSize; } + +void WebKitBlobBuilder::append(ArrayBufferView* arrayBufferView) +{ + if (!arrayBufferView) + return; + Vector<char>& buffer = getBuffer(); + size_t oldSize = buffer.size(); + buffer.append(static_cast<const char*>(arrayBufferView->baseAddress()), arrayBufferView->byteLength()); + m_size += buffer.size() - oldSize; +} #endif void WebKitBlobBuilder::append(Blob* blob) diff --git a/Source/WebCore/fileapi/WebKitBlobBuilder.h b/Source/WebCore/fileapi/WebKitBlobBuilder.h index 76b90beab..b78c7a696 100644 --- a/Source/WebCore/fileapi/WebKitBlobBuilder.h +++ b/Source/WebCore/fileapi/WebKitBlobBuilder.h @@ -38,19 +38,25 @@ namespace WebCore { class Blob; +class ScriptExecutionContext; class TextEncoding; typedef int ExceptionCode; class WebKitBlobBuilder : public RefCounted<WebKitBlobBuilder> { public: + // Called when BlobBuilder is instantiated in JS API. We show deprecate warning message. + static PassRefPtr<WebKitBlobBuilder> create(ScriptExecutionContext*); + + // Called by Blob constructor. static PassRefPtr<WebKitBlobBuilder> create() { return adoptRef(new WebKitBlobBuilder()); } void append(Blob*); void append(const String& text, ExceptionCode&); void append(const String& text, const String& ending, ExceptionCode&); #if ENABLE(BLOB) - void append(ArrayBuffer*); + void append(ScriptExecutionContext*, ArrayBuffer*); + void append(ArrayBufferView*); #endif PassRefPtr<Blob> getBlob(const String& contentType = String()); diff --git a/Source/WebCore/fileapi/WebKitBlobBuilder.idl b/Source/WebCore/fileapi/WebKitBlobBuilder.idl index e0c7c5c92..e3479a40a 100644 --- a/Source/WebCore/fileapi/WebKitBlobBuilder.idl +++ b/Source/WebCore/fileapi/WebKitBlobBuilder.idl @@ -33,14 +33,16 @@ module html { Conditional=LEGACY_WEBKIT_BLOB_BUILDER, Constructor, JSGenerateToNativeObject, - JSNoStaticTables + JSNoStaticTables, + CallWith=ScriptExecutionContext ] WebKitBlobBuilder { #if !defined(LANGUAGE_OBJECTIVE_C) Blob getBlob(in [Optional, TreatNullAs=NullString, TreatUndefinedAs=NullString] DOMString contentType); #endif void append(in Blob blob); #if defined(ENABLE_BLOB) && ENABLE_BLOB - void append(in ArrayBuffer arrayBuffer); + [CallWith=ScriptExecutionContext] void append(in ArrayBuffer arrayBuffer); + void append(in ArrayBufferView arrayBufferView); #endif void append(in DOMString value, in [Optional, TreatNullAs=NullString, TreatUndefinedAs=NullString] DOMString endings) raises (DOMException); }; |