Changeset 284059 in webkit


Ignore:
Timestamp:
Oct 12, 2021 4:35:55 PM (9 months ago)
Author:
sihui_liu@apple.com
Message:

Implement FileSystemSyncAccessHandle read() and write()
https://bugs.webkit.org/show_bug.cgi?id=231466
<rdar://problem/84050394>

Reviewed by Youenn Fablet.

LayoutTests/imported/w3c:

  • web-platform-tests/file-system-access/sandboxed_FileSystemSyncAccessHandle-close.https.tentative.worker-expected.txt:
  • web-platform-tests/file-system-access/sandboxed_FileSystemSyncAccessHandle-flush.https.tentative.worker-expected.txt:
  • web-platform-tests/file-system-access/sandboxed_FileSystemSyncAccessHandle-getSize.https.tentative.worker-expected.txt:
  • web-platform-tests/file-system-access/sandboxed_FileSystemSyncAccessHandle-read-write.https.tentative.worker-expected.txt:
  • web-platform-tests/file-system-access/sandboxed_FileSystemSyncAccessHandle-truncate.https.tentative.worker-expected.txt:

Source/WebCore:

Implement read() and write() according to proposal:
https://github.com/WICG/file-system-access/blob/main/AccessHandle.md

Test: storage/filesystemaccess/sync-access-handle-read-write-worker.html
API test: FileSystemAccess.ProcessCrashDuringWrite

  • Modules/filesystemaccess/FileSystemFileHandle.cpp:

(WebCore::FileSystemFileHandle::createSyncAccessHandle):
(WebCore::FileSystemFileHandle::getSize):
(WebCore::FileSystemFileHandle::truncate):
(WebCore::FileSystemFileHandle::flush):

  • Modules/filesystemaccess/FileSystemFileHandle.h:
  • Modules/filesystemaccess/FileSystemStorageConnection.h:
  • Modules/filesystemaccess/FileSystemSyncAccessHandle.cpp:

(WebCore::FileSystemSyncAccessHandle::create):
(WebCore::FileSystemSyncAccessHandle::FileSystemSyncAccessHandle):
(WebCore::FileSystemSyncAccessHandle::truncate):
(WebCore::FileSystemSyncAccessHandle::getSize):
(WebCore::FileSystemSyncAccessHandle::flush):
(WebCore::FileSystemSyncAccessHandle::close):
(WebCore::FileSystemSyncAccessHandle::read):
(WebCore::FileSystemSyncAccessHandle::write):

  • Modules/filesystemaccess/FileSystemSyncAccessHandle.h:
  • Modules/filesystemaccess/FileSystemSyncAccessHandle.idl:
  • Modules/filesystemaccess/WorkerFileSystemStorageConnection.cpp:

(WebCore::WorkerFileSystemStorageConnection::didCreateSyncAccessHandle):
(WebCore::WorkerFileSystemStorageConnection::createSyncAccessHandle):

  • Modules/filesystemaccess/WorkerFileSystemStorageConnection.h:
  • bindings/js/BufferSource.h:

(WebCore::BufferSource::mutableData const):

Source/WebCore/PAL:

  • PAL.xcodeproj/project.pbxproj:
  • pal/spi/cocoa/FilePortSPI.h: Added.

Source/WebKit:

Let network process open the file and pass file descriptor to web process, so that web process can read and
write the file without sending IPC messages. Currently getting file size, truncating file and syncing file are
still performed by network process.

  • NetworkProcess/storage/FileSystemStorageError.h:

(WebKit::convertToException):

  • NetworkProcess/storage/FileSystemStorageHandle.cpp:

(WebKit::FileSystemStorageHandle::createSyncAccessHandle):
(WebKit::FileSystemStorageHandle::truncate):
(WebKit::FileSystemStorageHandle::flush):
(WebKit::FileSystemStorageHandle::close):

  • NetworkProcess/storage/FileSystemStorageHandle.h:
  • NetworkProcess/storage/NetworkStorageManager.cpp:

(WebKit::NetworkStorageManager::createSyncAccessHandle):

  • NetworkProcess/storage/NetworkStorageManager.h:
  • NetworkProcess/storage/NetworkStorageManager.messages.in:
  • Platform/IPC/SharedFileHandle.cpp: Added.

(IPC::SharedFileHandle::create):
(IPC::SharedFileHandle::encode const):
(IPC::SharedFileHandle::decode):

  • Platform/IPC/SharedFileHandle.h: Added.

(IPC::SharedFileHandle::handle):
(IPC::SharedFileHandle::SharedFileHandle):

  • Platform/IPC/cocoa/SharedFileHandleCocoa.cpp: Added.

(IPC::SharedFileHandle::create):
(IPC::SharedFileHandle::encode const):
(IPC::SharedFileHandle::decode):

  • Sources.txt:
  • UIProcess/API/Cocoa/WKPreferences.mm:

(-[WKPreferences _fileSystemAccessEnabled]):
(-[WKPreferences _setFileSystemAccessEnabled:]):
(-[WKPreferences _storageAPIEnabled]):
(-[WKPreferences _setStorageAPIEnabled:]):
(-[WKPreferences _accessHandleEnabled]):
(-[WKPreferences _setAccessHandleEnabled:]):

  • UIProcess/API/Cocoa/WKPreferencesPrivate.h:
  • WebKit.xcodeproj/project.pbxproj:
  • WebProcess/WebCoreSupport/WebFileSystemStorageConnection.cpp:

(WebKit::WebFileSystemStorageConnection::createSyncAccessHandle):

  • WebProcess/com.apple.WebProcess.sb.in:

Source/WTF:

  • wtf/PlatformHave.h:

Tools:

  • TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
  • TestWebKitAPI/Tests/WebKitCocoa/FileSystemAccess.mm: Added.

(-[FileSystemAccessMessageHandler userContentController:didReceiveScriptMessage:]):
(test):

LayoutTests:

  • storage/filesystemaccess/resources/sync-access-handle-read-write.js: Added.

(finishTest):
(arrayBufferToString):
(stringToArrayBuffer):
(write):
(read):
(async test):

  • storage/filesystemaccess/sync-access-handle-read-write-worker-expected.txt: Added.
  • storage/filesystemaccess/sync-access-handle-read-write-worker.html: Added.
Location:
trunk
Files:
4 added
35 edited
4 copied

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r284058 r284059  
     12021-10-12  Sihui Liu  <sihui_liu@apple.com>
     2
     3        Implement FileSystemSyncAccessHandle read() and write()
     4        https://bugs.webkit.org/show_bug.cgi?id=231466
     5        <rdar://problem/84050394>
     6
     7        Reviewed by Youenn Fablet.
     8
     9        * storage/filesystemaccess/resources/sync-access-handle-read-write.js: Added.
     10        (finishTest):
     11        (arrayBufferToString):
     12        (stringToArrayBuffer):
     13        (write):
     14        (read):
     15        (async test):
     16        * storage/filesystemaccess/sync-access-handle-read-write-worker-expected.txt: Added.
     17        * storage/filesystemaccess/sync-access-handle-read-write-worker.html: Added.
     18
    1192021-10-12  Ayumi Kojima  <ayumi_kojima@apple.com>
    220
  • trunk/LayoutTests/imported/w3c/ChangeLog

    r283980 r284059  
     12021-10-12  Sihui Liu  <sihui_liu@apple.com>
     2
     3        Implement FileSystemSyncAccessHandle read() and write()
     4        https://bugs.webkit.org/show_bug.cgi?id=231466
     5        <rdar://problem/84050394>
     6
     7        Reviewed by Youenn Fablet.
     8
     9        * web-platform-tests/file-system-access/sandboxed_FileSystemSyncAccessHandle-close.https.tentative.worker-expected.txt:
     10        * web-platform-tests/file-system-access/sandboxed_FileSystemSyncAccessHandle-flush.https.tentative.worker-expected.txt:
     11        * web-platform-tests/file-system-access/sandboxed_FileSystemSyncAccessHandle-getSize.https.tentative.worker-expected.txt:
     12        * web-platform-tests/file-system-access/sandboxed_FileSystemSyncAccessHandle-read-write.https.tentative.worker-expected.txt:
     13        * web-platform-tests/file-system-access/sandboxed_FileSystemSyncAccessHandle-truncate.https.tentative.worker-expected.txt:
     14
    1152021-10-12  Aditya Keerthi  <akeerthi@apple.com>
    216
  • trunk/LayoutTests/imported/w3c/web-platform-tests/file-system-access/sandboxed_FileSystemSyncAccessHandle-close.https.tentative.worker-expected.txt

    r283881 r284059  
    22FAIL SyncAccessHandle.close is idempotent promise_test: Unhandled rejection with value: object "InvalidStateError: The object is in an invalid state."
    33FAIL SyncAccessHandle.close is idempotent when called immediately promise_test: Unhandled rejection with value: object "UnknownError: The operation failed for an unknown transient reason (e.g. out of memory)."
    4 FAIL SyncAccessHandle.read fails after SyncAccessHandle.close settles assert_throws_dom: function "() => handle.read(readBuffer, {at: 0})" threw object "TypeError: handle.read is not a function. (In 'handle.read(readBuffer, {at: 0})', 'handle.read' is undefined)" that is not a DOMException InvalidStateError: property "code" is equal to undefined, expected 11
    5 FAIL SyncAccessHandle.read fails immediately after calling SyncAccessHandle.close assert_throws_dom: function "() => handle.read(readBuffer, {at: 0})" threw object "TypeError: handle.read is not a function. (In 'handle.read(readBuffer, {at: 0})', 'handle.read' is undefined)" that is not a DOMException InvalidStateError: property "code" is equal to undefined, expected 11
    6 FAIL SyncAccessHandle.write fails after SyncAccessHandle.close settles assert_throws_dom: function "() => handle.write(writeBuffer, {at: 0})" threw object "TypeError: handle.write is not a function. (In 'handle.write(writeBuffer, {at: 0})', 'handle.write' is undefined)" that is not a DOMException InvalidStateError: property "code" is equal to undefined, expected 11
    7 FAIL SyncAccessHandle.write fails immediately after calling SyncAccessHandle.close assert_throws_dom: function "() => handle.write(writeBuffer, {at: 0})" threw object "TypeError: handle.write is not a function. (In 'handle.write(writeBuffer, {at: 0})', 'handle.write' is undefined)" that is not a DOMException InvalidStateError: property "code" is equal to undefined, expected 11
     4FAIL SyncAccessHandle.read fails after SyncAccessHandle.close settles promise_test: Unhandled rejection with value: object "InvalidStateError: The object is in an invalid state."
     5FAIL SyncAccessHandle.read fails immediately after calling SyncAccessHandle.close promise_test: Unhandled rejection with value: object "InvalidStateError: The object is in an invalid state."
     6FAIL SyncAccessHandle.write fails after SyncAccessHandle.close settles promise_test: Unhandled rejection with value: object "InvalidStateError: The object is in an invalid state."
     7FAIL SyncAccessHandle.write fails immediately after calling SyncAccessHandle.close promise_test: Unhandled rejection with value: object "InvalidStateError: The object is in an invalid state."
    88FAIL SyncAccessHandle.flush fails after SyncAccessHandle.close settles promise_rejects_dom: function "function () { throw e }" threw object "UnknownError: The operation failed for an unknown transient reason (e.g. out of memory)." that is not a DOMException InvalidStateError: property "code" is equal to 0, expected 11
    99FAIL SyncAccessHandle.flush fails immediately after calling SyncAccessHandle.close promise_rejects_dom: function "function () { throw e }" threw object "UnknownError: The operation failed for an unknown transient reason (e.g. out of memory)." that is not a DOMException InvalidStateError: property "code" is equal to 0, expected 11
  • trunk/LayoutTests/imported/w3c/web-platform-tests/file-system-access/sandboxed_FileSystemSyncAccessHandle-flush.https.tentative.worker-expected.txt

    r283881 r284059  
    11
    22PASS Test flush on an empty file.
    3 FAIL SyncAccessHandle.read returns bytes written by SyncAccessHandle.write after SyncAccessHandle.flush promise_test: Unhandled rejection with value: object "TypeError: handle.write is not a function. (In 'handle.write(writeBuffer, {at: 0})', 'handle.write' is undefined)"
    4 FAIL SyncAccessHandle.read fails when there is a pending SyncAccessHandle.flush promise_test: Unhandled rejection with value: object "InvalidStateError: The object is in an invalid state."
    5 FAIL SyncAccessHandle.write fails when there is a pending SyncAccessHandle.flush promise_test: Unhandled rejection with value: object "InvalidStateError: The object is in an invalid state."
     3PASS SyncAccessHandle.read returns bytes written by SyncAccessHandle.write after SyncAccessHandle.flush
     4PASS SyncAccessHandle.read fails when there is a pending SyncAccessHandle.flush
     5PASS SyncAccessHandle.write fails when there is a pending SyncAccessHandle.flush
    66
  • trunk/LayoutTests/imported/w3c/web-platform-tests/file-system-access/sandboxed_FileSystemSyncAccessHandle-getSize.https.tentative.worker-expected.txt

    r283881 r284059  
    11
    2 FAIL test SyncAccessHandle.getSize after SyncAccessHandle.write promise_test: Unhandled rejection with value: object "TypeError: handle.write is not a function. (In 'handle.write(writeBuffer, {at: 0})', 'handle.write' is undefined)"
    3 FAIL test createSyncAccessHandle.getSize with pending operation promise_test: Unhandled rejection with value: object "InvalidStateError: The object is in an invalid state."
     2PASS test SyncAccessHandle.getSize after SyncAccessHandle.write
     3FAIL test createSyncAccessHandle.getSize with pending operation assert_unreached: Should have rejected: undefined Reached unreachable code
    44
  • trunk/LayoutTests/imported/w3c/web-platform-tests/file-system-access/sandboxed_FileSystemSyncAccessHandle-read-write.https.tentative.worker-expected.txt

    r283881 r284059  
    11
    2 FAIL Test reading an empty file through a sync access handle. promise_test: Unhandled rejection with value: object "TypeError: handle.read is not a function. (In 'handle.read(readBuffer, {at: 0})', 'handle.read' is undefined)"
    3 FAIL Test writing and reading through a sync access handle. promise_test: Unhandled rejection with value: object "InvalidStateError: The object is in an invalid state."
    4 FAIL Test second write that is bigger than the first write promise_test: Unhandled rejection with value: object "InvalidStateError: The object is in an invalid state."
    5 FAIL Test second write that is smaller than the first write promise_test: Unhandled rejection with value: object "InvalidStateError: The object is in an invalid state."
    6 FAIL Test initial write with an offset promise_test: Unhandled rejection with value: object "InvalidStateError: The object is in an invalid state."
    7 FAIL Test overwriting the file at an offset promise_test: Unhandled rejection with value: object "InvalidStateError: The object is in an invalid state."
    8 FAIL Test read at an offset promise_test: Unhandled rejection with value: object "InvalidStateError: The object is in an invalid state."
    9 FAIL Test reading at a negative offset fails. promise_test: Unhandled rejection with value: object "InvalidStateError: The object is in an invalid state."
     2PASS Test reading an empty file through a sync access handle.
     3PASS Test writing and reading through a sync access handle.
     4PASS Test second write that is bigger than the first write
     5PASS Test second write that is smaller than the first write
     6PASS Test initial write with an offset
     7PASS Test overwriting the file at an offset
     8PASS Test read at an offset
     9FAIL Test reading at a negative offset fails. assert_throws_dom: function "() => handle.read(readBuffer, { at: -1 })" threw object "TypeError: Value -1 is outside the range [0, 9007199254740991]" that is not a DOMException NotSupportedError: property "code" is equal to undefined, expected 9
    1010
  • trunk/LayoutTests/imported/w3c/web-platform-tests/file-system-access/sandboxed_FileSystemSyncAccessHandle-truncate.https.tentative.worker-expected.txt

    r283881 r284059  
    22FAIL test createSyncAccessHandle.truncate with pending operation assert_unreached: Should have rejected: undefined Reached unreachable code
    33PASS test SyncAccessHandle.truncate with different sizes
    4 FAIL test SyncAccessHandle.truncate after SyncAccessHandle.write promise_test: Unhandled rejection with value: object "TypeError: handle.write is not a function. (In 'handle.write(writeBuffer, {at: 0})', 'handle.write' is undefined)"
     4PASS test SyncAccessHandle.truncate after SyncAccessHandle.write
    55
  • trunk/Source/WTF/ChangeLog

    r284057 r284059  
     12021-10-12  Sihui Liu  <sihui_liu@apple.com>
     2
     3        Implement FileSystemSyncAccessHandle read() and write()
     4        https://bugs.webkit.org/show_bug.cgi?id=231466
     5        <rdar://problem/84050394>
     6
     7        Reviewed by Youenn Fablet.
     8
     9        * wtf/PlatformHave.h:
     10
    1112021-10-12  Chris Dumez  <cdumez@apple.com>
    212
  • trunk/Source/WebCore/ChangeLog

    r284057 r284059  
     12021-10-12  Sihui Liu  <sihui_liu@apple.com>
     2
     3        Implement FileSystemSyncAccessHandle read() and write()
     4        https://bugs.webkit.org/show_bug.cgi?id=231466
     5        <rdar://problem/84050394>
     6
     7        Reviewed by Youenn Fablet.
     8
     9        Implement read() and write() according to proposal:
     10        https://github.com/WICG/file-system-access/blob/main/AccessHandle.md
     11
     12        Test: storage/filesystemaccess/sync-access-handle-read-write-worker.html
     13        API test: FileSystemAccess.ProcessCrashDuringWrite
     14
     15        * Modules/filesystemaccess/FileSystemFileHandle.cpp:
     16        (WebCore::FileSystemFileHandle::createSyncAccessHandle):
     17        (WebCore::FileSystemFileHandle::getSize):
     18        (WebCore::FileSystemFileHandle::truncate):
     19        (WebCore::FileSystemFileHandle::flush):
     20        * Modules/filesystemaccess/FileSystemFileHandle.h:
     21        * Modules/filesystemaccess/FileSystemStorageConnection.h:
     22        * Modules/filesystemaccess/FileSystemSyncAccessHandle.cpp:
     23        (WebCore::FileSystemSyncAccessHandle::create):
     24        (WebCore::FileSystemSyncAccessHandle::FileSystemSyncAccessHandle):
     25        (WebCore::FileSystemSyncAccessHandle::truncate):
     26        (WebCore::FileSystemSyncAccessHandle::getSize):
     27        (WebCore::FileSystemSyncAccessHandle::flush):
     28        (WebCore::FileSystemSyncAccessHandle::close):
     29        (WebCore::FileSystemSyncAccessHandle::read):
     30        (WebCore::FileSystemSyncAccessHandle::write):
     31        * Modules/filesystemaccess/FileSystemSyncAccessHandle.h:
     32        * Modules/filesystemaccess/FileSystemSyncAccessHandle.idl:
     33        * Modules/filesystemaccess/WorkerFileSystemStorageConnection.cpp:
     34        (WebCore::WorkerFileSystemStorageConnection::didCreateSyncAccessHandle):
     35        (WebCore::WorkerFileSystemStorageConnection::createSyncAccessHandle):
     36        * Modules/filesystemaccess/WorkerFileSystemStorageConnection.h:
     37        * bindings/js/BufferSource.h:
     38        (WebCore::BufferSource::mutableData const):
     39
    1402021-10-12  Chris Dumez  <cdumez@apple.com>
    241
  • trunk/Source/WebCore/Modules/filesystemaccess/FileSystemFileHandle.cpp

    r283881 r284059  
    5858            return promise.reject(result.releaseException());
    5959
    60         promise.settle(FileSystemSyncAccessHandle::create(protectedThis.get(), result.returnValue()));
     60        auto resultValue = result.releaseReturnValue();
     61        promise.settle(FileSystemSyncAccessHandle::create(protectedThis.get(), resultValue.first, resultValue.second));
    6162    });
    6263}
    6364
    64 void FileSystemFileHandle::getSize(FileSystemSyncAccessHandleIdentifier accessHandleIdentifier, DOMPromiseDeferred<IDLUnsignedLongLong>&& promise)
     65void FileSystemFileHandle::getSize(FileSystemSyncAccessHandleIdentifier accessHandleIdentifier, CompletionHandler<void(ExceptionOr<uint64_t>&&)>&& completionHandler)
    6566{
    66     connection().getSize(identifier(), accessHandleIdentifier, [promise = WTFMove(promise)](auto result) mutable {
    67         promise.settle(WTFMove(result));
    68     });
     67    connection().getSize(identifier(), accessHandleIdentifier, WTFMove(completionHandler));
    6968}
    7069
    71 void FileSystemFileHandle::truncate(FileSystemSyncAccessHandleIdentifier accessHandleIdentifier, unsigned long long size, DOMPromiseDeferred<void>&& promise)
     70void FileSystemFileHandle::truncate(FileSystemSyncAccessHandleIdentifier accessHandleIdentifier, unsigned long long size, CompletionHandler<void(ExceptionOr<void>&&)>&& completionHandler)
    7271{
    73     connection().truncate(identifier(), accessHandleIdentifier, size, [promise = WTFMove(promise)](auto result) mutable {
    74         promise.settle(WTFMove(result));
    75     });
     72    connection().truncate(identifier(), accessHandleIdentifier, size, WTFMove(completionHandler));
    7673}
    7774
    78 void FileSystemFileHandle::flush(FileSystemSyncAccessHandleIdentifier accessHandleIdentifier, DOMPromiseDeferred<void>&& promise)
     75void FileSystemFileHandle::flush(FileSystemSyncAccessHandleIdentifier accessHandleIdentifier, CompletionHandler<void(ExceptionOr<void>&&)>&& completionHandler)
    7976{
    80     connection().flush(identifier(), accessHandleIdentifier, [promise = WTFMove(promise)](auto result) mutable {
    81         promise.settle(WTFMove(result));
    82     });
     77    connection().flush(identifier(), accessHandleIdentifier, WTFMove(completionHandler));
    8378}
    8479
  • trunk/Source/WebCore/Modules/filesystemaccess/FileSystemFileHandle.h

    r283676 r284059  
    4242
    4343    void createSyncAccessHandle(DOMPromiseDeferred<IDLInterface<FileSystemSyncAccessHandle>>&&);
    44     void getSize(FileSystemSyncAccessHandleIdentifier, DOMPromiseDeferred<IDLUnsignedLongLong>&&);
    45     void truncate(FileSystemSyncAccessHandleIdentifier, unsigned long long size, DOMPromiseDeferred<void>&&);
    46     void flush(FileSystemSyncAccessHandleIdentifier, DOMPromiseDeferred<void>&&);
     44    void getSize(FileSystemSyncAccessHandleIdentifier, CompletionHandler<void(ExceptionOr<uint64_t>&&)>&&);
     45    void truncate(FileSystemSyncAccessHandleIdentifier, unsigned long long size, CompletionHandler<void(ExceptionOr<void>&&)>&&);
     46    void flush(FileSystemSyncAccessHandleIdentifier, CompletionHandler<void(ExceptionOr<void>&&)>&&);
    4747    void close(FileSystemSyncAccessHandleIdentifier, CompletionHandler<void(ExceptionOr<void>&&)>&&);
    4848
  • trunk/Source/WebCore/Modules/filesystemaccess/FileSystemStorageConnection.h

    r283881 r284059  
    2929#include "FileSystemSyncAccessHandleIdentifier.h"
    3030#include <wtf/CompletionHandler.h>
     31#include <wtf/FileSystem.h>
    3132#include <wtf/ThreadSafeRefCounted.h>
    3233
     
    4445    using GetHandleCallback = CompletionHandler<void(ExceptionOr<FileSystemHandleIdentifier>&&)>;
    4546    using ResolveCallback = CompletionHandler<void(ExceptionOr<Vector<String>>&&)>;
    46     using GetAccessHandleCallback = CompletionHandler<void(ExceptionOr<FileSystemSyncAccessHandleIdentifier>&&)>;
     47    using GetAccessHandleCallback = CompletionHandler<void(ExceptionOr<std::pair<FileSystemSyncAccessHandleIdentifier, FileSystem::PlatformFileHandle>>&&)>;
    4748    using VoidCallback = CompletionHandler<void(ExceptionOr<void>&&)>;
    4849    using IntegerCallback = CompletionHandler<void(ExceptionOr<uint64_t>&&)>;
  • trunk/Source/WebCore/Modules/filesystemaccess/FileSystemSyncAccessHandle.cpp

    r283676 r284059  
    3535namespace WebCore {
    3636
    37 Ref<FileSystemSyncAccessHandle> FileSystemSyncAccessHandle::create(FileSystemFileHandle& source, FileSystemSyncAccessHandleIdentifier identifier)
     37Ref<FileSystemSyncAccessHandle> FileSystemSyncAccessHandle::create(FileSystemFileHandle& source, FileSystemSyncAccessHandleIdentifier identifier, FileSystem::PlatformFileHandle file)
    3838{
    39     return adoptRef(*new FileSystemSyncAccessHandle(source, identifier));
     39    return adoptRef(*new FileSystemSyncAccessHandle(source, identifier, file));
    4040}
    4141
    42 FileSystemSyncAccessHandle::FileSystemSyncAccessHandle(FileSystemFileHandle& source, FileSystemSyncAccessHandleIdentifier identifier)
     42FileSystemSyncAccessHandle::FileSystemSyncAccessHandle(FileSystemFileHandle& source, FileSystemSyncAccessHandleIdentifier identifier, FileSystem::PlatformFileHandle file)
    4343    : m_source(source)
    4444    , m_identifier(identifier)
     45    , m_file(file)
    4546{
    4647}
     
    5455void FileSystemSyncAccessHandle::truncate(unsigned long long size, DOMPromiseDeferred<void>&& promise)
    5556{
    56     m_source->truncate(m_identifier, size, WTFMove(promise));
     57    m_pendingOperationCount++;
     58    m_source->truncate(m_identifier, size, [weakThis = makeWeakPtr(*this), promise = WTFMove(promise)](auto result) mutable {
     59        if (weakThis)
     60            weakThis->m_pendingOperationCount--;
     61
     62        promise.settle(WTFMove(result));
     63    });
    5764}
    5865
    5966void FileSystemSyncAccessHandle::getSize(DOMPromiseDeferred<IDLUnsignedLongLong>&& promise)
    6067{
    61     m_source->getSize(m_identifier, WTFMove(promise));
     68    m_pendingOperationCount++;
     69    m_source->getSize(m_identifier, [weakThis = makeWeakPtr(*this), promise = WTFMove(promise)](auto result) mutable {
     70        if (weakThis)
     71            weakThis->m_pendingOperationCount--;
     72
     73        promise.settle(WTFMove(result));
     74    });
    6275}
    6376
    6477void FileSystemSyncAccessHandle::flush(DOMPromiseDeferred<void>&& promise)
    6578{
    66     m_source->flush(m_identifier, WTFMove(promise));
     79    m_pendingOperationCount++;
     80    m_source->flush(m_identifier, [weakThis = makeWeakPtr(*this), promise = WTFMove(promise)](auto result) mutable {
     81        if (weakThis)
     82            weakThis->m_pendingOperationCount--;
     83
     84        promise.settle(WTFMove(result));
     85    });
    6786}
    6887
     
    7291        return promise.reject(Exception { InvalidStateError });
    7392
     93    m_pendingOperationCount++;
    7494    m_source->close(m_identifier, [weakThis = makeWeakPtr(*this), promise = WTFMove(promise)](auto result) mutable {
    75         if (weakThis)
     95        if (weakThis) {
     96            weakThis->m_pendingOperationCount--;
    7697            weakThis->didClose();
     98        }
    7799
    78100        promise.settle(WTFMove(result));
     
    85107}
    86108
     109ExceptionOr<unsigned long long> FileSystemSyncAccessHandle::read(BufferSource&& buffer, FileSystemSyncAccessHandle::FilesystemReadWriteOptions options)
     110{
     111    ASSERT(!isMainThread());
     112
     113    if (m_file == FileSystem::invalidPlatformFileHandle || m_isClosed)
     114        return Exception { InvalidStateError };
     115
     116    if (m_pendingOperationCount)
     117        return Exception { InvalidStateError, "Access handle has unfinished operation"_s };
     118
     119    int result = FileSystem::seekFile(m_file, options.at, FileSystem::FileSeekOrigin::Beginning);
     120    if (result == -1)
     121        return Exception { InvalidStateError, "Failed to read at offset"_s };
     122
     123    result = FileSystem::readFromFile(m_file, buffer.mutableData(), buffer.length());
     124    if (result == -1)
     125        return Exception { InvalidStateError, "Failed to read from file"_s };
     126
     127    return result;
     128}
     129
     130ExceptionOr<unsigned long long> FileSystemSyncAccessHandle::write(BufferSource&& buffer, FileSystemSyncAccessHandle::FilesystemReadWriteOptions options)
     131{
     132    ASSERT(!isMainThread());
     133
     134    if (m_file == FileSystem::invalidPlatformFileHandle || m_isClosed)
     135        return Exception { InvalidStateError };
     136
     137    if (m_pendingOperationCount)
     138        return Exception { InvalidStateError, "Access handle has unfinished operation"_s };
     139
     140    int result = FileSystem::seekFile(m_file, options.at, FileSystem::FileSeekOrigin::Beginning);
     141    if (result == -1)
     142        return Exception { InvalidStateError, "Failed to write at offset"_s };
     143
     144    result = FileSystem::writeToFile(m_file, buffer.data(), buffer.length());
     145    if (result == -1)
     146        return Exception { InvalidStateError, "Failed to write to file"_s };
     147
     148    return result;
     149}
     150
    87151} // namespace WebCore
  • trunk/Source/WebCore/Modules/filesystemaccess/FileSystemSyncAccessHandle.h

    r283676 r284059  
    2626#pragma once
    2727
     28#include "BufferSource.h"
    2829#include "FileSystemSyncAccessHandleIdentifier.h"
    2930#include "IDLTypes.h"
     31#include <wtf/FileSystem.h>
    3032#include <wtf/WeakPtr.h>
    3133
     
    3436class FileSystemFileHandle;
    3537template<typename> class DOMPromiseDeferred;
     38template<typename> class ExceptionOr;
    3639
    3740class FileSystemSyncAccessHandle : public RefCounted<FileSystemSyncAccessHandle>, public CanMakeWeakPtr<FileSystemSyncAccessHandle> {
     
    4144    };
    4245
    43     static Ref<FileSystemSyncAccessHandle> create(FileSystemFileHandle&, FileSystemSyncAccessHandleIdentifier);
     46    static Ref<FileSystemSyncAccessHandle> create(FileSystemFileHandle&, FileSystemSyncAccessHandleIdentifier, FileSystem::PlatformFileHandle);
    4447    ~FileSystemSyncAccessHandle();
    4548
     
    4952    void close(DOMPromiseDeferred<void>&&);
    5053    void didClose();
     54    ExceptionOr<unsigned long long> read(BufferSource&&, FilesystemReadWriteOptions);
     55    ExceptionOr<unsigned long long> write(BufferSource&&, FilesystemReadWriteOptions);
    5156
    5257private:
    53     FileSystemSyncAccessHandle(FileSystemFileHandle&, FileSystemSyncAccessHandleIdentifier);
     58    FileSystemSyncAccessHandle(FileSystemFileHandle&, FileSystemSyncAccessHandleIdentifier, FileSystem::PlatformFileHandle);
    5459
    5560    Ref<FileSystemFileHandle> m_source;
    5661    FileSystemSyncAccessHandleIdentifier m_identifier;
    5762    bool m_isClosed { false };
     63    uint64_t m_pendingOperationCount { 0 };
     64    FileSystem::PlatformFileHandle m_file;
    5865};
    5966
  • trunk/Source/WebCore/Modules/filesystemaccess/FileSystemSyncAccessHandle.idl

    r283676 r284059  
    3434    Promise<undefined> flush();
    3535    Promise<undefined> close();
     36    unsigned long long read([AllowShared] BufferSource buffer, FilesystemReadWriteOptions options);
     37    unsigned long long write([AllowShared] BufferSource buffer, FilesystemReadWriteOptions options);
    3638};
    3739
  • trunk/Source/WebCore/Modules/filesystemaccess/WorkerFileSystemStorageConnection.cpp

    r284057 r284059  
    194194}
    195195
    196 void WorkerFileSystemStorageConnection::didCreateSyncAccessHandle(CallbackIdentifier callbackIdentifier, ExceptionOr<FileSystemSyncAccessHandleIdentifier>&& result)
     196void WorkerFileSystemStorageConnection::didCreateSyncAccessHandle(CallbackIdentifier callbackIdentifier, ExceptionOr<std::pair<FileSystemSyncAccessHandleIdentifier, FileSystem::PlatformFileHandle>>&& result)
    197197{
    198198    if (auto callback = m_getAccessHandlCallbacks.take(callbackIdentifier))
     
    222222    callOnMainThread([callbackIdentifier, workerThread = Ref { m_scope->thread() }, mainThreadConnection = m_mainThreadConnection, identifier]() mutable {
    223223        auto mainThreadCallback = [callbackIdentifier, workerThread = WTFMove(workerThread)](auto result) mutable {
    224             workerThread->runLoop().postTaskForMode([callbackIdentifier, result = crossThreadCopy(result)] (auto& scope) mutable {
     224            auto crossThreadResult = result;
     225            if (result.hasException())
     226                crossThreadResult = crossThreadCopy(result.exception());
     227            workerThread->runLoop().postTaskForMode([callbackIdentifier, result = WTFMove(crossThreadResult)] (auto& scope) mutable {
    225228                if (auto connection = downcast<WorkerGlobalScope>(scope).fileSystemStorageConnection())
    226229                    connection->didCreateSyncAccessHandle(callbackIdentifier, WTFMove(result));
  • trunk/Source/WebCore/Modules/filesystemaccess/WorkerFileSystemStorageConnection.h

    r283881 r284059  
    4848    void didGetHandle(CallbackIdentifier, ExceptionOr<FileSystemHandleIdentifier>&&);
    4949    void didResolve(CallbackIdentifier, ExceptionOr<Vector<String>>&&);
    50     void didCreateSyncAccessHandle(CallbackIdentifier, ExceptionOr<FileSystemSyncAccessHandleIdentifier>&& result);
     50    void didCreateSyncAccessHandle(CallbackIdentifier, ExceptionOr<std::pair<FileSystemSyncAccessHandleIdentifier, FileSystem::PlatformFileHandle>>&&);
    5151    void completeVoidCallback(CallbackIdentifier, ExceptionOr<void>&& result);
    5252    void completeIntegerCallback(CallbackIdentifier, ExceptionOr<uint64_t>&& result);
  • trunk/Source/WebCore/PAL/ChangeLog

    r284009 r284059  
     12021-10-12  Sihui Liu  <sihui_liu@apple.com>
     2
     3        Implement FileSystemSyncAccessHandle read() and write()
     4        https://bugs.webkit.org/show_bug.cgi?id=231466
     5        <rdar://problem/84050394>
     6
     7        Reviewed by Youenn Fablet.
     8
     9        * PAL.xcodeproj/project.pbxproj:
     10        * pal/spi/cocoa/FilePortSPI.h: Added.
     11
    1122021-10-12  Chris Dumez  <cdumez@apple.com>
    213
  • trunk/Source/WebCore/PAL/PAL.xcodeproj/project.pbxproj

    r282313 r284059  
    155155                7A36D0F9223AD9AB00B0522E /* CommonCryptoSPI.h in Headers */ = {isa = PBXBuildFile; fileRef = 7A36D0F8223AD9AB00B0522E /* CommonCryptoSPI.h */; };
    156156                7A3A6A8020CADB4700317AAE /* NSImageSPI.h in Headers */ = {isa = PBXBuildFile; fileRef = 7A3A6A7F20CADB4600317AAE /* NSImageSPI.h */; };
     157                93468E672714A7CD009983E3 /* FilePortSPI.h in Headers */ = {isa = PBXBuildFile; fileRef = 93468E662714A7CD009983E3 /* FilePortSPI.h */; };
    157158                93B38EBE25821CB600198E63 /* SpeechSoftLink.h in Headers */ = {isa = PBXBuildFile; fileRef = 93B38EBD25821CB600198E63 /* SpeechSoftLink.h */; };
    158159                93B38EC025821CD800198E63 /* SpeechSoftLink.mm in Sources */ = {isa = PBXBuildFile; fileRef = 93B38EBF25821CD700198E63 /* SpeechSoftLink.mm */; };
     
    377378                7A36D0F8223AD9AB00B0522E /* CommonCryptoSPI.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CommonCryptoSPI.h; sourceTree = "<group>"; };
    378379                7A3A6A7F20CADB4600317AAE /* NSImageSPI.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = NSImageSPI.h; sourceTree = "<group>"; };
     380                93468E662714A7CD009983E3 /* FilePortSPI.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FilePortSPI.h; sourceTree = "<group>"; };
    379381                93B38EBD25821CB600198E63 /* SpeechSoftLink.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SpeechSoftLink.h; sourceTree = "<group>"; };
    380382                93B38EBF25821CD700198E63 /* SpeechSoftLink.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = SpeechSoftLink.mm; sourceTree = "<group>"; };
     
    535537                                0C2DA1251F3BEB4900DBC317 /* DataDetectorsCoreSPI.h */,
    536538                                1D12CC4A2411BCAE00FDA0A3 /* FeatureFlagsSPI.h */,
     539                                93468E662714A7CD009983E3 /* FilePortSPI.h */,
    537540                                CE5673862151A7B9002F92D7 /* IOKitSPI.h */,
    538541                                0C2DA1261F3BEB4900DBC317 /* IOPMLibSPI.h */,
     
    901904                                0C2D9E731EEF5AF600DBC317 /* ExportMacros.h in Headers */,
    902905                                1D12CC4B2411BCAE00FDA0A3 /* FeatureFlagsSPI.h in Headers */,
     906                                93468E672714A7CD009983E3 /* FilePortSPI.h in Headers */,
    903907                                F44291601FA5261E002CC93E /* FileSizeFormatter.h in Headers */,
    904908                                0C5AF91B1F43A4C7002EAC02 /* GraphicsServicesSPI.h in Headers */,
  • trunk/Source/WebCore/PAL/pal/spi/cocoa/FilePortSPI.h

    r284058 r284059  
    2424 */
    2525
    26 [
    27     EnabledBySetting=AccessHandleEnabled,
    28     ImplementationLacksVTable,
    29     Exposed=DedicatedWorker,
    30     SecureContext
    31 ] interface FileSystemSyncAccessHandle {
    32     Promise<undefined> truncate([EnforceRange] unsigned long long size);
    33     Promise<unsigned long long> getSize();
    34     Promise<undefined> flush();
    35     Promise<undefined> close();
    36 };
     26#pragma once
    3727
    38 dictionary FilesystemReadWriteOptions {
    39     [EnforceRange] unsigned long long at;
    40 };
     28#if USE(APPLE_INTERNAL_SDK)
     29
     30#include <System/sys/fileport.h>
     31
     32#else
     33
     34extern "C" {
     35int fileport_makeport(int, mach_port_t*);
     36int fileport_makefd(mach_port_t);
     37}
     38
     39#endif // #if USE(APPLE_INTERNAL_SDK)
     40
  • trunk/Source/WebCore/bindings/js/BufferSource.h

    r284016 r284059  
    5050        }, m_variant);
    5151    }
     52   
     53    void* mutableData() const
     54    {
     55        return std::visit([](auto& buffer) -> void* {
     56            return buffer->data();
     57        }, m_variant);
     58    }
    5259
    5360    size_t length() const
  • trunk/Source/WebKit/ChangeLog

    r284057 r284059  
     12021-10-12  Sihui Liu  <sihui_liu@apple.com>
     2
     3        Implement FileSystemSyncAccessHandle read() and write()
     4        https://bugs.webkit.org/show_bug.cgi?id=231466
     5        <rdar://problem/84050394>
     6
     7        Reviewed by Youenn Fablet.
     8
     9        Let network process open the file and pass file descriptor to web process, so that web process can read and
     10        write the file without sending IPC messages. Currently getting file size, truncating file and syncing file are
     11        still performed by network process.
     12
     13        * NetworkProcess/storage/FileSystemStorageError.h:
     14        (WebKit::convertToException):
     15        * NetworkProcess/storage/FileSystemStorageHandle.cpp:
     16        (WebKit::FileSystemStorageHandle::createSyncAccessHandle):
     17        (WebKit::FileSystemStorageHandle::truncate):
     18        (WebKit::FileSystemStorageHandle::flush):
     19        (WebKit::FileSystemStorageHandle::close):
     20        * NetworkProcess/storage/FileSystemStorageHandle.h:
     21        * NetworkProcess/storage/NetworkStorageManager.cpp:
     22        (WebKit::NetworkStorageManager::createSyncAccessHandle):
     23        * NetworkProcess/storage/NetworkStorageManager.h:
     24        * NetworkProcess/storage/NetworkStorageManager.messages.in:
     25        * Platform/IPC/SharedFileHandle.cpp: Added.
     26        (IPC::SharedFileHandle::create):
     27        (IPC::SharedFileHandle::encode const):
     28        (IPC::SharedFileHandle::decode):
     29        * Platform/IPC/SharedFileHandle.h: Added.
     30        (IPC::SharedFileHandle::handle):
     31        (IPC::SharedFileHandle::SharedFileHandle):
     32        * Platform/IPC/cocoa/SharedFileHandleCocoa.cpp: Added.
     33        (IPC::SharedFileHandle::create):
     34        (IPC::SharedFileHandle::encode const):
     35        (IPC::SharedFileHandle::decode):
     36        * Sources.txt:
     37        * UIProcess/API/Cocoa/WKPreferences.mm:
     38        (-[WKPreferences _fileSystemAccessEnabled]):
     39        (-[WKPreferences _setFileSystemAccessEnabled:]):
     40        (-[WKPreferences _storageAPIEnabled]):
     41        (-[WKPreferences _setStorageAPIEnabled:]):
     42        (-[WKPreferences _accessHandleEnabled]):
     43        (-[WKPreferences _setAccessHandleEnabled:]):
     44        * UIProcess/API/Cocoa/WKPreferencesPrivate.h:
     45        * WebKit.xcodeproj/project.pbxproj:
     46        * WebProcess/WebCoreSupport/WebFileSystemStorageConnection.cpp:
     47        (WebKit::WebFileSystemStorageConnection::createSyncAccessHandle):
     48        * WebProcess/com.apple.WebProcess.sb.in:
     49
    1502021-10-12  Chris Dumez  <cdumez@apple.com>
    251
  • trunk/Source/WebKit/NetworkProcess/storage/FileSystemStorageError.h

    r283676 r284059  
    3232
    3333enum class FileSystemStorageError : uint8_t {
     34    BackendNotSupported,
    3435    FileNotFound,
     36    InvalidModification,
    3537    InvalidName,
    36     InvalidModification,
    3738    InvalidState,
    3839    TypeMismatch,
     
    4344{
    4445    switch (error) {
     46    case FileSystemStorageError::BackendNotSupported:
     47        return WebCore::Exception { WebCore::NotSupportedError, "Backend does not support this operation" };
    4548    case FileSystemStorageError::FileNotFound:
    4649        return WebCore::Exception { WebCore::NotFoundError };
    4750    case FileSystemStorageError::InvalidModification:
    4851        return WebCore::Exception { WebCore::InvalidModificationError };
    49     case FileSystemStorageError::TypeMismatch:
    50         return WebCore::Exception { WebCore::TypeError };
    5152    case FileSystemStorageError::InvalidName:
    5253        return WebCore::Exception { WebCore::UnknownError, "Name is invalid" };
    5354    case FileSystemStorageError::InvalidState:
    5455        return WebCore::Exception { WebCore::InvalidStateError };
     56    case FileSystemStorageError::TypeMismatch:
     57        return WebCore::Exception { WebCore::TypeError };
    5558    case FileSystemStorageError::Unknown:
    5659        break;
     
    7578    using values = EnumValues<
    7679        WebKit::FileSystemStorageError,
     80        WebKit::FileSystemStorageError::BackendNotSupported,
    7781        WebKit::FileSystemStorageError::FileNotFound,
     82        WebKit::FileSystemStorageError::InvalidModification,
    7883        WebKit::FileSystemStorageError::InvalidName,
    79         WebKit::FileSystemStorageError::InvalidModification,
    8084        WebKit::FileSystemStorageError::InvalidState,
    8185        WebKit::FileSystemStorageError::TypeMismatch,
  • trunk/Source/WebKit/NetworkProcess/storage/FileSystemStorageHandle.cpp

    r283881 r284059  
    2929#include "FileSystemStorageError.h"
    3030#include "FileSystemStorageManager.h"
     31#include "SharedFileHandle.h"
    3132#include <wtf/Scope.h>
    3233
     
    144145}
    145146
    146 Expected<WebCore::FileSystemSyncAccessHandleIdentifier, FileSystemStorageError> FileSystemStorageHandle::createSyncAccessHandle()
     147Expected<FileSystemStorageHandle::AccessHandleInfo, FileSystemStorageError> FileSystemStorageHandle::createSyncAccessHandle()
    147148{
    148149    if (!m_manager)
     
    153154        return makeUnexpected(FileSystemStorageError::InvalidState);
    154155
     156    m_handle = FileSystem::openFile(m_path, FileSystem::FileOpenMode::ReadWrite);
     157    if (m_handle == FileSystem::invalidPlatformFileHandle)
     158        return makeUnexpected(FileSystemStorageError::Unknown);
     159
     160    auto ipcHandle = IPC::SharedFileHandle::create(m_handle);
     161    if (!ipcHandle) {
     162        FileSystem::closeFile(m_handle);
     163        m_handle = FileSystem::invalidPlatformFileHandle;
     164        return makeUnexpected(FileSystemStorageError::BackendNotSupported);
     165    }
     166
    155167    ASSERT(!m_activeSyncAccessHandle);
    156168    m_activeSyncAccessHandle = WebCore::FileSystemSyncAccessHandleIdentifier::generateThreadSafe();
    157     return *m_activeSyncAccessHandle;
     169    return std::pair { *m_activeSyncAccessHandle, WTFMove(*ipcHandle) };
    158170}
    159171
     
    181193        return FileSystemStorageError::Unknown;
    182194
    183     auto handle = FileSystem::openFile(m_path, FileSystem::FileOpenMode::ReadWrite);
    184     auto closeFileScope = makeScopeExit([&] {
    185         FileSystem::closeFile(handle);
    186     });
    187 
    188     auto result = FileSystem::truncateFile(handle, size);
     195    ASSERT(m_handle != FileSystem::invalidPlatformFileHandle);
     196    auto result = FileSystem::truncateFile(m_handle, size);
    189197    if (!result)
    190198        return FileSystemStorageError::Unknown;
     
    201209        return FileSystemStorageError::Unknown;
    202210
    203     // FIXME: when write operation is implemented, perform actual flush here.
     211    ASSERT(m_handle != FileSystem::invalidPlatformFileHandle);
     212    auto result = FileSystem::flushFile(m_handle);
     213    if (!result)
     214        return FileSystemStorageError::Unknown;
     215
    204216    return std::nullopt;
    205217}
     
    212224    if (!m_activeSyncAccessHandle || *m_activeSyncAccessHandle != accessHandleIdentifier)
    213225        return FileSystemStorageError::Unknown;
     226
     227    ASSERT(m_handle != FileSystem::invalidPlatformFileHandle);
     228    FileSystem::closeFile(m_handle);
     229    m_handle = FileSystem::invalidPlatformFileHandle;
    214230
    215231    m_manager->releaseLockForFile(m_path, m_identifier);
  • trunk/Source/WebKit/NetworkProcess/storage/FileSystemStorageHandle.h

    r283881 r284059  
    3131#include <wtf/WeakPtr.h>
    3232
     33namespace IPC {
     34class SharedFileHandle;
     35}
     36
    3337namespace WebKit {
    3438
     
    5458    Expected<std::pair<WebCore::FileSystemHandleIdentifier, bool>, FileSystemStorageError> getHandle(IPC::Connection::UniqueID, String&& name);
    5559
    56     Expected<WebCore::FileSystemSyncAccessHandleIdentifier, FileSystemStorageError> createSyncAccessHandle();
     60    using AccessHandleInfo = std::pair<WebCore::FileSystemSyncAccessHandleIdentifier, IPC::SharedFileHandle>;
     61    Expected<AccessHandleInfo, FileSystemStorageError> createSyncAccessHandle();
    5762    Expected<uint64_t, FileSystemStorageError> getSize(WebCore::FileSystemSyncAccessHandleIdentifier);
    5863    std::optional<FileSystemStorageError> truncate(WebCore::FileSystemSyncAccessHandleIdentifier, uint64_t size);
     
    6974    String m_name;
    7075    std::optional<WebCore::FileSystemSyncAccessHandleIdentifier> m_activeSyncAccessHandle;
     76    FileSystem::PlatformFileHandle m_handle { FileSystem::invalidPlatformFileHandle };
    7177};
    7278
  • trunk/Source/WebKit/NetworkProcess/storage/NetworkStorageManager.cpp

    r283881 r284059  
    227227}
    228228
    229 void NetworkStorageManager::createSyncAccessHandle(WebCore::FileSystemHandleIdentifier identifier, CompletionHandler<void(Expected<WebCore::FileSystemSyncAccessHandleIdentifier, FileSystemStorageError>)>&& completionHandler)
     229void NetworkStorageManager::createSyncAccessHandle(WebCore::FileSystemHandleIdentifier identifier, CompletionHandler<void(Expected<AccessHandleInfo, FileSystemStorageError>)>&& completionHandler)
    230230{
    231231    ASSERT(!RunLoop::isMain());
  • trunk/Source/WebKit/NetworkProcess/storage/NetworkStorageManager.h

    r283881 r284059  
    3333#include <WebCore/FileSystemSyncAccessHandleIdentifier.h>
    3434#include <pal/SessionID.h>
     35
     36namespace IPC {
     37class SharedFileHandle;
     38}
    3539
    3640namespace WebCore {
     
    7175    void removeEntry(WebCore::FileSystemHandleIdentifier, const String& name, bool deleteRecursively, CompletionHandler<void(std::optional<FileSystemStorageError>)>&&);
    7276    void resolve(WebCore::FileSystemHandleIdentifier, WebCore::FileSystemHandleIdentifier, CompletionHandler<void(Expected<Vector<String>, FileSystemStorageError>)>&&);
    73     void createSyncAccessHandle(WebCore::FileSystemHandleIdentifier, CompletionHandler<void(Expected<WebCore::FileSystemSyncAccessHandleIdentifier, FileSystemStorageError>)>&&);
     77    using AccessHandleInfo = std::pair<WebCore::FileSystemSyncAccessHandleIdentifier, IPC::SharedFileHandle>;
     78    void createSyncAccessHandle(WebCore::FileSystemHandleIdentifier, CompletionHandler<void(Expected<AccessHandleInfo, FileSystemStorageError>)>&&);
    7479    void getSizeForAccessHandle(WebCore::FileSystemHandleIdentifier, WebCore::FileSystemSyncAccessHandleIdentifier, CompletionHandler<void(Expected<uint64_t, FileSystemStorageError>)>&&);
    7580    void truncateForAccessHandle(WebCore::FileSystemHandleIdentifier, WebCore::FileSystemSyncAccessHandleIdentifier, uint64_t size, CompletionHandler<void(std::optional<FileSystemStorageError>)>&&);
  • trunk/Source/WebKit/NetworkProcess/storage/NetworkStorageManager.messages.in

    r283881 r284059  
    3434    Resolve(WebCore::FileSystemHandleIdentifier identifier, WebCore::FileSystemHandleIdentifier targetIdentifier) -> (Expected<Vector<String>, WebKit::FileSystemStorageError> result) Async
    3535
    36     CreateSyncAccessHandle(WebCore::FileSystemHandleIdentifier identifier) -> (Expected<WebCore::FileSystemSyncAccessHandleIdentifier, WebKit::FileSystemStorageError> result) Async
     36    CreateSyncAccessHandle(WebCore::FileSystemHandleIdentifier identifier) -> (Expected<std::pair<WebCore::FileSystemSyncAccessHandleIdentifier, IPC::SharedFileHandle>, WebKit::FileSystemStorageError> result) Async
    3737    GetSizeForAccessHandle(WebCore::FileSystemHandleIdentifier identifier, WebCore::FileSystemSyncAccessHandleIdentifier accessHandleIdentifier) -> (Expected<uint64_t, WebKit::FileSystemStorageError> result) Async
    3838    TruncateForAccessHandle(WebCore::FileSystemHandleIdentifier identifier, WebCore::FileSystemSyncAccessHandleIdentifier accessHandleIdentifier, uint64_t size) -> (std::optional<WebKit::FileSystemStorageError> result) Async
  • trunk/Source/WebKit/Platform/IPC/SharedFileHandle.cpp

    r284058 r284059  
    2424 */
    2525
    26 [
    27     EnabledBySetting=AccessHandleEnabled,
    28     ImplementationLacksVTable,
    29     Exposed=DedicatedWorker,
    30     SecureContext
    31 ] interface FileSystemSyncAccessHandle {
    32     Promise<undefined> truncate([EnforceRange] unsigned long long size);
    33     Promise<unsigned long long> getSize();
    34     Promise<undefined> flush();
    35     Promise<undefined> close();
    36 };
     26#include "config.h"
     27#include "SharedFileHandle.h"
    3728
    38 dictionary FilesystemReadWriteOptions {
    39     [EnforceRange] unsigned long long at;
    40 };
     29namespace IPC {
     30
     31#if !PLATFORM(COCOA)
     32
     33std::optional<SharedFileHandle> SharedFileHandle::create(FileSystem::PlatformFileHandle)
     34{
     35    return std::nullopt;
     36}
     37
     38void SharedFileHandle::encode(Encoder&) const
     39{
     40}
     41
     42std::optional<SharedFileHandle> SharedFileHandle::decode(Decoder&)
     43{
     44    return std::nullopt;
     45}
     46
     47#endif
     48
     49} // namespace IPC
  • trunk/Source/WebKit/Platform/IPC/SharedFileHandle.h

    r284058 r284059  
    2424 */
    2525
    26 [
    27     EnabledBySetting=AccessHandleEnabled,
    28     ImplementationLacksVTable,
    29     Exposed=DedicatedWorker,
    30     SecureContext
    31 ] interface FileSystemSyncAccessHandle {
    32     Promise<undefined> truncate([EnforceRange] unsigned long long size);
    33     Promise<unsigned long long> getSize();
    34     Promise<undefined> flush();
    35     Promise<undefined> close();
     26#pragma once
     27
     28#include <fcntl.h>
     29#include <wtf/FileSystem.h>
     30
     31namespace IPC {
     32
     33class Decoder;
     34class Encoder;
     35
     36class SharedFileHandle {
     37public:
     38    static std::optional<SharedFileHandle> create(FileSystem::PlatformFileHandle);
     39
     40    SharedFileHandle() = default;
     41    FileSystem::PlatformFileHandle handle() { return m_handle; }
     42
     43    void encode(Encoder&) const;
     44
     45    static std::optional<SharedFileHandle> decode(Decoder&);
     46   
     47private:
     48    explicit SharedFileHandle(FileSystem::PlatformFileHandle handle)
     49        : m_handle(handle)
     50    {
     51    }
     52
     53    FileSystem::PlatformFileHandle m_handle { FileSystem::invalidPlatformFileHandle };
    3654};
    3755
    38 dictionary FilesystemReadWriteOptions {
    39     [EnforceRange] unsigned long long at;
    40 };
     56} // namespace IPC
     57
     58
  • trunk/Source/WebKit/Platform/IPC/cocoa/SharedFileHandleCocoa.cpp

    r284058 r284059  
    2424 */
    2525
    26 [
    27     EnabledBySetting=AccessHandleEnabled,
    28     ImplementationLacksVTable,
    29     Exposed=DedicatedWorker,
    30     SecureContext
    31 ] interface FileSystemSyncAccessHandle {
    32     Promise<undefined> truncate([EnforceRange] unsigned long long size);
    33     Promise<unsigned long long> getSize();
    34     Promise<undefined> flush();
    35     Promise<undefined> close();
    36 };
     26#include "config.h"
     27#include "SharedFileHandle.h"
    3728
    38 dictionary FilesystemReadWriteOptions {
    39     [EnforceRange] unsigned long long at;
    40 };
     29#include "MachPort.h"
     30#include <pal/spi/cocoa/FilePortSPI.h>
     31
     32namespace IPC {
     33
     34std::optional<SharedFileHandle> SharedFileHandle::create(FileSystem::PlatformFileHandle handle)
     35{
     36    return SharedFileHandle { handle };
     37}
     38
     39void SharedFileHandle::encode(Encoder& encoder) const
     40{
     41    mach_port_name_t fileport = MACH_PORT_NULL;
     42    if (fileport_makeport(m_handle, &fileport) == -1) {
     43        encoder << MachPort();
     44        return;
     45    }
     46
     47    encoder << MachPort(fileport, MACH_MSG_TYPE_MOVE_SEND);
     48}
     49
     50std::optional<SharedFileHandle> SharedFileHandle::decode(Decoder& decoder)
     51{
     52    MachPort machPort;
     53    if (!decoder.decode(machPort))
     54        return std::nullopt;
     55   
     56    int fd = fileport_makefd(machPort.port());
     57    if (fd == -1)
     58        return SharedFileHandle { };
     59
     60    return SharedFileHandle::create(fileport_makefd(machPort.port()));
     61}
     62
     63} // namespace IPC
  • trunk/Source/WebKit/Sources.txt

    r283941 r284059  
    174174Platform/IPC/StreamConnectionBuffer.cpp @no-unify
    175175Platform/IPC/StreamConnectionWorkQueue.cpp @no-unify
     176Platform/IPC/SharedFileHandle.cpp @no-unify
    176177Platform/IPC/StreamServerConnection.cpp @no-unify
    177178Platform/IPC/StringReference.cpp @no-unify
  • trunk/Source/WebKit/UIProcess/API/Cocoa/WKPreferences.mm

    r280298 r284059  
    15181518}
    15191519
     1520- (BOOL)_fileSystemAccessEnabled
     1521{
     1522    return _preferences->fileSystemAccessEnabled();
     1523}
     1524
     1525- (void)_setFileSystemAccessEnabled:(BOOL)fileSystemAccessEnabled
     1526{
     1527    _preferences->setFileSystemAccessEnabled(fileSystemAccessEnabled);
     1528}
     1529
     1530- (BOOL)_storageAPIEnabled
     1531{
     1532    return _preferences->storageAPIEnabled();
     1533}
     1534
     1535- (void)_setStorageAPIEnabled:(BOOL)storageAPIEnabled
     1536{
     1537    _preferences->setStorageAPIEnabled(storageAPIEnabled);
     1538}
     1539
     1540- (BOOL)_accessHandleEnabled
     1541{
     1542    return _preferences->accessHandleEnabled();
     1543}
     1544
     1545- (void)_setAccessHandleEnabled:(BOOL)accessHandleEnabled
     1546{
     1547    _preferences->setAccessHandleEnabled(accessHandleEnabled);
     1548}
     1549
    15201550@end
    15211551
  • trunk/Source/WebKit/UIProcess/API/Cocoa/WKPreferencesPrivate.h

    r280298 r284059  
    174174@property (nonatomic, getter=_isExtensibleSSOEnabled, setter=_setExtensibleSSOEnabled:) BOOL _extensibleSSOEnabled WK_API_AVAILABLE(macos(12.0), ios(15.0));
    175175@property (nonatomic, setter=_setRequiresPageVisibilityToPlayAudio:) BOOL _requiresPageVisibilityToPlayAudio WK_API_AVAILABLE(macos(12.0), ios(15.0));
     176@property (nonatomic, setter=_setFileSystemAccessEnabled:) BOOL _fileSystemAccessEnabled WK_API_AVAILABLE(macos(WK_MAC_TBA), ios(WK_IOS_TBA));
     177@property (nonatomic, setter=_setStorageAPIEnabled:) BOOL _storageAPIEnabled WK_API_AVAILABLE(macos(WK_MAC_TBA), ios(WK_IOS_TBA));
     178@property (nonatomic, setter=_setAccessHandleEnabled:) BOOL _accessHandleEnabled WK_API_AVAILABLE(macos(WK_MAC_TBA), ios(WK_IOS_TBA));
    176179
    177180#if !TARGET_OS_IPHONE
  • trunk/Source/WebKit/WebKit.xcodeproj/project.pbxproj

    r284055 r284059  
    14731473                93085DE026E5BCFD000EC6A7 /* NetworkStorageManager.h in Headers */ = {isa = PBXBuildFile; fileRef = 93085DC426E1BBBD000EC6A7 /* NetworkStorageManager.h */; };
    14741474                93085DE126E5BD13000EC6A7 /* NetworkStorageManagerMessages.h in Headers */ = {isa = PBXBuildFile; fileRef = 93085DCD26E2E902000EC6A7 /* NetworkStorageManagerMessages.h */; };
     1475                93122C862710CCDF001D819F /* SharedFileHandle.h in Headers */ = {isa = PBXBuildFile; fileRef = 93122C852710CCDE001D819F /* SharedFileHandle.h */; };
    14751476                9312BAD526F33C2600FDDF5F /* FileSystemStorageManager.h in Headers */ = {isa = PBXBuildFile; fileRef = 931A075026F06310004474CD /* FileSystemStorageManager.h */; };
    14761477                9312BAD626F33C2900FDDF5F /* FileSystemStorageHandle.h in Headers */ = {isa = PBXBuildFile; fileRef = 931A075326F06AB4004474CD /* FileSystemStorageHandle.h */; };
     
    14851486                933E835B23A1B75000DEF289 /* WebIDBServerMessageReceiver.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 933E835823A1ADF500DEF289 /* WebIDBServerMessageReceiver.cpp */; };
    14861487                9342589A255B535A0059EEDD /* MediaPermissionUtilities.h in Headers */ = {isa = PBXBuildFile; fileRef = 93425898255B534B0059EEDD /* MediaPermissionUtilities.h */; };
     1488                93468E6B2714AF47009983E3 /* SharedFileHandle.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 93468E6A2714AF47009983E3 /* SharedFileHandle.cpp */; };
     1489                93468E6D2714AF88009983E3 /* SharedFileHandleCocoa.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 93468E6C2714AF88009983E3 /* SharedFileHandleCocoa.cpp */; };
    14871490                934B724419F5B9BE00AE96D6 /* WKActionMenuItemTypes.h in Headers */ = {isa = PBXBuildFile; fileRef = 934B724319F5B9BE00AE96D6 /* WKActionMenuItemTypes.h */; settings = {ATTRIBUTES = (Private, ); }; };
    14881491                9354242C2703BDCB005CA72C /* WebFileSystemStorageConnection.h in Headers */ = {isa = PBXBuildFile; fileRef = 9354242A2703BDCB005CA72C /* WebFileSystemStorageConnection.h */; };
     
    49514954                93085DCD26E2E902000EC6A7 /* NetworkStorageManagerMessages.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = NetworkStorageManagerMessages.h; sourceTree = "<group>"; };
    49524955                93085DCE26E2E902000EC6A7 /* NetworkStorageManagerMessagesReplies.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = NetworkStorageManagerMessagesReplies.h; sourceTree = "<group>"; };
     4956                93122C852710CCDE001D819F /* SharedFileHandle.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SharedFileHandle.h; sourceTree = "<group>"; };
    49534957                931A075026F06310004474CD /* FileSystemStorageManager.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FileSystemStorageManager.h; sourceTree = "<group>"; };
    49544958                931A075126F06310004474CD /* FileSystemStorageManager.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = FileSystemStorageManager.cpp; sourceTree = "<group>"; };
     
    49694973                9342588F2555DCA50059EEDD /* MediaPermissionUtilities.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = MediaPermissionUtilities.mm; sourceTree = "<group>"; };
    49704974                93425898255B534B0059EEDD /* MediaPermissionUtilities.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MediaPermissionUtilities.h; sourceTree = "<group>"; };
     4975                93468E6A2714AF47009983E3 /* SharedFileHandle.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = SharedFileHandle.cpp; sourceTree = "<group>"; };
     4976                93468E6C2714AF88009983E3 /* SharedFileHandleCocoa.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = SharedFileHandleCocoa.cpp; sourceTree = "<group>"; };
    49714977                934B724319F5B9BE00AE96D6 /* WKActionMenuItemTypes.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WKActionMenuItemTypes.h; sourceTree = "<group>"; };
    49724978                9354242A2703BDCB005CA72C /* WebFileSystemStorageConnection.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WebFileSystemStorageConnection.h; sourceTree = "<group>"; };
     
    73607366                                2DC1855EDBFB850BA0B6D06D /* SharedBufferDataReference.cpp */,
    73617367                                2DC1881ACBCAB5D57C5C6EF0 /* SharedBufferDataReference.h */,
     7368                                93468E6A2714AF47009983E3 /* SharedFileHandle.cpp */,
     7369                                93122C852710CCDE001D819F /* SharedFileHandle.h */,
    73627370                                7B73123625CC8524003B2796 /* StreamClientConnection.cpp */,
    73637371                                7B73123325CC8523003B2796 /* StreamClientConnection.h */,
     
    1113311141                                1A6D86C01DF75265007745E8 /* MachMessage.h */,
    1113411142                                BCC56F771159957D001CCAF9 /* MachPort.h */,
     11143                                93468E6C2714AF88009983E3 /* SharedFileHandleCocoa.cpp */,
    1113511144                        );
    1113611145                        path = cocoa;
     
    1265712666                                2DC18FF6EF2A3130C1301767 /* SharedBufferDataReference.h in Headers */,
    1265812667                                F4A6D6BC254CA3E900B65FAA /* SharedDisplayListHandle.h in Headers */,
     12668                                93122C862710CCDF001D819F /* SharedFileHandle.h in Headers */,
    1265912669                                1A24BED5120894D100FBB059 /* SharedMemory.h in Headers */,
    1266012670                                CD4B4D9D1E765E0000D27092 /* SharedRingBufferStorage.h in Headers */,
     
    1461914629                                2DC18FEBF337B9671C88E3CD /* SharedBufferCopy.cpp in Sources */,
    1462014630                                2DC181245B549343BC98164C /* SharedBufferDataReference.cpp in Sources */,
     14631                                93468E6B2714AF47009983E3 /* SharedFileHandle.cpp in Sources */,
     14632                                93468E6D2714AF88009983E3 /* SharedFileHandleCocoa.cpp in Sources */,
    1462114633                                A1ADAFB62368E6A8009CB776 /* SharedMemory.cpp in Sources */,
    1462214634                                575B1BB923CE9C0B0020639A /* SimulatedInputDispatcher.cpp in Sources */,
  • trunk/Source/WebKit/WebProcess/WebCoreSupport/WebFileSystemStorageConnection.cpp

    r283881 r284059  
    122122            return completionHandler(convertToException(result.error()));
    123123
    124         completionHandler(WTFMove(result.value()));
     124        auto resultValue = result.value();
     125        completionHandler(std::pair { resultValue.first, resultValue.second.handle() });
    125126    });
    126127}
  • trunk/Source/WebKit/WebProcess/com.apple.WebProcess.sb.in

    r283998 r284059  
    19791979        (syscall-number SYS_sendto_nocancel)
    19801980        (syscall-number SYS_fsgetpath)
     1981        (syscall-number SYS_fileport_makefd)
    19811982        (syscall-number SYS_fileport_makeport)
    19821983        (syscall-number SYS_guarded_open_np)
  • trunk/Tools/ChangeLog

    r284055 r284059  
     12021-10-12  Sihui Liu  <sihui_liu@apple.com>
     2
     3        Implement FileSystemSyncAccessHandle read() and write()
     4        https://bugs.webkit.org/show_bug.cgi?id=231466
     5        <rdar://problem/84050394>
     6
     7        Reviewed by Youenn Fablet.
     8
     9        * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
     10        * TestWebKitAPI/Tests/WebKitCocoa/FileSystemAccess.mm: Added.
     11        (-[FileSystemAccessMessageHandler userContentController:didReceiveScriptMessage:]):
     12        (test):
     13
    1142021-10-12  Alex Christensen  <achristensen@webkit.org>
    215
  • trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj

    r283857 r284059  
    855855                9342589C255B609B0059EEDD /* SpeechRecognition.mm in Sources */ = {isa = PBXBuildFile; fileRef = 9342589B255B609A0059EEDD /* SpeechRecognition.mm */; };
    856856                9342589E255B6A120059EEDD /* speechrecognition-user-permission-persistence.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = 9342589D255B66A00059EEDD /* speechrecognition-user-permission-persistence.html */; };
     857                93468E6F2714B4F2009983E3 /* FileSystemAccess.mm in Sources */ = {isa = PBXBuildFile; fileRef = 93468E6E2714B4F1009983E3 /* FileSystemAccess.mm */; };
    857858                935786CC20F6A2700000CDFC /* IndexedDB.sqlite3-wal in Copy Resources */ = {isa = PBXBuildFile; fileRef = 934FA5C520F69FED0040DC1B /* IndexedDB.sqlite3-wal */; };
    858859                935786CD20F6A2910000CDFC /* IndexedDB.sqlite3 in Copy Resources */ = {isa = PBXBuildFile; fileRef = 934FA5C720F69FEE0040DC1B /* IndexedDB.sqlite3 */; };
     
    25832584                9342589B255B609A0059EEDD /* SpeechRecognition.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = SpeechRecognition.mm; sourceTree = "<group>"; };
    25842585                9342589D255B66A00059EEDD /* speechrecognition-user-permission-persistence.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = "speechrecognition-user-permission-persistence.html"; sourceTree = "<group>"; };
     2586                93468E6E2714B4F1009983E3 /* FileSystemAccess.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = FileSystemAccess.mm; sourceTree = "<group>"; };
    25852587                934FA5C520F69FED0040DC1B /* IndexedDB.sqlite3-wal */ = {isa = PBXFileReference; lastKnownFileType = file; path = "IndexedDB.sqlite3-wal"; sourceTree = "<group>"; };
    25862588                934FA5C620F69FED0040DC1B /* IndexedDB.sqlite3-shm */ = {isa = PBXFileReference; lastKnownFileType = file; path = "IndexedDB.sqlite3-shm"; sourceTree = "<group>"; };
     
    35113513                                CDA29B2820FD2A9900F15CED /* ExitFullscreenOnEnterPiP.mm */,
    35123514                                1D12BEBF245BEF85004C0B7A /* ExitPiPOnSuspendVideoElement.mm */,
     3515                                93468E6E2714B4F1009983E3 /* FileSystemAccess.mm */,
    35133516                                2D8104CB1BEC13E70020DA46 /* FindInPage.mm */,
    35143517                                51242CD42374E61E00EED9C1 /* FindInPageAPI.mm */,
     
    55695572                                579651E7216BFDED006EBFE5 /* FidoHidMessageTest.cpp in Sources */,
    55705573                                7A32D74A1F02151500162C44 /* FileMonitor.cpp in Sources */,
     5574                                93468E6F2714B4F2009983E3 /* FileSystemAccess.mm in Sources */,
    55715575                                7CCE7EF31A411AE600447C4C /* Find.cpp in Sources */,
    55725576                                7C83E0BB1D0A650000FEBCF3 /* FindInPage.mm in Sources */,
Note: See TracChangeset for help on using the changeset viewer.