[Attachment Support] Add a way to write blob data to a file URL from the UI process
authorwenson_hsieh@apple.com <wenson_hsieh@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 5 Jan 2018 23:48:35 +0000 (23:48 +0000)
committerwenson_hsieh@apple.com <wenson_hsieh@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 5 Jan 2018 23:48:35 +0000 (23:48 +0000)
commitfe8e6d92bf64e83c9cc84d9518ee77bc163a39f3
treedacffef36f1b6290bd02bc999ce93f5f915bc351
parentc52f7f7523bddd583a76ecc95096a5844a81db13
[Attachment Support] Add a way to write blob data to a file URL from the UI process
https://bugs.webkit.org/show_bug.cgi?id=181236

Reviewed by Brady Eidson.

Source/WebCore:

Add support for writing a blob to a designated file path. See comments below for more detail. No new tests, as
there change in behavior yet. See part 2: https://bugs.webkit.org/show_bug.cgi?id=181199.

* page/DragController.cpp:
(WebCore::DragController::dragAttachmentElement):
* platform/PromisedBlobInfo.h:

Remove PromisedBlobData entirely. This was added with the premise of having the web process deliver blob data to
the UI process. However, the new approach I'm taking just has the UI process tell the network process to write
a blob to a given location, so a data structure to deliver blob data over IPC is no longer necessary.

(WebCore::PromisedBlobData::hasData const): Deleted.
(WebCore::PromisedBlobData::hasFile const): Deleted.
(WebCore::PromisedBlobData::operator bool const): Deleted.
(WebCore::PromisedBlobData::fulfills const): Deleted.
* platform/network/BlobRegistryImpl.cpp:
(WebCore::BlobRegistryImpl::populateBlobsForFileWriting):

Introduce a new helper to build a list of blob data for file writing.

(WebCore::writeFilePathsOrDataBuffersToFile):

Introduce a new static helper to write blob data (a list of file paths and data buffers) to a given file handle.
Automatically closes the given file handle upon exit.

(WebCore::BlobRegistryImpl::writeBlobsToTemporaryFiles):
(WebCore::BlobRegistryImpl::writeBlobToFilePath):

Pull out common logic in writeBlobsToTemporaryFiles and writeBlobToFilePath into helper methods (see above), and
refactor both methods to use the helpers.

* platform/network/BlobRegistryImpl.h:

Source/WebKit:

Add support for writing a blob to a designated file path. In WebKit, this is mainly plumbing writeBlobToFilePath
through WebPageProxy to the network process.

* NetworkProcess/FileAPI/NetworkBlobRegistry.cpp:
(WebKit::NetworkBlobRegistry::writeBlobToFilePath):

Call out to the BlobRegistryImpl to write blobs to the file path. Additionally grant sandbox extensions for any
file-backed blob parts corresponding to the given blob URL.

(WebKit::NetworkBlobRegistry::filesInBlob):

Introduce a version of filesInBlob that doesn't check against the NetworkConnectionToWebProcess. This is used
when the UI process is the driver for writing a blob.

* NetworkProcess/FileAPI/NetworkBlobRegistry.h:
* NetworkProcess/NetworkProcess.cpp:
(WebKit::NetworkProcess::writeBlobToFilePath):

Temporarily grant sandbox access to the given file path.

* NetworkProcess/NetworkProcess.h:
* NetworkProcess/NetworkProcess.messages.in:
* Shared/WebCoreArgumentCoders.cpp:
(IPC::ArgumentCoder<PromisedBlobInfo>::encode):
(IPC::ArgumentCoder<PromisedBlobInfo>::decode):
(IPC::ArgumentCoder<PromisedBlobData>::encode): Deleted.
(IPC::ArgumentCoder<PromisedBlobData>::decode): Deleted.

Remove PromisedBlobData (see WebCore/ChangeLog for more information).

* Shared/WebCoreArgumentCoders.h:
* UIProcess/Network/NetworkProcessProxy.cpp:
(WebKit::NetworkProcessProxy::didClose):

If the network process is terminated, flush any pending callbacks in m_writeBlobToFilePathCallbackMap, passing
in a failure result (success := false) and clearing the callback map.

(WebKit::NetworkProcessProxy::writeBlobToFilePath):
(WebKit::NetworkProcessProxy::didWriteBlobToFilePath):
* UIProcess/Network/NetworkProcessProxy.h:
* UIProcess/Network/NetworkProcessProxy.messages.in:
* UIProcess/WebPageProxy.cpp:
(WebKit::WebPageProxy::writeBlobToFilePath):
* UIProcess/WebPageProxy.h:

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@226470 268f45cc-cd09-0410-ab3c-d52691b4dbfc
18 files changed:
Source/WebCore/ChangeLog
Source/WebCore/page/DragController.cpp
Source/WebCore/platform/PromisedBlobInfo.h
Source/WebCore/platform/network/BlobRegistryImpl.cpp
Source/WebCore/platform/network/BlobRegistryImpl.h
Source/WebKit/ChangeLog
Source/WebKit/NetworkProcess/FileAPI/NetworkBlobRegistry.cpp
Source/WebKit/NetworkProcess/FileAPI/NetworkBlobRegistry.h
Source/WebKit/NetworkProcess/NetworkProcess.cpp
Source/WebKit/NetworkProcess/NetworkProcess.h
Source/WebKit/NetworkProcess/NetworkProcess.messages.in
Source/WebKit/Shared/WebCoreArgumentCoders.cpp
Source/WebKit/Shared/WebCoreArgumentCoders.h
Source/WebKit/UIProcess/Network/NetworkProcessProxy.cpp
Source/WebKit/UIProcess/Network/NetworkProcessProxy.h
Source/WebKit/UIProcess/Network/NetworkProcessProxy.messages.in
Source/WebKit/UIProcess/WebPageProxy.cpp
Source/WebKit/UIProcess/WebPageProxy.h