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

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

Issue 2147633002: Remove nonstandard 'endings' option for Blob/File constructor (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Layout test updates Created 4 years, 5 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 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
88 88
89 // static 89 // static
90 Blob* Blob::create(ExecutionContext* context, const HeapVector<ArrayBufferOrArra yBufferViewOrBlobOrUSVString>& blobParts, const BlobPropertyBag& options, Except ionState& exceptionState) 90 Blob* Blob::create(ExecutionContext* context, const HeapVector<ArrayBufferOrArra yBufferViewOrBlobOrUSVString>& blobParts, const BlobPropertyBag& options, Except ionState& exceptionState)
91 { 91 {
92 ASSERT(options.hasType()); 92 ASSERT(options.hasType());
93 if (!options.type().containsOnlyASCII()) { 93 if (!options.type().containsOnlyASCII()) {
94 exceptionState.throwDOMException(SyntaxError, "The 'type' property must consist of ASCII characters."); 94 exceptionState.throwDOMException(SyntaxError, "The 'type' property must consist of ASCII characters.");
95 return nullptr; 95 return nullptr;
96 } 96 }
97 97
98 ASSERT(options.hasEndings());
99 bool normalizeLineEndingsToNative = options.endings() == "native";
100 if (normalizeLineEndingsToNative)
101 UseCounter::count(context, UseCounter::FileAPINativeLineEndings);
102
103 std::unique_ptr<BlobData> blobData = BlobData::create(); 98 std::unique_ptr<BlobData> blobData = BlobData::create();
104 blobData->setContentType(options.type().lower()); 99 blobData->setContentType(options.type().lower());
105 100
106 populateBlobData(blobData.get(), blobParts, normalizeLineEndingsToNative); 101 populateBlobData(blobData.get(), blobParts);
107 102
108 long long blobSize = blobData->length(); 103 long long blobSize = blobData->length();
109 return new Blob(BlobDataHandle::create(std::move(blobData), blobSize)); 104 return new Blob(BlobDataHandle::create(std::move(blobData), blobSize));
110 } 105 }
111 106
112 Blob* Blob::create(const unsigned char* data, size_t bytes, const String& conten tType) 107 Blob* Blob::create(const unsigned char* data, size_t bytes, const String& conten tType)
113 { 108 {
114 ASSERT(data); 109 ASSERT(data);
115 110
116 std::unique_ptr<BlobData> blobData = BlobData::create(); 111 std::unique_ptr<BlobData> blobData = BlobData::create();
117 blobData->setContentType(contentType); 112 blobData->setContentType(contentType);
118 blobData->appendBytes(data, bytes); 113 blobData->appendBytes(data, bytes);
119 long long blobSize = blobData->length(); 114 long long blobSize = blobData->length();
120 115
121 return new Blob(BlobDataHandle::create(std::move(blobData), blobSize)); 116 return new Blob(BlobDataHandle::create(std::move(blobData), blobSize));
122 } 117 }
123 118
124 // static 119 // static
125 void Blob::populateBlobData(BlobData* blobData, const HeapVector<ArrayBufferOrAr rayBufferViewOrBlobOrUSVString>& parts, bool normalizeLineEndingsToNative) 120 void Blob::populateBlobData(BlobData* blobData, const HeapVector<ArrayBufferOrAr rayBufferViewOrBlobOrUSVString>& parts)
126 { 121 {
127 for (const auto& item : parts) { 122 for (const auto& item : parts) {
128 if (item.isArrayBuffer()) { 123 if (item.isArrayBuffer()) {
129 DOMArrayBuffer* arrayBuffer = item.getAsArrayBuffer(); 124 DOMArrayBuffer* arrayBuffer = item.getAsArrayBuffer();
130 blobData->appendBytes(arrayBuffer->data(), arrayBuffer->byteLength() ); 125 blobData->appendBytes(arrayBuffer->data(), arrayBuffer->byteLength() );
131 } else if (item.isArrayBufferView()) { 126 } else if (item.isArrayBufferView()) {
132 DOMArrayBufferView* arrayBufferView = item.getAsArrayBufferView(); 127 DOMArrayBufferView* arrayBufferView = item.getAsArrayBufferView();
133 blobData->appendBytes(arrayBufferView->baseAddress(), arrayBufferVie w->byteLength()); 128 blobData->appendBytes(arrayBufferView->baseAddress(), arrayBufferVie w->byteLength());
134 } else if (item.isBlob()) { 129 } else if (item.isBlob()) {
135 item.getAsBlob()->appendTo(*blobData); 130 item.getAsBlob()->appendTo(*blobData);
136 } else if (item.isUSVString()) { 131 } else if (item.isUSVString()) {
137 blobData->appendText(item.getAsUSVString(), normalizeLineEndingsToNa tive); 132 blobData->appendText(item.getAsUSVString());
138 } else { 133 } else {
139 NOTREACHED(); 134 NOTREACHED();
140 } 135 }
141 } 136 }
142 } 137 }
143 138
144 // static 139 // static
145 void Blob::clampSliceOffsets(long long size, long long& start, long long& end) 140 void Blob::clampSliceOffsets(long long size, long long& start, long long& end)
146 { 141 {
147 ASSERT(size != -1); 142 ASSERT(size != -1);
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
210 { 205 {
211 blobData.appendBlob(m_blobDataHandle, 0, m_blobDataHandle->size()); 206 blobData.appendBlob(m_blobDataHandle, 0, m_blobDataHandle->size());
212 } 207 }
213 208
214 URLRegistry& Blob::registry() const 209 URLRegistry& Blob::registry() const
215 { 210 {
216 return BlobURLRegistry::registry(); 211 return BlobURLRegistry::registry();
217 } 212 }
218 213
219 } // namespace blink 214 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698