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

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

Issue 1257253004: [HTMLCanvasElement.toBlob] Default callback version without scheduler (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Modifications based on feedback from Patch Set 3 including Layout Tests and Rebaseline of Mac and Win Created 5 years, 4 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 13 matching lines...) Expand all
24 */ 24 */
25 25
26 #include "config.h" 26 #include "config.h"
27 #include "core/fileapi/File.h" 27 #include "core/fileapi/File.h"
28 28
29 #include "bindings/core/v8/ExceptionState.h" 29 #include "bindings/core/v8/ExceptionState.h"
30 #include "core/dom/ExceptionCode.h" 30 #include "core/dom/ExceptionCode.h"
31 #include "core/fileapi/FilePropertyBag.h" 31 #include "core/fileapi/FilePropertyBag.h"
32 #include "platform/FileMetadata.h" 32 #include "platform/FileMetadata.h"
33 #include "platform/MIMETypeRegistry.h" 33 #include "platform/MIMETypeRegistry.h"
34 #include "platform/blob/BlobData.h"
34 #include "public/platform/Platform.h" 35 #include "public/platform/Platform.h"
35 #include "public/platform/WebFileUtilities.h" 36 #include "public/platform/WebFileUtilities.h"
36 #include "wtf/CurrentTime.h" 37 #include "wtf/CurrentTime.h"
37 #include "wtf/DateMath.h" 38 #include "wtf/DateMath.h"
38 39
39 namespace blink { 40 namespace blink {
40 41
41 static String getContentTypeFromFileName(const String& name, File::ContentTypeLo okupPolicy policy) 42 static String getContentTypeFromFileName(const String& name, File::ContentTypeLo okupPolicy policy)
42 { 43 {
43 String type; 44 String type;
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
94 if (!options.type().containsOnlyASCII()) { 95 if (!options.type().containsOnlyASCII()) {
95 exceptionState.throwDOMException(SyntaxError, "The 'type' property must consist of ASCII characters."); 96 exceptionState.throwDOMException(SyntaxError, "The 'type' property must consist of ASCII characters.");
96 return nullptr; 97 return nullptr;
97 } 98 }
98 99
99 double lastModified; 100 double lastModified;
100 if (options.hasLastModified()) 101 if (options.hasLastModified())
101 lastModified = static_cast<double>(options.lastModified()); 102 lastModified = static_cast<double>(options.lastModified());
102 else 103 else
103 lastModified = currentTimeMS(); 104 lastModified = currentTimeMS();
104
105 ASSERT(options.hasEndings()); 105 ASSERT(options.hasEndings());
106 bool normalizeLineEndingsToNative = options.endings() == "native"; 106 bool normalizeLineEndingsToNative = options.endings() == "native";
107 107
108 OwnPtr<BlobData> blobData = BlobData::create(); 108 OwnPtr<BlobData> blobData = BlobData::create();
109 blobData->setContentType(options.type().lower()); 109 blobData->setContentType(options.type().lower());
110 populateBlobData(blobData.get(), fileBits, normalizeLineEndingsToNative); 110 populateBlobData(blobData.get(), fileBits, normalizeLineEndingsToNative);
111 111
112 long long fileSize = blobData->length(); 112 long long fileSize = blobData->length();
113 return File::create(fileName, lastModified, BlobDataHandle::create(blobData. release(), fileSize)); 113 return File::create(fileName, lastModified, BlobDataHandle::create(blobData. release(), fileSize));
114 } 114 }
115 115
116 File* File::create(char* encodedImage, size_t size, const String& mimeType)
Justin Novosad 2015/08/20 20:38:43 encodedImage -> data size -> bytes
xlai (Olivia) 2015/08/20 21:36:29 Acknowledged.
117 {
118 ASSERT(encodedImage);
119
120 OwnPtr<BlobData> blobData = BlobData::create();
121 blobData->setContentType(mimeType);
122 blobData->appendBytes(encodedImage, size);
123 long long blobSize = blobData->length();
124
125 // create blob as the type of file with two additional attributes -- name an d lastModificationTime
126 return File::create("", currentTimeMS(), BlobDataHandle::create(blobData.rel ease(), blobSize));
127 }
128
116 File* File::createWithRelativePath(const String& path, const String& relativePat h) 129 File* File::createWithRelativePath(const String& path, const String& relativePat h)
117 { 130 {
118 File* file = new File(path, File::AllContentTypes, File::IsUserVisible); 131 File* file = new File(path, File::AllContentTypes, File::IsUserVisible);
119 file->m_relativePath = relativePath; 132 file->m_relativePath = relativePath;
120 return file; 133 return file;
121 } 134 }
122 135
123 File::File(const String& path, ContentTypeLookupPolicy policy, UserVisibility us erVisibility) 136 File::File(const String& path, ContentTypeLookupPolicy policy, UserVisibility us erVisibility)
124 : Blob(BlobDataHandle::create(createBlobDataForFile(path, policy), -1)) 137 : Blob(BlobDataHandle::create(createBlobDataForFile(path, policy), -1))
125 , m_hasBackingFile(true) 138 , m_hasBackingFile(true)
(...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after
355 if (m_fileSystemURL.isEmpty() != other.m_fileSystemURL.isEmpty()) 368 if (m_fileSystemURL.isEmpty() != other.m_fileSystemURL.isEmpty())
356 return false; 369 return false;
357 370
358 if (!m_fileSystemURL.isEmpty()) 371 if (!m_fileSystemURL.isEmpty())
359 return m_fileSystemURL == other.m_fileSystemURL; 372 return m_fileSystemURL == other.m_fileSystemURL;
360 373
361 return uuid() == other.uuid(); 374 return uuid() == other.uuid();
362 } 375 }
363 376
364 } // namespace blink 377 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698