Bug 1342303 part 5 - Remove nsCOMArray::EnumerateForwards uses in xpfe. r?froydnj draft
authorXidorn Quan <me@upsuper.org>
Fri, 24 Feb 2017 22:01:42 +1100
changeset 489871 b9a8be66e511f65cb9a2880557f8ca1c31748be0
parent 489870 f3194b27737c0975d671473e2349502d48235c20
child 489872 413aad310c5203429eb1ce1e578ad7b9c1f93b6d
push id46926
push userxquan@mozilla.com
push dateSun, 26 Feb 2017 23:47:03 +0000
reviewersfroydnj
bugs1342303
milestone54.0a1
Bug 1342303 part 5 - Remove nsCOMArray::EnumerateForwards uses in xpfe. r?froydnj 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;
-}