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/V8Binding.h" | |
36 #include "bindings/v8/V8Utilities.h" | |
37 #include "bindings/v8/custom/V8ArrayBufferCustom.h" | |
38 #include "bindings/v8/custom/V8ArrayBufferViewCustom.h" | |
39 #include "core/fileapi/BlobBuilder.h" | 35 #include "core/fileapi/BlobBuilder.h" |
40 #include "wtf/RefPtr.h" | 36 #include "wtf/RefPtr.h" |
41 | 37 |
42 namespace WebCore { | 38 namespace WebCore { |
43 | 39 |
44 void V8Blob::constructorCustom(const v8::FunctionCallbackInfo<v8::Value>& info) | 40 void V8Blob::constructorCustom(const v8::FunctionCallbackInfo<v8::Value>& info) |
45 { | 41 { |
46 if (!info.Length()) { | 42 if (!info.Length()) { |
47 RefPtr<Blob> blob = Blob::create(); | 43 RefPtr<Blob> blob = Blob::create(); |
48 info.GetReturnValue().Set(toV8(blob.get(), info.Holder(), info.GetIsolat
e())); | 44 info.GetReturnValue().Set(toV8(blob.get(), info.Holder(), info.GetIsolat
e())); |
49 return; | 45 return; |
50 } | 46 } |
51 | 47 |
52 v8::Local<v8::Value> firstArg = info[0]; | 48 // FIXME: handle WebIDL sequences, see http://crbug.com/314755 |
53 if (!firstArg->IsArray()) { | 49 if (!info[0]->IsArray()) { |
54 throwTypeError("First argument of the constructor is not of type Array",
info.GetIsolate()); | 50 throwTypeError("First argument of the constructor is not of type Array",
info.GetIsolate()); |
55 return; | 51 return; |
56 } | 52 } |
57 | 53 |
58 String type; | 54 String contentType; |
59 String endings = "transparent"; | 55 String endings = "transparent"; |
60 | |
61 if (info.Length() > 1) { | 56 if (info.Length() > 1) { |
62 if (!info[1]->IsObject()) { | 57 if (!info[1]->IsObject()) { |
63 throwTypeError("Second argument of the constructor is not of type Ob
ject", info.GetIsolate()); | 58 throwTypeError("Second argument of the constructor is not of type Ob
ject", info.GetIsolate()); |
64 return; | 59 return; |
65 } | 60 } |
66 | 61 |
67 V8TRYCATCH_VOID(Dictionary, dictionary, Dictionary(info[1], info.GetIsol
ate())); | 62 if (!V8BlobCustomHelpers::processBlobPropertyBag(info[1], info.GetIsolat
e(), contentType, endings)) |
68 | |
69 V8TRYCATCH_VOID(bool, containsEndings, dictionary.get("endings", endings
)); | |
70 if (containsEndings) { | |
71 if (endings != "transparent" && endings != "native") { | |
72 throwTypeError("The endings property must be either \"transparen
t\" or \"native\"", info.GetIsolate()); | |
73 return; | |
74 } | |
75 } | |
76 | |
77 V8TRYCATCH_VOID(bool, containsType, dictionary.get("type", type)); | |
78 UNUSED_PARAM(containsType); | |
79 if (!type.containsOnlyASCII()) { | |
80 throwError(v8SyntaxError, "type must consist of ASCII characters", i
nfo.GetIsolate()); | |
81 return; | 63 return; |
82 } | |
83 type = type.lower(); | |
84 } | 64 } |
85 | |
86 ASSERT(endings == "transparent" || endings == "native"); | 65 ASSERT(endings == "transparent" || endings == "native"); |
87 | 66 |
88 BlobBuilder blobBuilder; | 67 BlobBuilder blobBuilder; |
| 68 if (!V8BlobCustomHelpers::processBlobParts(info[0], info.GetIsolate(), endin
gs, blobBuilder)) |
| 69 return; |
89 | 70 |
90 V8TRYCATCH_VOID(v8::Local<v8::Array>, blobParts, v8::Local<v8::Array>::Cast(
firstArg)); | 71 RefPtr<Blob> blob = blobBuilder.createBlob(contentType); |
91 uint32_t length = blobParts->Length(); | |
92 | |
93 for (uint32_t i = 0; i < length; ++i) { | |
94 v8::Local<v8::Value> item = blobParts->Get(v8::Uint32::New(i, info.GetIs
olate())); | |
95 ASSERT(!item.IsEmpty()); | |
96 if (V8ArrayBuffer::HasInstance(item, info.GetIsolate(), worldType(info.G
etIsolate()))) { | |
97 ArrayBuffer* arrayBuffer = V8ArrayBuffer::toNative(v8::Handle<v8::Ob
ject>::Cast(item)); | |
98 ASSERT(arrayBuffer); | |
99 blobBuilder.append(arrayBuffer); | |
100 } else if (V8ArrayBufferView::HasInstance(item, info.GetIsolate(), world
Type(info.GetIsolate()))) { | |
101 ArrayBufferView* arrayBufferView = V8ArrayBufferView::toNative(v8::H
andle<v8::Object>::Cast(item)); | |
102 ASSERT(arrayBufferView); | |
103 blobBuilder.append(arrayBufferView); | |
104 } else if (V8Blob::HasInstance(item, info.GetIsolate(), worldType(info.G
etIsolate()))) { | |
105 Blob* blob = V8Blob::toNative(v8::Handle<v8::Object>::Cast(item)); | |
106 ASSERT(blob); | |
107 blobBuilder.append(blob); | |
108 } else { | |
109 V8TRYCATCH_FOR_V8STRINGRESOURCE_VOID(V8StringResource<>, stringValue
, item); | |
110 blobBuilder.append(stringValue, endings); | |
111 } | |
112 } | |
113 | |
114 RefPtr<Blob> blob = blobBuilder.getBlob(type); | |
115 info.GetReturnValue().Set(toV8(blob.get(), info.Holder(), info.GetIsolate())
); | 72 info.GetReturnValue().Set(toV8(blob.get(), info.Holder(), info.GetIsolate())
); |
116 } | 73 } |
117 | 74 |
118 } // namespace WebCore | 75 } // namespace WebCore |
OLD | NEW |