Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright (C) 2012 Google Inc. All rights reserved. | 2 * Copyright (C) 2012 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 "V8Blob.h" | 32 #include "V8Blob.h" |
| 33 | 33 |
| 34 #include "bindings/v8/Dictionary.h" | 34 #include "bindings/v8/custom/V8BlobCustomHelpers.h" |
| 35 #include "bindings/v8/ExceptionMessages.h" | |
| 36 #include "bindings/v8/V8Binding.h" | |
| 37 #include "bindings/v8/V8Utilities.h" | |
| 38 #include "bindings/v8/custom/V8ArrayBufferCustom.h" | |
| 39 #include "bindings/v8/custom/V8ArrayBufferViewCustom.h" | |
| 40 #include "core/fileapi/BlobBuilder.h" | 35 #include "core/fileapi/BlobBuilder.h" |
| 41 #include "wtf/RefPtr.h" | 36 #include "wtf/RefPtr.h" |
|
haraken
2013/11/15 08:40:05
Nit: This won't be needed.
pwnall-personal
2013/11/15 10:28:53
Done.
Thank you!
| |
| 42 | 37 |
| 43 namespace WebCore { | 38 namespace WebCore { |
| 44 | 39 |
| 45 void V8Blob::constructorCustom(const v8::FunctionCallbackInfo<v8::Value>& info) | 40 void V8Blob::constructorCustom(const v8::FunctionCallbackInfo<v8::Value>& info) |
| 46 { | 41 { |
| 47 if (!info.Length()) { | 42 if (!info.Length()) { |
| 48 RefPtr<Blob> blob = Blob::create(); | 43 RefPtr<Blob> blob = Blob::create(); |
| 49 info.GetReturnValue().Set(toV8(blob.get(), info.Holder(), info.GetIsolat e())); | 44 info.GetReturnValue().Set(toV8(blob.get(), info.Holder(), info.GetIsolat e())); |
|
haraken
2013/11/15 08:40:05
Use v8SetReturnValue() in V8Binding.h.
pwnall-personal
2013/11/15 10:28:53
Done.
I just looked up how this works. It's really
| |
| 50 return; | 45 return; |
| 51 } | 46 } |
| 52 | 47 |
| 53 uint32_t length = 0; | 48 uint32_t length = 0; |
| 54 if (info[0]->IsArray()) { | 49 if (info[0]->IsArray()) { |
| 55 length = v8::Local<v8::Array>::Cast(info[0])->Length(); | 50 length = v8::Local<v8::Array>::Cast(info[0])->Length(); |
| 56 } else { | 51 } else { |
| 57 const int sequenceArgumentIndex = 0; | 52 const int sequenceArgumentIndex = 0; |
| 58 if (toV8Sequence(info[sequenceArgumentIndex], length, info.GetIsolate()) .IsEmpty()) { | 53 if (toV8Sequence(info[sequenceArgumentIndex], length, info.GetIsolate()) .IsEmpty()) { |
|
haraken
2013/11/15 08:40:05
I don't fully understand this code. You're calling
pwnall-personal
2013/11/15 10:28:53
FWIW, I think the toV8Sequence() method name is mi
haraken
2013/11/15 10:39:12
Ah, got it. I'd be happy if you could make the cha
| |
| 59 throwTypeError(ExceptionMessages::failedToConstruct("Blob", Exceptio nMessages::notAnArrayTypeArgumentOrValue(sequenceArgumentIndex + 1)), info.GetIs olate()); | 54 throwTypeError(ExceptionMessages::failedToConstruct("Blob", Exceptio nMessages::notAnArrayTypeArgumentOrValue(sequenceArgumentIndex + 1)), info.GetIs olate()); |
| 60 return; | 55 return; |
| 61 } | 56 } |
| 62 } | 57 } |
| 63 | 58 |
| 64 String type; | 59 String contentType; |
| 65 String endings = "transparent"; | 60 String endings = "transparent"; |
|
haraken
2013/11/15 08:40:05
Nit: How about setting 'endings = "transparent"' i
pwnall-personal
2013/11/15 10:28:53
I can't get rid of the default easily, because pro
haraken
2013/11/15 10:39:12
Understood. Let's keep it as is.
| |
| 66 | |
| 67 if (info.Length() > 1) { | 61 if (info.Length() > 1) { |
| 68 if (!info[1]->IsObject()) { | 62 if (!info[1]->IsObject()) { |
| 69 throwTypeError(ExceptionMessages::failedToConstruct("Blob", "The 2nd argument is not of type Object."), info.GetIsolate()); | 63 throwTypeError(ExceptionMessages::failedToConstruct("Blob", "The 2nd argument is not of type Object."), info.GetIsolate()); |
| 70 return; | 64 return; |
| 71 } | 65 } |
| 72 | 66 |
| 73 V8TRYCATCH_VOID(Dictionary, dictionary, Dictionary(info[1], info.GetIsol ate())); | 67 if (!V8BlobCustomHelpers::processBlobPropertyBag(info[1], info.GetIsolat e(), "Blob", contentType, endings)) |
|
haraken
2013/11/15 08:40:05
processBlobPropertyBag => processBlobDictionary ?
pwnall-personal
2013/11/15 08:58:42
I used BlobPropertyBag because that's the name tha
haraken
2013/11/15 09:09:40
Then let's call it processBlobPropertyBag. Sorry a
pwnall-personal
2013/11/15 10:28:53
FWIW, I also find the name a bit awkward :)
| |
| 74 | |
| 75 V8TRYCATCH_VOID(bool, containsEndings, dictionary.get("endings", endings )); | |
| 76 if (containsEndings) { | |
| 77 if (endings != "transparent" && endings != "native") { | |
| 78 throwTypeError(ExceptionMessages::failedToConstruct("Blob", "The 2nd argument's \"endings\" property must be either \"transparent\" or \"native\ "."), info.GetIsolate()); | |
| 79 return; | |
| 80 } | |
| 81 } | |
| 82 | |
| 83 V8TRYCATCH_VOID(bool, containsType, dictionary.get("type", type)); | |
| 84 UNUSED_PARAM(containsType); | |
| 85 if (!type.containsOnlyASCII()) { | |
| 86 throwError(v8SyntaxError, ExceptionMessages::failedToConstruct("Blob ", "The 2nd argument's \"type\" property must consist of ASCII characters."), in fo.GetIsolate()); | |
| 87 return; | 68 return; |
| 88 } | |
| 89 type = type.lower(); | |
| 90 } | 69 } |
| 91 | |
| 92 ASSERT(endings == "transparent" || endings == "native"); | 70 ASSERT(endings == "transparent" || endings == "native"); |
| 93 | 71 |
| 94 BlobBuilder blobBuilder; | 72 BlobBuilder blobBuilder; |
| 95 v8::Local<v8::Object> blobParts = v8::Local<v8::Object>::Cast(info[0]); | 73 v8::Local<v8::Object> blobParts = v8::Local<v8::Object>::Cast(info[0]); |
| 96 for (uint32_t i = 0; i < length; ++i) { | 74 if (!V8BlobCustomHelpers::processBlobParts(blobParts, length, info.GetIsolat e(), endings, blobBuilder)) |
| 97 v8::Local<v8::Value> item = blobParts->Get(v8::Uint32::New(i, info.GetIs olate())); | 75 return; |
| 98 if (item.IsEmpty()) | |
| 99 return; | |
| 100 | 76 |
| 101 if (V8ArrayBuffer::hasInstance(item, info.GetIsolate(), worldType(info.G etIsolate()))) { | 77 RefPtr<Blob> blob = blobBuilder.createBlob(contentType); |
| 102 ArrayBuffer* arrayBuffer = V8ArrayBuffer::toNative(v8::Handle<v8::Ob ject>::Cast(item)); | |
| 103 ASSERT(arrayBuffer); | |
| 104 blobBuilder.append(arrayBuffer); | |
| 105 } else if (V8ArrayBufferView::hasInstance(item, info.GetIsolate(), world Type(info.GetIsolate()))) { | |
| 106 ArrayBufferView* arrayBufferView = V8ArrayBufferView::toNative(v8::H andle<v8::Object>::Cast(item)); | |
| 107 ASSERT(arrayBufferView); | |
| 108 blobBuilder.append(arrayBufferView); | |
| 109 } else if (V8Blob::hasInstance(item, info.GetIsolate(), worldType(info.G etIsolate()))) { | |
| 110 Blob* blob = V8Blob::toNative(v8::Handle<v8::Object>::Cast(item)); | |
| 111 ASSERT(blob); | |
| 112 blobBuilder.append(blob); | |
| 113 } else { | |
| 114 V8TRYCATCH_FOR_V8STRINGRESOURCE_VOID(V8StringResource<>, stringValue , item); | |
| 115 blobBuilder.append(stringValue, endings); | |
| 116 } | |
| 117 } | |
| 118 | |
| 119 RefPtr<Blob> blob = blobBuilder.getBlob(type); | |
| 120 info.GetReturnValue().Set(toV8(blob.get(), info.Holder(), info.GetIsolate()) ); | 78 info.GetReturnValue().Set(toV8(blob.get(), info.Holder(), info.GetIsolate()) ); |
|
haraken
2013/11/15 08:40:05
Use v8SetReturnValue() in V8Binding.h.
pwnall-personal
2013/11/15 10:28:53
Done.
| |
| 121 } | 79 } |
| 122 | 80 |
| 123 } // namespace WebCore | 81 } // namespace WebCore |
| OLD | NEW |