Bug 1627437 - Add attributes to cope with [can_run_script] methods in nsITransaction (Bug 1619914). r=mkmelin a=wsmwk
authorBen Campbell <benc@thunderbird.net>
Mon, 20 Apr 2020 13:49:34 +0300
changeset 38717 c6fef8bbb3fc779a2acac3b7ba0032924911dd1f
parent 38716 b71c0178061e402b58f787d9b0eca7e58dc8de61
child 38718 12de722b5dc20b1d13ad51af831225270d31e82d
push id400
push userclokep@gmail.com
push dateMon, 04 May 2020 18:56:09 +0000
reviewersmkmelin, wsmwk
bugs1627437, 1619914
Bug 1627437 - Add attributes to cope with [can_run_script] methods in nsITransaction (Bug 1619914). r=mkmelin a=wsmwk
mailnews/base/src/nsMessenger.cpp
mailnews/base/src/nsMsgCopyService.cpp
mailnews/base/util/nsMsgDBFolder.h
mailnews/imap/src/nsImapMailFolder.cpp
mailnews/imap/src/nsImapMailFolder.h
mailnews/local/src/nsLocalMailFolder.cpp
mailnews/local/src/nsLocalMailFolder.h
--- a/mailnews/base/src/nsMessenger.cpp
+++ b/mailnews/base/src/nsMessenger.cpp
@@ -1390,49 +1390,51 @@ NS_IMETHODIMP nsMessenger::CanRedo(bool 
   nsresult rv;
   *bValue = false;
   int32_t count = 0;
   rv = mTxnMgr->GetNumberOfRedoItems(&count);
   if (NS_SUCCEEDED(rv) && count > 0) *bValue = true;
   return rv;
 }
 
-NS_IMETHODIMP
+MOZ_CAN_RUN_SCRIPT_BOUNDARY NS_IMETHODIMP
 nsMessenger::Undo(nsIMsgWindow *msgWindow) {
   nsresult rv = NS_OK;
   if (mTxnMgr) {
     int32_t numTxn = 0;
     rv = mTxnMgr->GetNumberOfUndoItems(&numTxn);
     if (NS_SUCCEEDED(rv) && numTxn > 0) {
       nsCOMPtr<nsITransaction> txn;
       rv = mTxnMgr->PeekUndoStack(getter_AddRefs(txn));
       if (NS_SUCCEEDED(rv) && txn) {
         static_cast<nsMsgTxn *>(static_cast<nsITransaction *>(txn.get()))
             ->SetMsgWindow(msgWindow);
       }
-      mTxnMgr->UndoTransaction();
+      nsCOMPtr<nsITransactionManager> txnMgr = mTxnMgr;
+      txnMgr->UndoTransaction();
     }
   }
   return rv;
 }
 
-NS_IMETHODIMP
+MOZ_CAN_RUN_SCRIPT_BOUNDARY NS_IMETHODIMP
 nsMessenger::Redo(nsIMsgWindow *msgWindow) {
   nsresult rv = NS_OK;
   if (mTxnMgr) {
     int32_t numTxn = 0;
     rv = mTxnMgr->GetNumberOfRedoItems(&numTxn);
     if (NS_SUCCEEDED(rv) && numTxn > 0) {
       nsCOMPtr<nsITransaction> txn;
       rv = mTxnMgr->PeekRedoStack(getter_AddRefs(txn));
       if (NS_SUCCEEDED(rv) && txn) {
         static_cast<nsMsgTxn *>(static_cast<nsITransaction *>(txn.get()))
             ->SetMsgWindow(msgWindow);
       }
-      mTxnMgr->RedoTransaction();
+      nsCOMPtr<nsITransactionManager> txnMgr = mTxnMgr;
+      txnMgr->RedoTransaction();
     }
   }
   return rv;
 }
 
 NS_IMETHODIMP
 nsMessenger::GetTransactionManager(nsITransactionManager **aTxnMgr) {
   NS_ENSURE_TRUE(mTxnMgr && aTxnMgr, NS_ERROR_NULL_POINTER);
--- a/mailnews/base/src/nsMsgCopyService.cpp
+++ b/mailnews/base/src/nsMsgCopyService.cpp
@@ -356,21 +356,20 @@ nsCopyRequest* nsMsgCopyService::FindReq
       copyRequest = nullptr;
   }
 
   return copyRequest;
 }
 
 NS_IMPL_ISUPPORTS(nsMsgCopyService, nsIMsgCopyService)
 
-NS_IMETHODIMP
-nsMsgCopyService::CopyMessages(nsIMsgFolder* srcFolder, /* UI src folder */
-                               nsIArray* messages, nsIMsgFolder* dstFolder,
-                               bool isMove, nsIMsgCopyServiceListener* listener,
-                               nsIMsgWindow* window, bool allowUndo) {
+MOZ_CAN_RUN_SCRIPT_BOUNDARY NS_IMETHODIMP nsMsgCopyService::CopyMessages(
+    nsIMsgFolder* srcFolder, /* UI src folder */
+    nsIArray* messages, nsIMsgFolder* dstFolder, bool isMove,
+    nsIMsgCopyServiceListener* listener, nsIMsgWindow* window, bool allowUndo) {
   NS_ENSURE_ARG_POINTER(srcFolder);
   NS_ENSURE_ARG_POINTER(messages);
   NS_ENSURE_ARG_POINTER(dstFolder);
 
   MOZ_LOG(gCopyServiceLog, mozilla::LogLevel::Debug, ("CopyMessages"));
 
   if (srcFolder == dstFolder) {
     NS_ERROR("src and dest folders for msg copy can't be the same");
@@ -446,18 +445,20 @@ nsMsgCopyService::CopyMessages(nsIMsgFol
         // Force to create a new one and continue grouping the messages.
         copySource = nullptr;
       }
     }
   }
 
   // undo stuff
   if (NS_SUCCEEDED(rv) && copyRequest->m_allowUndo &&
-      copyRequest->m_copySourceArray.Length() > 1 && copyRequest->m_txnMgr)
-    copyRequest->m_txnMgr->BeginBatch(nullptr);
+      copyRequest->m_copySourceArray.Length() > 1 && copyRequest->m_txnMgr) {
+    nsCOMPtr<nsITransactionManager> txnMgr = copyRequest->m_txnMgr;
+    txnMgr->BeginBatch(nullptr);
+  }
 
 done:
 
   if (NS_FAILED(rv))
     delete copyRequest;
   else
     rv = DoCopy(copyRequest);
 
--- a/mailnews/base/util/nsMsgDBFolder.h
+++ b/mailnews/base/util/nsMsgDBFolder.h
@@ -173,19 +173,18 @@ class NS_MSG_BASE nsMsgDBFolder : public
   nsresult AutoCompact(nsIMsgWindow *aWindow);
   // this is a helper routine that ignores whether nsMsgMessageFlags::Offline is
   // set for the folder
   nsresult MsgFitsDownloadCriteria(nsMsgKey msgKey, bool *result);
   nsresult GetPromptPurgeThreshold(bool *aPrompt);
   nsresult GetPurgeThreshold(int32_t *aThreshold);
   nsresult ApplyRetentionSettings(bool deleteViaFolder);
   bool VerifyOfflineMessage(nsIMsgDBHdr *msgHdr, nsIInputStream *fileStream);
-  MOZ_CAN_RUN_SCRIPT nsresult AddMarkAllReadUndoAction(nsIMsgWindow *msgWindow,
-                                                       nsMsgKey *thoseMarked,
-                                                       uint32_t numMarked);
+  MOZ_CAN_RUN_SCRIPT_BOUNDARY nsresult AddMarkAllReadUndoAction(
+      nsIMsgWindow *msgWindow, nsMsgKey *thoseMarked, uint32_t numMarked);
 
   nsresult PerformBiffNotifications(
       void);  // if there are new, non spam messages, do biff
   nsresult CloseDBIfFolderNotOpen();
 
   // Helper function for Move code to call to update the MRU and MRM time.
   void UpdateTimestamps(bool allowUndo);
   void SetMRUTime();
--- a/mailnews/imap/src/nsImapMailFolder.cpp
+++ b/mailnews/imap/src/nsImapMailFolder.cpp
@@ -5016,18 +5016,18 @@ nsImapMailFolder::OnStopRunningUrl(nsIUR
                 m_copyState->m_undoMsgTxn &&  // may be null from filters
                 NS_SUCCEEDED(
                     aExitCode))  // we should do this only if move/copy succeeds
             {
               nsCOMPtr<nsITransactionManager> txnMgr;
               m_copyState->m_msgWindow->GetTransactionManager(
                   getter_AddRefs(txnMgr));
               if (txnMgr) {
-                mozilla::DebugOnly<nsresult> rv2 =
-                    txnMgr->DoTransaction(m_copyState->m_undoMsgTxn);
+                RefPtr<nsImapMoveCopyMsgTxn> txn = m_copyState->m_undoMsgTxn;
+                mozilla::DebugOnly<nsresult> rv2 = txnMgr->DoTransaction(txn);
                 NS_ASSERTION(NS_SUCCEEDED(rv2), "doing transaction failed");
               }
             }
             (void)OnCopyCompleted(m_copyState->m_srcSupport, aExitCode);
           }
 
           // we're the dest folder of a move/copy - if we're not open in the ui,
           // then we should clear our nsMsgDatabase pointer. Otherwise, the db
@@ -5124,17 +5124,21 @@ nsImapMailFolder::OnStopRunningUrl(nsIUR
                   // when the UpdateFolder url is done.
                   if (m_copyState->m_listener)
                     m_urlListener = do_QueryInterface(m_copyState->m_listener);
                 }
                 if (m_copyState->m_msgWindow && m_copyState->m_undoMsgTxn) {
                   nsCOMPtr<nsITransactionManager> txnMgr;
                   m_copyState->m_msgWindow->GetTransactionManager(
                       getter_AddRefs(txnMgr));
-                  if (txnMgr) txnMgr->DoTransaction(m_copyState->m_undoMsgTxn);
+                  if (txnMgr) {
+                    RefPtr<nsImapMoveCopyMsgTxn> txn =
+                        m_copyState->m_undoMsgTxn;
+                    txnMgr->DoTransaction(txn);
+                  }
                 }
                 (void)OnCopyCompleted(m_copyState->m_srcSupport, aExitCode);
                 if (folderOpen ||
                     imapAction == nsIImapUrl::nsImapAppendDraftFromFile) {
                   UpdateFolderWithListener(msgWindow, m_urlListener);
                   m_urlListener = saveUrlListener;
                 }
               }
--- a/mailnews/imap/src/nsImapMailFolder.h
+++ b/mailnews/imap/src/nsImapMailFolder.h
@@ -280,20 +280,20 @@ class nsImapMailFolder : public nsMsgDBF
   NS_IMETHOD DeleteSubFolders(nsIArray *folders,
                               nsIMsgWindow *msgWindow) override;
   NS_IMETHOD ReadFromFolderCacheElem(
       nsIMsgFolderCacheElement *element) override;
   NS_IMETHOD WriteToFolderCacheElem(nsIMsgFolderCacheElement *element) override;
 
   NS_IMETHOD GetDBFolderInfoAndDB(nsIDBFolderInfo **folderInfo,
                                   nsIMsgDatabase **db) override;
-  NS_IMETHOD DeleteMessages(nsIArray *messages, nsIMsgWindow *msgWindow,
-                            bool deleteStorage, bool isMove,
-                            nsIMsgCopyServiceListener *listener,
-                            bool allowUndo) override;
+  MOZ_CAN_RUN_SCRIPT_BOUNDARY NS_IMETHOD
+  DeleteMessages(nsIArray *messages, nsIMsgWindow *msgWindow,
+                 bool deleteStorage, bool isMove,
+                 nsIMsgCopyServiceListener *listener, bool allowUndo) override;
   NS_IMETHOD CopyMessages(nsIMsgFolder *srcFolder, nsIArray *messages,
                           bool isMove, nsIMsgWindow *msgWindow,
                           nsIMsgCopyServiceListener *listener, bool isFolder,
                           bool allowUndo) override;
   NS_IMETHOD CopyFolder(nsIMsgFolder *srcFolder, bool isMove,
                         nsIMsgWindow *msgWindow,
                         nsIMsgCopyServiceListener *listener) override;
   NS_IMETHOD CopyFileMessage(nsIFile *file, nsIMsgDBHdr *msgToReplace,
@@ -336,17 +336,18 @@ class nsImapMailFolder : public nsMsgDBF
 
   NS_DECL_NSIMSGIMAPMAILFOLDER
   NS_DECL_NSIIMAPMAILFOLDERSINK
   NS_DECL_NSIIMAPMESSAGESINK
   NS_DECL_NSICOPYMESSAGELISTENER
 
   // nsIUrlListener methods
   NS_IMETHOD OnStartRunningUrl(nsIURI *aUrl) override;
-  NS_IMETHOD OnStopRunningUrl(nsIURI *aUrl, nsresult aExitCode) override;
+  MOZ_CAN_RUN_SCRIPT_BOUNDARY NS_IMETHOD
+  OnStopRunningUrl(nsIURI *aUrl, nsresult aExitCode) override;
 
   NS_DECL_NSIMSGFILTERHITNOTIFY
   NS_DECL_NSIJUNKMAILCLASSIFICATIONLISTENER
 
   NS_IMETHOD IsCommandEnabled(const nsACString &command, bool *result) override;
   NS_IMETHOD SetFilterList(nsIMsgFilterList *aMsgFilterList) override;
   NS_IMETHOD GetCustomIdentity(nsIMsgIdentity **aIdentity) override;
 
@@ -472,19 +473,19 @@ class nsImapMailFolder : public nsMsgDBF
   virtual nsresult CreateBaseMessageURI(const nsACString &aURI) override;
   // offline-ish methods
   nsresult GetClearedOriginalOp(nsIMsgOfflineImapOperation *op,
                                 nsIMsgOfflineImapOperation **originalOp,
                                 nsIMsgDatabase **originalDB);
   nsresult GetOriginalOp(nsIMsgOfflineImapOperation *op,
                          nsIMsgOfflineImapOperation **originalOp,
                          nsIMsgDatabase **originalDB);
-  nsresult CopyMessagesOffline(nsIMsgFolder *srcFolder, nsIArray *messages,
-                               bool isMove, nsIMsgWindow *msgWindow,
-                               nsIMsgCopyServiceListener *listener);
+  MOZ_CAN_RUN_SCRIPT_BOUNDARY nsresult CopyMessagesOffline(
+      nsIMsgFolder *srcFolder, nsIArray *messages, bool isMove,
+      nsIMsgWindow *msgWindow, nsIMsgCopyServiceListener *listener);
   void SetPendingAttributes(nsIArray *messages, bool aIsMove, bool aSetOffline);
 
   nsresult CopyOfflineMsgBody(nsIMsgFolder *srcFolder, nsIMsgDBHdr *destHdr,
                               nsIMsgDBHdr *origHdr, nsIInputStream *inputStream,
                               nsIOutputStream *outputStream);
 
   void GetTrashFolderName(nsAString &aFolderName);
   bool ShowPreviewText();
--- a/mailnews/local/src/nsLocalMailFolder.cpp
+++ b/mailnews/local/src/nsLocalMailFolder.cpp
@@ -2082,17 +2082,18 @@ void nsMsgLocalMailFolder::CopyHdrProper
     destHdr->SetStringProperty(property.get(), sourceString.get());
   }
 
   nsMsgLabelValue label = 0;
   srcHdr->GetLabel(&label);
   destHdr->SetLabel(label);
 }
 
-NS_IMETHODIMP nsMsgLocalMailFolder::EndCopy(bool aCopySucceeded) {
+MOZ_CAN_RUN_SCRIPT_BOUNDARY NS_IMETHODIMP
+nsMsgLocalMailFolder::EndCopy(bool aCopySucceeded) {
   if (!mCopyState) return NS_OK;
 
   // we are the destination folder for a move/copy
   nsresult rv = aCopySucceeded ? NS_OK : NS_ERROR_FAILURE;
 
   if (!aCopySucceeded || mCopyState->m_writeFailed) {
     if (mCopyState->m_fileStream) {
       if (mCopyState->m_curDstKey != nsMsgKey_None)
@@ -2294,17 +2295,20 @@ NS_IMETHODIMP nsMsgLocalMailFolder::EndC
           CopyAllSubFolders(
               srcFolder, nullptr,
               nullptr);  // Copy all subfolders then notify completion
 
         if (mCopyState->m_msgWindow && mCopyState->m_undoMsgTxn) {
           nsCOMPtr<nsITransactionManager> txnMgr;
           mCopyState->m_msgWindow->GetTransactionManager(
               getter_AddRefs(txnMgr));
-          if (txnMgr) txnMgr->DoTransaction(mCopyState->m_undoMsgTxn);
+          if (txnMgr) {
+            RefPtr<nsLocalMoveCopyMsgTxn> txn = mCopyState->m_undoMsgTxn;
+            txnMgr->DoTransaction(txn);
+          }
         }
 
         // enable the dest folder
         EnableNotifications(allMessageCountNotifications, true);
         if (srcFolder && !mCopyState->m_isFolder) {
           // I'm not too sure of the proper location of this event. It seems to
           // need to be after the EnableNotifications, or the folder counts can
           // be incorrect during the kDeleteOrMoveMsgCompleted call.
@@ -2347,17 +2351,18 @@ bool nsMsgLocalMailFolder::GetDeleteFrom
       pPrefBranch->GetBoolPref("mail.pop3.deleteFromServerOnMove",
                                &gDeleteFromServerOnMove);
       gGotGlobalPrefs = true;
     }
   }
   return gDeleteFromServerOnMove;
 }
 
-NS_IMETHODIMP nsMsgLocalMailFolder::EndMove(bool moveSucceeded) {
+MOZ_CAN_RUN_SCRIPT_BOUNDARY NS_IMETHODIMP
+nsMsgLocalMailFolder::EndMove(bool moveSucceeded) {
   nsresult rv;
   if (!mCopyState) return NS_OK;
 
   if (!moveSucceeded || mCopyState->m_writeFailed) {
     // Notify that a completion finished.
     nsCOMPtr<nsIMsgFolder> srcFolder =
         do_QueryInterface(mCopyState->m_srcSupport, &rv);
     NS_ENSURE_SUCCESS(rv, rv);
@@ -2405,17 +2410,20 @@ NS_IMETHODIMP nsMsgLocalMailFolder::EndM
     // incorrect during the kDeleteOrMoveMsgCompleted call.
     srcFolder->NotifyFolderEvent(NS_SUCCEEDED(rv) ? kDeleteOrMoveMsgCompleted
                                                   : kDeleteOrMoveMsgFailed);
 
     if (NS_SUCCEEDED(rv) && mCopyState->m_msgWindow &&
         mCopyState->m_undoMsgTxn) {
       nsCOMPtr<nsITransactionManager> txnMgr;
       mCopyState->m_msgWindow->GetTransactionManager(getter_AddRefs(txnMgr));
-      if (txnMgr) txnMgr->DoTransaction(mCopyState->m_undoMsgTxn);
+      if (txnMgr) {
+        RefPtr<nsLocalMoveCopyMsgTxn> txn = mCopyState->m_undoMsgTxn;
+        txnMgr->DoTransaction(txn);
+      }
     }
     (void)OnCopyCompleted(
         mCopyState->m_srcSupport,
         NS_SUCCEEDED(rv)
             ? true
             : false);  // clear the copy state so that the next message from a
                        // different folder can be move
   }
--- a/mailnews/local/src/nsLocalMailFolder.h
+++ b/mailnews/local/src/nsLocalMailFolder.h
@@ -144,20 +144,20 @@ class nsMsgLocalMailFolder : public nsMs
 
   NS_IMETHOD GetDBFolderInfoAndDB(nsIDBFolderInfo **folderInfo,
                                   nsIMsgDatabase **db) override;
 
   NS_IMETHOD DeleteMessages(nsIArray *messages, nsIMsgWindow *msgWindow,
                             bool deleteStorage, bool isMove,
                             nsIMsgCopyServiceListener *listener,
                             bool allowUndo) override;
-  NS_IMETHOD CopyMessages(nsIMsgFolder *srcFolder, nsIArray *messages,
-                          bool isMove, nsIMsgWindow *msgWindow,
-                          nsIMsgCopyServiceListener *listener, bool isFolder,
-                          bool allowUndo) override;
+  MOZ_CAN_RUN_SCRIPT_BOUNDARY NS_IMETHOD
+  CopyMessages(nsIMsgFolder *srcFolder, nsIArray *messages, bool isMove,
+               nsIMsgWindow *msgWindow, nsIMsgCopyServiceListener *listener,
+               bool isFolder, bool allowUndo) override;
   NS_IMETHOD CopyFolder(nsIMsgFolder *srcFolder, bool isMoveFolder,
                         nsIMsgWindow *msgWindow,
                         nsIMsgCopyServiceListener *listener) override;
   NS_IMETHOD CopyFileMessage(nsIFile *aFile, nsIMsgDBHdr *msgToReplace,
                              bool isDraftOrTemplate, uint32_t newMsgFlags,
                              const nsACString &aNewMsgKeywords,
                              nsIMsgWindow *msgWindow,
                              nsIMsgCopyServiceListener *listener) override;