Bug 1122553 - BroadcastChannel should keep FileImpl alive when sent to the PBackground actors, r=bent

This commit is contained in:
Andrea Marchesini 2015-01-17 07:29:15 +00:00
parent e39b7feaa4
commit f6d9fe809a
3 changed files with 48 additions and 2 deletions

View File

@ -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<BlobParent*>(aData.blobsParent()[0])->GetBackgroundManager() == Manager()) {
unused << SendNotify(aData);
return;
}

View File

@ -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<FileImpl> impl =
static_cast<BlobParent*>(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<nsRefPtr<FileImpl>> mFiles;
const nsString mOrigin;
const nsString mChannel;
};

View File

@ -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");