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 20 matching lines...) Expand all Loading... |
31 #include "config.h" | 31 #include "config.h" |
32 #include "V8BlobCustomHelpers.h" | 32 #include "V8BlobCustomHelpers.h" |
33 | 33 |
34 #include "V8Blob.h" | 34 #include "V8Blob.h" |
35 #include "bindings/v8/Dictionary.h" | 35 #include "bindings/v8/Dictionary.h" |
36 #include "bindings/v8/V8Binding.h" | 36 #include "bindings/v8/V8Binding.h" |
37 #include "bindings/v8/V8Utilities.h" | 37 #include "bindings/v8/V8Utilities.h" |
38 #include "bindings/v8/custom/V8ArrayBufferCustom.h" | 38 #include "bindings/v8/custom/V8ArrayBufferCustom.h" |
39 #include "bindings/v8/custom/V8ArrayBufferViewCustom.h" | 39 #include "bindings/v8/custom/V8ArrayBufferViewCustom.h" |
40 #include "core/fileapi/BlobBuilder.h" | 40 #include "core/fileapi/BlobBuilder.h" |
| 41 #include "wtf/DateMath.h" |
41 | 42 |
42 namespace WebCore { | 43 namespace WebCore { |
43 | 44 |
44 namespace V8BlobCustomHelpers { | 45 namespace V8BlobCustomHelpers { |
45 | 46 |
46 bool processBlobPropertyBag(v8::Local<v8::Value> propertyBag, const char* blobCl
assName, String& contentType, String& endings, v8::Isolate* isolate) | 47 ParsedProperties::ParsedProperties(bool hasFileProperties) |
| 48 : endings("transparent") |
| 49 , hasFileProperties(hasFileProperties) |
| 50 #ifndef NDEBUG |
| 51 , m_hasLastModifiedDate(false) |
| 52 #endif // NDEBUG |
| 53 { |
| 54 } |
| 55 |
| 56 double ParsedProperties::lastModifiedDate() |
| 57 { |
| 58 ASSERT(this->hasFileProperties); |
| 59 ASSERT(this->m_hasLastModifiedDate); |
| 60 return m_lastModifiedDate; |
| 61 } |
| 62 |
| 63 void ParsedProperties::setLastModifiedDate(double lastModifiedDate) |
| 64 { |
| 65 ASSERT(this->hasFileProperties); |
| 66 ASSERT(!this->m_hasLastModifiedDate); |
| 67 m_lastModifiedDate = lastModifiedDate; |
| 68 #ifndef NDEBUG |
| 69 m_hasLastModifiedDate = true; |
| 70 #endif // NDEBUG |
| 71 } |
| 72 |
| 73 void ParsedProperties::setDefaultLastModifiedDate() |
| 74 { |
| 75 setLastModifiedDate(currentTime()); |
| 76 } |
| 77 |
| 78 bool ParsedProperties::parseBlobPropertyBag(v8::Local<v8::Value> propertyBag, co
nst char* blobClassName, v8::Isolate* isolate) |
47 { | 79 { |
48 ASSERT(endings == "transparent"); | 80 ASSERT(endings == "transparent"); |
49 | 81 |
50 V8TRYCATCH_RETURN(Dictionary, dictionary, Dictionary(propertyBag, isolate),
false); | 82 V8TRYCATCH_RETURN(Dictionary, dictionary, Dictionary(propertyBag, isolate),
false); |
51 | 83 |
52 V8TRYCATCH_RETURN(bool, containsEndings, dictionary.get("endings", endings),
false); | 84 V8TRYCATCH_RETURN(bool, containsEndings, dictionary.get("endings", endings),
false); |
53 if (containsEndings) { | 85 if (containsEndings) { |
54 if (endings != "transparent" && endings != "native") { | 86 if (endings != "transparent" && endings != "native") { |
55 throwTypeError(ExceptionMessages::failedToConstruct(blobClassName, "
The \"endings\" property must be either \"transparent\" or \"native\"."), isolat
e); | 87 throwTypeError(ExceptionMessages::failedToConstruct(blobClassName, "
The \"endings\" property must be either \"transparent\" or \"native\"."), isolat
e); |
56 return false; | 88 return false; |
57 } | 89 } |
58 } | 90 } |
59 | 91 |
60 V8TRYCATCH_RETURN(bool, containsType, dictionary.get("type", contentType), f
alse); | 92 V8TRYCATCH_RETURN(bool, containsType, dictionary.get("type", contentType), f
alse); |
61 if (containsType) { | 93 if (containsType) { |
62 if (!contentType.containsOnlyASCII()) { | 94 if (!contentType.containsOnlyASCII()) { |
63 throwError(v8SyntaxError, ExceptionMessages::failedToConstruct(blobC
lassName, "The \"type\" property must consist of ASCII characters."), isolate); | 95 throwError(v8SyntaxError, ExceptionMessages::failedToConstruct(blobC
lassName, "The \"type\" property must consist of ASCII characters."), isolate); |
64 return false; | 96 return false; |
65 } | 97 } |
66 contentType = contentType.lower(); | 98 contentType = contentType.lower(); |
67 } | 99 } |
| 100 |
| 101 if (!hasFileProperties) |
| 102 return true; |
| 103 |
| 104 v8::Local<v8::Value> lastModifiedDate; |
| 105 V8TRYCATCH_RETURN(bool, containsLastModifiedDate, dictionary.get("lastModifi
edDate", lastModifiedDate), false); |
| 106 if (containsLastModifiedDate) { |
| 107 if (!lastModifiedDate->IsDate()) { |
| 108 throwTypeError(ExceptionMessages::failedToConstruct(blobClassName, "
The \"lastModifiedDate\" property must be a Date instance."), isolate); |
| 109 return false; |
| 110 } |
| 111 double dateValue = toWebCoreDate(lastModifiedDate); |
| 112 setLastModifiedDate(dateValue / msPerSecond); |
| 113 } else { |
| 114 setDefaultLastModifiedDate(); |
| 115 } |
| 116 |
68 return true; | 117 return true; |
69 } | 118 } |
70 | 119 |
71 bool processBlobParts(v8::Local<v8::Object> blobParts, uint32_t blobPartsLength,
const String& endings, BlobBuilder& blobBuilder, v8::Isolate* isolate) | 120 bool processBlobParts(v8::Local<v8::Object> blobParts, uint32_t blobPartsLength,
const String& endings, BlobBuilder& blobBuilder, v8::Isolate* isolate) |
72 { | 121 { |
73 ASSERT(endings == "transparent" || endings == "native"); | 122 ASSERT(endings == "transparent" || endings == "native"); |
74 | 123 |
75 for (uint32_t i = 0; i < blobPartsLength; ++i) { | 124 for (uint32_t i = 0; i < blobPartsLength; ++i) { |
76 v8::Local<v8::Value> item = blobParts->Get(v8::Uint32::New(i, isolate)); | 125 v8::Local<v8::Value> item = blobParts->Get(v8::Uint32::New(i, isolate)); |
77 if (item.IsEmpty()) | 126 if (item.IsEmpty()) |
(...skipping 15 matching lines...) Expand all Loading... |
93 V8TRYCATCH_FOR_V8STRINGRESOURCE_RETURN(V8StringResource<>, stringVal
ue, item, false); | 142 V8TRYCATCH_FOR_V8STRINGRESOURCE_RETURN(V8StringResource<>, stringVal
ue, item, false); |
94 blobBuilder.append(stringValue, endings); | 143 blobBuilder.append(stringValue, endings); |
95 } | 144 } |
96 } | 145 } |
97 return true; | 146 return true; |
98 } | 147 } |
99 | 148 |
100 } // namespace V8BlobCustomHelpers | 149 } // namespace V8BlobCustomHelpers |
101 | 150 |
102 } // namespace WebCore | 151 } // namespace WebCore |
OLD | NEW |