Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(31)

Side by Side Diff: Source/bindings/v8/custom/V8BlobCustomHelpers.cpp

Issue 74213009: File constructor understands lastModified. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Addressed feedback. Created 7 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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 void ParsedProperties::setLastModified(double lastModified)
57 {
58 ASSERT(m_hasFileProperties);
59 ASSERT(!m_hasLastModified);
60 m_lastModified = lastModified;
61 #ifndef NDEBUG
62 m_hasLastModified = true;
63 #endif // NDEBUG
64 }
65
66 void ParsedProperties::setDefaultLastModified()
67 {
68 setLastModified(currentTime());
69 }
70
71 bool ParsedProperties::parseBlobPropertyBag(v8::Local<v8::Value> propertyBag, co nst char* blobClassName, v8::Isolate* isolate)
72 {
73 ASSERT(m_endings == "transparent");
49 74
50 V8TRYCATCH_RETURN(Dictionary, dictionary, Dictionary(propertyBag, isolate), false); 75 V8TRYCATCH_RETURN(Dictionary, dictionary, Dictionary(propertyBag, isolate), false);
51 76
52 V8TRYCATCH_RETURN(bool, containsEndings, dictionary.get("endings", endings), false); 77 V8TRYCATCH_RETURN(bool, containsEndings, dictionary.get("endings", m_endings ), false);
53 if (containsEndings) { 78 if (containsEndings) {
54 if (endings != "transparent" && endings != "native") { 79 if (m_endings != "transparent" && m_endings != "native") {
55 throwTypeError(ExceptionMessages::failedToConstruct(blobClassName, " The \"endings\" property must be either \"transparent\" or \"native\"."), isolat e); 80 throwTypeError(ExceptionMessages::failedToConstruct(blobClassName, " The \"endings\" property must be either \"transparent\" or \"native\"."), isolat e);
56 return false; 81 return false;
57 } 82 }
58 } 83 }
59 84
60 V8TRYCATCH_RETURN(bool, containsType, dictionary.get("type", contentType), f alse); 85 V8TRYCATCH_RETURN(bool, containsType, dictionary.get("type", m_contentType), false);
61 if (containsType) { 86 if (containsType) {
62 if (!contentType.containsOnlyASCII()) { 87 if (!m_contentType.containsOnlyASCII()) {
63 throwError(v8SyntaxError, ExceptionMessages::failedToConstruct(blobC lassName, "The \"type\" property must consist of ASCII characters."), isolate); 88 throwError(v8SyntaxError, ExceptionMessages::failedToConstruct(blobC lassName, "The \"type\" property must consist of ASCII characters."), isolate);
64 return false; 89 return false;
65 } 90 }
66 contentType = contentType.lower(); 91 m_contentType = m_contentType.lower();
67 } 92 }
93
94 if (!m_hasFileProperties)
95 return true;
96
97 v8::Local<v8::Value> lastModified;
98 V8TRYCATCH_RETURN(bool, containsLastModified, dictionary.get("lastModified", lastModified), false);
99 if (containsLastModified) {
100 V8TRYCATCH_RETURN(long long, lastModifiedInt, toInt64(lastModified), fal se);
101 setLastModified(static_cast<double>(lastModifiedInt) / msPerSecond);
102 } else {
103 setDefaultLastModified();
104 }
105
68 return true; 106 return true;
69 } 107 }
70 108
71 bool processBlobParts(v8::Local<v8::Object> blobParts, uint32_t blobPartsLength, const String& endings, BlobBuilder& blobBuilder, v8::Isolate* isolate) 109 bool processBlobParts(v8::Local<v8::Object> blobParts, uint32_t blobPartsLength, const String& endings, BlobBuilder& blobBuilder, v8::Isolate* isolate)
72 { 110 {
73 ASSERT(endings == "transparent" || endings == "native"); 111 ASSERT(endings == "transparent" || endings == "native");
74 112
75 for (uint32_t i = 0; i < blobPartsLength; ++i) { 113 for (uint32_t i = 0; i < blobPartsLength; ++i) {
76 v8::Local<v8::Value> item = blobParts->Get(v8::Uint32::New(i, isolate)); 114 v8::Local<v8::Value> item = blobParts->Get(v8::Uint32::New(i, isolate));
77 if (item.IsEmpty()) 115 if (item.IsEmpty())
(...skipping 15 matching lines...) Expand all
93 V8TRYCATCH_FOR_V8STRINGRESOURCE_RETURN(V8StringResource<>, stringVal ue, item, false); 131 V8TRYCATCH_FOR_V8STRINGRESOURCE_RETURN(V8StringResource<>, stringVal ue, item, false);
94 blobBuilder.append(stringValue, endings); 132 blobBuilder.append(stringValue, endings);
95 } 133 }
96 } 134 }
97 return true; 135 return true;
98 } 136 }
99 137
100 } // namespace V8BlobCustomHelpers 138 } // namespace V8BlobCustomHelpers
101 139
102 } // namespace WebCore 140 } // namespace WebCore
OLDNEW
« no previous file with comments | « Source/bindings/v8/custom/V8BlobCustomHelpers.h ('k') | Source/bindings/v8/custom/V8FileCustom.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698