Bug 1439831 - Enable ESLint rule mozilla/use-services for mobile/android. r=nechen
authorMark Banner <standard8@mozilla.com>
Wed, 21 Feb 2018 08:57:28 +0000
changeset 461244 0d73894a5fc45ca86b7498a1da0de719516b654e
parent 461243 9f0ee2f582a28742d8a4c5025418d71934b55401
child 461245 784928adcf87fadbbbcfc2a28345d94b6cffb31c
push id1683
push usersfraser@mozilla.com
push dateThu, 26 Apr 2018 16:43:40 +0000
treeherdermozilla-release@5af6cb21869d [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersnechen
bugs1439831
milestone60.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1439831 - Enable ESLint rule mozilla/use-services for mobile/android. r=nechen MozReview-Commit-ID: 3MuRD78hMuE
.eslintrc.js
mobile/android/chrome/content/aboutAddons.js
mobile/android/components/AboutRedirector.js
mobile/android/components/BlocklistPrompt.js
mobile/android/components/DirectoryProvider.js
mobile/android/components/LoginManagerPrompter.js
mobile/android/components/PromptService.js
mobile/android/modules/Sanitizer.jsm
mobile/android/tests/browser/chrome/test_awsy_lite.html
mobile/android/tests/browser/chrome/test_offline_page.html
mobile/android/tests/browser/robocop/robocop_head.js
mobile/android/tests/browser/robocop/roboextender/bootstrap.js
mobile/android/tests/browser/robocop/testUITelemetry.js
--- a/.eslintrc.js
+++ b/.eslintrc.js
@@ -39,17 +39,16 @@ module.exports = {
     "env": {
       "mozilla/browser-window": true
     }
   },{
     // XXX Bug 1421969. These files/directories are still being fixed,
     // so turn off mozilla/use-services for them for now.
     "files": [
       "extensions/pref/**",
-      "mobile/android/**",
     ],
     "rules": {
       "mozilla/use-services": "off",
     }
   }, {
     // XXX Bug 1434446. These directories have jsm files still being fixed, so
     // turn off global no-unused-vars checking for them.
     "files": [
--- a/mobile/android/chrome/content/aboutAddons.js
+++ b/mobile/android/chrome/content/aboutAddons.js
@@ -244,18 +244,17 @@ var Addons = {
   },
 
   _createBrowseItem: function _createBrowseItem() {
     let outer = document.createElement("div");
     outer.className = "addon-item list-item";
     outer.setAttribute("role", "button");
     outer.addEventListener("click", function(event) {
       try {
-        let formatter = Cc["@mozilla.org/toolkit/URLFormatterService;1"].getService(Ci.nsIURLFormatter);
-        openLink(formatter.formatURLPref("extensions.getAddons.browseAddons"));
+        openLink(Services.urlFormatter.formatURLPref("extensions.getAddons.browseAddons"));
       } catch (e) {
         Cu.reportError(e);
       }
     }, true);
 
     let img = document.createElement("img");
     img.className = "icon";
     img.setAttribute("src", AMO_ICON);
--- a/mobile/android/components/AboutRedirector.js
+++ b/mobile/android/components/AboutRedirector.js
@@ -1,13 +1,14 @@
 /* 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/. */
 ChromeUtils.import("resource://gre/modules/AppConstants.jsm");
 ChromeUtils.import("resource://gre/modules/XPCOMUtils.jsm");
+ChromeUtils.import("resource://gre/modules/Services.jsm");
 
 var modules = {
   fennec: {
     uri: "chrome://browser/content/about.xhtml",
     privileged: true,
     hide: true
   },
 
@@ -86,22 +87,19 @@ AboutRedirector.prototype = {
       flags = Ci.nsIAboutModule.HIDE_FROM_ABOUTABOUT;
 
     return flags | Ci.nsIAboutModule.ALLOW_SCRIPT;
   },
 
   newChannel: function(aURI, aLoadInfo) {
     let moduleInfo = this._getModuleInfo(aURI);
 
-    var ios = Cc["@mozilla.org/network/io-service;1"].
-              getService(Ci.nsIIOService);
+    var newURI = Services.io.newURI(moduleInfo.uri);
 
-    var newURI = ios.newURI(moduleInfo.uri);
-
-    var channel = ios.newChannelFromURIWithLoadInfo(newURI, aLoadInfo);
+    var channel = Services.io.newChannelFromURIWithLoadInfo(newURI, aLoadInfo);
 
     if (!moduleInfo.privileged) {
       // Setting the owner to null means that we'll go through the normal
       // path in GetChannelPrincipal and create a codebase principal based
       // on the channel's originalURI
       channel.owner = null;
     }
 
--- a/mobile/android/components/BlocklistPrompt.js
+++ b/mobile/android/components/BlocklistPrompt.js
@@ -22,18 +22,17 @@ BlocklistPrompt.prototype = {
       let notifyBox = win.getNotificationBox();
       let restartCallback = function(aNotification, aDescription) {
         // Notify all windows that an application quit has been requested
         var cancelQuit = Cc["@mozilla.org/supports-PRBool;1"].createInstance(Ci.nsISupportsPRBool);
         Services.obs.notifyObservers(cancelQuit, "quit-application-requested", "restart");
 
         // If nothing aborted, quit the app
         if (!cancelQuit.data) {
-          let appStartup = Cc["@mozilla.org/toolkit/app-startup;1"].getService(Ci.nsIAppStartup);
-          appStartup.quit(Ci.nsIAppStartup.eRestart | Ci.nsIAppStartup.eAttemptQuit);
+          Services.startup.quit(Ci.nsIAppStartup.eRestart | Ci.nsIAppStartup.eAttemptQuit);
         }
       };
 
       let buttons = [{accessKey: null,
                       label: bundle.GetStringFromName("notificationRestart.button"),
                       callback: restartCallback}];
       notifyBox.appendNotification(bundle.GetStringFromName("notificationRestart.blocked"),
                                    "blocked-add-on",
@@ -49,9 +48,8 @@ BlocklistPrompt.prototype = {
         aAddons[i].item.userDisabled = true;
     }
   },
   classID: Components.ID("{4e6ea350-b09a-11df-94e2-0800200c9a66}"),
   QueryInterface: XPCOMUtils.generateQI([Ci.nsIBlocklistPrompt])
 };
 
 this.NSGetFactory = XPCOMUtils.generateNSGetFactory([BlocklistPrompt]);
-
--- a/mobile/android/components/DirectoryProvider.js
+++ b/mobile/android/components/DirectoryProvider.js
@@ -30,25 +30,23 @@ function DirectoryProvider() {}
 DirectoryProvider.prototype = {
   classID: Components.ID("{ef0f7a87-c1ee-45a8-8d67-26f586e46a4b}"),
 
   QueryInterface: XPCOMUtils.generateQI([Ci.nsIDirectoryServiceProvider,
                                          Ci.nsIDirectoryServiceProvider2]),
 
   getFile: function(prop, persistent) {
     if (prop == NS_APP_CACHE_PARENT_DIR) {
-      let dirsvc = Cc["@mozilla.org/file/directory_service;1"].getService(Ci.nsIProperties);
-      let profile = dirsvc.get("ProfD", Ci.nsIFile);
+      let profile = Services.dirsvc.get("ProfD", Ci.nsIFile);
       return profile;
     } else if (prop == WEBAPPS_DIR) {
       // returns the folder that should hold the webapps database file
       // For fennec we will store that in the root profile folder so that all
       // webapps can easily access it
-      let dirsvc = Cc["@mozilla.org/file/directory_service;1"].getService(Ci.nsIProperties);
-      let profile = dirsvc.get("ProfD", Ci.nsIFile);
+      let profile = Services.dirsvc.get("ProfD", Ci.nsIFile);
       return profile.parent;
     } else if (prop == XRE_APP_DISTRIBUTION_DIR) {
       let distributionDirectories =  this._getDistributionDirectories();
       for (let i = 0; i < distributionDirectories.length; i++) {
         if (distributionDirectories[i].exists()) {
           return distributionDirectories[i];
         }
       }
--- a/mobile/android/components/LoginManagerPrompter.js
+++ b/mobile/android/components/LoginManagerPrompter.js
@@ -37,21 +37,19 @@ LoginManagerPrompter.prototype = {
 
   _factory: null,
   _window: null,
   _debug: false, // mirrors signon.debug
 
   __strBundle: null, // String bundle for L10N
   get _strBundle() {
     if (!this.__strBundle) {
-      let bunService = Cc["@mozilla.org/intl/stringbundle;1"].
-                       getService(Ci.nsIStringBundleService);
       this.__strBundle = {
-        pwmgr: bunService.createBundle("chrome://browser/locale/passwordmgr.properties"),
-        brand: bunService.createBundle("chrome://branding/locale/brand.properties")
+        pwmgr: Services.strings.createBundle("chrome://browser/locale/passwordmgr.properties"),
+        brand: Services.strings.createBundle("chrome://branding/locale/brand.properties")
       };
 
       if (!this.__strBundle)
         throw "String bundle for Login Manager not present!";
     }
 
     return this.__strBundle;
   },
--- a/mobile/android/components/PromptService.js
+++ b/mobile/android/components/PromptService.js
@@ -560,18 +560,17 @@ var PromptUtils = {
 
     // Special code for using that & symbol
     aLabel = aLabel.replace(/\&\&/g, "&");
 
     return aLabel;
   },
 
   get pwmgr() {
-    delete this.pwmgr;
-    return this.pwmgr = Cc["@mozilla.org/login-manager;1"].getService(Ci.nsILoginManager);
+    return Services.logins;
   },
 
   getHostnameAndRealm: function pu_getHostnameAndRealm(aRealmString) {
     let httpRealm = /^.+ \(.+\)$/;
     if (httpRealm.test(aRealmString))
       return [null, null, null];
 
     let uri = Services.io.newURI(aRealmString);
--- a/mobile/android/modules/Sanitizer.jsm
+++ b/mobile/android/modules/Sanitizer.jsm
@@ -62,19 +62,18 @@ Sanitizer.prototype = {
 
   items: {
     cache: {
       clear: function() {
         return new Promise(function(resolve, reject) {
           let refObj = {};
           TelemetryStopwatch.start("FX_SANITIZE_CACHE", refObj);
 
-          var cache = Cc["@mozilla.org/netwerk/cache-storage-service;1"].getService(Ci.nsICacheStorageService);
           try {
-            cache.clear();
+            Services.cache2.clear();
           } catch (er) {}
 
           let imageCache = Cc["@mozilla.org/image/tools;1"].getService(Ci.imgITools)
                                                            .getImgCacheForDocument(null);
           try {
             imageCache.clearCache(false); // true=chrome, false=content
           } catch (er) {}
 
@@ -143,18 +142,17 @@ Sanitizer.prototype = {
       get canClear() {
         return true;
       }
     },
 
     offlineApps: {
       clear: function() {
         return new Promise(function(resolve, reject) {
-          var cacheService = Cc["@mozilla.org/netwerk/cache-storage-service;1"].getService(Ci.nsICacheStorageService);
-          var appCacheStorage = cacheService.appCacheStorage(Services.loadContextInfo.default, null);
+          var appCacheStorage = Services.cache2.appCacheStorage(Services.loadContextInfo.default, null);
           try {
             appCacheStorage.asyncEvictStorage(null);
           } catch (er) {}
 
           resolve();
         });
       },
 
--- a/mobile/android/tests/browser/chrome/test_awsy_lite.html
+++ b/mobile/android/tests/browser/chrome/test_awsy_lite.html
@@ -54,21 +54,20 @@
     },
 
     onCloseWindow: function(aWindow) {
         detachFrom(aWindow);
     },
   };
 
   function doFullGc(aCallback, aIterations) {
-    var threadMan = Cc["@mozilla.org/thread-manager;1"].getService(Ci.nsIThreadManager);
     var domWindowUtils = gWindow.QueryInterface(Ci.nsIInterfaceRequestor).getInterface(Ci.nsIDOMWindowUtils);
 
     function runSoon(f) {
-        threadMan.dispatchToMainThread({ run: f });
+        Services.tm.dispatchToMainThread({ run: f });
     }
 
     function cc() {
         if (domWindowUtils.cycleCollect) {
             domWindowUtils.cycleCollect();
         }
         Services.obs.notifyObservers(null, "child-cc-request");
     }
--- a/mobile/android/tests/browser/chrome/test_offline_page.html
+++ b/mobile/android/tests/browser/chrome/test_offline_page.html
@@ -46,17 +46,17 @@ Migrated from Robocop: https://bugzilla.
 
   add_task(function* test_offline() {
     // Tests always connect to localhost, and per bug 87717, localhost is now
     // reachable in offline mode.  To avoid this, disable any proxy.
     proxyPrefValue = Services.prefs.getIntPref("network.proxy.type");
     Services.prefs.setIntPref("network.proxy.type", 0);
 
     // Clear network cache.
-    Cc["@mozilla.org/netwerk/cache-storage-service;1"].getService(Ci.nsICacheStorageService).clear();
+    Services.cache2.clear();
 
     chromeWin = Services.wm.getMostRecentWindow("navigator:browser");
     let BrowserApp = chromeWin.BrowserApp;
 
     // Add a new tab with a blank page so we can better control the real page load and the offline state
     browser = BrowserApp.addTab("about:blank", { selected: true, parentId: BrowserApp.selectedTab.id }).browser;
 
     SimpleTest.registerCleanupFunction(function() {
--- a/mobile/android/tests/browser/robocop/robocop_head.js
+++ b/mobile/android/tests/browser/robocop/robocop_head.js
@@ -21,16 +21,17 @@
 /*
  * This file contains common code that is loaded before each test file(s).
  * See http://developer.mozilla.org/en/docs/Writing_xpcshell-based_unit_tests
  * for more information.
  */
 
 /* eslint-disable mozilla/use-cc-etc */
 /* eslint-disable mozilla/use-chromeutils-import */
+/* eslint-disable mozilla/use-services */
 
 var _quit = false;
 var _tests_pending = 0;
 var _pendingTimers = [];
 var _cleanupFunctions = [];
 
 function _dump(str) {
   let start = /^TEST-/.test(str) ? "\n" : "";
--- a/mobile/android/tests/browser/robocop/roboextender/bootstrap.js
+++ b/mobile/android/tests/browser/robocop/roboextender/bootstrap.js
@@ -25,32 +25,26 @@ var windowListener = {
         });
       }
     }, {once: true});
   },
   onCloseWindow: function(aWindow) { },
 };
 
 function startup(aData, aReason) {
-  let wm = Cc["@mozilla.org/appshell/window-mediator;1"].getService(Ci.nsIWindowMediator);
-
   // Load into any new windows
-  wm.addListener(windowListener);
+  Services.wm.addListener(windowListener);
   EventDispatcher.instance.registerListener(function(event, data, callback) {
       dump("Robocop:Quit received -- requesting quit");
-      let appStartup = Cc["@mozilla.org/toolkit/app-startup;1"].getService(Ci.nsIAppStartup);
-      appStartup.quit(Ci.nsIAppStartup.eForceQuit);
+      Services.startup.quit(Ci.nsIAppStartup.eForceQuit);
   }, "Robocop:Quit");
 }
 
 function shutdown(aData, aReason) {
   // When the application is shutting down we normally don't have to clean up any UI changes
   if (aReason == APP_SHUTDOWN) return;
 
-  let wm = Cc["@mozilla.org/appshell/window-mediator;1"].getService(Ci.nsIWindowMediator);
-
   // Stop watching for new windows
-  wm.removeListener(windowListener);
+  Services.wm.removeListener(windowListener);
 }
 
 function install(aData, aReason) { }
 function uninstall(aData, aReason) { }
-
--- a/mobile/android/tests/browser/robocop/testUITelemetry.js
+++ b/mobile/android/tests/browser/robocop/testUITelemetry.js
@@ -51,19 +51,17 @@ function do_check_measurement_eq(m1, m2)
       break;
 
     default:
       do_throw("Unknown event type: " + m1.type);
   }
 }
 
 function getObserver() {
-  let bridge = Cc["@mozilla.org/android/bridge;1"]
-                 .getService(Ci.nsIAndroidBridge);
-  let obsXPCOM = bridge.browserApp.getUITelemetryObserver();
+  let obsXPCOM = Services.androidBridge.browserApp.getUITelemetryObserver();
   do_check_true(!!obsXPCOM);
   return obsXPCOM.wrappedJSObject;
 }
 
 /**
  * The following event test will fail if telemetry isn't enabled. The Java-side
  * part of this test should have turned it on; fail if it didn't work.
  */