Bug 1817183 - Migrate most of services/fxaccounts to ES modules. r=markh

Differential Revision: https://phabricator.services.mozilla.com/D170061
This commit is contained in:
Mark Banner 2023-02-17 16:34:42 +00:00
parent 48a366e1ec
commit 0a0248d5ae
19 changed files with 67 additions and 130 deletions

View File

@ -183,7 +183,7 @@ services/common/kinto-http-client.js
services/common/kinto-offline-client.js
# Webpack-bundled library
services/fxaccounts/FxAccountsPairingChannel.js
services/fxaccounts/FxAccountsPairingChannel.sys.mjs
# Servo is imported.
servo/

View File

@ -83,8 +83,8 @@ const startupPhases = {
"resource://gre/modules/BookmarkHTMLUtils.sys.mjs",
"resource://gre/modules/Bookmarks.sys.mjs",
"resource://gre/modules/ContextualIdentityService.sys.mjs",
"resource://gre/modules/FxAccounts.jsm",
"resource://gre/modules/FxAccountsStorage.jsm",
"resource://gre/modules/FxAccounts.sys.mjs",
"resource://gre/modules/FxAccountsStorage.sys.mjs",
"resource://gre/modules/PlacesBackups.sys.mjs",
"resource://gre/modules/PlacesExpiration.sys.mjs",
"resource://gre/modules/PlacesSyncUtils.sys.mjs",

View File

@ -9,13 +9,8 @@
* See https://github.com/mozilla/fxa-auth-server/wiki/onepw-protocol
*/
"use strict";
import { Log } from "resource://gre/modules/Log.sys.mjs";
var EXPORTED_SYMBOLS = ["Credentials"];
const { Log } = ChromeUtils.importESModule(
"resource://gre/modules/Log.sys.mjs"
);
const { CryptoUtils } = ChromeUtils.import(
"resource://services-crypto/utils.js"
);
@ -45,7 +40,7 @@ var log = Log.repository.getLogger("Identity.FxAccounts");
log.level = LOG_LEVEL;
log.addAppender(new Log.ConsoleAppender(new Log.BasicFormatter()));
var Credentials = Object.freeze({
export var Credentials = Object.freeze({
/**
* Make constants accessible to tests
*/

View File

@ -1,20 +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/. */
"use strict";
const { PromiseUtils } = ChromeUtils.importESModule(
"resource://gre/modules/PromiseUtils.sys.mjs"
);
import { PromiseUtils } from "resource://gre/modules/PromiseUtils.sys.mjs";
const { CryptoUtils } = ChromeUtils.import(
"resource://services-crypto/utils.js"
);
const { XPCOMUtils } = ChromeUtils.importESModule(
"resource://gre/modules/XPCOMUtils.sys.mjs"
);
const { clearTimeout, setTimeout } = ChromeUtils.importESModule(
"resource://gre/modules/Timer.sys.mjs"
);
import { XPCOMUtils } from "resource://gre/modules/XPCOMUtils.sys.mjs";
import { clearTimeout, setTimeout } from "resource://gre/modules/Timer.sys.mjs";
const { FxAccountsStorageManager } = ChromeUtils.import(
"resource://gre/modules/FxAccountsStorage.jsm"
);
@ -129,7 +124,7 @@ XPCOMUtils.defineLazyPreferenceGetter(
// }
// If the state has changed between the function being called and the promise
// being resolved, the .resolve() call will actually be rejected.
function AccountState(storageManager) {
export function AccountState(storageManager) {
this.storageManager = storageManager;
this.inFlightTokenRequests = new Map();
this.promiseInitialized = this.storageManager
@ -375,7 +370,7 @@ function copyObjectProperties(from, to, thisObj, keys) {
* (although |./mach doc| is broken on windows (bug 1232403) and on Linux for
* markh (some obscure npm issue he gave up on) - so later...)
*/
class FxAccounts {
export class FxAccounts {
constructor(mocks = null) {
this._internal = new FxAccountsInternal();
if (mocks) {
@ -1645,7 +1640,8 @@ FxAccountsInternal.prototype = {
};
let fxAccountsSingleton = null;
function getFxAccountsSingleton() {
export function getFxAccountsSingleton() {
if (fxAccountsSingleton) {
return fxAccountsSingleton;
}
@ -1660,4 +1656,3 @@ function getFxAccountsSingleton() {
}
// `AccountState` is exported for tests.
var EXPORTED_SYMBOLS = ["getFxAccountsSingleton", "FxAccounts", "AccountState"];

View File

@ -2,8 +2,6 @@
* 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 EXPORTED_SYMBOLS = ["FxAccountsClient"];
const { CommonUtils } = ChromeUtils.import(
"resource://services-common/utils.js"
);
@ -36,7 +34,9 @@ const SIGNUP = "/account/create";
// Devices older than this many days will not appear in the devices list
const DEVICES_FILTER_DAYS = 21;
var FxAccountsClient = function(host = Services.prefs.getCharPref(HOST_PREF)) {
export var FxAccountsClient = function(
host = Services.prefs.getCharPref(HOST_PREF)
) {
this.host = host;
// The FxA auth server expects requests to certain endpoints to be authorized

View File

@ -2,8 +2,6 @@
* 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 = ["SendTab", "FxAccountsCommands"];
const {
COMMAND_SENDTAB,
COMMAND_SENDTAB_TAIL,
@ -16,9 +14,8 @@ ChromeUtils.defineModuleGetter(
"PushCrypto",
"resource://gre/modules/PushCrypto.jsm"
);
const { XPCOMUtils } = ChromeUtils.importESModule(
"resource://gre/modules/XPCOMUtils.sys.mjs"
);
import { XPCOMUtils } from "resource://gre/modules/XPCOMUtils.sys.mjs";
const { Observers } = ChromeUtils.import(
"resource://services-common/observers.js"
);
@ -39,7 +36,7 @@ XPCOMUtils.defineLazyPreferenceGetter(
}
);
class FxAccountsCommands {
export class FxAccountsCommands {
constructor(fxAccountsInternal) {
this._fxai = fxAccountsInternal;
this.sendTab = new SendTab(this, fxAccountsInternal);
@ -248,7 +245,7 @@ class FxAccountsCommands {
* the push keys to deliver the tabs using same mechanism we use for web-push.
* However, clients use the send-tab keys for end-to-end encryption.
*/
class SendTab {
export class SendTab {
constructor(commands, fxAccountsInternal) {
this._commands = commands;
this._fxai = fxAccountsInternal;

View File

@ -1,8 +1,6 @@
/* 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/. */
"use strict";
var EXPORTED_SYMBOLS = ["FxAccountsConfig"];
const { RESTRequest } = ChromeUtils.import(
"resource://services-common/rest.js"
@ -10,9 +8,7 @@ const { RESTRequest } = ChromeUtils.import(
const { log } = ChromeUtils.import(
"resource://gre/modules/FxAccountsCommon.js"
);
const { XPCOMUtils } = ChromeUtils.importESModule(
"resource://gre/modules/XPCOMUtils.sys.mjs"
);
import { XPCOMUtils } from "resource://gre/modules/XPCOMUtils.sys.mjs";
const lazy = {};
@ -57,7 +53,7 @@ const CONFIG_PREFS = [
];
const SYNC_PARAM = "sync";
var FxAccountsConfig = {
export var FxAccountsConfig = {
async promiseEmailURI(email, entrypoint, extraParams = {}) {
return this._buildURL("", {
extraParams: { entrypoint, email, service: SYNC_PARAM, ...extraParams },

View File

@ -1,11 +1,8 @@
/* 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/. */
"use strict";
const { XPCOMUtils } = ChromeUtils.importESModule(
"resource://gre/modules/XPCOMUtils.sys.mjs"
);
import { XPCOMUtils } from "resource://gre/modules/XPCOMUtils.sys.mjs";
const {
log,
@ -57,7 +54,7 @@ function sanitizeDeviceName(name) {
}
// Everything to do with FxA devices.
class FxAccountsDevice {
export class FxAccountsDevice {
constructor(fxai) {
this._fxai = fxai;
this._deviceListCache = null;
@ -653,5 +650,3 @@ FxAccountsDevice.prototype.QueryInterface = ChromeUtils.generateQI([
function urlsafeBase64Encode(buffer) {
return ChromeUtils.base64URLEncode(new Uint8Array(buffer), { pad: false });
}
var EXPORTED_SYMBOLS = ["FxAccountsDevice"];

View File

@ -1,11 +1,9 @@
/* 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/. */
"use strict";
const { PromiseUtils } = ChromeUtils.importESModule(
"resource://gre/modules/PromiseUtils.sys.mjs"
);
import { PromiseUtils } from "resource://gre/modules/PromiseUtils.sys.mjs";
const { CommonUtils } = ChromeUtils.import(
"resource://services-common/utils.js"
);
@ -56,7 +54,7 @@ const DEPRECATED_KEY_SCOPES = [DEPRECATED_SCOPE_ECOSYSTEM_TELEMETRY];
* possible. We intend to remove support for Firefox ever directly handling `kB`
* at some point in the future.
*/
class FxAccountsKeys {
export class FxAccountsKeys {
constructor(fxAccountsInternal) {
this._fxai = fxAccountsInternal;
}
@ -749,5 +747,3 @@ class FxAccountsKeys {
return CryptoUtils.digestBytes(bytes, hasher);
}
}
var EXPORTED_SYMBOLS = ["FxAccountsKeys"];

View File

@ -2,8 +2,6 @@
// 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/.
"use strict";
const {
log,
PREF_REMOTE_PAIRING_URI,
@ -17,9 +15,8 @@ const { getFxAccountsSingleton, FxAccounts } = ChromeUtils.import(
"resource://gre/modules/FxAccounts.jsm"
);
const fxAccounts = getFxAccountsSingleton();
const { setTimeout, clearTimeout } = ChromeUtils.importESModule(
"resource://gre/modules/Timer.sys.mjs"
);
import { setTimeout, clearTimeout } from "resource://gre/modules/Timer.sys.mjs";
ChromeUtils.import("resource://services-common/utils.js");
const lazy = {};
ChromeUtils.defineESModuleGetters(lazy, {
@ -173,7 +170,8 @@ class Errored extends State {
}
const flows = new Map();
class FxAccountsPairingFlow {
export class FxAccountsPairingFlow {
static get(channelId) {
return flows.get(channelId);
}
@ -518,5 +516,3 @@ class FxAccountsPairingFlow {
);
}
}
const EXPORTED_SYMBOLS = ["FxAccountsPairingFlow"];

View File

@ -22,15 +22,14 @@
// from Firefox browser code, hence the presence of these privileged browser APIs.
// If you're trying to use this from ordinary web content you're in for a bad time.
const {setTimeout} = ChromeUtils.importESModule("resource://gre/modules/Timer.sys.mjs");
import { setTimeout } from "resource://gre/modules/Timer.sys.mjs";
// We cannot use WebSocket from chrome code without a window,
// see https://bugzilla.mozilla.org/show_bug.cgi?id=784686
const browser = Services.appShell.createWindowlessBrowser(true);
const {WebSocket} = browser.document.ownerGlobal;
const EXPORTED_SYMBOLS = ["FxAccountsPairingChannel"];
var FxAccountsPairingChannel =
export var FxAccountsPairingChannel =
/******/ (function(modules) { // webpackBootstrap
/******/ // The module cache
/******/ var installedModules = {};
@ -704,7 +703,7 @@ async function verifyHmac(keyBytes, signature, message) {
hash: { name: 'SHA-256' },
name: 'HMAC',
}, false, ['verify']);
if (! await crypto.subtle.verify({ name: 'HMAC' }, key, signature, message)) {
if (! (await crypto.subtle.verify({ name: 'HMAC' }, key, signature, message))) {
// Yes, we really do throw 'decrypt_error' when failing to verify a HMAC,
// and a 'bad_record_mac' error when failing to decrypt.
throw new TLSError(ALERT_DESCRIPTION.DECRYPT_ERROR);

View File

@ -2,8 +2,6 @@
* 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/. */
"use strict";
/**
* Firefox Accounts Profile helper.
*
@ -12,8 +10,6 @@
* the user's profile in open browser tabs, and cacheing/invalidating profile data.
*/
var EXPORTED_SYMBOLS = ["FxAccountsProfile"];
const { ON_PROFILE_CHANGE_NOTIFICATION, log } = ChromeUtils.import(
"resource://gre/modules/FxAccountsCommon.js"
);
@ -30,7 +26,7 @@ ChromeUtils.defineModuleGetter(
"resource://gre/modules/FxAccountsProfileClient.jsm"
);
var FxAccountsProfile = function(options = {}) {
export var FxAccountsProfile = function(options = {}) {
this._currentFetchPromise = null;
this._cachedAt = 0; // when we saved the cached version.
this._isNotifying = false; // are we sending a notification?

View File

@ -7,11 +7,6 @@
*/
"use strict;";
var EXPORTED_SYMBOLS = [
"FxAccountsProfileClient",
"FxAccountsProfileClientError",
];
const {
ERRNO_NETWORK,
ERRNO_PARSE,
@ -44,7 +39,7 @@ const { RESTRequest } = ChromeUtils.import(
* The bearer token to access the profile server
* @constructor
*/
var FxAccountsProfileClient = function(options) {
export var FxAccountsProfileClient = function(options) {
if (!options || !options.serverURL) {
throw new Error("Missing 'serverURL' configuration option");
}
@ -244,7 +239,7 @@ FxAccountsProfileClient.prototype = {
* Error message
* @constructor
*/
var FxAccountsProfileClientError = function(details) {
export var FxAccountsProfileClientError = function(details) {
details = details || {};
this.name = "FxAccountsProfileClientError";

View File

@ -26,7 +26,7 @@ const {
* Object, custom options that used for testing
* @constructor
*/
function FxAccountsPushService(options = {}) {
export function FxAccountsPushService(options = {}) {
this.log = log;
if (options.log) {
@ -312,5 +312,3 @@ FxAccountsPushService.prototype = {
});
},
};
var EXPORTED_SYMBOLS = ["FxAccountsPushService"];

View File

@ -1,14 +1,6 @@
/* 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/. */
"use strict";
var EXPORTED_SYMBOLS = [
"FxAccountsStorageManagerCanStoreField",
"FxAccountsStorageManager",
// Exported for tests.
"LoginManagerStorage",
];
const {
DATA_FORMAT_VERSION,
@ -22,7 +14,7 @@ const {
// A helper function so code can check what fields are able to be stored by
// the storage manager without having a reference to a manager instance.
function FxAccountsStorageManagerCanStoreField(fieldName) {
export function FxAccountsStorageManagerCanStoreField(fieldName) {
return (
FXA_PWDMGR_PLAINTEXT_FIELDS.has(fieldName) ||
FXA_PWDMGR_SECURE_FIELDS.has(fieldName)
@ -30,7 +22,7 @@ function FxAccountsStorageManagerCanStoreField(fieldName) {
}
// The storage manager object.
var FxAccountsStorageManager = function(options = {}) {
export var FxAccountsStorageManager = function(options = {}) {
this.options = {
filename: options.filename || DEFAULT_STORAGE_FILENAME,
baseDir: options.baseDir || Services.dirsvc.get("ProfD", Ci.nsIFile).path,
@ -475,6 +467,7 @@ JSONStorage.prototype = {
};
function StorageLockedError() {}
/**
* LoginManagerStorage constructor that creates instances that set/get
* data stored securely in the nsILoginManager.
@ -482,7 +475,7 @@ function StorageLockedError() {}
* @return instance
*/
function LoginManagerStorage() {}
export function LoginManagerStorage() {}
LoginManagerStorage.prototype = {
STORAGE_LOCKED: StorageLockedError,

View File

@ -2,16 +2,12 @@
* 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/. */
"use strict";
// FxA Telemetry support. For hysterical raisins, the actual implementation
// is inside "sync". We should move the core implementation somewhere that's
// sanely shared (eg, services-common?), but let's wait and see where we end up
// first...
const { XPCOMUtils } = ChromeUtils.importESModule(
"resource://gre/modules/XPCOMUtils.sys.mjs"
);
import { XPCOMUtils } from "resource://gre/modules/XPCOMUtils.sys.mjs";
const lazy = {};
@ -34,7 +30,7 @@ XPCOMUtils.defineLazyPreferenceGetter(
""
);
class FxAccountsTelemetry {
export class FxAccountsTelemetry {
constructor(fxai) {
this._fxai = fxai;
Services.telemetry.setEventRecordingEnabled("fxa", true);
@ -176,5 +172,3 @@ class FxAccountsTelemetry {
}
}
}
var EXPORTED_SYMBOLS = ["FxAccountsTelemetry"];

View File

@ -1,7 +1,6 @@
/* 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/. */
"use strict";
/**
* Firefox Accounts Web Channel.
@ -10,16 +9,8 @@
* about account state changes.
*/
var EXPORTED_SYMBOLS = [
"EnsureFxAccountsWebChannel",
// These are exported for tests.
"FxAccountsWebChannel",
"FxAccountsWebChannelHelpers",
];
import { XPCOMUtils } from "resource://gre/modules/XPCOMUtils.sys.mjs";
const { XPCOMUtils } = ChromeUtils.importESModule(
"resource://gre/modules/XPCOMUtils.sys.mjs"
);
const {
COMMAND_PROFILE_CHANGE,
COMMAND_LOGIN,
@ -141,7 +132,7 @@ function getErrorDetails(error) {
* Helpers functions. Should only be passed in for testing.
* @constructor
*/
function FxAccountsWebChannel(options) {
export function FxAccountsWebChannel(options) {
if (!options) {
throw new Error("Missing configuration options");
}
@ -406,7 +397,7 @@ FxAccountsWebChannel.prototype = {
},
};
function FxAccountsWebChannelHelpers(options) {
export function FxAccountsWebChannelHelpers(options) {
options = options || {};
this._fxAccounts = options.fxAccounts || lazy.fxAccounts;
@ -743,12 +734,13 @@ FxAccountsWebChannelHelpers.prototype = {
};
var singleton;
// The entry-point for this module, which ensures only one of our channels is
// ever created - we require this because the WebChannel is global in scope
// (eg, it uses the observer service to tell interested parties of interesting
// things) and allowing multiple channels would cause such notifications to be
// sent multiple times.
var EnsureFxAccountsWebChannel = () => {
export var EnsureFxAccountsWebChannel = () => {
let contentUri = Services.urlFormatter.formatURLPref(
"identity.fxaccounts.remote.root"
);

View File

@ -8,7 +8,7 @@ Classes = [
{
'cid': '{1b7db999-2ecd-4abf-bb95-a726896798ca}',
'contract_ids': ['@mozilla.org/fxaccounts/push;1'],
'jsm': 'resource://gre/modules/FxAccountsPush.jsm',
'esModule': 'resource://gre/modules/FxAccountsPush.sys.mjs',
'constructor': 'FxAccountsPushService',
'processes': ProcessSelector.MAIN_PROCESS_ONLY,
'categories': {'push': 'chrome://fxa-device-update'},

View File

@ -14,22 +14,22 @@ BROWSER_CHROME_MANIFESTS += ["tests/browser/browser.ini"]
XPCSHELL_TESTS_MANIFESTS += ["tests/xpcshell/xpcshell.ini"]
EXTRA_JS_MODULES += [
"Credentials.jsm",
"FxAccounts.jsm",
"FxAccountsClient.jsm",
"FxAccountsCommands.js",
"Credentials.sys.mjs",
"FxAccounts.sys.mjs",
"FxAccountsClient.sys.mjs",
"FxAccountsCommands.sys.mjs",
"FxAccountsCommon.js",
"FxAccountsConfig.jsm",
"FxAccountsDevice.jsm",
"FxAccountsKeys.jsm",
"FxAccountsPairing.jsm",
"FxAccountsPairingChannel.js",
"FxAccountsProfile.jsm",
"FxAccountsProfileClient.jsm",
"FxAccountsPush.jsm",
"FxAccountsStorage.jsm",
"FxAccountsTelemetry.jsm",
"FxAccountsWebChannel.jsm",
"FxAccountsConfig.sys.mjs",
"FxAccountsDevice.sys.mjs",
"FxAccountsKeys.sys.mjs",
"FxAccountsPairing.sys.mjs",
"FxAccountsPairingChannel.sys.mjs",
"FxAccountsProfile.sys.mjs",
"FxAccountsProfileClient.sys.mjs",
"FxAccountsPush.sys.mjs",
"FxAccountsStorage.sys.mjs",
"FxAccountsTelemetry.sys.mjs",
"FxAccountsWebChannel.sys.mjs",
]
XPCOM_MANIFESTS += [