Bug 1463889 part 1. Switch nsPIDOMWindowOuter::GetFrames to returning an nsDOMWindowList. r=qdot
authorBoris Zbarsky <bzbarsky@mit.edu>
Thu, 24 May 2018 23:32:19 -0400
changeset 419781 65911939342cfc409769dce5ee51c0052f04a879
parent 419780 b865f2b5fb123595a56bf44e895fd50e4231cac1
child 419782 1615e41be9ee378f154b5a8c416a98fba59fcb92
push id103619
push userbzbarsky@mozilla.com
push dateFri, 25 May 2018 03:36:06 +0000
treeherdermozilla-inbound@c3d5f4c7e1d9 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersqdot
bugs1463889
milestone62.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 1463889 part 1. Switch nsPIDOMWindowOuter::GetFrames to returning an nsDOMWindowList. r=qdot
chrome/nsChromeRegistry.cpp
dom/base/nsDOMWindowList.cpp
dom/base/nsDOMWindowList.h
dom/base/nsGlobalWindowInner.cpp
dom/base/nsGlobalWindowInner.h
dom/base/nsGlobalWindowOuter.cpp
dom/base/nsGlobalWindowOuter.h
dom/base/nsPIDOMWindow.h
dom/base/nsWindowMemoryReporter.cpp
js/xpconnect/wrappers/AccessCheck.cpp
--- a/chrome/nsChromeRegistry.cpp
+++ b/chrome/nsChromeRegistry.cpp
@@ -11,19 +11,19 @@
 #include "nsCOMPtr.h"
 #include "nsError.h"
 #include "nsEscape.h"
 #include "nsNetUtil.h"
 #include "nsString.h"
 #include "nsQueryObject.h"
 
 #include "mozilla/dom/URL.h"
+#include "nsDOMWindowList.h"
 #include "nsIConsoleService.h"
 #include "nsIDocument.h"
-#include "nsIDOMWindowCollection.h"
 #include "nsIDOMWindow.h"
 #include "nsIObserverService.h"
 #include "nsIPresShell.h"
 #include "nsIScriptError.h"
 #include "nsIWindowMediator.h"
 #include "nsIPrefService.h"
 #include "mozilla/Preferences.h"
 #include "mozilla/Printf.h"
@@ -376,24 +376,20 @@ nsChromeRegistry::FlushSkinCaches()
   obsSvc->NotifyObservers(static_cast<nsIChromeRegistry*>(this),
                           NS_CHROME_FLUSH_SKINS_TOPIC, nullptr);
 }
 
 // XXXbsmedberg: move this to windowmediator
 nsresult nsChromeRegistry::RefreshWindow(nsPIDOMWindowOuter* aWindow)
 {
   // Deal with our subframes first.
-  nsCOMPtr<nsIDOMWindowCollection> frames = aWindow->GetFrames();
-  uint32_t length;
-  frames->GetLength(&length);
-  uint32_t j;
-  for (j = 0; j < length; j++) {
-    nsCOMPtr<mozIDOMWindowProxy> childWin;
-    frames->Item(j, getter_AddRefs(childWin));
-    nsCOMPtr<nsPIDOMWindowOuter> piWindow = nsPIDOMWindowOuter::From(childWin);
+  nsDOMWindowList* frames = aWindow->GetFrames();
+  uint32_t length = frames->GetLength();
+  for (uint32_t j = 0; j < length; j++) {
+    nsCOMPtr<nsPIDOMWindowOuter> piWindow = frames->IndexedGetter(j);
     RefreshWindow(piWindow);
   }
 
   nsresult rv;
   // Get the document.
   nsCOMPtr<nsIDocument> document = aWindow->GetDoc();
   if (!document)
     return NS_OK;
--- a/dom/base/nsDOMWindowList.cpp
+++ b/dom/base/nsDOMWindowList.cpp
@@ -95,29 +95,32 @@ nsDOMWindowList::IndexedGetter(uint32_t 
 NS_IMETHODIMP
 nsDOMWindowList::Item(uint32_t aIndex, mozIDOMWindowProxy** aReturn)
 {
   nsCOMPtr<nsPIDOMWindowOuter> window = IndexedGetter(aIndex);
   window.forget(aReturn);
   return NS_OK;
 }
 
+already_AddRefed<nsPIDOMWindowOuter>
+nsDOMWindowList::NamedItem(const nsAString& aName)
+{
+  EnsureFresh();
+
+  if (!mDocShellNode) {
+    return nullptr;
+  }
+
+  nsCOMPtr<nsIDocShellTreeItem> item;
+  mDocShellNode->FindChildWithName(aName, false, false, nullptr,
+                                   nullptr, getter_AddRefs(item));
+
+  nsCOMPtr<nsPIDOMWindowOuter> childWindow(do_GetInterface(item));
+  return childWindow.forget();
+}
+
 NS_IMETHODIMP
 nsDOMWindowList::NamedItem(const nsAString& aName, mozIDOMWindowProxy** aReturn)
 {
-  nsCOMPtr<nsIDocShellTreeItem> item;
-
-  *aReturn = nullptr;
-
-  EnsureFresh();
-
-  if (mDocShellNode) {
-    mDocShellNode->FindChildWithName(aName, false, false, nullptr,
-                                     nullptr, getter_AddRefs(item));
-
-    nsCOMPtr<nsIScriptGlobalObject> globalObject(do_GetInterface(item));
-    if (globalObject) {
-      CallQueryInterface(globalObject.get(), aReturn);
-    }
-  }
-
+  nsCOMPtr<nsPIDOMWindowOuter> item = NamedItem(aName);
+  item.forget(aReturn);
   return NS_OK;
 }
--- a/dom/base/nsDOMWindowList.h
+++ b/dom/base/nsDOMWindowList.h
@@ -19,16 +19,17 @@ class nsDOMWindowList : public nsIDOMWin
 public:
   explicit nsDOMWindowList(nsIDocShell* aDocShell);
 
   NS_DECL_ISUPPORTS
   NS_DECL_NSIDOMWINDOWCOLLECTION
 
   uint32_t GetLength();
   already_AddRefed<nsPIDOMWindowOuter> IndexedGetter(uint32_t aIndex);
+  already_AddRefed<nsPIDOMWindowOuter> NamedItem(const nsAString& aName);
 
   //local methods
   NS_IMETHOD SetDocShell(nsIDocShell* aDocShell);
   already_AddRefed<nsIDocShellTreeItem> GetDocShellTreeItemAt(uint32_t aIndex)
   {
     EnsureFresh();
     nsCOMPtr<nsIDocShellTreeItem> item;
     if (mDocShellNode) {
--- a/dom/base/nsGlobalWindowInner.cpp
+++ b/dom/base/nsGlobalWindowInner.cpp
@@ -2809,17 +2809,17 @@ nsGlobalWindowInner::GetScrollbars(Error
 }
 
 bool
 nsGlobalWindowInner::GetClosed(ErrorResult& aError)
 {
   FORWARD_TO_OUTER_OR_THROW(GetClosedOuter, (), aError, false);
 }
 
-already_AddRefed<nsIDOMWindowCollection>
+nsDOMWindowList*
 nsGlobalWindowInner::GetFrames()
 {
   FORWARD_TO_OUTER(GetFrames, (), nullptr);
 }
 
 already_AddRefed<nsPIDOMWindowOuter>
 nsGlobalWindowInner::IndexedGetter(uint32_t aIndex)
 {
--- a/dom/base/nsGlobalWindowInner.h
+++ b/dom/base/nsGlobalWindowInner.h
@@ -645,17 +645,17 @@ public:
   void SetStatus(const nsAString& aStatus, mozilla::ErrorResult& aError);
   void Close(mozilla::ErrorResult& aError);
   nsresult Close() override;
   bool GetClosed(mozilla::ErrorResult& aError);
   void Stop(mozilla::ErrorResult& aError);
   void Focus(mozilla::ErrorResult& aError);
   nsresult Focus() override;
   void Blur(mozilla::ErrorResult& aError);
-  already_AddRefed<nsIDOMWindowCollection> GetFrames() override;
+  nsDOMWindowList* GetFrames() final;
   already_AddRefed<nsPIDOMWindowOuter> GetFrames(mozilla::ErrorResult& aError);
   uint32_t Length();
   already_AddRefed<nsPIDOMWindowOuter> GetTop(mozilla::ErrorResult& aError);
 protected:
   explicit nsGlobalWindowInner(nsGlobalWindowOuter *aOuterWindow);
   // Initializes the mWasOffline member variable
   void InitWasOffline();
 public:
--- a/dom/base/nsGlobalWindowOuter.cpp
+++ b/dom/base/nsGlobalWindowOuter.cpp
@@ -2918,21 +2918,20 @@ nsGlobalWindowOuter::GetWindowList()
 {
   if (!mFrames && mDocShell) {
     mFrames = new nsDOMWindowList(mDocShell);
   }
 
   return mFrames;
 }
 
-already_AddRefed<nsIDOMWindowCollection>
+nsDOMWindowList*
 nsGlobalWindowOuter::GetFrames()
 {
-  nsCOMPtr<nsIDOMWindowCollection> frames = GetWindowList();
-  return frames.forget();
+  return GetWindowList();
 }
 
 already_AddRefed<nsPIDOMWindowOuter>
 nsGlobalWindowOuter::IndexedGetterOuter(uint32_t aIndex)
 {
   nsDOMWindowList* windows = GetWindowList();
   NS_ENSURE_TRUE(windows, nullptr);
 
--- a/dom/base/nsGlobalWindowOuter.h
+++ b/dom/base/nsGlobalWindowOuter.h
@@ -577,17 +577,17 @@ public:
   nsresult Close() override;
   bool GetClosedOuter();
   bool Closed() override;
   void StopOuter(mozilla::ErrorResult& aError);
   void FocusOuter(mozilla::ErrorResult& aError);
   nsresult Focus() override;
   void BlurOuter();
   already_AddRefed<nsPIDOMWindowOuter> GetFramesOuter();
-  already_AddRefed<nsIDOMWindowCollection> GetFrames() override;
+  nsDOMWindowList* GetFrames() final;
   uint32_t Length();
   already_AddRefed<nsPIDOMWindowOuter> GetTopOuter();
 
   nsresult GetPrompter(nsIPrompt** aPrompt) override;
 protected:
   explicit nsGlobalWindowOuter();
   nsPIDOMWindowOuter* GetOpenerWindowOuter();
   // Initializes the mWasOffline member variable
--- a/dom/base/nsPIDOMWindow.h
+++ b/dom/base/nsPIDOMWindow.h
@@ -17,16 +17,17 @@
 #include "js/TypeDecls.h"
 #include "nsRefPtrHashtable.h"
 
 // Only fired for inner windows.
 #define DOM_WINDOW_DESTROYED_TOPIC "dom-window-destroyed"
 #define DOM_WINDOW_FROZEN_TOPIC "dom-window-frozen"
 #define DOM_WINDOW_THAWED_TOPIC "dom-window-thawed"
 
+class nsDOMWindowList;
 class nsGlobalWindowInner;
 class nsGlobalWindowOuter;
 class nsIArray;
 class nsIContent;
 class nsICSSDeclaration;
 class nsIDocShell;
 class nsIDocShellLoadInfo;
 class nsIDocument;
@@ -583,17 +584,17 @@ public:
     return mMarkedCCGeneration;
   }
 
   mozilla::dom::Navigator* Navigator();
   virtual mozilla::dom::Location* GetLocation() = 0;
 
   virtual nsresult GetControllers(nsIControllers** aControllers) = 0;
 
-  virtual already_AddRefed<nsIDOMWindowCollection> GetFrames() = 0;
+  virtual nsDOMWindowList* GetFrames() = 0;
 
   virtual nsresult GetInnerWidth(int32_t* aWidth) = 0;
   virtual nsresult GetInnerHeight(int32_t* aHeight) = 0;
 
   virtual already_AddRefed<nsICSSDeclaration>
   GetComputedStyle(mozilla::dom::Element& aElt, const nsAString& aPseudoElt,
                    mozilla::ErrorResult& aError) = 0;
 
@@ -1085,17 +1086,17 @@ public:
   virtual mozilla::dom::Navigator* GetNavigator() = 0;
   virtual mozilla::dom::Location* GetLocation() = 0;
 
   virtual nsresult GetPrompter(nsIPrompt** aPrompt) = 0;
   virtual nsresult GetControllers(nsIControllers** aControllers) = 0;
   virtual already_AddRefed<mozilla::dom::Selection> GetSelection() = 0;
   virtual already_AddRefed<nsPIDOMWindowOuter> GetOpener() = 0;
 
-  virtual already_AddRefed<nsIDOMWindowCollection> GetFrames() = 0;
+  virtual nsDOMWindowList* GetFrames() = 0;
 
   // aLoadInfo will be passed on through to the windowwatcher.
   // aForceNoOpener will act just like a "noopener" feature in aOptions except
   //                will not affect any other window features.
   virtual nsresult Open(const nsAString& aUrl, const nsAString& aName,
                         const nsAString& aOptions,
                         nsIDocShellLoadInfo* aLoadInfo,
                         bool aForceNoOpener,
--- a/dom/base/nsWindowMemoryReporter.cpp
+++ b/dom/base/nsWindowMemoryReporter.cpp
@@ -3,17 +3,17 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "nsWindowMemoryReporter.h"
 #include "nsWindowSizes.h"
 #include "nsGlobalWindow.h"
 #include "nsIDocument.h"
-#include "nsIDOMWindowCollection.h"
+#include "nsDOMWindowList.h"
 #include "mozilla/ClearOnShutdown.h"
 #include "mozilla/Preferences.h"
 #include "mozilla/Services.h"
 #include "mozilla/StaticPtr.h"
 #include "mozilla/Telemetry.h"
 #include "nsNetCID.h"
 #include "nsPrintfCString.h"
 #include "XPCJSMemoryReporter.h"
@@ -62,32 +62,28 @@ AddNonJSSizeOfWindowAndItsDescendents(ns
   // Measure the inner window, if there is one.
   nsGlobalWindowInner* inner = aWindow->GetCurrentInnerWindowInternal();
   if (inner) {
     inner->AddSizeOfIncludingThis(windowSizes);
   }
 
   windowSizes.addToTabSizes(aSizes);
 
-  nsCOMPtr<nsIDOMWindowCollection> frames = aWindow->GetFrames();
+  nsDOMWindowList* frames = aWindow->GetFrames();
 
-  uint32_t length;
-  nsresult rv = frames->GetLength(&length);
-  NS_ENSURE_SUCCESS(rv, rv);
+  uint32_t length = frames->GetLength();
 
   // Measure this window's descendents.
   for (uint32_t i = 0; i < length; i++) {
-      nsCOMPtr<mozIDOMWindowProxy> child;
-      rv = frames->Item(i, getter_AddRefs(child));
-      NS_ENSURE_SUCCESS(rv, rv);
+      nsCOMPtr<nsPIDOMWindowOuter> child = frames->IndexedGetter(i);
       NS_ENSURE_STATE(child);
 
       nsGlobalWindowOuter* childWin = nsGlobalWindowOuter::Cast(child);
 
-      rv = AddNonJSSizeOfWindowAndItsDescendents(childWin, aSizes);
+      nsresult rv = AddNonJSSizeOfWindowAndItsDescendents(childWin, aSizes);
       NS_ENSURE_SUCCESS(rv, rv);
   }
   return NS_OK;
 }
 
 static nsresult
 NonJSSizeOfTab(nsPIDOMWindowOuter* aWindow, size_t* aDomSize, size_t* aStyleSize, size_t* aOtherSize)
 {
--- a/js/xpconnect/wrappers/AccessCheck.cpp
+++ b/js/xpconnect/wrappers/AccessCheck.cpp
@@ -3,29 +3,29 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "AccessCheck.h"
 
 #include "nsJSPrincipals.h"
 #include "BasePrincipal.h"
+#include "nsDOMWindowList.h"
 #include "nsGlobalWindow.h"
 
 #include "XPCWrapper.h"
 #include "XrayWrapper.h"
 #include "FilteringWrapper.h"
 
 #include "jsfriendapi.h"
 #include "mozilla/ErrorResult.h"
 #include "mozilla/dom/BindingUtils.h"
 #include "mozilla/dom/LocationBinding.h"
 #include "mozilla/dom/WindowBinding.h"
 #include "mozilla/jsipc/CrossProcessObjectWrappers.h"
-#include "nsIDOMWindowCollection.h"
 #include "nsJSUtils.h"
 #include "xpcprivate.h"
 
 using namespace mozilla;
 using namespace JS;
 using namespace js;
 
 namespace xpc {
@@ -129,30 +129,30 @@ IsFrameId(JSContext* cx, JSObject* obj, 
     MOZ_ASSERT(!js::IsWrapper(obj));
     RootedId id(cx, idArg);
 
     nsGlobalWindowInner* win = WindowOrNull(obj);
     if (!win) {
         return false;
     }
 
-    nsCOMPtr<nsIDOMWindowCollection> col = win->GetFrames();
+    nsDOMWindowList* col = win->GetFrames();
     if (!col) {
         return false;
     }
 
     nsCOMPtr<mozIDOMWindowProxy> domwin;
     if (JSID_IS_INT(id)) {
-        col->Item(JSID_TO_INT(id), getter_AddRefs(domwin));
+        domwin = col->IndexedGetter(JSID_TO_INT(id));
     } else if (JSID_IS_STRING(id)) {
         nsAutoJSString idAsString;
         if (!idAsString.init(cx, JSID_TO_STRING(id))) {
             return false;
         }
-        col->NamedItem(idAsString, getter_AddRefs(domwin));
+        domwin = col->NamedItem(idAsString);
     }
 
     return domwin != nullptr;
 }
 
 CrossOriginObjectType
 IdentifyCrossOriginObject(JSObject* obj)
 {