<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[287405] trunk/Source</title>
</head>
<body>
<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; }
#msg dl a { font-weight: bold}
#msg dl a:link { color:#fc3; }
#msg dl a:active { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://trac.webkit.org/projects/webkit/changeset/287405">287405</a></dd>
<dt>Author</dt> <dd>sihui_liu@apple.com</dd>
<dt>Date</dt> <dd>2021-12-23 10:36:33 -0800 (Thu, 23 Dec 2021)</dd>
</dl>
<h3>Log Message</h3>
<pre>Ensure file handles used in FileSystemAccess API are closed
https://bugs.webkit.org/show_bug.cgi?id=234520
Reviewed by Darin Adler.
Source/WebCore:
WebCore::FileHandle closes file handle in its destructor. Replace FileSystem::PlatformFileHandle with
WebCore::FileHandle in FileSystemSyncAccessHandle and WorkerFileSystemStorageConnection to ensure file handle
get closed if worker thread fails to execute the callback of createSyncAccessHandle, and if
FileSystemSyncAccessHandle is destroyed.
* Modules/filesystemaccess/FileSystemFileHandle.cpp:
(WebCore::FileSystemFileHandle::createSyncAccessHandle):
* Modules/filesystemaccess/FileSystemStorageConnection.h:
* Modules/filesystemaccess/FileSystemSyncAccessHandle.cpp:
(WebCore::FileSystemSyncAccessHandle::create):
(WebCore::FileSystemSyncAccessHandle::FileSystemSyncAccessHandle):
(WebCore::FileSystemSyncAccessHandle::truncate):
(WebCore::FileSystemSyncAccessHandle::getSize):
(WebCore::FileSystemSyncAccessHandle::flush):
(WebCore::FileSystemSyncAccessHandle::closeInternal):
(WebCore::FileSystemSyncAccessHandle::closeFile):
(WebCore::FileSystemSyncAccessHandle::read):
(WebCore::FileSystemSyncAccessHandle::write):
* Modules/filesystemaccess/FileSystemSyncAccessHandle.h:
* Modules/filesystemaccess/WorkerFileSystemStorageConnection.cpp:
(WebCore::WorkerFileSystemStorageConnection::didCreateSyncAccessHandle):
(WebCore::WorkerFileSystemStorageConnection::createSyncAccessHandle):
* Modules/filesystemaccess/WorkerFileSystemStorageConnection.h:
* platform/FileHandle.cpp:
(WebCore::FileHandle::FileHandle):
(WebCore::FileHandle::operator=):
(WebCore::FileHandle::open):
(WebCore::FileHandle::read):
(WebCore::FileHandle::write):
(WebCore::FileHandle::close):
(WebCore::FileHandle::handle const):
* platform/FileHandle.h:
Source/WebKit:
Replace FileSystem::PlatformFileHandle with WebCore::FileHandle in SharedFileHandle to ensure file handle get
closed, if it's not released for use.
* NetworkProcess/storage/FileSystemStorageHandle.cpp:
(WebKit::FileSystemStorageHandle::createSyncAccessHandle):
* NetworkProcess/storage/NetworkStorageManager.cpp:
(WebKit::NetworkStorageManager::createSyncAccessHandle):
* Platform/IPC/SharedFileHandle.cpp:
(IPC::SharedFileHandle::create):
(IPC::SharedFileHandle::close): Deleted.
* Platform/IPC/SharedFileHandle.h:
(IPC::SharedFileHandle::release):
(IPC::SharedFileHandle::SharedFileHandle):
(IPC::SharedFileHandle::handle): Deleted.
(): Deleted.
* Platform/IPC/cocoa/SharedFileHandleCocoa.cpp:
(IPC::SharedFileHandle::create):
(IPC::SharedFileHandle::encode const):
(IPC::SharedFileHandle::decode):
* WebProcess/WebCoreSupport/WebFileSystemStorageConnection.cpp:
(WebKit::WebFileSystemStorageConnection::createSyncAccessHandle):
Source/WTF:
* wtf/CrossThreadCopier.h:</pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkSourceWTFChangeLog">trunk/Source/WTF/ChangeLog</a></li>
<li><a href="#trunkSourceWebCoreChangeLog">trunk/Source/WebCore/ChangeLog</a></li>
<li><a href="#trunkSourceWebCoreModulesfilesystemaccessFileSystemFileHandlecpp">trunk/Source/WebCore/Modules/filesystemaccess/FileSystemFileHandle.cpp</a></li>
<li><a href="#trunkSourceWebCoreModulesfilesystemaccessFileSystemStorageConnectionh">trunk/Source/WebCore/Modules/filesystemaccess/FileSystemStorageConnection.h</a></li>
<li><a href="#trunkSourceWebCoreModulesfilesystemaccessFileSystemSyncAccessHandlecpp">trunk/Source/WebCore/Modules/filesystemaccess/FileSystemSyncAccessHandle.cpp</a></li>
<li><a href="#trunkSourceWebCoreModulesfilesystemaccessFileSystemSyncAccessHandleh">trunk/Source/WebCore/Modules/filesystemaccess/FileSystemSyncAccessHandle.h</a></li>
<li><a href="#trunkSourceWebCoreModulesfilesystemaccessWorkerFileSystemStorageConnectioncpp">trunk/Source/WebCore/Modules/filesystemaccess/WorkerFileSystemStorageConnection.cpp</a></li>
<li><a href="#trunkSourceWebCoreModulesfilesystemaccessWorkerFileSystemStorageConnectionh">trunk/Source/WebCore/Modules/filesystemaccess/WorkerFileSystemStorageConnection.h</a></li>
<li><a href="#trunkSourceWebCoreplatformFileHandlecpp">trunk/Source/WebCore/platform/FileHandle.cpp</a></li>
<li><a href="#trunkSourceWebCoreplatformFileHandleh">trunk/Source/WebCore/platform/FileHandle.h</a></li>
<li><a href="#trunkSourceWebKitChangeLog">trunk/Source/WebKit/ChangeLog</a></li>
<li><a href="#trunkSourceWebKitNetworkProcessstorageFileSystemStorageHandlecpp">trunk/Source/WebKit/NetworkProcess/storage/FileSystemStorageHandle.cpp</a></li>
<li><a href="#trunkSourceWebKitNetworkProcessstorageNetworkStorageManagercpp">trunk/Source/WebKit/NetworkProcess/storage/NetworkStorageManager.cpp</a></li>
<li><a href="#trunkSourceWebKitPlatformIPCSharedFileHandlecpp">trunk/Source/WebKit/Platform/IPC/SharedFileHandle.cpp</a></li>
<li><a href="#trunkSourceWebKitPlatformIPCSharedFileHandleh">trunk/Source/WebKit/Platform/IPC/SharedFileHandle.h</a></li>
<li><a href="#trunkSourceWebKitPlatformIPCcocoaSharedFileHandleCocoacpp">trunk/Source/WebKit/Platform/IPC/cocoa/SharedFileHandleCocoa.cpp</a></li>
<li><a href="#trunkSourceWebKitWebProcessWebCoreSupportWebFileSystemStorageConnectioncpp">trunk/Source/WebKit/WebProcess/WebCoreSupport/WebFileSystemStorageConnection.cpp</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkSourceWTFChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WTF/ChangeLog (287404 => 287405)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WTF/ChangeLog 2021-12-23 17:57:29 UTC (rev 287404)
+++ trunk/Source/WTF/ChangeLog 2021-12-23 18:36:33 UTC (rev 287405)
</span><span class="lines">@@ -1,3 +1,12 @@
</span><ins>+2021-12-23 Sihui Liu <sihui_liu@apple.com>
+
+ Ensure file handles used in FileSystemAccess API are closed
+ https://bugs.webkit.org/show_bug.cgi?id=234520
+
+ Reviewed by Darin Adler.
+
+ * wtf/CrossThreadCopier.h:
+
</ins><span class="cx"> 2021-12-22 Sihui Liu <sihui_liu@apple.com>
</span><span class="cx">
</span><span class="cx"> WebsiteDataStore::excludeDirectoryFromBackup should set attribute for existing directories
</span></span></pre></div>
<a id="trunkSourceWebCoreChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/ChangeLog (287404 => 287405)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/ChangeLog 2021-12-23 17:57:29 UTC (rev 287404)
+++ trunk/Source/WebCore/ChangeLog 2021-12-23 18:36:33 UTC (rev 287405)
</span><span class="lines">@@ -1,3 +1,43 @@
</span><ins>+2021-12-23 Sihui Liu <sihui_liu@apple.com>
+
+ Ensure file handles used in FileSystemAccess API are closed
+ https://bugs.webkit.org/show_bug.cgi?id=234520
+
+ Reviewed by Darin Adler.
+
+ WebCore::FileHandle closes file handle in its destructor. Replace FileSystem::PlatformFileHandle with
+ WebCore::FileHandle in FileSystemSyncAccessHandle and WorkerFileSystemStorageConnection to ensure file handle
+ get closed if worker thread fails to execute the callback of createSyncAccessHandle, and if
+ FileSystemSyncAccessHandle is destroyed.
+
+ * Modules/filesystemaccess/FileSystemFileHandle.cpp:
+ (WebCore::FileSystemFileHandle::createSyncAccessHandle):
+ * Modules/filesystemaccess/FileSystemStorageConnection.h:
+ * Modules/filesystemaccess/FileSystemSyncAccessHandle.cpp:
+ (WebCore::FileSystemSyncAccessHandle::create):
+ (WebCore::FileSystemSyncAccessHandle::FileSystemSyncAccessHandle):
+ (WebCore::FileSystemSyncAccessHandle::truncate):
+ (WebCore::FileSystemSyncAccessHandle::getSize):
+ (WebCore::FileSystemSyncAccessHandle::flush):
+ (WebCore::FileSystemSyncAccessHandle::closeInternal):
+ (WebCore::FileSystemSyncAccessHandle::closeFile):
+ (WebCore::FileSystemSyncAccessHandle::read):
+ (WebCore::FileSystemSyncAccessHandle::write):
+ * Modules/filesystemaccess/FileSystemSyncAccessHandle.h:
+ * Modules/filesystemaccess/WorkerFileSystemStorageConnection.cpp:
+ (WebCore::WorkerFileSystemStorageConnection::didCreateSyncAccessHandle):
+ (WebCore::WorkerFileSystemStorageConnection::createSyncAccessHandle):
+ * Modules/filesystemaccess/WorkerFileSystemStorageConnection.h:
+ * platform/FileHandle.cpp:
+ (WebCore::FileHandle::FileHandle):
+ (WebCore::FileHandle::operator=):
+ (WebCore::FileHandle::open):
+ (WebCore::FileHandle::read):
+ (WebCore::FileHandle::write):
+ (WebCore::FileHandle::close):
+ (WebCore::FileHandle::handle const):
+ * platform/FileHandle.h:
+
</ins><span class="cx"> 2021-12-23 Wenson Hsieh <wenson_hsieh@apple.com>
</span><span class="cx">
</span><span class="cx"> Add API testing support for modal container observation
</span></span></pre></div>
<a id="trunkSourceWebCoreModulesfilesystemaccessFileSystemFileHandlecpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/Modules/filesystemaccess/FileSystemFileHandle.cpp (287404 => 287405)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/Modules/filesystemaccess/FileSystemFileHandle.cpp 2021-12-23 17:57:29 UTC (rev 287404)
+++ trunk/Source/WebCore/Modules/filesystemaccess/FileSystemFileHandle.cpp 2021-12-23 18:36:33 UTC (rev 287405)
</span><span class="lines">@@ -79,17 +79,16 @@
</span><span class="cx"> return promise.reject(result.releaseException());
</span><span class="cx">
</span><span class="cx"> auto [identifier, file] = result.releaseReturnValue();
</span><del>- if (file == FileSystem::invalidPlatformFileHandle)
</del><ins>+ if (!file)
</ins><span class="cx"> return promise.reject(Exception { UnknownError, "Invalid platform file handle"_s });
</span><span class="cx">
</span><span class="cx"> auto* context = protectedThis->scriptExecutionContext();
</span><span class="cx"> if (!context) {
</span><del>- FileSystem::closeFile(file);
</del><span class="cx"> protectedThis->closeSyncAccessHandle(identifier, { });
</span><span class="cx"> return promise.reject(Exception { InvalidStateError, "Context has stopped"_s });
</span><span class="cx"> }
</span><span class="cx">
</span><del>- promise.resolve(FileSystemSyncAccessHandle::create(*context, protectedThis.get(), identifier, file));
</del><ins>+ promise.resolve(FileSystemSyncAccessHandle::create(*context, protectedThis.get(), identifier, WTFMove(file)));
</ins><span class="cx"> });
</span><span class="cx"> }
</span><span class="cx">
</span></span></pre></div>
<a id="trunkSourceWebCoreModulesfilesystemaccessFileSystemStorageConnectionh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/Modules/filesystemaccess/FileSystemStorageConnection.h (287404 => 287405)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/Modules/filesystemaccess/FileSystemStorageConnection.h 2021-12-23 17:57:29 UTC (rev 287404)
+++ trunk/Source/WebCore/Modules/filesystemaccess/FileSystemStorageConnection.h 2021-12-23 18:36:33 UTC (rev 287405)
</span><span class="lines">@@ -37,6 +37,7 @@
</span><span class="cx">
</span><span class="cx"> class FileSystemDirectoryHandle;
</span><span class="cx"> class FileSystemFileHandle;
</span><ins>+class FileHandle;
</ins><span class="cx"> class FileSystemHandleCloseScope;
</span><span class="cx"> class FileSystemSyncAccessHandle;
</span><span class="cx"> template<typename> class ExceptionOr;
</span><span class="lines">@@ -48,7 +49,7 @@
</span><span class="cx"> using SameEntryCallback = CompletionHandler<void(ExceptionOr<bool>&&)>;
</span><span class="cx"> using GetHandleCallback = CompletionHandler<void(ExceptionOr<Ref<FileSystemHandleCloseScope>>&&)>;
</span><span class="cx"> using ResolveCallback = CompletionHandler<void(ExceptionOr<Vector<String>>&&)>;
</span><del>- using GetAccessHandleCallback = CompletionHandler<void(ExceptionOr<std::pair<FileSystemSyncAccessHandleIdentifier, FileSystem::PlatformFileHandle>>&&)>;
</del><ins>+ using GetAccessHandleCallback = CompletionHandler<void(ExceptionOr<std::pair<FileSystemSyncAccessHandleIdentifier, FileHandle>>&&)>;
</ins><span class="cx"> using VoidCallback = CompletionHandler<void(ExceptionOr<void>&&)>;
</span><span class="cx"> using GetHandleNamesCallback = CompletionHandler<void(ExceptionOr<Vector<String>>&&)>;
</span><span class="cx"> using StringCallback = CompletionHandler<void(ExceptionOr<String>&&)>;
</span></span></pre></div>
<a id="trunkSourceWebCoreModulesfilesystemaccessFileSystemSyncAccessHandlecpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/Modules/filesystemaccess/FileSystemSyncAccessHandle.cpp (287404 => 287405)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/Modules/filesystemaccess/FileSystemSyncAccessHandle.cpp 2021-12-23 17:57:29 UTC (rev 287404)
+++ trunk/Source/WebCore/Modules/filesystemaccess/FileSystemSyncAccessHandle.cpp 2021-12-23 18:36:33 UTC (rev 287405)
</span><span class="lines">@@ -35,20 +35,20 @@
</span><span class="cx">
</span><span class="cx"> namespace WebCore {
</span><span class="cx">
</span><del>-Ref<FileSystemSyncAccessHandle> FileSystemSyncAccessHandle::create(ScriptExecutionContext& context, FileSystemFileHandle& source, FileSystemSyncAccessHandleIdentifier identifier, FileSystem::PlatformFileHandle file)
</del><ins>+Ref<FileSystemSyncAccessHandle> FileSystemSyncAccessHandle::create(ScriptExecutionContext& context, FileSystemFileHandle& source, FileSystemSyncAccessHandleIdentifier identifier, FileHandle&& file)
</ins><span class="cx"> {
</span><del>- auto handle = adoptRef(*new FileSystemSyncAccessHandle(context, source, identifier, file));
</del><ins>+ auto handle = adoptRef(*new FileSystemSyncAccessHandle(context, source, identifier, WTFMove(file)));
</ins><span class="cx"> handle->suspendIfNeeded();
</span><span class="cx"> return handle;
</span><span class="cx"> }
</span><span class="cx">
</span><del>-FileSystemSyncAccessHandle::FileSystemSyncAccessHandle(ScriptExecutionContext& context, FileSystemFileHandle& source, FileSystemSyncAccessHandleIdentifier identifier, FileSystem::PlatformFileHandle file)
</del><ins>+FileSystemSyncAccessHandle::FileSystemSyncAccessHandle(ScriptExecutionContext& context, FileSystemFileHandle& source, FileSystemSyncAccessHandleIdentifier identifier, FileHandle&& file)
</ins><span class="cx"> : ActiveDOMObject(&context)
</span><span class="cx"> , m_source(source)
</span><span class="cx"> , m_identifier(identifier)
</span><del>- , m_file(file)
</del><ins>+ , m_file(WTFMove(file))
</ins><span class="cx"> {
</span><del>- ASSERT(m_file != FileSystem::invalidPlatformFileHandle);
</del><ins>+ ASSERT(m_file);
</ins><span class="cx">
</span><span class="cx"> m_source->registerSyncAccessHandle(m_identifier, *this);
</span><span class="cx"> }
</span><span class="lines">@@ -88,7 +88,7 @@
</span><span class="cx"> return promise.reject(Exception { InvalidStateError, "Context is invalid"_s });
</span><span class="cx">
</span><span class="cx"> m_pendingPromises.append(WTFMove(promise));
</span><del>- WorkerGlobalScope::postFileSystemStorageTask([weakThis = WeakPtr { *this }, file = m_file, size, workerThread = Ref { scope->thread() }]() mutable {
</del><ins>+ WorkerGlobalScope::postFileSystemStorageTask([weakThis = WeakPtr { *this }, file = m_file.handle(), size, workerThread = Ref { scope->thread() }]() mutable {
</ins><span class="cx"> workerThread->runLoop().postTask([weakThis = WTFMove(weakThis), success = FileSystem::truncateFile(file, size)](auto&) mutable {
</span><span class="cx"> if (weakThis)
</span><span class="cx"> weakThis->completePromise(success ? ExceptionOr<void> { } : Exception { UnknownError });
</span><span class="lines">@@ -106,7 +106,7 @@
</span><span class="cx"> return promise.reject(Exception { InvalidStateError, "Context is invalid"_s });
</span><span class="cx">
</span><span class="cx"> m_pendingPromises.append(WTFMove(promise));
</span><del>- WorkerGlobalScope::postFileSystemStorageTask([weakThis = WeakPtr { *this }, file = m_file, workerThread = Ref { scope->thread() }]() mutable {
</del><ins>+ WorkerGlobalScope::postFileSystemStorageTask([weakThis = WeakPtr { *this }, file = m_file.handle(), workerThread = Ref { scope->thread() }]() mutable {
</ins><span class="cx"> workerThread->runLoop().postTask([weakThis = WTFMove(weakThis), success = FileSystem::fileSize(file)](auto&) mutable {
</span><span class="cx"> if (weakThis)
</span><span class="cx"> weakThis->completePromise(success ? ExceptionOr<uint64_t> { success.value() } : Exception { UnknownError });
</span><span class="lines">@@ -124,7 +124,7 @@
</span><span class="cx"> return promise.reject(Exception { InvalidStateError, "Context is invalid"_s });
</span><span class="cx">
</span><span class="cx"> m_pendingPromises.append(WTFMove(promise));
</span><del>- WorkerGlobalScope::postFileSystemStorageTask([weakThis = WeakPtr { *this }, file = m_file, workerThread = Ref { scope->thread() }]() mutable {
</del><ins>+ WorkerGlobalScope::postFileSystemStorageTask([weakThis = WeakPtr { *this }, file = m_file.handle(), workerThread = Ref { scope->thread() }]() mutable {
</ins><span class="cx"> workerThread->runLoop().postTask([weakThis = WTFMove(weakThis), success = FileSystem::flushFile(file)](auto&) mutable {
</span><span class="cx"> if (weakThis)
</span><span class="cx"> weakThis->completePromise(success ? ExceptionOr<void> { } : Exception { UnknownError });
</span><span class="lines">@@ -149,20 +149,19 @@
</span><span class="cx"> if (isClosing)
</span><span class="cx"> return;
</span><span class="cx">
</span><del>- ASSERT(m_file != FileSystem::invalidPlatformFileHandle);
</del><ins>+ ASSERT(m_file);
</ins><span class="cx"> closeFile();
</span><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> void FileSystemSyncAccessHandle::closeFile()
</span><span class="cx"> {
</span><del>- if (m_file == FileSystem::invalidPlatformFileHandle)
</del><ins>+ if (!m_file)
</ins><span class="cx"> return;
</span><span class="cx">
</span><span class="cx"> auto* scope = downcast<WorkerGlobalScope>(scriptExecutionContext());
</span><span class="cx"> ASSERT(scope);
</span><span class="cx">
</span><del>- WorkerGlobalScope::postFileSystemStorageTask([weakThis = WeakPtr { *this }, file = std::exchange(m_file, FileSystem::invalidPlatformFileHandle), workerThread = Ref { scope->thread() }]() mutable {
- FileSystem::closeFile(file);
</del><ins>+ WorkerGlobalScope::postFileSystemStorageTask([weakThis = WeakPtr { *this }, file = std::exchange(m_file, { }), workerThread = Ref { scope->thread() }]() mutable {
</ins><span class="cx"> workerThread->runLoop().postTask([weakThis = WTFMove(weakThis)](auto&) mutable {
</span><span class="cx"> if (weakThis)
</span><span class="cx"> weakThis->didCloseFile();
</span><span class="lines">@@ -212,11 +211,11 @@
</span><span class="cx"> if (!m_pendingPromises.isEmpty())
</span><span class="cx"> return Exception { InvalidStateError, "Access handle has unfinished operation"_s };
</span><span class="cx">
</span><del>- int result = FileSystem::seekFile(m_file, options.at, FileSystem::FileSeekOrigin::Beginning);
</del><ins>+ int result = FileSystem::seekFile(m_file.handle(), options.at, FileSystem::FileSeekOrigin::Beginning);
</ins><span class="cx"> if (result == -1)
</span><span class="cx"> return Exception { InvalidStateError, "Failed to read at offset"_s };
</span><span class="cx">
</span><del>- result = FileSystem::readFromFile(m_file, buffer.mutableData(), buffer.length());
</del><ins>+ result = FileSystem::readFromFile(m_file.handle(), buffer.mutableData(), buffer.length());
</ins><span class="cx"> if (result == -1)
</span><span class="cx"> return Exception { InvalidStateError, "Failed to read from file"_s };
</span><span class="cx">
</span><span class="lines">@@ -233,11 +232,11 @@
</span><span class="cx"> if (!m_pendingPromises.isEmpty())
</span><span class="cx"> return Exception { InvalidStateError, "Access handle has unfinished operation"_s };
</span><span class="cx">
</span><del>- int result = FileSystem::seekFile(m_file, options.at, FileSystem::FileSeekOrigin::Beginning);
</del><ins>+ int result = FileSystem::seekFile(m_file.handle(), options.at, FileSystem::FileSeekOrigin::Beginning);
</ins><span class="cx"> if (result == -1)
</span><span class="cx"> return Exception { InvalidStateError, "Failed to write at offset"_s };
</span><span class="cx">
</span><del>- result = FileSystem::writeToFile(m_file, buffer.data(), buffer.length());
</del><ins>+ result = FileSystem::writeToFile(m_file.handle(), buffer.data(), buffer.length());
</ins><span class="cx"> if (result == -1)
</span><span class="cx"> return Exception { InvalidStateError, "Failed to write to file"_s };
</span><span class="cx">
</span></span></pre></div>
<a id="trunkSourceWebCoreModulesfilesystemaccessFileSystemSyncAccessHandleh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/Modules/filesystemaccess/FileSystemSyncAccessHandle.h (287404 => 287405)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/Modules/filesystemaccess/FileSystemSyncAccessHandle.h 2021-12-23 17:57:29 UTC (rev 287404)
+++ trunk/Source/WebCore/Modules/filesystemaccess/FileSystemSyncAccessHandle.h 2021-12-23 18:36:33 UTC (rev 287405)
</span><span class="lines">@@ -28,6 +28,7 @@
</span><span class="cx"> #include "ActiveDOMObject.h"
</span><span class="cx"> #include "BufferSource.h"
</span><span class="cx"> #include "ExceptionOr.h"
</span><ins>+#include "FileHandle.h"
</ins><span class="cx"> #include "FileSystemSyncAccessHandleIdentifier.h"
</span><span class="cx"> #include "IDLTypes.h"
</span><span class="cx"> #include <wtf/Deque.h>
</span><span class="lines">@@ -45,7 +46,7 @@
</span><span class="cx"> unsigned long long at;
</span><span class="cx"> };
</span><span class="cx">
</span><del>- static Ref<FileSystemSyncAccessHandle> create(ScriptExecutionContext&, FileSystemFileHandle&, FileSystemSyncAccessHandleIdentifier, FileSystem::PlatformFileHandle);
</del><ins>+ static Ref<FileSystemSyncAccessHandle> create(ScriptExecutionContext&, FileSystemFileHandle&, FileSystemSyncAccessHandleIdentifier, FileHandle&&);
</ins><span class="cx"> ~FileSystemSyncAccessHandle();
</span><span class="cx">
</span><span class="cx"> void truncate(unsigned long long size, DOMPromiseDeferred<void>&&);
</span><span class="lines">@@ -59,7 +60,7 @@
</span><span class="cx"> void invalidate();
</span><span class="cx">
</span><span class="cx"> private:
</span><del>- FileSystemSyncAccessHandle(ScriptExecutionContext&, FileSystemFileHandle&, FileSystemSyncAccessHandleIdentifier, FileSystem::PlatformFileHandle);
</del><ins>+ FileSystemSyncAccessHandle(ScriptExecutionContext&, FileSystemFileHandle&, FileSystemSyncAccessHandleIdentifier, FileHandle&&);
</ins><span class="cx"> bool isClosingOrClosed() const;
</span><span class="cx"> using CloseCallback = CompletionHandler<void(ExceptionOr<void>&&)>;
</span><span class="cx"> void closeInternal(CloseCallback&&);
</span><span class="lines">@@ -75,7 +76,7 @@
</span><span class="cx">
</span><span class="cx"> Ref<FileSystemFileHandle> m_source;
</span><span class="cx"> FileSystemSyncAccessHandleIdentifier m_identifier;
</span><del>- FileSystem::PlatformFileHandle m_file;
</del><ins>+ FileHandle m_file;
</ins><span class="cx"> std::optional<ExceptionOr<void>> m_closeResult;
</span><span class="cx"> Vector<CloseCallback> m_closeCallbacks;
</span><span class="cx"> using Promise = std::variant<DOMPromiseDeferred<void>, DOMPromiseDeferred<IDLUnsignedLongLong>>;
</span></span></pre></div>
<a id="trunkSourceWebCoreModulesfilesystemaccessWorkerFileSystemStorageConnectioncpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/Modules/filesystemaccess/WorkerFileSystemStorageConnection.cpp (287404 => 287405)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/Modules/filesystemaccess/WorkerFileSystemStorageConnection.cpp 2021-12-23 17:57:29 UTC (rev 287404)
+++ trunk/Source/WebCore/Modules/filesystemaccess/WorkerFileSystemStorageConnection.cpp 2021-12-23 18:36:33 UTC (rev 287405)
</span><span class="lines">@@ -237,7 +237,7 @@
</span><span class="cx"> callback(WTFMove(result));
</span><span class="cx"> }
</span><span class="cx">
</span><del>-void WorkerFileSystemStorageConnection::didCreateSyncAccessHandle(CallbackIdentifier callbackIdentifier, ExceptionOr<std::pair<FileSystemSyncAccessHandleIdentifier, FileSystem::PlatformFileHandle>>&& result)
</del><ins>+void WorkerFileSystemStorageConnection::didCreateSyncAccessHandle(CallbackIdentifier callbackIdentifier, ExceptionOr<std::pair<FileSystemSyncAccessHandleIdentifier, FileHandle>>&& result)
</ins><span class="cx"> {
</span><span class="cx"> if (auto callback = m_getAccessHandlCallbacks.take(callbackIdentifier))
</span><span class="cx"> callback(WTFMove(result));
</span><span class="lines">@@ -259,10 +259,9 @@
</span><span class="cx">
</span><span class="cx"> callOnMainThread([callbackIdentifier, workerThread = Ref { m_scope->thread() }, mainThreadConnection = m_mainThreadConnection, identifier]() mutable {
</span><span class="cx"> auto mainThreadCallback = [callbackIdentifier, workerThread = WTFMove(workerThread)](auto result) mutable {
</span><del>- auto crossThreadResult = result;
</del><span class="cx"> if (result.hasException())
</span><del>- crossThreadResult = crossThreadCopy(result.exception());
- workerThread->runLoop().postTaskForMode([callbackIdentifier, result = WTFMove(crossThreadResult)] (auto& scope) mutable {
</del><ins>+ result = crossThreadCopy(result.exception());
+ workerThread->runLoop().postTaskForMode([callbackIdentifier, result = WTFMove(result)] (auto& scope) mutable {
</ins><span class="cx"> if (auto connection = downcast<WorkerGlobalScope>(scope).fileSystemStorageConnection())
</span><span class="cx"> connection->didCreateSyncAccessHandle(callbackIdentifier, WTFMove(result));
</span><span class="cx"> }, WorkerRunLoop::defaultMode());
</span></span></pre></div>
<a id="trunkSourceWebCoreModulesfilesystemaccessWorkerFileSystemStorageConnectionh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/Modules/filesystemaccess/WorkerFileSystemStorageConnection.h (287404 => 287405)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/Modules/filesystemaccess/WorkerFileSystemStorageConnection.h 2021-12-23 17:57:29 UTC (rev 287404)
+++ trunk/Source/WebCore/Modules/filesystemaccess/WorkerFileSystemStorageConnection.h 2021-12-23 18:36:33 UTC (rev 287405)
</span><span class="lines">@@ -32,6 +32,7 @@
</span><span class="cx">
</span><span class="cx"> namespace WebCore {
</span><span class="cx">
</span><ins>+class FileHandle;
</ins><span class="cx"> class FileSystemSyncAccessHandle;
</span><span class="cx"> class WorkerGlobalScope;
</span><span class="cx"> class WorkerThread;
</span><span class="lines">@@ -50,7 +51,7 @@
</span><span class="cx"> void didGetHandle(CallbackIdentifier, ExceptionOr<Ref<FileSystemHandleCloseScope>>&&);
</span><span class="cx"> void didResolve(CallbackIdentifier, ExceptionOr<Vector<String>>&&);
</span><span class="cx"> void completeStringCallback(CallbackIdentifier, ExceptionOr<String>&&);
</span><del>- void didCreateSyncAccessHandle(CallbackIdentifier, ExceptionOr<std::pair<FileSystemSyncAccessHandleIdentifier, FileSystem::PlatformFileHandle>>&&);
</del><ins>+ void didCreateSyncAccessHandle(CallbackIdentifier, ExceptionOr<std::pair<FileSystemSyncAccessHandleIdentifier, FileHandle>>&&);
</ins><span class="cx"> void completeVoidCallback(CallbackIdentifier, ExceptionOr<void>&& result);
</span><span class="cx"> void didGetHandleNames(CallbackIdentifier, ExceptionOr<Vector<String>>&&);
</span><span class="cx">
</span></span></pre></div>
<a id="trunkSourceWebCoreplatformFileHandlecpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/FileHandle.cpp (287404 => 287405)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/FileHandle.cpp 2021-12-23 17:57:29 UTC (rev 287404)
+++ trunk/Source/WebCore/platform/FileHandle.cpp 2021-12-23 18:36:33 UTC (rev 287405)
</span><span class="lines">@@ -52,6 +52,11 @@
</span><span class="cx"> {
</span><span class="cx"> }
</span><span class="cx">
</span><ins>+FileHandle::FileHandle(FileSystem::PlatformFileHandle&& handle)
+ : m_fileHandle(WTFMove(handle))
+{
+}
+
</ins><span class="cx"> FileHandle::~FileHandle()
</span><span class="cx"> {
</span><span class="cx"> close();
</span><span class="lines">@@ -63,6 +68,9 @@
</span><span class="cx"> m_path = WTFMove(other.m_path);
</span><span class="cx"> m_mode = WTFMove(other.m_mode);
</span><span class="cx"> m_fileHandle = std::exchange(other.m_fileHandle, FileSystem::invalidPlatformFileHandle);
</span><ins>+ m_shouldLock = other.m_shouldLock;
+ m_lockMode = other.m_lockMode;
+
</ins><span class="cx"> return *this;
</span><span class="cx"> }
</span><span class="cx">
</span><span class="lines">@@ -84,8 +92,12 @@
</span><span class="cx">
</span><span class="cx"> bool FileHandle::open()
</span><span class="cx"> {
</span><ins>+ if (m_path.isEmpty())
+ return false;
+
</ins><span class="cx"> if (!*this)
</span><span class="cx"> m_fileHandle = m_shouldLock ? FileSystem::openAndLockFile(m_path, m_mode, m_lockMode) : FileSystem::openFile(m_path, m_mode);
</span><ins>+
</ins><span class="cx"> return static_cast<bool>(*this);
</span><span class="cx"> }
</span><span class="cx">
</span><span class="lines">@@ -93,6 +105,7 @@
</span><span class="cx"> {
</span><span class="cx"> if (!open())
</span><span class="cx"> return -1;
</span><ins>+
</ins><span class="cx"> return FileSystem::readFromFile(m_fileHandle, data, length);
</span><span class="cx"> }
</span><span class="cx">
</span><span class="lines">@@ -100,6 +113,7 @@
</span><span class="cx"> {
</span><span class="cx"> if (!open())
</span><span class="cx"> return -1;
</span><ins>+
</ins><span class="cx"> return FileSystem::writeToFile(m_fileHandle, data, length);
</span><span class="cx"> }
</span><span class="cx">
</span><span class="lines">@@ -126,8 +140,15 @@
</span><span class="cx"> if (m_shouldLock && *this) {
</span><span class="cx"> // FileSystem::unlockAndCloseFile requires the file handle to be valid while closeFile does not
</span><span class="cx"> FileSystem::unlockAndCloseFile(m_fileHandle);
</span><del>- } else
- FileSystem::closeFile(m_fileHandle);
</del><ins>+ return;
+ }
+
+ FileSystem::closeFile(m_fileHandle);
</ins><span class="cx"> }
</span><span class="cx">
</span><ins>+FileSystem::PlatformFileHandle FileHandle::handle() const
+{
+ return m_fileHandle;
+}
+
</ins><span class="cx"> } // namespace WebCore
</span></span></pre></div>
<a id="trunkSourceWebCoreplatformFileHandleh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/FileHandle.h (287404 => 287405)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/FileHandle.h 2021-12-23 17:57:29 UTC (rev 287404)
+++ trunk/Source/WebCore/platform/FileHandle.h 2021-12-23 18:36:33 UTC (rev 287405)
</span><span class="lines">@@ -36,15 +36,14 @@
</span><span class="cx"> class WEBCORE_EXPORT FileHandle final {
</span><span class="cx"> public:
</span><span class="cx"> FileHandle() = default;
</span><ins>+ ~FileHandle();
</ins><span class="cx"> FileHandle(const String& path, FileSystem::FileOpenMode);
</span><span class="cx"> FileHandle(const String& path, FileSystem::FileOpenMode, OptionSet<FileSystem::FileLockMode>);
</span><del>- FileHandle(const FileHandle& other) = delete;
</del><span class="cx"> FileHandle(FileHandle&& other);
</span><del>-
- ~FileHandle();
-
- FileHandle& operator=(const FileHandle& other) = delete;
</del><span class="cx"> FileHandle& operator=(FileHandle&& other);
</span><ins>+ FileHandle(const FileHandle&) = delete;
+ FileHandle& operator=(const FileHandle&) = delete;
+ explicit FileHandle(FileSystem::PlatformFileHandle&&);
</ins><span class="cx">
</span><span class="cx"> explicit operator bool() const;
</span><span class="cx">
</span><span class="lines">@@ -55,6 +54,8 @@
</span><span class="cx"> bool printf(const char* format, ...) WTF_ATTRIBUTE_PRINTF(2, 3);
</span><span class="cx"> void close();
</span><span class="cx">
</span><ins>+ FileSystem::PlatformFileHandle handle() const;
+
</ins><span class="cx"> private:
</span><span class="cx"> String m_path;
</span><span class="cx"> FileSystem::FileOpenMode m_mode { FileSystem::FileOpenMode::Read };
</span></span></pre></div>
<a id="trunkSourceWebKitChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit/ChangeLog (287404 => 287405)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit/ChangeLog 2021-12-23 17:57:29 UTC (rev 287404)
+++ trunk/Source/WebKit/ChangeLog 2021-12-23 18:36:33 UTC (rev 287405)
</span><span class="lines">@@ -1,3 +1,32 @@
</span><ins>+2021-12-23 Sihui Liu <sihui_liu@apple.com>
+
+ Ensure file handles used in FileSystemAccess API are closed
+ https://bugs.webkit.org/show_bug.cgi?id=234520
+
+ Reviewed by Darin Adler.
+
+ Replace FileSystem::PlatformFileHandle with WebCore::FileHandle in SharedFileHandle to ensure file handle get
+ closed, if it's not released for use.
+
+ * NetworkProcess/storage/FileSystemStorageHandle.cpp:
+ (WebKit::FileSystemStorageHandle::createSyncAccessHandle):
+ * NetworkProcess/storage/NetworkStorageManager.cpp:
+ (WebKit::NetworkStorageManager::createSyncAccessHandle):
+ * Platform/IPC/SharedFileHandle.cpp:
+ (IPC::SharedFileHandle::create):
+ (IPC::SharedFileHandle::close): Deleted.
+ * Platform/IPC/SharedFileHandle.h:
+ (IPC::SharedFileHandle::release):
+ (IPC::SharedFileHandle::SharedFileHandle):
+ (IPC::SharedFileHandle::handle): Deleted.
+ (): Deleted.
+ * Platform/IPC/cocoa/SharedFileHandleCocoa.cpp:
+ (IPC::SharedFileHandle::create):
+ (IPC::SharedFileHandle::encode const):
+ (IPC::SharedFileHandle::decode):
+ * WebProcess/WebCoreSupport/WebFileSystemStorageConnection.cpp:
+ (WebKit::WebFileSystemStorageConnection::createSyncAccessHandle):
+
</ins><span class="cx"> 2021-12-22 Alex Christensen <achristensen@webkit.org>
</span><span class="cx">
</span><span class="cx"> Re-enable WebPushD.HandleInjectedPush API test
</span></span></pre></div>
<a id="trunkSourceWebKitNetworkProcessstorageFileSystemStorageHandlecpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit/NetworkProcess/storage/FileSystemStorageHandle.cpp (287404 => 287405)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit/NetworkProcess/storage/FileSystemStorageHandle.cpp 2021-12-23 17:57:29 UTC (rev 287404)
+++ trunk/Source/WebKit/NetworkProcess/storage/FileSystemStorageHandle.cpp 2021-12-23 18:36:33 UTC (rev 287405)
</span><span class="lines">@@ -172,7 +172,7 @@
</span><span class="cx"> if (handle == FileSystem::invalidPlatformFileHandle)
</span><span class="cx"> return makeUnexpected(FileSystemStorageError::Unknown);
</span><span class="cx">
</span><del>- auto ipcHandle = IPC::SharedFileHandle::create(handle);
</del><ins>+ auto ipcHandle = IPC::SharedFileHandle::create(std::exchange(handle, FileSystem::invalidPlatformFileHandle));
</ins><span class="cx"> if (!ipcHandle) {
</span><span class="cx"> FileSystem::closeFile(handle);
</span><span class="cx"> return makeUnexpected(FileSystemStorageError::BackendNotSupported);
</span></span></pre></div>
<a id="trunkSourceWebKitNetworkProcessstorageNetworkStorageManagercpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit/NetworkProcess/storage/NetworkStorageManager.cpp (287404 => 287405)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit/NetworkProcess/storage/NetworkStorageManager.cpp 2021-12-23 17:57:29 UTC (rev 287404)
+++ trunk/Source/WebKit/NetworkProcess/storage/NetworkStorageManager.cpp 2021-12-23 18:36:33 UTC (rev 287405)
</span><span class="lines">@@ -371,12 +371,7 @@
</span><span class="cx"> if (!handle)
</span><span class="cx"> return completionHandler(makeUnexpected(FileSystemStorageError::Unknown));
</span><span class="cx">
</span><del>- auto result = handle->createSyncAccessHandle();
- auto fileHandle = result ? result.value().second : IPC::SharedFileHandle();
- completionHandler(WTFMove(result));
-
- // Close the file handle in network process.
- fileHandle.close();
</del><ins>+ completionHandler(handle->createSyncAccessHandle());
</ins><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> void NetworkStorageManager::closeSyncAccessHandle(WebCore::FileSystemHandleIdentifier identifier, WebCore::FileSystemSyncAccessHandleIdentifier accessHandleIdentifier, CompletionHandler<void(std::optional<FileSystemStorageError>)>&& completionHandler)
</span></span></pre></div>
<a id="trunkSourceWebKitPlatformIPCSharedFileHandlecpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit/Platform/IPC/SharedFileHandle.cpp (287404 => 287405)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit/Platform/IPC/SharedFileHandle.cpp 2021-12-23 17:57:29 UTC (rev 287404)
+++ trunk/Source/WebKit/Platform/IPC/SharedFileHandle.cpp 2021-12-23 18:36:33 UTC (rev 287405)
</span><span class="lines">@@ -28,15 +28,13 @@
</span><span class="cx">
</span><span class="cx"> namespace IPC {
</span><span class="cx">
</span><del>-void SharedFileHandle::close()
-{
- FileSystem::closeFile(m_handle);
-}
-
</del><span class="cx"> #if !PLATFORM(COCOA)
</span><span class="cx">
</span><del>-std::optional<SharedFileHandle> SharedFileHandle::create(FileSystem::PlatformFileHandle)
</del><ins>+std::optional<SharedFileHandle> SharedFileHandle::create(FileSystem::PlatformFileHandle&& handle)
</ins><span class="cx"> {
</span><ins>+ auto currentHandle = WTFMove(handle);
+ FileSystem::closeFile(currentHandle);
+
</ins><span class="cx"> return std::nullopt;
</span><span class="cx"> }
</span><span class="cx">
</span></span></pre></div>
<a id="trunkSourceWebKitPlatformIPCSharedFileHandleh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit/Platform/IPC/SharedFileHandle.h (287404 => 287405)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit/Platform/IPC/SharedFileHandle.h 2021-12-23 17:57:29 UTC (rev 287404)
+++ trunk/Source/WebKit/Platform/IPC/SharedFileHandle.h 2021-12-23 18:36:33 UTC (rev 287405)
</span><span class="lines">@@ -25,6 +25,7 @@
</span><span class="cx">
</span><span class="cx"> #pragma once
</span><span class="cx">
</span><ins>+#include <WebCore/FileHandle.h>
</ins><span class="cx"> #include <fcntl.h>
</span><span class="cx"> #include <wtf/FileSystem.h>
</span><span class="cx">
</span><span class="lines">@@ -35,22 +36,21 @@
</span><span class="cx">
</span><span class="cx"> class SharedFileHandle {
</span><span class="cx"> public:
</span><del>- static std::optional<SharedFileHandle> create(FileSystem::PlatformFileHandle);
</del><ins>+ static std::optional<SharedFileHandle> create(FileSystem::PlatformFileHandle&&);
</ins><span class="cx">
</span><span class="cx"> SharedFileHandle() = default;
</span><del>- FileSystem::PlatformFileHandle handle() { return m_handle; }
- void close();
</del><ins>+ WebCore::FileHandle release() { return std::exchange(m_handle, { }); }
</ins><span class="cx">
</span><span class="cx"> void encode(Encoder&) const;
</span><span class="cx"> static std::optional<SharedFileHandle> decode(Decoder&);
</span><span class="cx">
</span><span class="cx"> private:
</span><del>- explicit SharedFileHandle(FileSystem::PlatformFileHandle handle)
- : m_handle(handle)
</del><ins>+ explicit SharedFileHandle(FileSystem::PlatformFileHandle&& handle)
+ : m_handle(WTFMove(handle))
</ins><span class="cx"> {
</span><span class="cx"> }
</span><span class="cx">
</span><del>- FileSystem::PlatformFileHandle m_handle { FileSystem::invalidPlatformFileHandle };
</del><ins>+ WebCore::FileHandle m_handle;
</ins><span class="cx"> };
</span><span class="cx">
</span><span class="cx"> } // namespace IPC
</span></span></pre></div>
<a id="trunkSourceWebKitPlatformIPCcocoaSharedFileHandleCocoacpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit/Platform/IPC/cocoa/SharedFileHandleCocoa.cpp (287404 => 287405)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit/Platform/IPC/cocoa/SharedFileHandleCocoa.cpp 2021-12-23 17:57:29 UTC (rev 287404)
+++ trunk/Source/WebKit/Platform/IPC/cocoa/SharedFileHandleCocoa.cpp 2021-12-23 18:36:33 UTC (rev 287405)
</span><span class="lines">@@ -31,15 +31,15 @@
</span><span class="cx">
</span><span class="cx"> namespace IPC {
</span><span class="cx">
</span><del>-std::optional<SharedFileHandle> SharedFileHandle::create(FileSystem::PlatformFileHandle handle)
</del><ins>+std::optional<SharedFileHandle> SharedFileHandle::create(FileSystem::PlatformFileHandle&& handle)
</ins><span class="cx"> {
</span><del>- return SharedFileHandle { handle };
</del><ins>+ return SharedFileHandle { WTFMove(handle) };
</ins><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> void SharedFileHandle::encode(Encoder& encoder) const
</span><span class="cx"> {
</span><span class="cx"> mach_port_name_t fileport = MACH_PORT_NULL;
</span><del>- if (fileport_makeport(m_handle, &fileport) == -1) {
</del><ins>+ if (fileport_makeport(m_handle.handle(), &fileport) == -1) {
</ins><span class="cx"> encoder << MachPort();
</span><span class="cx"> return;
</span><span class="cx"> }
</span><span class="lines">@@ -57,7 +57,7 @@
</span><span class="cx"> if (fd == -1)
</span><span class="cx"> return SharedFileHandle { };
</span><span class="cx">
</span><del>- return SharedFileHandle::create(fd);
</del><ins>+ return SharedFileHandle::create(WTFMove(fd));
</ins><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> } // namespace IPC
</span></span></pre></div>
<a id="trunkSourceWebKitWebProcessWebCoreSupportWebFileSystemStorageConnectioncpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit/WebProcess/WebCoreSupport/WebFileSystemStorageConnection.cpp (287404 => 287405)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit/WebProcess/WebCoreSupport/WebFileSystemStorageConnection.cpp 2021-12-23 17:57:29 UTC (rev 287404)
+++ trunk/Source/WebKit/WebProcess/WebCoreSupport/WebFileSystemStorageConnection.cpp 2021-12-23 18:36:33 UTC (rev 287405)
</span><span class="lines">@@ -149,8 +149,7 @@
</span><span class="cx"> if (!result)
</span><span class="cx"> return completionHandler(convertToException(result.error()));
</span><span class="cx">
</span><del>- auto resultValue = result.value();
- completionHandler(std::pair { resultValue.first, resultValue.second.handle() });
</del><ins>+ completionHandler(std::pair { result.value().first, result.value().second.release() });
</ins><span class="cx"> });
</span><span class="cx"> }
</span><span class="cx">
</span></span></pre>
</div>
</div>
</body>
</html>