Bug 1176034 - MessagePort should force a close() if the structured clone algorithm fails, r=bent

This commit is contained in:
Andrea Marchesini
2015-06-23 15:50:00 -07:00
parent 0f4cbeab2c
commit d720e96813
14 changed files with 213 additions and 4 deletions

View File

@@ -6,16 +6,27 @@
#include "MessagePortService.h"
#include "MessagePortParent.h"
#include "SharedMessagePortMessage.h"
#include "mozilla/ipc/BackgroundParent.h"
#include "mozilla/StaticPtr.h"
#include "mozilla/unused.h"
#include "nsDataHashtable.h"
#include "nsTArray.h"
using mozilla::ipc::AssertIsOnBackgroundThread;
namespace mozilla {
namespace dom {
namespace {
StaticRefPtr<MessagePortService> gInstance;
void
AssertIsInMainProcess()
{
MOZ_ASSERT(XRE_GetProcessType() == GeckoProcessType_Default);
}
} // anonymous namespace
class MessagePortService::MessagePortServiceData final
@@ -53,9 +64,21 @@ public:
FallibleTArray<nsRefPtr<SharedMessagePortMessage>> mMessages;
};
/* static */ MessagePortService*
MessagePortService::Get()
{
AssertIsInMainProcess();
AssertIsOnBackgroundThread();
return gInstance;
}
/* static */ MessagePortService*
MessagePortService::GetOrCreate()
{
AssertIsInMainProcess();
AssertIsOnBackgroundThread();
if (!gInstance) {
gInstance = new MessagePortService();
}
@@ -248,6 +271,12 @@ MessagePortService::CloseAll(const nsID& aUUID)
CloseAll(destinationUUID);
// CloseAll calls itself recursively and it can happen that it deletes
// itself. Before continuing we must check if we are still alive.
if (!gInstance) {
return;
}
#ifdef DEBUG
mPorts.EnumerateRead(CloseAllDebugCheck, const_cast<nsID*>(&aUUID));
#endif
@@ -324,5 +353,26 @@ MessagePortService::ParentDestroy(MessagePortParent* aParent)
CloseAll(aParent->ID());
}
bool
MessagePortService::ForceClose(const nsID& aUUID,
const nsID& aDestinationUUID,
const uint32_t& aSequenceID)
{
MessagePortServiceData* data;
if (!mPorts.Get(aUUID, &data)) {
NS_WARNING("Unknown MessagePort in ForceClose()");
return true;
}
if (!data->mDestinationUUID.Equals(aDestinationUUID) ||
data->mSequenceID != aSequenceID) {
NS_WARNING("DestinationUUID and/or sequenceID do not match.");
return false;
}
CloseAll(aUUID);
return true;
}
} // dom namespace
} // mozilla namespace