diff --git a/dom/broadcastchannel/BroadcastChannelParent.cpp b/dom/broadcastchannel/BroadcastChannelParent.cpp index 2ba7576a278d..4d3191ce1a27 100644 --- a/dom/broadcastchannel/BroadcastChannelParent.cpp +++ b/dom/broadcastchannel/BroadcastChannelParent.cpp @@ -18,12 +18,16 @@ using namespace ipc; namespace dom { -BroadcastChannelParent::BroadcastChannelParent(const nsAString& aOriginChannelKey) +BroadcastChannelParent::BroadcastChannelParent(const nsACString& aOrigin, + const nsAString& aChannel, + bool aPrivateBrowsing) : mService(BroadcastChannelService::GetOrCreate()) - , mOriginChannelKey(aOriginChannelKey) + , mOrigin(aOrigin) + , mChannel(aChannel) + , mPrivateBrowsing(aPrivateBrowsing) { AssertIsOnBackgroundThread(); - mService->RegisterActor(this, mOriginChannelKey); + mService->RegisterActor(this); } BroadcastChannelParent::~BroadcastChannelParent() @@ -40,7 +44,7 @@ BroadcastChannelParent::RecvPostMessage(const ClonedMessageData& aData) return false; } - mService->PostMessage(this, aData, mOriginChannelKey); + mService->PostMessage(this, aData, mOrigin, mChannel, mPrivateBrowsing); return true; } @@ -53,7 +57,7 @@ BroadcastChannelParent::RecvClose() return false; } - mService->UnregisterActor(this, mOriginChannelKey); + mService->UnregisterActor(this); mService = nullptr; Unused << Send__delete__(this); @@ -69,33 +73,40 @@ BroadcastChannelParent::ActorDestroy(ActorDestroyReason aWhy) if (mService) { // This object is about to be released and with it, also mService will be // released too. - mService->UnregisterActor(this, mOriginChannelKey); + mService->UnregisterActor(this); } } void -BroadcastChannelParent::Deliver(const ClonedMessageData& aData) +BroadcastChannelParent::CheckAndDeliver(const ClonedMessageData& aData, + const nsCString& aOrigin, + const nsString& aChannel, + bool aPrivateBrowsing) { AssertIsOnBackgroundThread(); - // Duplicate the data for this parent. - ClonedMessageData newData(aData); + if (aOrigin == mOrigin && + aChannel == mChannel && + aPrivateBrowsing == mPrivateBrowsing) { + // Duplicate the data for this parent. + ClonedMessageData newData(aData); - // Create new BlobParent objects for this message. - for (uint32_t i = 0, len = newData.blobsParent().Length(); i < len; ++i) { - RefPtr impl = - static_cast(newData.blobsParent()[i])->GetBlobImpl(); + // Ricreate the BlobParent for this new message. + for (uint32_t i = 0, len = newData.blobsParent().Length(); i < len; ++i) { + RefPtr impl = + static_cast(newData.blobsParent()[i])->GetBlobImpl(); - PBlobParent* blobParent = - BackgroundParent::GetOrCreateActorForBlobImpl(Manager(), impl); - if (!blobParent) { - return; + PBlobParent* blobParent = + BackgroundParent::GetOrCreateActorForBlobImpl(Manager(), impl); + if (!blobParent) { + return; + } + + newData.blobsParent()[i] = blobParent; } - newData.blobsParent()[i] = blobParent; + Unused << SendNotify(newData); } - - Unused << SendNotify(newData); } } // namespace dom diff --git a/dom/broadcastchannel/BroadcastChannelParent.h b/dom/broadcastchannel/BroadcastChannelParent.h index be6e1106639e..3311db429892 100644 --- a/dom/broadcastchannel/BroadcastChannelParent.h +++ b/dom/broadcastchannel/BroadcastChannelParent.h @@ -27,10 +27,15 @@ class BroadcastChannelParent final : public PBroadcastChannelParent typedef mozilla::ipc::PrincipalInfo PrincipalInfo; public: - void Deliver(const ClonedMessageData& aData); + void CheckAndDeliver(const ClonedMessageData& aData, + const nsCString& aOrigin, + const nsString& aChannel, + bool aPrivateBrowsing); private: - explicit BroadcastChannelParent(const nsAString& aOriginChannelKey); + BroadcastChannelParent(const nsACString& aOrigin, + const nsAString& aChannel, + bool aPrivateBrowsing); ~BroadcastChannelParent(); virtual bool @@ -41,7 +46,9 @@ private: virtual void ActorDestroy(ActorDestroyReason aWhy) override; RefPtr mService; - nsString mOriginChannelKey; + nsCString mOrigin; + nsString mChannel; + bool mPrivateBrowsing; }; } // namespace dom diff --git a/dom/broadcastchannel/BroadcastChannelService.cpp b/dom/broadcastchannel/BroadcastChannelService.cpp index f88108c3a3a6..d0a3b754fda2 100644 --- a/dom/broadcastchannel/BroadcastChannelService.cpp +++ b/dom/broadcastchannel/BroadcastChannelService.cpp @@ -58,52 +58,35 @@ BroadcastChannelService::GetOrCreate() } void -BroadcastChannelService::RegisterActor(BroadcastChannelParent* aParent, - const nsAString& aOriginChannelKey) +BroadcastChannelService::RegisterActor(BroadcastChannelParent* aParent) { AssertIsOnBackgroundThread(); MOZ_ASSERT(aParent); + MOZ_ASSERT(!mAgents.Contains(aParent)); - nsTArray* parents; - if (!mAgents.Get(aOriginChannelKey, &parents)) { - parents = new nsTArray(); - mAgents.Put(aOriginChannelKey, parents); - } - - MOZ_ASSERT(!parents->Contains(aParent)); - parents->AppendElement(aParent); + mAgents.PutEntry(aParent); } void -BroadcastChannelService::UnregisterActor(BroadcastChannelParent* aParent, - const nsAString& aOriginChannelKey) +BroadcastChannelService::UnregisterActor(BroadcastChannelParent* aParent) { AssertIsOnBackgroundThread(); MOZ_ASSERT(aParent); + MOZ_ASSERT(mAgents.Contains(aParent)); - nsTArray* parents; - if (!mAgents.Get(aOriginChannelKey, &parents)) { - MOZ_CRASH("Invalid state"); - } - - parents->RemoveElement(aParent); - if (parents->IsEmpty()) { - mAgents.Remove(aOriginChannelKey); - } + mAgents.RemoveEntry(aParent); } void BroadcastChannelService::PostMessage(BroadcastChannelParent* aParent, const ClonedMessageData& aData, - const nsAString& aOriginChannelKey) + const nsACString& aOrigin, + const nsAString& aChannel, + bool aPrivateBrowsing) { AssertIsOnBackgroundThread(); MOZ_ASSERT(aParent); - - nsTArray* parents; - if (!mAgents.Get(aOriginChannelKey, &parents)) { - MOZ_CRASH("Invalid state"); - } + MOZ_ASSERT(mAgents.Contains(aParent)); // We need to keep the array alive for the life-time of this operation. nsTArray> blobs; @@ -118,12 +101,13 @@ BroadcastChannelService::PostMessage(BroadcastChannelParent* aParent, } } - for (uint32_t i = 0; i < parents->Length(); ++i) { - BroadcastChannelParent* parent = parents->ElementAt(i); + for (auto iter = mAgents.Iter(); !iter.Done(); iter.Next()) { + BroadcastChannelParent* parent = iter.Get()->GetKey(); MOZ_ASSERT(parent); if (parent != aParent) { - parent->Deliver(aData); + parent->CheckAndDeliver(aData, PromiseFlatCString(aOrigin), + PromiseFlatString(aChannel), aPrivateBrowsing); } } } diff --git a/dom/broadcastchannel/BroadcastChannelService.h b/dom/broadcastchannel/BroadcastChannelService.h index 694be3ca706b..ba3251d61078 100644 --- a/dom/broadcastchannel/BroadcastChannelService.h +++ b/dom/broadcastchannel/BroadcastChannelService.h @@ -9,7 +9,7 @@ #include "nsISupportsImpl.h" #include "nsHashKeys.h" -#include "nsDataHashtable.h" +#include "nsTHashtable.h" #ifdef XP_WIN #undef PostMessage @@ -28,22 +28,20 @@ public: static already_AddRefed GetOrCreate(); - void RegisterActor(BroadcastChannelParent* aParent, - const nsAString& aOriginChannelKey); - void UnregisterActor(BroadcastChannelParent* aParent, - const nsAString& aOriginChannelKey); + void RegisterActor(BroadcastChannelParent* aParent); + void UnregisterActor(BroadcastChannelParent* aParent); void PostMessage(BroadcastChannelParent* aParent, const ClonedMessageData& aData, - const nsAString& aOriginChannelKey); + const nsACString& aOrigin, + const nsAString& aChannel, + bool aPrivateBrowsing); private: BroadcastChannelService(); ~BroadcastChannelService(); - // Raw Pointers because the actors keep alive this service. - nsDataHashtable*> mAgents; + nsTHashtable> mAgents; }; } // namespace dom diff --git a/dom/broadcastchannel/tests/mochitest.ini b/dom/broadcastchannel/tests/mochitest.ini index 41b29bd09934..e218db09c756 100644 --- a/dom/broadcastchannel/tests/mochitest.ini +++ b/dom/broadcastchannel/tests/mochitest.ini @@ -25,4 +25,3 @@ skip-if = buildapp != 'mulet' skip-if = buildapp != 'mulet' [test_bfcache.html] [test_invalidState.html] -[test_ordering.html] diff --git a/dom/broadcastchannel/tests/test_ordering.html b/dom/broadcastchannel/tests/test_ordering.html deleted file mode 100644 index eab1f955e5ba..000000000000 --- a/dom/broadcastchannel/tests/test_ordering.html +++ /dev/null @@ -1,65 +0,0 @@ - - - - Test for BroadcastChannel.postMessage invalid State - - - - - -
- - - - - diff --git a/ipc/glue/BackgroundParentImpl.cpp b/ipc/glue/BackgroundParentImpl.cpp index 222ae8b31e49..9264ca7d1a01 100644 --- a/ipc/glue/BackgroundParentImpl.cpp +++ b/ipc/glue/BackgroundParentImpl.cpp @@ -471,22 +471,7 @@ BackgroundParentImpl::AllocPBroadcastChannelParent( AssertIsInMainProcess(); AssertIsOnBackgroundThread(); - nsString originChannelKey; - - // The format of originChannelKey is: - // |pb={true,false}| - - originChannelKey.Assign(aChannel); - - if (aPrivateBrowsing) { - originChannelKey.AppendLiteral("|pb=true|"); - } else { - originChannelKey.AppendLiteral("|pb=false|"); - } - - originChannelKey.Append(NS_ConvertUTF8toUTF16(aOrigin)); - - return new BroadcastChannelParent(originChannelKey); + return new BroadcastChannelParent(aOrigin, aChannel, aPrivateBrowsing); } namespace {