Bug 1589892 - Port |Bug 440616 (part 1 v2) Clean up Thunderbird's global scope a bit more (mail session and 3pane commands)| to SeaMonkey. r=frg a=frg DONTBUILD CLOSED TREE
authorIan Neal <iann_cvs@blueyonder.co.uk>
Thu, 14 Nov 2019 21:02:01 +0100
changeset 32364 328b908326fa7075f4930dd4b92bf94be6243b69
parent 32363 b17101745e4aec9ee1c98b8d36f21cd023913812
child 32365 b066b5e8868cfc79d802338e9d03492ac5e8f502
push id229
push userfrgrahl@gmx.net
push dateThu, 14 Nov 2019 20:02:28 +0000
treeherdercomm-esr60@b05f05a590f4 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersfrg, frg
bugs1589892, 440616
Bug 1589892 - Port |Bug 440616 (part 1 v2) Clean up Thunderbird's global scope a bit more (mail session and 3pane commands)| to SeaMonkey. r=frg a=frg DONTBUILD CLOSED TREE
suite/mailnews/content/commandglue.js
suite/mailnews/content/mail3PaneWindowCommands.js
suite/mailnews/content/mailContextMenus.js
suite/mailnews/content/mailWindow.js
suite/mailnews/content/messageWindow.js
suite/mailnews/content/msgMail3PaneWindow.js
--- a/suite/mailnews/content/commandglue.js
+++ b/suite/mailnews/content/commandglue.js
@@ -914,33 +914,28 @@ var gFolderPicker;
 var gStatusBar = null;
 var gMessengerBundle = null;
 
 // Datasource search listener -- made global as it has to be registered
 // and unregistered in different functions.
 var gDataSourceSearchListener;
 var gViewSearchListener;
 
-var gMailSession;
-
 function GetScopeForFolder(folder)
 {
   return folder.server.searchScope;
 }
 
 function setupXFVirtualFolderSearch(folderUrisToSearch, searchTerms, searchOnline)
 {
     var count = new Object;
   var i;
 
     gSearchSession = Cc[searchSessionContractID].createInstance(Ci.nsIMsgSearchSession);
 
-    gMailSession = Cc["@mozilla.org/messenger/services/session;1"]
-                     .getService(Ci.nsIMsgMailSession);
-
   for (i in folderUrisToSearch)
     {
       let realFolder = GetMsgFolderFromUri(folderUrisToSearch[i]);
       if (!realFolder.isServer)
         gSearchSession.addScopeTerm(!searchOnline ? nsMsgSearchScope.offlineMail : GetScopeForFolder(realFolder), realFolder);
     }
 
     const nsIMsgSearchTerm = Ci.nsIMsgSearchTerm;
--- a/suite/mailnews/content/mail3PaneWindowCommands.js
+++ b/suite/mailnews/content/mail3PaneWindowCommands.js
@@ -533,43 +533,43 @@ var DefaultController =
       case "cmd_killSubthread":
         GoNextMessage(nsMsgNavigationType.toggleSubthreadKilled, true);
         break;
       case "cmd_watchThread":
         gDBView.doCommand(nsMsgViewCommandType.toggleThreadWatched);
         break;
       case "button_next":
       case "cmd_nextUnreadMsg":
-        MsgNextUnreadMessage();
+        GoNextMessage(nsMsgNavigationType.nextUnreadMessage, true);
         break;
       case "cmd_nextUnreadThread":
-        MsgNextUnreadThread();
+        GoNextMessage(nsMsgNavigationType.nextUnreadThread, true);
         break;
       case "cmd_nextMsg":
-        MsgNextMessage();
+        GoNextMessage(nsMsgNavigationType.nextMessage, false);
         break;
       case "cmd_nextFlaggedMsg":
-        MsgNextFlaggedMessage();
+        GoNextMessage(nsMsgNavigationType.nextFlagged, true);
         break;
       case "cmd_previousMsg":
-        MsgPreviousMessage();
+        GoNextMessage(nsMsgNavigationType.previousMessage, false);
         break;
       case "cmd_previousUnreadMsg":
-        MsgPreviousUnreadMessage();
+        GoNextMessage(nsMsgNavigationType.previousUnreadMessage, true);
         break;
       case "cmd_previousFlaggedMsg":
-        MsgPreviousFlaggedMessage();
+        GoNextMessage(nsMsgNavigationType.previousFlagged, true);
+        break;
+      case "button_goForward":
+      case "cmd_goForward":
+        GoNextMessage(nsMsgNavigationType.forward, true);
         break;
       case "button_goBack":
       case "cmd_goBack":
-        MsgGoBack();
-        break;
-       case "button_goForward":
-       case "cmd_goForward":
-        MsgGoForward();
+        GoNextMessage(nsMsgNavigationType.back, true);
         break;
       case "cmd_goStartPage":
         HideMessageHeaderPane();
         loadStartPage();
         break;
       case "cmd_viewAllMsgs":
       case "cmd_viewThreadsWithUnread":
       case "cmd_viewWatchedThreadsWithUnread":
@@ -653,17 +653,17 @@ var DefaultController =
         return;
       case "cmd_markReadByDate":
         MsgMarkReadByDate();
         return;
       case "button_junk":
         MsgJunk();
         return;
       case "cmd_stop":
-        MsgStop();
+        msgWindow.StopUrls();
         return;
       case "cmd_markAsFlagged":
         MsgMarkAsFlagged(null);
         return;
       case "cmd_markAsJunk":
         JunkSelectedMessages(true);
         return;
       case "cmd_markAsNotJunk":
@@ -994,61 +994,16 @@ function SetFocusThreadPaneIfNotOnMessag
 {
   var focusedElement = WhichPaneHasFocus();
 
   if((focusedElement != GetThreadTree()) &&
      (focusedElement != GetMessagePane()))
      SetFocusThreadPane();
 }
 
-// 3pane related commands.  Need to go in own file.  Putting here for the moment.
-function MsgNextMessage()
-{
-  GoNextMessage(nsMsgNavigationType.nextMessage, false);
-}
-
-function MsgNextUnreadMessage()
-{
-  GoNextMessage(nsMsgNavigationType.nextUnreadMessage, true);
-}
-function MsgNextFlaggedMessage()
-{
-  GoNextMessage(nsMsgNavigationType.nextFlagged, true);
-}
-
-function MsgNextUnreadThread()
-{
-  GoNextMessage(nsMsgNavigationType.nextUnreadThread, true);
-}
-
-function MsgPreviousMessage()
-{
-  GoNextMessage(nsMsgNavigationType.previousMessage, false);
-}
-
-function MsgPreviousUnreadMessage()
-{
-  GoNextMessage(nsMsgNavigationType.previousUnreadMessage, true);
-}
-
-function MsgPreviousFlaggedMessage()
-{
-  GoNextMessage(nsMsgNavigationType.previousFlagged, true);
-}
-
-function MsgGoBack()
-{
-  GoNextMessage(nsMsgNavigationType.back, true);
-}
-
-function MsgGoForward()
-{
-  GoNextMessage(nsMsgNavigationType.forward, true);
-}
-
 function SwitchPaneFocus(event)
 {
   var folderTree = GetFolderTree();
   var threadTree = GetThreadTree();
   var messagePane = GetMessagePane();
 
   // Although internally this is actually a four-pane window, it is presented as
   // a three-pane -- the search pane is more of a toolbar.  So, shift among the
--- a/suite/mailnews/content/mailContextMenus.js
+++ b/suite/mailnews/content/mailContextMenus.js
@@ -674,24 +674,18 @@ function CheckForMessageIdInFolder(folde
   {
     messageHeader = messageDatabase.getMsgHdrForMessageID(messageId);
   }
   catch (ex)
   {
     dump("Failed to find message-id in folder!");
   }
 
-  if (!gMailSession)
-  {
-    gMailSession = Cc["@mozilla.org/messenger/services/session;1"]
-                     .getService(Ci.nsIMsgMailSession);
-  }
-
   const nsMsgFolderFlags = Ci.nsMsgFolderFlags;
-  if (!gMailSession.IsFolderOpenInWindow(folder) &&
+  if (!MailServices.mailSession.IsFolderOpenInWindow(folder) &&
       !(folder.flags & (nsMsgFolderFlags.Trash | nsMsgFolderFlags.Inbox)))
   {
     folder.msgDatabase = null;
   }
 
   return messageHeader;
 }
 
--- a/suite/mailnews/content/mailWindow.js
+++ b/suite/mailnews/content/mailWindow.js
@@ -10,18 +10,16 @@ var statusFeedback;
 var msgWindow;
 
 var msgComposeService;
 var accountManager;
 var RDF;
 var msgComposeType;
 var msgComposeFormat;
 
-var mailSession;
-
 var gMessengerBundle;
 var gBrandBundle;
 
 var accountManagerDataSource;
 var folderDataSource;
 
 var accountCentralBox = null;
 var gDisableViewsSearch = null;
@@ -43,21 +41,19 @@ function OnMailWindowUnload()
       gPreQuickSearchView.close();
   }
 
   var dbview = GetDBView();
   if (dbview) {
     dbview.close();
   }
 
-  var mailSession = Cc["@mozilla.org/messenger/services/session;1"]
-                      .getService();
-  if (mailSession instanceof Ci.nsIMsgMailSession)
-    mailSession.RemoveFolderListener(folderListener);
-  mailSession.RemoveMsgWindow(msgWindow);
+  MailServices.mailSession.RemoveFolderListener(folderListener);
+
+  MailServices.mailSession.RemoveMsgWindow(msgWindow);
   messenger.setWindow(null, null);
 
   msgWindow.closeWindow();
 }
 
 /**
  * When copying/dragging, convert imap/mailbox URLs of images into data URLs so
  * that the images can be accessed in a paste elsewhere.
@@ -181,18 +177,16 @@ function CreateMailWindowGlobals()
 
   //Create message window object
   msgWindow = Cc["@mozilla.org/messenger/msgwindow;1"]
                 .createInstance(Ci.nsIMsgWindow);
 
   msgComposeService = Cc['@mozilla.org/messengercompose;1']
                         .getService(Ci.nsIMsgComposeService);
 
-  mailSession = Cc["@mozilla.org/messenger/services/session;1"].getService(Ci.nsIMsgMailSession);
-
   accountManager = Cc["@mozilla.org/messenger/account-manager;1"].getService(Ci.nsIMsgAccountManager);
 
   RDF = Cc['@mozilla.org/rdf/rdf-service;1']
           .getService(Ci.nsIRDFService);
 
   msgComposeType = Ci.nsIMsgCompType;
   msgComposeFormat = Ci.nsIMsgCompFormat;
 
@@ -213,17 +207,17 @@ function CreateMailWindowGlobals()
 
 function InitMsgWindow()
 {
   msgWindow.windowCommands = new nsMsgWindowCommands();
   // set the domWindow before setting the status feedback and header sink objects
   msgWindow.domWindow = window;
   msgWindow.statusFeedback = statusFeedback;
   msgWindow.msgHeaderSink = messageHeaderSink;
-  mailSession.AddMsgWindow(msgWindow);
+  MailServices.mailSession.AddMsgWindow(msgWindow);
 
   var messagepane = getMessageBrowser();
   messagepane.docShell.allowAuth = false;
   messagepane.docShell.allowDNSPrefetch = false;
   msgWindow.rootDocShell.allowAuth = true;
   msgWindow.rootDocShell.appType = Ci.nsIDocShell.APP_TYPE_MAIL;
   // Ensure we don't load xul error pages into the main window
   msgWindow.rootDocShell.useErrorPages = false;
--- a/suite/mailnews/content/messageWindow.js
+++ b/suite/mailnews/content/messageWindow.js
@@ -214,23 +214,20 @@ function OnLoadMessageWindow()
 
   InitMsgWindow();
 
   messenger.setWindow(window, msgWindow);
   AddDataSources();
   // FIX ME - later we will be able to use onload from the overlay
   OnLoadMsgHeaderPane();
 
-  try {
-    var nsIFolderListener = Ci.nsIFolderListener;
-    var notifyFlags = nsIFolderListener.removed | nsIFolderListener.event | nsIFolderListener.intPropertyChanged;
-    mailSession.AddFolderListener(folderListener, notifyFlags);
-  } catch (ex) {
-    dump("Error adding to session: " +ex + "\n");
-  }
+  var nsIFolderListener = Ci.nsIFolderListener;
+  var notifyFlags = nsIFolderListener.removed | nsIFolderListener.event |
+                    nsIFolderListener.intPropertyChanged;
+  MailServices.mailSession.AddFolderListener(folderListener, notifyFlags);
 
   var originalView = null;
   var folder = null;
   var messageUri;
   var loadCustomMessage = false;       //set to true when either loading a message/rfc822 attachment or a .eml file
   if (window.arguments)
   {
     if (window.arguments[0])
--- a/suite/mailnews/content/msgMail3PaneWindow.js
+++ b/suite/mailnews/content/msgMail3PaneWindow.js
@@ -950,25 +950,20 @@ function loadStartFolder(initialUri)
         }
         else if(sendUnsentWhenGoingOnlinePref == 1) // pref is "yes"
           SendUnsentMessages();
     }
 }
 
 function AddToSession()
 {
-  try {
-    var mailSession = Cc["@mozilla.org/messenger/services/session;1"]
-                        .getService(Ci.nsIMsgMailSession);
-    var nsIFolderListener = Ci.nsIFolderListener;
-    var notifyFlags = nsIFolderListener.intPropertyChanged | nsIFolderListener.event;
-    mailSession.AddFolderListener(folderListener, notifyFlags);
-  } catch (ex) {
-    dump("Error adding to session\n");
-  }
+  var nsIFolderListener = Ci.nsIFolderListener;
+  var notifyFlags = nsIFolderListener.intPropertyChanged |
+                    nsIFolderListener.event;
+  MailServices.mailSession.AddFolderListener(folderListener, notifyFlags);
 }
 
 function InitPanes()
 {
   OnLoadFolderPane();
   OnLoadLocationTree();
   OnLoadThreadPane();
   SetupCommandUpdateHandlers();