diff options
Diffstat (limited to 'WebCore/fileapi')
40 files changed, 191 insertions, 156 deletions
diff --git a/WebCore/fileapi/AsyncFileWriter.h b/WebCore/fileapi/AsyncFileWriter.h index cdb815c..ff6c1fa 100644 --- a/WebCore/fileapi/AsyncFileWriter.h +++ b/WebCore/fileapi/AsyncFileWriter.h @@ -31,7 +31,7 @@ #ifndef AsyncFileWriter_h #define AsyncFileWriter_h -#if ENABLE(FILE_WRITER) +#if ENABLE(FILE_SYSTEM) #include "PlatformString.h" #include <wtf/RefCounted.h> @@ -54,7 +54,7 @@ public: } // namespace -#endif // ENABLE(FILE_WRITER) +#endif // ENABLE(FILE_SYSTEM) #endif // AsyncFileWriter_h diff --git a/WebCore/fileapi/Blob.cpp b/WebCore/fileapi/Blob.cpp index 5fed327..d5a5602 100644 --- a/WebCore/fileapi/Blob.cpp +++ b/WebCore/fileapi/Blob.cpp @@ -33,57 +33,37 @@ #include "BlobURL.h" #include "File.h" -#include "ScriptExecutionContext.h" #include "ThreadableBlobRegistry.h" namespace WebCore { -Blob::Blob(ScriptExecutionContext* scriptExecutionContext, PassOwnPtr<BlobData> blobData, long long size) - : m_scriptExecutionContext(scriptExecutionContext) - , m_type(blobData->contentType()) +Blob::Blob(PassOwnPtr<BlobData> blobData, long long size) + : m_type(blobData->contentType()) , m_size(size) { ASSERT(blobData); - m_scriptExecutionContext->addBlob(this); - // Create a new internal URL and register it with the provided blob data. - m_url = BlobURL::createURL(scriptExecutionContext); - ThreadableBlobRegistry::registerBlobURL(scriptExecutionContext, m_url, blobData); + m_internalURL = BlobURL::createInternalURL(); + ThreadableBlobRegistry::registerBlobURL(m_internalURL, blobData); } -Blob::Blob(ScriptExecutionContext* scriptExecutionContext, const KURL& srcURL, const String& type, long long size) - : m_scriptExecutionContext(scriptExecutionContext) - , m_type(type) +Blob::Blob(const KURL& srcURL, const String& type, long long size) + : m_type(type) , m_size(size) { - m_scriptExecutionContext->addBlob(this); - // Create a new internal URL and register it with the same blob data as the source URL. - m_url = BlobURL::createURL(scriptExecutionContext); - ThreadableBlobRegistry::registerBlobURL(scriptExecutionContext, m_url, srcURL); + m_internalURL = BlobURL::createInternalURL(); + ThreadableBlobRegistry::registerBlobURL(m_internalURL, srcURL); } Blob::~Blob() { - // The internal URL is only used to refer to the Blob object. So we need to unregister the URL when the object is GC-ed. - if (m_scriptExecutionContext) { - m_scriptExecutionContext->removeBlob(this); - ThreadableBlobRegistry::unregisterBlobURL(m_scriptExecutionContext, m_url); - } -} - -void Blob::contextDestroyed() -{ - ASSERT(m_scriptExecutionContext); - - // Unregister the internal URL before the context is gone. - ThreadableBlobRegistry::unregisterBlobURL(m_scriptExecutionContext, m_url); - m_scriptExecutionContext = 0; + ThreadableBlobRegistry::unregisterBlobURL(m_internalURL); } #if ENABLE(BLOB) -PassRefPtr<Blob> Blob::slice(ScriptExecutionContext* scriptExecutionContext, long long start, long long length, const String& contentType) const +PassRefPtr<Blob> Blob::slice(long long start, long long length, 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. @@ -114,9 +94,9 @@ PassRefPtr<Blob> Blob::slice(ScriptExecutionContext* scriptExecutionContext, lon if (isFile()) blobData->appendFile(static_cast<const File*>(this)->path(), start, length, modificationTime); else - blobData->appendBlob(m_url, start, length); + blobData->appendBlob(m_internalURL, start, length); - return Blob::create(scriptExecutionContext, blobData.release(), length); + return Blob::create(blobData.release(), length); } #endif diff --git a/WebCore/fileapi/Blob.h b/WebCore/fileapi/Blob.h index 0d5649c..2690ff5 100644 --- a/WebCore/fileapi/Blob.h +++ b/WebCore/fileapi/Blob.h @@ -41,46 +41,42 @@ namespace WebCore { -class ScriptExecutionContext; - class Blob : public RefCounted<Blob> { public: - static PassRefPtr<Blob> create(ScriptExecutionContext* scriptExecutionContext, PassOwnPtr<BlobData> blobData, long long size) + static PassRefPtr<Blob> create(PassOwnPtr<BlobData> blobData, long long size) { - return adoptRef(new Blob(scriptExecutionContext, blobData, size)); + return adoptRef(new Blob(blobData, size)); } // For deserialization. - static PassRefPtr<Blob> create(ScriptExecutionContext* scriptExecutionContext, const KURL& srcURL, const String& type, long long size) + static PassRefPtr<Blob> create(const KURL& srcURL, const String& type, long long size) { - return adoptRef(new Blob(scriptExecutionContext, srcURL, type, size)); + return adoptRef(new Blob(srcURL, type, size)); } virtual ~Blob(); - void contextDestroyed(); - - const KURL& url() const { return m_url; } + const KURL& url() const { return m_internalURL; } const String& type() const { return m_type; } virtual unsigned long long size() const { return static_cast<unsigned long long>(m_size); } virtual bool isFile() const { return false; } #if ENABLE(BLOB) - PassRefPtr<Blob> slice(ScriptExecutionContext*, long long start, long long length, const String& contentType = String()) const; + PassRefPtr<Blob> slice(long long start, long long length, const String& contentType = String()) const; #endif protected: - Blob(ScriptExecutionContext*, PassOwnPtr<BlobData>, long long size); + Blob(PassOwnPtr<BlobData>, long long size); // For deserialization. - Blob(ScriptExecutionContext*, const KURL& srcURL, const String& type, long long size); + Blob(const KURL& srcURL, const String& type, long long size); - // This is an internal URL referring to the blob data associated with this object. - // It is only used by FileReader to read the blob data via loading from the blob URL resource. - KURL m_url; + // 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. + KURL m_internalURL; - ScriptExecutionContext* m_scriptExecutionContext; String m_type; long long m_size; }; diff --git a/WebCore/fileapi/Blob.idl b/WebCore/fileapi/Blob.idl index b220233..297d039 100644 --- a/WebCore/fileapi/Blob.idl +++ b/WebCore/fileapi/Blob.idl @@ -38,7 +38,7 @@ module html { #if !defined(LANGUAGE_OBJECTIVE_C) #if defined(ENABLE_BLOB) && ENABLE_BLOB - [CallWith=ScriptExecutionContext] Blob slice(in long long start, in long long length, in [Optional, ConvertUndefinedOrNullToNullString] DOMString contentType); + Blob slice(in long long start, in long long length, in [Optional, ConvertUndefinedOrNullToNullString] DOMString contentType); #endif #endif }; diff --git a/WebCore/fileapi/BlobBuilder.cpp b/WebCore/fileapi/BlobBuilder.cpp index e10df6b..34864a5 100644 --- a/WebCore/fileapi/BlobBuilder.cpp +++ b/WebCore/fileapi/BlobBuilder.cpp @@ -117,13 +117,13 @@ bool BlobBuilder::append(PassRefPtr<Blob> blob) return true; } -PassRefPtr<Blob> BlobBuilder::getBlob(ScriptExecutionContext* scriptExecutionContext, const String& contentType) +PassRefPtr<Blob> BlobBuilder::getBlob(const String& contentType) { OwnPtr<BlobData> blobData = BlobData::create(); blobData->setContentType(contentType); blobData->swapItems(m_items); - RefPtr<Blob> blob = Blob::create(scriptExecutionContext, blobData.release(), m_size); + RefPtr<Blob> blob = Blob::create(blobData.release(), m_size); // After creating a blob from the current blob data, we do not need to keep the data around any more. Instead, we only // need to keep a reference to the URL of the blob just created. diff --git a/WebCore/fileapi/BlobBuilder.h b/WebCore/fileapi/BlobBuilder.h index 20e510a..a981e31 100644 --- a/WebCore/fileapi/BlobBuilder.h +++ b/WebCore/fileapi/BlobBuilder.h @@ -41,7 +41,6 @@ namespace WebCore { class Blob; -class ScriptExecutionContext; class TextEncoding; typedef int ExceptionCode; @@ -54,7 +53,7 @@ public: bool append(const String& text, ExceptionCode&); bool append(const String& text, const String& ending, ExceptionCode&); - PassRefPtr<Blob> getBlob(ScriptExecutionContext*, const String& contentType = String()); + PassRefPtr<Blob> getBlob(const String& contentType = String()); private: BlobBuilder(); diff --git a/WebCore/fileapi/BlobBuilder.idl b/WebCore/fileapi/BlobBuilder.idl index 53c7add..0da9314 100644 --- a/WebCore/fileapi/BlobBuilder.idl +++ b/WebCore/fileapi/BlobBuilder.idl @@ -35,7 +35,7 @@ module html { NoStaticTables ] BlobBuilder { #if !defined(LANGUAGE_OBJECTIVE_C) - [CallWith=ScriptExecutionContext] Blob getBlob(in [Optional, ConvertUndefinedOrNullToNullString] DOMString contentType); + Blob getBlob(in [Optional, ConvertUndefinedOrNullToNullString] DOMString contentType); #endif void append(in Blob blob); void append(in DOMString value, in [Optional, ConvertUndefinedOrNullToNullString] DOMString endings) raises (DOMException); diff --git a/WebCore/fileapi/BlobURL.cpp b/WebCore/fileapi/BlobURL.cpp index c5571a7..47ebe8d 100644 --- a/WebCore/fileapi/BlobURL.cpp +++ b/WebCore/fileapi/BlobURL.cpp @@ -34,28 +34,27 @@ #include "KURL.h" #include "PlatformString.h" -#include "ScriptExecutionContext.h" #include "SecurityOrigin.h" #include "UUID.h" namespace WebCore { -KURL BlobURL::createURL(ScriptExecutionContext* scriptExecutionContext) +const char BlobURL::kBlobProtocol[] = "blob"; + +KURL BlobURL::createPublicURL(SecurityOrigin* securityOrigin) { - // Create the blob URL in the following format: - // blob:%escaped_origin%/%UUID% - // The origin of the host page is encoded in the URL value to allow easy lookup of the origin when the security check needs - // to be performed. - String urlString = "blob:"; - urlString += encodeWithURLEscapeSequences(scriptExecutionContext->securityOrigin()->toString()); - urlString += "/"; - urlString += createCanonicalUUIDString(); - return KURL(ParsedURLString, urlString); + ASSERT(securityOrigin); + return createBlobURL(securityOrigin->toString()); +} + +KURL BlobURL::createInternalURL() +{ + return createBlobURL("blobinternal://"); } KURL BlobURL::getOrigin(const KURL& url) { - ASSERT(url.protocolIs("blob")); + ASSERT(url.protocolIs(kBlobProtocol)); unsigned startIndex = url.pathStart(); unsigned afterEndIndex = url.pathAfterLastSlash(); @@ -65,10 +64,20 @@ KURL BlobURL::getOrigin(const KURL& url) String BlobURL::getIdentifier(const KURL& url) { - ASSERT(url.protocolIs("blob")); + ASSERT(url.protocolIs(kBlobProtocol)); unsigned startIndex = url.pathAfterLastSlash(); return url.string().substring(startIndex); } +KURL BlobURL::createBlobURL(const String& originString) +{ + String urlString = kBlobProtocol; + urlString += ":"; + urlString += encodeWithURLEscapeSequences(originString); + urlString += "/"; + urlString += createCanonicalUUIDString(); + return KURL(ParsedURLString, urlString); +} + } // namespace WebCore diff --git a/WebCore/fileapi/BlobURL.h b/WebCore/fileapi/BlobURL.h index e73b771..4526e63 100644 --- a/WebCore/fileapi/BlobURL.h +++ b/WebCore/fileapi/BlobURL.h @@ -35,13 +35,29 @@ namespace WebCore { -class ScriptExecutionContext; +class SecurityOrigin; +// Blob URLs are of the form +// blob:%escaped_origin%/%UUID% +// For public urls, the origin of the host page is encoded in the URL value to +// allow easy lookup of the origin when security checks need to be performed. +// When loading blobs via ResourceHandle or when reading blobs via FileReader +// the loader conducts security checks that examine the origin of host page +// encoded in the public blob url. The origin baked into internal blob urls +// is a simple constant value, "blobinternal://", internal urls should not +// be used with ResourceHandle or FileReader. class BlobURL { public: - static KURL createURL(ScriptExecutionContext*); + static KURL createPublicURL(SecurityOrigin*); + static KURL createInternalURL(); static KURL getOrigin(const KURL&); - static String getIdentifier(const KURL& url); + static String getIdentifier(const KURL&); + static const char* blobProtocol() { return kBlobProtocol; } + +private: + static KURL createBlobURL(const String& originString); + static const char kBlobProtocol[]; + BlobURL() { } }; } diff --git a/WebCore/fileapi/DOMFilePath.cpp b/WebCore/fileapi/DOMFilePath.cpp index 2da057c..1e0d788 100644 --- a/WebCore/fileapi/DOMFilePath.cpp +++ b/WebCore/fileapi/DOMFilePath.cpp @@ -61,7 +61,7 @@ String DOMFilePath::getName(const String& path) { int index = path.reverseFind(DOMFilePath::separator); if (index != -1) - return path.substring(index); + return path.substring(index + 1); return path; } diff --git a/WebCore/fileapi/DirectoryEntry.h b/WebCore/fileapi/DirectoryEntry.h index 3cd8ab5..c76b204 100644 --- a/WebCore/fileapi/DirectoryEntry.h +++ b/WebCore/fileapi/DirectoryEntry.h @@ -54,8 +54,8 @@ public: virtual bool isDirectory() const { return true; } PassRefPtr<DirectoryReader> createReader(); - void getFile(const String& path, PassRefPtr<Flags> options = 0, PassRefPtr<EntryCallback> successCallback = 0, PassRefPtr<ErrorCallback> errorCallback = 0); - void getDirectory(const String& path, PassRefPtr<Flags> options = 0, PassRefPtr<EntryCallback> successCallback = 0, PassRefPtr<ErrorCallback> errorCallback = 0); + void getFile(const String& path, PassRefPtr<Flags> = 0, PassRefPtr<EntryCallback> = 0, PassRefPtr<ErrorCallback> = 0); + void getDirectory(const String& path, PassRefPtr<Flags> = 0, PassRefPtr<EntryCallback> = 0, PassRefPtr<ErrorCallback> = 0); private: DirectoryEntry(DOMFileSystem* fileSystem, const String& fullPath); diff --git a/WebCore/fileapi/DirectoryEntry.idl b/WebCore/fileapi/DirectoryEntry.idl index ac30c7f..7a0efdd 100644 --- a/WebCore/fileapi/DirectoryEntry.idl +++ b/WebCore/fileapi/DirectoryEntry.idl @@ -35,7 +35,7 @@ module storage { GenerateToJS ] DirectoryEntry : Entry { DirectoryReader createReader(); - void getFile(in DOMString path, in [Optional] Flags options, in [Optional, Callback] EntryCallback successCallback, in [Optional, Callback] ErrorCallback errorCallback); - void getDirectory(in DOMString path, in [Optional] Flags options, in [Optional, Callback] EntryCallback successCallback, in [Optional, Callback] ErrorCallback errorCallback); + [Custom] void getFile(in [ConvertUndefinedOrNullToNullString] DOMString path, in [Optional] Flags flags, in [Optional, Callback] EntryCallback successCallback, in [Optional, Callback] ErrorCallback errorCallback); + [Custom] void getDirectory(in [ConvertUndefinedOrNullToNullString] DOMString path, in [Optional] Flags flags, in [Optional, Callback] EntryCallback successCallback, in [Optional, Callback] ErrorCallback errorCallback); }; } diff --git a/WebCore/fileapi/Entry.cpp b/WebCore/fileapi/Entry.cpp index fbbedf2..969ae2b 100644 --- a/WebCore/fileapi/Entry.cpp +++ b/WebCore/fileapi/Entry.cpp @@ -45,12 +45,8 @@ namespace WebCore { Entry::Entry(DOMFileSystem* fileSystem, const String& fullPath) : m_fileSystem(fileSystem) , m_fullPath(fullPath) + , m_name(DOMFilePath::getName(fullPath)) { - size_t index = fullPath.reverseFind("/"); - if (index != notFound) - m_name = fullPath.substring(index); - else - m_name = fullPath; } void Entry::getMetadata(PassRefPtr<MetadataCallback> successCallback, PassRefPtr<ErrorCallback> errorCallback) diff --git a/WebCore/fileapi/Entry.idl b/WebCore/fileapi/Entry.idl index e2c1e12..b674455 100644 --- a/WebCore/fileapi/Entry.idl +++ b/WebCore/fileapi/Entry.idl @@ -30,7 +30,8 @@ module storage { interface [ - Conditional=FILE_SYSTEM + Conditional=FILE_SYSTEM, + CustomToJS ] Entry { readonly attribute boolean isFile; readonly attribute boolean isDirectory; @@ -39,8 +40,8 @@ module storage { readonly attribute DOMFileSystem filesystem; void getMetadata(in [Optional, Callback] MetadataCallback successCallback, in [Optional, Callback] ErrorCallback errorCallback); - void moveTo(in Entry parent, in [Optional] DOMString name, in [Optional, Callback] EntryCallback successCallback, in [Optional, Callback] ErrorCallback errorCallback); - void copyTo(in Entry parent, in [Optional] DOMString name, in [Optional, Callback] EntryCallback successCallback, in [Optional, Callback] ErrorCallback errorCallback); + void moveTo(in Entry parent, in [Optional, ConvertUndefinedOrNullToNullString] DOMString name, in [Optional, Callback] EntryCallback successCallback, in [Optional, Callback] ErrorCallback errorCallback); + void copyTo(in Entry parent, in [Optional, ConvertUndefinedOrNullToNullString] DOMString name, in [Optional, Callback] EntryCallback successCallback, in [Optional, Callback] ErrorCallback errorCallback); void remove(in [Optional, Callback] VoidCallback successCallback, in [Optional, Callback] ErrorCallback errorCallback); void getParent(in [Optional, Callback] EntryCallback successCallback, in [Optional, Callback] ErrorCallback errorCallback); }; diff --git a/WebCore/fileapi/File.cpp b/WebCore/fileapi/File.cpp index 150a05b..51ada6c 100644 --- a/WebCore/fileapi/File.cpp +++ b/WebCore/fileapi/File.cpp @@ -26,7 +26,6 @@ #include "config.h" #include "File.h" -#include "BlobRegistry.h" #include "FileSystem.h" #include "MIMETypeRegistry.h" @@ -45,23 +44,23 @@ static PassOwnPtr<BlobData> createBlobDataForFile(const String& path) return blobData.release(); } -File::File(ScriptExecutionContext* scriptExecutionContext, const String& path) - : Blob(scriptExecutionContext, createBlobDataForFile(path), -1) +File::File(const String& path) + : Blob(createBlobDataForFile(path), -1) , m_path(path) , m_name(pathGetFileName(path)) { } -File::File(ScriptExecutionContext* scriptExecutionContext, const String& path, const KURL& url, const String& type) - : Blob(scriptExecutionContext, url, type, -1) +File::File(const String& path, const KURL& url, const String& type) + : Blob(url, type, -1) , m_path(path) { m_name = pathGetFileName(path); } #if ENABLE(DIRECTORY_UPLOAD) -File::File(ScriptExecutionContext* scriptExecutionContext, const String& relativePath, const String& path) - : Blob(scriptExecutionContext, createBlobDataForFile(path), -1) +File::File(const String& relativePath, const String& path) + : Blob(createBlobDataForFile(path), -1) , m_path(path) , m_relativePath(relativePath) { diff --git a/WebCore/fileapi/File.h b/WebCore/fileapi/File.h index d6446d3..06b03cd 100644 --- a/WebCore/fileapi/File.h +++ b/WebCore/fileapi/File.h @@ -34,25 +34,24 @@ namespace WebCore { class KURL; -class ScriptExecutionContext; class File : public Blob { public: - static PassRefPtr<File> create(ScriptExecutionContext* scriptExecutionContext, const String& path) + static PassRefPtr<File> create(const String& path) { - return adoptRef(new File(scriptExecutionContext, path)); + return adoptRef(new File(path)); } // For deserialization. - static PassRefPtr<File> create(ScriptExecutionContext* scriptExecutionContext, const String& path, const KURL& srcURL, const String& type) + static PassRefPtr<File> create(const String& path, const KURL& srcURL, const String& type) { - return adoptRef(new File(scriptExecutionContext, path, srcURL, type)); + return adoptRef(new File(path, srcURL, type)); } #if ENABLE(DIRECTORY_UPLOAD) - static PassRefPtr<File> create(ScriptExecutionContext* scriptExecutionContext, const String& relativePath, const String& path) + static PassRefPtr<File> create(const String& relativePath, const String& path) { - return adoptRef(new File(scriptExecutionContext, relativePath, path)); + return adoptRef(new File(relativePath, path)); } #endif @@ -74,13 +73,13 @@ public: unsigned long long fileSize() const { return size(); } private: - File(ScriptExecutionContext*, const String& path); + File(const String& path); // For deserialization. - File(ScriptExecutionContext*, const String& path, const KURL& srcURL, const String& type); + File(const String& path, const KURL& srcURL, const String& type); #if ENABLE(DIRECTORY_UPLOAD) - File(ScriptExecutionContext*, const String& relativePath, const String& path); + File(const String& relativePath, const String& path); #endif String m_path; diff --git a/WebCore/fileapi/FileEntry.cpp b/WebCore/fileapi/FileEntry.cpp index e2a583c..2d1e623 100644 --- a/WebCore/fileapi/FileEntry.cpp +++ b/WebCore/fileapi/FileEntry.cpp @@ -33,6 +33,10 @@ #if ENABLE(FILE_SYSTEM) +#include "ErrorCallback.h" +#include "FileCallback.h" +#include "FileWriterCallback.h" + namespace WebCore { FileEntry::FileEntry(DOMFileSystem* fileSystem, const String& fullPath) @@ -40,6 +44,16 @@ FileEntry::FileEntry(DOMFileSystem* fileSystem, const String& fullPath) { } +void FileEntry::createWriter(PassRefPtr<FileWriterCallback>, PassRefPtr<ErrorCallback>) +{ + // FIXME: to be implemented. +} + +void FileEntry::file(PassRefPtr<FileCallback>, PassRefPtr<ErrorCallback>) +{ + // FIXME: to be implemented. +} + } // namespace #endif // ENABLE(FILE_SYSTEM) diff --git a/WebCore/fileapi/FileEntry.h b/WebCore/fileapi/FileEntry.h index abcc6bb..2c85d73 100644 --- a/WebCore/fileapi/FileEntry.h +++ b/WebCore/fileapi/FileEntry.h @@ -34,6 +34,8 @@ #if ENABLE(FILE_SYSTEM) #include "Entry.h" +#include "FileCallback.h" +#include "FileWriterCallback.h" namespace WebCore { @@ -45,6 +47,10 @@ public: { return adoptRef(new FileEntry(fileSystem, fullPath)); } + + void createWriter(PassRefPtr<FileWriterCallback>, PassRefPtr<ErrorCallback> = 0); + void file(PassRefPtr<FileCallback>, PassRefPtr<ErrorCallback> = 0); + virtual bool isFile() const { return true; } private: diff --git a/WebCore/fileapi/FileEntry.idl b/WebCore/fileapi/FileEntry.idl index af3b807..eb913b8 100644 --- a/WebCore/fileapi/FileEntry.idl +++ b/WebCore/fileapi/FileEntry.idl @@ -34,5 +34,7 @@ module storage { GenerateNativeConverter, GenerateToJS ] FileEntry : Entry { + void createWriter(in [Callback] FileWriterCallback successCallback, in [Optional, Callback] ErrorCallback errorCallback); + void file(in [Callback] FileCallback successCallback, in [Optional, Callback] ErrorCallback errorCallback); }; } diff --git a/WebCore/fileapi/FileError.h b/WebCore/fileapi/FileError.h index 1c74c07..3528109 100644 --- a/WebCore/fileapi/FileError.h +++ b/WebCore/fileapi/FileError.h @@ -31,7 +31,7 @@ #ifndef FileError_h #define FileError_h -#if ENABLE(BLOB) || ENABLE(FILE_WRITER) +#if ENABLE(BLOB) || ENABLE(FILE_SYSTEM) #include "ExceptionCode.h" #include <wtf/PassRefPtr.h> @@ -55,6 +55,6 @@ private: } // namespace WebCore -#endif // ENABLE(BLOB) || ENABLE(FILE_WRITER) +#endif // ENABLE(BLOB) || ENABLE(FILE_SYSTEM) #endif // FileError_h diff --git a/WebCore/fileapi/FileError.idl b/WebCore/fileapi/FileError.idl index a5e2bac..c5dedbe 100644 --- a/WebCore/fileapi/FileError.idl +++ b/WebCore/fileapi/FileError.idl @@ -30,7 +30,7 @@ module html { interface [ - Conditional=BLOB|FILE_WRITER, + Conditional=BLOB|FILE_SYSTEM, DontCheckEnums, NoStaticTables ] FileError { diff --git a/WebCore/fileapi/FileException.h b/WebCore/fileapi/FileException.h index 4419eb7..e90ab90 100644 --- a/WebCore/fileapi/FileException.h +++ b/WebCore/fileapi/FileException.h @@ -31,7 +31,7 @@ #ifndef FileException_h #define FileException_h -#if ENABLE(BLOB) || ENABLE(FILE_WRITER) +#if ENABLE(BLOB) || ENABLE(FILE_SYSTEM) #include "ExceptionBase.h" @@ -60,7 +60,7 @@ private: } // namespace WebCore -#endif // ENABLE(BLOB) || ENABLE(FILE_WRITER) +#endif // ENABLE(BLOB) || ENABLE(FILE_SYSTEM) #endif // FileException_h diff --git a/WebCore/fileapi/FileException.idl b/WebCore/fileapi/FileException.idl index cd53a7e..0b2ab9c 100644 --- a/WebCore/fileapi/FileException.idl +++ b/WebCore/fileapi/FileException.idl @@ -30,7 +30,7 @@ module html { interface [ - Conditional=BLOB|FILE_WRITER, + Conditional=BLOB|FILE_SYSTEM, DontCheckEnums, NoStaticTables ] FileException { diff --git a/WebCore/fileapi/FileReader.cpp b/WebCore/fileapi/FileReader.cpp index 747b6ff..8036468 100644 --- a/WebCore/fileapi/FileReader.cpp +++ b/WebCore/fileapi/FileReader.cpp @@ -36,6 +36,7 @@ #include "Base64.h" #include "Blob.h" +#include "BlobURL.h" #include "CrossThreadTask.h" #include "File.h" #include "Logging.h" @@ -44,6 +45,7 @@ #include "ResourceRequest.h" #include "ScriptExecutionContext.h" #include "TextResourceDecoder.h" +#include "ThreadableBlobRegistry.h" #include "ThreadableLoader.h" #include <wtf/CurrentTime.h> @@ -154,17 +156,27 @@ void FileReader::terminate() { if (m_loader) { m_loader->cancel(); - m_loader = 0; + cleanup(); } m_state = Completed; } +void FileReader::cleanup() +{ + m_loader = 0; + ThreadableBlobRegistry::unregisterBlobURL(m_urlForReading); + m_urlForReading = KURL(); +} + void FileReader::start() { m_state = Opening; - // The blob is read by routing through the request handling layer given the blob url. - ResourceRequest request(m_blob->url()); + // The blob is read by routing through the request handling layer given a temporary public url. + m_urlForReading = BlobURL::createPublicURL(scriptExecutionContext()->securityOrigin()); + ThreadableBlobRegistry::registerBlobURL(m_urlForReading, m_blob->url()); + + ResourceRequest request(m_urlForReading); request.setHTTPMethod("GET"); ThreadableLoaderOptions options; @@ -230,7 +242,7 @@ void FileReader::didFinishLoading(unsigned long) fireEvent(eventNames().loadEvent); fireEvent(eventNames().loadendEvent); - m_loader = 0; + cleanup(); } void FileReader::didFail(const ResourceError&) @@ -247,7 +259,7 @@ void FileReader::failed(int httpStatusCode) fireEvent(eventNames().errorEvent); fireEvent(eventNames().loadendEvent); - m_loader = 0; + cleanup(); } ExceptionCode FileReader::httpStatusCodeToExceptionCode(int httpStatusCode) diff --git a/WebCore/fileapi/FileReader.h b/WebCore/fileapi/FileReader.h index 48ce229..68c0f83 100644 --- a/WebCore/fileapi/FileReader.h +++ b/WebCore/fileapi/FileReader.h @@ -36,6 +36,7 @@ #include "ActiveDOMObject.h" #include "EventTarget.h" #include "FileError.h" +#include "KURL.h" #include "PlatformString.h" #include "ScriptString.h" #include "TextEncoding.h" @@ -130,6 +131,7 @@ private: virtual EventTargetData* ensureEventTargetData() { return &m_eventTargetData; } void terminate(); + void cleanup(); void readInternal(Blob*, ReadType); void failed(int httpStatusCode); void fireErrorEvent(int httpStatusCode); @@ -141,6 +143,7 @@ private: EventTargetData m_eventTargetData; RefPtr<Blob> m_blob; + KURL m_urlForReading; ReadType m_readType; TextEncoding m_encoding; diff --git a/WebCore/fileapi/FileReaderSync.cpp b/WebCore/fileapi/FileReaderSync.cpp index a907044..6c76714 100644 --- a/WebCore/fileapi/FileReaderSync.cpp +++ b/WebCore/fileapi/FileReaderSync.cpp @@ -36,11 +36,13 @@ #include "Base64.h" #include "Blob.h" +#include "BlobURL.h" #include "FileReader.h" #include "ResourceRequest.h" #include "ScriptExecutionContext.h" #include "TextEncoding.h" #include "TextResourceDecoder.h" +#include "ThreadableBlobRegistry.h" #include "ThreadableLoader.h" namespace WebCore { @@ -149,12 +151,16 @@ const ScriptString& FileReaderSync::readAsDataURL(ScriptExecutionContext* script void FileReaderSync::read(ScriptExecutionContext* scriptExecutionContext, Blob* blob, ReadType readType, ExceptionCode& ec) { - // The blob is read by routing through the request handling layer given the blob url. - ResourceRequest request(blob->url()); + // The blob is read by routing through the request handling layer given the temporary public url. + KURL urlForReading = BlobURL::createPublicURL(scriptExecutionContext->securityOrigin()); + ThreadableBlobRegistry::registerBlobURL(urlForReading, blob->url()); + + ResourceRequest request(urlForReading); request.setHTTPMethod("GET"); FileReaderSyncLoader loader((readType == ReadAsBinaryString) ? &m_result : 0); loader.start(scriptExecutionContext, request, ec); + ThreadableBlobRegistry::unregisterBlobURL(urlForReading); if (ec) return; diff --git a/WebCore/fileapi/FileStreamProxy.cpp b/WebCore/fileapi/FileStreamProxy.cpp index 30813d3..5daf983 100644 --- a/WebCore/fileapi/FileStreamProxy.cpp +++ b/WebCore/fileapi/FileStreamProxy.cpp @@ -30,7 +30,7 @@ #include "config.h" -#if ENABLE(BLOB) || ENABLE(FILE_WRITER) +#if ENABLE(BLOB) || ENABLE(FILE_SYSTEM) #include "FileStreamProxy.h" @@ -216,4 +216,4 @@ void FileStreamProxy::truncateOnFileThread(long long position) } // namespace WebCore -#endif // ENABLE(BLOB) || ENABLE(FILE_WRITER) +#endif // ENABLE(BLOB) || ENABLE(FILE_SYSTEM) diff --git a/WebCore/fileapi/FileStreamProxy.h b/WebCore/fileapi/FileStreamProxy.h index 35a3af8..ce9a105 100644 --- a/WebCore/fileapi/FileStreamProxy.h +++ b/WebCore/fileapi/FileStreamProxy.h @@ -32,7 +32,7 @@ #ifndef FileStreamProxy_h #define FileStreamProxy_h -#if ENABLE(BLOB) || ENABLE(FILE_WRITER) +#if ENABLE(BLOB) || ENABLE(FILE_SYSTEM) #include "AsyncFileStream.h" #include <wtf/Forward.h> @@ -87,6 +87,6 @@ private: } // namespace WebCore -#endif // ENABLE(BLOB) || ENABLE(FILE_WRITER) +#endif // ENABLE(BLOB) || ENABLE(FILE_SYSTEM) #endif // FileStreamProxy_h diff --git a/WebCore/fileapi/FileSystemCallbacks.cpp b/WebCore/fileapi/FileSystemCallbacks.cpp index 741df78..d59e47a 100644 --- a/WebCore/fileapi/FileSystemCallbacks.cpp +++ b/WebCore/fileapi/FileSystemCallbacks.cpp @@ -128,13 +128,12 @@ EntriesCallbacks::EntriesCallbacks(PassRefPtr<EntriesCallback> successCallback, , m_successCallback(successCallback) , m_fileSystem(fileSystem) , m_basePath(basePath) + , m_entries(EntryArray::create()) { } void EntriesCallbacks::didReadDirectoryEntry(const String& name, bool isDirectory) { - if (!m_entries) - m_entries = EntryArray::create(); if (isDirectory) m_entries->append(DirectoryEntry::create(m_fileSystem, DOMFilePath::append(m_basePath, name))); else @@ -143,15 +142,14 @@ void EntriesCallbacks::didReadDirectoryEntry(const String& name, bool isDirector void EntriesCallbacks::didReadDirectoryEntries(bool hasMore) { - ASSERT(m_entries); if (m_successCallback) { m_successCallback->handleEvent(m_entries.get()); - m_entries->clear(); - if (!hasMore) { - // If there're no more entries, call back once more with an empty array. - m_successCallback->handleEvent(m_entries.get()); + if (!m_entries->isEmpty() && !hasMore) { + // If we have returned some entries and there're no more coming entries (hasMore==false), call back once more with an empty array. + m_successCallback->handleEvent(EntryArray::create().get()); m_successCallback.clear(); } + m_entries->clear(); } } diff --git a/WebCore/fileapi/FileThread.cpp b/WebCore/fileapi/FileThread.cpp index 4e48cfb..4d55630 100644 --- a/WebCore/fileapi/FileThread.cpp +++ b/WebCore/fileapi/FileThread.cpp @@ -30,7 +30,7 @@ #include "config.h" -#if ENABLE(BLOB) || ENABLE(FILE_WRITER) +#if ENABLE(BLOB) || ENABLE(FILE_SYSTEM) #include "FileThread.h" @@ -116,4 +116,4 @@ void* FileThread::runLoop() } // namespace WebCore -#endif // ENABLE(BLOB) || ENABLE(FILE_WRITER) +#endif // ENABLE(BLOB) || ENABLE(FILE_SYSTEM) diff --git a/WebCore/fileapi/FileThread.h b/WebCore/fileapi/FileThread.h index 16acacc..d7aabf7 100644 --- a/WebCore/fileapi/FileThread.h +++ b/WebCore/fileapi/FileThread.h @@ -31,7 +31,7 @@ #ifndef FileThread_h #define FileThread_h -#if ENABLE(BLOB) || ENABLE(FILE_WRITER) +#if ENABLE(BLOB) || ENABLE(FILE_SYSTEM) #include <wtf/MessageQueue.h> #include <wtf/PassOwnPtr.h> @@ -83,6 +83,6 @@ private: } // namespace WebCore -#endif // ENABLE(BLOB) || ENABLE(FILE_WRITER) +#endif // ENABLE(BLOB) || ENABLE(FILE_SYSTEM) #endif // FileThread_h diff --git a/WebCore/fileapi/FileWriter.cpp b/WebCore/fileapi/FileWriter.cpp index 7ead354..a9f9afd 100644 --- a/WebCore/fileapi/FileWriter.cpp +++ b/WebCore/fileapi/FileWriter.cpp @@ -30,7 +30,7 @@ #include "config.h" -#if ENABLE(FILE_WRITER) +#if ENABLE(FILE_SYSTEM) #include "FileWriter.h" @@ -196,4 +196,4 @@ void FileWriter::fireEvent(const AtomicString& type) } // namespace WebCore -#endif // ENABLE(FILE_WRITER) +#endif // ENABLE(FILE_SYSTEM) diff --git a/WebCore/fileapi/FileWriter.h b/WebCore/fileapi/FileWriter.h index b0af7ea..0737085 100644 --- a/WebCore/fileapi/FileWriter.h +++ b/WebCore/fileapi/FileWriter.h @@ -31,7 +31,7 @@ #ifndef FileWriter_h #define FileWriter_h -#if ENABLE(FILE_WRITER) +#if ENABLE(FILE_SYSTEM) #include "ActiveDOMObject.h" #include "EventTarget.h" @@ -103,7 +103,7 @@ private: virtual ~FileWriter(); - friend class RefCounted<FileWriter>; + friend class WTF::RefCounted<FileWriter>; // EventTarget virtual void refEventTarget() { ref(); } @@ -125,6 +125,6 @@ private: } // namespace WebCore -#endif // ENABLE(FILE_WRITER) +#endif // ENABLE(FILE_SYSTEM) #endif // FileWriter_h diff --git a/WebCore/fileapi/FileWriter.idl b/WebCore/fileapi/FileWriter.idl index bb95ee1..4d46e9e 100644 --- a/WebCore/fileapi/FileWriter.idl +++ b/WebCore/fileapi/FileWriter.idl @@ -30,7 +30,7 @@ module html { interface [ - Conditional=FILE_WRITER, + Conditional=FILE_SYSTEM, CallWith=ScriptExecutionContext, EventTarget, NoStaticTables diff --git a/WebCore/fileapi/FileWriterCallback.h b/WebCore/fileapi/FileWriterCallback.h index f5f4d37..3f9e746 100644 --- a/WebCore/fileapi/FileWriterCallback.h +++ b/WebCore/fileapi/FileWriterCallback.h @@ -31,7 +31,7 @@ #ifndef FileWriterCallback_h #define FileWriterCallback_h -#if ENABLE(FILE_SYSTEM) && ENABLE(FILE_WRITER) +#if ENABLE(FILE_SYSTEM) #include <wtf/RefCounted.h> @@ -47,6 +47,6 @@ public: } // namespace -#endif // ENABLE(FILE_SYSTEM) && ENABLE(FILE_WRITER) +#endif // ENABLE(FILE_SYSTEM) #endif // FileWriterCallback_h diff --git a/WebCore/fileapi/FileWriterCallback.idl b/WebCore/fileapi/FileWriterCallback.idl index ba77891..df82fed 100644 --- a/WebCore/fileapi/FileWriterCallback.idl +++ b/WebCore/fileapi/FileWriterCallback.idl @@ -30,7 +30,7 @@ module fileapi { interface [ - Conditional=FILE_SYSTEM&FILE_WRITER, + Conditional=FILE_SYSTEM, Callback ] FileWriterCallback { boolean handleEvent(in FileWriter fileWriter); diff --git a/WebCore/fileapi/FileWriterClient.h b/WebCore/fileapi/FileWriterClient.h index 091b1c1..1bebbd6 100644 --- a/WebCore/fileapi/FileWriterClient.h +++ b/WebCore/fileapi/FileWriterClient.h @@ -31,7 +31,7 @@ #ifndef FileWriterClient_h #define FileWriterClient_h -#if ENABLE(FILE_WRITER) +#if ENABLE(FILE_SYSTEM) #include "ExceptionCode.h" @@ -48,6 +48,6 @@ public: } // namespace -#endif // ENABLE(FILE_WRITER) +#endif // ENABLE(FILE_SYSTEM) #endif // FileWriterClient_h diff --git a/WebCore/fileapi/Flags.idl b/WebCore/fileapi/Flags.idl index cfe73d2..29658a1 100644 --- a/WebCore/fileapi/Flags.idl +++ b/WebCore/fileapi/Flags.idl @@ -30,9 +30,10 @@ module storage { interface [ - Conditional=FILE_SYSTEM + Conditional=FILE_SYSTEM, + CanBeConstructed ] Flags { - attribute boolean CREATE; - attribute boolean EXCLUSIVE; + attribute boolean create; + attribute boolean exclusive; }; } diff --git a/WebCore/fileapi/ThreadableBlobRegistry.cpp b/WebCore/fileapi/ThreadableBlobRegistry.cpp index 034557b..f74c680 100644 --- a/WebCore/fileapi/ThreadableBlobRegistry.cpp +++ b/WebCore/fileapi/ThreadableBlobRegistry.cpp @@ -34,7 +34,6 @@ #include "BlobData.h" #include "BlobRegistry.h" -#include "ScriptExecutionContext.h" #include <wtf/MainThread.h> namespace WebCore { @@ -42,7 +41,7 @@ namespace WebCore { struct BlobRegistryContext { BlobRegistryContext(const KURL& url, PassOwnPtr<BlobData> blobData) : url(url.copy()) - , blobData(blobData) + , blobData(blobData->copy()) { } @@ -70,7 +69,7 @@ static void registerBlobURLTask(void* context) blobRegistry().registerBlobURL(blobRegistryContext->url, blobRegistryContext->blobData.release()); } -void ThreadableBlobRegistry::registerBlobURL(ScriptExecutionContext*, const KURL& url, PassOwnPtr<BlobData> blobData) +void ThreadableBlobRegistry::registerBlobURL(const KURL& url, PassOwnPtr<BlobData> blobData) { if (isMainThread()) blobRegistry().registerBlobURL(url, blobData); @@ -86,7 +85,7 @@ static void registerBlobURLFromTask(void* context) blobRegistry().registerBlobURL(blobRegistryContext->url, blobRegistryContext->srcURL); } -void ThreadableBlobRegistry::registerBlobURL(ScriptExecutionContext*, const KURL& url, const KURL& srcURL) +void ThreadableBlobRegistry::registerBlobURL(const KURL& url, const KURL& srcURL) { if (isMainThread()) blobRegistry().registerBlobURL(url, srcURL); @@ -102,7 +101,7 @@ static void unregisterBlobURLTask(void* context) blobRegistry().unregisterBlobURL(blobRegistryContext->url); } -void ThreadableBlobRegistry::unregisterBlobURL(ScriptExecutionContext*, const KURL& url) +void ThreadableBlobRegistry::unregisterBlobURL(const KURL& url) { if (isMainThread()) blobRegistry().unregisterBlobURL(url); @@ -114,15 +113,15 @@ void ThreadableBlobRegistry::unregisterBlobURL(ScriptExecutionContext*, const KU #else -void ThreadableBlobRegistry::registerBlobURL(ScriptExecutionContext*, const KURL&, PassOwnPtr<BlobData>) +void ThreadableBlobRegistry::registerBlobURL(const KURL&, PassOwnPtr<BlobData>) { } -void ThreadableBlobRegistry::registerBlobURL(ScriptExecutionContext*, const KURL&, const KURL&) +void ThreadableBlobRegistry::registerBlobURL(const KURL&, const KURL&) { } -void ThreadableBlobRegistry::unregisterBlobURL(ScriptExecutionContext*, const KURL&) +void ThreadableBlobRegistry::unregisterBlobURL(const KURL&) { } #endif // ENABL(BLOB) diff --git a/WebCore/fileapi/ThreadableBlobRegistry.h b/WebCore/fileapi/ThreadableBlobRegistry.h index 7dce6bb..fe7df7f 100644 --- a/WebCore/fileapi/ThreadableBlobRegistry.h +++ b/WebCore/fileapi/ThreadableBlobRegistry.h @@ -37,13 +37,12 @@ namespace WebCore { class BlobData; class KURL; -class ScriptExecutionContext; class ThreadableBlobRegistry { public: - static void registerBlobURL(ScriptExecutionContext*, const KURL&, PassOwnPtr<BlobData>); - static void registerBlobURL(ScriptExecutionContext*, const KURL&, const KURL& srcURL); - static void unregisterBlobURL(ScriptExecutionContext*, const KURL&); + static void registerBlobURL(const KURL&, PassOwnPtr<BlobData>); + static void registerBlobURL(const KURL&, const KURL& srcURL); + static void unregisterBlobURL(const KURL&); }; } // namespace WebCore |