Bug 1772313 - Part 6: Stop calling ChromeUtils.defineModuleGetter for Services, in services/. r=kmag

Differential Revision: https://phabricator.services.mozilla.com/D148159
This commit is contained in:
Tooru Fujisawa 2022-06-06 04:42:06 +00:00
Родитель 2dcfd09f81
Коммит 52f97da911
4 изменённых файлов: 23 добавлений и 45 удалений

Просмотреть файл

@ -5,11 +5,7 @@
const lazy = {};
ChromeUtils.defineModuleGetter(
lazy,
"Services",
"resource://gre/modules/Services.jsm"
);
const { Services } = ChromeUtils.import("resource://gre/modules/Services.jsm");
ChromeUtils.defineModuleGetter(
lazy,
"FileUtils",
@ -493,7 +489,7 @@ LogManager.prototype = {
this._cleaningUpFileLogs = false;
this._log.debug("Done deleting files.");
// This notification is used only for tests.
lazy.Services.obs.notifyObservers(
Services.obs.notifyObservers(
null,
"services-tests:common:log-manager:cleanup-logs"
);

Просмотреть файл

@ -20,11 +20,7 @@ ChromeUtils.defineModuleGetter(
"ClientID",
"resource://gre/modules/ClientID.jsm"
);
ChromeUtils.defineModuleGetter(
lazy,
"Services",
"resource://gre/modules/Services.jsm"
);
const { Services } = ChromeUtils.import("resource://gre/modules/Services.jsm");
XPCOMUtils.defineLazyGetter(lazy, "CryptoHash", () => {
return Components.Constructor(
@ -186,10 +182,7 @@ class UptakeTelemetry {
// Contrary to histograms, Telemetry Events are not enabled by default.
// Enable them on first call to `report()`.
if (!this._eventsEnabled) {
lazy.Services.telemetry.setEventRecordingEnabled(
TELEMETRY_EVENTS_ID,
true
);
Services.telemetry.setEventRecordingEnabled(TELEMETRY_EVENTS_ID, true);
this._eventsEnabled = true;
}
@ -203,7 +196,7 @@ class UptakeTelemetry {
acc[k] = extra[k].toString();
return acc;
}, {});
lazy.Services.telemetry.recordEvent(
Services.telemetry.recordEvent(
TELEMETRY_EVENTS_ID,
"uptake",
component,

Просмотреть файл

@ -45,11 +45,7 @@ const {
const lazy = {};
ChromeUtils.defineModuleGetter(
lazy,
"Services",
"resource://gre/modules/Services.jsm"
);
const { Services } = ChromeUtils.import("resource://gre/modules/Services.jsm");
ChromeUtils.defineModuleGetter(
lazy,
"WebChannel",
@ -110,7 +106,7 @@ XPCOMUtils.defineLazyPreferenceGetter(
"identity.fxaccounts.remote.root",
null,
false,
val => lazy.Services.io.newURI(val)
val => Services.io.newURI(val)
);
// These engines were added years after Sync had been introduced, they need
@ -214,7 +210,7 @@ FxAccountsWebChannel.prototype = {
_setupChannel() {
// if this.contentUri is present but not a valid URI, then this will throw an error.
try {
this._webChannelOrigin = lazy.Services.io.newURI(this._contentUri);
this._webChannelOrigin = Services.io.newURI(this._contentUri);
this._registerChannel();
} catch (e) {
log.error(e);
@ -244,7 +240,7 @@ FxAccountsWebChannel.prototype = {
let browser = sendingContext.browsingContext.top.embedderElement;
switch (command) {
case COMMAND_PROFILE_CHANGE:
lazy.Services.obs.notifyObservers(
Services.obs.notifyObservers(
null,
ON_PROFILE_CHANGE_NOTIFICATION,
data.uid
@ -279,7 +275,7 @@ FxAccountsWebChannel.prototype = {
case COMMAND_PAIR_PREFERENCES:
if (lazy.pairingEnabled) {
browser.loadURI("about:preferences?action=pair#sync", {
triggeringPrincipal: lazy.Services.scriptSecurityManager.getSystemPrincipal(),
triggeringPrincipal: Services.scriptSecurityManager.getSystemPrincipal(),
});
}
break;
@ -477,7 +473,7 @@ FxAccountsWebChannelHelpers.prototype = {
!declinedEngines.includes(engine)
) {
// These extra engines are disabled by default.
lazy.Services.prefs.setBoolPref(
Services.prefs.setBoolPref(
`services.sync.engine.${engine}`,
true
);
@ -486,10 +482,7 @@ FxAccountsWebChannelHelpers.prototype = {
log.debug("Received declined engines", declinedEngines);
lazy.Weave.Service.engineManager.setDeclined(declinedEngines);
declinedEngines.forEach(engine => {
lazy.Services.prefs.setBoolPref(
`services.sync.engine.${engine}`,
false
);
Services.prefs.setBoolPref(`services.sync.engine.${engine}`, false);
});
}
log.debug("Webchannel is enabling sync");
@ -601,7 +594,7 @@ FxAccountsWebChannelHelpers.prototype = {
_getAvailableExtraEngines() {
return EXTRA_ENGINES.filter(engineName => {
try {
return lazy.Services.prefs.getBoolPref(
return Services.prefs.getBoolPref(
`services.sync.engine.${engineName}.available`
);
} catch (e) {
@ -645,7 +638,7 @@ FxAccountsWebChannelHelpers.prototype = {
*/
getPreviousAccountNameHashPref() {
try {
return lazy.Services.prefs.getStringPref(PREF_LAST_FXA_USER);
return Services.prefs.getStringPref(PREF_LAST_FXA_USER);
} catch (_) {
return "";
}
@ -657,7 +650,7 @@ FxAccountsWebChannelHelpers.prototype = {
* @param acctName the account name of the user's account.
*/
setPreviousAccountNameHashPref(acctName) {
lazy.Services.prefs.setStringPref(
Services.prefs.setStringPref(
PREF_LAST_FXA_USER,
lazy.CryptoUtils.sha256Base64(acctName)
);
@ -677,7 +670,7 @@ FxAccountsWebChannelHelpers.prototype = {
uri += "#sync";
browser.loadURI(uri, {
triggeringPrincipal: lazy.Services.scriptSecurityManager.getSystemPrincipal(),
triggeringPrincipal: Services.scriptSecurityManager.getSystemPrincipal(),
});
},
@ -702,7 +695,7 @@ FxAccountsWebChannelHelpers.prototype = {
* @private
*/
_promptForRelink(acctName) {
let sb = lazy.Services.strings.createBundle(
let sb = Services.strings.createBundle(
"chrome://browser/locale/syncSetup.properties"
);
let continueLabel = sb.GetStringFromName("continue.label");
@ -712,14 +705,14 @@ FxAccountsWebChannelHelpers.prototype = {
]);
let body =
sb.GetStringFromName("relinkVerify.heading") + "\n\n" + description;
let ps = lazy.Services.prompt;
let ps = Services.prompt;
let buttonFlags =
ps.BUTTON_POS_0 * ps.BUTTON_TITLE_IS_STRING +
ps.BUTTON_POS_1 * ps.BUTTON_TITLE_CANCEL +
ps.BUTTON_POS_1_DEFAULT;
// If running in context of the browser chrome, window does not exist.
let pressed = lazy.Services.prompt.confirmEx(
let pressed = Services.prompt.confirmEx(
null,
title,
body,
@ -741,7 +734,7 @@ var singleton;
// things) and allowing multiple channels would cause such notifications to be
// sent multiple times.
var EnsureFxAccountsWebChannel = () => {
let contentUri = lazy.Services.urlFormatter.formatURLPref(
let contentUri = Services.urlFormatter.formatURLPref(
"identity.fxaccounts.remote.root"
);
if (singleton && singleton._contentUri !== contentUri) {

Просмотреть файл

@ -24,13 +24,9 @@ const { Logger } = ChromeUtils.import("resource://tps/logger.jsm");
const { XPCOMUtils } = ChromeUtils.import(
"resource://gre/modules/XPCOMUtils.jsm"
);
const lazy = {};
ChromeUtils.defineModuleGetter(
lazy,
"Services",
"resource://gre/modules/Services.jsm"
);
const { Services } = ChromeUtils.import("resource://gre/modules/Services.jsm");
const lazy = {};
XPCOMUtils.defineLazyGlobalGetters(lazy, ["fetch"]);
/**
@ -75,7 +71,7 @@ var Authentication = {
},
async _openVerificationPage(uri) {
let mainWindow = lazy.Services.wm.getMostRecentWindow("navigator:browser");
let mainWindow = Services.wm.getMostRecentWindow("navigator:browser");
let newtab = mainWindow.gBrowser.addWebTab(uri);
let win = mainWindow.gBrowser.getBrowserForTab(newtab);
await new Promise(resolve => {