Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright (C) 2010 Google Inc. All rights reserved. | 2 * Copyright (C) 2010 Google Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
| 6 * met: | 6 * met: |
| 7 * | 7 * |
| 8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 29 */ | 29 */ |
| 30 | 30 |
| 31 #include "config.h" | 31 #include "config.h" |
| 32 #include "core/fileapi/Blob.h" | 32 #include "core/fileapi/Blob.h" |
| 33 | 33 |
| 34 #include "core/dom/ExecutionContext.h" | |
| 35 #include "core/html/PublicURLManager.h" | |
| 34 #include "platform/blob/BlobRegistry.h" | 36 #include "platform/blob/BlobRegistry.h" |
| 35 #include "platform/blob/BlobURL.h" | 37 #include "platform/blob/BlobURL.h" |
| 36 | 38 |
| 37 namespace WebCore { | 39 namespace WebCore { |
| 38 | 40 |
| 39 namespace { | 41 namespace { |
| 40 | 42 |
| 41 class BlobURLRegistry FINAL : public URLRegistry { | 43 class BlobURLRegistry FINAL : public URLRegistry { |
| 42 public: | 44 public: |
| 43 virtual void registerURL(SecurityOrigin*, const KURL&, URLRegistrable*) OVER RIDE; | 45 virtual void registerURL(SecurityOrigin*, const KURL&, URLRegistrable*) OVER RIDE; |
| 44 virtual void unregisterURL(const KURL&) OVERRIDE; | 46 virtual void unregisterURL(const KURL&) OVERRIDE; |
| 45 | 47 |
| 46 static URLRegistry& registry(); | 48 static URLRegistry& registry(); |
| 47 }; | 49 }; |
| 48 | 50 |
| 49 void BlobURLRegistry::registerURL(SecurityOrigin* origin, const KURL& publicURL, URLRegistrable* blob) | 51 void BlobURLRegistry::registerURL(SecurityOrigin* origin, const KURL& publicURL, URLRegistrable* registrableObject) |
| 50 { | 52 { |
| 51 ASSERT(&blob->registry() == this); | 53 ASSERT(®istrableObject->registry() == this); |
| 52 BlobRegistry::registerPublicBlobURL(origin, publicURL, static_cast<Blob*>(bl ob)->blobDataHandle()); | 54 Blob* blob = static_cast<Blob*>(registrableObject); |
| 55 BlobRegistry::registerPublicBlobURL(origin, publicURL, blob->blobDataHandle( )); | |
| 53 } | 56 } |
| 54 | 57 |
| 55 void BlobURLRegistry::unregisterURL(const KURL& publicURL) | 58 void BlobURLRegistry::unregisterURL(const KURL& publicURL) |
| 56 { | 59 { |
| 57 BlobRegistry::revokePublicBlobURL(publicURL); | 60 BlobRegistry::revokePublicBlobURL(publicURL); |
| 58 } | 61 } |
| 59 | 62 |
| 60 URLRegistry& BlobURLRegistry::registry() | 63 URLRegistry& BlobURLRegistry::registry() |
| 61 { | 64 { |
| 62 DEFINE_STATIC_LOCAL(BlobURLRegistry, instance, ()); | 65 DEFINE_STATIC_LOCAL(BlobURLRegistry, instance, ()); |
| 63 return instance; | 66 return instance; |
| 64 } | 67 } |
| 65 | 68 |
| 66 } // namespace | 69 } // namespace |
| 67 | 70 |
| 68 Blob::Blob(PassRefPtr<BlobDataHandle> dataHandle) | 71 Blob::Blob(PassRefPtr<BlobDataHandle> dataHandle) |
| 69 : m_blobDataHandle(dataHandle) | 72 : m_blobDataHandle(dataHandle) |
| 73 , m_hasBeenClosed(false) | |
| 70 { | 74 { |
| 71 ScriptWrappable::init(this); | 75 ScriptWrappable::init(this); |
| 72 } | 76 } |
| 73 | 77 |
| 74 Blob::~Blob() | 78 Blob::~Blob() |
| 75 { | 79 { |
| 76 } | 80 } |
| 77 | 81 |
| 78 void Blob::clampSliceOffsets(long long size, long long& start, long long& end) | 82 void Blob::clampSliceOffsets(long long size, long long& start, long long& end) |
| 79 { | 83 { |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 104 long long size = this->size(); | 108 long long size = this->size(); |
| 105 clampSliceOffsets(size, start, end); | 109 clampSliceOffsets(size, start, end); |
| 106 | 110 |
| 107 long long length = end - start; | 111 long long length = end - start; |
| 108 OwnPtr<BlobData> blobData = BlobData::create(); | 112 OwnPtr<BlobData> blobData = BlobData::create(); |
| 109 blobData->setContentType(contentType); | 113 blobData->setContentType(contentType); |
| 110 blobData->appendBlob(m_blobDataHandle, start, length); | 114 blobData->appendBlob(m_blobDataHandle, start, length); |
| 111 return Blob::create(BlobDataHandle::create(blobData.release(), length)); | 115 return Blob::create(BlobDataHandle::create(blobData.release(), length)); |
| 112 } | 116 } |
| 113 | 117 |
| 118 void Blob::close(ExecutionContext* executionContext) | |
| 119 { | |
| 120 if (!hasBeenClosed()) { | |
| 121 // Dereferencing a Blob that has been closed should result in | |
| 122 // a network error. Revoke URLs registered against it through | |
| 123 // its UUID. | |
| 124 executionContext->publicURLManager().revoke(uuid()); | |
| 125 | |
| 126 // A closed Blob should have size zero, which most consumers | |
| 127 // will treat as an empty Blob. The exception being the FileReader | |
| 128 // read operations which will throw. | |
| 129 OwnPtr<BlobData> blobData = BlobData::create(); | |
| 130 blobData->setContentType(type()); | |
| 131 m_blobDataHandle = BlobDataHandle::create(blobData.release(), 0); | |
|
michaeln
2014/02/12 20:33:04
nice and safe :)
| |
| 132 m_hasBeenClosed = true; | |
| 133 } | |
| 134 } | |
| 135 | |
| 114 void Blob::appendTo(BlobData& blobData) const | 136 void Blob::appendTo(BlobData& blobData) const |
| 115 { | 137 { |
| 116 blobData.appendBlob(m_blobDataHandle, 0, m_blobDataHandle->size()); | 138 blobData.appendBlob(m_blobDataHandle, 0, m_blobDataHandle->size()); |
| 117 } | 139 } |
| 118 | 140 |
| 119 URLRegistry& Blob::registry() const | 141 URLRegistry& Blob::registry() const |
| 120 { | 142 { |
| 121 return BlobURLRegistry::registry(); | 143 return BlobURLRegistry::registry(); |
| 122 } | 144 } |
| 123 | 145 |
| 124 | |
| 125 } // namespace WebCore | 146 } // namespace WebCore |
| OLD | NEW |