Bug 1358109 - Use IPCBlob in PFilePicker, r=smaug

This commit is contained in:
Andrea Marchesini 2017-04-25 14:07:30 +02:00
parent 660878a108
commit c4efbc7670
4 changed files with 25 additions and 19 deletions

View File

@ -154,13 +154,15 @@ nsresult
Serialize(BlobImpl* aBlobImpl, nsIContentChild* aManager, IPCBlob& aIPCBlob);
nsresult
Serialize(BlobImpl* aBlobImpl, PBackgroundChild* aManager, IPCBlob& aIPCBlob);
Serialize(BlobImpl* aBlobImpl, mozilla::ipc::PBackgroundChild* aManager,
IPCBlob& aIPCBlob);
nsresult
Serialize(BlobImpl* aBlobImpl, nsIContentParent* aManager, IPCBlob& aIPCBlob);
nsresult
Serialize(BlobImpl* aBlobImpl, PBackgroundParent* aManager, IPCBlob& aIPCBlob);
Serialize(BlobImpl* aBlobImpl, mozilla::ipc::PBackgroundParent* aManager,
IPCBlob& aIPCBlob);
} // IPCBlobUtils
} // dom namespace

View File

@ -17,7 +17,7 @@
#include "mozilla/dom/ContentParent.h"
#include "mozilla/dom/Element.h"
#include "mozilla/dom/TabParent.h"
#include "mozilla/dom/ipc/BlobParent.h"
#include "mozilla/dom/IPCBlobUtils.h"
using mozilla::Unused;
using namespace mozilla::dom;
@ -44,11 +44,6 @@ FilePickerParent::~FilePickerParent()
{
}
// Before sending a blob to the child, we need to get its size and modification
// date. Otherwise it will be sent as a "mystery blob" by
// GetOrCreateActorForBlob, which will cause problems for the child
// process. This runnable stat()s the file off the main thread.
//
// We run code in three places:
// 1. The main thread calls Dispatch() to start the runnable.
// 2. The stream transport thread stat()s the file in Run() and then dispatches
@ -169,18 +164,23 @@ FilePickerParent::SendFilesOrDirectories(const nsTArray<BlobImplOrString>& aData
return;
}
InfallibleTArray<PBlobParent*> blobs;
InfallibleTArray<IPCBlob> ipcBlobs;
for (unsigned i = 0; i < aData.Length(); i++) {
IPCBlob ipcBlob;
MOZ_ASSERT(aData[i].mType == BlobImplOrString::eBlobImpl);
BlobParent* blobParent = parent->GetOrCreateActorForBlobImpl(aData[i].mBlobImpl);
if (blobParent) {
blobs.AppendElement(blobParent);
nsresult rv = IPCBlobUtils::Serialize(aData[i].mBlobImpl, parent, ipcBlob);
if (NS_WARN_IF(NS_FAILED(rv))) {
break;
}
ipcBlobs.AppendElement(ipcBlob);
}
InputBlobs inblobs;
inblobs.blobsParent().SwapElements(blobs);
inblobs.blobs().SwapElements(ipcBlobs);
Unused << Send__delete__(this, inblobs, mResult);
}

View File

@ -4,8 +4,13 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
include protocol PBlob;
include protocol PBrowser;
include protocol PChildToParentStream;
include protocol PIPCBlobInputStream;
include protocol PFileDescriptorSet;
include protocol PParentToChildStream;
include IPCBlob;
using struct mozilla::void_t from "ipc/IPCMessageUtils.h";
@ -14,7 +19,7 @@ namespace dom {
struct InputBlobs
{
PBlob[] blobs;
IPCBlob[] blobs;
};
struct InputDirectory

View File

@ -10,7 +10,7 @@
#include "mozilla/dom/Directory.h"
#include "mozilla/dom/File.h"
#include "mozilla/dom/TabChild.h"
#include "mozilla/dom/ipc/BlobChild.h"
#include "mozilla/dom/IPCBlobUtils.h"
using namespace mozilla::dom;
@ -154,10 +154,9 @@ nsFilePickerProxy::Recv__delete__(const MaybeInputData& aData,
const int16_t& aResult)
{
if (aData.type() == MaybeInputData::TInputBlobs) {
const InfallibleTArray<PBlobChild*>& blobs = aData.get_InputBlobs().blobsChild();
const InfallibleTArray<IPCBlob>& blobs = aData.get_InputBlobs().blobs();
for (uint32_t i = 0; i < blobs.Length(); ++i) {
BlobChild* actor = static_cast<BlobChild*>(blobs[i]);
RefPtr<BlobImpl> blobImpl = actor->GetBlobImpl();
RefPtr<BlobImpl> blobImpl = IPCBlobUtils::Deserialize(blobs[i]);
NS_ENSURE_TRUE(blobImpl, IPC_OK());
if (!blobImpl->IsFile()) {