Bug 795158 - Switch to Services.jsm: /editor/ui/: Services.<other>. r=mconley, r=IanN
authorSebastian Hengst <archaeopteryx@coole-files.de>
Tue, 05 Feb 2013 00:29:30 +0100
changeset 14801 c8d667fee51c287e243db21ff76c6701596741e0
parent 14800 e7f920afc8bd218f51fe5e49b66c95258b9663e7
child 14802 7301f1cf35e0a4f85c85f34b0219823c05e32bbd
push id867
push userbugzilla@standard8.plus.com
push dateMon, 01 Apr 2013 20:44:27 +0000
treeherdercomm-beta@797726b8d244 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmconley, IanN
bugs795158
Bug 795158 - Switch to Services.jsm: /editor/ui/: Services.<other>. r=mconley, r=IanN
editor/ui/composer/content/ComposerCommands.js
editor/ui/composer/content/editor.js
editor/ui/composer/content/editorApplicationOverlay.js
editor/ui/composer/content/editorUtilities.js
editor/ui/composer/content/publishprefs.js
editor/ui/dialogs/content/EditorSaveAsCharset.js
editor/ui/nsComposerCmdLineHandler.js
--- a/editor/ui/composer/content/ComposerCommands.js
+++ b/editor/ui/composer/content/ComposerCommands.js
@@ -2120,22 +2120,20 @@ var nsPreviewCommand =
     // Don't continue if user canceled during prompt for saving
     // DocumentHasBeenSaved will test if we have a URL and suppress "Don't Save" button if not
     if (!CheckAndSaveDocument("cmd_preview", DocumentHasBeenSaved()))
       return;
 
     // Check if we saved again just in case?
     if (DocumentHasBeenSaved())
     {
-      var browser;
+      let browser;
       try {
         // Find a browser with this URL
-        var windowManager = Components.classes["@mozilla.org/appshell/window-mediator;1"].getService();
-        var windowManagerInterface = windowManager.QueryInterface(Components.interfaces.nsIWindowMediator);
-        var enumerator = windowManagerInterface.getEnumerator("navigator:browser");
+        let enumerator = Services.wm.getEnumerator("navigator:browser");
 
         var documentURI = GetDocumentUrl();
         while (enumerator.hasMoreElements())
         {
           browser = enumerator.getNext();
           if (browser && (documentURI == browser.getBrowser().currentURI.spec))
             break;
 
@@ -2623,41 +2621,41 @@ var nsHLineCommand =
   doCommand: function(aCommand)
   {
     // Inserting an HLine is different in that we don't use properties dialog
     //  unless we are editing an existing line's attributes
     //  We get the last-used attributes from the prefs and insert immediately
 
     var tagName = "hr";
     var editor = GetCurrentEditor();
-      
+
     var hLine;
     try {
       hLine = editor.getSelectedElement(tagName);
     } catch (e) {return;}
 
     if (hLine)
     {
       // We only open the dialog for an existing HRule
       window.openDialog("chrome://editor/content/EdHLineProps.xul", "_blank", "chrome,close,titlebar,modal");
-    } 
+    }
     else
     {
       try {
         hLine = editor.createElementWithDefaults(tagName);
 
         // We change the default attributes to those saved in the user prefs
         let align = Services.prefs.getIntPref("editor.hrule.align");
         if (align == 0)
           editor.setAttributeOrEquivalent(hLine, "align", "left", true);
         else if (align == 2)
           editor.setAttributeOrEquivalent(hLine, "align", "right", true);
 
         //Note: Default is center (don't write attribute)
-  
+
         let width = Services.prefs.getIntPref("editor.hrule.width");
         if (Services.prefs.getBoolPref("editor.hrule.width_percent"))
           width = width +"%";
 
         editor.setAttributeOrEquivalent(hLine, "width", width, true);
 
         let height = Services.prefs.getIntPref("editor.hrule.height");
         editor.setAttributeOrEquivalent(hLine, "size", String(height), true);
--- a/editor/ui/composer/content/editor.js
+++ b/editor/ui/composer/content/editor.js
@@ -2782,21 +2782,19 @@ function SwitchInsertCharToThisWindow(wi
   }
   return false;
 }
 
 function FindEditorWithInsertCharDialog()
 {
   try {
     // Find window with an InsertCharsWindow and switch association to this one
-    var windowManager = Components.classes['@mozilla.org/appshell/window-mediator;1'].getService();
-    var windowManagerInterface = windowManager.QueryInterface( Components.interfaces.nsIWindowMediator);
-    var enumerator = windowManagerInterface.getEnumerator( null );
-
-    while ( enumerator.hasMoreElements()  )
+    let enumerator = Services.wm.getEnumerator(null);
+
+    while (enumerator.hasMoreElements())
     {
       var tempWindow = enumerator.getNext();
 
       if (tempWindow != window && "InsertCharWindow" in tempWindow &&
           tempWindow.InsertCharWindow)
       {
         return tempWindow;
       }
@@ -2828,21 +2826,19 @@ function EditorFindOrCreateInsertCharWin
 }
 
 // Find another HTML editor window to associate with the InsertChar dialog
 //   or close it if none found  (May be a mail composer)
 function SwitchInsertCharToAnotherEditorOrClose()
 {
   if ("InsertCharWindow" in window && window.InsertCharWindow)
   {
-    var windowManager = Components.classes['@mozilla.org/appshell/window-mediator;1'].getService();
     var enumerator;
     try {
-      var windowManagerInterface = windowManager.QueryInterface( Components.interfaces.nsIWindowMediator);
-      enumerator = windowManagerInterface.getEnumerator( null );
+      enumerator = Services.wm.getEnumerator(null);
     }
     catch(e) {}
     if (!enumerator) return;
 
     // TODO: Fix this to search for command controllers and look for "cmd_InsertChars"
     // For now, detect just Web Composer and HTML Mail Composer
     while ( enumerator.hasMoreElements()  )
     {
--- a/editor/ui/composer/content/editorApplicationOverlay.js
+++ b/editor/ui/composer/content/editorApplicationOverlay.js
@@ -66,22 +66,20 @@ function editPage(url, aFileType)
 
   var wintype = document.documentElement.getAttribute('windowtype');
   var charsetArg;
 
   if (wintype == "navigator:browser" && content.document)
     charsetArg = "charset=" + content.document.characterSet;
 
   try {
-    var uri = createURI(url, null, null);
+    let uri = createURI(url, null, null);
 
-    var windowManager = Components.classes['@mozilla.org/appshell/window-mediator;1'].getService();
-    var windowManagerInterface = windowManager.QueryInterface( Components.interfaces.nsIWindowMediator);
-    var enumerator = windowManagerInterface.getEnumerator("composer:" + aFileType);
-    var emptyWindow;
+    let enumerator = Services.wm.getEnumerator("composer:" + aFileType);
+    let emptyWindow;
     while ( enumerator.hasMoreElements() )
     {
       var win = enumerator.getNext();
       if ( win && win.IsWebComposer())
       {
         if (CheckOpenWindowForURIMatch(uri, win))
         {
           // We found an editor with our url
--- a/editor/ui/composer/content/editorUtilities.js
+++ b/editor/ui/composer/content/editorUtilities.js
@@ -56,44 +56,34 @@ function ConfirmWithTitle(title, message
 
 /************* String Utilities ***************/
 
 function GetString(name)
 {
   if (!gStringBundle)
   {
     try {
-      var strBundleService =
-          Components.classes["@mozilla.org/intl/stringbundle;1"].getService(); 
-      strBundleService = 
-          strBundleService.QueryInterface(Components.interfaces.nsIStringBundleService);
-
-      gStringBundle = strBundleService.createBundle("chrome://editor/locale/editor.properties"); 
-
+      gStringBundle = Services.strings.createBundle("chrome://editor/locale/editor.properties");
     } catch (ex) {}
   }
   if (gStringBundle)
   {
     try {
       return gStringBundle.GetStringFromName(name);
     } catch (e) {}
   }
   return null;
 }
 
 function GetFormattedString(aName, aVal)
 {
   if (!gStringBundle)
   {
     try {
-      var gStringBundle =
-          Components.classes["@mozilla.org/intl/stringbundle;1"]
-                    .getService(Components.interfaces.nsIStringBundleService)
-                    .createBundle("chrome://editor/locale/editor.properties"); 
-
+      gStringBundle = Services.strings.createBundle("chrome://editor/locale/editor.properties");
     } catch (ex) {}
   }
   if (gStringBundle)
   {
     try {
       return gStringBundle.formatStringFromName(aName, [aVal], 1);
     } catch (e) {}
   }
@@ -209,27 +199,27 @@ function GetCurrentTableEditor()
 {
   var editor = GetCurrentEditor();
   return (editor && (editor instanceof nsITableEditor)) ? editor : null;
 }
 
 function GetCurrentEditorElement()
 {
   var tmpWindow = window;
-  
+
   do {
     // Get the <editor> element(s)
     var editorList = tmpWindow.document.getElementsByTagName("editor");
 
     // This will change if we support > 1 editor element
     if (editorList.item(0))
       return editorList.item(0);
 
     tmpWindow = tmpWindow.opener;
-  } 
+  }
   while (tmpWindow);
 
   return null;
 }
 
 function GetCurrentCommandManager()
 {
   try {
@@ -597,22 +587,22 @@ function MakeRelativeUrl(url)
     if (nextUrlSlash == -1)
     {
       // We're done matching and all dirs in url
       // what's left is the filename
       done = true;
 
       // Remove filename for named anchors in the same file
       if (nextDocSlash == -1 && docFilename)
-      { 
+      {
         var anchorIndex = urlPath.indexOf("#");
         if (anchorIndex > 0)
         {
           var urlFilename = doCaseInsensitive ? urlPath.toLowerCase() : urlPath;
-        
+
           if (urlFilename.indexOf(docFilename) == 0)
             urlPath = urlPath.slice(anchorIndex);
         }
       }
     }
     else if (nextDocSlash >= 0)
     {
       // Test for matching subdir
@@ -629,18 +619,18 @@ function MakeRelativeUrl(url)
         docPath = docPath.slice(nextDocSlash+1);
         urlPath = urlPath.slice(nextUrlSlash+1);
       }
       else
       {
         // No match, we're done
         done = true;
 
-        // Be sure we are on the same local drive or volume 
-        //   (the first "dir" in the path) because we can't 
+        // Be sure we are on the same local drive or volume
+        //   (the first "dir" in the path) because we can't
         //   relativize to different drives/volumes.
         // UNIX doesn't have volumes, so we must not do this else
         //  the first directory will be misinterpreted as a volume name
         if (firstDirTest && docScheme == "file" && os != gUNIX)
           return inputUrl;
       }
     }
     else  // No more doc dirs left, we're done
@@ -679,32 +669,32 @@ function MakeAbsoluteUrl(url)
     return resultUrl;
 
   // Make a URI object to use its "resolve" method
   let absoluteUrl = resultUrl;
   let docUri = Services.io.newURI(docUrl, GetCurrentEditor().documentCharacterSet, null);
 
   try {
     absoluteUrl = docUri.resolve(resultUrl);
-    // This is deprecated and buggy! 
+    // This is deprecated and buggy!
     // If used, we must make it a path for the parent directory (remove filename)
     //absoluteUrl = IOService.resolveRelativePath(resultUrl, docUrl);
   } catch (e) {}
 
   return absoluteUrl;
 }
 
 // Get the HREF of the page's <base> tag or the document location
 // returns empty string if no base href and document hasn't been saved yet
 function GetDocumentBaseUrl()
 {
   try {
     var docUrl;
 
-    // if document supplies a <base> tag, use that URL instead 
+    // if document supplies a <base> tag, use that URL instead
     var baseList = GetCurrentEditor().document.getElementsByTagName("base");
     if (baseList)
     {
       var base = baseList.item(0);
       if (base)
         docUrl = base.getAttribute("href");
     }
     if (!docUrl)
@@ -869,17 +859,17 @@ function StripUsernamePasswordFromURI(ur
     try {
       urlspec = uri.spec;
       var userPass = uri.userPass;
       if (userPass)
       {
         start = urlspec.indexOf(userPass);
         urlspec = urlspec.slice(0, start) + urlspec.slice(start+userPass.length+1);
       }
-    } catch (e) {}    
+    } catch (e) {}
   }
   return urlspec;
 }
 
 function InsertUsernameIntoUrl(urlspec, username)
 {
   if (!urlspec || !username)
     return urlspec;
@@ -944,18 +934,18 @@ function GetHTMLOrCSSStyleValue(element,
   if (!value)
     return "";
 
   return value;
 }
 
 /************* Miscellaneous ***************/
 // Clone simple JS objects
-function Clone(obj) 
-{ 
+function Clone(obj)
+{
   var clone = {};
   for (var i in obj)
   {
     if (typeof obj[i] == 'object')
       clone[i] = Clone(obj[i]);
     else
       clone[i] = obj[i];
   }
--- a/editor/ui/composer/content/publishprefs.js
+++ b/editor/ui/composer/content/publishprefs.js
@@ -806,77 +806,60 @@ function FormatDirForPublishing(dir)
   var dirLen = dir.length;
   var lastChar = dir.charAt(dirLen-1);
   if (dirLen > 1 && lastChar != "/" && lastChar != "=" && lastChar != "&" && lastChar  != "?")
     return (dir + "/");
 
   return dir;
 }
 
-var gLoginManager;
-function GetLoginManager()
-{
-  if (!gLoginManager)
-    gLoginManager = Components.classes["@mozilla.org/login-manager;1"]
-                              .getService(Components.interfaces.nsILoginManager);
-
-  return gLoginManager;
-}
-
 function GetSavedPassword(publishData)
 {
   if (!publishData || !publishData.publishUrl)
     return "";
 
-  var loginManager = GetLoginManager();
-  var url = GetUrlForPasswordManager(publishData);
-  var logins = loginManager.findLogins({}, url, null, url);
+  let url = GetUrlForPasswordManager(publishData);
+  let logins = Services.logins.findLogins({}, url, null, url);
 
-  for (var i = 0; i < logins.length; i++) {
+  for (let i = 0; i < logins.length; i++) {
     if (logins[i].username == publishData.username)
       return logins[i].password;
   }
 
   return "";
 }
 
 function SavePassword(publishData)
 {
   if (!publishData || !publishData.publishUrl || !publishData.username)
     return false;
 
-  var loginManager = GetLoginManager();
-  if (loginManager)
-  {
-    var url = GetUrlForPasswordManager(publishData);
+  let url = GetUrlForPasswordManager(publishData);
 
-    // Remove existing entry by finding all logins that match
-    var logins = loginManager.findLogins({}, url, null, url);
+  // Remove existing entry by finding all logins that match.
+  let logins = Services.logins.findLogins({}, url, null, url);
 
-    for (var i = 0; i < logins.length; i++) {
-      if (logins[i].username == publishData.username) {
-        loginManager.removeLogin(logins[i]);
-        break;
-      }
+  for (let i = 0; i < logins.length; i++) {
+    if (logins[i].username == publishData.username) {
+      Services.logins.removeLogin(logins[i]);
+      break;
     }
-
-    // If SavePassword is true, add new password
-    if (publishData.savePassword)
-    {
-      var authInfo = Components.classes["@mozilla.org/login-manager/loginInfo;1"]
-                               .createInstance(Components.interfaces.nsILoginInfo);
-      authInfo.init(url, null, url, publishData.username, publishData.password,
-                    "", "");
-      loginManager.addLogin(authInfo);
-    }
-
-    return true;
   }
 
-  return false;
+  // If SavePassword is true, add new password.
+  if (publishData.savePassword)
+  {
+    let authInfo = Components.classes["@mozilla.org/login-manager/loginInfo;1"]
+                             .createInstance(Components.interfaces.nsILoginInfo);
+    authInfo.init(url, null, url, publishData.username, publishData.password,
+                  "", "");
+    Services.logins.addLogin(authInfo);
+  }
+
+  return true;
 }
 
 function GetUrlForPasswordManager(publishData)
 {
   if (!publishData || !publishData.publishUrl)
     return false;
 
   let url = Services.io.newURI(publishData.publishUrl, null, null);
--- a/editor/ui/dialogs/content/EditorSaveAsCharset.js
+++ b/editor/ui/dialogs/content/EditorSaveAsCharset.js
@@ -1,13 +1,12 @@
 /* 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/. */
 
-
 var gCharset="";
 var gTitleWasEdited = false;
 var gCharsetWasChanged = false;
 var gInsertNewContentType = false;
 var gContenttypeElement;
 var gInitDone = false;
 
 //Cancel() is in EdDialogCommon.js
@@ -16,18 +15,17 @@ function Startup()
 {
   var editor = GetCurrentEditor();
   if (!editor)
   {
     window.close();
     return;
   }
 
-  var observerService = Components.classes["@mozilla.org/observer-service;1"].getService(Components.interfaces.nsIObserverService);
-  observerService.notifyObservers(null, "charsetmenu-selected", "other");
+  Services.obs.notifyObservers(null, "charsetmenu-selected", "other");
 
   gDialog.TitleInput    = document.getElementById("TitleInput");
   gDialog.charsetTree   = document.getElementById('CharsetTree'); 
   gDialog.exportToText  = document.getElementById('ExportToText');
 
   gContenttypeElement = GetHTTPEquivMetaElement("content-type");
   if (!gContenttypeElement && (editor.contentsMIMEType != 'text/plain')) 
   {
--- a/editor/ui/nsComposerCmdLineHandler.js
+++ b/editor/ui/nsComposerCmdLineHandler.js
@@ -1,12 +1,13 @@
 /* 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/. */
 
+Components.utils.import("resource://gre/modules/Services.jsm");
 Components.utils.import("resource://gre/modules/XPCOMUtils.jsm");
 
 const nsICommandLineHandler = Components.interfaces.nsICommandLineHandler;
 const nsISupportsString     = Components.interfaces.nsISupportsString;
 const nsIWindowWatcher      = Components.interfaces.nsIWindowWatcher;
 
 function nsComposerCmdLineHandler() {}
 nsComposerCmdLineHandler.prototype = {
@@ -37,20 +38,18 @@ nsComposerCmdLineHandler.prototype = {
         return;
       }
     }
     catch (e) {
       // One of the flags is present but no data, so set default arg.
       args.data = "about:blank";
     }
 
-    var wwatch = Components.classes["@mozilla.org/embedcomp/window-watcher;1"]
-                           .getService(nsIWindowWatcher);
-    wwatch.openWindow(null, "chrome://editor/content", "_blank",
-                      "chrome,dialog=no,all", args);
+    Services.ww.openWindow(null, "chrome://editor/content", "_blank",
+                           "chrome,dialog=no,all", args);
     cmdLine.preventDefault = true;
   },
 
   helpInfo : "  -edit <url>        Open Composer.\n",
 
   /* XPCOMUtils */
   classID: Components.ID("{f7d8db95-ab5d-4393-a796-9112fe758cfa}")
 };