This source file includes following definitions.
- registerURL
- unregisterURL
- registry
- m_hasBeenClosed
- clampSliceOffsets
- slice
- close
- appendTo
- registry
#include "config.h"
#include "core/fileapi/Blob.h"
#include "bindings/v8/ExceptionState.h"
#include "core/dom/DOMURL.h"
#include "core/dom/ExceptionCode.h"
#include "core/dom/ExecutionContext.h"
#include "core/fileapi/File.h"
#include "platform/blob/BlobRegistry.h"
#include "platform/blob/BlobURL.h"
namespace WebCore {
namespace {
class BlobURLRegistry FINAL : public URLRegistry {
public:
virtual void registerURL(SecurityOrigin*, const KURL&, URLRegistrable*) OVERRIDE;
virtual void unregisterURL(const KURL&) OVERRIDE;
static URLRegistry& registry();
};
void BlobURLRegistry::registerURL(SecurityOrigin* origin, const KURL& publicURL, URLRegistrable* registrableObject)
{
ASSERT(®istrableObject->registry() == this);
Blob* blob = static_cast<Blob*>(registrableObject);
BlobRegistry::registerPublicBlobURL(origin, publicURL, blob->blobDataHandle());
}
void BlobURLRegistry::unregisterURL(const KURL& publicURL)
{
BlobRegistry::revokePublicBlobURL(publicURL);
}
URLRegistry& BlobURLRegistry::registry()
{
DEFINE_STATIC_LOCAL(BlobURLRegistry, instance, ());
return instance;
}
}
Blob::Blob(PassRefPtr<BlobDataHandle> dataHandle)
: m_blobDataHandle(dataHandle)
, m_hasBeenClosed(false)
{
ScriptWrappable::init(this);
}
Blob::~Blob()
{
}
void Blob::clampSliceOffsets(long long size, long long& start, long long& end)
{
ASSERT(size != -1);
if (start < 0)
start = start + size;
if (end < 0)
end = end + size;
if (start < 0)
start = 0;
if (end < 0)
end = 0;
if (start >= size) {
start = 0;
end = 0;
} else if (end < start)
end = start;
else if (end > size)
end = size;
}
PassRefPtrWillBeRawPtr<Blob> Blob::slice(long long start, long long end, const String& contentType, ExceptionState& exceptionState) const
{
if (hasBeenClosed()) {
exceptionState.throwDOMException(InvalidStateError, "Blob has been closed.");
return nullptr;
}
long long size = this->size();
clampSliceOffsets(size, start, end);
long long length = end - start;
OwnPtr<BlobData> blobData = BlobData::create();
blobData->setContentType(contentType);
blobData->appendBlob(m_blobDataHandle, start, length);
return Blob::create(BlobDataHandle::create(blobData.release(), length));
}
void Blob::close(ExecutionContext* executionContext, ExceptionState& exceptionState)
{
if (hasBeenClosed()) {
exceptionState.throwDOMException(InvalidStateError, "Blob has been closed.");
return;
}
DOMURL::revokeObjectUUID(executionContext, uuid());
OwnPtr<BlobData> blobData = BlobData::create();
blobData->setContentType(type());
m_blobDataHandle = BlobDataHandle::create(blobData.release(), 0);
m_hasBeenClosed = true;
}
void Blob::appendTo(BlobData& blobData) const
{
blobData.appendBlob(m_blobDataHandle, 0, m_blobDataHandle->size());
}
URLRegistry& Blob::registry() const
{
return BlobURLRegistry::registry();
}
}