| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2012 Google Inc. All rights reserved. | 2 * Copyright (C) 2013 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 |
| 11 * copyright notice, this list of conditions and the following disclaimer | 11 * copyright notice, this list of conditions and the following disclaimer |
| 12 * in the documentation and/or other materials provided with the | 12 * in the documentation and/or other materials provided with the |
| 13 * distribution. | 13 * distribution. |
| 14 * * Neither the name of Google Inc. nor the names of its | 14 * * Neither the name of Google Inc. nor the names of its |
| 15 * contributors may be used to endorse or promote products derived from | 15 * contributors may be used to endorse or promote products derived from |
| 16 * this software without specific prior written permission. | 16 * this software without specific prior written permission. |
| 17 * | 17 * |
| 18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | 18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | 19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | 20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | 21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | 22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | 23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 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 "V8File.h" |
| 33 | 33 |
| 34 #include "RuntimeEnabledFeatures.h" |
| 34 #include "bindings/v8/Dictionary.h" | 35 #include "bindings/v8/Dictionary.h" |
| 35 #include "bindings/v8/V8Binding.h" | 36 #include "bindings/v8/V8Binding.h" |
| 36 #include "bindings/v8/V8Utilities.h" | 37 #include "bindings/v8/V8Utilities.h" |
| 37 #include "bindings/v8/custom/V8ArrayBufferCustom.h" | 38 #include "bindings/v8/custom/V8ArrayBufferCustom.h" |
| 38 #include "bindings/v8/custom/V8ArrayBufferViewCustom.h" | 39 #include "bindings/v8/custom/V8ArrayBufferViewCustom.h" |
| 39 #include "core/fileapi/BlobBuilder.h" | 40 #include "core/fileapi/BlobBuilder.h" |
| 40 #include "wtf/RefPtr.h" | 41 #include "wtf/RefPtr.h" |
| 41 | 42 |
| 42 namespace WebCore { | 43 namespace WebCore { |
| 43 | 44 |
| 44 void V8Blob::constructorCustom(const v8::FunctionCallbackInfo<v8::Value>& info) | 45 void V8File::constructorCustom(const v8::FunctionCallbackInfo<v8::Value>& info) |
| 45 { | 46 { |
| 46 if (!info.Length()) { | 47 if (!RuntimeEnabledFeatures::fileConstructorEnabled()) { |
| 47 RefPtr<Blob> blob = Blob::create(); | 48 throwTypeError("Illegal constructor", info.GetIsolate()); |
| 48 info.GetReturnValue().Set(toV8(blob.get(), info.Holder(), info.GetIsolat
e())); | 49 return; |
| 50 } |
| 51 |
| 52 if (info.Length() < 2) { |
| 53 throwTypeError("Constructor requires at least two arguments", info.GetIs
olate()); |
| 49 return; | 54 return; |
| 50 } | 55 } |
| 51 | 56 |
| 52 v8::Local<v8::Value> firstArg = info[0]; | 57 v8::Local<v8::Value> firstArg = info[0]; |
| 58 // FIXME: handle WebIDL sequences, possibly by using toV8Sequence |
| 53 if (!firstArg->IsArray()) { | 59 if (!firstArg->IsArray()) { |
| 54 throwTypeError("First argument of the constructor is not of type Array",
info.GetIsolate()); | 60 throwTypeError("First argument of the constructor is not of type Array",
info.GetIsolate()); |
| 55 return; | 61 return; |
| 56 } | 62 } |
| 57 | 63 |
| 64 v8::Local<v8::Value> secondArg = info[1]; |
| 65 V8TRYCATCH_FOR_V8STRINGRESOURCE_VOID(V8StringResource<>, fileName, secondArg
); |
| 66 |
| 58 String type; | 67 String type; |
| 59 String endings = "transparent"; | 68 String endings = "transparent"; |
| 60 | 69 |
| 61 if (info.Length() > 1) { | 70 if (info.Length() > 2) { |
| 62 if (!info[1]->IsObject()) { | 71 if (!info[2]->IsObject()) { |
| 63 throwTypeError("Second argument of the constructor is not of type Ob
ject", info.GetIsolate()); | 72 throwTypeError("Third argument of the constructor is not of type Obj
ect", info.GetIsolate()); |
| 64 return; | 73 return; |
| 65 } | 74 } |
| 66 | 75 |
| 67 V8TRYCATCH_VOID(Dictionary, dictionary, Dictionary(info[1], info.GetIsol
ate())); | 76 V8TRYCATCH_VOID(Dictionary, dictionary, Dictionary(info[2], info.GetIsol
ate())); |
| 68 | 77 |
| 69 V8TRYCATCH_VOID(bool, containsEndings, dictionary.get("endings", endings
)); | 78 V8TRYCATCH_VOID(bool, containsEndings, dictionary.get("endings", endings
)); |
| 70 if (containsEndings) { | 79 if (containsEndings) { |
| 71 if (endings != "transparent" && endings != "native") { | 80 if (endings != "transparent" && endings != "native") { |
| 72 throwTypeError("The endings property must be either \"transparen
t\" or \"native\"", info.GetIsolate()); | 81 throwTypeError("The endings property must be either \"transparen
t\" or \"native\"", info.GetIsolate()); |
| 73 return; | 82 return; |
| 74 } | 83 } |
| 75 } | 84 } |
| 76 | 85 |
| 77 V8TRYCATCH_VOID(bool, containsType, dictionary.get("type", type)); | 86 V8TRYCATCH_VOID(bool, containsType, dictionary.get("type", type)); |
| (...skipping 26 matching lines...) Expand all Loading... |
| 104 } else if (V8Blob::HasInstance(item, info.GetIsolate(), worldType(info.G
etIsolate()))) { | 113 } else if (V8Blob::HasInstance(item, info.GetIsolate(), worldType(info.G
etIsolate()))) { |
| 105 Blob* blob = V8Blob::toNative(v8::Handle<v8::Object>::Cast(item)); | 114 Blob* blob = V8Blob::toNative(v8::Handle<v8::Object>::Cast(item)); |
| 106 ASSERT(blob); | 115 ASSERT(blob); |
| 107 blobBuilder.append(blob); | 116 blobBuilder.append(blob); |
| 108 } else { | 117 } else { |
| 109 V8TRYCATCH_FOR_V8STRINGRESOURCE_VOID(V8StringResource<>, stringValue
, item); | 118 V8TRYCATCH_FOR_V8STRINGRESOURCE_VOID(V8StringResource<>, stringValue
, item); |
| 110 blobBuilder.append(stringValue, endings); | 119 blobBuilder.append(stringValue, endings); |
| 111 } | 120 } |
| 112 } | 121 } |
| 113 | 122 |
| 114 RefPtr<Blob> blob = blobBuilder.getBlob(type); | 123 RefPtr<File> file = blobBuilder.getFile(type, fileName, currentTime()); |
| 115 info.GetReturnValue().Set(toV8(blob.get(), info.Holder(), info.GetIsolate())
); | 124 info.GetReturnValue().Set(toV8(file.get(), info.Holder(), info.GetIsolate())
); |
| 116 } | 125 } |
| 117 | 126 |
| 118 } // namespace WebCore | 127 } // namespace WebCore |
| 128 |
| OLD | NEW |