Bug 1358114 - Use IPCBlob in BlobURL, r=smaug
☠☠ backed out by 6e7b7e621dc3 ☠ ☠
authorAndrea Marchesini <amarchesini@mozilla.com>
Mon, 24 Apr 2017 12:16:49 +0200
changeset 354634 a180e3f4de16aa456c8cd039805aa0924618d5c9
parent 354633 73f62ae76c08245b15223918602b6b9db31809a2
child 354635 2577afd226ff64101e4ed3767d0abff83c34c9bd
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
bugs1358114
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 1358114 - Use IPCBlob in BlobURL, r=smaug
dom/file/nsHostObjectProtocolHandler.cpp
dom/file/nsHostObjectProtocolHandler.h
dom/ipc/ContentChild.cpp
dom/ipc/ContentChild.h
dom/ipc/ContentParent.cpp
dom/ipc/ContentParent.h
dom/ipc/PContent.ipdl
dom/url/URL.cpp
--- a/dom/file/nsHostObjectProtocolHandler.cpp
+++ b/dom/file/nsHostObjectProtocolHandler.cpp
@@ -6,40 +6,36 @@
 
 #include "nsHostObjectProtocolHandler.h"
 
 #include "DOMMediaStream.h"
 #include "mozilla/dom/ContentChild.h"
 #include "mozilla/dom/ContentParent.h"
 #include "mozilla/dom/Exceptions.h"
 #include "mozilla/dom/BlobImpl.h"
-#include "mozilla/dom/ipc/BlobChild.h"
-#include "mozilla/dom/ipc/BlobParent.h"
+#include "mozilla/dom/IPCBlobUtils.h"
 #include "mozilla/dom/MediaSource.h"
+#include "mozilla/ipc/IPCStreamUtils.h"
 #include "mozilla/LoadInfo.h"
 #include "mozilla/ModuleUtils.h"
 #include "mozilla/Preferences.h"
 #include "nsClassHashtable.h"
 #include "nsContentUtils.h"
 #include "nsError.h"
 #include "nsHostObjectURI.h"
 #include "nsIMemoryReporter.h"
 #include "nsIPrincipal.h"
 #include "nsIUUIDGenerator.h"
 #include "nsNetUtil.h"
 
 #define RELEASING_TIMER 1000
 
-using mozilla::DOMMediaStream;
-using mozilla::dom::BlobImpl;
-using mozilla::dom::MediaSource;
-using mozilla::ErrorResult;
-using mozilla::net::LoadInfo;
-using mozilla::Move;
-using mozilla::Unused;
+using namespace mozilla;
+using namespace mozilla::dom;
+using namespace mozilla::ipc;
 
 // -----------------------------------------------------------------------
 // Hash table
 struct DataInfo
 {
   enum ObjectType {
     eBlobImpl,
     eMediaStream,
@@ -139,23 +135,25 @@ BroadcastBlobURLRegistration(const nsACS
 
   if (XRE_IsParentProcess()) {
     dom::ContentParent::BroadcastBlobURLRegistration(aURI, aBlobImpl,
                                                      aPrincipal);
     return;
   }
 
   dom::ContentChild* cc = dom::ContentChild::GetSingleton();
-  dom::BlobChild* actor = cc->GetOrCreateActorForBlobImpl(aBlobImpl);
-  if (NS_WARN_IF(!actor)) {
+
+  IPCBlob ipcBlob;
+  nsresult rv = IPCBlobUtils::Serialize(aBlobImpl, cc, ipcBlob);
+  if (NS_WARN_IF(NS_FAILED(rv))) {
     return;
   }
 
   Unused << NS_WARN_IF(!cc->SendStoreAndBroadcastBlobURLRegistration(
-    nsCString(aURI), actor, IPC::Principal(aPrincipal)));
+    nsCString(aURI), ipcBlob, IPC::Principal(aPrincipal)));
 }
 
 void
 BroadcastBlobURLUnregistration(const nsACString& aURI, DataInfo* aInfo)
 {
   MOZ_ASSERT(aInfo);
   MOZ_ASSERT(NS_IsMainThread());
 
@@ -516,17 +514,17 @@ nsHostObjectProtocolHandler::AddDataEntr
   Init();
 
   nsresult rv = GenerateURIStringForBlobURL(aPrincipal, aUri);
   NS_ENSURE_SUCCESS(rv, rv);
 
   rv = AddDataEntryInternal(aUri, aBlobImpl, aPrincipal);
   NS_ENSURE_SUCCESS(rv, rv);
 
-  mozilla::BroadcastBlobURLRegistration(aUri, aBlobImpl, aPrincipal);
+  BroadcastBlobURLRegistration(aUri, aBlobImpl, aPrincipal);
   return NS_OK;
 }
 
 /* static */ nsresult
 nsHostObjectProtocolHandler::AddDataEntry(DOMMediaStream* aMediaStream,
                                           nsIPrincipal* aPrincipal,
                                           nsACString& aUri)
 {
@@ -555,50 +553,50 @@ nsHostObjectProtocolHandler::AddDataEntr
   NS_ENSURE_SUCCESS(rv, rv);
 
   return NS_OK;
 }
 
 /* static */ nsresult
 nsHostObjectProtocolHandler::AddDataEntry(const nsACString& aURI,
                                           nsIPrincipal* aPrincipal,
-                                          mozilla::dom::BlobImpl* aBlobImpl)
+                                          BlobImpl* aBlobImpl)
 {
   return AddDataEntryInternal(aURI, aBlobImpl, aPrincipal);
 }
 
 /* static */ bool
 nsHostObjectProtocolHandler::GetAllBlobURLEntries(
-  nsTArray<mozilla::dom::BlobURLRegistrationData>& aRegistrations,
-  mozilla::dom::ContentParent* aCP)
+  nsTArray<BlobURLRegistrationData>& aRegistrations,
+  ContentParent* aCP)
 {
   MOZ_ASSERT(aCP);
 
   if (!gDataTable) {
     return true;
   }
 
   for (auto iter = gDataTable->ConstIter(); !iter.Done(); iter.Next()) {
     DataInfo* info = iter.UserData();
     MOZ_ASSERT(info);
 
     if (info->mObjectType != DataInfo::eBlobImpl) {
       continue;
     }
 
     MOZ_ASSERT(info->mBlobImpl);
-    mozilla::dom::PBlobParent* blobParent =
-      aCP->GetOrCreateActorForBlobImpl(info->mBlobImpl);
-    if (!blobParent) {
+
+    IPCBlob ipcBlob;
+    nsresult rv = IPCBlobUtils::Serialize(info->mBlobImpl, aCP, ipcBlob);
+    if (NS_WARN_IF(NS_FAILED(rv))) {
       return false;
     }
 
-    aRegistrations.AppendElement(mozilla::dom::BlobURLRegistrationData(
-      nsCString(iter.Key()), blobParent, nullptr,
-      IPC::Principal(info->mPrincipal)));
+    aRegistrations.AppendElement(BlobURLRegistrationData(
+      nsCString(iter.Key()), ipcBlob, IPC::Principal(info->mPrincipal)));
   }
 
   return true;
 }
 
 /*static */ void
 nsHostObjectProtocolHandler::RemoveDataEntry(const nsACString& aUri,
                                              bool aBroadcastToOtherProcesses)
@@ -608,21 +606,21 @@ nsHostObjectProtocolHandler::RemoveDataE
   }
 
   DataInfo* info = GetDataInfo(aUri);
   if (!info) {
     return;
   }
 
   if (aBroadcastToOtherProcesses && info->mObjectType == DataInfo::eBlobImpl) {
-    mozilla::BroadcastBlobURLUnregistration(aUri, info);
+    BroadcastBlobURLUnregistration(aUri, info);
   }
 
   if (!info->mURIs.IsEmpty()) {
-    mozilla::ReleasingTimerHolder::Create(Move(info->mURIs));
+    ReleasingTimerHolder::Create(Move(info->mURIs));
   }
 
   gDataTable->Remove(aUri);
   if (gDataTable->Count() == 0) {
     delete gDataTable;
     gDataTable = nullptr;
   }
 }
@@ -955,17 +953,17 @@ NS_GetStreamForBlobURI(nsIURI* aURI, nsI
   if (NS_WARN_IF(rv.Failed())) {
     return rv.StealNSResult();
   }
 
   return NS_OK;
 }
 
 nsresult
-NS_GetStreamForMediaStreamURI(nsIURI* aURI, mozilla::DOMMediaStream** aStream)
+NS_GetStreamForMediaStreamURI(nsIURI* aURI, DOMMediaStream** aStream)
 {
   DataInfo* info = GetDataInfoFromURI(aURI);
   if (!info || info->mObjectType != DataInfo::eMediaStream) {
     return NS_ERROR_DOM_BAD_URI;
   }
 
   RefPtr<DOMMediaStream> mediaStream = info->mMediaStream;
   mediaStream.forget(aStream);
@@ -1002,17 +1000,17 @@ nsFontTableProtocolHandler::NewURI(const
     return NS_ERROR_NOT_AVAILABLE;
   }
 
   uri.forget(aResult);
   return NS_OK;
 }
 
 nsresult
-NS_GetSourceForMediaSourceURI(nsIURI* aURI, mozilla::dom::MediaSource** aSource)
+NS_GetSourceForMediaSourceURI(nsIURI* aURI, MediaSource** aSource)
 {
   *aSource = nullptr;
 
   DataInfo* info = GetDataInfoFromURI(aURI);
   if (!info || info->mObjectType != DataInfo::eMediaSource) {
     return NS_ERROR_DOM_BAD_URI;
   }
 
--- a/dom/file/nsHostObjectProtocolHandler.h
+++ b/dom/file/nsHostObjectProtocolHandler.h
@@ -18,16 +18,17 @@
 #define FONTTABLEURI_SCHEME "moz-fonttable"
 #define RTSPURI_SCHEME "rtsp"
 
 class nsIPrincipal;
 
 namespace mozilla {
 class BlobURLsReporter;
 class DOMMediaStream;
+
 namespace dom {
 class BlobImpl;
 class BlobURLRegistrationData;
 class ContentParent;
 class MediaSource;
 } // namespace dom
 } // namespace mozilla
 
--- a/dom/ipc/ContentChild.cpp
+++ b/dom/ipc/ContentChild.cpp
@@ -2417,18 +2417,17 @@ ContentChild::RecvInitServiceWorkers(con
   return IPC_OK();
 }
 
 mozilla::ipc::IPCResult
 ContentChild::RecvInitBlobURLs(nsTArray<BlobURLRegistrationData>&& aRegistrations)
 {
   for (uint32_t i = 0; i < aRegistrations.Length(); ++i) {
     BlobURLRegistrationData& registration = aRegistrations[i];
-    RefPtr<BlobImpl> blobImpl =
-      static_cast<BlobChild*>(registration.blobChild())->GetBlobImpl();
+    RefPtr<BlobImpl> blobImpl = IPCBlobUtils::Deserialize(registration.blob());
     MOZ_ASSERT(blobImpl);
 
     nsHostObjectProtocolHandler::AddDataEntry(registration.url(),
                                               registration.principal(),
                                               blobImpl);
   }
 
   return IPC_OK();
@@ -3068,20 +3067,21 @@ ContentChild::RecvNotifyPushSubscription
                                                           const IPC::Principal& aPrincipal)
 {
   PushSubscriptionModifiedDispatcher dispatcher(aScope, aPrincipal);
   Unused << NS_WARN_IF(NS_FAILED(dispatcher.NotifyObservers()));
   return IPC_OK();
 }
 
 mozilla::ipc::IPCResult
-ContentChild::RecvBlobURLRegistration(const nsCString& aURI, PBlobChild* aBlobChild,
+ContentChild::RecvBlobURLRegistration(const nsCString& aURI,
+                                      const IPCBlob& aBlob,
                                       const IPC::Principal& aPrincipal)
 {
-  RefPtr<BlobImpl> blobImpl = static_cast<BlobChild*>(aBlobChild)->GetBlobImpl();
+  RefPtr<BlobImpl> blobImpl = IPCBlobUtils::Deserialize(aBlob);
   MOZ_ASSERT(blobImpl);
 
   nsHostObjectProtocolHandler::AddDataEntry(aURI, aPrincipal, blobImpl);
   return IPC_OK();
 }
 
 mozilla::ipc::IPCResult
 ContentChild::RecvBlobURLUnregistration(const nsCString& aURI)
--- a/dom/ipc/ContentChild.h
+++ b/dom/ipc/ContentChild.h
@@ -576,17 +576,17 @@ public:
   void
   DeleteGetFilesRequest(nsID& aUUID, GetFilesHelperChild* aChild);
 
   virtual mozilla::ipc::IPCResult
   RecvGetFilesResponse(const nsID& aUUID,
                        const GetFilesResponseResult& aResult) override;
 
   virtual mozilla::ipc::IPCResult
-  RecvBlobURLRegistration(const nsCString& aURI, PBlobChild* aBlobChild,
+  RecvBlobURLRegistration(const nsCString& aURI, const IPCBlob& aBlob,
                           const IPC::Principal& aPrincipal) override;
 
   virtual mozilla::ipc::IPCResult
   RecvBlobURLUnregistration(const nsCString& aURI) override;
 
   virtual mozilla::ipc::IPCResult
   RecvFileCreationResponse(const nsID& aUUID,
                            const FileCreationResult& aResult) override;
--- a/dom/ipc/ContentParent.cpp
+++ b/dom/ipc/ContentParent.cpp
@@ -4849,20 +4849,23 @@ ContentParent::BroadcastBlobURLRegistrat
                                             nsIPrincipal* aPrincipal,
                                             ContentParent* aIgnoreThisCP)
 {
   nsCString uri(aURI);
   IPC::Principal principal(aPrincipal);
 
   for (auto* cp : AllProcesses(eLive)) {
     if (cp != aIgnoreThisCP) {
-      PBlobParent* blobParent = cp->GetOrCreateActorForBlobImpl(aBlobImpl);
-      if (blobParent) {
-        Unused << cp->SendBlobURLRegistration(uri, blobParent, principal);
+      IPCBlob ipcBlob;
+      nsresult rv = IPCBlobUtils::Serialize(aBlobImpl, cp, ipcBlob);
+      if (NS_WARN_IF(NS_FAILED(rv))) {
+        break;
       }
+
+      Unused << cp->SendBlobURLRegistration(uri, ipcBlob, principal);
     }
   }
 }
 
 /* static */ void
 ContentParent::BroadcastBlobURLUnregistration(const nsACString& aURI,
                                               ContentParent* aIgnoreThisCP)
 {
@@ -4872,21 +4875,20 @@ ContentParent::BroadcastBlobURLUnregistr
     if (cp != aIgnoreThisCP) {
       Unused << cp->SendBlobURLUnregistration(uri);
     }
   }
 }
 
 mozilla::ipc::IPCResult
 ContentParent::RecvStoreAndBroadcastBlobURLRegistration(const nsCString& aURI,
-                                                        PBlobParent* aBlobParent,
+                                                        const IPCBlob& aBlob,
                                                         const Principal& aPrincipal)
 {
-  RefPtr<BlobImpl> blobImpl =
-    static_cast<BlobParent*>(aBlobParent)->GetBlobImpl();
+  RefPtr<BlobImpl> blobImpl = IPCBlobUtils::Deserialize(aBlob);
   if (NS_WARN_IF(!blobImpl)) {
     return IPC_FAIL_NO_REASON(this);
   }
 
   if (NS_SUCCEEDED(nsHostObjectProtocolHandler::AddDataEntry(aURI, aPrincipal,
                                                              blobImpl))) {
     BroadcastBlobURLRegistration(aURI, blobImpl, aPrincipal, this);
 
--- a/dom/ipc/ContentParent.h
+++ b/dom/ipc/ContentParent.h
@@ -579,17 +579,17 @@ public:
                                ContentParent* aIgnoreThisCP = nullptr);
 
   static void
   BroadcastBlobURLUnregistration(const nsACString& aURI,
                                  ContentParent* aIgnoreThisCP = nullptr);
 
   virtual mozilla::ipc::IPCResult
   RecvStoreAndBroadcastBlobURLRegistration(const nsCString& aURI,
-                                           PBlobParent* aBlobParent,
+                                           const IPCBlob& aBlob,
                                            const Principal& aPrincipal) override;
 
   virtual mozilla::ipc::IPCResult
   RecvUnstoreAndBroadcastBlobURLUnregistration(const nsCString& aURI) override;
 
   virtual mozilla::ipc::IPCResult
   RecvBroadcastLocalStorageChange(const nsString& aDocumentURI,
                                   const nsString& aKey,
--- a/dom/ipc/PContent.ipdl
+++ b/dom/ipc/PContent.ipdl
@@ -224,17 +224,17 @@ union FileCreationResult
 {
   FileCreationSuccessResult;
   FileCreationErrorResult;
 };
 
 struct BlobURLRegistrationData
 {
     nsCString url;
-    PBlob blob;
+    IPCBlob blob;
     Principal principal;
 };
 
 struct GMPAPITags
 {
     nsCString api;
     nsCString[] tags;
 };
@@ -573,17 +573,17 @@ child:
      * audio session.
      */
     async SetAudioSessionData(nsID aID,
                               nsString aDisplayName,
                               nsString aIconPath);
 
     async GetFilesResponse(nsID aID, GetFilesResponseResult aResult);
 
-    async BlobURLRegistration(nsCString aURI, PBlob aBlob,
+    async BlobURLRegistration(nsCString aURI, IPCBlob aBlob,
                               Principal aPrincipal);
 
     async BlobURLUnregistration(nsCString aURI);
 
     async DispatchLocalStorageChange(nsString documentURI,
                                      nsString key,
                                      nsString oldValue,
                                      nsString newValue,
@@ -1076,17 +1076,17 @@ parent:
      async GetFilesRequest(nsID aID, nsString aDirectory, bool aRecursiveFlag);
      async DeleteGetFilesRequest(nsID aID);
 
      async FileCreationRequest(nsID aID, nsString aFullPath, nsString aType,
                                nsString aName, bool lastModifiedPassed,
                                int64_t lastModified, bool aExistenceCheck,
                                bool aIsFromNsIFile);
 
-     async StoreAndBroadcastBlobURLRegistration(nsCString url, PBlob blob,
+     async StoreAndBroadcastBlobURLRegistration(nsCString url, IPCBlob blob,
                                                 Principal principal);
 
      async UnstoreAndBroadcastBlobURLUnregistration(nsCString url);
 
      async BroadcastLocalStorageChange(nsString documentURI,
                                        nsString key,
                                        nsString oldValue,
                                        nsString newValue,
--- a/dom/url/URL.cpp
+++ b/dom/url/URL.cpp
@@ -5,18 +5,16 @@
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "URL.h"
 
 #include "DOMMediaStream.h"
 #include "mozilla/dom/File.h"
 #include "mozilla/dom/MediaSource.h"
 #include "mozilla/dom/URLBinding.h"
-#include "mozilla/dom/ipc/BlobChild.h"
-#include "mozilla/dom/ipc/nsIRemoteBlob.h"
 #include "mozilla/ipc/BackgroundChild.h"
 #include "nsContentUtils.h"
 #include "nsEscape.h"
 #include "nsHostObjectProtocolHandler.h"
 #include "nsIIOService.h"
 #include "nsIURL.h"
 #include "nsNetCID.h"
 #include "nsNetUtil.h"
@@ -762,40 +760,16 @@ public:
 
   bool
   MainThreadRun()
   {
     using namespace mozilla::ipc;
 
     AssertIsOnMainThread();
 
-    RefPtr<BlobImpl> newBlobImplHolder;
-
-    if (nsCOMPtr<nsIRemoteBlob> remoteBlob = do_QueryInterface(mBlobImpl)) {
-      if (BlobChild* blobChild = remoteBlob->GetBlobChild()) {
-        if (PBackgroundChild* blobManager = blobChild->GetBackgroundManager()) {
-          PBackgroundChild* backgroundManager =
-            BackgroundChild::GetForCurrentThread();
-          MOZ_ASSERT(backgroundManager);
-
-          if (blobManager != backgroundManager) {
-            // Always make sure we have a blob from an actor we can use on this
-            // thread.
-            blobChild = BlobChild::GetOrCreate(backgroundManager, mBlobImpl);
-            MOZ_ASSERT(blobChild);
-
-            newBlobImplHolder = blobChild->GetBlobImpl();
-            MOZ_ASSERT(newBlobImplHolder);
-
-            mBlobImpl = newBlobImplHolder;
-          }
-        }
-      }
-    }
-
     DebugOnly<bool> isMutable;
     MOZ_ASSERT(NS_SUCCEEDED(mBlobImpl->GetMutable(&isMutable)));
     MOZ_ASSERT(!isMutable);
 
     nsCOMPtr<nsIPrincipal> principal = mWorkerPrivate->GetPrincipal();
 
     nsAutoCString url;
     nsresult rv =