From f6d9fe809adcbe9d868110c7a992557439b9cdd7 Mon Sep 17 00:00:00 2001 From: Andrea Marchesini Date: Sat, 17 Jan 2015 07:29:15 +0000 Subject: [PATCH] Bug 1122553 - BroadcastChannel should keep FileImpl alive when sent to the PBackground actors, r=bent --- .../BroadcastChannelParent.cpp | 6 ++-- .../BroadcastChannelService.cpp | 16 +++++++++++ .../tests/test_broadcastchannel_any.html | 28 +++++++++++++++++++ 3 files changed, 48 insertions(+), 2 deletions(-) diff --git a/dom/broadcastchannel/BroadcastChannelParent.cpp b/dom/broadcastchannel/BroadcastChannelParent.cpp index a85929d1185..b0550cf1612 100644 --- a/dom/broadcastchannel/BroadcastChannelParent.cpp +++ b/dom/broadcastchannel/BroadcastChannelParent.cpp @@ -82,8 +82,10 @@ BroadcastChannelParent::CheckAndDeliver(const ClonedMessageData& aData, AssertIsOnBackgroundThread(); if (aOrigin == mOrigin && aChannel == mChannel) { - // We need to duplicate data only if we have blobs. - if (aData.blobsParent().IsEmpty()) { + // We need to duplicate data only if we have blobs or if the manager of + // them is different than the manager of this parent actor. + if (aData.blobsParent().IsEmpty() || + static_cast(aData.blobsParent()[0])->GetBackgroundManager() == Manager()) { unused << SendNotify(aData); return; } diff --git a/dom/broadcastchannel/BroadcastChannelService.cpp b/dom/broadcastchannel/BroadcastChannelService.cpp index 41a8b22d296..b40a24d12f3 100644 --- a/dom/broadcastchannel/BroadcastChannelService.cpp +++ b/dom/broadcastchannel/BroadcastChannelService.cpp @@ -5,6 +5,8 @@ #include "BroadcastChannelService.h" #include "BroadcastChannelParent.h" +#include "mozilla/dom/File.h" +#include "mozilla/dom/ipc/BlobParent.h" #include "mozilla/ipc/BackgroundParent.h" #ifdef XP_WIN @@ -89,6 +91,19 @@ struct MOZ_STACK_CLASS PostMessageData MOZ_FINAL { MOZ_ASSERT(aParent); MOZ_COUNT_CTOR(PostMessageData); + + // We need to keep the array alive for the life-time of this + // PostMessageData. + if (!aData.blobsParent().IsEmpty()) { + mFiles.SetCapacity(aData.blobsParent().Length()); + + for (uint32_t i = 0, len = aData.blobsParent().Length(); i < len; ++i) { + nsRefPtr impl = + static_cast(aData.blobsParent()[i])->GetBlobImpl(); + MOZ_ASSERT(impl); + mFiles.AppendElement(impl); + } + } } ~PostMessageData() @@ -98,6 +113,7 @@ struct MOZ_STACK_CLASS PostMessageData MOZ_FINAL BroadcastChannelParent* mParent; const ClonedMessageData& mData; + nsTArray> mFiles; const nsString mOrigin; const nsString mChannel; }; diff --git a/dom/broadcastchannel/tests/test_broadcastchannel_any.html b/dom/broadcastchannel/tests/test_broadcastchannel_any.html index e1bbd703408..38535ce1474 100644 --- a/dom/broadcastchannel/tests/test_broadcastchannel_any.html +++ b/dom/broadcastchannel/tests/test_broadcastchannel_any.html @@ -75,15 +75,42 @@ function compare(a, b) { } function runTest() { + var count = 2; + var bc = new BroadcastChannel("foobar"); ok(bc, "BroadcastChannel can be created"); bc.onmessage = function(event) { + ok(count < 2, "Still comparing..."); + info("bc: " + currentTest); compare(event.data, currentTest); + ++count; + next(); + } + + var bc2 = new BroadcastChannel("foobar"); + ok(bc2, "BroadcastChannel can be created"); + + var toSkip = true; + bc2.onmessage = function(event) { + toSkip = !toSkip; + if (toSkip) return; + + ok(count < 2, "Still comparing..."); + info("bc2: " + currentTest); + compare(event.data, currentTest); + ++count; next(); } function next() { + if (count < 2) { + return; + } + + is(count, 2, "Just 2 comparations"); + count = 0; + if (!tests.length) { SimpleTest.finish(); return; @@ -91,6 +118,7 @@ function runTest() { currentTest = tests.shift(); bc.postMessage(currentTest); + info("Posted: " + currentTest); } var worker = new Worker("broadcastchannel_worker_any.js");