Bug 1820878 - Convert toolkit/mozapps/downloads to ESmodules . r=Standard8,extension-reviewers,application-update-reviewers,bytesized,robwu

Differential Revision: https://phabricator.services.mozilla.com/D172245
This commit is contained in:
Abhishek Tiwari 2023-04-12 17:32:30 +00:00
parent 01a9df7e5c
commit a0830c7eed
29 changed files with 62 additions and 115 deletions

View File

@ -13,13 +13,10 @@ var { XPCOMUtils } = ChromeUtils.importESModule(
ChromeUtils.defineESModuleGetters(this, {
AppUpdater: "resource://gre/modules/AppUpdater.sys.mjs",
DownloadUtils: "resource://gre/modules/DownloadUtils.sys.mjs",
UpdateUtils: "resource://gre/modules/UpdateUtils.sys.mjs",
});
XPCOMUtils.defineLazyModuleGetters(this, {
DownloadUtils: "resource://gre/modules/DownloadUtils.jsm",
});
XPCOMUtils.defineLazyServiceGetter(
this,
"AUS",

View File

@ -94,8 +94,8 @@ var PointerlockFsWarning = {
} else {
textElem.removeAttribute("hidden");
// Document's principal's URI has a host. Display a warning including it.
let { DownloadUtils } = ChromeUtils.import(
"resource://gre/modules/DownloadUtils.jsm"
let { DownloadUtils } = ChromeUtils.importESModule(
"resource://gre/modules/DownloadUtils.sys.mjs"
);
let displayHost = DownloadUtils.getURIHost(uri.spec)[0];
let l10nString = {

View File

@ -23,6 +23,7 @@ ChromeUtils.defineESModuleGetters(this, {
Deprecated: "resource://gre/modules/Deprecated.sys.mjs",
DevToolsSocketStatus:
"resource://devtools/shared/security/DevToolsSocketStatus.sys.mjs",
DownloadUtils: "resource://gre/modules/DownloadUtils.sys.mjs",
DownloadsCommon: "resource:///modules/DownloadsCommon.sys.mjs",
E10SUtils: "resource://gre/modules/E10SUtils.sys.mjs",
FirefoxViewNotificationManager:
@ -80,7 +81,6 @@ XPCOMUtils.defineLazyModuleGetters(this, {
BrowserWindowTracker: "resource:///modules/BrowserWindowTracker.jsm",
CFRPageActions: "resource://activity-stream/lib/CFRPageActions.jsm",
CustomizableUI: "resource:///modules/CustomizableUI.jsm",
DownloadUtils: "resource://gre/modules/DownloadUtils.jsm",
ExtensionsUI: "resource:///modules/ExtensionsUI.jsm",
HomePage: "resource:///modules/HomePage.jsm",
NetUtil: "resource://gre/modules/NetUtil.jsm",

View File

@ -6,8 +6,8 @@
const { SiteDataManager } = ChromeUtils.import(
"resource:///modules/SiteDataManager.jsm"
);
const { DownloadUtils } = ChromeUtils.import(
"resource://gre/modules/DownloadUtils.jsm"
const { DownloadUtils } = ChromeUtils.importESModule(
"resource://gre/modules/DownloadUtils.sys.mjs"
);
/* import-globals-from pageInfo.js */

View File

@ -1,11 +1,7 @@
ChromeUtils.defineESModuleGetters(this, {
DownloadUtils: "resource://gre/modules/DownloadUtils.sys.mjs",
SiteDataTestUtils: "resource://testing-common/SiteDataTestUtils.sys.mjs",
});
ChromeUtils.defineModuleGetter(
this,
"DownloadUtils",
"resource://gre/modules/DownloadUtils.jsm"
);
const TEST_ORIGIN = "https://example.com";
// eslint-disable-next-line @microsoft/sdl/no-insecure-url

View File

@ -32,6 +32,7 @@ const lazy = {};
ChromeUtils.defineESModuleGetters(lazy, {
DownloadHistory: "resource://gre/modules/DownloadHistory.sys.mjs",
DownloadUtils: "resource://gre/modules/DownloadUtils.sys.mjs",
Downloads: "resource://gre/modules/Downloads.sys.mjs",
PlacesUtils: "resource://gre/modules/PlacesUtils.sys.mjs",
PrivateBrowsingUtils: "resource://gre/modules/PrivateBrowsingUtils.sys.mjs",
@ -40,7 +41,6 @@ ChromeUtils.defineESModuleGetters(lazy, {
XPCOMUtils.defineLazyModuleGetters(lazy, {
NetUtil: "resource://gre/modules/NetUtil.jsm",
BrowserWindowTracker: "resource:///modules/BrowserWindowTracker.jsm",
DownloadUtils: "resource://gre/modules/DownloadUtils.jsm",
});
XPCOMUtils.defineLazyServiceGetters(lazy, {

View File

@ -12,6 +12,7 @@ import { XPCOMUtils } from "resource://gre/modules/XPCOMUtils.sys.mjs";
const lazy = {};
ChromeUtils.defineESModuleGetters(lazy, {
DownloadUtils: "resource://gre/modules/DownloadUtils.sys.mjs",
Downloads: "resource://gre/modules/Downloads.sys.mjs",
DownloadsCommon: "resource:///modules/DownloadsCommon.sys.mjs",
FileUtils: "resource://gre/modules/FileUtils.sys.mjs",
@ -20,7 +21,6 @@ ChromeUtils.defineESModuleGetters(lazy, {
XPCOMUtils.defineLazyModuleGetters(lazy, {
BrowserWindowTracker: "resource:///modules/BrowserWindowTracker.jsm",
DownloadUtils: "resource://gre/modules/DownloadUtils.jsm",
});
XPCOMUtils.defineLazyServiceGetter(

View File

@ -5,8 +5,8 @@ function test_deleted_iframe(perSitePref, windowOptions = {}) {
await SpecialPowers.pushPrefEnv({
set: [[SAVE_PER_SITE_PREF, perSitePref]],
});
let { DownloadLastDir } = ChromeUtils.import(
"resource://gre/modules/DownloadLastDir.jsm"
let { DownloadLastDir } = ChromeUtils.importESModule(
"resource://gre/modules/DownloadLastDir.sys.mjs"
);
let win = await BrowserTestUtils.openNewBrowserWindow(windowOptions);

View File

@ -16,6 +16,7 @@ ChromeUtils.defineESModuleGetters(this, {
MigrationUtils: "resource:///modules/MigrationUtils.sys.mjs",
PlacesBackups: "resource://gre/modules/PlacesBackups.sys.mjs",
PrivateBrowsingUtils: "resource://gre/modules/PrivateBrowsingUtils.sys.mjs",
DownloadUtils: "resource://gre/modules/DownloadUtils.sys.mjs",
});
XPCOMUtils.defineLazyScriptGetter(
this,
@ -33,12 +34,6 @@ var { AppConstants } = ChromeUtils.importESModule(
"resource://gre/modules/AppConstants.sys.mjs"
);
ChromeUtils.defineModuleGetter(
this,
"DownloadUtils",
"resource://gre/modules/DownloadUtils.jsm"
);
const RESTORE_FILEPICKER_FILTER_EXT = "*.json;*.jsonlz4";
const HISTORY_LIBRARY_SEARCH_TELEMETRY =
"PLACES_HISTORY_LIBRARY_SEARCH_TIME_MS";

View File

@ -6,11 +6,9 @@ const { SiteDataManager } = ChromeUtils.import(
"resource:///modules/SiteDataManager.jsm"
);
ChromeUtils.defineModuleGetter(
this,
"DownloadUtils",
"resource://gre/modules/DownloadUtils.jsm"
);
ChromeUtils.defineESModuleGetters(this, {
DownloadUtils: "resource://gre/modules/DownloadUtils.sys.mjs",
});
var gClearSiteDataDialog = {
_clearSiteDataCheckbox: null,

View File

@ -14,11 +14,9 @@ ChromeUtils.defineModuleGetter(
"SiteDataManager",
"resource:///modules/SiteDataManager.jsm"
);
ChromeUtils.defineModuleGetter(
this,
"DownloadUtils",
"resource://gre/modules/DownloadUtils.jsm"
);
ChromeUtils.defineESModuleGetters(this, {
DownloadUtils: "resource://gre/modules/DownloadUtils.sys.mjs",
});
let gSiteDataSettings = {
// Array of metadata of sites. Each array element is object holding:

View File

@ -83,6 +83,7 @@ ChromeUtils.defineESModuleGetters(this, {
BrowserUtils: "resource://gre/modules/BrowserUtils.sys.mjs",
ContextualIdentityService:
"resource://gre/modules/ContextualIdentityService.sys.mjs",
DownloadUtils: "resource://gre/modules/DownloadUtils.sys.mjs",
FeatureGate: "resource://featuregates/FeatureGate.sys.mjs",
FileUtils: "resource://gre/modules/FileUtils.sys.mjs",
FirefoxRelay: "resource://gre/modules/FirefoxRelay.sys.mjs",
@ -101,7 +102,6 @@ ChromeUtils.defineESModuleGetters(this, {
});
XPCOMUtils.defineLazyModuleGetters(this, {
DownloadUtils: "resource://gre/modules/DownloadUtils.jsm",
ExtensionPreferencesManager:
"resource://gre/modules/ExtensionPreferencesManager.jsm",
ExtensionSettingsStore: "resource://gre/modules/ExtensionSettingsStore.jsm",

View File

@ -44,8 +44,8 @@ async function runTest() {
let { FileUtils } = ChromeUtils.importESModule(
"resource://gre/modules/FileUtils.sys.mjs"
);
let { DownloadLastDir } = ChromeUtils.import(
"resource://gre/modules/DownloadLastDir.jsm"
let { DownloadLastDir } = ChromeUtils.importESModule(
"resource://gre/modules/DownloadLastDir.sys.mjs"
);
let tmpDir = FileUtils.getDir("TmpD", [], true);

View File

@ -9,8 +9,8 @@ function test() {
let { FileUtils } = ChromeUtils.importESModule(
"resource://gre/modules/FileUtils.sys.mjs"
);
let { DownloadLastDir } = ChromeUtils.import(
"resource://gre/modules/DownloadLastDir.jsm"
let { DownloadLastDir } = ChromeUtils.importESModule(
"resource://gre/modules/DownloadLastDir.sys.mjs"
);
let MockFilePicker = SpecialPowers.MockFilePicker;
let launcher = {

View File

@ -9,8 +9,8 @@ function test() {
let { FileUtils } = ChromeUtils.importESModule(
"resource://gre/modules/FileUtils.sys.mjs"
);
let { DownloadLastDir } = ChromeUtils.import(
"resource://gre/modules/DownloadLastDir.jsm"
let { DownloadLastDir } = ChromeUtils.importESModule(
"resource://gre/modules/DownloadLastDir.sys.mjs"
);
let MockFilePicker = SpecialPowers.MockFilePicker;

View File

@ -13,6 +13,7 @@ const { AppConstants } = ChromeUtils.import(
const lazy = {};
ChromeUtils.defineESModuleGetters(lazy, {
DownloadLastDir: "resource://gre/modules/DownloadLastDir.sys.mjs",
FileUtils: "resource://gre/modules/FileUtils.sys.mjs",
ScreenshotsUtils: "resource:///modules/ScreenshotsUtils.sys.mjs",
});
@ -20,7 +21,6 @@ ChromeUtils.defineESModuleGetters(lazy, {
XPCOMUtils.defineLazyModuleGetters(lazy, {
Downloads: "resource://gre/modules/Downloads.jsm",
DownloadPaths: "resource://gre/modules/DownloadPaths.jsm",
DownloadLastDir: "resource://gre/modules/DownloadLastDir.jsm",
});
/**

View File

@ -5,16 +5,12 @@
"use strict";
ChromeUtils.defineESModuleGetters(this, {
DownloadLastDir: "resource://gre/modules/DownloadLastDir.sys.mjs",
DownloadPaths: "resource://gre/modules/DownloadPaths.sys.mjs",
Downloads: "resource://gre/modules/Downloads.sys.mjs",
FileUtils: "resource://gre/modules/FileUtils.sys.mjs",
});
ChromeUtils.defineModuleGetter(this, "OS", "resource://gre/modules/osfile.jsm");
ChromeUtils.defineModuleGetter(
this,
"DownloadLastDir",
"resource://gre/modules/DownloadLastDir.jsm"
);
var { EventEmitter, ignoreEvent } = ExtensionCommon;

View File

@ -14,21 +14,17 @@ const { AppConstants } = ChromeUtils.importESModule(
"resource://gre/modules/AppConstants.sys.mjs"
);
ChromeUtils.defineModuleGetter(
this,
"DownloadUtils",
"resource://gre/modules/DownloadUtils.jsm"
);
ChromeUtils.defineESModuleGetters(this, {
DownloadUtils: "resource://gre/modules/DownloadUtils.sys.mjs",
PlacesDBUtils: "resource://gre/modules/PlacesDBUtils.sys.mjs",
ProcessType: "resource://gre/modules/ProcessType.sys.mjs",
});
ChromeUtils.defineModuleGetter(
this,
"PluralForm",
"resource://gre/modules/PluralForm.jsm"
);
ChromeUtils.defineESModuleGetters(this, {
PlacesDBUtils: "resource://gre/modules/PlacesDBUtils.sys.mjs",
ProcessType: "resource://gre/modules/ProcessType.sys.mjs",
});
window.addEventListener("load", function onload(event) {
try {

View File

@ -12,6 +12,7 @@ var { XPCOMUtils } = ChromeUtils.importESModule(
ChromeUtils.defineESModuleGetters(this, {
BrowserUtils: "resource://gre/modules/BrowserUtils.sys.mjs",
Deprecated: "resource://gre/modules/Deprecated.sys.mjs",
DownloadLastDir: "resource://gre/modules/DownloadLastDir.sys.mjs",
DownloadPaths: "resource://gre/modules/DownloadPaths.sys.mjs",
Downloads: "resource://gre/modules/Downloads.sys.mjs",
FileUtils: "resource://gre/modules/FileUtils.sys.mjs",
@ -19,7 +20,6 @@ ChromeUtils.defineESModuleGetters(this, {
});
XPCOMUtils.defineLazyModuleGetters(this, {
DownloadLastDir: "resource://gre/modules/DownloadLastDir.jsm",
NetUtil: "resource://gre/modules/NetUtil.jsm",
});

View File

@ -28,11 +28,7 @@ const LAST_DIR_PREF = "browser.download.lastDir";
const SAVE_PER_SITE_PREF = LAST_DIR_PREF + ".savePerSite";
const nsIFile = Ci.nsIFile;
var EXPORTED_SYMBOLS = ["DownloadLastDir"];
const { PrivateBrowsingUtils } = ChromeUtils.importESModule(
"resource://gre/modules/PrivateBrowsingUtils.sys.mjs"
);
import { PrivateBrowsingUtils } from "resource://gre/modules/PrivateBrowsingUtils.sys.mjs";
let nonPrivateLoadContext = Cu.createLoadContext();
let privateLoadContext = Cu.createPrivateLoadContext();
@ -88,7 +84,7 @@ function isContentPrefEnabled() {
var gDownloadLastDirFile = readLastDirPref();
// aForcePrivate is only used when aWindow is null.
function DownloadLastDir(aWindow, aForcePrivate) {
export function DownloadLastDir(aWindow, aForcePrivate) {
let isPrivate = false;
if (aWindow === null) {
isPrivate = aForcePrivate || PrivateBrowsingUtils.permanentPrivateBrowsing;

View File

@ -3,10 +3,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";
var EXPORTED_SYMBOLS = ["DownloadUtils"];
/**
* This module provides the DownloadUtils object which contains useful methods
* for downloads such as displaying file sizes, transfer times, and download
@ -78,7 +74,7 @@ const l10n = new Localization(["toolkit/downloads/downloadUtils.ftl"], true);
const kCachedLastMaxSize = 10;
var gCachedLast = [];
var DownloadUtils = {
export var DownloadUtils = {
/**
* Generate a full status string for a download given its current progress,
* total size, speed, last time remaining

View File

@ -2,15 +2,10 @@
* 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 { AppConstants } = ChromeUtils.importESModule(
"resource://gre/modules/AppConstants.sys.mjs"
);
const { XPCOMUtils } = ChromeUtils.importESModule(
"resource://gre/modules/XPCOMUtils.sys.mjs"
);
const { BrowserUtils } = ChromeUtils.importESModule(
"resource://gre/modules/BrowserUtils.sys.mjs"
);
import { AppConstants } from "resource://gre/modules/AppConstants.sys.mjs";
import { XPCOMUtils } from "resource://gre/modules/XPCOMUtils.sys.mjs";
import { BrowserUtils } from "resource://gre/modules/BrowserUtils.sys.mjs";
const lazy = {};
ChromeUtils.defineESModuleGetters(lazy, {
@ -30,9 +25,8 @@ XPCOMUtils.defineLazyServiceGetter(
Ci.nsIMIMEService
);
const { Integration } = ChromeUtils.importESModule(
"resource://gre/modules/Integration.sys.mjs"
);
import { Integration } from "resource://gre/modules/Integration.sys.mjs";
Integration.downloads.defineESModuleGetter(
lazy,
"DownloadIntegration",
@ -123,25 +117,16 @@ nsUnknownContentTypeDialogProgressListener.prototype = {
const PREF_BD_USEDOWNLOADDIR = "browser.download.useDownloadDir";
const nsITimer = Ci.nsITimer;
var downloadModule = ChromeUtils.import(
"resource://gre/modules/DownloadLastDir.jsm"
);
const { DownloadPaths } = ChromeUtils.importESModule(
"resource://gre/modules/DownloadPaths.sys.mjs"
);
const { DownloadUtils } = ChromeUtils.import(
"resource://gre/modules/DownloadUtils.jsm"
);
const { Downloads } = ChromeUtils.importESModule(
"resource://gre/modules/Downloads.sys.mjs"
);
const { FileUtils } = ChromeUtils.importESModule(
"resource://gre/modules/FileUtils.sys.mjs"
);
import * as downloadModule from "resource://gre/modules/DownloadLastDir.sys.mjs";
import { DownloadPaths } from "resource://gre/modules/DownloadPaths.sys.mjs";
import { DownloadUtils } from "resource://gre/modules/DownloadUtils.sys.mjs";
import { Downloads } from "resource://gre/modules/Downloads.sys.mjs";
import { FileUtils } from "resource://gre/modules/FileUtils.sys.mjs";
/* ctor
*/
function nsUnknownContentTypeDialog() {
export function nsUnknownContentTypeDialog() {
// Initialize data properties.
this.mLauncher = null;
this.mContext = null;
@ -1356,5 +1341,3 @@ nsUnknownContentTypeDialog.prototype = {
}
},
};
var EXPORTED_SYMBOLS = ["nsUnknownContentTypeDialog"];

View File

@ -8,7 +8,7 @@ Classes = [
{
'cid': '{F68578EB-6EC2-4169-AE19-8C6243F0ABE1}',
'contract_ids': ['@mozilla.org/helperapplauncherdialog;1'],
'jsm': 'resource://gre/modules/HelperAppDlg.jsm',
'esModule': 'resource://gre/modules/HelperAppDlg.sys.mjs',
'constructor': 'nsUnknownContentTypeDialog',
},
]

View File

@ -10,9 +10,9 @@ with Files("**"):
TEST_DIRS += ["tests"]
EXTRA_JS_MODULES += [
"DownloadLastDir.jsm",
"DownloadUtils.jsm",
"HelperAppDlg.jsm",
"DownloadLastDir.sys.mjs",
"DownloadUtils.sys.mjs",
"HelperAppDlg.sys.mjs",
]
XPCOM_MANIFESTS += [

View File

@ -2,8 +2,8 @@
* 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 { DownloadUtils } = ChromeUtils.import(
"resource://gre/modules/DownloadUtils.jsm"
const { DownloadUtils } = ChromeUtils.importESModule(
"resource://gre/modules/DownloadUtils.sys.mjs"
);
const gDecimalSymbol = Number(5.4)

View File

@ -7,8 +7,8 @@
* and seconds; but continue to show only minutes when we have plenty.
*/
const { DownloadUtils } = ChromeUtils.import(
"resource://gre/modules/DownloadUtils.jsm"
const { DownloadUtils } = ChromeUtils.importESModule(
"resource://gre/modules/DownloadUtils.sys.mjs"
);
/**

View File

@ -8,8 +8,8 @@
* "last time".
*/
const { DownloadUtils } = ChromeUtils.import(
"resource://gre/modules/DownloadUtils.jsm"
const { DownloadUtils } = ChromeUtils.importESModule(
"resource://gre/modules/DownloadUtils.sys.mjs"
);
function run_test() {

View File

@ -7,8 +7,8 @@
* methods provide the same result.
*/
const { DownloadUtils } = ChromeUtils.import(
"resource://gre/modules/DownloadUtils.jsm"
const { DownloadUtils } = ChromeUtils.importESModule(
"resource://gre/modules/DownloadUtils.sys.mjs"
);
function run_test() {

View File

@ -5,13 +5,9 @@
ChromeUtils.defineESModuleGetters(this, {
AppMenuNotifications: "resource://gre/modules/AppMenuNotifications.sys.mjs",
DownloadUtils: "resource://gre/modules/DownloadUtils.sys.mjs",
UpdateListener: "resource://gre/modules/UpdateListener.sys.mjs",
});
ChromeUtils.defineModuleGetter(
this,
"DownloadUtils",
"resource://gre/modules/DownloadUtils.jsm"
);
const { XPIInstall } = ChromeUtils.import(
"resource://gre/modules/addons/XPIInstall.jsm"
);