1313#include " mozilla/dom/WorkerRunnable.h"
1414#include " nsContentUtils.h"
1515#include " nsIDocument.h"
16+ #include " nsIGlobalObject.h"
1617#include " nsIPrincipal.h"
17- #include " nsPIDOMWindow.h"
1818#include " nsServiceManagerUtils.h"
1919
2020namespace mozilla {
2121namespace dom {
2222
23- NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE (MessageChannel, mWindow , mPort1 , mPort2 )
23+ NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE (MessageChannel, mGlobal , mPort1 , mPort2 )
2424NS_IMPL_CYCLE_COLLECTING_ADDREF (MessageChannel)
2525NS_IMPL_CYCLE_COLLECTING_RELEASE (MessageChannel)
2626
@@ -29,9 +29,10 @@ NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(MessageChannel)
2929 NS_INTERFACE_MAP_ENTRY (nsISupports)
3030NS_INTERFACE_MAP_END
3131
32- MessageChannel::MessageChannel (nsPIDOMWindowInner* aWindow )
33- : mWindow (aWindow )
32+ MessageChannel::MessageChannel (nsIGlobalObject* aGlobal )
33+ : mGlobal (aGlobal )
3434{
35+ MOZ_ASSERT (aGlobal);
3536}
3637
3738MessageChannel::~MessageChannel ()
@@ -47,14 +48,15 @@ MessageChannel::WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto)
4748/* static */ already_AddRefed<MessageChannel>
4849MessageChannel::Constructor (const GlobalObject& aGlobal, ErrorResult& aRv)
4950{
50- // window can be null in workers.
51- nsCOMPtr<nsPIDOMWindowInner> window = do_QueryInterface (aGlobal.GetAsSupports ());
52- return Constructor (window, aRv);
51+ nsCOMPtr<nsIGlobalObject> global = do_QueryInterface (aGlobal.GetAsSupports ());
52+ return Constructor (global, aRv);
5353}
5454
5555/* static */ already_AddRefed<MessageChannel>
56- MessageChannel::Constructor (nsPIDOMWindowInner* aWindow , ErrorResult& aRv)
56+ MessageChannel::Constructor (nsIGlobalObject* aGlobal , ErrorResult& aRv)
5757{
58+ MOZ_ASSERT (aGlobal);
59+
5860 nsID portUUID1;
5961 aRv = nsContentUtils::GenerateUUIDInPlace (portUUID1);
6062 if (aRv.Failed ()) {
@@ -67,14 +69,14 @@ MessageChannel::Constructor(nsPIDOMWindowInner* aWindow, ErrorResult& aRv)
6769 return nullptr ;
6870 }
6971
70- RefPtr<MessageChannel> channel = new MessageChannel (aWindow );
72+ RefPtr<MessageChannel> channel = new MessageChannel (aGlobal );
7173
72- channel->mPort1 = MessagePort::Create (aWindow , portUUID1, portUUID2, aRv);
74+ channel->mPort1 = MessagePort::Create (aGlobal , portUUID1, portUUID2, aRv);
7375 if (NS_WARN_IF(aRv.Failed ())) {
7476 return nullptr ;
7577 }
7678
77- channel->mPort2 = MessagePort::Create (aWindow , portUUID2, portUUID1, aRv);
79+ channel->mPort2 = MessagePort::Create (aGlobal , portUUID2, portUUID1, aRv);
7880 if (NS_WARN_IF(aRv.Failed ())) {
7981 return nullptr ;
8082 }
0 commit comments