15c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)/* 25c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * Copyright (C) 2010 Google Inc. All rights reserved. 35c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * 45c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * Redistribution and use in source and binary forms, with or without 55c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * modification, are permitted provided that the following conditions are 65c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * met: 75c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * 85c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * * Redistributions of source code must retain the above copyright 95c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * notice, this list of conditions and the following disclaimer. 105c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * * Redistributions in binary form must reproduce the above 115c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * copyright notice, this list of conditions and the following disclaimer 125c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * in the documentation and/or other materials provided with the 135c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * distribution. 145c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * * Neither the name of Google Inc. nor the names of its 155c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * contributors may be used to endorse or promote products derived from 165c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * this software without specific prior written permission. 175c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * 185c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 195c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 205c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 215c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 225c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 235c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 245c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 255c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 265c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 275c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 285c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 295c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) */ 305c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 315c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)#ifndef Blob_h 325c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)#define Blob_h 335c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 3453e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)#include "bindings/v8/ScriptWrappable.h" 355267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles)#include "core/html/URLRegistry.h" 36bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles)#include "platform/blob/BlobData.h" 37521d96ec04ace82590870fb04353ec4f82bb150fTorne (Richard Coles)#include "wtf/PassOwnPtr.h" 38521d96ec04ace82590870fb04353ec4f82bb150fTorne (Richard Coles)#include "wtf/PassRefPtr.h" 39521d96ec04ace82590870fb04353ec4f82bb150fTorne (Richard Coles)#include "wtf/RefCounted.h" 40521d96ec04ace82590870fb04353ec4f82bb150fTorne (Richard Coles)#include "wtf/text/WTFString.h" 415c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 425c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)namespace WebCore { 435c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 441e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)class ExecutionContext; 455c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 465267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles)class Blob : public ScriptWrappable, public URLRegistrable, public RefCounted<Blob> { 475c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)public: 485c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) static PassRefPtr<Blob> create() 495c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) { 501e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles) return adoptRef(new Blob(BlobDataHandle::create())); 515c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) } 525c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 531e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles) static PassRefPtr<Blob> create(PassRefPtr<BlobDataHandle> blobDataHandle) 545c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) { 551e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles) return adoptRef(new Blob(blobDataHandle)); 565c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) } 575c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 585c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) virtual ~Blob(); 595c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 601e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles) String uuid() const { return m_blobDataHandle->uuid(); } 611e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles) String type() const { return m_blobDataHandle->type(); } 621e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles) virtual unsigned long long size() const { return m_blobDataHandle->size(); } 6351b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) // True for all File instances, including the user-built ones. 645c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) virtual bool isFile() const { return false; } 6551b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) // Only true for File instances that are backed by platform files. 6651b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) virtual bool hasBackingFile() const { return false; } 671e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles) PassRefPtr<BlobDataHandle> blobDataHandle() const { return m_blobDataHandle; } 681e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles) PassRefPtr<Blob> slice(long long start = 0, long long end = std::numeric_limits<long long>::max(), const String& contentType = String()) const; 695c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 701e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles) // URLRegistrable to support PublicURLs. 715267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) virtual URLRegistry& registry() const OVERRIDE; 725267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) 735c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)protected: 741e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles) explicit Blob(PassRefPtr<BlobDataHandle>); 755c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 761e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)private: 771e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles) Blob(); 781e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles) RefPtr<BlobDataHandle> m_blobDataHandle; 795c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)}; 805c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 815c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)} // namespace WebCore 825c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 835c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)#endif // Blob_h 84