diff --git a/dom/chrome-webidl/JSWindowActor.webidl b/dom/chrome-webidl/JSWindowActor.webidl index 8a8f72305067..566edf8c5617 100644 --- a/dom/chrome-webidl/JSWindowActor.webidl +++ b/dom/chrome-webidl/JSWindowActor.webidl @@ -7,7 +7,8 @@ [NoInterfaceObject] interface JSWindowActor { [Throws] - void sendAsyncMessage(DOMString messageName, + void sendAsyncMessage(DOMString actorName, + DOMString messageName, optional any obj, optional any transfers); }; diff --git a/dom/ipc/JSWindowActorChild.cpp b/dom/ipc/JSWindowActorChild.cpp index d2ebb5fca823..c1158325979d 100644 --- a/dom/ipc/JSWindowActorChild.cpp +++ b/dom/ipc/JSWindowActorChild.cpp @@ -20,10 +20,8 @@ JSObject* JSWindowActorChild::WrapObject(JSContext* aCx, WindowGlobalChild* JSWindowActorChild::Manager() const { return mManager; } -void JSWindowActorChild::Init(const nsAString& aName, - WindowGlobalChild* aManager) { +void JSWindowActorChild::Init(WindowGlobalChild* aManager) { MOZ_ASSERT(!mManager, "Cannot Init() a JSWindowActorChild twice!"); - mName = aName; mManager = aManager; } @@ -61,6 +59,7 @@ class AsyncMessageToParent : public Runnable { } // anonymous namespace void JSWindowActorChild::SendAsyncMessage(JSContext* aCx, + const nsAString& aActorName, const nsAString& aMessageName, JS::Handle aObj, JS::Handle aTransfers, @@ -83,8 +82,8 @@ void JSWindowActorChild::SendAsyncMessage(JSContext* aCx, // loads. if (mManager->IsInProcess()) { RefPtr parent = mManager->GetParentActor(); - RefPtr ev = - new AsyncMessageToParent(mName, aMessageName, std::move(data), parent); + RefPtr ev = new AsyncMessageToParent( + aActorName, aMessageName, std::move(data), parent); DebugOnly rv = NS_DispatchToMainThread(ev); NS_WARNING_ASSERTION( NS_SUCCEEDED(rv), @@ -101,8 +100,8 @@ void JSWindowActorChild::SendAsyncMessage(JSContext* aCx, return; } - if (!mManager->SendAsyncMessage(mName, PromiseFlatString(aMessageName), - msgData)) { + if (!mManager->SendAsyncMessage(PromiseFlatString(aActorName), + PromiseFlatString(aMessageName), msgData)) { aRv.Throw(NS_ERROR_UNEXPECTED); return; } diff --git a/dom/ipc/JSWindowActorChild.h b/dom/ipc/JSWindowActorChild.h index 44ca25b8032b..eae28f2d5e17 100644 --- a/dom/ipc/JSWindowActorChild.h +++ b/dom/ipc/JSWindowActorChild.h @@ -45,13 +45,13 @@ class JSWindowActorChild final : public nsWrapperCache { } WindowGlobalChild* Manager() const; - void Init(const nsAString& aName, WindowGlobalChild* aManager); - void SendAsyncMessage(JSContext* aCx, const nsAString& aMessageName, + void Init(WindowGlobalChild* aManager); + void SendAsyncMessage(JSContext* aCx, const nsAString& aActorName, + const nsAString& aMessageName, JS::Handle aObj, JS::Handle aTransfers, ErrorResult& aRv); private: - nsString mName; RefPtr mManager; }; diff --git a/dom/ipc/JSWindowActorParent.cpp b/dom/ipc/JSWindowActorParent.cpp index b4acd395c645..30fa533525b9 100644 --- a/dom/ipc/JSWindowActorParent.cpp +++ b/dom/ipc/JSWindowActorParent.cpp @@ -19,10 +19,8 @@ JSObject* JSWindowActorParent::WrapObject(JSContext* aCx, WindowGlobalParent* JSWindowActorParent::Manager() const { return mManager; } -void JSWindowActorParent::Init(const nsAString& aName, - WindowGlobalParent* aManager) { +void JSWindowActorParent::Init(WindowGlobalParent* aManager) { MOZ_ASSERT(!mManager, "Cannot Init() a JSWindowActorParent twice!"); - mName = aName; mManager = aManager; } @@ -60,6 +58,7 @@ class AsyncMessageToChild : public Runnable { } // anonymous namespace void JSWindowActorParent::SendAsyncMessage(JSContext* aCx, + const nsAString& aActorName, const nsAString& aMessageName, JS::Handle aObj, JS::Handle aTransfers, @@ -82,8 +81,8 @@ void JSWindowActorParent::SendAsyncMessage(JSContext* aCx, // loads. if (mManager->IsInProcess()) { RefPtr child = mManager->GetChildActor(); - RefPtr ev = - new AsyncMessageToChild(mName, aMessageName, std::move(data), child); + RefPtr ev = new AsyncMessageToChild( + aActorName, aMessageName, std::move(data), child); DebugOnly rv = NS_DispatchToMainThread(ev); NS_WARNING_ASSERTION(NS_SUCCEEDED(rv), "JS Window Actor AsyncMessageToChild dispatch failed"); @@ -100,8 +99,8 @@ void JSWindowActorParent::SendAsyncMessage(JSContext* aCx, return; } - if (!mManager->SendAsyncMessage(mName, PromiseFlatString(aMessageName), - msgData)) { + if (!mManager->SendAsyncMessage(PromiseFlatString(aActorName), + PromiseFlatString(aMessageName), msgData)) { aRv.Throw(NS_ERROR_UNEXPECTED); return; } diff --git a/dom/ipc/JSWindowActorParent.h b/dom/ipc/JSWindowActorParent.h index aba2418bcf01..bffbdcaec592 100644 --- a/dom/ipc/JSWindowActorParent.h +++ b/dom/ipc/JSWindowActorParent.h @@ -45,13 +45,13 @@ class JSWindowActorParent final : public nsWrapperCache { } WindowGlobalParent* Manager() const; - void Init(const nsAString& aName, WindowGlobalParent* aManager); - void SendAsyncMessage(JSContext* aCx, const nsAString& aMessageName, + void Init(WindowGlobalParent* aManager); + void SendAsyncMessage(JSContext* aCx, const nsAString& aActorName, + const nsAString& aMessageName, JS::Handle aObj, JS::Handle aTransfers, ErrorResult& aRv); private: - nsString mName; RefPtr mManager; }; diff --git a/dom/ipc/WindowGlobalChild.cpp b/dom/ipc/WindowGlobalChild.cpp index 97a3d5ef8f53..e6a591148683 100644 --- a/dom/ipc/WindowGlobalChild.cpp +++ b/dom/ipc/WindowGlobalChild.cpp @@ -178,7 +178,7 @@ already_AddRefed WindowGlobalChild::GetActor( MOZ_RELEASE_ASSERT(!actor->Manager(), "mManager was already initialized once!"); - actor->Init(aName, this); + actor->Init(this); mWindowActors.Put(aName, actor); return actor.forget(); } diff --git a/dom/ipc/WindowGlobalParent.cpp b/dom/ipc/WindowGlobalParent.cpp index e009216dc098..cfa3519a3d35 100644 --- a/dom/ipc/WindowGlobalParent.cpp +++ b/dom/ipc/WindowGlobalParent.cpp @@ -221,7 +221,7 @@ already_AddRefed WindowGlobalParent::GetActor( MOZ_RELEASE_ASSERT(!actor->Manager(), "mManager was already initialized once!"); - actor->Init(aName, this); + actor->Init(this); mWindowActors.Put(aName, actor); return actor.forget(); } diff --git a/dom/ipc/tests/browser_JSWindowActor.js b/dom/ipc/tests/browser_JSWindowActor.js index 94fc2bf16fbf..178fcf67bbba 100644 --- a/dom/ipc/tests/browser_JSWindowActor.js +++ b/dom/ipc/tests/browser_JSWindowActor.js @@ -59,7 +59,7 @@ add_task(async function test_asyncMessage() { ok(actorChild, "JSWindowActorChild should have value."); let promise = new Promise(resolve => { - actorChild.sendAsyncMessage("init", {}); + actorChild.sendAsyncMessage("Test", "init", {}); actorChild.done = (data) => resolve(data); }).then(data => { ok(data.initial, "Initial should be true."); @@ -86,7 +86,7 @@ add_task(async function test_asyncMessage_without_both_side_actor() { ok(actorChild, "JSWindowActorChild should have value."); let promise = new Promise(resolve => { - actorChild.sendAsyncMessage("init", {}); + actorChild.sendAsyncMessage("Test", "init", {}); actorChild.done = (data) => resolve(data); }).then(data => { ok(data.initial, "Initial should be true."); @@ -99,4 +99,3 @@ add_task(async function test_asyncMessage_without_both_side_actor() { ChromeUtils.unregisterWindowActor("Test"); }); }); - diff --git a/toolkit/actors/TestChild.jsm b/toolkit/actors/TestChild.jsm index 09a22105046f..84e40ceb9124 100644 --- a/toolkit/actors/TestChild.jsm +++ b/toolkit/actors/TestChild.jsm @@ -15,7 +15,7 @@ class TestChild extends JSWindowActorChild { switch (aMessage.name) { case "toChild": aMessage.data.toChild = true; - this.sendAsyncMessage("toParent", aMessage.data); + this.sendAsyncMessage("Test", "toParent", aMessage.data); break; case "done": this.done(aMessage.data); diff --git a/toolkit/actors/TestParent.jsm b/toolkit/actors/TestParent.jsm index eef91f6c1d64..0ae67d4ffce9 100644 --- a/toolkit/actors/TestParent.jsm +++ b/toolkit/actors/TestParent.jsm @@ -15,11 +15,11 @@ class TestParent extends JSWindowActorParent { switch (aMessage.name) { case "init": aMessage.data.initial = true; - this.sendAsyncMessage("toChild", aMessage.data); + this.sendAsyncMessage("Test", "toChild", aMessage.data); break; case "toParent": aMessage.data.toParent = true; - this.sendAsyncMessage("done", aMessage.data); + this.sendAsyncMessage("Test", "done", aMessage.data); break; } } @@ -28,4 +28,3 @@ class TestParent extends JSWindowActorParent { return "TestParent"; } } -