Bug 1552751 - MessagePort should not work when created from a disconnected window, r=smaug
authorAndrea Marchesini <amarchesini@mozilla.com>
Thu, 23 May 2019 13:44:17 +0000
changeset 475194 4ff05bda88b2aa7f9aac46bf68b9669b3ad0f655
parent 475193 3b4d36cfde13ee105da6c3a8ed6f2e25c211cee1
child 475195 eaafaaab2b4d5ec0fbd553eb951d0cea2c82ff77
push id36057
push useraciure@mozilla.com
push dateThu, 23 May 2019 21:52:03 +0000
treeherdermozilla-central@d551d37b9ad0 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssmaug
bugs1552751
milestone69.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1552751 - MessagePort should not work when created from a disconnected window, r=smaug Differential Revision: https://phabricator.services.mozilla.com/D32265
dom/messagechannel/MessageChannel.cpp
--- a/dom/messagechannel/MessageChannel.cpp
+++ b/dom/messagechannel/MessageChannel.cpp
@@ -73,13 +73,21 @@ already_AddRefed<MessageChannel> Message
   channel->mPort2 = MessagePort::Create(aGlobal, portUUID2, portUUID1, aRv);
   if (NS_WARN_IF(aRv.Failed())) {
     return nullptr;
   }
 
   channel->mPort1->UnshippedEntangle(channel->mPort2);
   channel->mPort2->UnshippedEntangle(channel->mPort1);
 
+  // MessagePorts should not work if created from a disconnected window.
+  nsCOMPtr<nsPIDOMWindowInner> window = do_QueryInterface(aGlobal);
+  if (window && !window->GetDocShell()) {
+    // The 2 ports are entangled. We can close one of them to close the other
+    // too.
+    channel->mPort1->CloseForced();
+  }
+
   return channel.forget();
 }
 
 }  // namespace dom
 }  // namespace mozilla