Title: [283676] trunk
Revision
283676
Author
[email protected]
Date
2021-10-06 15:58:42 -0700 (Wed, 06 Oct 2021)

Log Message

Add support for FileSystemSyncAccessHandle
https://bugs.webkit.org/show_bug.cgi?id=231185
<rdar://problem/83847859>

Reviewed by Youenn Fablet.

LayoutTests/imported/w3c:

* web-platform-tests/file-system-access/sandboxed_FileSystemFileHandle-sync-access-handle-lock.https.tentative.worker-expected.txt:

Source/WebCore:

Implement basic support for FileSystemSyncAccessHandle as proposal:
https://github.com/WICG/file-system-access/blob/main/AccessHandle.md

FileSystemSyncAccessHandle can be created via FileSystemFileHandle, and it commuicates with backend via
FileSystemFileHandle.

Test: storage/filesystemaccess/sync-access-handle-basics-worker.html

* CMakeLists.txt:
* DerivedSources-input.xcfilelist:
* DerivedSources-output.xcfilelist:
* DerivedSources.make:
* Headers.cmake:
* Modules/filesystemaccess/FileSystemFileHandle.cpp:
(WebCore::FileSystemFileHandle::createSyncAccessHandle):
(WebCore::FileSystemFileHandle::getSize):
(WebCore::FileSystemFileHandle::truncate):
(WebCore::FileSystemFileHandle::flush):
(WebCore::FileSystemFileHandle::close):
* Modules/filesystemaccess/FileSystemFileHandle.h:
* Modules/filesystemaccess/FileSystemFileHandle.idl:
* Modules/filesystemaccess/FileSystemStorageConnection.h:
* Modules/filesystemaccess/FileSystemSyncAccessHandle.cpp: Added.
(WebCore::FileSystemSyncAccessHandle::create):
(WebCore::FileSystemSyncAccessHandle::FileSystemSyncAccessHandle):
(WebCore::FileSystemSyncAccessHandle::~FileSystemSyncAccessHandle):
(WebCore::FileSystemSyncAccessHandle::truncate):
(WebCore::FileSystemSyncAccessHandle::getSize):
(WebCore::FileSystemSyncAccessHandle::flush):
(WebCore::FileSystemSyncAccessHandle::close):
(WebCore::FileSystemSyncAccessHandle::didClose):
* Modules/filesystemaccess/FileSystemSyncAccessHandle.h: Added.
* Modules/filesystemaccess/FileSystemSyncAccessHandle.idl: Added.
* Modules/filesystemaccess/FileSystemSyncAccessHandleIdentifier.h: Added.
* Modules/filesystemaccess/WorkerFileSystemStorageConnection.cpp:
(WebCore::WorkerFileSystemStorageConnection::scopeClosed):
(WebCore::WorkerFileSystemStorageConnection::removeEntry):
(WebCore::WorkerFileSystemStorageConnection::didCreateSyncAccessHandle):
(WebCore::WorkerFileSystemStorageConnection::completeIntegerCallback):
(WebCore::WorkerFileSystemStorageConnection::completeVoidCallback):
(WebCore::WorkerFileSystemStorageConnection::createSyncAccessHandle):
(WebCore::WorkerFileSystemStorageConnection::getSize):
(WebCore::WorkerFileSystemStorageConnection::truncate):
(WebCore::WorkerFileSystemStorageConnection::flush):
(WebCore::WorkerFileSystemStorageConnection::close):
(WebCore::WorkerFileSystemStorageConnection::didRemoveEntry): Deleted.
* Modules/filesystemaccess/WorkerFileSystemStorageConnection.h:
* Sources.txt:
* WebCore.xcodeproj/project.pbxproj:
* bindings/js/WebCoreBuiltinNames.h:

Source/WebKit:

Currently we only allow one open access handle on one file. Second access handle can be created after the first
is closed.

* NetworkProcess/storage/FileSystemStorageError.h:
(WebKit::convertToException):
(WebKit::convertToExceptionOr):
(WebKit::convertToExceptionCode): Deleted.
* NetworkProcess/storage/FileSystemStorageHandle.cpp:
(WebKit::FileSystemStorageHandle::createSyncAccessHandle):
(WebKit::FileSystemStorageHandle::getSize):
(WebKit::FileSystemStorageHandle::truncate):
(WebKit::FileSystemStorageHandle::flush):
(WebKit::FileSystemStorageHandle::close):
* NetworkProcess/storage/FileSystemStorageHandle.h:
* NetworkProcess/storage/FileSystemStorageManager.cpp:
(WebKit::FileSystemStorageManager::connectionClosed):
(WebKit::FileSystemStorageManager::acquireLockForFile):
(WebKit::FileSystemStorageManager::releaseLockForFile):
* NetworkProcess/storage/FileSystemStorageManager.h:
* NetworkProcess/storage/NetworkStorageManager.cpp:
(WebKit::NetworkStorageManager::createSyncAccessHandle):
(WebKit::NetworkStorageManager::getSizeForAccessHandle):
(WebKit::NetworkStorageManager::truncateForAccessHandle):
(WebKit::NetworkStorageManager::flushForAccessHandle):
(WebKit::NetworkStorageManager::closeAccessHandle):
* NetworkProcess/storage/NetworkStorageManager.h:
* NetworkProcess/storage/NetworkStorageManager.messages.in:
* Scripts/webkit/messages.py:
(types_that_cannot_be_forward_declared):
* WebProcess/WebCoreSupport/WebFileSystemStorageConnection.cpp:
(WebKit::WebFileSystemStorageConnection::getFileHandle):
(WebKit::WebFileSystemStorageConnection::getDirectoryHandle):
(WebKit::WebFileSystemStorageConnection::removeEntry):
(WebKit::WebFileSystemStorageConnection::resolve):
(WebKit::WebFileSystemStorageConnection::createSyncAccessHandle):
(WebKit::WebFileSystemStorageConnection::getSize):
(WebKit::WebFileSystemStorageConnection::truncate):
(WebKit::WebFileSystemStorageConnection::flush):
(WebKit::WebFileSystemStorageConnection::close):
* WebProcess/WebCoreSupport/WebFileSystemStorageConnection.h:
* WebProcess/WebCoreSupport/WebStorageConnection.cpp:
(WebKit::WebStorageConnection::fileSystemGetDirectory):

Source/WTF:

* Scripts/Preferences/WebPreferencesExperimental.yaml:
* wtf/FileSystem.h:
* wtf/glib/FileSystemGlib.cpp:
(WTF::FileSystemImpl::flushFile):
* wtf/posix/FileSystemPOSIX.cpp:
(WTF::FileSystemImpl::flushFile):
* wtf/win/FileSystemWin.cpp:
(WTF::FileSystemImpl::flushFile):

LayoutTests:

* storage/filesystemaccess/resources/sync-access-handle-basics.js: Added.
(finishTest):
(getDirectory):
* storage/filesystemaccess/sync-access-handle-basics-worker-expected.txt: Added.
* storage/filesystemaccess/sync-access-handle-basics-worker.html: Added.

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (283675 => 283676)


--- trunk/LayoutTests/ChangeLog	2021-10-06 22:41:36 UTC (rev 283675)
+++ trunk/LayoutTests/ChangeLog	2021-10-06 22:58:42 UTC (rev 283676)
@@ -1,3 +1,17 @@
+2021-10-06  Sihui Liu  <[email protected]>
+
+        Add support for FileSystemSyncAccessHandle
+        https://bugs.webkit.org/show_bug.cgi?id=231185
+        <rdar://problem/83847859>
+
+        Reviewed by Youenn Fablet.
+
+        * storage/filesystemaccess/resources/sync-access-handle-basics.js: Added.
+        (finishTest):
+        (getDirectory):
+        * storage/filesystemaccess/sync-access-handle-basics-worker-expected.txt: Added.
+        * storage/filesystemaccess/sync-access-handle-basics-worker.html: Added.
+
 2021-10-06  Wenson Hsieh  <[email protected]>
 
         Make ImageBuffer::drawingContext() return GraphicsContext instead of DisplayList::DrawingContext

Modified: trunk/LayoutTests/imported/w3c/ChangeLog (283675 => 283676)


--- trunk/LayoutTests/imported/w3c/ChangeLog	2021-10-06 22:41:36 UTC (rev 283675)
+++ trunk/LayoutTests/imported/w3c/ChangeLog	2021-10-06 22:58:42 UTC (rev 283676)
@@ -1,3 +1,13 @@
+2021-10-06  Sihui Liu  <[email protected]>
+
+        Add support for FileSystemSyncAccessHandle
+        https://bugs.webkit.org/show_bug.cgi?id=231185
+        <rdar://problem/83847859>
+
+        Reviewed by Youenn Fablet.
+
+        * web-platform-tests/file-system-access/sandboxed_FileSystemFileHandle-sync-access-handle-lock.https.tentative.worker-expected.txt:
+
 2021-10-06  Kiet Ho  <[email protected]>
 
         Import css/motion tests from WPT

Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/file-system-access/sandboxed_FileSystemFileHandle-sync-access-handle-lock.https.tentative.worker-expected.txt (283675 => 283676)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/file-system-access/sandboxed_FileSystemFileHandle-sync-access-handle-lock.https.tentative.worker-expected.txt	2021-10-06 22:41:36 UTC (rev 283675)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/file-system-access/sandboxed_FileSystemFileHandle-sync-access-handle-lock.https.tentative.worker-expected.txt	2021-10-06 22:58:42 UTC (rev 283676)
@@ -1,4 +1,4 @@
 
-FAIL There can only be one open access handle at any given time promise_test: Unhandled rejection with value: object "TypeError: fileHandle.createSyncAccessHandle is not a function. (In 'fileHandle.createSyncAccessHandle()', 'fileHandle.createSyncAccessHandle' is undefined)"
-FAIL An access handle from one file does not interfere with the creation of an access handle on another file promise_test: Unhandled rejection with value: object "TypeError: fooFileHandle.createSyncAccessHandle is not a function. (In 'fooFileHandle.createSyncAccessHandle()', 'fooFileHandle.createSyncAccessHandle' is undefined)"
+PASS There can only be one open access handle at any given time
+PASS An access handle from one file does not interfere with the creation of an access handle on another file
 

Added: trunk/LayoutTests/storage/filesystemaccess/resources/sync-access-handle-basics.js (0 => 283676)


--- trunk/LayoutTests/storage/filesystemaccess/resources/sync-access-handle-basics.js	                        (rev 0)
+++ trunk/LayoutTests/storage/filesystemaccess/resources/sync-access-handle-basics.js	2021-10-06 22:58:42 UTC (rev 283676)
@@ -0,0 +1,81 @@
+if (this.importScripts) {
+    importScripts('../../../resources/js-test.js');
+}
+
+description("This test checks basic funtionalities of FileSystemSyncAccessHandle.");
+
+var rootHandle, fileHandle, accessHandle1, accessHandle2, createError;
+
+function finishTest(error)
+{
+    if (error) {
+        testFailed(error);
+    }
+    finishJSTest();
+}
+
+function getDirectory() {
+    navigator.storage.getDirectory().then((handle) => {
+        rootHandle = handle;
+        createFileHandle(rootHandle);
+    }).catch((error) => {
+        finishTest(error);
+    });
+}
+
+function createFileHandle(fromHandle) {
+    fromHandle.getFileHandle("sync-access-handle.txt", { "create" : true }).then((handle) => {
+        fileHandle = handle;
+        shouldBeEqualToString("fileHandle.name", "sync-access-handle.txt");
+        shouldBeEqualToString("fileHandle.kind", "file");
+        createSyncAccessHandle(fileHandle);
+    }).catch((error) => {
+        finishTest(error);
+    });
+}
+
+function createSyncAccessHandle(fromHandle) {
+    fromHandle.createSyncAccessHandle().then((handle) => {
+        accessHandle1 = handle;
+        debug("accessHandle1 is created");
+        getSize(accessHandle1);
+    }).catch((error) => {
+        finishTest(error);
+    });
+}
+
+function getSize(accessHandle) {
+    accessHandle.getSize().then((result) => {
+        size = result;
+        shouldBe("size", "0");
+        createSecondSyncAcessHandle(fileHandle);
+    }).catch((error) => {
+        finishTest(error);
+    });
+}
+
+function createSecondSyncAcessHandle(fromHandle) {
+    fromHandle.createSyncAccessHandle().then((handle) => {
+        accessHandle2 = handle;
+        // Second creation should succeed.
+        debug("accessHandle2 is created");
+        finishTest();
+    }).catch((error) => {
+        // First creation should fail as there is an active handle.
+        createError = error;
+        debug("accessHandle2 cannot be created");
+        shouldBeEqualToString("createError.toString()", "InvalidStateError: The object is in an invalid state.");
+        close();
+    });
+}
+
+function close() {
+    accessHandle1.close().then((result) => {
+        debug("accessHandle1 is closed");
+        createSecondSyncAcessHandle(fileHandle);
+    }).catch((error) => {
+        finishTest(error);
+    });
+}
+
+getDirectory();

Added: trunk/LayoutTests/storage/filesystemaccess/sync-access-handle-basics-worker-expected.txt (0 => 283676)


--- trunk/LayoutTests/storage/filesystemaccess/sync-access-handle-basics-worker-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/storage/filesystemaccess/sync-access-handle-basics-worker-expected.txt	2021-10-06 22:58:42 UTC (rev 283676)
@@ -0,0 +1,18 @@
+[Worker] This test checks basic funtionalities of FileSystemSyncAccessHandle.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+Starting worker: resources/sync-access-handle-basics.js
+PASS [Worker] fileHandle.name is "sync-access-handle.txt"
+PASS [Worker] fileHandle.kind is "file"
+[Worker] accessHandle1 is created
+PASS [Worker] size is 0
+[Worker] accessHandle2 cannot be created
+PASS [Worker] createError.toString() is "InvalidStateError: The object is in an invalid state."
+[Worker] accessHandle1 is closed
+[Worker] accessHandle2 is created
+PASS successfullyParsed is true
+
+TEST COMPLETE
+

Added: trunk/LayoutTests/storage/filesystemaccess/sync-access-handle-basics-worker.html (0 => 283676)


--- trunk/LayoutTests/storage/filesystemaccess/sync-access-handle-basics-worker.html	                        (rev 0)
+++ trunk/LayoutTests/storage/filesystemaccess/sync-access-handle-basics-worker.html	2021-10-06 22:58:42 UTC (rev 283676)
@@ -0,0 +1,9 @@
+<html>
+<head>
+<script src=""
+</head>
+<body>
+<script>
+worker = startWorker('resources/sync-access-handle-basics.js');</script>
+</body>
+</html>
\ No newline at end of file

Modified: trunk/Source/WTF/ChangeLog (283675 => 283676)


--- trunk/Source/WTF/ChangeLog	2021-10-06 22:41:36 UTC (rev 283675)
+++ trunk/Source/WTF/ChangeLog	2021-10-06 22:58:42 UTC (rev 283676)
@@ -1,3 +1,20 @@
+2021-10-06  Sihui Liu  <[email protected]>
+
+        Add support for FileSystemSyncAccessHandle
+        https://bugs.webkit.org/show_bug.cgi?id=231185
+        <rdar://problem/83847859>
+
+        Reviewed by Youenn Fablet.
+
+        * Scripts/Preferences/WebPreferencesExperimental.yaml:
+        * wtf/FileSystem.h:
+        * wtf/glib/FileSystemGlib.cpp:
+        (WTF::FileSystemImpl::flushFile):
+        * wtf/posix/FileSystemPOSIX.cpp:
+        (WTF::FileSystemImpl::flushFile):
+        * wtf/win/FileSystemWin.cpp:
+        (WTF::FileSystemImpl::flushFile):
+
 2021-10-06  Aditya Keerthi  <[email protected]>
 
         Fix watchOS, tvOS, and macCatalyst builds after r283592

Modified: trunk/Source/WTF/Scripts/Preferences/WebPreferencesExperimental.yaml (283675 => 283676)


--- trunk/Source/WTF/Scripts/Preferences/WebPreferencesExperimental.yaml	2021-10-06 22:41:36 UTC (rev 283675)
+++ trunk/Source/WTF/Scripts/Preferences/WebPreferencesExperimental.yaml	2021-10-06 22:58:42 UTC (rev 283676)
@@ -26,6 +26,18 @@
 # They must include a humanReadableName and humanReadableDescription. This is
 #   the text exposed to the user from the WebKit client.
 
+AccessHandleEnabled:
+  type: bool
+  humanReadableName: "AccessHandle API"
+  humanReadableDescription: "Enable AccessHandle API"
+  defaultValue:
+    WebKitLegacy:
+      default: false
+    WebKit:
+      default: false
+    WebCore:
+      default: false
+
 AccessibilityObjectModelEnabled:
   type: bool
   humanReadableName: "Accessibility Object Model"

Modified: trunk/Source/WTF/wtf/FileSystem.h (283675 => 283676)


--- trunk/Source/WTF/wtf/FileSystem.h	2021-10-06 22:41:36 UTC (rev 283675)
+++ trunk/Source/WTF/wtf/FileSystem.h	2021-10-06 22:58:42 UTC (rev 283676)
@@ -154,6 +154,7 @@
 // Returns the resulting offset from the beginning of the file if successful, -1 otherwise.
 WTF_EXPORT_PRIVATE long long seekFile(PlatformFileHandle, long long offset, FileSeekOrigin);
 WTF_EXPORT_PRIVATE bool truncateFile(PlatformFileHandle, long long offset);
+WTF_EXPORT_PRIVATE bool flushFile(PlatformFileHandle);
 // Returns number of bytes actually read if successful, -1 otherwise.
 WTF_EXPORT_PRIVATE int writeToFile(PlatformFileHandle, const void* data, int length);
 // Returns number of bytes actually written if successful, -1 otherwise.

Modified: trunk/Source/WTF/wtf/glib/FileSystemGlib.cpp (283675 => 283676)


--- trunk/Source/WTF/wtf/glib/FileSystemGlib.cpp	2021-10-06 22:41:36 UTC (rev 283675)
+++ trunk/Source/WTF/wtf/glib/FileSystemGlib.cpp	2021-10-06 22:58:42 UTC (rev 283676)
@@ -213,6 +213,11 @@
     return g_seekable_truncate(G_SEEKABLE(g_io_stream_get_output_stream(G_IO_STREAM(handle))), offset, nullptr, nullptr);
 }
 
+bool flushFile(PlatformFileHandle handle)
+{
+    return g_output_stream_flush(g_io_stream_get_output_stream(G_IO_STREAM(handle)), nullptr, nullptr);
+}
+
 int writeToFile(PlatformFileHandle handle, const void* data, int length)
 {
     if (!length)

Modified: trunk/Source/WTF/wtf/posix/FileSystemPOSIX.cpp (283675 => 283676)


--- trunk/Source/WTF/wtf/posix/FileSystemPOSIX.cpp	2021-10-06 22:41:36 UTC (rev 283675)
+++ trunk/Source/WTF/wtf/posix/FileSystemPOSIX.cpp	2021-10-06 22:58:42 UTC (rev 283676)
@@ -118,6 +118,11 @@
     return !ftruncate(handle, offset);
 }
 
+bool flushFile(PlatformFileHandle handle)
+{
+    return !fsync(handle);
+}
+
 int writeToFile(PlatformFileHandle handle, const void* data, int length)
 {
     do {

Modified: trunk/Source/WTF/wtf/win/FileSystemWin.cpp (283675 => 283676)


--- trunk/Source/WTF/wtf/win/FileSystemWin.cpp	2021-10-06 22:41:36 UTC (rev 283675)
+++ trunk/Source/WTF/wtf/win/FileSystemWin.cpp	2021-10-06 22:58:42 UTC (rev 283676)
@@ -303,6 +303,12 @@
     return SetFileInformationByHandle(handle, FileEndOfFileInfo, &eofInfo, sizeof(FILE_END_OF_FILE_INFO));
 }
 
+bool flushFile(PlatformFileHandle handle)
+{
+    // Not implemented.
+    return false;
+}
+
 int writeToFile(PlatformFileHandle handle, const void* data, int length)
 {
     if (!isHandleValid(handle))

Modified: trunk/Source/WebCore/CMakeLists.txt (283675 => 283676)


--- trunk/Source/WebCore/CMakeLists.txt	2021-10-06 22:41:36 UTC (rev 283675)
+++ trunk/Source/WebCore/CMakeLists.txt	2021-10-06 22:58:42 UTC (rev 283676)
@@ -297,6 +297,7 @@
     Modules/filesystemaccess/FileSystemDirectoryHandle.idl
     Modules/filesystemaccess/FileSystemFileHandle.idl
     Modules/filesystemaccess/FileSystemHandle.idl
+    Modules/filesystemaccess/FileSystemSyncAccessHandle.idl
     Modules/filesystemaccess/StorageManager+FileSystemAccess.idl
 
     Modules/geolocation/Geolocation.idl

Modified: trunk/Source/WebCore/ChangeLog (283675 => 283676)


--- trunk/Source/WebCore/ChangeLog	2021-10-06 22:41:36 UTC (rev 283675)
+++ trunk/Source/WebCore/ChangeLog	2021-10-06 22:58:42 UTC (rev 283676)
@@ -1,3 +1,62 @@
+2021-10-06  Sihui Liu  <[email protected]>
+
+        Add support for FileSystemSyncAccessHandle
+        https://bugs.webkit.org/show_bug.cgi?id=231185
+        <rdar://problem/83847859>
+
+        Reviewed by Youenn Fablet.
+
+        Implement basic support for FileSystemSyncAccessHandle as proposal:
+        https://github.com/WICG/file-system-access/blob/main/AccessHandle.md
+
+        FileSystemSyncAccessHandle can be created via FileSystemFileHandle, and it commuicates with backend via 
+        FileSystemFileHandle.
+
+        Test: storage/filesystemaccess/sync-access-handle-basics-worker.html
+
+        * CMakeLists.txt:
+        * DerivedSources-input.xcfilelist:
+        * DerivedSources-output.xcfilelist:
+        * DerivedSources.make:
+        * Headers.cmake:
+        * Modules/filesystemaccess/FileSystemFileHandle.cpp:
+        (WebCore::FileSystemFileHandle::createSyncAccessHandle):
+        (WebCore::FileSystemFileHandle::getSize):
+        (WebCore::FileSystemFileHandle::truncate):
+        (WebCore::FileSystemFileHandle::flush):
+        (WebCore::FileSystemFileHandle::close):
+        * Modules/filesystemaccess/FileSystemFileHandle.h:
+        * Modules/filesystemaccess/FileSystemFileHandle.idl:
+        * Modules/filesystemaccess/FileSystemStorageConnection.h:
+        * Modules/filesystemaccess/FileSystemSyncAccessHandle.cpp: Added.
+        (WebCore::FileSystemSyncAccessHandle::create):
+        (WebCore::FileSystemSyncAccessHandle::FileSystemSyncAccessHandle):
+        (WebCore::FileSystemSyncAccessHandle::~FileSystemSyncAccessHandle):
+        (WebCore::FileSystemSyncAccessHandle::truncate):
+        (WebCore::FileSystemSyncAccessHandle::getSize):
+        (WebCore::FileSystemSyncAccessHandle::flush):
+        (WebCore::FileSystemSyncAccessHandle::close):
+        (WebCore::FileSystemSyncAccessHandle::didClose):
+        * Modules/filesystemaccess/FileSystemSyncAccessHandle.h: Added.
+        * Modules/filesystemaccess/FileSystemSyncAccessHandle.idl: Added.
+        * Modules/filesystemaccess/FileSystemSyncAccessHandleIdentifier.h: Added.
+        * Modules/filesystemaccess/WorkerFileSystemStorageConnection.cpp:
+        (WebCore::WorkerFileSystemStorageConnection::scopeClosed):
+        (WebCore::WorkerFileSystemStorageConnection::removeEntry):
+        (WebCore::WorkerFileSystemStorageConnection::didCreateSyncAccessHandle):
+        (WebCore::WorkerFileSystemStorageConnection::completeIntegerCallback):
+        (WebCore::WorkerFileSystemStorageConnection::completeVoidCallback):
+        (WebCore::WorkerFileSystemStorageConnection::createSyncAccessHandle):
+        (WebCore::WorkerFileSystemStorageConnection::getSize):
+        (WebCore::WorkerFileSystemStorageConnection::truncate):
+        (WebCore::WorkerFileSystemStorageConnection::flush):
+        (WebCore::WorkerFileSystemStorageConnection::close):
+        (WebCore::WorkerFileSystemStorageConnection::didRemoveEntry): Deleted.
+        * Modules/filesystemaccess/WorkerFileSystemStorageConnection.h:
+        * Sources.txt:
+        * WebCore.xcodeproj/project.pbxproj:
+        * bindings/js/WebCoreBuiltinNames.h:
+
 2021-10-06  Wenson Hsieh  <[email protected]>
 
         Make ImageBuffer::drawingContext() return GraphicsContext instead of DisplayList::DrawingContext

Modified: trunk/Source/WebCore/DerivedSources-input.xcfilelist (283675 => 283676)


--- trunk/Source/WebCore/DerivedSources-input.xcfilelist	2021-10-06 22:41:36 UTC (rev 283675)
+++ trunk/Source/WebCore/DerivedSources-input.xcfilelist	2021-10-06 22:58:42 UTC (rev 283676)
@@ -126,6 +126,7 @@
 $(PROJECT_DIR)/Modules/filesystemaccess/FileSystemDirectoryHandle.idl
 $(PROJECT_DIR)/Modules/filesystemaccess/FileSystemFileHandle.idl
 $(PROJECT_DIR)/Modules/filesystemaccess/FileSystemHandle.idl
+$(PROJECT_DIR)/Modules/filesystemaccess/FileSystemSyncAccessHandle.idl
 $(PROJECT_DIR)/Modules/filesystemaccess/StorageManager+FileSystemAccess.idl
 $(PROJECT_DIR)/Modules/gamepad/Gamepad.idl
 $(PROJECT_DIR)/Modules/gamepad/GamepadButton.idl

Modified: trunk/Source/WebCore/DerivedSources-output.xcfilelist (283675 => 283676)


--- trunk/Source/WebCore/DerivedSources-output.xcfilelist	2021-10-06 22:41:36 UTC (rev 283675)
+++ trunk/Source/WebCore/DerivedSources-output.xcfilelist	2021-10-06 22:58:42 UTC (rev 283676)
@@ -907,6 +907,8 @@
 $(BUILT_PRODUCTS_DIR)/DerivedSources/WebCore/JSFileSystemFileHandle.h
 $(BUILT_PRODUCTS_DIR)/DerivedSources/WebCore/JSFileSystemHandle.cpp
 $(BUILT_PRODUCTS_DIR)/DerivedSources/WebCore/JSFileSystemHandle.h
+$(BUILT_PRODUCTS_DIR)/DerivedSources/WebCore/JSFileSystemSyncAccessHandle.cpp
+$(BUILT_PRODUCTS_DIR)/DerivedSources/WebCore/JSFileSystemSyncAccessHandle.h
 $(BUILT_PRODUCTS_DIR)/DerivedSources/WebCore/JSFillMode.cpp
 $(BUILT_PRODUCTS_DIR)/DerivedSources/WebCore/JSFillMode.h
 $(BUILT_PRODUCTS_DIR)/DerivedSources/WebCore/JSFocusEvent.cpp

Modified: trunk/Source/WebCore/DerivedSources.make (283675 => 283676)


--- trunk/Source/WebCore/DerivedSources.make	2021-10-06 22:41:36 UTC (rev 283675)
+++ trunk/Source/WebCore/DerivedSources.make	2021-10-06 22:58:42 UTC (rev 283676)
@@ -155,6 +155,7 @@
     $(WebCore)/Modules/filesystemaccess/FileSystemDirectoryHandle.idl \
     $(WebCore)/Modules/filesystemaccess/FileSystemFileHandle.idl \
     $(WebCore)/Modules/filesystemaccess/FileSystemHandle.idl \
+	$(WebCore)/Modules/filesystemaccess/FileSystemSyncAccessHandle.idl \
     $(WebCore)/Modules/filesystemaccess/StorageManager+FileSystemAccess.idl \
     $(WebCore)/Modules/gamepad/Gamepad.idl \
     $(WebCore)/Modules/gamepad/GamepadButton.idl \

Modified: trunk/Source/WebCore/Headers.cmake (283675 => 283676)


--- trunk/Source/WebCore/Headers.cmake	2021-10-06 22:41:36 UTC (rev 283675)
+++ trunk/Source/WebCore/Headers.cmake	2021-10-06 22:58:42 UTC (rev 283676)
@@ -42,6 +42,8 @@
     Modules/filesystemaccess/FileSystemHandle.h
     Modules/filesystemaccess/FileSystemHandleIdentifier.h
     Modules/filesystemaccess/FileSystemStorageConnection.h
+    Modules/filesystemaccess/FileSystemSyncAccessHandle.h
+    Modules/filesystemaccess/FileSystemSyncAccessHandleIdentifier.h
     Modules/filesystemaccess/StorageManagerFileSystemAccess.h
     Modules/filesystemaccess/WorkerFileSystemStorageConnection.h
     Modules/filesystemaccess/WorkerFileSystemStorageConnectionCallbackIdentifier.h

Modified: trunk/Source/WebCore/Modules/filesystemaccess/FileSystemFileHandle.cpp (283675 => 283676)


--- trunk/Source/WebCore/Modules/filesystemaccess/FileSystemFileHandle.cpp	2021-10-06 22:41:36 UTC (rev 283675)
+++ trunk/Source/WebCore/Modules/filesystemaccess/FileSystemFileHandle.cpp	2021-10-06 22:58:42 UTC (rev 283676)
@@ -27,7 +27,9 @@
 #include "FileSystemFileHandle.h"
 
 #include "FileSystemStorageConnection.h"
+#include "FileSystemSyncAccessHandle.h"
 #include "JSDOMPromiseDeferred.h"
+#include "JSFileSystemSyncAccessHandle.h"
 #include <wtf/IsoMallocInlines.h>
 
 namespace WebCore {
@@ -49,5 +51,41 @@
     promise.reject(Exception { NotSupportedError, "Not implemented"_s });
 }
 
+void FileSystemFileHandle::createSyncAccessHandle(DOMPromiseDeferred<IDLInterface<FileSystemSyncAccessHandle>>&& promise)
+{
+    connection().createSyncAccessHandle(identifier(), [protectedThis = Ref { *this }, promise = WTFMove(promise)](auto result) mutable {
+        if (result.hasException())
+            return promise.reject(result.releaseException());
+
+        promise.settle(FileSystemSyncAccessHandle::create(protectedThis.get(), result.returnValue()));
+    });
+}
+
+void FileSystemFileHandle::getSize(FileSystemSyncAccessHandleIdentifier accessHandleIdentifier, DOMPromiseDeferred<IDLUnsignedLongLong>&& promise)
+{
+    connection().getSize(identifier(), accessHandleIdentifier, [promise = WTFMove(promise)](auto result) mutable {
+        promise.settle(WTFMove(result));
+    });
+}
+
+void FileSystemFileHandle::truncate(FileSystemSyncAccessHandleIdentifier accessHandleIdentifier, unsigned long long size, DOMPromiseDeferred<void>&& promise)
+{
+    connection().truncate(identifier(), accessHandleIdentifier, size, [promise = WTFMove(promise)](auto result) mutable {
+        promise.settle(WTFMove(result));
+    });
+}
+
+void FileSystemFileHandle::flush(FileSystemSyncAccessHandleIdentifier accessHandleIdentifier, DOMPromiseDeferred<void>&& promise)
+{
+    connection().flush(identifier(), accessHandleIdentifier, [promise = WTFMove(promise)](auto result) mutable {
+        promise.settle(WTFMove(result));
+    });
+}
+
+void FileSystemFileHandle::close(FileSystemSyncAccessHandleIdentifier accessHandleIdentifier, CompletionHandler<void(ExceptionOr<void>&&)>&& completionHandler)
+{
+    connection().close(identifier(), accessHandleIdentifier, WTFMove(completionHandler));
+}
+
 } // namespace WebCore
 

Modified: trunk/Source/WebCore/Modules/filesystemaccess/FileSystemFileHandle.h (283675 => 283676)


--- trunk/Source/WebCore/Modules/filesystemaccess/FileSystemFileHandle.h	2021-10-06 22:41:36 UTC (rev 283675)
+++ trunk/Source/WebCore/Modules/filesystemaccess/FileSystemFileHandle.h	2021-10-06 22:58:42 UTC (rev 283676)
@@ -26,10 +26,13 @@
 #pragma once
 
 #include "FileSystemHandle.h"
+#include "FileSystemSyncAccessHandleIdentifier.h"
 
 namespace WebCore {
 
 class File;
+class FileSystemSyncAccessHandle;
+template<typename> class ExceptionOr;
 
 class FileSystemFileHandle final : public FileSystemHandle {
     WTF_MAKE_ISO_ALLOCATED(FileSystemFileHandle);
@@ -37,6 +40,12 @@
     WEBCORE_EXPORT static Ref<FileSystemFileHandle> create(String&&, FileSystemHandleIdentifier, Ref<FileSystemStorageConnection>&&);
     void getFile(DOMPromiseDeferred<IDLInterface<File>>&&);
 
+    void createSyncAccessHandle(DOMPromiseDeferred<IDLInterface<FileSystemSyncAccessHandle>>&&);
+    void getSize(FileSystemSyncAccessHandleIdentifier, DOMPromiseDeferred<IDLUnsignedLongLong>&&);
+    void truncate(FileSystemSyncAccessHandleIdentifier, unsigned long long size, DOMPromiseDeferred<void>&&);
+    void flush(FileSystemSyncAccessHandleIdentifier, DOMPromiseDeferred<void>&&);
+    void close(FileSystemSyncAccessHandleIdentifier, CompletionHandler<void(ExceptionOr<void>&&)>&&);
+
 private:
     FileSystemFileHandle(String&&, FileSystemHandleIdentifier, Ref<FileSystemStorageConnection>&&);
 };

Modified: trunk/Source/WebCore/Modules/filesystemaccess/FileSystemFileHandle.idl (283675 => 283676)


--- trunk/Source/WebCore/Modules/filesystemaccess/FileSystemFileHandle.idl	2021-10-06 22:41:36 UTC (rev 283675)
+++ trunk/Source/WebCore/Modules/filesystemaccess/FileSystemFileHandle.idl	2021-10-06 22:58:42 UTC (rev 283676)
@@ -23,6 +23,8 @@
  * THE POSSIBILITY OF SUCH DAMAGE.
  */
 
+// https://wicg.github.io/file-system-access/#api-filesystemhandle
+
 [
     EnabledBySetting=FileSystemAccessEnabled,
     Exposed=(Window,Worker),
@@ -29,5 +31,5 @@
     SecureContext
 ] interface FileSystemFileHandle : FileSystemHandle {
     Promise<File> getFile();
-    // FIXME: add Promise<FileSystemWritableFileStream> createWritable(optional FileSystemCreateWritableOptions options);
+    [EnabledBySetting=AccessHandleEnabled, Exposed=Worker] Promise<FileSystemSyncAccessHandle> createSyncAccessHandle();
 };

Modified: trunk/Source/WebCore/Modules/filesystemaccess/FileSystemStorageConnection.h (283675 => 283676)


--- trunk/Source/WebCore/Modules/filesystemaccess/FileSystemStorageConnection.h	2021-10-06 22:41:36 UTC (rev 283675)
+++ trunk/Source/WebCore/Modules/filesystemaccess/FileSystemStorageConnection.h	2021-10-06 22:58:42 UTC (rev 283676)
@@ -26,6 +26,7 @@
 #pragma once
 
 #include "FileSystemHandleIdentifier.h"
+#include "FileSystemSyncAccessHandleIdentifier.h"
 #include <wtf/CompletionHandler.h>
 #include <wtf/ThreadSafeRefCounted.h>
 
@@ -38,15 +39,24 @@
 class FileSystemStorageConnection : public ThreadSafeRefCounted<FileSystemStorageConnection> {
 public:
     virtual ~FileSystemStorageConnection() { }
+
     using SameEntryCallback = CompletionHandler<void(ExceptionOr<bool>&&)>;
     using GetHandleCallback = CompletionHandler<void(ExceptionOr<FileSystemHandleIdentifier>&&)>;
-    using RemoveEntryCallback = CompletionHandler<void(ExceptionOr<void>&&)>;
     using ResolveCallback = CompletionHandler<void(ExceptionOr<Vector<String>>&&)>;
+    using GetAccessHandleCallback = CompletionHandler<void(ExceptionOr<FileSystemSyncAccessHandleIdentifier>&&)>;
+    using VoidCallback = CompletionHandler<void(ExceptionOr<void>&&)>;
+    using IntegerCallback = CompletionHandler<void(ExceptionOr<uint64_t>&&)>;
+
     virtual void isSameEntry(FileSystemHandleIdentifier, FileSystemHandleIdentifier, SameEntryCallback&&) = 0;
     virtual void getFileHandle(FileSystemHandleIdentifier, const String& name, bool createIfNecessary, GetHandleCallback&&) = 0;
     virtual void getDirectoryHandle(FileSystemHandleIdentifier, const String& name, bool createIfNecessary, GetHandleCallback&&) = 0;
-    virtual void removeEntry(FileSystemHandleIdentifier, const String& name, bool deleteRecursively, RemoveEntryCallback&&) = 0;
+    virtual void removeEntry(FileSystemHandleIdentifier, const String& name, bool deleteRecursively, VoidCallback&&) = 0;
     virtual void resolve(FileSystemHandleIdentifier, FileSystemHandleIdentifier, ResolveCallback&&) = 0;
+    virtual void createSyncAccessHandle(FileSystemHandleIdentifier, GetAccessHandleCallback&&) = 0;
+    virtual void getSize(FileSystemHandleIdentifier, FileSystemSyncAccessHandleIdentifier, IntegerCallback&&) = 0;
+    virtual void truncate(FileSystemHandleIdentifier, FileSystemSyncAccessHandleIdentifier, uint64_t size, VoidCallback&&) = 0;
+    virtual void flush(FileSystemHandleIdentifier, FileSystemSyncAccessHandleIdentifier, VoidCallback&&) = 0;
+    virtual void close(FileSystemHandleIdentifier, FileSystemSyncAccessHandleIdentifier, VoidCallback&&) = 0;
 };
 
 } // namespace WebCore

Added: trunk/Source/WebCore/Modules/filesystemaccess/FileSystemSyncAccessHandle.cpp (0 => 283676)


--- trunk/Source/WebCore/Modules/filesystemaccess/FileSystemSyncAccessHandle.cpp	                        (rev 0)
+++ trunk/Source/WebCore/Modules/filesystemaccess/FileSystemSyncAccessHandle.cpp	2021-10-06 22:58:42 UTC (rev 283676)
@@ -0,0 +1,87 @@
+/*
+ * Copyright (C) 2021 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "FileSystemSyncAccessHandle.h"
+
+#include "BufferSource.h"
+#include "ExceptionOr.h"
+#include "FileSystemFileHandle.h"
+#include "JSDOMPromiseDeferred.h"
+#include <wtf/CompletionHandler.h>
+
+namespace WebCore {
+
+Ref<FileSystemSyncAccessHandle> FileSystemSyncAccessHandle::create(FileSystemFileHandle& source, FileSystemSyncAccessHandleIdentifier identifier)
+{
+    return adoptRef(*new FileSystemSyncAccessHandle(source, identifier));
+}
+
+FileSystemSyncAccessHandle::FileSystemSyncAccessHandle(FileSystemFileHandle& source, FileSystemSyncAccessHandleIdentifier identifier)
+    : m_source(source)
+    , m_identifier(identifier)
+{
+}
+
+FileSystemSyncAccessHandle::~FileSystemSyncAccessHandle()
+{
+    if (!m_isClosed)
+        m_source->close(m_identifier, [](auto) { });
+}
+
+void FileSystemSyncAccessHandle::truncate(unsigned long long size, DOMPromiseDeferred<void>&& promise)
+{
+    m_source->truncate(m_identifier, size, WTFMove(promise));
+}
+
+void FileSystemSyncAccessHandle::getSize(DOMPromiseDeferred<IDLUnsignedLongLong>&& promise)
+{
+    m_source->getSize(m_identifier, WTFMove(promise));
+}
+
+void FileSystemSyncAccessHandle::flush(DOMPromiseDeferred<void>&& promise)
+{
+    m_source->flush(m_identifier, WTFMove(promise));
+}
+
+void FileSystemSyncAccessHandle::close(DOMPromiseDeferred<void>&& promise)
+{
+    if (m_isClosed)
+        return promise.reject(Exception { InvalidStateError });
+
+    m_source->close(m_identifier, [weakThis = makeWeakPtr(*this), promise = WTFMove(promise)](auto result) mutable {
+        if (weakThis)
+            weakThis->didClose();
+
+        promise.settle(WTFMove(result));
+    });
+}
+
+void FileSystemSyncAccessHandle::didClose()
+{
+    m_isClosed = true;
+}
+
+} // namespace WebCore

Copied: trunk/Source/WebCore/Modules/filesystemaccess/FileSystemSyncAccessHandle.h (from rev 283675, trunk/Source/WebCore/Modules/filesystemaccess/FileSystemFileHandle.h) (0 => 283676)


--- trunk/Source/WebCore/Modules/filesystemaccess/FileSystemSyncAccessHandle.h	                        (rev 0)
+++ trunk/Source/WebCore/Modules/filesystemaccess/FileSystemSyncAccessHandle.h	2021-10-06 22:58:42 UTC (rev 283676)
@@ -0,0 +1,60 @@
+/*
+ * Copyright (C) 2021 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#pragma once
+
+#include "FileSystemSyncAccessHandleIdentifier.h"
+#include "IDLTypes.h"
+#include <wtf/WeakPtr.h>
+
+namespace WebCore {
+
+class FileSystemFileHandle;
+template<typename> class DOMPromiseDeferred;
+
+class FileSystemSyncAccessHandle : public RefCounted<FileSystemSyncAccessHandle>, public CanMakeWeakPtr<FileSystemSyncAccessHandle> {
+public:
+    struct FilesystemReadWriteOptions {
+        unsigned long long at;
+    };
+
+    static Ref<FileSystemSyncAccessHandle> create(FileSystemFileHandle&, FileSystemSyncAccessHandleIdentifier);
+    ~FileSystemSyncAccessHandle();
+
+    void truncate(unsigned long long size, DOMPromiseDeferred<void>&&);
+    void getSize(DOMPromiseDeferred<IDLUnsignedLongLong>&&);
+    void flush(DOMPromiseDeferred<void>&&);
+    void close(DOMPromiseDeferred<void>&&);
+    void didClose();
+
+private:
+    FileSystemSyncAccessHandle(FileSystemFileHandle&, FileSystemSyncAccessHandleIdentifier);
+
+    Ref<FileSystemFileHandle> m_source;
+    FileSystemSyncAccessHandleIdentifier m_identifier;
+    bool m_isClosed { false };
+};
+
+} // namespace WebCore

Copied: trunk/Source/WebCore/Modules/filesystemaccess/FileSystemSyncAccessHandle.idl (from rev 283675, trunk/Source/WebCore/Modules/filesystemaccess/FileSystemFileHandle.idl) (0 => 283676)


--- trunk/Source/WebCore/Modules/filesystemaccess/FileSystemSyncAccessHandle.idl	                        (rev 0)
+++ trunk/Source/WebCore/Modules/filesystemaccess/FileSystemSyncAccessHandle.idl	2021-10-06 22:58:42 UTC (rev 283676)
@@ -0,0 +1,40 @@
+/*
+ * Copyright (C) 2021 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+[
+    EnabledBySetting=AccessHandleEnabled,
+    ImplementationLacksVTable,
+    Exposed=DedicatedWorker,
+    SecureContext
+] interface FileSystemSyncAccessHandle {
+    Promise<undefined> truncate([EnforceRange] unsigned long long size);
+    Promise<unsigned long long> getSize();
+    Promise<undefined> flush();
+    Promise<undefined> close();
+};
+
+dictionary FilesystemReadWriteOptions {
+    [EnforceRange] unsigned long long at;
+};

Copied: trunk/Source/WebCore/Modules/filesystemaccess/FileSystemSyncAccessHandleIdentifier.h (from rev 283675, trunk/Source/WebCore/Modules/filesystemaccess/FileSystemFileHandle.idl) (0 => 283676)


--- trunk/Source/WebCore/Modules/filesystemaccess/FileSystemSyncAccessHandleIdentifier.h	                        (rev 0)
+++ trunk/Source/WebCore/Modules/filesystemaccess/FileSystemSyncAccessHandleIdentifier.h	2021-10-06 22:58:42 UTC (rev 283676)
@@ -0,0 +1,36 @@
+/*
+ * Copyright (C) 2021 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#pragma once
+
+#include <wtf/ObjectIdentifier.h>
+
+namespace WebCore {
+
+enum FileSystemSyncAccessHandleIdentifierType { };
+using FileSystemSyncAccessHandleIdentifier = ObjectIdentifier<FileSystemSyncAccessHandleIdentifierType>;
+
+} // namespace WebCore
+

Modified: trunk/Source/WebCore/Modules/filesystemaccess/WorkerFileSystemStorageConnection.cpp (283675 => 283676)


--- trunk/Source/WebCore/Modules/filesystemaccess/WorkerFileSystemStorageConnection.cpp	2021-10-06 22:41:36 UTC (rev 283675)
+++ trunk/Source/WebCore/Modules/filesystemaccess/WorkerFileSystemStorageConnection.cpp	2021-10-06 22:58:42 UTC (rev 283676)
@@ -64,7 +64,7 @@
     for (auto& callback : getHandleCallbacks.values())
         callback(Exception { InvalidStateError });
 
-    auto removeEntryCallbacks = std::exchange(m_removeEntryCallbacks, { });
+    auto removeEntryCallbacks = std::exchange(m_voidCallbacks, { });
     for (auto& callback : removeEntryCallbacks.values())
         callback(Exception { InvalidStateError });
 
@@ -147,19 +147,19 @@
         callback(WTFMove(result));
 }
 
-void WorkerFileSystemStorageConnection::removeEntry(FileSystemHandleIdentifier identifier, const String& name, bool deleteRecursively, FileSystemStorageConnection::RemoveEntryCallback&& callback)
+void WorkerFileSystemStorageConnection::removeEntry(FileSystemHandleIdentifier identifier, const String& name, bool deleteRecursively, FileSystemStorageConnection::VoidCallback&& callback)
 {
     if (!m_scope)
         return callback(Exception { InvalidStateError });
 
     auto callbackIdentifier = CallbackIdentifier::generateThreadSafe();
-    m_removeEntryCallbacks.add(callbackIdentifier, WTFMove(callback));
+    m_voidCallbacks.add(callbackIdentifier, WTFMove(callback));
 
     callOnMainThread([callbackIdentifier, workerThread = Ref { m_scope->thread() }, mainThreadConnection = m_mainThreadConnection, identifier, name = name.isolatedCopy(), deleteRecursively]() mutable {
         auto mainThreadCallback = [callbackIdentifier, workerThread = WTFMove(workerThread)](auto result) mutable {
             workerThread->runLoop().postTaskForMode([callbackIdentifier, result = crossThreadCopy(result)] (auto& scope) mutable {
                 if (auto connection = downcast<WorkerGlobalScope>(scope).fileSystemStorageConnection())
-                    connection->didRemoveEntry(callbackIdentifier, WTFMove(result));
+                    connection->completeVoidCallback(callbackIdentifier, WTFMove(result));
             }, WorkerRunLoop::defaultMode());
         };
 
@@ -167,12 +167,6 @@
     });
 }
 
-void WorkerFileSystemStorageConnection::didRemoveEntry(CallbackIdentifier callbackIdentifier, ExceptionOr<void>&& result)
-{
-    if (auto callback = m_removeEntryCallbacks.take(callbackIdentifier))
-        callback(WTFMove(result));
-}
-
 void WorkerFileSystemStorageConnection::resolve(FileSystemHandleIdentifier identifier, FileSystemHandleIdentifier otherIdentifier, FileSystemStorageConnection::ResolveCallback&& callback)
 {
     if (!m_scope)
@@ -199,4 +193,122 @@
         callback(WTFMove(result));
 }
 
+void WorkerFileSystemStorageConnection::didCreateSyncAccessHandle(CallbackIdentifier callbackIdentifier, ExceptionOr<FileSystemSyncAccessHandleIdentifier>&& result)
+{
+    if (auto callback = m_getAccessHandlCallbacks.take(callbackIdentifier))
+        callback(WTFMove(result));
+}
+
+void WorkerFileSystemStorageConnection::completeIntegerCallback(CallbackIdentifier callbackIdentifier, ExceptionOr<uint64_t>&& result)
+{
+    if (auto callback = m_integerCallbacks.take(callbackIdentifier))
+        callback(WTFMove(result));
+}
+
+void WorkerFileSystemStorageConnection::completeVoidCallback(CallbackIdentifier callbackIdentifier, ExceptionOr<void>&& result)
+{
+    if (auto callback = m_voidCallbacks.take(callbackIdentifier))
+        callback(WTFMove(result));
+}
+
+void WorkerFileSystemStorageConnection::createSyncAccessHandle(FileSystemHandleIdentifier identifier, FileSystemStorageConnection::GetAccessHandleCallback&& callback)
+{
+    if (!m_scope)
+        return callback(Exception { InvalidStateError });
+
+    auto callbackIdentifier = CallbackIdentifier::generateThreadSafe();
+    m_getAccessHandlCallbacks.add(callbackIdentifier, WTFMove(callback));
+
+    callOnMainThread([callbackIdentifier, workerThread = Ref { m_scope->thread() }, mainThreadConnection = m_mainThreadConnection, identifier]() mutable {
+        auto mainThreadCallback = [callbackIdentifier, workerThread = WTFMove(workerThread)](auto result) mutable {
+            workerThread->runLoop().postTaskForMode([callbackIdentifier, result = crossThreadCopy(result)] (auto& scope) mutable {
+                if (auto connection = downcast<WorkerGlobalScope>(scope).fileSystemStorageConnection())
+                    connection->didCreateSyncAccessHandle(callbackIdentifier, WTFMove(result));
+            }, WorkerRunLoop::defaultMode());
+        };
+
+        mainThreadConnection->createSyncAccessHandle(identifier, WTFMove(mainThreadCallback));
+    });
+}
+
+void WorkerFileSystemStorageConnection::getSize(FileSystemHandleIdentifier identifier, FileSystemSyncAccessHandleIdentifier accessHandleIdentifier, FileSystemStorageConnection::IntegerCallback&& callback)
+{
+    if (!m_scope)
+        return callback(Exception { InvalidStateError });
+
+    auto callbackIdentifier = CallbackIdentifier::generateThreadSafe();
+    m_integerCallbacks.add(callbackIdentifier, WTFMove(callback));
+
+    callOnMainThread([callbackIdentifier, workerThread = Ref { m_scope->thread() }, mainThreadConnection = m_mainThreadConnection, identifier, accessHandleIdentifier]() mutable {
+        auto mainThreadCallback = [callbackIdentifier, workerThread = WTFMove(workerThread)](auto result) mutable {
+            workerThread->runLoop().postTaskForMode([callbackIdentifier, result = crossThreadCopy(result)] (auto& scope) mutable {
+                if (auto connection = downcast<WorkerGlobalScope>(scope).fileSystemStorageConnection())
+                    connection->completeIntegerCallback(callbackIdentifier, WTFMove(result));
+            }, WorkerRunLoop::defaultMode());
+        };
+
+        mainThreadConnection->getSize(identifier, accessHandleIdentifier, WTFMove(mainThreadCallback));
+    });
+}
+
+void WorkerFileSystemStorageConnection::truncate(FileSystemHandleIdentifier identifier, FileSystemSyncAccessHandleIdentifier accessHandleIdentifier, uint64_t size, FileSystemStorageConnection::VoidCallback&& callback)
+{
+    if (!m_scope)
+        return callback(Exception { InvalidStateError });
+
+    auto callbackIdentifier = CallbackIdentifier::generateThreadSafe();
+    m_voidCallbacks.add(callbackIdentifier, WTFMove(callback));
+
+    callOnMainThread([callbackIdentifier, workerThread = Ref { m_scope->thread() }, mainThreadConnection = m_mainThreadConnection, identifier, accessHandleIdentifier, size]() mutable {
+        auto mainThreadCallback = [callbackIdentifier, workerThread = WTFMove(workerThread)](auto result) mutable {
+            workerThread->runLoop().postTaskForMode([callbackIdentifier, result = crossThreadCopy(result)] (auto& scope) mutable {
+                if (auto connection = downcast<WorkerGlobalScope>(scope).fileSystemStorageConnection())
+                    connection->completeVoidCallback(callbackIdentifier, WTFMove(result));
+            }, WorkerRunLoop::defaultMode());
+        };
+
+        mainThreadConnection->truncate(identifier, accessHandleIdentifier, size, WTFMove(mainThreadCallback));
+    });
+}
+
+void WorkerFileSystemStorageConnection::flush(FileSystemHandleIdentifier identifier, FileSystemSyncAccessHandleIdentifier accessHandleIdentifier, FileSystemStorageConnection::VoidCallback&& callback)
+{
+    if (!m_scope)
+        return callback(Exception { InvalidStateError });
+
+    auto callbackIdentifier = CallbackIdentifier::generateThreadSafe();
+    m_voidCallbacks.add(callbackIdentifier, WTFMove(callback));
+
+    callOnMainThread([callbackIdentifier, workerThread = Ref { m_scope->thread() }, mainThreadConnection = m_mainThreadConnection, identifier, accessHandleIdentifier]() mutable {
+        auto mainThreadCallback = [callbackIdentifier, workerThread = WTFMove(workerThread)](auto result) mutable {
+            workerThread->runLoop().postTaskForMode([callbackIdentifier, result = crossThreadCopy(result)] (auto& scope) mutable {
+                if (auto connection = downcast<WorkerGlobalScope>(scope).fileSystemStorageConnection())
+                    connection->completeVoidCallback(callbackIdentifier, WTFMove(result));
+            }, WorkerRunLoop::defaultMode());
+        };
+
+        mainThreadConnection->flush(identifier, accessHandleIdentifier, WTFMove(mainThreadCallback));
+    });
+}
+
+void WorkerFileSystemStorageConnection::close(FileSystemHandleIdentifier identifier, FileSystemSyncAccessHandleIdentifier accessHandleIdentifier, FileSystemStorageConnection::VoidCallback&& callback)
+{
+    if (!m_scope)
+        return callback(Exception { InvalidStateError });
+
+    auto callbackIdentifier = CallbackIdentifier::generateThreadSafe();
+    m_voidCallbacks.add(callbackIdentifier, WTFMove(callback));
+
+    callOnMainThread([callbackIdentifier, workerThread = Ref { m_scope->thread() }, mainThreadConnection = m_mainThreadConnection, identifier, accessHandleIdentifier]() mutable {
+        auto mainThreadCallback = [callbackIdentifier, workerThread = WTFMove(workerThread)](auto result) mutable {
+            workerThread->runLoop().postTaskForMode([callbackIdentifier, result = crossThreadCopy(result)] (auto& scope) mutable {
+                if (auto connection = downcast<WorkerGlobalScope>(scope).fileSystemStorageConnection())
+                    connection->completeVoidCallback(callbackIdentifier, WTFMove(result));
+            }, WorkerRunLoop::defaultMode());
+        };
+
+        mainThreadConnection->close(identifier, accessHandleIdentifier, WTFMove(mainThreadCallback));
+    });
+}
+
 } // namespace WebCore

Modified: trunk/Source/WebCore/Modules/filesystemaccess/WorkerFileSystemStorageConnection.h (283675 => 283676)


--- trunk/Source/WebCore/Modules/filesystemaccess/WorkerFileSystemStorageConnection.h	2021-10-06 22:41:36 UTC (rev 283675)
+++ trunk/Source/WebCore/Modules/filesystemaccess/WorkerFileSystemStorageConnection.h	2021-10-06 22:58:42 UTC (rev 283676)
@@ -46,8 +46,10 @@
     using CallbackIdentifier = WorkerFileSystemStorageConnectionCallbackIdentifier;
     void didIsSameEntry(CallbackIdentifier, ExceptionOr<bool>&&);
     void didGetHandle(CallbackIdentifier, ExceptionOr<FileSystemHandleIdentifier>&&);
-    void didRemoveEntry(CallbackIdentifier, ExceptionOr<void>&&);
     void didResolve(CallbackIdentifier, ExceptionOr<Vector<String>>&&);
+    void didCreateSyncAccessHandle(CallbackIdentifier, ExceptionOr<FileSystemSyncAccessHandleIdentifier>&& result);
+    void completeVoidCallback(CallbackIdentifier, ExceptionOr<void>&& result);
+    void completeIntegerCallback(CallbackIdentifier, ExceptionOr<uint64_t>&& result);
 
 private:
     WorkerFileSystemStorageConnection(WorkerGlobalScope&, Ref<FileSystemStorageConnection>&&);
@@ -56,15 +58,23 @@
     void isSameEntry(FileSystemHandleIdentifier, FileSystemHandleIdentifier, FileSystemStorageConnection::SameEntryCallback&&) final;
     void getFileHandle(FileSystemHandleIdentifier, const String& name, bool createIfNecessary, FileSystemStorageConnection::GetHandleCallback&&) final;
     void getDirectoryHandle(FileSystemHandleIdentifier, const String& name, bool createIfNecessary, FileSystemStorageConnection::GetHandleCallback&&) final;
-    void removeEntry(FileSystemHandleIdentifier, const String& name, bool deleteRecursively, FileSystemStorageConnection::RemoveEntryCallback&&) final;
+    void removeEntry(FileSystemHandleIdentifier, const String& name, bool deleteRecursively, FileSystemStorageConnection::VoidCallback&&) final;
     void resolve(FileSystemHandleIdentifier, FileSystemHandleIdentifier, FileSystemStorageConnection::ResolveCallback&&) final;
 
+    void createSyncAccessHandle(FileSystemHandleIdentifier, FileSystemStorageConnection::GetAccessHandleCallback&&) final;
+    void getSize(FileSystemHandleIdentifier, FileSystemSyncAccessHandleIdentifier, FileSystemStorageConnection::IntegerCallback&&) final;
+    void truncate(FileSystemHandleIdentifier, FileSystemSyncAccessHandleIdentifier, uint64_t size, FileSystemStorageConnection::VoidCallback&&) final;
+    void flush(FileSystemHandleIdentifier, FileSystemSyncAccessHandleIdentifier, FileSystemStorageConnection::VoidCallback&&) final;
+    void close(FileSystemHandleIdentifier, FileSystemSyncAccessHandleIdentifier, FileSystemStorageConnection::VoidCallback&&) final;
+
     WeakPtr<WorkerGlobalScope> m_scope;
     RefPtr<FileSystemStorageConnection> m_mainThreadConnection;
     HashMap<CallbackIdentifier, FileSystemStorageConnection::SameEntryCallback> m_sameEntryCallbacks;
     HashMap<CallbackIdentifier, FileSystemStorageConnection::GetHandleCallback> m_getHandleCallbacks;
-    HashMap<CallbackIdentifier, FileSystemStorageConnection::RemoveEntryCallback> m_removeEntryCallbacks;
     HashMap<CallbackIdentifier, FileSystemStorageConnection::ResolveCallback> m_resolveCallbacks;
+    HashMap<CallbackIdentifier, FileSystemStorageConnection::GetAccessHandleCallback> m_getAccessHandlCallbacks;
+    HashMap<CallbackIdentifier, FileSystemStorageConnection::VoidCallback> m_voidCallbacks;
+    HashMap<CallbackIdentifier, FileSystemStorageConnection::IntegerCallback> m_integerCallbacks;
 };
 
 } // namespace WebCore

Modified: trunk/Source/WebCore/Sources.txt (283675 => 283676)


--- trunk/Source/WebCore/Sources.txt	2021-10-06 22:41:36 UTC (rev 283675)
+++ trunk/Source/WebCore/Sources.txt	2021-10-06 22:58:42 UTC (rev 283676)
@@ -61,6 +61,7 @@
 Modules/filesystemaccess/FileSystemDirectoryHandle.cpp
 Modules/filesystemaccess/FileSystemFileHandle.cpp
 Modules/filesystemaccess/FileSystemHandle.cpp
+Modules/filesystemaccess/FileSystemSyncAccessHandle.cpp
 Modules/filesystemaccess/WorkerFileSystemStorageConnection.cpp
 Modules/geolocation/GeoNotifier.cpp
 Modules/geolocation/Geolocation.cpp
@@ -3046,6 +3047,7 @@
 JSFileSystemFileEntry.cpp
 JSFileSystemFileHandle.cpp
 JSFileSystemHandle.cpp
+JSFileSystemSyncAccessHandle.cpp
 JSFillMode.cpp
 JSFocusEvent.cpp
 JSFocusOptions.cpp

Modified: trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj (283675 => 283676)


--- trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj	2021-10-06 22:41:36 UTC (rev 283675)
+++ trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj	2021-10-06 22:58:42 UTC (rev 283676)
@@ -2809,6 +2809,7 @@
 		930AAC9A250EB8490013DA9F /* CSSConditionRule.h in Headers */ = {isa = PBXBuildFile; fileRef = 930AAC98250EB8170013DA9F /* CSSConditionRule.h */; settings = {ATTRIBUTES = (Private, ); }; };
 		930AAC9F250ED4090013DA9F /* JSCSSConditionRule.h in Headers */ = {isa = PBXBuildFile; fileRef = 930AAC9D250ED4090013DA9F /* JSCSSConditionRule.h */; };
 		930AACA2250ED4110013DA9F /* JSCSSGroupingRule.h in Headers */ = {isa = PBXBuildFile; fileRef = 930AACA0250ED4110013DA9F /* JSCSSGroupingRule.h */; };
+		930E4486270C372200DE7AB7 /* FileSystemSyncAccessHandleIdentifier.h in Headers */ = {isa = PBXBuildFile; fileRef = 930E4484270C372100DE7AB7 /* FileSystemSyncAccessHandleIdentifier.h */; settings = {ATTRIBUTES = (Private, ); }; };
 		93153BDA14181F7A00FCF5BE /* [email protected] in Resources */ = {isa = PBXBuildFile; fileRef = 93153BD914181F7A00FCF5BE /* [email protected] */; };
 		93153BDC141959BC00FCF5BE /* textAreaResizeCorner.png in Resources */ = {isa = PBXBuildFile; fileRef = 93153BDB141959BB00FCF5BE /* textAreaResizeCorner.png */; };
 		93153BE214195A5700FCF5BE /* missingImage.png in Resources */ = {isa = PBXBuildFile; fileRef = 93153BE114195A5700FCF5BE /* missingImage.png */; };
@@ -2962,6 +2963,7 @@
 		93D6B7A82551D41F0058DD3A /* DummySpeechRecognitionProvider.h in Headers */ = {isa = PBXBuildFile; fileRef = 93D6B7A62551D3ED0058DD3A /* DummySpeechRecognitionProvider.h */; settings = {ATTRIBUTES = (Private, ); }; };
 		93D9D53C0DA27E180077216C /* RangeBoundaryPoint.h in Headers */ = {isa = PBXBuildFile; fileRef = 93D9D53B0DA27E180077216C /* RangeBoundaryPoint.h */; settings = {ATTRIBUTES = (Private, ); }; };
 		93E241FF0B2B4E4000C732A1 /* HTMLFrameOwnerElement.h in Headers */ = {isa = PBXBuildFile; fileRef = 93E241FE0B2B4E4000C732A1 /* HTMLFrameOwnerElement.h */; settings = {ATTRIBUTES = (Private, ); }; };
+		93E269A2270A5D5D002C4FF0 /* FileSystemSyncAccessHandle.h in Headers */ = {isa = PBXBuildFile; fileRef = 93E2699F270A5D5C002C4FF0 /* FileSystemSyncAccessHandle.h */; settings = {ATTRIBUTES = (Private, ); }; };
 		93E2A307123E9DC0009FE12A /* HTMLParserIdioms.h in Headers */ = {isa = PBXBuildFile; fileRef = 93E2A305123E9DC0009FE12A /* HTMLParserIdioms.h */; settings = {ATTRIBUTES = (Private, ); }; };
 		93E5B2652455E96F005C52D0 /* AttributedString.h in Headers */ = {isa = PBXBuildFile; fileRef = 93E5B2632455E96F005C52D0 /* AttributedString.h */; settings = {ATTRIBUTES = (Private, ); }; };
 		93F198E508245E59001E9ABC /* HTMLDocument.h in Headers */ = {isa = PBXBuildFile; fileRef = F523D23C02DE4396018635CA /* HTMLDocument.h */; settings = {ATTRIBUTES = (Private, ); }; };
@@ -11694,6 +11696,7 @@
 		930AACA0250ED4110013DA9F /* JSCSSGroupingRule.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSCSSGroupingRule.h; sourceTree = "<group>"; };
 		930AACA1250ED4110013DA9F /* JSCSSGroupingRule.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSCSSGroupingRule.cpp; sourceTree = "<group>"; };
 		930C90DC19CF965300D6C21A /* LegacyInlineIterator.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = LegacyInlineIterator.cpp; sourceTree = "<group>"; };
+		930E4484270C372100DE7AB7 /* FileSystemSyncAccessHandleIdentifier.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FileSystemSyncAccessHandleIdentifier.h; sourceTree = "<group>"; };
 		93153BD914181F7A00FCF5BE /* [email protected] */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "[email protected]"; sourceTree = "<group>"; };
 		93153BDB141959BB00FCF5BE /* textAreaResizeCorner.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = textAreaResizeCorner.png; sourceTree = "<group>"; };
 		93153BE114195A5700FCF5BE /* missingImage.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = missingImage.png; sourceTree = "<group>"; };
@@ -11993,6 +11996,9 @@
 		93E227DF0AF589AD00D48324 /* SubresourceLoader.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = SubresourceLoader.cpp; sourceTree = "<group>"; };
 		93E241FE0B2B4E4000C732A1 /* HTMLFrameOwnerElement.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = HTMLFrameOwnerElement.h; sourceTree = "<group>"; };
 		93E2425E0B2B509500C732A1 /* HTMLFrameOwnerElement.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = HTMLFrameOwnerElement.cpp; sourceTree = "<group>"; };
+		93E2699D270A5D5B002C4FF0 /* FileSystemSyncAccessHandle.idl */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = FileSystemSyncAccessHandle.idl; sourceTree = "<group>"; };
+		93E2699F270A5D5C002C4FF0 /* FileSystemSyncAccessHandle.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FileSystemSyncAccessHandle.h; sourceTree = "<group>"; };
+		93E269A0270A5D5C002C4FF0 /* FileSystemSyncAccessHandle.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = FileSystemSyncAccessHandle.cpp; sourceTree = "<group>"; };
 		93E2A304123E9DC0009FE12A /* HTMLParserIdioms.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = HTMLParserIdioms.cpp; sourceTree = "<group>"; };
 		93E2A305123E9DC0009FE12A /* HTMLParserIdioms.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = HTMLParserIdioms.h; sourceTree = "<group>"; };
 		93E5B25424536B1E005C52D0 /* URLDecomposition.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = URLDecomposition.cpp; sourceTree = "<group>"; };
@@ -23437,6 +23443,10 @@
 				932C9BD926DD62600053B3DB /* FileSystemHandle.idl */,
 				935424272703BC88005CA72C /* FileSystemHandleIdentifier.h */,
 				935424292703BCAD005CA72C /* FileSystemStorageConnection.h */,
+				93E269A0270A5D5C002C4FF0 /* FileSystemSyncAccessHandle.cpp */,
+				93E2699F270A5D5C002C4FF0 /* FileSystemSyncAccessHandle.h */,
+				93E2699D270A5D5B002C4FF0 /* FileSystemSyncAccessHandle.idl */,
+				930E4484270C372100DE7AB7 /* FileSystemSyncAccessHandleIdentifier.h */,
 				93443E7B26E8A6BC0058538F /* StorageManager+FileSystemAccess.idl */,
 				93443E7D26E8A6BC0058538F /* StorageManagerFileSystemAccess.h */,
 				93233C8527054C7800BBF41E /* WorkerFileSystemStorageConnection.cpp */,
@@ -32559,6 +32569,8 @@
 				93443E8826E995C40058538F /* FileSystemHandle.h in Headers */,
 				9354242F2703CA51005CA72C /* FileSystemHandleIdentifier.h in Headers */,
 				935424302703CB86005CA72C /* FileSystemStorageConnection.h in Headers */,
+				93E269A2270A5D5D002C4FF0 /* FileSystemSyncAccessHandle.h in Headers */,
+				930E4486270C372200DE7AB7 /* FileSystemSyncAccessHandleIdentifier.h in Headers */,
 				BC5EB69F0E81DAEB00B25965 /* FillLayer.h in Headers */,
 				712BE4831FE865DD002031CC /* FillMode.h in Headers */,
 				845E72F80FD261EE00A87D79 /* Filter.h in Headers */,

Modified: trunk/Source/WebCore/bindings/js/WebCoreBuiltinNames.h (283675 => 283676)


--- trunk/Source/WebCore/bindings/js/WebCoreBuiltinNames.h	2021-10-06 22:41:36 UTC (rev 283675)
+++ trunk/Source/WebCore/bindings/js/WebCoreBuiltinNames.h	2021-10-06 22:58:42 UTC (rev 283676)
@@ -124,6 +124,7 @@
     macro(FileSystemFileEntry) \
     macro(FileSystemFileHandle) \
     macro(FileSystemHandle) \
+    macro(FileSystemSyncAccessHandle) \
     macro(Gamepad) \
     macro(GamepadButton) \
     macro(GamepadEvent) \

Modified: trunk/Source/WebKit/ChangeLog (283675 => 283676)


--- trunk/Source/WebKit/ChangeLog	2021-10-06 22:41:36 UTC (rev 283675)
+++ trunk/Source/WebKit/ChangeLog	2021-10-06 22:58:42 UTC (rev 283676)
@@ -1,3 +1,54 @@
+2021-10-06  Sihui Liu  <[email protected]>
+
+        Add support for FileSystemSyncAccessHandle
+        https://bugs.webkit.org/show_bug.cgi?id=231185
+        <rdar://problem/83847859>
+
+        Reviewed by Youenn Fablet.
+
+        Currently we only allow one open access handle on one file. Second access handle can be created after the first
+        is closed.
+
+        * NetworkProcess/storage/FileSystemStorageError.h:
+        (WebKit::convertToException):
+        (WebKit::convertToExceptionOr):
+        (WebKit::convertToExceptionCode): Deleted.
+        * NetworkProcess/storage/FileSystemStorageHandle.cpp:
+        (WebKit::FileSystemStorageHandle::createSyncAccessHandle):
+        (WebKit::FileSystemStorageHandle::getSize):
+        (WebKit::FileSystemStorageHandle::truncate):
+        (WebKit::FileSystemStorageHandle::flush):
+        (WebKit::FileSystemStorageHandle::close):
+        * NetworkProcess/storage/FileSystemStorageHandle.h:
+        * NetworkProcess/storage/FileSystemStorageManager.cpp:
+        (WebKit::FileSystemStorageManager::connectionClosed):
+        (WebKit::FileSystemStorageManager::acquireLockForFile):
+        (WebKit::FileSystemStorageManager::releaseLockForFile):
+        * NetworkProcess/storage/FileSystemStorageManager.h:
+        * NetworkProcess/storage/NetworkStorageManager.cpp:
+        (WebKit::NetworkStorageManager::createSyncAccessHandle):
+        (WebKit::NetworkStorageManager::getSizeForAccessHandle):
+        (WebKit::NetworkStorageManager::truncateForAccessHandle):
+        (WebKit::NetworkStorageManager::flushForAccessHandle):
+        (WebKit::NetworkStorageManager::closeAccessHandle):
+        * NetworkProcess/storage/NetworkStorageManager.h:
+        * NetworkProcess/storage/NetworkStorageManager.messages.in:
+        * Scripts/webkit/messages.py:
+        (types_that_cannot_be_forward_declared):
+        * WebProcess/WebCoreSupport/WebFileSystemStorageConnection.cpp:
+        (WebKit::WebFileSystemStorageConnection::getFileHandle):
+        (WebKit::WebFileSystemStorageConnection::getDirectoryHandle):
+        (WebKit::WebFileSystemStorageConnection::removeEntry):
+        (WebKit::WebFileSystemStorageConnection::resolve):
+        (WebKit::WebFileSystemStorageConnection::createSyncAccessHandle):
+        (WebKit::WebFileSystemStorageConnection::getSize):
+        (WebKit::WebFileSystemStorageConnection::truncate):
+        (WebKit::WebFileSystemStorageConnection::flush):
+        (WebKit::WebFileSystemStorageConnection::close):
+        * WebProcess/WebCoreSupport/WebFileSystemStorageConnection.h:
+        * WebProcess/WebCoreSupport/WebStorageConnection.cpp:
+        (WebKit::WebStorageConnection::fileSystemGetDirectory):
+
 2021-10-06  Wenson Hsieh  <[email protected]>
 
         Move FlushIdentifier out of the DisplayList namespace

Modified: trunk/Source/WebKit/NetworkProcess/storage/FileSystemStorageError.h (283675 => 283676)


--- trunk/Source/WebKit/NetworkProcess/storage/FileSystemStorageError.h	2021-10-06 22:41:36 UTC (rev 283675)
+++ trunk/Source/WebKit/NetworkProcess/storage/FileSystemStorageError.h	2021-10-06 22:58:42 UTC (rev 283676)
@@ -25,7 +25,7 @@
 
 #pragma once
 
-#include <WebCore/ExceptionCode.h>
+#include <WebCore/ExceptionOr.h>
 #include <wtf/EnumTraits.h>
 
 namespace WebKit {
@@ -34,28 +34,39 @@
     FileNotFound,
     InvalidName,
     InvalidModification,
+    InvalidState,
     TypeMismatch,
     Unknown
 };
 
-inline WebCore::ExceptionCode convertToExceptionCode(FileSystemStorageError error)
+inline WebCore::Exception convertToException(FileSystemStorageError error)
 {
     switch (error) {
     case FileSystemStorageError::FileNotFound:
-        return WebCore::ExceptionCode::NotFoundError;
+        return WebCore::Exception { WebCore::NotFoundError };
     case FileSystemStorageError::InvalidModification:
-        return WebCore::ExceptionCode::InvalidModificationError;
+        return WebCore::Exception { WebCore::InvalidModificationError };
     case FileSystemStorageError::TypeMismatch:
-        return WebCore::ExceptionCode::TypeError;
+        return WebCore::Exception { WebCore::TypeError };
     case FileSystemStorageError::InvalidName:
-        return WebCore::ExceptionCode::UnknownError;
+        return WebCore::Exception { WebCore::UnknownError, "Name is invalid" };
+    case FileSystemStorageError::InvalidState:
+        return WebCore::Exception { WebCore::InvalidStateError };
     case FileSystemStorageError::Unknown:
         break;
     }
 
-    return WebCore::ExceptionCode::UnknownError;
+    return WebCore::Exception { WebCore::UnknownError };
 }
 
+inline WebCore::ExceptionOr<void> convertToExceptionOr(std::optional<FileSystemStorageError> error)
+{
+    if (!error)
+        return { };
+
+    return convertToException(*error);
+}
+
 } // namespace WebKit
 
 namespace WTF {
@@ -66,6 +77,7 @@
         WebKit::FileSystemStorageError::FileNotFound,
         WebKit::FileSystemStorageError::InvalidName,
         WebKit::FileSystemStorageError::InvalidModification,
+        WebKit::FileSystemStorageError::InvalidState,
         WebKit::FileSystemStorageError::TypeMismatch,
         WebKit::FileSystemStorageError::Unknown
     >;

Modified: trunk/Source/WebKit/NetworkProcess/storage/FileSystemStorageHandle.cpp (283675 => 283676)


--- trunk/Source/WebKit/NetworkProcess/storage/FileSystemStorageHandle.cpp	2021-10-06 22:41:36 UTC (rev 283675)
+++ trunk/Source/WebKit/NetworkProcess/storage/FileSystemStorageHandle.cpp	2021-10-06 22:58:42 UTC (rev 283676)
@@ -28,6 +28,7 @@
 
 #include "FileSystemStorageError.h"
 #include "FileSystemStorageManager.h"
+#include <wtf/Scope.h>
 
 namespace WebKit {
 
@@ -139,4 +140,79 @@
     return restPath.split(pathSeparator);
 }
 
+Expected<WebCore::FileSystemSyncAccessHandleIdentifier, FileSystemStorageError> FileSystemStorageHandle::createSyncAccessHandle()
+{
+    if (!m_manager)
+        return makeUnexpected(FileSystemStorageError::Unknown);
+
+    bool acquired = m_manager->acquireLockForFile(m_path, m_identifier);
+    if (!acquired)
+        return makeUnexpected(FileSystemStorageError::InvalidState);
+
+    ASSERT(!m_activeSyncAccessHandle);
+    m_activeSyncAccessHandle = WebCore::FileSystemSyncAccessHandleIdentifier::generateThreadSafe();
+    return *m_activeSyncAccessHandle;
+}
+
+Expected<uint64_t, FileSystemStorageError> FileSystemStorageHandle::getSize(WebCore::FileSystemSyncAccessHandleIdentifier accessHandleIdentifier)
+{
+    if (!m_manager)
+        return makeUnexpected(FileSystemStorageError::Unknown);
+
+    if (!m_activeSyncAccessHandle || *m_activeSyncAccessHandle != accessHandleIdentifier)
+        return makeUnexpected(FileSystemStorageError::Unknown);
+
+    auto size = FileSystem::fileSize(m_path);
+    if (!size)
+        return makeUnexpected(FileSystemStorageError::Unknown);
+
+    return size.value();
+}
+
+std::optional<FileSystemStorageError> FileSystemStorageHandle::truncate(WebCore::FileSystemSyncAccessHandleIdentifier accessHandleIdentifier, uint64_t size)
+{
+    if (!m_manager)
+        return FileSystemStorageError::Unknown;
+
+    if (!m_activeSyncAccessHandle || *m_activeSyncAccessHandle != accessHandleIdentifier)
+        return FileSystemStorageError::Unknown;
+
+    auto handle = FileSystem::openFile(m_path, FileSystem::FileOpenMode::ReadWrite);
+    auto closeFileScope = makeScopeExit([&] {
+        FileSystem::closeFile(handle);
+    });
+
+    auto result = FileSystem::truncateFile(handle, size);
+    if (!result)
+        return FileSystemStorageError::Unknown;
+
+    return std::nullopt;
+}
+
+std::optional<FileSystemStorageError> FileSystemStorageHandle::flush(WebCore::FileSystemSyncAccessHandleIdentifier accessHandleIdentifier)
+{
+    if (!m_manager)
+        return FileSystemStorageError::Unknown;
+
+    if (!m_activeSyncAccessHandle || *m_activeSyncAccessHandle != accessHandleIdentifier)
+        return FileSystemStorageError::Unknown;
+
+    // FIXME: when write operation is implemented, perform actual flush here.
+    return std::nullopt;
+}
+
+std::optional<FileSystemStorageError> FileSystemStorageHandle::close(WebCore::FileSystemSyncAccessHandleIdentifier accessHandleIdentifier)
+{
+    if (!m_manager)
+        return FileSystemStorageError::Unknown;
+
+    if (!m_activeSyncAccessHandle || *m_activeSyncAccessHandle != accessHandleIdentifier)
+        return FileSystemStorageError::Unknown;
+
+    m_manager->releaseLockForFile(m_path, m_identifier);
+    m_activeSyncAccessHandle = std::nullopt;
+
+    return std::nullopt;
+}
+
 } // namespace WebKit

Modified: trunk/Source/WebKit/NetworkProcess/storage/FileSystemStorageHandle.h (283675 => 283676)


--- trunk/Source/WebKit/NetworkProcess/storage/FileSystemStorageHandle.h	2021-10-06 22:41:36 UTC (rev 283675)
+++ trunk/Source/WebKit/NetworkProcess/storage/FileSystemStorageHandle.h	2021-10-06 22:58:42 UTC (rev 283676)
@@ -27,6 +27,7 @@
 
 #include "Connection.h"
 #include <WebCore/FileSystemHandleIdentifier.h>
+#include <WebCore/FileSystemSyncAccessHandleIdentifier.h>
 #include <wtf/WeakPtr.h>
 
 namespace WebKit {
@@ -49,6 +50,12 @@
     std::optional<FileSystemStorageError> removeEntry(const String& name, bool deleteRecursively);
     Expected<Vector<String>, FileSystemStorageError> resolve(WebCore::FileSystemHandleIdentifier);
 
+    Expected<WebCore::FileSystemSyncAccessHandleIdentifier, FileSystemStorageError> createSyncAccessHandle();
+    Expected<uint64_t, FileSystemStorageError> getSize(WebCore::FileSystemSyncAccessHandleIdentifier);
+    std::optional<FileSystemStorageError> truncate(WebCore::FileSystemSyncAccessHandleIdentifier, uint64_t size);
+    std::optional<FileSystemStorageError> flush(WebCore::FileSystemSyncAccessHandleIdentifier);
+    std::optional<FileSystemStorageError> close(WebCore::FileSystemSyncAccessHandleIdentifier);
+
 private:
     Expected<WebCore::FileSystemHandleIdentifier, FileSystemStorageError> requestCreateHandle(IPC::Connection::UniqueID, Type, String&& name, bool createIfNecessary);
 
@@ -57,6 +64,7 @@
     Type m_type;
     String m_path;
     String m_name;
+    std::optional<WebCore::FileSystemSyncAccessHandleIdentifier> m_activeSyncAccessHandle;
 };
 
 } // namespace WebKit

Modified: trunk/Source/WebKit/NetworkProcess/storage/FileSystemStorageManager.cpp (283675 => 283676)


--- trunk/Source/WebKit/NetworkProcess/storage/FileSystemStorageManager.cpp	2021-10-06 22:41:36 UTC (rev 283675)
+++ trunk/Source/WebKit/NetworkProcess/storage/FileSystemStorageManager.cpp	2021-10-06 22:58:42 UTC (rev 283676)
@@ -87,15 +87,21 @@
 {
     ASSERT(!RunLoop::isMain());
 
-    auto handles = m_handlesByConnection.find(connection);
-    if (handles == m_handlesByConnection.end())
+    auto connectionHandles = m_handlesByConnection.find(connection);
+    if (connectionHandles == m_handlesByConnection.end())
         return;
 
-    for (auto handleIdentifier : handles->value) {
-        auto handle = m_handles.take(handleIdentifier);
-        m_registry.unregisterHandle(handleIdentifier);
+    auto identifiers = connectionHandles->value;
+    for (auto identifier : identifiers) {
+        auto handle = m_handles.take(identifier);
+        m_registry.unregisterHandle(identifier);
     }
-    m_handlesByConnection.remove(handles);
+
+    m_lockMap.removeIf([&identifiers](auto& entry) {
+        return identifiers.contains(entry.value);
+    });
+
+    m_handlesByConnection.remove(connectionHandles);
 }
 
 Expected<WebCore::FileSystemHandleIdentifier, FileSystemStorageError> FileSystemStorageManager::getDirectory(IPC::Connection::UniqueID connection)
@@ -105,4 +111,23 @@
     return createHandle(connection, FileSystemStorageHandle::Type::Directory, String { m_path }, { }, true);
 }
 
+bool FileSystemStorageManager::acquireLockForFile(const String& path, WebCore::FileSystemHandleIdentifier identifier)
+{
+    if (m_lockMap.contains(path))
+        return false;
+
+    m_lockMap.add(path, identifier);
+    return true;
+}
+
+bool FileSystemStorageManager::releaseLockForFile(const String& path, WebCore::FileSystemHandleIdentifier identifier)
+{
+    if (auto lockedByIdentifier = m_lockMap.get(path); lockedByIdentifier == identifier) {
+        m_lockMap.remove(path);
+        return true;
+    }
+
+    return false;
+}
+
 } // namespace WebKit

Modified: trunk/Source/WebKit/NetworkProcess/storage/FileSystemStorageManager.h (283675 => 283676)


--- trunk/Source/WebKit/NetworkProcess/storage/FileSystemStorageManager.h	2021-10-06 22:41:36 UTC (rev 283675)
+++ trunk/Source/WebKit/NetworkProcess/storage/FileSystemStorageManager.h	2021-10-06 22:58:42 UTC (rev 283676)
@@ -43,6 +43,8 @@
     const String& getPath(WebCore::FileSystemHandleIdentifier);
     void connectionClosed(IPC::Connection::UniqueID);
     Expected<WebCore::FileSystemHandleIdentifier, FileSystemStorageError> getDirectory(IPC::Connection::UniqueID);
+    bool acquireLockForFile(const String& path, WebCore::FileSystemHandleIdentifier);
+    bool releaseLockForFile(const String& path, WebCore::FileSystemHandleIdentifier);
 
 private:
     String m_path;
@@ -49,6 +51,7 @@
     FileSystemStorageHandleRegistry& m_registry;
     HashMap<IPC::Connection::UniqueID, HashSet<WebCore::FileSystemHandleIdentifier>> m_handlesByConnection;
     HashMap<WebCore::FileSystemHandleIdentifier, std::unique_ptr<FileSystemStorageHandle>> m_handles;
+    HashMap<String, WebCore::FileSystemHandleIdentifier> m_lockMap;
 };
 
 } // namespace WebKit

Modified: trunk/Source/WebKit/NetworkProcess/storage/NetworkStorageManager.cpp (283675 => 283676)


--- trunk/Source/WebKit/NetworkProcess/storage/NetworkStorageManager.cpp	2021-10-06 22:41:36 UTC (rev 283675)
+++ trunk/Source/WebKit/NetworkProcess/storage/NetworkStorageManager.cpp	2021-10-06 22:58:42 UTC (rev 283676)
@@ -226,5 +226,60 @@
     completionHandler(handle->resolve(targetIdentifier));
 }
 
+void NetworkStorageManager::createSyncAccessHandle(WebCore::FileSystemHandleIdentifier identifier, CompletionHandler<void(Expected<WebCore::FileSystemSyncAccessHandleIdentifier, FileSystemStorageError>)>&& completionHandler)
+{
+    ASSERT(!RunLoop::isMain());
+
+    auto handle = m_fileSystemStorageHandleRegistry->getHandle(identifier);
+    if (!handle)
+        return completionHandler(makeUnexpected(FileSystemStorageError::Unknown));
+
+    completionHandler(handle->createSyncAccessHandle());
+}
+
+void NetworkStorageManager::getSizeForAccessHandle(WebCore::FileSystemHandleIdentifier identifier, WebCore::FileSystemSyncAccessHandleIdentifier accessHandleIdentifier, CompletionHandler<void(Expected<uint64_t, FileSystemStorageError>)>&& completionHandler)
+{
+    ASSERT(!RunLoop::isMain());
+
+    auto handle = m_fileSystemStorageHandleRegistry->getHandle(identifier);
+    if (!handle)
+        return completionHandler(makeUnexpected(FileSystemStorageError::Unknown));
+
+    completionHandler(handle->getSize(accessHandleIdentifier));
+}
+
+void NetworkStorageManager::truncateForAccessHandle(WebCore::FileSystemHandleIdentifier identifier, WebCore::FileSystemSyncAccessHandleIdentifier accessHandleIdentifier, uint64_t size, CompletionHandler<void(std::optional<FileSystemStorageError>)>&& completionHandler)
+{
+    ASSERT(!RunLoop::isMain());
+
+    auto handle = m_fileSystemStorageHandleRegistry->getHandle(identifier);
+    if (!handle)
+        return completionHandler(FileSystemStorageError::Unknown);
+
+    completionHandler(handle->truncate(accessHandleIdentifier, size));
+}
+
+void NetworkStorageManager::flushForAccessHandle(WebCore::FileSystemHandleIdentifier identifier, WebCore::FileSystemSyncAccessHandleIdentifier accessHandleIdentifier, CompletionHandler<void(std::optional<FileSystemStorageError>)>&& completionHandler)
+{
+    ASSERT(!RunLoop::isMain());
+
+    auto handle = m_fileSystemStorageHandleRegistry->getHandle(identifier);
+    if (!handle)
+        return completionHandler(FileSystemStorageError::Unknown);
+
+    completionHandler(handle->flush(accessHandleIdentifier));
+}
+
+void NetworkStorageManager::closeAccessHandle(WebCore::FileSystemHandleIdentifier identifier, WebCore::FileSystemSyncAccessHandleIdentifier accessHandleIdentifier, CompletionHandler<void(std::optional<FileSystemStorageError>)>&& completionHandler)
+{
+    ASSERT(!RunLoop::isMain());
+
+    auto handle = m_fileSystemStorageHandleRegistry->getHandle(identifier);
+    if (!handle)
+        return completionHandler(FileSystemStorageError::Unknown);
+
+    completionHandler(handle->close(accessHandleIdentifier));
+}
+
 } // namespace WebKit
 

Modified: trunk/Source/WebKit/NetworkProcess/storage/NetworkStorageManager.h (283675 => 283676)


--- trunk/Source/WebKit/NetworkProcess/storage/NetworkStorageManager.h	2021-10-06 22:41:36 UTC (rev 283675)
+++ trunk/Source/WebKit/NetworkProcess/storage/NetworkStorageManager.h	2021-10-06 22:58:42 UTC (rev 283676)
@@ -30,6 +30,7 @@
 #include "OriginStorageManager.h"
 #include <WebCore/ClientOrigin.h>
 #include <WebCore/FileSystemHandleIdentifier.h>
+#include <WebCore/FileSystemSyncAccessHandleIdentifier.h>
 #include <pal/SessionID.h>
 
 namespace WebCore {
@@ -69,6 +70,11 @@
     void getDirectoryHandle(IPC::Connection&, WebCore::FileSystemHandleIdentifier, String&& name, bool createIfNecessary, CompletionHandler<void(Expected<WebCore::FileSystemHandleIdentifier, FileSystemStorageError>)>&&);
     void removeEntry(WebCore::FileSystemHandleIdentifier, const String& name, bool deleteRecursively, CompletionHandler<void(std::optional<FileSystemStorageError>)>&&);
     void resolve(WebCore::FileSystemHandleIdentifier, WebCore::FileSystemHandleIdentifier, CompletionHandler<void(Expected<Vector<String>, FileSystemStorageError>)>&&);
+    void createSyncAccessHandle(WebCore::FileSystemHandleIdentifier, CompletionHandler<void(Expected<WebCore::FileSystemSyncAccessHandleIdentifier, FileSystemStorageError>)>&&);
+    void getSizeForAccessHandle(WebCore::FileSystemHandleIdentifier, WebCore::FileSystemSyncAccessHandleIdentifier, CompletionHandler<void(Expected<uint64_t, FileSystemStorageError>)>&&);
+    void truncateForAccessHandle(WebCore::FileSystemHandleIdentifier, WebCore::FileSystemSyncAccessHandleIdentifier, uint64_t size, CompletionHandler<void(std::optional<FileSystemStorageError>)>&&);
+    void flushForAccessHandle(WebCore::FileSystemHandleIdentifier, WebCore::FileSystemSyncAccessHandleIdentifier, CompletionHandler<void(std::optional<FileSystemStorageError>)>&&);
+    void closeAccessHandle(WebCore::FileSystemHandleIdentifier, WebCore::FileSystemSyncAccessHandleIdentifier, CompletionHandler<void(std::optional<FileSystemStorageError>)>&&);
 
     PAL::SessionID m_sessionID;
     Ref<WorkQueue> m_queue;

Modified: trunk/Source/WebKit/NetworkProcess/storage/NetworkStorageManager.messages.in (283675 => 283676)


--- trunk/Source/WebKit/NetworkProcess/storage/NetworkStorageManager.messages.in	2021-10-06 22:41:36 UTC (rev 283675)
+++ trunk/Source/WebKit/NetworkProcess/storage/NetworkStorageManager.messages.in	2021-10-06 22:58:42 UTC (rev 283676)
@@ -32,4 +32,10 @@
     GetDirectoryHandle(WebCore::FileSystemHandleIdentifier identifier, String name, bool createIfNecessary) -> (Expected<WebCore::FileSystemHandleIdentifier, WebKit::FileSystemStorageError> result) Async WantsConnection
     RemoveEntry(WebCore::FileSystemHandleIdentifier identifier, String name, bool deleteRecursively) -> (std::optional<WebKit::FileSystemStorageError> result) Async
     Resolve(WebCore::FileSystemHandleIdentifier identifier, WebCore::FileSystemHandleIdentifier targetIdentifier) -> (Expected<Vector<String>, WebKit::FileSystemStorageError> result) Async
+
+    CreateSyncAccessHandle(WebCore::FileSystemHandleIdentifier identifier) -> (Expected<WebCore::FileSystemSyncAccessHandleIdentifier, WebKit::FileSystemStorageError> result) Async
+    GetSizeForAccessHandle(WebCore::FileSystemHandleIdentifier identifier, WebCore::FileSystemSyncAccessHandleIdentifier accessHandleIdentifier) -> (Expected<uint64_t, WebKit::FileSystemStorageError> result) Async
+    TruncateForAccessHandle(WebCore::FileSystemHandleIdentifier identifier, WebCore::FileSystemSyncAccessHandleIdentifier accessHandleIdentifier, uint64_t size) -> (std::optional<WebKit::FileSystemStorageError> result) Async
+    FlushForAccessHandle(WebCore::FileSystemHandleIdentifier identifier, WebCore::FileSystemSyncAccessHandleIdentifier accessHandleIdentifier) -> (std::optional<WebKit::FileSystemStorageError> result) Async
+    CloseAccessHandle(WebCore::FileSystemHandleIdentifier identifier, WebCore::FileSystemSyncAccessHandleIdentifier accessHandleIdentifier) -> (std::optional<WebKit::FileSystemStorageError> result) Async
 }

Modified: trunk/Source/WebKit/Scripts/webkit/messages.py (283675 => 283676)


--- trunk/Source/WebKit/Scripts/webkit/messages.py	2021-10-06 22:41:36 UTC (rev 283675)
+++ trunk/Source/WebKit/Scripts/webkit/messages.py	2021-10-06 22:58:42 UTC (rev 283676)
@@ -281,6 +281,7 @@
         'WebCore::DragApplicationFlags',
         'WebCore::FetchIdentifier',
         'WebCore::FileSystemHandleIdentifier',
+        'WebCore::FileSystemSyncAccessHandleIdentifier',
         'WebCore::FrameIdentifier',
         'WebCore::GraphicsContextFlushIdentifier',
         'WebCore::GraphicsContextGLAttributes',

Modified: trunk/Source/WebKit/WebProcess/WebCoreSupport/WebFileSystemStorageConnection.cpp (283675 => 283676)


--- trunk/Source/WebKit/WebProcess/WebCoreSupport/WebFileSystemStorageConnection.cpp	2021-10-06 22:41:36 UTC (rev 283675)
+++ trunk/Source/WebKit/WebProcess/WebCoreSupport/WebFileSystemStorageConnection.cpp	2021-10-06 22:58:42 UTC (rev 283676)
@@ -67,7 +67,7 @@
 
     m_connection->sendWithAsyncReply(Messages::NetworkStorageManager::GetFileHandle(identifier, name, createIfNecessary), [name, completionHandler = WTFMove(completionHandler)](auto result) mutable {
         if (!result)
-            return completionHandler(WebCore::Exception { convertToExceptionCode(result.error()) });
+            return completionHandler(convertToException(result.error()));
 
         auto identifier = result.value();
         if (!identifier.isValid())
@@ -84,7 +84,7 @@
 
     m_connection->sendWithAsyncReply(Messages::NetworkStorageManager::GetDirectoryHandle(identifier, name, createIfNecessary), [name, completionHandler = WTFMove(completionHandler)](auto result) mutable {
         if (!result)
-            return completionHandler(WebCore::Exception { convertToExceptionCode(result.error()) });
+            return completionHandler(convertToException(result.error()));
 
         auto identifier = result.value();
         if (!identifier.isValid())
@@ -94,16 +94,13 @@
     });
 }
 
-void WebFileSystemStorageConnection::removeEntry(WebCore::FileSystemHandleIdentifier identifier, const String& name, bool deleteRecursively, WebCore::FileSystemStorageConnection::RemoveEntryCallback&& completionHandler)
+void WebFileSystemStorageConnection::removeEntry(WebCore::FileSystemHandleIdentifier identifier, const String& name, bool deleteRecursively, WebCore::FileSystemStorageConnection::VoidCallback&& completionHandler)
 {
     if (!m_connection)
         return completionHandler(WebCore::Exception { WebCore::UnknownError, "Connection is lost" });
 
     m_connection->sendWithAsyncReply(Messages::NetworkStorageManager::RemoveEntry(identifier, name, deleteRecursively), [completionHandler = WTFMove(completionHandler)](auto error) mutable {
-        if (error)
-            return completionHandler(WebCore::Exception { convertToExceptionCode(error.value()) });
-
-        completionHandler({ });
+        return completionHandler(convertToExceptionOr(error));
     });
 }
 
@@ -114,10 +111,66 @@
 
     m_connection->sendWithAsyncReply(Messages::NetworkStorageManager::Resolve(identifier, otherIdentifier), [completionHandler = WTFMove(completionHandler)](auto result) mutable {
         if (!result)
-            return completionHandler(WebCore::Exception { convertToExceptionCode(result.error()) });
+            return completionHandler(convertToException(result.error()));
 
         completionHandler(WTFMove(result.value()));
     });
 }
 
+void WebFileSystemStorageConnection::createSyncAccessHandle(WebCore::FileSystemHandleIdentifier identifier, WebCore::FileSystemStorageConnection::GetAccessHandleCallback&& completionHandler)
+{
+    if (!m_connection)
+        return completionHandler(WebCore::Exception { WebCore::UnknownError, "Connection is lost" });
+
+    m_connection->sendWithAsyncReply(Messages::NetworkStorageManager::CreateSyncAccessHandle(identifier), [completionHandler = WTFMove(completionHandler)](auto result) mutable {
+        if (!result)
+            return completionHandler(convertToException(result.error()));
+
+        completionHandler(WTFMove(result.value()));
+    });
+}
+
+void WebFileSystemStorageConnection::getSize(WebCore::FileSystemHandleIdentifier identifier, WebCore::FileSystemSyncAccessHandleIdentifier accessHandleIdentifier, IntegerCallback&& completionHandler)
+{
+    if (!m_connection)
+        return completionHandler(WebCore::Exception { WebCore::UnknownError, "Connection is lost" });
+
+    m_connection->sendWithAsyncReply(Messages::NetworkStorageManager::GetSizeForAccessHandle(identifier, accessHandleIdentifier), [completionHandler = WTFMove(completionHandler)](auto result) mutable {
+        if (!result)
+            return completionHandler(convertToException(result.error()));
+
+        completionHandler(result.value());
+    });
+}
+
+void WebFileSystemStorageConnection::truncate(WebCore::FileSystemHandleIdentifier identifier, WebCore::FileSystemSyncAccessHandleIdentifier accessHandleIdentifier, uint64_t size, VoidCallback&& completionHandler)
+{
+    if (!m_connection)
+        return completionHandler(WebCore::Exception { WebCore::UnknownError, "Connection is lost" });
+
+    m_connection->sendWithAsyncReply(Messages::NetworkStorageManager::TruncateForAccessHandle(identifier, accessHandleIdentifier, size), [completionHandler = WTFMove(completionHandler)](auto error) mutable {
+        completionHandler(convertToExceptionOr(error));
+    });
+}
+
+void WebFileSystemStorageConnection::flush(WebCore::FileSystemHandleIdentifier identifier, WebCore::FileSystemSyncAccessHandleIdentifier accessHandleIdentifier, VoidCallback&& completionHandler)
+{
+    if (!m_connection)
+        return completionHandler(WebCore::Exception { WebCore::UnknownError, "Connection is lost" });
+
+    m_connection->sendWithAsyncReply(Messages::NetworkStorageManager::FlushForAccessHandle(identifier, accessHandleIdentifier), [completionHandler = WTFMove(completionHandler)](auto error) mutable {
+        completionHandler(convertToExceptionOr(error));
+    });
+}
+
+void WebFileSystemStorageConnection::close(WebCore::FileSystemHandleIdentifier identifier, WebCore::FileSystemSyncAccessHandleIdentifier accessHandleIdentifier, VoidCallback&& completionHandler)
+{
+    if (!m_connection)
+        return completionHandler(WebCore::Exception { WebCore::UnknownError, "Connection is lost" });
+
+    m_connection->sendWithAsyncReply(Messages::NetworkStorageManager::CloseAccessHandle(identifier, accessHandleIdentifier), [completionHandler = WTFMove(completionHandler)](auto error) mutable {
+        completionHandler(convertToExceptionOr(error));
+    });
+}
+
 } // namespace WebKit

Modified: trunk/Source/WebKit/WebProcess/WebCoreSupport/WebFileSystemStorageConnection.h (283675 => 283676)


--- trunk/Source/WebKit/WebProcess/WebCoreSupport/WebFileSystemStorageConnection.h	2021-10-06 22:41:36 UTC (rev 283675)
+++ trunk/Source/WebKit/WebProcess/WebCoreSupport/WebFileSystemStorageConnection.h	2021-10-06 22:58:42 UTC (rev 283676)
@@ -51,9 +51,15 @@
     void isSameEntry(WebCore::FileSystemHandleIdentifier, WebCore::FileSystemHandleIdentifier, WebCore::FileSystemStorageConnection::SameEntryCallback&&);
     void getFileHandle(WebCore::FileSystemHandleIdentifier, const String& name, bool createIfNecessary, WebCore::FileSystemStorageConnection::GetHandleCallback&&);
     void getDirectoryHandle(WebCore::FileSystemHandleIdentifier, const String& name, bool createIfNecessary, WebCore::FileSystemStorageConnection::GetHandleCallback&&);
-    void removeEntry(WebCore::FileSystemHandleIdentifier, const String& name, bool deleteRecursively, WebCore::FileSystemStorageConnection::RemoveEntryCallback&&);
+    void removeEntry(WebCore::FileSystemHandleIdentifier, const String& name, bool deleteRecursively, WebCore::FileSystemStorageConnection::VoidCallback&&);
     void resolve(WebCore::FileSystemHandleIdentifier, WebCore::FileSystemHandleIdentifier, WebCore::FileSystemStorageConnection::ResolveCallback&&);
 
+    void createSyncAccessHandle(WebCore::FileSystemHandleIdentifier, WebCore::FileSystemStorageConnection::GetAccessHandleCallback&&) final;
+    void getSize(WebCore::FileSystemHandleIdentifier, WebCore::FileSystemSyncAccessHandleIdentifier, WebCore::FileSystemStorageConnection::IntegerCallback&&) final;
+    void truncate(WebCore::FileSystemHandleIdentifier, WebCore::FileSystemSyncAccessHandleIdentifier, uint64_t size, WebCore::FileSystemStorageConnection::VoidCallback&&) final;
+    void flush(WebCore::FileSystemHandleIdentifier, WebCore::FileSystemSyncAccessHandleIdentifier, WebCore::FileSystemStorageConnection::VoidCallback&&) final;
+    void close(WebCore::FileSystemHandleIdentifier, WebCore::FileSystemSyncAccessHandleIdentifier, WebCore::FileSystemStorageConnection::VoidCallback&&) final;
+
     RefPtr<IPC::Connection> m_connection;
 };
 

Modified: trunk/Source/WebKit/WebProcess/WebCoreSupport/WebStorageConnection.cpp (283675 => 283676)


--- trunk/Source/WebKit/WebProcess/WebCoreSupport/WebStorageConnection.cpp	2021-10-06 22:41:36 UTC (rev 283675)
+++ trunk/Source/WebKit/WebProcess/WebCoreSupport/WebStorageConnection.cpp	2021-10-06 22:58:42 UTC (rev 283676)
@@ -56,7 +56,7 @@
     auto& connection = WebProcess::singleton().ensureNetworkProcessConnection().connection();
     connection.sendWithAsyncReply(Messages::NetworkStorageManager::FileSystemGetDirectory(origin), [completionHandler = WTFMove(completionHandler)](auto result) mutable {
         if (!result)
-            return completionHandler(WebCore::Exception { convertToExceptionCode(result.error()) });
+            return completionHandler(convertToException(result.error()));
 
         auto identifier = result.value();
         if (!identifier.isValid())
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to