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

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

Issue 2080623002: Revert "Remove OwnPtr from Blink." (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 6 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 18 matching lines...) Expand all
29 #include "core/dom/ExceptionCode.h" 29 #include "core/dom/ExceptionCode.h"
30 #include "core/fileapi/FilePropertyBag.h" 30 #include "core/fileapi/FilePropertyBag.h"
31 #include "core/frame/UseCounter.h" 31 #include "core/frame/UseCounter.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 "platform/blob/BlobData.h"
35 #include "public/platform/Platform.h" 35 #include "public/platform/Platform.h"
36 #include "public/platform/WebFileUtilities.h" 36 #include "public/platform/WebFileUtilities.h"
37 #include "wtf/CurrentTime.h" 37 #include "wtf/CurrentTime.h"
38 #include "wtf/DateMath.h" 38 #include "wtf/DateMath.h"
39 #include <memory>
40 39
41 namespace blink { 40 namespace blink {
42 41
43 static String getContentTypeFromFileName(const String& name, File::ContentTypeLo okupPolicy policy) 42 static String getContentTypeFromFileName(const String& name, File::ContentTypeLo okupPolicy policy)
44 { 43 {
45 String type; 44 String type;
46 int index = name.reverseFind('.'); 45 int index = name.reverseFind('.');
47 if (index != -1) { 46 if (index != -1) {
48 if (policy == File::WellKnownContentTypes) { 47 if (policy == File::WellKnownContentTypes) {
49 type = MIMETypeRegistry::getWellKnownMIMETypeForExtension(name.subst ring(index + 1)); 48 type = MIMETypeRegistry::getWellKnownMIMETypeForExtension(name.subst ring(index + 1));
50 } else { 49 } else {
51 ASSERT(policy == File::AllContentTypes); 50 ASSERT(policy == File::AllContentTypes);
52 type = MIMETypeRegistry::getMIMETypeForExtension(name.substring(inde x + 1)); 51 type = MIMETypeRegistry::getMIMETypeForExtension(name.substring(inde x + 1));
53 } 52 }
54 } 53 }
55 return type; 54 return type;
56 } 55 }
57 56
58 static std::unique_ptr<BlobData> createBlobDataForFileWithType(const String& pat h, const String& contentType) 57 static PassOwnPtr<BlobData> createBlobDataForFileWithType(const String& path, co nst String& contentType)
59 { 58 {
60 std::unique_ptr<BlobData> blobData = BlobData::create(); 59 OwnPtr<BlobData> blobData = BlobData::create();
61 blobData->setContentType(contentType); 60 blobData->setContentType(contentType);
62 blobData->appendFile(path); 61 blobData->appendFile(path);
63 return blobData; 62 return blobData;
64 } 63 }
65 64
66 static std::unique_ptr<BlobData> createBlobDataForFile(const String& path, File: :ContentTypeLookupPolicy policy) 65 static PassOwnPtr<BlobData> createBlobDataForFile(const String& path, File::Cont entTypeLookupPolicy policy)
67 { 66 {
68 return createBlobDataForFileWithType(path, getContentTypeFromFileName(path, policy)); 67 return createBlobDataForFileWithType(path, getContentTypeFromFileName(path, policy));
69 } 68 }
70 69
71 static std::unique_ptr<BlobData> createBlobDataForFileWithName(const String& pat h, const String& fileSystemName, File::ContentTypeLookupPolicy policy) 70 static PassOwnPtr<BlobData> createBlobDataForFileWithName(const String& path, co nst String& fileSystemName, File::ContentTypeLookupPolicy policy)
72 { 71 {
73 return createBlobDataForFileWithType(path, getContentTypeFromFileName(fileSy stemName, policy)); 72 return createBlobDataForFileWithType(path, getContentTypeFromFileName(fileSy stemName, policy));
74 } 73 }
75 74
76 static std::unique_ptr<BlobData> createBlobDataForFileWithMetadata(const String& fileSystemName, const FileMetadata& metadata) 75 static PassOwnPtr<BlobData> createBlobDataForFileWithMetadata(const String& file SystemName, const FileMetadata& metadata)
77 { 76 {
78 std::unique_ptr<BlobData> blobData = BlobData::create(); 77 OwnPtr<BlobData> blobData = BlobData::create();
79 blobData->setContentType(getContentTypeFromFileName(fileSystemName, File::We llKnownContentTypes)); 78 blobData->setContentType(getContentTypeFromFileName(fileSystemName, File::We llKnownContentTypes));
80 blobData->appendFile(metadata.platformPath, 0, metadata.length, metadata.mod ificationTime / msPerSecond); 79 blobData->appendFile(metadata.platformPath, 0, metadata.length, metadata.mod ificationTime / msPerSecond);
81 return blobData; 80 return blobData;
82 } 81 }
83 82
84 static std::unique_ptr<BlobData> createBlobDataForFileSystemURL(const KURL& file SystemURL, const FileMetadata& metadata) 83 static PassOwnPtr<BlobData> createBlobDataForFileSystemURL(const KURL& fileSyste mURL, const FileMetadata& metadata)
85 { 84 {
86 std::unique_ptr<BlobData> blobData = BlobData::create(); 85 OwnPtr<BlobData> blobData = BlobData::create();
87 blobData->setContentType(getContentTypeFromFileName(fileSystemURL.path(), Fi le::WellKnownContentTypes)); 86 blobData->setContentType(getContentTypeFromFileName(fileSystemURL.path(), Fi le::WellKnownContentTypes));
88 blobData->appendFileSystemURL(fileSystemURL, 0, metadata.length, metadata.mo dificationTime / msPerSecond); 87 blobData->appendFileSystemURL(fileSystemURL, 0, metadata.length, metadata.mo dificationTime / msPerSecond);
89 return blobData; 88 return blobData;
90 } 89 }
91 90
92 // static 91 // static
93 File* File::create(ExecutionContext* context, const HeapVector<ArrayBufferOrArra yBufferViewOrBlobOrUSVString>& fileBits, const String& fileName, const FilePrope rtyBag& options, ExceptionState& exceptionState) 92 File* File::create(ExecutionContext* context, const HeapVector<ArrayBufferOrArra yBufferViewOrBlobOrUSVString>& fileBits, const String& fileName, const FilePrope rtyBag& options, ExceptionState& exceptionState)
94 { 93 {
95 ASSERT(options.hasType()); 94 ASSERT(options.hasType());
96 if (!options.type().containsOnlyASCII()) { 95 if (!options.type().containsOnlyASCII()) {
97 exceptionState.throwDOMException(SyntaxError, "The 'type' property must consist of ASCII characters."); 96 exceptionState.throwDOMException(SyntaxError, "The 'type' property must consist of ASCII characters.");
98 return nullptr; 97 return nullptr;
99 } 98 }
100 99
101 double lastModified; 100 double lastModified;
102 if (options.hasLastModified()) 101 if (options.hasLastModified())
103 lastModified = static_cast<double>(options.lastModified()); 102 lastModified = static_cast<double>(options.lastModified());
104 else 103 else
105 lastModified = currentTimeMS(); 104 lastModified = currentTimeMS();
106 ASSERT(options.hasEndings()); 105 ASSERT(options.hasEndings());
107 bool normalizeLineEndingsToNative = options.endings() == "native"; 106 bool normalizeLineEndingsToNative = options.endings() == "native";
108 if (normalizeLineEndingsToNative) 107 if (normalizeLineEndingsToNative)
109 UseCounter::count(context, UseCounter::FileAPINativeLineEndings); 108 UseCounter::count(context, UseCounter::FileAPINativeLineEndings);
110 109
111 std::unique_ptr<BlobData> blobData = BlobData::create(); 110 OwnPtr<BlobData> blobData = BlobData::create();
112 blobData->setContentType(options.type().lower()); 111 blobData->setContentType(options.type().lower());
113 populateBlobData(blobData.get(), fileBits, normalizeLineEndingsToNative); 112 populateBlobData(blobData.get(), fileBits, normalizeLineEndingsToNative);
114 113
115 long long fileSize = blobData->length(); 114 long long fileSize = blobData->length();
116 return File::create(fileName, lastModified, BlobDataHandle::create(std::move (blobData), fileSize)); 115 return File::create(fileName, lastModified, BlobDataHandle::create(std::move (blobData), fileSize));
117 } 116 }
118 117
119 File* File::createWithRelativePath(const String& path, const String& relativePat h) 118 File* File::createWithRelativePath(const String& path, const String& relativePat h)
120 { 119 {
121 File* file = new File(path, File::AllContentTypes, File::IsUserVisible); 120 File* file = new File(path, File::AllContentTypes, File::IsUserVisible);
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after
271 if (!m_hasBackingFile) 270 if (!m_hasBackingFile)
272 return Blob::slice(start, end, contentType, exceptionState); 271 return Blob::slice(start, end, contentType, exceptionState);
273 272
274 // FIXME: This involves synchronous file operation. We need to figure out ho w to make it asynchronous. 273 // FIXME: This involves synchronous file operation. We need to figure out ho w to make it asynchronous.
275 long long size; 274 long long size;
276 double modificationTimeMS; 275 double modificationTimeMS;
277 captureSnapshot(size, modificationTimeMS); 276 captureSnapshot(size, modificationTimeMS);
278 clampSliceOffsets(size, start, end); 277 clampSliceOffsets(size, start, end);
279 278
280 long long length = end - start; 279 long long length = end - start;
281 std::unique_ptr<BlobData> blobData = BlobData::create(); 280 OwnPtr<BlobData> blobData = BlobData::create();
282 blobData->setContentType(contentType); 281 blobData->setContentType(contentType);
283 if (!m_fileSystemURL.isEmpty()) { 282 if (!m_fileSystemURL.isEmpty()) {
284 blobData->appendFileSystemURL(m_fileSystemURL, start, length, modificati onTimeMS / msPerSecond); 283 blobData->appendFileSystemURL(m_fileSystemURL, start, length, modificati onTimeMS / msPerSecond);
285 } else { 284 } else {
286 ASSERT(!m_path.isEmpty()); 285 ASSERT(!m_path.isEmpty());
287 blobData->appendFile(m_path, start, length, modificationTimeMS / msPerSe cond); 286 blobData->appendFile(m_path, start, length, modificationTimeMS / msPerSe cond);
288 } 287 }
289 return Blob::create(BlobDataHandle::create(std::move(blobData), length)); 288 return Blob::create(BlobDataHandle::create(std::move(blobData), length));
290 } 289 }
291 290
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
358 if (m_fileSystemURL.isEmpty() != other.m_fileSystemURL.isEmpty()) 357 if (m_fileSystemURL.isEmpty() != other.m_fileSystemURL.isEmpty())
359 return false; 358 return false;
360 359
361 if (!m_fileSystemURL.isEmpty()) 360 if (!m_fileSystemURL.isEmpty())
362 return m_fileSystemURL == other.m_fileSystemURL; 361 return m_fileSystemURL == other.m_fileSystemURL;
363 362
364 return uuid() == other.uuid(); 363 return uuid() == other.uuid();
365 } 364 }
366 365
367 } // namespace blink 366 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/fileapi/Blob.cpp ('k') | third_party/WebKit/Source/core/fileapi/FileReader.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698