| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2013 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 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 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 #ifndef HTMLDimension_h | 31 #include "config.h" |
| 32 #define HTMLDimension_h | 32 #include "V8File.h" |
| 33 | 33 |
| 34 #include "wtf/Forward.h" | 34 #include "RuntimeEnabledFeatures.h" |
| 35 #include "wtf/Vector.h" | 35 #include "bindings/v8/custom/V8BlobCustomHelpers.h" |
| 36 #include "core/fileapi/BlobBuilder.h" |
| 37 #include "wtf/RefPtr.h" |
| 36 | 38 |
| 37 namespace WebCore { | 39 namespace WebCore { |
| 38 | 40 |
| 39 // This class corresponds to a dimension as described in HTML5 by the | 41 void V8File::constructorCustom(const v8::FunctionCallbackInfo<v8::Value>& info) |
| 40 // "rules for parsing a list of dimensions" (section 2.4.4.6). | 42 { |
| 41 class HTMLDimension { | 43 if (!RuntimeEnabledFeatures::fileConstructorEnabled()) { |
| 42 public: | 44 throwTypeError("Illegal constructor", info.GetIsolate()); |
| 43 enum HTMLDimensionType { | 45 return; |
| 44 Relative, Percentage, Absolute | |
| 45 }; | |
| 46 | |
| 47 HTMLDimension() | |
| 48 : m_type(Absolute) | |
| 49 , m_value(0) | |
| 50 { | |
| 51 } | 46 } |
| 52 | 47 |
| 53 HTMLDimension(double value, HTMLDimensionType type) | 48 if (info.Length() < 2) { |
| 54 : m_type(type) | 49 throwTypeError("Constructor requires at least two arguments", info.GetIs
olate()); |
| 55 , m_value(value) | 50 return; |
| 56 { | |
| 57 } | 51 } |
| 58 | 52 |
| 59 HTMLDimensionType type() const { return m_type; } | 53 // FIXME: handle WebIDL sequences, see http://crbug.com/314755 |
| 54 if (!info[0]->IsArray()) { |
| 55 throwTypeError("First argument of the constructor is not of type Array",
info.GetIsolate()); |
| 56 return; |
| 57 } |
| 60 | 58 |
| 61 bool isRelative() const { return m_type == Relative; } | 59 V8TRYCATCH_FOR_V8STRINGRESOURCE_VOID(V8StringResource<>, fileName, info[1]); |
| 62 bool isPercentage() const { return m_type == Percentage; } | |
| 63 bool isAbsolute() const { return m_type == Absolute; } | |
| 64 | 60 |
| 65 double value() const { return m_value; } | 61 String contentType; |
| 62 String endings = "transparent"; |
| 66 | 63 |
| 67 bool operator==(const HTMLDimension& other) const | 64 if (info.Length() > 2) { |
| 68 { | 65 if (!info[2]->IsObject()) { |
| 69 return m_type == other.m_type && m_value == other.m_value; | 66 throwTypeError("Third argument of the constructor is not of type Obj
ect", info.GetIsolate()); |
| 67 return; |
| 68 } |
| 69 |
| 70 if (!V8BlobCustomHelpers::processBlobPropertyBag(info[2], info.GetIsolat
e(), contentType, endings)) |
| 71 return; |
| 70 } | 72 } |
| 71 bool operator!=(const HTMLDimension& other) const { return !(*this == other)
; } | 73 ASSERT(endings == "transparent" || endings == "native"); |
| 72 | 74 |
| 73 private: | 75 BlobBuilder blobBuilder; |
| 74 HTMLDimensionType m_type; | 76 if (!V8BlobCustomHelpers::processBlobParts(info[0], info.GetIsolate(), endin
gs, blobBuilder)) |
| 75 double m_value; | 77 return; |
| 76 }; | |
| 77 | 78 |
| 78 Vector<HTMLDimension> parseListOfDimensions(const String&); | 79 RefPtr<File> file = blobBuilder.createFile(contentType, fileName, currentTim
e()); |
| 80 info.GetReturnValue().Set(toV8(file.get(), info.Holder(), info.GetIsolate())
); |
| 81 } |
| 79 | 82 |
| 80 } // namespace WebCore | 83 } // namespace WebCore |
| 81 | |
| 82 #endif // HTMLDimension_h | |
| OLD | NEW |