Bug 1667455 - Part 6: Stop importing Services.jsm from chrome-priv JS code, non-top-level or multi-line cases. r=kmag,perftest-reviewers,AlexandruIonescu,sparky

Differential Revision: https://phabricator.services.mozilla.com/D150895
This commit is contained in:
Tooru Fujisawa
2022-07-11 12:41:51 +00:00
parent 48c568867c
commit eda08a4a05
52 changed files with 4 additions and 191 deletions

View File

@@ -283,10 +283,6 @@ function invokeContentTask(browser, args, task) {
*/
async function comparePIDs(browser, isRemote) {
function getProcessID() {
const { Services } = ChromeUtils.import(
"resource://gre/modules/Services.jsm"
);
return Services.appinfo.processID;
}

View File

@@ -52,10 +52,6 @@ function getFocusedElementForBrowser(browser, dontCheckExtraFocus = false) {
browser,
[dontCheckExtraFocus],
dontCheckExtraFocusChild => {
const { Services } = ChromeUtils.import(
"resource://gre/modules/Services.jsm"
);
let focusedWindow = {};
let node = Services.focus.getFocusedElementForWindow(
content,

View File

@@ -8,10 +8,6 @@
// This is loaded into chrome windows with the subscript loader. Wrap in
// a block to prevent accidentally leaking globals onto `window`.
{
const { Services } = ChromeUtils.import(
"resource://gre/modules/Services.jsm"
);
class ScreenshotsButtons extends MozXULElement {
static get markup() {
return `

View File

@@ -10,10 +10,6 @@
// Wrap in a block to prevent leaking to window scope.
(() => {
const { Services } = ChromeUtils.import(
"resource://gre/modules/Services.jsm"
);
function sendMessageToBrowser(msgName, data) {
let { AutoCompleteParent } = ChromeUtils.import(
"resource://gre/actors/AutoCompleteParent.jsm"

View File

@@ -73,10 +73,6 @@ add_task(async function runTest() {
addBreakpoint, assertPausedAtSourceAndLine, stepIn, findSource,
removeBreakpoint, resume, selectSource, assertNotPaused, assertBreakpoint,
assertTextContentOnLine */
const { Services } = ChromeUtils.import(
"resource://gre/modules/Services.jsm"
);
Services.prefs.clearUserPref("devtools.debugger.tabs");
Services.prefs.clearUserPref("devtools.debugger.pending-selected-location");

View File

@@ -79,10 +79,6 @@ add_task(async () => {
}
function processScript() {
// eslint-disable-next-line no-shadow
const { Services } = ChromeUtils.import(
"resource://gre/modules/Services.jsm"
);
const listener = function() {
/* global sendAsyncMessage */
Services.obs.removeObserver(listener, "devtools:loader:destroy");

View File

@@ -30,9 +30,6 @@ function checkBaseProcessCount(description) {
}
function processScript() {
const { Services } = ChromeUtils.import(
"resource://gre/modules/Services.jsm"
);
if (Services.cpmm !== this) {
dump("Test failed: wrong global object\n");
return;

View File

@@ -1,8 +1,4 @@
function frameScript() {
const { Services } = ChromeUtils.import(
"resource://gre/modules/Services.jsm"
);
function eventHandler(e) {
if (!docShell) {
sendAsyncMessage("Test:Fail", "docShell is null");

View File

@@ -1,8 +1,4 @@
add_task(async function() {
const { Services } = ChromeUtils.import(
"resource://gre/modules/Services.jsm"
);
do_get_profile();
let existingFile = Services.dirsvc

View File

@@ -4,10 +4,6 @@
*/
function run_test() {
const { Services } = ChromeUtils.import(
"resource://gre/modules/Services.jsm"
);
const INDEXEDDB_HEAD_FILE = "xpcshell-head-parent-process.js";
const INDEXEDDB_PREF_EXPERIMENTAL = "dom.indexedDB.experimental";

View File

@@ -29,9 +29,6 @@ let processActorOptions = {
};
function promiseNotification(aNotification) {
const { Services } = ChromeUtils.import(
"resource://gre/modules/Services.jsm"
);
let notificationResolve;
let notificationObserver = function observer() {
notificationResolve();

View File

@@ -57,10 +57,6 @@ async function waitForGCEnd() {
}
function getProcessID() {
const { Services } = ChromeUtils.import(
"resource://gre/modules/Services.jsm"
);
return Services.appinfo.processID;
}

View File

@@ -44,10 +44,6 @@ add_task(async function test() {
// Inject a frame script in the child process:
page.loadFrameScript(async function() {
const { Services } = ChromeUtils.import(
"resource://gre/modules/Services.jsm"
);
var chromeEventHandler = docShell.chromeEventHandler;
sendAsyncMessage("chromeEventHandler", {
processType: Services.appinfo.processType,

View File

@@ -569,9 +569,6 @@ async function waitUntilApzStable() {
/* eslint-env mozilla/frame-script */
function parentProcessFlush() {
function apzFlush() {
const { Services } = ChromeUtils.import(
"resource://gre/modules/Services.jsm"
);
var topWin = Services.wm.getMostRecentWindow("navigator:browser");
if (!topWin) {
topWin = Services.wm.getMostRecentWindow("navigator:geckoview");
@@ -701,9 +698,6 @@ function isKeyApzEnabled() {
function getSnapshot(rect) {
function parentProcessSnapshot() {
addMessageListener("snapshot", function(parentRect) {
const { Services } = ChromeUtils.import(
"resource://gre/modules/Services.jsm"
);
var topWin = Services.wm.getMostRecentWindow("navigator:browser");
if (!topWin) {
topWin = Services.wm.getMostRecentWindow("navigator:geckoview");

View File

@@ -44,9 +44,6 @@ function assertSandboxHeadless() {
function getPage() {
let filePage = undefined;
const { Services } = ChromeUtils.import(
"resource://gre/modules/Services.jsm"
);
switch (Services.appinfo.OS) {
case "WINNT":
filePage = "file:///C:/";
@@ -65,9 +62,6 @@ function getPage() {
function getSize() {
let iconSize = undefined;
const { Services } = ChromeUtils.import(
"resource://gre/modules/Services.jsm"
);
switch (Services.appinfo.OS) {
case "WINNT":
iconSize = 32;

View File

@@ -1,7 +1,6 @@
function run_test()
{
const {addDebuggerToGlobal} = ChromeUtils.import("resource://gre/modules/jsdebugger.jsm");
const {Services} = ChromeUtils.import("resource://gre/modules/Services.jsm");
Services.prefs.setBoolPref("security.allow_eval_with_system_principal", true);
registerCleanupFunction(() => {

View File

@@ -21,7 +21,6 @@ const { prefs } = Services;
const defaultPrefs = prefs.getDefaultBranch("");
const FRAME_SCRIPT_INIT = `
const { Services } = ChromeUtils.import("resource://gre/modules/Services.jsm");
var { prefs } = Services;
var defaultPrefs = prefs.getDefaultBranch("");
`;

View File

@@ -67,9 +67,6 @@ add_task(async function test_sharedMap_static_prefs() {
/* eslint-disable no-shadow */
let values = await contentPage.spawn([PREF1_NAME, PREF2_NAME], prefs => {
const { Services } = ChromeUtils.import(
"resource://gre/modules/Services.jsm"
);
return prefs.map(pref => Services.prefs.getBoolPref(pref));
});
/* eslint-enable no-shadow */

View File

@@ -6,9 +6,6 @@ async function cleanupData() {
const chromeScript = SpecialPowers.loadChromeScript(_ => {
// eslint-disable-next-line no-undef
addMessageListener("go", __ => {
const { Services } = ChromeUtils.import(
"resource://gre/modules/Services.jsm"
);
Services.clearData.deleteData(
Services.clearData.CLEAR_COOKIES |
Services.clearData.CLEAR_ALL_CACHES |

View File

@@ -37,9 +37,6 @@ function resolveURI(uri) {
function remoteResolveURI(uri) {
return SpecialPowers.spawn(gBrowser.selectedBrowser, [uri], uriToResolve => {
const { Services } = ChromeUtils.import(
"resource://gre/modules/Services.jsm"
);
let resProtocol = Cc[
"@mozilla.org/network/protocol;1?name=resource"
].getService(Ci.nsIResProtocolHandler);

View File

@@ -6,9 +6,6 @@
function test() {
waitForExplicitFinish();
const { Services } = ChromeUtils.import(
"resource://gre/modules/Services.jsm"
);
// Types of processes to test, taken from GeckoProcessTypes.h
// GPU process might not run depending on the platform, so we need it to be

View File

@@ -20,9 +20,6 @@ updateAppInfo({
});
function addResourceAlias() {
const { Services } = ChromeUtils.import(
"resource://gre/modules/Services.jsm"
);
const handler = Services.io
.getProtocolHandler("resource")
.QueryInterface(Ci.nsIResProtocolHandler);

View File

@@ -208,9 +208,6 @@ function uninstallFakePAC() {
}
function getUptakeTelemetrySnapshot(component, source) {
const { Services } = ChromeUtils.import(
"resource://gre/modules/Services.jsm"
);
const TELEMETRY_CATEGORY_ID = "uptake.remotecontent.result";
const snapshot = Services.telemetry.snapshotEvents(
Ci.nsITelemetry.DATASET_ALL_CHANNELS,

View File

@@ -56,9 +56,6 @@ function base64UrlDecode(s) {
// Register resource alias. Normally done in SyncComponents.manifest.
function addResourceAlias() {
const { Services } = ChromeUtils.import(
"resource://gre/modules/Services.jsm"
);
const resProt = Services.io
.getProtocolHandler("resource")
.QueryInterface(Ci.nsIResProtocolHandler);

View File

@@ -11,10 +11,6 @@
function ChromeTask_ChromeScript() {
"use strict";
// eslint-disable-next-line no-unused-vars
const { Services } = ChromeUtils.import(
"resource://gre/modules/Services.jsm"
);
const { Assert: AssertCls } = ChromeUtils.import(
"resource://testing-common/Assert.jsm"
);

View File

@@ -1,7 +1,4 @@
(function() {
const { Services } = ChromeUtils.import(
"resource://gre/modules/Services.jsm"
);
sendAsyncMessage("CPStartup:BrowserChildReady", {
time: Services.telemetry.msSystemNow(),
});

View File

@@ -14,10 +14,6 @@ AntiTracking.runTest(
let chromeScript = SpecialPowers.loadChromeScript(_ => {
// eslint-disable-next-line no-undef
addMessageListener("go", _ => {
const { Services } = ChromeUtils.import(
"resource://gre/modules/Services.jsm"
);
function ok(what, msg) {
// eslint-disable-next-line no-undef
sendAsyncMessage("ok", { what: !!what, msg });

View File

@@ -185,10 +185,6 @@ add_task(async function test_set_responseHeaders() {
resolveHeaderPromise = resolve;
});
{
const { Services } = ChromeUtils.import(
"resource://gre/modules/Services.jsm"
);
let ssm = Services.scriptSecurityManager;
let channel = NetUtil.newChannel({

View File

@@ -113,9 +113,6 @@ add_task(async function test_web_accessible_resources_csp() {
`http://example.com/data/file_sample.html`
);
await page.spawn(null, () => {
let { Services } = ChromeUtils.import(
"resource://gre/modules/Services.jsm"
);
this.obs = {
events: [],
observe(subject, topic, data) {

View File

@@ -8,10 +8,6 @@ var profileDir = do_get_profile();
* Removes any files that could make our tests fail.
*/
async function cleanUp() {
const { Services } = ChromeUtils.import(
"resource://gre/modules/Services.jsm"
);
let files = ["places.sqlite", "cookies.sqlite", "signons.sqlite"];
for (let i = 0; i < files.length; i++) {

View File

@@ -3,9 +3,6 @@
* You can obtain one at http://mozilla.org/MPL/2.0/. */
function run_test() {
const { Services } = ChromeUtils.import(
"resource://gre/modules/Services.jsm"
);
const { OS } = ChromeUtils.import("resource://gre/modules/osfile.jsm");
const { FileUtils } = ChromeUtils.import(
"resource://gre/modules/FileUtils.jsm"

View File

@@ -7,6 +7,9 @@
const { LoginTestUtils } = SpecialPowers.ChromeUtils.import(
"resource://testing-common/LoginTestUtils.jsm"
);
const { Services } = SpecialPowers.ChromeUtils.import(
"resource://gre/modules/Services.jsm"
);
// Setup LoginTestUtils to report assertions to the mochitest harness.
LoginTestUtils.setAssertReporter(
@@ -18,9 +21,6 @@ LoginTestUtils.setAssertReporter(
const { LoginHelper } = SpecialPowers.ChromeUtils.import(
"resource://gre/modules/LoginHelper.jsm"
);
const { Services } = SpecialPowers.ChromeUtils.import(
"resource://gre/modules/Services.jsm"
);
const {
LENGTH: GENERATED_PASSWORD_LENGTH,
@@ -731,11 +731,6 @@ function runInParent(aFunctionOrURL) {
function addLoginsInParent(...aLogins) {
let script = runInParent(function addLoginsInParentInner() {
addMessageListener("addLogins", logins => {
// eslint-disable-next-line no-shadow
const { Services } = ChromeUtils.import(
"resource://gre/modules/Services.jsm"
);
let nsLoginInfo = Components.Constructor(
"@mozilla.org/login-manager/loginInfo;1",
Ci.nsILoginInfo,
@@ -816,10 +811,6 @@ SimpleTest.registerCleanupFunction(() => {
PWMGR_COMMON_PARENT.sendAsyncMessage("cleanup");
runInParent(function cleanupParent() {
// eslint-disable-next-line no-shadow
const { Services } = ChromeUtils.import(
"resource://gre/modules/Services.jsm"
);
// eslint-disable-next-line no-shadow
const { LoginManagerParent } = ChromeUtils.import(
"resource://gre/modules/LoginManagerParent.jsm"

View File

@@ -66,7 +66,6 @@ function onLoad() {
}
} catch (e) {}
let { Services } = ChromeUtils.import("resource://gre/modules/Services.jsm");
Services.obs.notifyObservers(window, "select-dialog-loaded");
}

View File

@@ -246,10 +246,6 @@ var chromeScript;
function runTests(flag, prefs, trackingResource) {
chromeScript = SpecialPowers.loadChromeScript(_ => {
const { Services } = ChromeUtils.import(
"resource://gre/modules/Services.jsm"
);
function onExamResp(subject, topic, data) {
let channel = subject.QueryInterface(Ci.nsIHttpChannel);
let classifiedChannel = subject.QueryInterface(Ci.nsIClassifiedChannel);

View File

@@ -21,9 +21,6 @@
const MozElements = {};
window.MozElements = MozElements;
const { Services } = ChromeUtils.import(
"resource://gre/modules/Services.jsm"
);
const { AppConstants } = ChromeUtils.import(
"resource://gre/modules/AppConstants.jsm"
);

View File

@@ -10,10 +10,6 @@ const Preferences = (window.Preferences = (function() {
const { EventEmitter } = ChromeUtils.import(
"resource://gre/modules/EventEmitter.jsm"
);
const { Services } = ChromeUtils.import(
"resource://gre/modules/Services.jsm"
);
ChromeUtils.import("resource://gre/modules/XPCOMUtils.jsm");
const lazy = {};
ChromeUtils.defineModuleGetter(

View File

@@ -7,10 +7,6 @@
// This is loaded into all XUL windows. Wrap in a block to prevent
// leaking to window scope.
{
const { Services } = ChromeUtils.import(
"resource://gre/modules/Services.jsm"
);
class MozArrowScrollbox extends MozElements.BaseControl {
static get inheritedAttributes() {
return {

View File

@@ -7,10 +7,6 @@
// This is loaded into all XUL windows. Wrap in a block to prevent
// leaking to window scope.
{
const { Services } = ChromeUtils.import(
"resource://gre/modules/Services.jsm"
);
MozElements.MozAutocompleteRichlistitem = class MozAutocompleteRichlistitem extends MozElements.MozRichlistitem {
constructor() {
super();

View File

@@ -7,9 +7,6 @@
// This is loaded into all XUL windows. Wrap in a block to prevent
// leaking to window scope.
{
const { Services } = ChromeUtils.import(
"resource://gre/modules/Services.jsm"
);
const { AppConstants } = ChromeUtils.import(
"resource://gre/modules/AppConstants.jsm"
);

View File

@@ -7,9 +7,6 @@
// This is loaded into all XUL windows. Wrap in a block to prevent
// leaking to window scope.
{
const { Services } = ChromeUtils.import(
"resource://gre/modules/Services.jsm"
);
const { AppConstants } = ChromeUtils.import(
"resource://gre/modules/AppConstants.jsm"
);

View File

@@ -7,9 +7,6 @@
// This is loaded into chrome windows with the subscript loader. Wrap in
// a block to prevent accidentally leaking globals onto `window`.
{
const { Services } = ChromeUtils.import(
"resource://gre/modules/Services.jsm"
);
const { AppConstants } = ChromeUtils.import(
"resource://gre/modules/AppConstants.jsm"
);

View File

@@ -10,9 +10,6 @@
const { AppConstants } = ChromeUtils.import(
"resource://gre/modules/AppConstants.jsm"
);
const { Services } = ChromeUtils.import(
"resource://gre/modules/Services.jsm"
);
// For the Windows 10 custom context menu styling, we need to know if we need
// a gutter for checkboxes. To do this, check whether there are any

View File

@@ -7,10 +7,6 @@
// This is loaded into chrome windows with the subscript loader. If you need to
// define globals, wrap in a block to prevent leaking onto `window`.
{
const { Services } = ChromeUtils.import(
"resource://gre/modules/Services.jsm"
);
MozElements.NotificationBox = class NotificationBox {
/**
* Creates a new class to handle a notification box, but does not add any

View File

@@ -7,10 +7,6 @@
// This is loaded into chrome windows with the subscript loader. Wrap in
// a block to prevent accidentally leaking globals onto `window`.
{
const { Services } = ChromeUtils.import(
"resource://gre/modules/Services.jsm"
);
class MozStringbundle extends MozXULElement {
get stringBundle() {
if (!this._bundle) {

View File

@@ -7,9 +7,6 @@
// This is loaded into chrome windows with the subscript loader. Wrap in
// a block to prevent accidentally leaking globals onto `window`.
{
const { Services } = ChromeUtils.import(
"resource://gre/modules/Services.jsm"
);
const { AppConstants } = ChromeUtils.import(
"resource://gre/modules/AppConstants.jsm"
);

View File

@@ -7,9 +7,6 @@
// This is loaded into all XUL windows. Wrap in a block to prevent
// leaking to window scope.
{
const { Services } = ChromeUtils.import(
"resource://gre/modules/Services.jsm"
);
const MozXULTextElement = MozElements.MozElementMixin(XULTextElement);
let gInsertSeparator = false;

View File

@@ -10,9 +10,6 @@
const { AppConstants } = ChromeUtils.import(
"resource://gre/modules/AppConstants.jsm"
);
const { Services } = ChromeUtils.import(
"resource://gre/modules/Services.jsm"
);
const XUL_NS =
"http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul";

View File

@@ -11,9 +11,6 @@ function setup_crash() {
const { AsyncShutdown } = ChromeUtils.import(
"resource://gre/modules/AsyncShutdown.jsm"
);
const { Services } = ChromeUtils.import(
"resource://gre/modules/Services.jsm"
);
const { PromiseUtils } = ChromeUtils.import(
"resource://gre/modules/PromiseUtils.jsm"
);
@@ -48,9 +45,6 @@ function after_crash(mdump, extra) {
// the latest operation succeeded
function setup_osfile_crash_noerror() {
const { Services } = ChromeUtils.import(
"resource://gre/modules/Services.jsm"
);
const { OS } = ChromeUtils.import("resource://gre/modules/osfile.jsm");
const { PromiseUtils } = ChromeUtils.import(
"resource://gre/modules/PromiseUtils.jsm"
@@ -88,9 +82,6 @@ function after_osfile_crash_noerror(mdump, extra) {
// the latest operation failed
function setup_osfile_crash_exn() {
const { Services } = ChromeUtils.import(
"resource://gre/modules/Services.jsm"
);
const { OS } = ChromeUtils.import("resource://gre/modules/osfile.jsm");
const { PromiseUtils } = ChromeUtils.import(
"resource://gre/modules/PromiseUtils.jsm"

View File

@@ -6,10 +6,6 @@
// Test that the Shutdown Terminator report errors correctly
function setup_crash() {
const { Services } = ChromeUtils.import(
"resource://gre/modules/Services.jsm"
);
Services.prefs.setBoolPref("toolkit.terminator.testing", true);
Services.prefs.setIntPref("toolkit.asyncshutdown.crash_timeout", 150);

View File

@@ -63,8 +63,6 @@ const ADDONS = [
},
"bootstrap.js": `
/* exported startup, shutdown */
ChromeUtils.import("resource://gre/modules/Services.jsm");
function startup(data, reason) {
Services.prefs.setIntPref("bootstraptest.active_version", 1);
}

View File

@@ -63,7 +63,7 @@ skip-if = appname != "firefox" || (os == "win" && processor == "aarch64") # bug
[test_loadManifest_isPrivileged.js]
[test_locale.js]
[test_moved_extension_metadata.js]
skip-if = true
skip-if = true # bug 1777900
[test_no_addons.js]
[test_nodisable_hidden.js]
[test_onPropertyChanged_appDisabled.js]

View File

@@ -1,10 +1,6 @@
"use strict";
(function() {
const { Services } = ChromeUtils.import(
"resource://gre/modules/Services.jsm"
);
async function startProfiler(settings) {
let startPromise = Services.profiler.StartProfiler(
settings.entries,