Bug 1270753 part 1 - Use the weak reference itself as an index for OldWindowSize item. r=smaug, a=lizzard
authorXidorn Quan <me@upsuper.org>
Tue, 21 Jun 2016 08:19:50 +1000
changeset 339787 a220a220982c3691b9b673c499221e7401d0b3ab
parent 339786 9f1e8d6946eacd1220c8f08d9260d8f1aa33cdd0
child 339788 a1123aa655ff7e42c1a549f3fa53909a9070c79a
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)
reviewerssmaug, lizzard
bugs1270753
milestone49.0a2
Bug 1270753 part 1 - Use the weak reference itself as an index for OldWindowSize item. r=smaug, a=lizzard MozReview-Commit-ID: 3X7O5pAuZ3N
dom/base/nsDOMWindowUtils.cpp
--- a/dom/base/nsDOMWindowUtils.cpp
+++ b/dom/base/nsDOMWindowUtils.cpp
@@ -3102,64 +3102,53 @@ PrepareForFullscreenChange(nsIPresShell*
       viewManager->SetWindowDimensions(aSize.width, aSize.height);
     }
   }
 }
 
 class OldWindowSize : public LinkedListElement<OldWindowSize>
 {
 public:
-  static void Set(nsPIDOMWindowOuter* aWindow, const nsSize& aSize)
+  static void Set(nsIWeakReference* aWindowRef, const nsSize& aSize)
   {
-    OldWindowSize* item = GetItem(aWindow);
+    OldWindowSize* item = GetItem(aWindowRef);
     if (item) {
       item->mSize = aSize;
-    } else if (aWindow) {
-      item = new OldWindowSize(do_GetWeakReference(aWindow), aSize);
+    } else {
+      item = new OldWindowSize(aWindowRef, aSize);
       sList.insertBack(item);
     }
   }
 
-  static nsSize GetAndRemove(nsPIDOMWindowOuter* aWindow)
+  static nsSize GetAndRemove(nsIWeakReference* aWindowRef)
   {
     nsSize result;
-    if (OldWindowSize* item = GetItem(aWindow)) {
+    if (OldWindowSize* item = GetItem(aWindowRef)) {
       result = item->mSize;
       delete item;
     }
     return result;
   }
 
 private:
-  explicit OldWindowSize(already_AddRefed<nsIWeakReference>&& aWindow,
-                         const nsSize& aSize)
-    : mWindow(Move(aWindow)), mSize(aSize) { }
+  explicit OldWindowSize(nsIWeakReference* aWindowRef, const nsSize& aSize)
+    : mWindowRef(aWindowRef), mSize(aSize) { }
   ~OldWindowSize() { };
 
-  static OldWindowSize* GetItem(nsPIDOMWindowOuter* aWindow)
+  static OldWindowSize* GetItem(nsIWeakReference* aWindowRef)
   {
     OldWindowSize* item = sList.getFirst();
-    while (item) {
-      nsCOMPtr<nsPIDOMWindowOuter> window = do_QueryReferent(item->mWindow);
-      if (!window) {
-        OldWindowSize* thisItem = item;
-        item = thisItem->getNext();
-        delete thisItem;
-        continue;
-      }
-      if (window == aWindow) {
-        break;
-      }
+    while (item && item->mWindowRef != aWindowRef) {
       item = item->getNext();
     }
     return item;
   }
 
   static LinkedList<OldWindowSize> sList;
-  nsWeakPtr mWindow;
+  nsWeakPtr mWindowRef;
   nsSize mSize;
 };
 
 LinkedList<OldWindowSize> OldWindowSize::sList;
 
 NS_IMETHODIMP
 nsDOMWindowUtils::HandleFullscreenRequests(bool* aRetVal)
 {
@@ -3172,32 +3161,32 @@ nsDOMWindowUtils::HandleFullscreenReques
   // comes after the fullscreen change call, doing so could avoid an
   // extra resize reflow after this point.
   nsRect screenRect;
   if (nsPresContext* presContext = GetPresContext()) {
     presContext->DeviceContext()->GetRect(screenRect);
   }
   nsSize oldSize;
   PrepareForFullscreenChange(GetPresShell(), screenRect.Size(), &oldSize);
-  OldWindowSize::Set(doc->GetWindow(), oldSize);
+  OldWindowSize::Set(mWindow, oldSize);
 
   *aRetVal = nsIDocument::HandlePendingFullscreenRequests(doc);
   return NS_OK;
 }
 
 nsresult
 nsDOMWindowUtils::ExitFullscreen()
 {
   PROFILER_MARKER("Exit fullscreen");
   nsCOMPtr<nsIDocument> doc = GetDocument();
   NS_ENSURE_STATE(doc);
 
   // Although we would not use the old size if we have already exited
   // fullscreen, we still want to cleanup in case we haven't.
-  nsSize oldSize = OldWindowSize::GetAndRemove(doc->GetWindow());
+  nsSize oldSize = OldWindowSize::GetAndRemove(mWindow);
   if (!doc->GetFullscreenElement()) {
     return NS_OK;
   }
 
   // Notify the pres shell that we are starting fullscreen change, and
   // set the window dimensions in advance. Since the resize message
   // comes after the fullscreen change call, doing so could avoid an
   // extra resize reflow after this point.