Skip to content
This repository has been archived by the owner on Aug 4, 2022. It is now read-only.

Commit

Permalink
Bug 1417944 - Enable ESLint rule mozilla/use-services for toolkit/. r…
Browse files Browse the repository at this point in the history
…=mossop

MozReview-Commit-ID: JhHXYma5Adp
  • Loading branch information
Standard8 committed Nov 22, 2017
1 parent 58d7da6 commit 4ae855d
Show file tree
Hide file tree
Showing 13 changed files with 73 additions and 83 deletions.
13 changes: 12 additions & 1 deletion toolkit/.eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,16 @@ module.exports = {
"complexity": ["error", 41],

"mozilla/no-task": "error",
}

"mozilla/use-services": "error",
},

"overrides": [{
// Turn off use-services for xml files. XBL bindings are going away, and
// working out the valid globals for those is difficult.
"files": "**/*.xml",
"rules": {
"mozilla/use-services": "off",
}
}]
};
7 changes: 0 additions & 7 deletions toolkit/components/.eslintrc.js

This file was deleted.

2 changes: 2 additions & 0 deletions toolkit/modules/LoadContextInfo.jsm
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,7 @@
*/

this.EXPORTED_SYMBOLS = ["LoadContextInfo"];
// XXX Bug 1417937 will remove this file.
// eslint-disable-next-line mozilla/use-services
this.LoadContextInfo = Components.classes["@mozilla.org/load-context-info-factory;1"]
.getService(Components.interfaces.nsILoadContextInfoFactory);
1 change: 1 addition & 0 deletions toolkit/modules/Promise.jsm
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ this.Ci = Components.interfaces;
this.Cu = Components.utils;
this.Cr = Components.results;

// eslint-disable-next-line mozilla/use-services
this.Cc["@mozilla.org/moz/jssubscript-loader;1"]
.getService(this.Ci.mozIJSSubScriptLoader)
.loadSubScript("resource://gre/modules/Promise-backend.js", this);
6 changes: 2 additions & 4 deletions toolkit/mozapps/downloads/DownloadLastDir.jsm
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,8 @@ var observer = {
}
};

var os = Components.classes["@mozilla.org/observer-service;1"]
.getService(Components.interfaces.nsIObserverService);
os.addObserver(observer, "last-pb-context-exited", true);
os.addObserver(observer, "browser:purge-session-history", true);
Services.obs.addObserver(observer, "last-pb-context-exited", true);
Services.obs.addObserver(observer, "browser:purge-session-history", true);

function readLastDirPref() {
try {
Expand Down
15 changes: 4 additions & 11 deletions toolkit/mozapps/downloads/DownloadUtils.jsm
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,7 @@ Object.defineProperty(this, "gBundle", {
enumerable: true,
get() {
delete this.gBundle;
return this.gBundle = Cc["@mozilla.org/intl/stringbundle;1"].
getService(Ci.nsIStringBundleService).
createBundle(kDownloadProperties);
return this.gBundle = Services.strings.createBundle(kDownloadProperties);
},
});

Expand Down Expand Up @@ -385,17 +383,13 @@ this.DownloadUtils = {
* @return A pair: [display host for the URI string, full host name]
*/
getURIHost: function DU_getURIHost(aURIString) {
let ioService = Cc["@mozilla.org/network/io-service;1"].
getService(Ci.nsIIOService);
let eTLDService = Cc["@mozilla.org/network/effective-tld-service;1"].
getService(Ci.nsIEffectiveTLDService);
let idnService = Cc["@mozilla.org/network/idn-service;1"].
getService(Ci.nsIIDNService);

// Get a URI that knows about its components
let uri;
try {
uri = ioService.newURI(aURIString);
uri = Services.io.newURI(aURIString);
} catch (ex) {
return ["", ""];
}
Expand All @@ -415,7 +409,7 @@ this.DownloadUtils = {
let displayHost;
try {
// This might fail if it's an IP address or doesn't have more than 1 part
let baseDomain = eTLDService.getBaseDomain(uri);
let baseDomain = Services.eTLD.getBaseDomain(uri);

// Convert base domain for display; ignore the isAscii out param
displayHost = idnService.convertToDisplayIDN(baseDomain, {});
Expand Down Expand Up @@ -555,7 +549,6 @@ function convertTimeUnitsUnits(aTime, aIndex) {
*/
function log(aMsg) {
let msg = "DownloadUtils.jsm: " + (aMsg.join ? aMsg.join("") : aMsg);
Cc["@mozilla.org/consoleservice;1"].getService(Ci.nsIConsoleService).
logStringMessage(msg);
Services.console.logStringMessage(msg);
dump(msg + "\n");
}
11 changes: 4 additions & 7 deletions toolkit/mozapps/handling/content/dialog.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ var Cr = Components.results;
var Cu = Components.utils;

Cu.import("resource://gre/modules/SharedPromptUtils.jsm");
Cu.import("resource://gre/modules/Services.jsm");


var dialog = {
Expand Down Expand Up @@ -106,8 +107,6 @@ var dialog = {
var items = document.getElementById("items");
var possibleHandlers = this._handlerInfo.possibleApplicationHandlers;
var preferredHandler = this._handlerInfo.preferredApplicationHandler;
var ios = Cc["@mozilla.org/network/io-service;1"].
getService(Ci.nsIIOService);
for (let i = possibleHandlers.length - 1; i >= 0; --i) {
let app = possibleHandlers.queryElementAt(i, Ci.nsIHandlerApp);
let elm = document.createElement("richlistitem");
Expand All @@ -117,10 +116,10 @@ var dialog = {

if (app instanceof Ci.nsILocalHandlerApp) {
// See if we have an nsILocalHandlerApp and set the icon
let uri = ios.newFileURI(app.executable);
let uri = Services.io.newFileURI(app.executable);
elm.setAttribute("image", "moz-icon://" + uri.spec + "?size=32");
} else if (app instanceof Ci.nsIWebHandlerApp) {
let uri = ios.newURI(app.uriTemplate);
let uri = Services.io.newURI(app.uriTemplate);
if (/^https?$/.test(uri.scheme)) {
// Unfortunately we can't use the favicon service to get the favicon,
// because the service looks for a record with the exact URL we give
Expand Down Expand Up @@ -168,9 +167,7 @@ var dialog = {

fp.open(rv => {
if (rv == Ci.nsIFilePicker.returnOK && fp.file) {
let uri = Cc["@mozilla.org/network/util;1"].
getService(Ci.nsIIOService).
newFileURI(fp.file);
let uri = Services.io.newFileURI(fp.file);

let handlerApp = Cc["@mozilla.org/uriloader/local-handler-app;1"].
createInstance(Ci.nsILocalHandlerApp);
Expand Down
26 changes: 11 additions & 15 deletions toolkit/mozapps/handling/nsContentDispatchChooser.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@
* 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/XPCOMUtils.jsm");

// Constants

const Cc = Components.classes;
const Ci = Components.interfaces;
const Cr = Components.results;
const Cu = Components.utils;

Cu.import("resource://gre/modules/XPCOMUtils.jsm");
Cu.import("resource://gre/modules/Services.jsm");

const CONTENT_HANDLING_URL = "chrome://mozapps/content/handling/dialog.xul";
const STRINGBUNDLE_URL = "chrome://mozapps/locale/handling/handling.properties";
Expand All @@ -31,12 +33,8 @@ nsContentDispatchChooser.prototype =
window = aWindowContext.getInterface(Ci.nsIDOMWindow);
} catch (e) { /* it's OK to not have a window */ }

var sbs = Cc["@mozilla.org/intl/stringbundle;1"].
getService(Ci.nsIStringBundleService);
var bundle = sbs.createBundle(STRINGBUNDLE_URL);
var bundle = Services.strings.createBundle(STRINGBUNDLE_URL);

var xai = Cc["@mozilla.org/xre/app-info;1"].
getService(Ci.nsIXULAppInfo);
// TODO when this is hooked up for content, we will need different strings
// for most of these
var arr = [bundle.GetStringFromName("protocol.title"),
Expand All @@ -47,7 +45,7 @@ nsContentDispatchChooser.prototype =
[aURI.scheme], 1),
bundle.GetStringFromName("protocol.checkbox.accesskey"),
bundle.formatStringFromName("protocol.checkbox.extra",
[xai.name], 1)];
[Services.appinfo.name], 1)];

var params = Cc["@mozilla.org/array;1"].createInstance(Ci.nsIMutableArray);
let SupportsString = Components.Constructor(
Expand All @@ -62,13 +60,11 @@ nsContentDispatchChooser.prototype =
params.appendElement(aURI);
params.appendElement(aWindowContext);

var ww = Cc["@mozilla.org/embedcomp/window-watcher;1"].
getService(Ci.nsIWindowWatcher);
ww.openWindow(window,
CONTENT_HANDLING_URL,
null,
"chrome,dialog=yes,resizable,centerscreen",
params);
Services.ww.openWindow(window,
CONTENT_HANDLING_URL,
null,
"chrome,dialog=yes,resizable,centerscreen",
params);
},

// nsISupports
Expand Down
44 changes: 22 additions & 22 deletions toolkit/mozapps/preferences/changemp.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

const { classes: Cc, interfaces: Ci, utils: Cu, results: Cr } = Components;

Cu.import("resource://gre/modules/Services.jsm");

const nsPK11TokenDB = "@mozilla.org/security/pk11tokendb;1";
const nsIPK11TokenDB = Components.interfaces.nsIPK11TokenDB;
const nsIDialogParamBlock = Components.interfaces.nsIDialogParamBlock;
Expand Down Expand Up @@ -69,8 +71,6 @@ function process() {

function setPassword() {
var pk11db = Components.classes[nsPK11TokenDB].getService(nsIPK11TokenDB);
var promptService = Components.classes["@mozilla.org/embedcomp/prompt-service;1"]
.getService(Components.interfaces.nsIPromptService);
var token = pk11db.getInternalKeyToken();

var oldpwbox = document.getElementById("oldpw");
Expand Down Expand Up @@ -100,46 +100,46 @@ function setPassword() {
var secmoddb = Components.classes[nsPKCS11ModuleDB].getService(nsIPKCS11ModuleDB);
if (secmoddb.isFIPSEnabled) {
// empty passwords are not allowed in FIPS mode
promptService.alert(window,
bundle.getString("pw_change_failed_title"),
bundle.getString("pw_change2empty_in_fips_mode"));
Services.prompt.alert(window,
bundle.getString("pw_change_failed_title"),
bundle.getString("pw_change2empty_in_fips_mode"));
passok = 0;
}
}
if (passok) {
token.changePassword(oldpw, pw1.value);
if (pw1.value == "") {
promptService.alert(window,
bundle.getString("pw_change_success_title"),
bundle.getString("pw_erased_ok")
+ " " + bundle.getString("pw_empty_warning"));
Services.prompt.alert(window,
bundle.getString("pw_change_success_title"),
bundle.getString("pw_erased_ok")
+ " " + bundle.getString("pw_empty_warning"));
} else {
promptService.alert(window,
bundle.getString("pw_change_success_title"),
bundle.getString("pw_change_ok"));
Services.prompt.alert(window,
bundle.getString("pw_change_success_title"),
bundle.getString("pw_change_ok"));
}
success = true;
}
}
} else {
oldpwbox.focus();
oldpwbox.setAttribute("value", "");
promptService.alert(window,
bundle.getString("pw_change_failed_title"),
bundle.getString("incorrect_pw"));
Services.prompt.alert(window,
bundle.getString("pw_change_failed_title"),
bundle.getString("incorrect_pw"));
}
} catch (e) {
promptService.alert(window,
bundle.getString("pw_change_failed_title"),
bundle.getString("failed_pw_change"));
Services.prompt.alert(window,
bundle.getString("pw_change_failed_title"),
bundle.getString("failed_pw_change"));
}
} else {
token.initPassword(pw1.value);
if (pw1.value == "") {
promptService.alert(window,
bundle.getString("pw_change_success_title"),
bundle.getString("pw_not_wanted")
+ " " + bundle.getString("pw_empty_warning"));
Services.prompt.alert(window,
bundle.getString("pw_change_success_title"),
bundle.getString("pw_not_wanted")
+ " " + bundle.getString("pw_empty_warning"));
}
success = true;
}
Expand Down
20 changes: 9 additions & 11 deletions toolkit/mozapps/preferences/removemp.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,14 @@
* 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");

var gRemovePasswordDialog = {
_token: null,
_bundle: null,
_prompt: null,
_okButton: null,
_password: null,
init() {
this._prompt = Components.classes["@mozilla.org/embedcomp/prompt-service;1"]
.getService(Components.interfaces.nsIPromptService);
this._bundle = document.getElementById("bundlePreferences");

this._okButton = document.documentElement.getButton("accept");
Expand All @@ -36,17 +35,16 @@ var gRemovePasswordDialog = {
removePassword() {
if (this._token.checkPassword(this._password.value)) {
this._token.changePassword(this._password.value, "");
this._prompt.alert(window,
this._bundle.getString("pw_change_success_title"),
this._bundle.getString("pw_erased_ok")
+ " " + this._bundle.getString("pw_empty_warning"));
Services.prompt.alert(window,
this._bundle.getString("pw_change_success_title"),
this._bundle.getString("pw_erased_ok")
+ " " + this._bundle.getString("pw_empty_warning"));
} else {
this._password.value = "";
this._password.focus();
this._prompt.alert(window,
this._bundle.getString("pw_change_failed_title"),
this._bundle.getString("incorrect_pw"));
Services.prompt.alert(window,
this._bundle.getString("pw_change_failed_title"),
this._bundle.getString("incorrect_pw"));
}
},
};

3 changes: 1 addition & 2 deletions toolkit/mozapps/update/content/updates.js
Original file line number Diff line number Diff line change
Expand Up @@ -1349,8 +1349,7 @@ var gFinishedPage = {
}

// Restart the application
CoC["@mozilla.org/toolkit/app-startup;1"].getService(CoI.nsIAppStartup).
quit(CoI.nsIAppStartup.eAttemptQuit | CoI.nsIAppStartup.eRestart);
Services.startup.quit(CoI.nsIAppStartup.eAttemptQuit | CoI.nsIAppStartup.eRestart);
},

/**
Expand Down
4 changes: 1 addition & 3 deletions toolkit/mozapps/update/tests/chrome/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -480,9 +480,7 @@ function delayedDefaultCallback() {
* @return nsIFile for the continue file.
*/
function getContinueFile() {
let continueFile = Cc["@mozilla.org/file/directory_service;1"].
getService(Ci.nsIProperties).
get("CurWorkD", Ci.nsIFile);
let continueFile = Services.dirsvc.get("CurWorkD", Ci.nsIFile);
let continuePath = REL_PATH_DATA + "continue";
let continuePathParts = continuePath.split("/");
for (let i = 0; i < continuePathParts.length; ++i) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,10 @@ function getInterfacesFromServicesFile() {
}
});

// nsIPropertyBag2 is used for system-info, but it is also used for other
// services and items as well, so we can't really warn for it.
delete servicesASTParser.result.nsIPropertyBag2;

return servicesASTParser.result;
}

Expand Down

0 comments on commit 4ae855d

Please sign in to comment.