diff --git a/mozilla/xpfe/appshell/src/nsXULWindow.cpp b/mozilla/xpfe/appshell/src/nsXULWindow.cpp index d9f7ccb8be3..784a56d658b 100644 --- a/mozilla/xpfe/appshell/src/nsXULWindow.cpp +++ b/mozilla/xpfe/appshell/src/nsXULWindow.cpp @@ -1632,8 +1632,23 @@ nsresult nsXULWindow::ContentShellAdded(nsIDocShellTreeItem* aContentShell, } #endif - NS_ENSURE_TRUE(mTargetableShells.AppendObject(contentShellWeak), - NS_ERROR_OUT_OF_MEMORY); + // put the new shell at the start of the targetable shells list if either + // it's the new primary shell or there is no existing primary shell (which + // means that chances are this one just stopped being primary). If we + // really cared, we could keep track of the "last no longer primary shell" + // explicitly, but it probably doesn't matter enough: the difference would + // only be felt in a situation where all shells were non-primary, which + // doesn't happen much. In a situation where there is one and only one + // primary shell, and in which shells get unmarked as primary before some + // other shell gets marked as primary, this effectively stores the list of + // targetable shells in "most recently primary first" order. + PRBool inserted; + if (aPrimary || !mPrimaryContentShell) { + inserted = mTargetableShells.InsertObjectAt(contentShellWeak, 0); + } else { + inserted = mTargetableShells.AppendObject(contentShellWeak); + } + NS_ENSURE_TRUE(inserted, NS_ERROR_OUT_OF_MEMORY); } return NS_OK;