2010-09-10 Michael Nordman <michaeln@google.com>

        Reviewed by Dumitru Daniliuc.

        Decouple Blob from ScriptExecutionContext.
        https://bugs.webkit.org/show_bug.cgi?id=45410

        - Removed ScriptExecutionContext pointers from Blob and File constructors.
        - Removed ScriptExecutionContext's collection of Blobs instance in that context.
        - Refactored BlobURL to make a distinction between 'public' blob urls and 'internal'
          urls that are used solely as identifiers. The former requires a SecurityOrigin to
          to manufacture, the latter does not.
        - Added a constant and accessor for the blob protocol scheme on the BlobURL class.

        No new tests are added since this is a cleanup.

        * bindings/js/SerializedScriptValue.cpp:
        (WebCore::CloneDeserializer::readFile):
        (WebCore::CloneDeserializer::readTerminal):
        * bindings/v8/SerializedScriptValue.cpp:
        (WebCore::ZigZag::Reader::readBlob):
        (WebCore::ZigZag::Reader::readFile):
        (WebCore::ZigZag::Reader::readFileList):
        * dom/ScriptExecutionContext.cpp:
        (WebCore::ScriptExecutionContext::~ScriptExecutionContext):
        (WebCore::ScriptExecutionContext::createPublicBlobURL):
        (WebCore::ScriptExecutionContext::revokePublicBlobURL):
        * dom/ScriptExecutionContext.h:
        * fileapi/Blob.cpp:
        (WebCore::Blob::Blob):
        (WebCore::Blob::~Blob):
        (WebCore::Blob::slice):
        * fileapi/Blob.h:
        (WebCore::Blob::create):
        (WebCore::Blob::url):
        * fileapi/Blob.idl:
        * fileapi/BlobBuilder.cpp:
        (WebCore::BlobBuilder::getBlob):
        * fileapi/BlobBuilder.h:
        * fileapi/BlobBuilder.idl:
        * fileapi/BlobURL.cpp:
        (WebCore::BlobURL::createPublicURL):
        (WebCore::BlobURL::createInternalURL):
        (WebCore::BlobURL::getOrigin):
        (WebCore::BlobURL::getIdentifier):
        (WebCore::BlobURL::createBlobURL):
        * fileapi/BlobURL.h:
        (WebCore::BlobURL::blobProtocol):
        (WebCore::BlobURL::BlobURL):
        * fileapi/File.cpp:
        (WebCore::File::File):
        * fileapi/File.h:
        (WebCore::File::create):
        * fileapi/FileReader.cpp: Register a public url to perform the read.
        (WebCore::FileReader::cleanup):
        (WebCore::FileReader::start):
        (WebCore::FileReader::didFinishLoading):
        (WebCore::FileReader::failed):
        * fileapi/FileReader.h: Added m_urlForReading data member.
        * fileapi/FileReaderSync.cpp:
        (WebCore::FileReaderSync::read): Register a public url to perform the read.
        * fileapi/ThreadableBlobRegistry.cpp:
        (WebCore::ThreadableBlobRegistry::registerBlobURL):
        (WebCore::ThreadableBlobRegistry::unregisterBlobURL):
        * fileapi/ThreadableBlobRegistry.h:
        * html/HTMLInputElement.cpp:
        (WebCore::HTMLInputElement::appendFormData):
        (WebCore::HTMLInputElement::setFileListFromRenderer):
        * page/SecurityOrigin.cpp: Use BlobURL.blobProtocol().
        (WebCore::SecurityOrigin::create):
        (WebCore::SecurityOrigin::canRequest):
        (WebCore::SecurityOrigin::canDisplay):
        * platform/chromium/ClipboardChromium.cpp:
        (WebCore::ClipboardChromium::files):
        * platform/gtk/ClipboardGtk.cpp:
        (WebCore::ClipboardGtk::files):
        * platform/mac/ClipboardMac.mm:
        (WebCore::ClipboardMac::files):
        * platform/win/ClipboardWin.cpp:
        (WebCore::ClipboardWin::files):

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@67208 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent da6ca9d9
2010-09-10 Michael Nordman <michaeln@google.com>
Reviewed by Dumitru Daniliuc.
Decouple Blob from ScriptExecutionContext.
https://bugs.webkit.org/show_bug.cgi?id=45410
- Removed ScriptExecutionContext pointers from Blob and File constructors.
- Removed ScriptExecutionContext's collection of Blobs instance in that context.
- Refactored BlobURL to make a distinction between 'public' blob urls and 'internal'
urls that are used solely as identifiers. The former requires a SecurityOrigin to
to manufacture, the latter does not.
- Added a constant and accessor for the blob protocol scheme on the BlobURL class.
No new tests are added since this is a cleanup.
* bindings/js/SerializedScriptValue.cpp:
(WebCore::CloneDeserializer::readFile):
(WebCore::CloneDeserializer::readTerminal):
* bindings/v8/SerializedScriptValue.cpp:
(WebCore::ZigZag::Reader::readBlob):
(WebCore::ZigZag::Reader::readFile):
(WebCore::ZigZag::Reader::readFileList):
* dom/ScriptExecutionContext.cpp:
(WebCore::ScriptExecutionContext::~ScriptExecutionContext):
(WebCore::ScriptExecutionContext::createPublicBlobURL):
(WebCore::ScriptExecutionContext::revokePublicBlobURL):
* dom/ScriptExecutionContext.h:
* fileapi/Blob.cpp:
(WebCore::Blob::Blob):
(WebCore::Blob::~Blob):
(WebCore::Blob::slice):
* fileapi/Blob.h:
(WebCore::Blob::create):
(WebCore::Blob::url):
* fileapi/Blob.idl:
* fileapi/BlobBuilder.cpp:
(WebCore::BlobBuilder::getBlob):
* fileapi/BlobBuilder.h:
* fileapi/BlobBuilder.idl:
* fileapi/BlobURL.cpp:
(WebCore::BlobURL::createPublicURL):
(WebCore::BlobURL::createInternalURL):
(WebCore::BlobURL::getOrigin):
(WebCore::BlobURL::getIdentifier):
(WebCore::BlobURL::createBlobURL):
* fileapi/BlobURL.h:
(WebCore::BlobURL::blobProtocol):
(WebCore::BlobURL::BlobURL):
* fileapi/File.cpp:
(WebCore::File::File):
* fileapi/File.h:
(WebCore::File::create):
* fileapi/FileReader.cpp: Register a public url to perform the read.
(WebCore::FileReader::cleanup):
(WebCore::FileReader::start):
(WebCore::FileReader::didFinishLoading):
(WebCore::FileReader::failed):
* fileapi/FileReader.h: Added m_urlForReading data member.
* fileapi/FileReaderSync.cpp:
(WebCore::FileReaderSync::read): Register a public url to perform the read.
* fileapi/ThreadableBlobRegistry.cpp:
(WebCore::ThreadableBlobRegistry::registerBlobURL):
(WebCore::ThreadableBlobRegistry::unregisterBlobURL):
* fileapi/ThreadableBlobRegistry.h:
* html/HTMLInputElement.cpp:
(WebCore::HTMLInputElement::appendFormData):
(WebCore::HTMLInputElement::setFileListFromRenderer):
* page/SecurityOrigin.cpp: Use BlobURL.blobProtocol().
(WebCore::SecurityOrigin::create):
(WebCore::SecurityOrigin::canRequest):
(WebCore::SecurityOrigin::canDisplay):
* platform/chromium/ClipboardChromium.cpp:
(WebCore::ClipboardChromium::files):
* platform/gtk/ClipboardGtk.cpp:
(WebCore::ClipboardGtk::files):
* platform/mac/ClipboardMac.mm:
(WebCore::ClipboardMac::files):
* platform/win/ClipboardWin.cpp:
(WebCore::ClipboardWin::files):
2010-09-10 Xan Lopez <xlopez@igalia.com>
Reviewed by Martin Robinson.
......@@ -974,10 +974,8 @@ private:
Identifier type;
if (!readStringData(type))
return 0;
if (m_isDOMGlobalObject) {
ScriptExecutionContext* scriptExecutionContext = static_cast<JSDOMGlobalObject*>(m_exec->lexicalGlobalObject())->scriptExecutionContext();
file = File::create(scriptExecutionContext, String(path.ustring().impl()), KURL(KURL(), String(url.ustring().impl())), String(type.ustring().impl()));
}
if (m_isDOMGlobalObject)
file = File::create(String(path.ustring().impl()), KURL(KURL(), String(url.ustring().impl())), String(type.ustring().impl()));
return true;
}
......@@ -1074,9 +1072,7 @@ private:
return JSValue();
if (!m_isDOMGlobalObject)
return jsNull();
ScriptExecutionContext* scriptExecutionContext = static_cast<JSDOMGlobalObject*>(m_exec->lexicalGlobalObject())->scriptExecutionContext();
ASSERT(scriptExecutionContext);
return toJS(m_exec, static_cast<JSDOMGlobalObject*>(m_globalObject), Blob::create(scriptExecutionContext, KURL(KURL(), url.ustring().impl()), String(type.ustring().impl()), size));
return toJS(m_exec, static_cast<JSDOMGlobalObject*>(m_globalObject), Blob::create(KURL(KURL(), url.ustring().impl()), String(type.ustring().impl()), size));
}
case StringTag: {
Identifier ident;
......
......@@ -879,7 +879,7 @@ private:
return false;
if (!doReadUint64(&size))
return false;
PassRefPtr<Blob> blob = Blob::create(getScriptExecutionContext(), KURL(ParsedURLString, url), type, size);
PassRefPtr<Blob> blob = Blob::create(KURL(ParsedURLString, url), type, size);
*value = toV8(blob);
return true;
}
......@@ -895,7 +895,7 @@ private:
return false;
if (!readWebCoreString(&type))
return false;
PassRefPtr<File> file = File::create(getScriptExecutionContext(), path, KURL(ParsedURLString, url), type);
PassRefPtr<File> file = File::create(path, KURL(ParsedURLString, url), type);
*value = toV8(file);
return true;
}
......@@ -916,7 +916,7 @@ private:
return false;
if (!readWebCoreString(&type))
return false;
fileList->append(File::create(getScriptExecutionContext(), path, KURL(ParsedURLString, urlString), type));
fileList->append(File::create(path, KURL(ParsedURLString, urlString), type));
}
*value = toV8(fileList);
return true;
......
......@@ -94,13 +94,10 @@ ScriptExecutionContext::~ScriptExecutionContext()
}
#endif
HashSet<Blob*>::iterator blobsEnd = m_blobs.end();
for (HashSet<Blob*>::iterator iter = m_blobs.begin(); iter != blobsEnd; ++iter)
(*iter)->contextDestroyed();
#if ENABLE(BLOB)
HashSet<String>::iterator publicBlobURLsEnd = m_publicBlobURLs.end();
for (HashSet<String>::iterator iter = m_publicBlobURLs.begin(); iter != publicBlobURLsEnd; ++iter)
ThreadableBlobRegistry::unregisterBlobURL(this, KURL(ParsedURLString, *iter));
ThreadableBlobRegistry::unregisterBlobURL(KURL(ParsedURLString, *iter));
#endif
}
......@@ -175,18 +172,6 @@ void ScriptExecutionContext::destroyedMessagePort(MessagePort* port)
m_messagePorts.remove(port);
}
void ScriptExecutionContext::addBlob(Blob* blob)
{
ASSERT(blob);
m_blobs.add(blob);
}
void ScriptExecutionContext::removeBlob(Blob* blob)
{
ASSERT(blob);
m_blobs.remove(blob);
}
bool ScriptExecutionContext::canSuspendActiveDOMObjects()
{
// No protection against m_activeDOMObjects changing during iteration: canSuspend() shouldn't execute arbitrary JS.
......@@ -277,8 +262,8 @@ DOMTimer* ScriptExecutionContext::findTimeout(int timeoutId)
#if ENABLE(BLOB)
KURL ScriptExecutionContext::createPublicBlobURL(Blob* blob)
{
KURL publicURL = BlobURL::createURL(this);
ThreadableBlobRegistry::registerBlobURL(this, publicURL, blob->url());
KURL publicURL = BlobURL::createPublicURL(securityOrigin());
ThreadableBlobRegistry::registerBlobURL(publicURL, blob->url());
m_publicBlobURLs.add(publicURL.string());
return publicURL;
}
......@@ -286,7 +271,7 @@ KURL ScriptExecutionContext::createPublicBlobURL(Blob* blob)
void ScriptExecutionContext::revokePublicBlobURL(const KURL& url)
{
if (m_publicBlobURLs.contains(url.string())) {
ThreadableBlobRegistry::unregisterBlobURL(this, url);
ThreadableBlobRegistry::unregisterBlobURL(url);
m_publicBlobURLs.remove(url.string());
}
}
......
......@@ -131,8 +131,6 @@ namespace WebCore {
void removeTimeout(int timeoutId);
DOMTimer* findTimeout(int timeoutId);
void addBlob(Blob*);
void removeBlob(Blob*);
#if ENABLE(BLOB)
KURL createPublicBlobURL(Blob*);
void revokePublicBlobURL(const KURL&);
......@@ -167,7 +165,6 @@ namespace WebCore {
HashMap<int, DOMTimer*> m_timeouts;
HashSet<Blob*> m_blobs;
#if ENABLE(BLOB)
HashSet<String> m_publicBlobURLs;
#endif
......
......@@ -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
......
......@@ -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;
};
......
......@@ -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
};
......
......@@ -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.
......
......@@ -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();
......
......@@ -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);
......
......@@ -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
......@@ -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() { }
};
}
......
......@@ -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)
{
......
......@@ -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;
......
......@@ -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);