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

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: Rebased 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
« no previous file with comments | « Source/core/fileapi/Blob.h ('k') | Source/core/fileapi/Blob.idl » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "core/fileapi/File.h" 38 #include "core/fileapi/File.h"
37 #include "platform/blob/BlobRegistry.h" 39 #include "platform/blob/BlobRegistry.h"
38 #include "platform/blob/BlobURL.h" 40 #include "platform/blob/BlobURL.h"
39 41
40 namespace WebCore { 42 namespace WebCore {
41 43
42 namespace { 44 namespace {
43 45
44 class BlobURLRegistry FINAL : public URLRegistry { 46 class BlobURLRegistry FINAL : public URLRegistry {
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
97 end = 0; 99 end = 0;
98 if (start >= size) { 100 if (start >= size) {
99 start = 0; 101 start = 0;
100 end = 0; 102 end = 0;
101 } else if (end < start) 103 } else if (end < start)
102 end = start; 104 end = start;
103 else if (end > size) 105 else if (end > size)
104 end = size; 106 end = size;
105 } 107 }
106 108
107 PassRefPtrWillBeRawPtr<Blob> Blob::slice(long long start, long long end, const S tring& contentType) const 109 PassRefPtrWillBeRawPtr<Blob> Blob::slice(long long start, long long end, const S tring& contentType, ExceptionState& exceptionState) const
108 { 110 {
111 if (hasBeenClosed()) {
112 exceptionState.throwDOMException(InvalidStateError, "Blob has been close d.");
113 return nullptr;
114 }
115
109 long long size = this->size(); 116 long long size = this->size();
110 clampSliceOffsets(size, start, end); 117 clampSliceOffsets(size, start, end);
111 118
112 long long length = end - start; 119 long long length = end - start;
113 OwnPtr<BlobData> blobData = BlobData::create(); 120 OwnPtr<BlobData> blobData = BlobData::create();
114 blobData->setContentType(contentType); 121 blobData->setContentType(contentType);
115 blobData->appendBlob(m_blobDataHandle, start, length); 122 blobData->appendBlob(m_blobDataHandle, start, length);
116 return Blob::create(BlobDataHandle::create(blobData.release(), length)); 123 return Blob::create(BlobDataHandle::create(blobData.release(), length));
117 } 124 }
118 125
119 void Blob::close(ExecutionContext* executionContext) 126 void Blob::close(ExecutionContext* executionContext, ExceptionState& exceptionSt ate)
120 { 127 {
121 if (!hasBeenClosed()) { 128 if (hasBeenClosed()) {
122 // Dereferencing a Blob that has been closed should result in 129 exceptionState.throwDOMException(InvalidStateError, "Blob has been close d.");
123 // a network error. Revoke URLs registered against it through 130 return;
124 // its UUID. 131 }
125 DOMURL::revokeObjectUUID(executionContext, uuid());
126 132
127 // A closed Blob should have size zero, which most consumers 133 // Dereferencing a Blob that has been closed should result in
128 // will treat as an empty Blob. The exception being the FileReader 134 // a network error. Revoke URLs registered against it through
129 // read operations which will throw. 135 // its UUID.
130 // FIXME: spec not yet set in stone in this regard, track updates to it (http://crbug.com/344820.) 136 DOMURL::revokeObjectUUID(executionContext, uuid());
131 OwnPtr<BlobData> blobData = BlobData::create(); 137
132 blobData->setContentType(type()); 138 // A Blob enters a 'readability state' of closed, where it will report its
133 m_blobDataHandle = BlobDataHandle::create(blobData.release(), 0); 139 // size as zero. Blob and FileReader operations now throws on
134 m_hasBeenClosed = true; 140 // being passed a Blob in that state. Downstream uses of closed Blobs
135 } 141 // (e.g., XHR.send()) consider them as empty.
142 OwnPtr<BlobData> blobData = BlobData::create();
143 blobData->setContentType(type());
144 m_blobDataHandle = BlobDataHandle::create(blobData.release(), 0);
145 m_hasBeenClosed = true;
136 } 146 }
137 147
138 void Blob::appendTo(BlobData& blobData) const 148 void Blob::appendTo(BlobData& blobData) const
139 { 149 {
140 blobData.appendBlob(m_blobDataHandle, 0, m_blobDataHandle->size()); 150 blobData.appendBlob(m_blobDataHandle, 0, m_blobDataHandle->size());
141 } 151 }
142 152
143 URLRegistry& Blob::registry() const 153 URLRegistry& Blob::registry() const
144 { 154 {
145 return BlobURLRegistry::registry(); 155 return BlobURLRegistry::registry();
146 } 156 }
147 157
148 } // namespace WebCore 158 } // namespace WebCore
OLDNEW
« no previous file with comments | « Source/core/fileapi/Blob.h ('k') | Source/core/fileapi/Blob.idl » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698