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 : m_endings("transparent") |
| 49 , m_hasFileProperties(hasFileProperties) |
| 50 #ifndef NDEBUG |
| 51 , m_hasLastModified(false) |
| 52 #endif // NDEBUG |
47 { | 53 { |
48 ASSERT(endings == "transparent"); | 54 } |
| 55 |
| 56 double ParsedProperties::lastModified() |
| 57 { |
| 58 ASSERT(m_hasFileProperties); |
| 59 ASSERT(m_hasLastModified); |
| 60 return m_lastModified; |
| 61 } |
| 62 |
| 63 void ParsedProperties::setLastModified(double lastModified) |
| 64 { |
| 65 ASSERT(m_hasFileProperties); |
| 66 ASSERT(!m_hasLastModified); |
| 67 m_lastModified = lastModified; |
| 68 #ifndef NDEBUG |
| 69 m_hasLastModified = true; |
| 70 #endif // NDEBUG |
| 71 } |
| 72 |
| 73 void ParsedProperties::setDefaultLastModified() |
| 74 { |
| 75 setLastModified(currentTime()); |
| 76 } |
| 77 |
| 78 bool ParsedProperties::parseBlobPropertyBag(v8::Local<v8::Value> propertyBag, co
nst char* blobClassName, v8::Isolate* isolate) |
| 79 { |
| 80 ASSERT(m_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", m_endings
), false); |
53 if (containsEndings) { | 85 if (containsEndings) { |
54 if (endings != "transparent" && endings != "native") { | 86 if (m_endings != "transparent" && m_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", m_contentType),
false); |
61 if (containsType) { | 93 if (containsType) { |
62 if (!contentType.containsOnlyASCII()) { | 94 if (!m_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 m_contentType = m_contentType.lower(); |
67 } | 99 } |
| 100 |
| 101 if (!m_hasFileProperties) |
| 102 return true; |
| 103 |
| 104 v8::Local<v8::Value> lastModified; |
| 105 V8TRYCATCH_RETURN(bool, containsLastModified, dictionary.get("lastModified",
lastModified), false); |
| 106 if (containsLastModified) { |
| 107 V8TRYCATCH_RETURN(long long, lastModifiedInt, toInt64(lastModified), fal
se); |
| 108 setLastModified(static_cast<double>(lastModifiedInt) / msPerSecond); |
| 109 } else { |
| 110 setDefaultLastModified(); |
| 111 } |
| 112 |
68 return true; | 113 return true; |
69 } | 114 } |
70 | 115 |
71 bool processBlobParts(v8::Local<v8::Object> blobParts, uint32_t blobPartsLength,
const String& endings, BlobBuilder& blobBuilder, v8::Isolate* isolate) | 116 bool processBlobParts(v8::Local<v8::Object> blobParts, uint32_t blobPartsLength,
const String& endings, BlobBuilder& blobBuilder, v8::Isolate* isolate) |
72 { | 117 { |
73 ASSERT(endings == "transparent" || endings == "native"); | 118 ASSERT(endings == "transparent" || endings == "native"); |
74 | 119 |
75 for (uint32_t i = 0; i < blobPartsLength; ++i) { | 120 for (uint32_t i = 0; i < blobPartsLength; ++i) { |
76 v8::Local<v8::Value> item = blobParts->Get(v8::Uint32::New(i, isolate)); | 121 v8::Local<v8::Value> item = blobParts->Get(v8::Uint32::New(i, isolate)); |
77 if (item.IsEmpty()) | 122 if (item.IsEmpty()) |
(...skipping 15 matching lines...) Expand all Loading... |
93 V8TRYCATCH_FOR_V8STRINGRESOURCE_RETURN(V8StringResource<>, stringVal
ue, item, false); | 138 V8TRYCATCH_FOR_V8STRINGRESOURCE_RETURN(V8StringResource<>, stringVal
ue, item, false); |
94 blobBuilder.append(stringValue, endings); | 139 blobBuilder.append(stringValue, endings); |
95 } | 140 } |
96 } | 141 } |
97 return true; | 142 return true; |
98 } | 143 } |
99 | 144 |
100 } // namespace V8BlobCustomHelpers | 145 } // namespace V8BlobCustomHelpers |
101 | 146 |
102 } // namespace WebCore | 147 } // namespace WebCore |
OLD | NEW |