Bug 1594877 - Remove xpidl [array] use in nsIMessenger.getNavigateHistory(). r=mkmelin
authorBen Campbell <benc@thunderbird.net>
Sun, 22 Dec 2019 00:08:49 +0200
changeset 37797 324f339c85f4c43e4c151e0b571e443abed9e958
parent 37796 d8d88f20aa207a30b777ec63b191d15579c8561c
child 37798 40a6184ebdaed285bef56b6499153c831281332b
push id397
push userclokep@gmail.com
push dateMon, 10 Feb 2020 21:16:13 +0000
reviewersmkmelin
bugs1594877
Bug 1594877 - Remove xpidl [array] use in nsIMessenger.getNavigateHistory(). r=mkmelin
mail/base/content/mailWindowOverlay.js
mailnews/base/public/nsIMessenger.idl
mailnews/base/src/nsMessenger.cpp
mailnews/base/src/nsMsgDBView.cpp
suite/mailnews/content/mailWindowOverlay.js
--- a/mail/base/content/mailWindowOverlay.js
+++ b/mail/base/content/mailWindowOverlay.js
@@ -1457,25 +1457,25 @@ function navDebug(str) {
   }
 }
 
 function populateHistoryMenu(menuPopup, isBackMenu) {
   // remove existing entries
   while (menuPopup.hasChildNodes()) {
     menuPopup.lastChild.remove();
   }
-  var curPos = {};
-  var numEntries = {};
-  var historyEntries = {};
-  messenger.getNavigateHistory(curPos, numEntries, historyEntries);
-  curPos.value = curPos.value * 2;
+  let historyArray = messenger.getNavigateHistory();
+  let curPos = messenger.navigatePos * 2;
   navDebug(
-    "curPos = " + curPos.value + " numEntries = " + numEntries.value + "\n"
+    "curPos = " +
+      curPos.value +
+      " historyArray.length = " +
+      historyArray.length +
+      "\n"
   );
-  var historyArray = historyEntries.value;
   var folder;
   var newMenuItem;
   if (gFolderDisplay.selectedMessage) {
     if (!isBackMenu) {
       curPos.value += 2;
     } else {
       curPos.value -= 2;
     }
--- a/mailnews/base/public/nsIMessenger.idl
+++ b/mailnews/base/public/nsIMessenger.idl
@@ -126,17 +126,18 @@ interface nsIMessenger : nsISupports {
 
     // aPos is relative to the current history cursor - 1 is forward, -1 is back.
     // Unfortunately, you must call this before navigating to this position,
     // because calling this has the side effect of making us adjust our current
     // history pos, and *not* adding the loaded message to the history queue.
     ACString getMsgUriAtNavigatePos(in long aPos);
     ACString getFolderUriAtNavigatePos(in long aPos);
     attribute long navigatePos;
-    // If caller just wants the count and cur pos, they can pass in a null history pointer, which will be more efficient
-    // if they want a list suitable for display in a back/forward menu drop down, they should pass in a aHistory pointer,
-    // and they'll get returned an array with strings containing something like subject and sender of the message -
-    // other possible info is the folder containing the message, and the preview text, if available.
-    void getNavigateHistory(out unsigned long aCurPos, out unsigned long aCount, [array, size_is(aCount)] out string aHistory);
-
+    /** Fetch the message navigation history.
+      *
+      * @returns An array containing two URIs for each history position.
+      *          First msgURI, then folderURI. So the array will be
+      *          twice as long as the number of history positions.
+      */
+    Array<ACString> getNavigateHistory();
     AString formatFileSize(in unsigned long long aPos, [optional] in boolean aUseKB);
 };
 
--- a/mailnews/base/src/nsMessenger.cpp
+++ b/mailnews/base/src/nsMessenger.cpp
@@ -1925,36 +1925,19 @@ NS_IMETHODIMP nsMessenger::GetFolderUriA
       desiredArrayIndex < (int32_t)mLoadedMsgHistory.Length()) {
     mNavigatingToUri = mLoadedMsgHistory[desiredArrayIndex + 1];
     aFolderUri = mNavigatingToUri;
     return NS_OK;
   }
   return NS_ERROR_FAILURE;
 }
 
-NS_IMETHODIMP nsMessenger::GetNavigateHistory(uint32_t *aCurPos,
-                                              uint32_t *aCount,
-                                              char ***aHistoryUris) {
-  NS_ENSURE_ARG_POINTER(aCount);
-  NS_ENSURE_ARG_POINTER(aCurPos);
-
-  *aCurPos = mCurHistoryPos >> 1;
-  *aCount = mLoadedMsgHistory.Length();
-  // for just enabling commands, we don't need the history uris.
-  if (!aHistoryUris) return NS_OK;
-
-  char **outArray, **next;
-  next = outArray = (char **)moz_xmalloc(*aCount * sizeof(char *));
-  if (!outArray) return NS_ERROR_OUT_OF_MEMORY;
-  for (uint32_t i = 0; i < *aCount; i++) {
-    *next = ToNewCString(mLoadedMsgHistory[i]);
-    if (!*next) return NS_ERROR_OUT_OF_MEMORY;
-    next++;
-  }
-  *aHistoryUris = outArray;
+NS_IMETHODIMP nsMessenger::GetNavigateHistory(
+    nsTArray<nsCString> &aHistoryUris) {
+  aHistoryUris = mLoadedMsgHistory;
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsMessenger::FormatFileSize(uint64_t aSize, bool aUseKB,
                             nsAString &aFormattedSize) {
   return ::FormatFileSize(aSize, aUseKB, aFormattedSize);
 }
--- a/mailnews/base/src/nsMsgDBView.cpp
+++ b/mailnews/base/src/nsMsgDBView.cpp
@@ -6500,28 +6500,28 @@ nsMsgDBView::NavigateStatus(nsMsgNavigat
       if (IsValidIndex(index)) {
         nsMsgKey threadId;
         rv = FindPrevUnread(m_keys[index], &resultKey, &threadId);
         enable = (resultKey != nsMsgKey_None);
       }
       break;
     case nsMsgNavigationType::forward:
     case nsMsgNavigationType::back:
-      uint32_t curPos;
-      uint32_t historyCount;
       if (messenger) {
-        messenger->GetNavigateHistory(&curPos, &historyCount, nullptr);
+        int32_t curPos;
+        messenger->GetNavigatePos(&curPos);
+        nsTArray<nsCString> history;
+        messenger->GetNavigateHistory(history);
         int32_t desiredPos = (int32_t)curPos;
         if (motion == nsMsgNavigationType::forward)
           desiredPos++;
         else
-          //? operator code didn't work for me.
           desiredPos--;
 
-        enable = (desiredPos >= 0 && desiredPos < (int32_t)historyCount / 2);
+        enable = (desiredPos >= 0 && desiredPos < (int32_t)history.Length() / 2);
       }
       break;
     default:
       NS_ERROR("unexpected");
       break;
   }
 
   *_retval = enable;
--- a/suite/mailnews/content/mailWindowOverlay.js
+++ b/suite/mailnews/content/mailWindowOverlay.js
@@ -702,23 +702,19 @@ function InitForwardToolbarMenu(menuPopu
 }
 
 function PopulateHistoryMenu(menuPopup, navOffset)
 {
   // remove existing entries
   while (menuPopup.hasChildNodes())
     menuPopup.lastChild.remove();
 
-  var curPos = {};
-  var numEntries = {};
-  var historyEntries = {};
-  messenger.getNavigateHistory(curPos, numEntries, historyEntries);
-  var historyArray = historyEntries.value;
-  var maxPos = numEntries.value / 2; // numEntries is always even
-  var startPos = curPos.value;
+  let startPos = messenger.navigatePos;
+  let historyArray = messenger.getNavigateHistory();
+  let maxPos = historyArray.length / 2; // Array consists of pairs.
   if (GetLoadedMessage())
     startPos += navOffset;
 
   // starting from the current entry, march through history until we reach
   // the array border or our menuitem limit
   for (var i = startPos, itemCount = 0;
        (i >= 0) && (i < maxPos) && (itemCount < 25);
        i += navOffset, ++itemCount)