Bug 795152 - Switch to Services.jsm: What's left: chat. r=florian
authorSebastian Hengst <archaeopteryx@coole-files.de>
Fri, 14 Dec 2012 17:22:28 +0100
changeset 14541 4379140e4ffc8578ab682619493561765e02f230
parent 14540 99481e63615e1630290faef171aa372e8d30b1d9
child 14542 df332995c5b4249997c830c713fcbf01d99b7563
push id845
push userbugzilla@standard8.plus.com
push dateTue, 19 Feb 2013 18:11:16 +0000
treeherdercomm-beta@ecc3ce2d7daa [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersflorian
bugs795152
Bug 795152 - Switch to Services.jsm: What's left: chat. r=florian
chat/components/src/imAccounts.js
chat/components/src/imContacts.js
chat/components/src/smileProtocolHandler.js
chat/content/convbrowser.xml
chat/modules/hiddenWindow.jsm
mail/components/im/content/imAccountWizard.js
mail/components/im/content/imcontact.xml
--- a/chat/components/src/imAccounts.js
+++ b/chat/components/src/imAccounts.js
@@ -16,20 +16,16 @@ const kPrefAccountPrpl = "prpl";
 const kPrefAccountAutoLogin = "autoLogin";
 const kPrefAccountAutoJoin = "autoJoin";
 const kPrefAccountAlias = "alias";
 const kPrefAccountFirstConnectionState = "firstConnectionState";
 
 const kPrefConvertOldPasswords = "messenger.accounts.convertOldPasswords";
 const kPrefAccountPassword = "password";
 
-XPCOMUtils.defineLazyGetter(this, "LoginManager", function()
-  Cc["@mozilla.org/login-manager;1"].getService(Ci.nsILoginManager)
-);
-
 XPCOMUtils.defineLazyGetter(this, "_", function()
   l10nHelper("chrome://chat/locale/accounts.properties")
 );
 
 var gUserCanceledMasterPasswordPrompt = false;
 var gConvertingOldPasswords = false;
 
 var SavePrefTimer = {
@@ -397,17 +393,17 @@ imAccount.prototype = {
 
     // Avoid prompting the user for the master password more than once at startup.
     if (gUserCanceledMasterPasswordPrompt)
       return "";
 
     let passwordURI = "im://" + this.protocol.id;
     let logins;
     try {
-      logins = LoginManager.findLogins({}, passwordURI, null, passwordURI);
+      logins = Services.logins.findLogins({}, passwordURI, null, passwordURI);
     } catch (e) {
       this._handleMasterPasswordException(e);
       return "";
     }
     let normalizedName = this.normalizedName;
     for each (let login in logins) {
       if (login.username == normalizedName) {
         this._password = login.password;
@@ -438,30 +434,30 @@ imAccount.prototype = {
     if (gUserCanceledMasterPasswordPrompt)
       return;
     let newLogin = Cc["@mozilla.org/login-manager/loginInfo;1"]
                    .createInstance(Ci.nsILoginInfo);
     let passwordURI = "im://" + this.protocol.id;
     newLogin.init(passwordURI, null, passwordURI, this.normalizedName,
                   aPassword, "", "");
     try {
-      let logins = LoginManager.findLogins({}, passwordURI, null, passwordURI);
+      let logins = Services.logins.findLogins({}, passwordURI, null, passwordURI);
       let saved = false;
       for each (let login in logins) {
         if (newLogin.matches(login, true)) {
           if (aPassword)
-            LoginManager.modifyLogin(login, newLogin);
+            Services.logins.modifyLogin(login, newLogin);
           else
-            LoginManager.removeLogin(login);
+            Services.logins.removeLogin(login);
           saved = true;
           break;
         }
       }
       if (!saved && aPassword)
-        LoginManager.addLogin(newLogin);
+        Services.logins.addLogin(newLogin);
     } catch (e) {
       this._handleMasterPasswordException(e);
     }
 
     this._connectionInfoChanged();
     if (aPassword &&
         this._connectionErrorReason == Ci.imIAccount.ERROR_MISSING_PASSWORD)
       this._connectionErrorReason = Ci.imIAccount.NO_ERROR;
@@ -519,20 +515,20 @@ imAccount.prototype = {
     let login = Cc["@mozilla.org/login-manager/loginInfo;1"]
                 .createInstance(Ci.nsILoginInfo);
     let passwordURI = "im://" + this.protocol.id;
     // The password is stored with the normalizedName. If the protocol
     // plugin is missing, we can't access the normalizedName, but in
     // lots of cases this.name is equivalent.
     let name = this.prplAccount ? this.normalizedName : this.name;
     login.init(passwordURI, null, passwordURI, name, "", "", "");
-    let logins = LoginManager.findLogins({}, passwordURI, null, passwordURI);
+    let logins = Services.logins.findLogins({}, passwordURI, null, passwordURI);
     for each (let l in logins) {
       if (login.matches(l, true)) {
-        LoginManager.removeLogin(l);
+        Services.logins.removeLogin(l);
         break;
       }
     }
     if (this.prplAccount)
       this.prplAccount.remove();
     this.unInit();
     Services.contacts.forgetAccount(this.numericId);
     this.prefBranch.deleteBranch("");
--- a/chat/components/src/imContacts.js
+++ b/chat/components/src/imContacts.js
@@ -9,19 +9,17 @@ Cu.import("resource:///modules/imService
 var gDBConnection = null;
 
 function getDBConnection()
 {
   const NS_APP_USER_PROFILE_50_DIR = "ProfD";
   let dbFile = Services.dirsvc.get(NS_APP_USER_PROFILE_50_DIR, Ci.nsIFile);
   dbFile.append("blist.sqlite");
 
-  let conn =
-    Cc["@mozilla.org/storage/service;1"].getService(Ci.mozIStorageService)
-                                        .openDatabase(dbFile);
+  let conn = Services.storage.openDatabase(dbFile);
   if (!conn.connectionReady)
     throw Cr.NS_ERROR_UNEXPECTED;
 
   // Grow blist db in 512KB increments.
   try {
     conn.setGrowthIncrement(512 * 1024, "");
   } catch (e if e.result == Cr.NS_ERROR_FILE_TOO_BIG) {
     Services.console.logStringMessage("Not setting growth increment on " +
--- a/chat/components/src/smileProtocolHandler.js
+++ b/chat/components/src/smileProtocolHandler.js
@@ -1,14 +1,15 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 const {classes: Cc, interfaces: Ci, utils: Cu} = Components;
 
+Cu.import("resource://gre/modules/Services.jsm");
 Cu.import("resource://gre/modules/XPCOMUtils.jsm");
 Cu.import("resource:///modules/imSmileys.jsm");
 
 const kSmileRegexp = /^smile:\/\//;
 
 function smileProtocolHandler() { }
 
 smileProtocolHandler.prototype = {
@@ -22,18 +23,17 @@ smileProtocolHandler.prototype = {
     let uri = Cc["@mozilla.org/network/simple-uri;1"].createInstance(Ci.nsIURI);
     uri.spec = aSpec;
     uri.QueryInterface(Ci.nsIMutable);
     uri.mutable = false;
     return uri;
   },
   newChannel: function SPH_newChannel(aURI) {
     let smile = aURI.spec.replace(kSmileRegexp, "");
-    let ios = Cc["@mozilla.org/network/io-service;1"].getService(Ci.nsIIOService);
-    let channel = ios.newChannel(getSmileRealURI(smile), null, null);
+    let channel = Services.io.newChannel(getSmileRealURI(smile), null, null);
     channel.originalURI = aURI;
     return channel;
   },
   allowPort: function  SPH_allowPort(aPort, aScheme) false,
 
   classDescription: "Smile Protocol Handler",
   classID: Components.ID("{04e58eae-dfbc-4c9e-8130-6d9ef19cbff4}"),
   contractID: "@mozilla.org/network/protocol;1?name=smile",
--- a/chat/content/convbrowser.xml
+++ b/chat/content/convbrowser.xml
@@ -612,31 +612,27 @@
         <parameter name="aSubject"/>
         <parameter name="aTopic"/>
         <parameter name="aData"/>
         <body>
         <![CDATA[
           if (aTopic != "nsPref:changed")
             throw "Bad notification";
 
-          var clipboard =
-            Components.classes["@mozilla.org/widget/clipboard;1"]
-                      .getService(Components.interfaces.nsIClipboard);
-
           if (this.magicCopyEnabled) {
             this.contentWindow.controllers.insertControllerAt(0, this);
-            if (clipboard.supportsSelectionClipboard()) {
+            if (Services.clipboard.supportsSelectionClipboard()) {
               this.contentWindow.getSelection()
                   .QueryInterface(Components.interfaces.nsISelectionPrivate)
                   .addSelectionListener(this);
             }
           }
           else {
             this.contentWindow.controllers.removeController(this);
-            if (clipboard.supportsSelectionClipboard()) {
+            if (Services.clipboard.supportsSelectionClipboard()) {
                this.contentWindow.getSelection()
                    .QueryInterface(Components.interfaces.nsISelectionPrivate)
                    .removeSelectionListener(this);
             }
           }
         ]]>
         </body>
       </method>
@@ -723,20 +719,17 @@
                 this.contentWindow.scrollToElement = this._scrollToElement.bind(this);
                 return;
               }
               this.removeProgressListener(this);
 
               if (this.magicCopyEnabled) {
                 this.contentWindow.controllers.insertControllerAt(0, this);
 
-                var clipboard =
-                  Components.classes["@mozilla.org/widget/clipboard;1"]
-                            .getService(Components.interfaces.nsIClipboard);
-                if (clipboard.supportsSelectionClipboard()) {
+                if (Services.clipboard.supportsSelectionClipboard()) {
                   this.contentWindow.getSelection()
                       .QueryInterface(Components.interfaces.nsISelectionPrivate)
                       .addSelectionListener(this);
                 }
               }
               if (!this.magicCopyInitialized) {
                 Services.prefs.addObserver(this.magicCopyPref, this, false);
                 this.magicCopyInitialized = true;
@@ -1018,19 +1011,17 @@
         <![CDATA[
           aOtherBrowser.destroy();
 
           var magicCopyEnabled = this.magicCopyEnabled;
 
           if (magicCopyEnabled) {
             // We need to remove the selection listener (unix only)
             // before _contentWindow is changed.
-            var clipboard = Components.classes["@mozilla.org/widget/clipboard;1"]
-                                      .getService(Ci.nsIClipboard);
-            if (clipboard.supportsSelectionClipboard()) {
+            if (Services.clipboard.supportsSelectionClipboard()) {
               aOtherBrowser.contentWindow.getSelection()
                            .QueryInterface(Components.interfaces.nsISelectionPrivate)
                            .removeSelectionListener(aOtherBrowser);
             }
           }
 
           // and the progress listener too!
           this.removeProgressListener(this);
@@ -1061,17 +1052,17 @@
 
           if (!magicCopyEnabled)
             return;
 
           // Now that we have the new _contentWindow, we can add back our controller
           this.contentWindow.controllers.insertControllerAt(0, this);
 
           // and our selection listener!
-          if (clipboard.supportsSelectionClipboard()) {
+          if (Services.clipboard.supportsSelectionClipboard()) {
             this.contentWindow.getSelection()
                 .QueryInterface(Components.interfaces.nsISelectionPrivate)
                 .addSelectionListener(this);
           }
         ]]>
         </body>
       </method>
     </implementation>
--- a/chat/modules/hiddenWindow.jsm
+++ b/chat/modules/hiddenWindow.jsm
@@ -1,20 +1,19 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 const EXPORTED_SYMBOLS = ["getHiddenHTMLWindow"];
 
+Components.utils.import("resource://gre/modules/Services.jsm");
 Components.utils.import("resource://gre/modules/XPCOMUtils.jsm");
 
 XPCOMUtils.defineLazyGetter(this, "hiddenWindow", function()
-  Components.classes["@mozilla.org/appshell/appShellService;1"]
-                      .getService(Components.interfaces.nsIAppShellService)
-                      .hiddenDOMWindow
+  Services.appshell.hiddenDOMWindow
 );
 #ifndef XP_MACOSX
 function getHiddenHTMLWindow() hiddenWindow
 #else
 function getHiddenHTMLWindow() {
   let browser = hiddenWindow.document.getElementById("hiddenBrowser");
   return browser.docShell ? browser.contentWindow : hiddenWindow;
 }
--- a/mail/components/im/content/imAccountWizard.js
+++ b/mail/components/im/content/imAccountWizard.js
@@ -469,19 +469,17 @@ var accountWizard = {
   setGetMoreProtocols: function (){
     let prefURL = PREF_EXTENSIONS_GETMOREPROTOCOLSURL;
     var getMore = document.getElementById("getMoreProtocols");
     var showGetMore = false;
     const nsIPrefBranch2 = Components.interfaces.nsIPrefBranch2;
 
     if (Services.prefs.getPrefType(prefURL) != nsIPrefBranch2.PREF_INVALID) {
       try {
-        var getMoreURL = Components.classes["@mozilla.org/toolkit/URLFormatterService;1"]
-                                   .getService(Components.interfaces.nsIURLFormatter)
-                                   .formatURLPref(prefURL);
+        var getMoreURL = Services.urlFormatter.formatURLPref(prefURL);
         getMore.setAttribute("getMoreURL", getMoreURL);
         showGetMore = getMoreURL != "about:blank";
       }
       catch (e) { }
     }
     getMore.hidden = !showGetMore;
   },
 
--- a/mail/components/im/content/imcontact.xml
+++ b/mail/components/im/content/imcontact.xml
@@ -215,21 +215,17 @@
      </method>
     </implementation>
     <handlers>
      <handler event="blur">
        <![CDATA[
          if (!this.hasAttribute("aliasing"))
            return;
 
-         let win =
-           Components.classes["@mozilla.org/focus-manager;1"]
-                     .getService(Components.interfaces.nsIFocusManager)
-                     .activeWindow;
-         if (win == document.defaultView)
+         if (Services.focus.activeWindow == document.defaultView)
            finishAliasing(true);
        ]]>
      </handler>
 
      <handler event="mousedown">
        <![CDATA[
          if (!this.hasAttribute("aliasing") && canOpenConversation() &&
              event.originalTarget.getAttribute("anonid") == "startChatBubble") {