Chromium Code Reviews| 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 | |
| 47 { | 53 { |
| 48 ASSERT(endings == "transparent"); | 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 processBlobPropertyBag(v8::Local<v8::Value> propertyBag, const char* blobCl assName, ParsedProperties& parsedProperties, v8::Isolate* isolate) | |
| 79 { | |
| 80 ASSERT(parsedProperties.endings == "transparent"); | |
| 81 String& endings = parsedProperties.endings; | |
| 49 | 82 |
| 50 V8TRYCATCH_RETURN(Dictionary, dictionary, Dictionary(propertyBag, isolate), false); | 83 V8TRYCATCH_RETURN(Dictionary, dictionary, Dictionary(propertyBag, isolate), false); |
| 51 | 84 |
| 52 V8TRYCATCH_RETURN(bool, containsEndings, dictionary.get("endings", endings), false); | 85 V8TRYCATCH_RETURN(bool, containsEndings, dictionary.get("endings", endings), false); |
| 53 if (containsEndings) { | 86 if (containsEndings) { |
| 54 if (endings != "transparent" && endings != "native") { | 87 if (endings != "transparent" && endings != "native") { |
| 55 throwTypeError(ExceptionMessages::failedToConstruct(blobClassName, " The \"endings\" property must be either \"transparent\" or \"native\"."), isolat e); | 88 throwTypeError(ExceptionMessages::failedToConstruct(blobClassName, " The \"endings\" property must be either \"transparent\" or \"native\"."), isolat e); |
| 56 return false; | 89 return false; |
| 57 } | 90 } |
| 58 } | 91 } |
| 59 | 92 |
| 93 String& contentType = parsedProperties.contentType; | |
| 60 V8TRYCATCH_RETURN(bool, containsType, dictionary.get("type", contentType), f alse); | 94 V8TRYCATCH_RETURN(bool, containsType, dictionary.get("type", contentType), f alse); |
| 61 if (containsType) { | 95 if (containsType) { |
| 62 if (!contentType.containsOnlyASCII()) { | 96 if (!contentType.containsOnlyASCII()) { |
| 63 throwError(v8SyntaxError, ExceptionMessages::failedToConstruct(blobC lassName, "The \"type\" property must consist of ASCII characters."), isolate); | 97 throwError(v8SyntaxError, ExceptionMessages::failedToConstruct(blobC lassName, "The \"type\" property must consist of ASCII characters."), isolate); |
| 64 return false; | 98 return false; |
| 65 } | 99 } |
| 66 contentType = contentType.lower(); | 100 contentType = contentType.lower(); |
| 67 } | 101 } |
| 102 | |
| 103 if (!parsedProperties.hasFileProperties) | |
| 104 return true; | |
| 105 | |
| 106 v8::Local<v8::Value> lastModifiedDate; | |
| 107 V8TRYCATCH_RETURN(bool, containsLastModifiedDate, dictionary.get("lastModifi edDate", lastModifiedDate), false); | |
| 108 if (containsLastModifiedDate) { | |
| 109 if (!lastModifiedDate->IsDate()) { | |
| 110 throwTypeError(ExceptionMessages::failedToConstruct(blobClassName, " The \"lastModifiedDate\" property must be a Date instance."), isolate); | |
| 111 return false; | |
| 112 } | |
| 113 double dateValue = static_cast<double>(v8::Local<v8::Date>::Cast(lastMod ifiedDate)->ValueOf()); | |
|
haraken
2013/11/18 10:27:48
You can use toWebCoreDate() in V8Binding.h.
pwnall-personal
2013/11/18 11:23:45
I avoided toWebCoreDate() because it does an unnec
haraken
2013/11/18 11:29:07
We want to use utility methods in V8Binding.h as m
pwnall-personal
2013/11/18 12:48:57
Done.
| |
| 114 parsedProperties.setLastModifiedDate(dateValue / msPerSecond); | |
| 115 } else { | |
| 116 parsedProperties.setDefaultLastModifiedDate(); | |
| 117 } | |
| 118 | |
| 68 return true; | 119 return true; |
| 69 } | 120 } |
| 70 | 121 |
| 71 bool processBlobParts(v8::Local<v8::Object> blobParts, uint32_t blobPartsLength, const String& endings, BlobBuilder& blobBuilder, v8::Isolate* isolate) | 122 bool processBlobParts(v8::Local<v8::Object> blobParts, uint32_t blobPartsLength, const String& endings, BlobBuilder& blobBuilder, v8::Isolate* isolate) |
| 72 { | 123 { |
| 73 ASSERT(endings == "transparent" || endings == "native"); | 124 ASSERT(endings == "transparent" || endings == "native"); |
| 74 | 125 |
| 75 for (uint32_t i = 0; i < blobPartsLength; ++i) { | 126 for (uint32_t i = 0; i < blobPartsLength; ++i) { |
| 76 v8::Local<v8::Value> item = blobParts->Get(v8::Uint32::New(i, isolate)); | 127 v8::Local<v8::Value> item = blobParts->Get(v8::Uint32::New(i, isolate)); |
| 77 if (item.IsEmpty()) | 128 if (item.IsEmpty()) |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 93 V8TRYCATCH_FOR_V8STRINGRESOURCE_RETURN(V8StringResource<>, stringVal ue, item, false); | 144 V8TRYCATCH_FOR_V8STRINGRESOURCE_RETURN(V8StringResource<>, stringVal ue, item, false); |
| 94 blobBuilder.append(stringValue, endings); | 145 blobBuilder.append(stringValue, endings); |
| 95 } | 146 } |
| 96 } | 147 } |
| 97 return true; | 148 return true; |
| 98 } | 149 } |
| 99 | 150 |
| 100 } // namespace V8BlobCustomHelpers | 151 } // namespace V8BlobCustomHelpers |
| 101 | 152 |
| 102 } // namespace WebCore | 153 } // namespace WebCore |
| OLD | NEW |