Bug 664841 - Switch suite/mailnews to use Services.obs r=neil
authorIan Neal <iann_cvs@blueyonder.co.uk>
Sat, 18 Jun 2011 18:55:57 +0100
changeset 7969 60e8a71353ae10a3da670d092e2e0961cb55aee7
parent 7968 6a9dc33c7bc34e9484085e64e2fd649cc232851e
child 7970 b7a5437581eff779521548c0d2ce471e373fe2ab
push id6128
push useriann_cvs@blueyonder.co.uk
push dateSat, 18 Jun 2011 17:54:41 +0000
treeherdercomm-central@60e8a71353ae [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersneil
bugs664841
Bug 664841 - Switch suite/mailnews to use Services.obs r=neil
suite/mailnews/compose/MsgComposeCommands.js
suite/mailnews/mailTasksOverlay.js
suite/mailnews/mailWindowOverlay.js
suite/mailnews/messageWindow.js
suite/mailnews/msgMail3PaneWindow.js
suite/mailnews/threadPane.js
--- a/suite/mailnews/compose/MsgComposeCommands.js
+++ b/suite/mailnews/compose/MsgComposeCommands.js
@@ -669,27 +669,27 @@ var messageComposeOfflineObserver = {
         // catch the exception and ignore it, so that if LDAP setup
         // fails, the entire compose window stuff doesn't get aborted
     }
   }
 }
 
 function AddMessageComposeOfflineObserver()
 {
-  var observerService = Components.classes["@mozilla.org/observer-service;1"].getService(Components.interfaces.nsIObserverService);
-  observerService.addObserver(messageComposeOfflineObserver, "network:offline-status-changed", false);
+  Services.obs.addObserver(messageComposeOfflineObserver,
+                           "network:offline-status-changed", false);
 
   // set the initial state of the send button
   MessageComposeOfflineStateChanged(Services.io.offline);
 }
 
 function RemoveMessageComposeOfflineObserver()
 {
-  var observerService = Components.classes["@mozilla.org/observer-service;1"].getService(Components.interfaces.nsIObserverService);
-  observerService.removeObserver(messageComposeOfflineObserver,"network:offline-status-changed");
+  Services.obs.removeObserver(messageComposeOfflineObserver,
+                              "network:offline-status-changed");
 }
 
 function MessageComposeOfflineStateChanged(goingOffline)
 {
   try {
     var sendButton = document.getElementById("button-send");
     var sendNowMenuItem = document.getElementById("menu_sendNow");
 
@@ -1805,18 +1805,17 @@ function GenericSendMessage( msgType )
             msgCompFields.forcePlainText = false;
             msgCompFields.useMultipartAlternative = true;
             break;
            default: dump("\###SendMessage Error: invalid action value\n"); return;
         }
       }
 
       // hook for extra compose pre-processing
-      var observerService = Components.classes["@mozilla.org/observer-service;1"].getService(Components.interfaces.nsIObserverService);
-      observerService.notifyObservers(window, "mail:composeOnSend", null);
+      Services.obs.notifyObservers(window, "mail:composeOnSend", null);
 
       var originalCharset = gMsgCompose.compFields.characterSet;
       // Check if the headers of composing mail can be converted to a mail charset.
       if (msgType == nsIMsgCompDeliverMode.Now ||
         msgType == nsIMsgCompDeliverMode.Later ||
         msgType == nsIMsgCompDeliverMode.Save ||
         msgType == nsIMsgCompDeliverMode.SaveAsDraft ||
         msgType == nsIMsgCompDeliverMode.AutoSaveAsDraft ||
--- a/suite/mailnews/mailTasksOverlay.js
+++ b/suite/mailnews/mailTasksOverlay.js
@@ -219,19 +219,17 @@ function MailTasksOnLoad(aEvent)
   // Without the mini-mail icon to show the biff state, there's no need to
   // initialize this here. We won't start with the hidden window alone,
   // so this early return doesn't break anything.
   var miniMail = document.getElementById("mini-mail");
   if (!miniMail)
     return;
 
   // initialize biff state
-  const kObserverService = Components.classes["@mozilla.org/observer-service;1"]
-                                     .getService(Components.interfaces.nsIObserverService);
-  kObserverService.addObserver(biffObserver, BIFF_TOPIC, false);
+  Services.obs.addObserver(biffObserver, BIFF_TOPIC, false);
   biffObserver.observe(null, BIFF_TOPIC, null); // init mini-mail icon
   addEventListener("unload", MailTasksOnUnload, false);
 
   // don't try to biff if offline, but do so silently
   if (Services.io.offline)
     return;
 
   // Performing biff here will mean performing it for all new windows opened!
@@ -256,19 +254,17 @@ function MailTasksOnLoad(aEvent)
     return;
 
   // still no excuse to refuse to use this ruse
   MailTasksGetMessagesForAllServers(true, null, null);
 }
 
 function MailTasksOnUnload(aEvent)
 {
-  var observerService = Components.classes["@mozilla.org/observer-service;1"]
-                                  .getService(Components.interfaces.nsIObserverService);
-  observerService.removeObserver(biffObserver, BIFF_TOPIC);
+  Services.obs.removeObserver(biffObserver, BIFF_TOPIC);
 }
 
 /**
  * This class implements nsIBadCertListener2.  Its job is to prevent "bad cert"
  * security dialogs from being shown to the user.  Currently it puts up the
  * cert override dialog, though we'd like to give the user more detailed
  * information in the future.
  */
--- a/suite/mailnews/mailWindowOverlay.js
+++ b/suite/mailnews/mailWindowOverlay.js
@@ -2827,19 +2827,18 @@ function OnMsgParsed(aUrl)
   // If rss feed (has 'content-base' header), show summary or load web
   // page per pref; earliest we have content DOM is here (onMsgParsed).
   FeedSetContentView();
 
   gMessageNotificationBar.setPhishingMsg(aUrl);
 
   // notify anyone (e.g., extensions) who's interested in when a message is loaded.
   var msgURI = GetLoadedMessage();
-  var observerService = Components.classes["@mozilla.org/observer-service;1"]
-                                  .getService(Components.interfaces.nsIObserverService);
-  observerService.notifyObservers(msgWindow.msgHeaderSink, "MsgMsgDisplayed", msgURI);
+  Services.obs.notifyObservers(msgWindow.msgHeaderSink,
+                               "MsgMsgDisplayed", msgURI);
 
   // scale any overflowing images
   var doc = getMessageBrowser().contentDocument;
   var imgs = doc.getElementsByTagName("img");
   for each (var img in imgs)
   {
     if (img.className == "moz-attached-image" && img.naturalWidth > doc.width)
     {
--- a/suite/mailnews/messageWindow.js
+++ b/suite/mailnews/messageWindow.js
@@ -160,18 +160,18 @@ var messagepaneObserver = {
 };
 
 function nsMsgDBViewCommandUpdater()
 {}
 
 function UpdateStandAloneMessageCounts()
 {
   // hook for extra toolbar items
-  var observerService = Components.classes["@mozilla.org/observer-service;1"].getService(Components.interfaces.nsIObserverService);
-  observerService.notifyObservers(window, "mail:updateStandAloneMessageCounts", "");
+  Services.obs.notifyObservers(window,
+                               "mail:updateStandAloneMessageCounts", "");
 }
 
 nsMsgDBViewCommandUpdater.prototype = 
 {
   updateCommandStatus : function()
     {
       // the back end is smart and is only telling us to update command status
       // when the # of items in the selection has actually changed.
@@ -422,18 +422,17 @@ function CreateView(originalView)
   else if (gCurrentFolderUri)
     uri = gCurrentFolderUri;
   else
     uri = null;
 
   SetUpToolbarButtons(uri);
 
   // hook for extra toolbar items
-  var observerService = Components.classes["@mozilla.org/observer-service;1"].getService(Components.interfaces.nsIObserverService);
-  observerService.notifyObservers(window, "mail:setupToolbarItems", uri);
+  Services.obs.notifyObservers(window, "mail:setupToolbarItems", uri);
 }
 
 function extractMsgKeyFromURI()
 {
   var msgKey = -1;
   var msgHdr = messenger.msgHdrFromURI(gCurrentMessageUri);
   if (msgHdr)
     msgKey = msgHdr.messageKey;
@@ -576,18 +575,17 @@ function RerootFolderForStandAlone(uri)
     LoadMessageByNavigationType(type);
   }
   
   SetUpToolbarButtons(gCurrentFolderUri);
   
   UpdateMailToolbar("reroot folder in stand alone window");
   
   // hook for extra toolbar items
-  var observerService = Components.classes["@mozilla.org/observer-service;1"].getService(Components.interfaces.nsIObserverService);
-  observerService.notifyObservers(window, "mail:setupToolbarItems", uri);
+  Services.obs.notifyObservers(window, "mail:setupToolbarItems", uri);
 } 
 
 function GetMsgHdrFromUri(messageUri)
 {
   return messenger.msgHdrFromURI(messageUri);
 }
 
 function SelectMessage(messageUri)
--- a/suite/mailnews/msgMail3PaneWindow.js
+++ b/suite/mailnews/msgMail3PaneWindow.js
@@ -756,19 +756,17 @@ function OnLoadMessenger()
       startFolderUri = (args.length > 0) ? args[0] : null;
     }
     gStartMsgKey = (args.length > 1) ? args[1] : nsMsgKey_None;
     gSearchEmailAddress = (args.length > 2) ? args[2] : null;
   }
 
   window.setTimeout(loadStartFolder, 0, startFolderUri);
 
-  Components.classes["@mozilla.org/observer-service;1"]
-                     .getService(Components.interfaces.nsIObserverService)
-                     .notifyObservers(window, "mail-startup-done", null);
+  Services.obs.notifyObservers(window, "mail-startup-done", null);
 
   // FIX ME - later we will be able to use onload from the overlay
   OnLoadMsgHeaderPane();
 
   gHaveLoadedMessage = false;
 
   //Set focus to the Thread Pane the first time the window is opened.
   SetFocusThreadPane();
@@ -861,23 +859,16 @@ function MailWindowIsClosing()
       // don't set the pref unless OK was pressed and it's false
       if (reallyClose && !warnOnClose.value)
         pref.setBoolPref("browser.tabs.warnOnClose", false);
     }
   }
   return reallyClose;
 }
 
-function NotifyObservers(aSubject, aTopic, aData)
-{
-  Components.classes["@mozilla.org/observer-service;1"]
-            .getService(Components.interfaces.nsIObserverService)
-            .notifyObservers(aSubject, aTopic, aData);
-}
-
 function Create3PaneGlobals()
 {
   // Update <mailWindow.js> global variables.
   accountCentralBox = document.getElementById("accountCentralBox");
   gDisableViewsSearch = document.getElementById("mailDisableViewsSearch");
 
   GetMessagePane().collapsed = true;
 }
--- a/suite/mailnews/threadPane.js
+++ b/suite/mailnews/threadPane.js
@@ -342,20 +342,18 @@ function MsgGroupBySort()
   if (!gThreadPaneCommandUpdater)
     gThreadPaneCommandUpdater = new nsMsgDBViewCommandUpdater();
 
 
   gDBView.init(messenger, msgWindow, gThreadPaneCommandUpdater);
   gDBView.open(msgFolder, sortType, sortOrder, viewFlags, count);
   RerootThreadPane();
   UpdateSortIndicators(sortType, nsMsgViewSortOrder.ascending);
-  Components.classes["@mozilla.org/observer-service;1"]
-            .getService(Components.interfaces.nsIObserverService)
-            .notifyObservers(msgFolder, "MsgCreateDBView",
-             Components.interfaces.nsMsgViewType.eShowAllThreads + ":" + viewFlags);
+  Services.obs.notifyObservers(msgFolder, "MsgCreateDBView",
+      Components.interfaces.nsMsgViewType.eShowAllThreads + ":" + viewFlags);
 }
 
 function MsgSortUnthreaded()
 {
     // Toggle if not already unthreaded.
     if ((GetDBView().viewFlags & nsMsgViewFlagsType.kThreadedDisplay) != 0)
         MsgToggleThreaded();
 }