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

Side by Side Diff: third_party/WebKit/Source/core/fileapi/File.cpp

Issue 1362963003: Blob/File constructors/slice method shouldn't throw on invalid types (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebased Created 3 years, 9 months 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) 2008 Apple Inc. All Rights Reserved. 2 * Copyright (C) 2008 Apple 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 5 * modification, are permitted provided that the following conditions
6 * are met: 6 * are met:
7 * 1. Redistributions of source code must retain the above copyright 7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer. 8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright 9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the 10 * notice, this list of conditions and the following disclaimer in the
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
104 } 104 }
105 105
106 // static 106 // static
107 File* File::create( 107 File* File::create(
108 ExecutionContext* context, 108 ExecutionContext* context,
109 const HeapVector<ArrayBufferOrArrayBufferViewOrBlobOrUSVString>& fileBits, 109 const HeapVector<ArrayBufferOrArrayBufferViewOrBlobOrUSVString>& fileBits,
110 const String& fileName, 110 const String& fileName,
111 const FilePropertyBag& options, 111 const FilePropertyBag& options,
112 ExceptionState& exceptionState) { 112 ExceptionState& exceptionState) {
113 ASSERT(options.hasType()); 113 ASSERT(options.hasType());
114 if (!options.type().containsOnlyASCII()) {
115 exceptionState.throwDOMException(
116 SyntaxError, "The 'type' property must consist of ASCII characters.");
117 return nullptr;
118 }
119 114
120 double lastModified; 115 double lastModified;
121 if (options.hasLastModified()) 116 if (options.hasLastModified())
122 lastModified = static_cast<double>(options.lastModified()); 117 lastModified = static_cast<double>(options.lastModified());
123 else 118 else
124 lastModified = currentTimeMS(); 119 lastModified = currentTimeMS();
125 ASSERT(options.hasEndings()); 120 ASSERT(options.hasEndings());
126 bool normalizeLineEndingsToNative = options.endings() == "native"; 121 bool normalizeLineEndingsToNative = options.endings() == "native";
127 if (normalizeLineEndingsToNative) 122 if (normalizeLineEndingsToNative)
128 UseCounter::count(context, UseCounter::FileAPINativeLineEndings); 123 UseCounter::count(context, UseCounter::FileAPINativeLineEndings);
129 124
130 std::unique_ptr<BlobData> blobData = BlobData::create(); 125 std::unique_ptr<BlobData> blobData = BlobData::create();
131 blobData->setContentType(options.type().lower()); 126 blobData->setContentType(normalizeType(options.type()));
132 populateBlobData(blobData.get(), fileBits, normalizeLineEndingsToNative); 127 populateBlobData(blobData.get(), fileBits, normalizeLineEndingsToNative);
133 128
134 long long fileSize = blobData->length(); 129 long long fileSize = blobData->length();
135 return File::create(fileName, lastModified, 130 return File::create(fileName, lastModified,
136 BlobDataHandle::create(std::move(blobData), fileSize)); 131 BlobDataHandle::create(std::move(blobData), fileSize));
137 } 132 }
138 133
139 File* File::createWithRelativePath(const String& path, 134 File* File::createWithRelativePath(const String& path,
140 const String& relativePath) { 135 const String& relativePath) {
141 File* file = new File(path, File::AllContentTypes, File::IsUserVisible); 136 File* file = new File(path, File::AllContentTypes, File::IsUserVisible);
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after
307 302
308 // FIXME: This involves synchronous file operation. We need to figure out how 303 // FIXME: This involves synchronous file operation. We need to figure out how
309 // to make it asynchronous. 304 // to make it asynchronous.
310 long long size; 305 long long size;
311 double modificationTimeMS; 306 double modificationTimeMS;
312 captureSnapshot(size, modificationTimeMS); 307 captureSnapshot(size, modificationTimeMS);
313 clampSliceOffsets(size, start, end); 308 clampSliceOffsets(size, start, end);
314 309
315 long long length = end - start; 310 long long length = end - start;
316 std::unique_ptr<BlobData> blobData = BlobData::create(); 311 std::unique_ptr<BlobData> blobData = BlobData::create();
317 blobData->setContentType(contentType); 312 blobData->setContentType(normalizeType(contentType));
318 if (!m_fileSystemURL.isEmpty()) { 313 if (!m_fileSystemURL.isEmpty()) {
319 blobData->appendFileSystemURL(m_fileSystemURL, start, length, 314 blobData->appendFileSystemURL(m_fileSystemURL, start, length,
320 modificationTimeMS / msPerSecond); 315 modificationTimeMS / msPerSecond);
321 } else { 316 } else {
322 ASSERT(!m_path.isEmpty()); 317 ASSERT(!m_path.isEmpty());
323 blobData->appendFile(m_path, start, length, 318 blobData->appendFile(m_path, start, length,
324 modificationTimeMS / msPerSecond); 319 modificationTimeMS / msPerSecond);
325 } 320 }
326 return Blob::create(BlobDataHandle::create(std::move(blobData), length)); 321 return Blob::create(BlobDataHandle::create(std::move(blobData), length));
327 } 322 }
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
398 if (m_fileSystemURL.isEmpty() != other.m_fileSystemURL.isEmpty()) 393 if (m_fileSystemURL.isEmpty() != other.m_fileSystemURL.isEmpty())
399 return false; 394 return false;
400 395
401 if (!m_fileSystemURL.isEmpty()) 396 if (!m_fileSystemURL.isEmpty())
402 return m_fileSystemURL == other.m_fileSystemURL; 397 return m_fileSystemURL == other.m_fileSystemURL;
403 398
404 return uuid() == other.uuid(); 399 return uuid() == other.uuid();
405 } 400 }
406 401
407 } // namespace blink 402 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698