Bug 1281762 - nsWindowRoot::mPopupNode may keep otherwise closed documents alive, r=enn, a=sylvestre
authorOlli Pettay <Olli.Pettay@helsinki.fi>
Thu, 23 Jun 2016 17:14:19 +0300
changeset 339715 74763893c0f373a9fa4a1c61cbf9d1b49cc9bb5f
parent 339714 af923f4926e7606c93218467f4de253c9a2bc783
child 339716 fe554517e03254038f631fa624f9f0badf83ca15
push id6249
push userjlund@mozilla.com
push dateMon, 01 Aug 2016 13:59:36 +0000
treeherdermozilla-beta@bad9d4f5bf7e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersenn, sylvestre
bugs1281762
milestone49.0a2
Bug 1281762 - nsWindowRoot::mPopupNode may keep otherwise closed documents alive, r=enn, a=sylvestre
dom/base/nsWindowRoot.cpp
dom/base/nsWindowRoot.h
--- a/dom/base/nsWindowRoot.cpp
+++ b/dom/base/nsWindowRoot.cpp
@@ -44,17 +44,16 @@ nsWindowRoot::~nsWindowRoot()
   if (mListenerManager) {
     mListenerManager->Disconnect();
   }
 }
 
 NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE(nsWindowRoot,
                                       mWindow,
                                       mListenerManager,
-                                      mPopupNode,
                                       mParent)
 
 NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(nsWindowRoot)
   NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY
   NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIDOMEventTarget)
   NS_INTERFACE_MAP_ENTRY(nsPIWindowRoot)
   NS_INTERFACE_MAP_ENTRY(nsIDOMEventTarget)
   NS_INTERFACE_MAP_ENTRY(mozilla::dom::EventTarget)
@@ -358,23 +357,24 @@ nsWindowRoot::GetEnabledDisabledCommands
     nsGlobalWindow* win = nsGlobalWindow::Cast(focusedWindow);
     focusedWindow = win->GetPrivateParent();
   }
 }
 
 nsIDOMNode*
 nsWindowRoot::GetPopupNode()
 {
-  return mPopupNode;
+  nsCOMPtr<nsIDOMNode> popupNode = do_QueryReferent(mPopupNode);
+  return popupNode;
 }
 
 void
 nsWindowRoot::SetPopupNode(nsIDOMNode* aNode)
 {
-  mPopupNode = aNode;
+  mPopupNode = do_GetWeakReference(aNode);
 }
 
 nsIGlobalObject*
 nsWindowRoot::GetParentObject()
 {
   return xpc::NativeGlobal(xpc::PrivilegedJunkScope());
 }
 
--- a/dom/base/nsWindowRoot.h
+++ b/dom/base/nsWindowRoot.h
@@ -8,16 +8,17 @@
 #define nsWindowRoot_h__
 
 class nsIDOMEvent;
 class nsIGlobalObject;
 
 #include "mozilla/Attributes.h"
 #include "mozilla/EventListenerManager.h"
 #include "nsIDOMEventTarget.h"
+#include "nsIWeakReferenceUtils.h"
 #include "nsPIWindowRoot.h"
 #include "nsCycleCollectionParticipant.h"
 #include "nsAutoPtr.h"
 #include "nsTHashtable.h"
 #include "nsHashKeys.h"
 
 class nsWindowRoot final : public nsPIWindowRoot
 {
@@ -79,17 +80,17 @@ protected:
                                                 nsTHashtable<nsCharPtrHashKey>& aCommandsHandled,
                                                 nsTArray<nsCString>& aEnabledCommands,
                                                 nsTArray<nsCString>& aDisabledCommands);
 
   // Members
   nsCOMPtr<nsPIDOMWindowOuter> mWindow;
   // We own the manager, which owns event listeners attached to us.
   RefPtr<mozilla::EventListenerManager> mListenerManager; // [Strong]
-  nsCOMPtr<nsIDOMNode> mPopupNode; // [OWNER]
+  nsWeakPtr mPopupNode;
 
   nsCOMPtr<mozilla::dom::EventTarget> mParent;
 
   // The TabParents that are currently registered with this top-level window.
   typedef nsTHashtable<nsRefPtrHashKey<nsIWeakReference>> WeakBrowserTable;
   WeakBrowserTable mWeakBrowsers;
 };