Bug 1358109 - Use IPCBlob in PFilePicker, r=smaug
☠☠ backed out by d8868683036b ☠ ☠
authorAndrea Marchesini <amarchesini@mozilla.com>
Mon, 24 Apr 2017 12:16:49 +0200
changeset 354631 dec83a85f824c2afb541ecbda08dab6aa1abcff0
parent 354630 6e18a14aa213774f5c80ca72e0667b87654c7b80
child 354632 50518d6aa0fc7d2f476b065ff877c02d7ba0a36a
push id31707
push userkwierso@gmail.com
push dateMon, 24 Apr 2017 22:53:41 +0000
treeherdermozilla-central@abdcc8dfc283 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssmaug
bugs1358109
milestone55.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1358109 - Use IPCBlob in PFilePicker, r=smaug
dom/file/ipc/IPCBlobUtils.h
dom/ipc/FilePickerParent.cpp
dom/ipc/PFilePicker.ipdl
widget/nsFilePickerProxy.cpp
--- a/dom/file/ipc/IPCBlobUtils.h
+++ b/dom/file/ipc/IPCBlobUtils.h
@@ -149,21 +149,23 @@ already_AddRefed<BlobImpl>
 Deserialize(const IPCBlob& aIPCBlob);
 
 // These 4 methods serialize aBlobImpl into aIPCBlob using the right manager.
 
 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
 } // mozilla namespace
 
 #endif // mozilla_dom_IPCBlobUtils_h
--- a/dom/ipc/FilePickerParent.cpp
+++ b/dom/ipc/FilePickerParent.cpp
@@ -12,17 +12,17 @@
 #include "nsIFile.h"
 #include "nsISimpleEnumerator.h"
 #include "mozilla/Unused.h"
 #include "mozilla/dom/FileBlobImpl.h"
 #include "mozilla/dom/FileSystemSecurity.h"
 #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;
 
 NS_IMPL_ISUPPORTS(FilePickerParent::FilePickerShownCallback,
                   nsIFilePickerShownCallback);
 
 NS_IMETHODIMP
@@ -39,21 +39,16 @@ FilePickerParent::FilePickerShownCallbac
 {
   mFilePickerParent = nullptr;
 }
 
 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
 // the same runnable on the main thread.
 // 3. The main thread sends the results over IPC.
 FilePickerParent::IORunnable::IORunnable(FilePickerParent *aFPParent,
                                          nsTArray<nsCOMPtr<nsIFile>>& aFiles,
                                          bool aIsDirectory)
@@ -164,28 +159,33 @@ FilePickerParent::SendFilesOrDirectories
                                      aData[0].mDirectoryPath);
 
     InputDirectory input;
     input.directoryPath() = aData[0].mDirectoryPath;
     Unused << Send__delete__(this, input, mResult);
     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);
 }
 
 void
 FilePickerParent::Done(int16_t aResult)
 {
   mResult = aResult;
 
--- a/dom/ipc/PFilePicker.ipdl
+++ b/dom/ipc/PFilePicker.ipdl
@@ -1,25 +1,30 @@
 /* -*- Mode: C++; c-basic-offset: 2; indent-tabs-mode: nil; tab-width: 8 -*- */
 /* vim: set sw=4 ts=8 et tw=80 ft=cpp : */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * 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";
 
 namespace mozilla {
 namespace dom {
 
 struct InputBlobs
 {
-  PBlob[] blobs;
+  IPCBlob[] blobs;
 };
 
 struct InputDirectory
 {
   nsString directoryPath;
 };
 
 union MaybeInputData
--- a/widget/nsFilePickerProxy.cpp
+++ b/widget/nsFilePickerProxy.cpp
@@ -5,17 +5,17 @@
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "nsFilePickerProxy.h"
 #include "nsComponentManagerUtils.h"
 #include "nsIFile.h"
 #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;
 
 NS_IMPL_ISUPPORTS(nsFilePickerProxy, nsIFilePicker)
 
 nsFilePickerProxy::nsFilePickerProxy()
   : mSelectedType(0)
   , mIPCActive(false)
@@ -149,20 +149,19 @@ nsFilePickerProxy::Open(nsIFilePickerSho
   return NS_OK;
 }
 
 mozilla::ipc::IPCResult
 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()) {
         return IPC_OK();
       }
 
       nsPIDOMWindowInner* inner =
         mParent ? mParent->GetCurrentInnerWindow() : nullptr;