Changeset 221544 in webkit
- Timestamp:
- Sep 2, 2017 9:02:05 PM (7 years ago)
- Location:
- trunk
- Files:
-
- 2 added
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/LayoutTests/ChangeLog
r221540 r221544 1 2017-09-02 Chris Dumez <cdumez@apple.com> 2 3 Implement FileSystemFileEntry.file() 4 https://bugs.webkit.org/show_bug.cgi?id=176166 5 <rdar://problem/34187756> 6 7 Reviewed by Sam Weinig. 8 9 Add layout test coverage. I have verified that this test passes in Chrome as well. 10 11 * editing/pasteboard/datatransfer-items-drop-fileEntry-file-expected.txt: Added. 12 * editing/pasteboard/datatransfer-items-drop-fileEntry-file.html: Added. 13 * platform/wk2/TestExpectations: 14 1 15 2017-09-02 Chris Dumez <cdumez@apple.com> 2 16 -
trunk/LayoutTests/platform/wk2/TestExpectations
r221540 r221544 567 567 editing/pasteboard/datatransfer-items-drop-directoryReader-error.html 568 568 editing/pasteboard/datatransfer-items-drop-directoryReader-root.html 569 editing/pasteboard/datatransfer-items-drop-fileEntry-file.html 569 570 editing/pasteboard/datatransfer-items-drop-getAsEntry.html 570 571 editing/pasteboard/datatransfer-items-drop-getDirectory.html -
trunk/Source/WebCore/ChangeLog
r221543 r221544 1 2017-09-02 Chris Dumez <cdumez@apple.com> 2 3 Implement FileSystemFileEntry.file() 4 https://bugs.webkit.org/show_bug.cgi?id=176166 5 <rdar://problem/34187756> 6 7 Reviewed by Sam Weinig. 8 9 Implement FileSystemFileEntry.file(): 10 - https://wicg.github.io/entries-api/#dom-filesystemfileentry-file 11 12 Test: editing/pasteboard/datatransfer-items-drop-fileEntry-file.html 13 14 * Modules/entriesapi/DOMFileSystem.cpp: 15 (WebCore::validatePathIsExpectedType): 16 (WebCore::DOMFileSystem::listDirectory): 17 (WebCore::DOMFileSystem::getParent): 18 (WebCore::DOMFileSystem::getFile): 19 * Modules/entriesapi/DOMFileSystem.h: 20 * Modules/entriesapi/FileSystemFileEntry.cpp: 21 (WebCore::FileSystemFileEntry::file): 22 1 23 2017-09-02 Andy Estes <aestes@apple.com> 2 24 -
trunk/Source/WebCore/Modules/entriesapi/DOMFileSystem.cpp
r221540 r221544 160 160 } 161 161 162 static ExceptionOr<String> validatePathIsExpectedType(const String& fullPath, String&& virtualPath, FileMetadata::Type expectedType) 163 { 164 ASSERT(!isMainThread()); 165 166 FileMetadata metadata; 167 if (!getFileMetadata(fullPath, metadata, ShouldFollowSymbolicLinks::No)) 168 return Exception { NotFoundError, ASCIILiteral("Path does not exist") }; 169 170 if (metadata.type != expectedType) 171 return Exception { TypeMismatchError, "Entry at path does not have expected type" }; 172 173 return WTFMove(virtualPath); 174 } 175 162 176 // https://wicg.github.io/entries-api/#resolve-a-relative-path 163 177 static String resolveRelativeVirtualPath(const String& baseVirtualPath, StringView relativeVirtualPath) … … 218 232 ASSERT(&directory.filesystem() == this); 219 233 220 StringdirectoryVirtualPath = directory.virtualPath();221 StringfullPath = evaluatePath(directoryVirtualPath);234 auto directoryVirtualPath = directory.virtualPath(); 235 auto fullPath = evaluatePath(directoryVirtualPath); 222 236 if (fullPath == m_rootPath) { 223 237 Vector<Ref<FileSystemEntry>> children; … … 227 241 } 228 242 229 m_workQueue->dispatch([this, context = makeRef(context), completionHandler = WTFMove(completionHandler), fullPath = fullPath.isolatedCopy(), directoryVirtualPath = directoryVirtualPath.isolatedCopy()]() mutable {243 m_workQueue->dispatch([this, context = makeRef(context), completionHandler = WTFMove(completionHandler), fullPath = crossThreadCopy(fullPath), directoryVirtualPath = crossThreadCopy(directoryVirtualPath)]() mutable { 230 244 auto listedChildren = listDirectoryWithMetadata(fullPath); 231 245 callOnMainThread([this, context = WTFMove(context), completionHandler = WTFMove(completionHandler), listedChildren = crossThreadCopy(listedChildren), directoryVirtualPath = directoryVirtualPath.isolatedCopy()]() mutable { … … 235 249 } 236 250 237 static ExceptionOr<String> validatePathIsDirectory(const String& fullPath, String&& virtualPath)238 {239 ASSERT(!isMainThread());240 241 if (!fileIsDirectory(fullPath, ShouldFollowSymbolicLinks::No))242 return Exception { NotFoundError, "Path no longer exists or is no longer a directory" };243 return WTFMove(virtualPath);244 }245 246 251 void DOMFileSystem::getParent(ScriptExecutionContext& context, FileSystemEntry& entry, GetParentCallback&& completionCallback) 247 252 { 248 253 ASSERT(&entry.filesystem() == this); 249 254 250 StringvirtualPath = resolveRelativeVirtualPath(entry.virtualPath(), "..");255 auto virtualPath = resolveRelativeVirtualPath(entry.virtualPath(), ".."); 251 256 ASSERT(virtualPath[0] == '/'); 252 StringfullPath = evaluatePath(virtualPath);257 auto fullPath = evaluatePath(virtualPath); 253 258 m_workQueue->dispatch([this, context = makeRef(context), fullPath = crossThreadCopy(fullPath), virtualPath = crossThreadCopy(virtualPath), completionCallback = WTFMove(completionCallback)]() mutable { 254 auto validatedVirtualPath = validatePathIs Directory(fullPath, WTFMove(virtualPath));259 auto validatedVirtualPath = validatePathIsExpectedType(fullPath, WTFMove(virtualPath), FileMetadata::TypeDirectory); 255 260 callOnMainThread([this, context = WTFMove(context), validatedVirtualPath = crossThreadCopy(validatedVirtualPath), completionCallback = WTFMove(completionCallback)]() mutable { 256 261 if (validatedVirtualPath.hasException()) … … 282 287 } 283 288 284 StringresolvedVirtualPath = resolveRelativeVirtualPath(directory.virtualPath(), virtualPath);289 auto resolvedVirtualPath = resolveRelativeVirtualPath(directory.virtualPath(), virtualPath); 285 290 ASSERT(resolvedVirtualPath[0] == '/'); 286 StringfullPath = evaluatePath(resolvedVirtualPath);291 auto fullPath = evaluatePath(resolvedVirtualPath); 287 292 if (fullPath == m_rootPath) { 288 293 callOnMainThread([this, context = makeRef(context), completionCallback = WTFMove(completionCallback)]() mutable { … … 311 316 } 312 317 318 void DOMFileSystem::getFile(ScriptExecutionContext& context, FileSystemFileEntry& fileEntry, GetFileCallback&& completionCallback) 319 { 320 auto virtualPath = fileEntry.virtualPath(); 321 auto fullPath = evaluatePath(virtualPath); 322 m_workQueue->dispatch([this, context = makeRef(context), fullPath = crossThreadCopy(fullPath), virtualPath = crossThreadCopy(virtualPath), completionCallback = WTFMove(completionCallback)]() mutable { 323 auto validatedVirtualPath = validatePathIsExpectedType(fullPath, WTFMove(virtualPath), FileMetadata::TypeFile); 324 callOnMainThread([this, context = WTFMove(context), fullPath = crossThreadCopy(fullPath), validatedVirtualPath = crossThreadCopy(validatedVirtualPath), completionCallback = WTFMove(completionCallback)]() mutable { 325 if (validatedVirtualPath.hasException()) 326 completionCallback(validatedVirtualPath.releaseException()); 327 else 328 completionCallback(File::create(fullPath)); 329 }); 330 }); 331 } 332 313 333 } // namespace WebCore -
trunk/Source/WebCore/Modules/entriesapi/DOMFileSystem.h
r221540 r221544 62 62 void getEntry(ScriptExecutionContext&, FileSystemDirectoryEntry&, const String& virtualPath, const FileSystemDirectoryEntry::Flags&, GetEntryCallback&&); 63 63 64 using GetFileCallback = WTF::Function<void(ExceptionOr<Ref<File>>&&)>; 65 void getFile(ScriptExecutionContext&, FileSystemFileEntry&, GetFileCallback&&); 66 64 67 private: 65 68 explicit DOMFileSystem(Ref<File>&&); -
trunk/Source/WebCore/Modules/entriesapi/FileSystemFileEntry.cpp
r221481 r221544 28 28 29 29 #include "DOMException.h" 30 #include "DOMFileSystem.h" 30 31 #include "ErrorCallback.h" 32 #include "FileCallback.h" 31 33 32 34 namespace WebCore { … … 37 39 } 38 40 39 void FileSystemFileEntry::file(ScriptExecutionContext& context, Ref Ptr<FileCallback>&&, RefPtr<ErrorCallback>&& errorCallback)41 void FileSystemFileEntry::file(ScriptExecutionContext& context, Ref<FileCallback>&& successCallback, RefPtr<ErrorCallback>&& errorCallback) 40 42 { 41 if (errorCallback) 42 errorCallback->scheduleCallback(context, DOMException::create(NotSupportedError)); 43 filesystem().getFile(context, *this, [successCallback = WTFMove(successCallback), errorCallback = WTFMove(errorCallback)](auto&& result) { 44 if (result.hasException()) { 45 if (errorCallback) 46 errorCallback->handleEvent(DOMException::create(result.releaseException())); 47 return; 48 } 49 successCallback->handleEvent(result.releaseReturnValue()); 50 }); 43 51 } 44 52 -
trunk/Source/WebCore/Modules/entriesapi/FileSystemFileEntry.h
r221481 r221544 41 41 } 42 42 43 void file(ScriptExecutionContext&, Ref Ptr<FileCallback>&&, RefPtr<ErrorCallback>&& = nullptr);43 void file(ScriptExecutionContext&, Ref<FileCallback>&&, RefPtr<ErrorCallback>&& = nullptr); 44 44 45 45 private: -
trunk/Source/WebCore/Modules/entriesapi/FileSystemFileEntry.idl
r221302 r221544 27 27 EnabledAtRuntime=DirectoryUpload, 28 28 ] interface FileSystemFileEntry : FileSystemEntry { 29 [CallWith=ScriptExecutionContext] void file(FileCallback ?successCallback, optional ErrorCallback? errorCallback);29 [CallWith=ScriptExecutionContext] void file(FileCallback successCallback, optional ErrorCallback? errorCallback); 30 30 };
Note: See TracChangeset
for help on using the changeset viewer.