Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(200)

Side by Side Diff: Source/core/fileapi/Blob.cpp

Issue 184473002: Sync Blob.close() behavior wrt updated spec. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 6 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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 "bindings/v8/ExceptionState.h"
34 #include "core/dom/DOMURL.h" 35 #include "core/dom/DOMURL.h"
36 #include "core/dom/ExceptionCode.h"
35 #include "core/dom/ExecutionContext.h" 37 #include "core/dom/ExecutionContext.h"
36 #include "platform/blob/BlobRegistry.h" 38 #include "platform/blob/BlobRegistry.h"
37 #include "platform/blob/BlobURL.h" 39 #include "platform/blob/BlobURL.h"
38 40
39 namespace WebCore { 41 namespace WebCore {
40 42
41 namespace { 43 namespace {
42 44
43 class BlobURLRegistry FINAL : public URLRegistry { 45 class BlobURLRegistry FINAL : public URLRegistry {
44 public: 46 public:
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
96 end = 0; 98 end = 0;
97 if (start >= size) { 99 if (start >= size) {
98 start = 0; 100 start = 0;
99 end = 0; 101 end = 0;
100 } else if (end < start) 102 } else if (end < start)
101 end = start; 103 end = start;
102 else if (end > size) 104 else if (end > size)
103 end = size; 105 end = size;
104 } 106 }
105 107
106 PassRefPtr<Blob> Blob::slice(long long start, long long end, const String& conte ntType) const 108 PassRefPtr<Blob> Blob::slice(long long start, long long end, const String& conte ntType, ExceptionState& exceptionState) const
107 { 109 {
110 if (hasBeenClosed()) {
111 exceptionState.throwDOMException(InvalidStateError, "Blob has been close d.");
112 return nullptr;
113 }
114
108 long long size = this->size(); 115 long long size = this->size();
109 clampSliceOffsets(size, start, end); 116 clampSliceOffsets(size, start, end);
110 117
111 long long length = end - start; 118 long long length = end - start;
112 OwnPtr<BlobData> blobData = BlobData::create(); 119 OwnPtr<BlobData> blobData = BlobData::create();
113 blobData->setContentType(contentType); 120 blobData->setContentType(contentType);
114 blobData->appendBlob(m_blobDataHandle, start, length); 121 blobData->appendBlob(m_blobDataHandle, start, length);
115 return Blob::create(BlobDataHandle::create(blobData.release(), length)); 122 return Blob::create(BlobDataHandle::create(blobData.release(), length));
116 } 123 }
117 124
118 void Blob::close(ExecutionContext* executionContext) 125 void Blob::close(ExecutionContext* executionContext, ExceptionState& exceptionSt ate)
119 { 126 {
120 if (!hasBeenClosed()) { 127 if (hasBeenClosed()) {
121 // Dereferencing a Blob that has been closed should result in 128 exceptionState.throwDOMException(InvalidStateError, "Blob has been close d.");
122 // a network error. Revoke URLs registered against it through 129 return;
123 // its UUID. 130 }
124 DOMURL::revokeObjectUUID(executionContext, uuid());
125 131
126 // A closed Blob should have size zero, which most consumers 132 // Dereferencing a Blob that has been closed should result in
127 // will treat as an empty Blob. The exception being the FileReader 133 // a network error. Revoke URLs registered against it through
128 // read operations which will throw. 134 // its UUID.
129 // FIXME: spec not yet set in stone in this regard, track updates to it (http://crbug.com/344820.) 135 DOMURL::revokeObjectUUID(executionContext, uuid());
130 OwnPtr<BlobData> blobData = BlobData::create(); 136
131 blobData->setContentType(type()); 137 // A Blob enters a 'readability state' of closed, where it will report its
132 m_blobDataHandle = BlobDataHandle::create(blobData.release(), 0); 138 // size as zero. Blob and FileReader operations now throws on
133 m_hasBeenClosed = true; 139 // being passed a Blob in that state. Downstream uses of closed Blobs
134 } 140 // (e.g., XHR.send()) consider them as empty.
141 OwnPtr<BlobData> blobData = BlobData::create();
142 blobData->setContentType(type());
143 m_blobDataHandle = BlobDataHandle::create(blobData.release(), 0);
144 m_hasBeenClosed = true;
135 } 145 }
136 146
137 void Blob::appendTo(BlobData& blobData) const 147 void Blob::appendTo(BlobData& blobData) const
138 { 148 {
139 blobData.appendBlob(m_blobDataHandle, 0, m_blobDataHandle->size()); 149 blobData.appendBlob(m_blobDataHandle, 0, m_blobDataHandle->size());
140 } 150 }
141 151
142 URLRegistry& Blob::registry() const 152 URLRegistry& Blob::registry() const
143 { 153 {
144 return BlobURLRegistry::registry(); 154 return BlobURLRegistry::registry();
145 } 155 }
146 156
147 } // namespace WebCore 157 } // namespace WebCore
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698