You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
[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: http://svn.webkit.org/repository/webkit/trunk@226470 268f45cc-cd09-0410-ab3c-d52691b4dbfc
auto fileCloser = WTF::makeScopeExit([file]() mutable {
290
-
FileSystem::closeFile(file);
291
-
});
292
-
293
-
if (tempFilePath.isEmpty() || !FileSystem::isHandleValid(file)) {
294
-
LOG_ERROR("Failed to open temporary file for writing a Blob to IndexedDB");
295
-
returnfalse;
296
-
}
297
-
298
-
for (auto& part : blob.filePathsOrDataBuffers) {
299
-
if (part.second.data()) {
300
-
int length = part.second.data()->size();
301
-
if (FileSystem::writeToFile(file, reinterpret_cast<constchar*>(part.second.data()->data()), length) != length) {
302
-
LOG_ERROR("Failed writing a Blob to temporary file for storage in IndexedDB");
303
-
returnfalse;
304
-
}
305
-
} else {
306
-
ASSERT(!part.first.isEmpty());
307
-
if (!FileSystem::appendFileContentsToFileHandle(part.first, file)) {
308
-
LOG_ERROR("Failed copying File contents to a Blob temporary file for storage in IndexedDB (%s to %s)", part.first.utf8().data(), tempFilePath.utf8().data());
309
-
returnfalse;
310
-
}
311
-
}
312
-
}
313
-
314
-
filePaths.append(tempFilePath.isolatedCopy());
280
+
if (path.isEmpty() || !FileSystem::isHandleValid(file)) {
281
+
LOG_ERROR("Failed to open temporary file for writing a Blob");
282
+
returnfalse;
283
+
}
284
+
285
+
for (auto& part : filePathsOrDataBuffers) {
286
+
if (part.second.data()) {
287
+
int length = part.second.data()->size();
288
+
if (FileSystem::writeToFile(file, reinterpret_cast<constchar*>(part.second.data()->data()), length) != length) {
289
+
LOG_ERROR("Failed writing a Blob to temporary file");
290
+
returnfalse;
315
291
}
292
+
} else {
293
+
ASSERT(!part.first.isEmpty());
294
+
if (!FileSystem::appendFileContentsToFileHandle(part.first, file)) {
295
+
LOG_ERROR("Failed copying File contents to a Blob temporary file (%s to %s)", part.first.utf8().data(), path.utf8().data());
0 commit comments