Bug 1342303 part 5 - Remove nsCOMArray::EnumerateForwards uses in xpfe. r=erahm draft
authorXidorn Quan <me@upsuper.org>
Fri, 24 Feb 2017 22:01:42 +1100
changeset 493005 2741fce7196d8ffb90f75b7bb8bcfbe6237178eb
parent 493004 60d1179aa28c9166fdcd9053f8b8c1708fa128c9
child 493006 30d47e2350ed863507302b6765c0e4b3937a182f
push id47619
push userxquan@mozilla.com
push dateFri, 03 Mar 2017 04:20:26 +0000
reviewerserahm
bugs1342303
milestone54.0a1
Bug 1342303 part 5 - Remove nsCOMArray::EnumerateForwards uses in xpfe. r=erahm MozReview-Commit-ID: j8csvjSYUM
xpfe/appshell/nsWindowMediator.cpp
--- a/xpfe/appshell/nsWindowMediator.cpp
+++ b/xpfe/appshell/nsWindowMediator.cpp
@@ -22,26 +22,16 @@
 
 #include "nsIDocShell.h"
 #include "nsIInterfaceRequestor.h"
 #include "nsIInterfaceRequestorUtils.h"
 #include "nsIXULWindow.h"
 
 using namespace mozilla;
 
-static bool notifyOpenWindow(nsIWindowMediatorListener *aElement, void* aData);
-static bool notifyCloseWindow(nsIWindowMediatorListener *aElement, void* aData);
-static bool notifyWindowTitleChange(nsIWindowMediatorListener *aElement, void* aData);
-
-// for notifyWindowTitleChange
-struct WindowTitleData {
-  nsIXULWindow* mWindow;
-  const char16_t *mTitle;
-};
-
 nsresult
 nsWindowMediator::GetDOMWindow(nsIXULWindow* inWindow,
                                nsCOMPtr<nsPIDOMWindowOuter>& outDOMWindow)
 {
   nsCOMPtr<nsIDocShell> docShell;
 
   outDOMWindow = nullptr;
   inWindow->GetDocShell(getter_AddRefs(docShell));
@@ -86,19 +76,20 @@ NS_IMETHODIMP nsWindowMediator::Register
     return NS_ERROR_FAILURE;
   }
 
   mTimeStamp++;
 
   // Create window info struct and add to list of windows
   nsWindowInfo* windowInfo = new nsWindowInfo(inWindow, mTimeStamp);
 
-  WindowTitleData winData = { inWindow, nullptr };
-  mListeners.EnumerateForwards(notifyOpenWindow, &winData);
-  
+  for (nsIWindowMediatorListener* listener : mListeners) {
+    listener->OnOpenWindow(inWindow);
+  }
+
   if (mOldestWindow)
     windowInfo->InsertAfter(mOldestWindow->mOlder, nullptr);
   else
     mOldestWindow = windowInfo;
 
   return NS_OK;
 }
 
@@ -118,18 +109,19 @@ nsWindowMediator::UnregisterWindow(nsWin
 {
   // Inform the iterators
   uint32_t index = 0;
   while (index < mEnumeratorList.Length()) {
     mEnumeratorList[index]->WindowRemoved(inInfo);
     index++;
   }
   
-  WindowTitleData winData = { inInfo->mWindow.get(), nullptr };
-  mListeners.EnumerateForwards(notifyCloseWindow, &winData);
+  for (nsIWindowMediatorListener* listener : mListeners) {
+    listener->OnCloseWindow(inInfo->mWindow.get());
+  }
 
   // Remove from the lists and free up 
   if (inInfo == mOldestWindow)
     mOldestWindow = inInfo->mYounger;
   if (inInfo == mTopmostWindow)
     mTopmostWindow = inInfo->mLower;
   inInfo->Unlink(true, true);
   if (inInfo == mOldestWindow)
@@ -402,18 +394,19 @@ nsWindowMediator::UpdateWindowTimeStamp(
 
 NS_IMETHODIMP
 nsWindowMediator::UpdateWindowTitle(nsIXULWindow* inWindow,
                                     const char16_t* inTitle)
 {
   MOZ_RELEASE_ASSERT(NS_IsMainThread());
   NS_ENSURE_STATE(mReady);
   if (GetInfoFor(inWindow)) {
-    WindowTitleData winData = { inWindow, inTitle };
-    mListeners.EnumerateForwards(notifyWindowTitleChange, &winData);
+    for (nsIWindowMediatorListener* listener : mListeners) {
+      listener->OnWindowTitleChange(inWindow, inTitle);
+    }
   }
 
   return NS_OK;
 }
 
 /* This method's plan is to intervene only when absolutely necessary.
    We will get requests to place our windows behind unknown windows.
    For the most part, we need to leave those alone (turning them into
@@ -812,35 +805,8 @@ nsWindowMediator::Observe(nsISupports* a
   if (!strcmp(aTopic, "xpcom-shutdown") && mReady) {
     MOZ_RELEASE_ASSERT(NS_IsMainThread());
     while (mOldestWindow)
       UnregisterWindow(mOldestWindow);
     mReady = false;
   }
   return NS_OK;
 }
-
-bool
-notifyOpenWindow(nsIWindowMediatorListener *aListener, void* aData)
-{
-  WindowTitleData* winData = static_cast<WindowTitleData*>(aData);
-  aListener->OnOpenWindow(winData->mWindow);
-
-  return true;
-}
-
-bool
-notifyCloseWindow(nsIWindowMediatorListener *aListener, void* aData)
-{
-  WindowTitleData* winData = static_cast<WindowTitleData*>(aData);
-  aListener->OnCloseWindow(winData->mWindow);
-
-  return true;
-}
-
-bool 
-notifyWindowTitleChange(nsIWindowMediatorListener *aListener, void* aData)
-{
-  WindowTitleData* titleData = reinterpret_cast<WindowTitleData*>(aData);
-  aListener->OnWindowTitleChange(titleData->mWindow, titleData->mTitle);
-
-  return true;
-}