Bug 1221992 - Skip closed windows in GetMostRecentNonPBWindow. r=smaug
authorCatalin Badea <catalin.badea392@gmail.com>
Fri, 11 Dec 2015 13:32:15 -0500
changeset 276229 f8931d8e5e4647cbf1e591851d5d1c9f7190a060
parent 276228 7f5522ec58503986db0b9c89c630b00f2b273842
child 276230 283333d47b1b1b2b55029e47c6e2d7cb4b0b9eb8
push id69082
push usercatalin.badea392@gmail.com
push dateFri, 11 Dec 2015 18:32:29 +0000
treeherdermozilla-inbound@f8931d8e5e46 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssmaug
bugs1221992
milestone45.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 1221992 - Skip closed windows in GetMostRecentNonPBWindow. r=smaug
xpfe/appshell/nsWindowMediator.cpp
xpfe/appshell/nsWindowMediator.h
--- a/xpfe/appshell/nsWindowMediator.cpp
+++ b/xpfe/appshell/nsWindowMediator.cpp
@@ -306,17 +306,18 @@ nsWindowMediator::GetMostRecentNonPBWind
     return NS_ERROR_FAILURE;
   }
 
   domWindow.forget(aWindow);
   return NS_OK;
 }
 
 nsWindowInfo*
-nsWindowMediator::MostRecentWindowInfo(const char16_t* inType, bool aSkipPrivateBrowsing)
+nsWindowMediator::MostRecentWindowInfo(const char16_t* inType,
+                                       bool aSkipPrivateBrowsingOrClosed)
 {
   int32_t       lastTimeStamp = -1;
   nsAutoString  typeString(inType);
   bool          allWindows = !inType || typeString.IsEmpty();
 
   // Find the most recent window with the highest time stamp that matches
   // the requested type and has the correct browsing mode.
   nsWindowInfo* searchInfo = mOldestWindow;
@@ -329,23 +330,28 @@ nsWindowMediator::MostRecentWindowInfo(c
       continue;
     }
     if (searchInfo->mTimeStamp < lastTimeStamp) {
       continue;
     }
     if (!searchInfo->mWindow) {
       continue;
     }
-    if (aSkipPrivateBrowsing) {
+    if (aSkipPrivateBrowsingOrClosed) {
       nsCOMPtr<nsIDocShell> docShell;
       searchInfo->mWindow->GetDocShell(getter_AddRefs(docShell));
       nsCOMPtr<nsILoadContext> loadContext = do_QueryInterface(docShell);
       if (!loadContext || loadContext->UsePrivateBrowsing()) {
         continue;
       }
+
+      nsCOMPtr<nsPIDOMWindow> piwindow = do_QueryInterface(docShell->GetWindow());
+      if (!piwindow || piwindow->Closed()) {
+        continue;
+      }
     }
 
     foundInfo = searchInfo;
     lastTimeStamp = searchInfo->mTimeStamp;
   }
 
   return foundInfo;
 }
--- a/xpfe/appshell/nsWindowMediator.h
+++ b/xpfe/appshell/nsWindowMediator.h
@@ -52,17 +52,17 @@ public:
 
   static nsresult GetDOMWindow(nsIXULWindow* inWindow,
                                nsCOMPtr<nsIDOMWindow>& outDOMWindow);
 
 private:
   int32_t AddEnumerator(nsAppShellWindowEnumerator* inEnumerator);
   int32_t RemoveEnumerator(nsAppShellWindowEnumerator* inEnumerator);
   nsWindowInfo* MostRecentWindowInfo(const char16_t* inType,
-                                     bool aSkipPrivateBrowsing = false);
+                                     bool aSkipPrivateBrowsingOrClosed = false);
 
   nsresult      UnregisterWindow(nsWindowInfo *inInfo);
   nsWindowInfo *GetInfoFor(nsIXULWindow *aWindow);
   nsWindowInfo *GetInfoFor(nsIWidget *aWindow);
   void          SortZOrderFrontToBack();
   void          SortZOrderBackToFront();
 
   nsTArray<nsAppShellWindowEnumerator*> mEnumeratorList;