Skip to content

Commit 9dd38d0

Browse files
committed
Bug 1830418 - Convert browser/components/customizableui/CustomizableUI.jsm to ESM r=Standard8,devtools-reviewers,nchevobbe
Differential Revision: https://phabricator.services.mozilla.com/D177423
1 parent cd1850f commit 9dd38d0

39 files changed

+95
-149
lines changed

browser/base/content/browser.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ ChromeUtils.defineESModuleGetters(this, {
2020
Color: "resource://gre/modules/Color.sys.mjs",
2121
ContextualIdentityService:
2222
"resource://gre/modules/ContextualIdentityService.sys.mjs",
23+
CustomizableUI: "resource:///modules/CustomizableUI.sys.mjs",
2324
Deprecated: "resource://gre/modules/Deprecated.sys.mjs",
2425
DevToolsSocketStatus:
2526
"resource://devtools/shared/security/DevToolsSocketStatus.sys.mjs",
@@ -87,7 +88,6 @@ XPCOMUtils.defineLazyModuleGetters(this, {
8788
BrowserUIUtils: "resource:///modules/BrowserUIUtils.jsm",
8889
BrowserWindowTracker: "resource:///modules/BrowserWindowTracker.jsm",
8990
CFRPageActions: "resource://activity-stream/lib/CFRPageActions.jsm",
90-
CustomizableUI: "resource:///modules/CustomizableUI.jsm",
9191
ExtensionsUI: "resource:///modules/ExtensionsUI.jsm",
9292
HomePage: "resource:///modules/HomePage.jsm",
9393
NetUtil: "resource://gre/modules/NetUtil.jsm",

browser/base/content/test/general/browser_newWindowDrop.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ add_task(async function test_setup() {
1919
);
2020

2121
// Move New Window button to nav bar, to make it possible to drag and drop.
22-
let { CustomizableUI } = ChromeUtils.import(
23-
"resource:///modules/CustomizableUI.jsm"
22+
let { CustomizableUI } = ChromeUtils.importESModule(
23+
"resource:///modules/CustomizableUI.sys.mjs"
2424
);
2525
let origPlacement = CustomizableUI.getPlacementOfWidget("new-window-button");
2626
if (!origPlacement || origPlacement.area != CustomizableUI.AREA_NAVBAR) {

browser/base/content/test/sidebar/browser_sidebar_keys.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ add_task(async function test_sidebar_in_customize_mode() {
2727
// Test bug 1756385 - widgets to appear unchecked in customize mode. Test that
2828
// the sidebar button widget doesn't appear checked, and that the sidebar
2929
// button toggle is inert while in customize mode.
30-
let { CustomizableUI } = ChromeUtils.import(
31-
"resource:///modules/CustomizableUI.jsm"
30+
let { CustomizableUI } = ChromeUtils.importESModule(
31+
"resource:///modules/CustomizableUI.sys.mjs"
3232
);
3333
registerCleanupFunction(() => SidebarUI.hide());
3434

browser/components/BrowserGlue.sys.mjs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3998,8 +3998,8 @@ BrowserGlue.prototype = {
39983998
// In Firefox 83, we moved to a dynamic button, so it needs to be removed
39993999
// from default placement. This is done early enough that it doesn't
40004000
// impact adding new managed bookmarks.
4001-
const { CustomizableUI } = ChromeUtils.import(
4002-
"resource:///modules/CustomizableUI.jsm"
4001+
const { CustomizableUI } = ChromeUtils.importESModule(
4002+
"resource:///modules/CustomizableUI.sys.mjs"
40034003
);
40044004
CustomizableUI.removeWidgetFromArea("managed-bookmarks");
40054005
}

browser/components/customizableui/CustomizableUI.jsm renamed to browser/components/customizableui/CustomizableUI.sys.mjs

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,17 @@
11
/* This Source Code Form is subject to the terms of the Mozilla Public
22
* License, v. 2.0. If a copy of the MPL was not distributed with this
33
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
4-
"use strict";
54

6-
var EXPORTED_SYMBOLS = ["CustomizableUI"];
7-
8-
const { XPCOMUtils } = ChromeUtils.importESModule(
9-
"resource://gre/modules/XPCOMUtils.sys.mjs"
10-
);
11-
const { AppConstants } = ChromeUtils.importESModule(
12-
"resource://gre/modules/AppConstants.sys.mjs"
13-
);
5+
import { XPCOMUtils } from "resource://gre/modules/XPCOMUtils.sys.mjs";
6+
import { AppConstants } from "resource://gre/modules/AppConstants.sys.mjs";
7+
import { SearchWidgetTracker } from "resource:///modules/SearchWidgetTracker.sys.mjs";
148

159
const lazy = {};
1610

1711
ChromeUtils.defineESModuleGetters(lazy, {
1812
CustomizableWidgets: "resource:///modules/CustomizableWidgets.sys.mjs",
1913
PanelMultiView: "resource:///modules/PanelMultiView.sys.mjs",
2014
PrivateBrowsingUtils: "resource://gre/modules/PrivateBrowsingUtils.sys.mjs",
21-
SearchWidgetTracker: "resource:///modules/SearchWidgetTracker.sys.mjs",
2215
ShortcutUtils: "resource://gre/modules/ShortcutUtils.sys.mjs",
2316
});
2417

@@ -79,7 +72,7 @@ var ObsoleteBuiltinButtons = {
7972
};
8073

8174
/**
82-
* gPalette is a map of every widget that CustomizableUI.jsm knows about, keyed
75+
* gPalette is a map of every widget that CustomizableUI.sys.mjs knows about, keyed
8376
* on their IDs.
8477
*/
8578
var gPalette = new Map();
@@ -308,7 +301,7 @@ var CustomizableUIInternal = {
308301
true
309302
);
310303

311-
lazy.SearchWidgetTracker.init();
304+
SearchWidgetTracker.init();
312305

313306
Services.obs.addObserver(this, "browser-set-toolbar-visibility");
314307
},
@@ -3710,7 +3703,7 @@ var CustomizableUIInternal = {
37103703
};
37113704
Object.freeze(CustomizableUIInternal);
37123705

3713-
var CustomizableUI = {
3706+
export var CustomizableUI = {
37143707
/**
37153708
* Constant reference to the ID of the navigation toolbar.
37163709
*/
@@ -4914,6 +4907,7 @@ var CustomizableUI = {
49144907
}
49154908
},
49164909
};
4910+
49174911
Object.freeze(CustomizableUI);
49184912
Object.freeze(CustomizableUI.windows);
49194913

browser/components/customizableui/CustomizableWidgets.sys.mjs

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,14 @@
22
* License, v. 2.0. If a copy of the MPL was not distributed with this
33
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
44

5-
const { CustomizableUI } = ChromeUtils.import(
6-
"resource:///modules/CustomizableUI.jsm"
7-
);
85
import { XPCOMUtils } from "resource://gre/modules/XPCOMUtils.sys.mjs";
96
import { AppConstants } from "resource://gre/modules/AppConstants.sys.mjs";
107
import { PrivateBrowsingUtils } from "resource://gre/modules/PrivateBrowsingUtils.sys.mjs";
118

129
const lazy = {};
1310

1411
ChromeUtils.defineESModuleGetters(lazy, {
12+
CustomizableUI: "resource:///modules/CustomizableUI.sys.mjs",
1513
PanelMultiView: "resource:///modules/PanelMultiView.sys.mjs",
1614
RecentlyClosedTabsAndWindowsMenuUtils:
1715
"resource:///modules/sessionstore/RecentlyClosedTabsAndWindowsMenuUtils.sys.mjs",
@@ -73,7 +71,7 @@ function setAttributes(aNode, aAttrs) {
7371
additionalArgs.push(lazy.ShortcutUtils.prettifyShortcut(shortcut));
7472
}
7573
}
76-
value = CustomizableUI.getLocalizedProperty(
74+
value = lazy.CustomizableUI.getLocalizedProperty(
7775
{ id: aAttrs.id },
7876
stringId,
7977
additionalArgs
@@ -209,7 +207,7 @@ export const CustomizableWidgets = [
209207
let footer;
210208
while (--elementCount >= 0) {
211209
let element = body.children[elementCount];
212-
CustomizableUI.addShortcut(element);
210+
lazy.CustomizableUI.addShortcut(element);
213211
element.classList.add("subviewbutton");
214212
if (element.classList.contains("restoreallitem")) {
215213
footer = element;
@@ -320,11 +318,11 @@ export const CustomizableWidgets = [
320318
node.setAttribute("id", "zoom-controls");
321319
node.setAttribute(
322320
"label",
323-
CustomizableUI.getLocalizedProperty(this, "label")
321+
lazy.CustomizableUI.getLocalizedProperty(this, "label")
324322
);
325323
node.setAttribute(
326324
"title",
327-
CustomizableUI.getLocalizedProperty(this, "tooltiptext")
325+
lazy.CustomizableUI.getLocalizedProperty(this, "tooltiptext")
328326
);
329327
// Set this as an attribute in addition to the property to make sure we can style correctly.
330328
node.setAttribute("removable", "true");
@@ -378,11 +376,11 @@ export const CustomizableWidgets = [
378376
node.setAttribute("id", "edit-controls");
379377
node.setAttribute(
380378
"label",
381-
CustomizableUI.getLocalizedProperty(this, "label")
379+
lazy.CustomizableUI.getLocalizedProperty(this, "label")
382380
);
383381
node.setAttribute(
384382
"title",
385-
CustomizableUI.getLocalizedProperty(this, "tooltiptext")
383+
lazy.CustomizableUI.getLocalizedProperty(this, "tooltiptext")
386384
);
387385
// Set this as an attribute in addition to the property to make sure we can style correctly.
388386
node.setAttribute("removable", "true");
@@ -403,7 +401,7 @@ export const CustomizableWidgets = [
403401
if (aWidgetId != this.id || aDoc != aDocument) {
404402
return;
405403
}
406-
CustomizableUI.removeListener(listener);
404+
lazy.CustomizableUI.removeListener(listener);
407405
},
408406
onWidgetOverflow(aWidgetNode) {
409407
if (aWidgetNode == node) {
@@ -416,7 +414,7 @@ export const CustomizableWidgets = [
416414
}
417415
},
418416
};
419-
CustomizableUI.addListener(listener);
417+
lazy.CustomizableUI.addListener(listener);
420418

421419
return node;
422420
},

browser/components/customizableui/CustomizeMode.sys.mjs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,7 @@ const kDownloadAutohideCheckboxId = "downloads-button-autohide-checkbox";
1818
const kDownloadAutohidePanelId = "downloads-button-autohide-panel";
1919
const kDownloadAutoHidePref = "browser.download.autohideButton";
2020

21-
const { CustomizableUI } = ChromeUtils.import(
22-
"resource:///modules/CustomizableUI.jsm"
23-
);
21+
import { CustomizableUI } from "resource:///modules/CustomizableUI.sys.mjs";
2422
import { XPCOMUtils } from "resource://gre/modules/XPCOMUtils.sys.mjs";
2523
import { AppConstants } from "resource://gre/modules/AppConstants.sys.mjs";
2624

browser/components/customizableui/PanelMultiView.sys.mjs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -100,11 +100,9 @@
100100
import { XPCOMUtils } from "resource://gre/modules/XPCOMUtils.sys.mjs";
101101

102102
const lazy = {};
103-
ChromeUtils.defineModuleGetter(
104-
lazy,
105-
"CustomizableUI",
106-
"resource:///modules/CustomizableUI.jsm"
107-
);
103+
ChromeUtils.defineESModuleGetters(lazy, {
104+
CustomizableUI: "resource:///modules/CustomizableUI.sys.mjs",
105+
});
108106

109107
XPCOMUtils.defineLazyGetter(lazy, "gBundle", function () {
110108
return Services.strings.createBundle(

browser/components/customizableui/SearchWidgetTracker.sys.mjs

Lines changed: 13 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,10 @@
88
*/
99

1010
import { AppConstants } from "resource://gre/modules/AppConstants.sys.mjs";
11+
import { CustomizableUI } from "resource:///modules/CustomizableUI.sys.mjs";
1112

1213
const lazy = {};
1314

14-
ChromeUtils.defineModuleGetter(
15-
lazy,
16-
"CustomizableUI",
17-
"resource:///modules/CustomizableUI.jsm"
18-
);
1915
ChromeUtils.defineModuleGetter(
2016
lazy,
2117
"BrowserUsageTelemetry",
@@ -33,20 +29,20 @@ export const SearchWidgetTracker = {
3329
this.removePersistedWidths();
3430
}
3531
};
36-
lazy.CustomizableUI.addListener(this);
32+
CustomizableUI.addListener(this);
3733
Services.prefs.addObserver(PREF_NAME, () =>
3834
this.syncWidgetWithPreference()
3935
);
4036
},
4137

4238
onWidgetAdded(widgetId, area) {
43-
if (widgetId == WIDGET_ID && area == lazy.CustomizableUI.AREA_NAVBAR) {
39+
if (widgetId == WIDGET_ID && area == CustomizableUI.AREA_NAVBAR) {
4440
this.syncPreferenceWithWidget();
4541
}
4642
},
4743

4844
onWidgetRemoved(aWidgetId, aArea) {
49-
if (aWidgetId == WIDGET_ID && aArea == lazy.CustomizableUI.AREA_NAVBAR) {
45+
if (aWidgetId == WIDGET_ID && aArea == CustomizableUI.AREA_NAVBAR) {
5046
this.syncPreferenceWithWidget();
5147
this.removePersistedWidths();
5248
}
@@ -56,7 +52,7 @@ export const SearchWidgetTracker = {
5652
// The placement of the widget always takes priority, and the preference
5753
// should always match the actual placement when the browser starts up - i.e.
5854
// once the navigation bar has been registered.
59-
if (aArea == lazy.CustomizableUI.AREA_NAVBAR) {
55+
if (aArea == CustomizableUI.AREA_NAVBAR) {
6056
this.syncPreferenceWithWidget();
6157
}
6258
},
@@ -80,19 +76,18 @@ export const SearchWidgetTracker = {
8076
if (newValue) {
8177
// The URL bar widget is always present in the navigation toolbar, so we
8278
// can simply read its position to place the search bar right after it.
83-
lazy.CustomizableUI.addWidgetToArea(
79+
CustomizableUI.addWidgetToArea(
8480
WIDGET_ID,
85-
lazy.CustomizableUI.AREA_NAVBAR,
86-
lazy.CustomizableUI.getPlacementOfWidget("urlbar-container").position +
87-
1
81+
CustomizableUI.AREA_NAVBAR,
82+
CustomizableUI.getPlacementOfWidget("urlbar-container").position + 1
8883
);
8984
lazy.BrowserUsageTelemetry.recordWidgetChange(
9085
WIDGET_ID,
91-
lazy.CustomizableUI.AREA_NAVBAR,
86+
CustomizableUI.AREA_NAVBAR,
9287
"searchpref"
9388
);
9489
} else {
95-
lazy.CustomizableUI.removeWidgetFromArea(WIDGET_ID);
90+
CustomizableUI.removeWidgetFromArea(WIDGET_ID);
9691
lazy.BrowserUsageTelemetry.recordWidgetChange(
9792
WIDGET_ID,
9893
null,
@@ -107,7 +102,7 @@ export const SearchWidgetTracker = {
107102
WIDGET_ID,
108103
"width"
109104
);
110-
for (let win of lazy.CustomizableUI.windows) {
105+
for (let win of CustomizableUI.windows) {
111106
let searchbar =
112107
win.document.getElementById(WIDGET_ID) ||
113108
win.gNavToolbox.palette.querySelector("#" + WIDGET_ID);
@@ -117,7 +112,7 @@ export const SearchWidgetTracker = {
117112
},
118113

119114
get widgetIsInNavBar() {
120-
let placement = lazy.CustomizableUI.getPlacementOfWidget(WIDGET_ID);
121-
return placement?.area == lazy.CustomizableUI.AREA_NAVBAR;
115+
let placement = CustomizableUI.getPlacementOfWidget(WIDGET_ID);
116+
return placement?.area == CustomizableUI.AREA_NAVBAR;
122117
},
123118
};

browser/components/customizableui/moz.build

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ TESTING_JS_MODULES += [
1616
]
1717

1818
EXTRA_JS_MODULES += [
19-
"CustomizableUI.jsm",
19+
"CustomizableUI.sys.mjs",
2020
"CustomizableWidgets.sys.mjs",
2121
"CustomizeMode.sys.mjs",
2222
"DragPositionManager.sys.mjs",

browser/components/customizableui/test/CustomizableUITestUtils.sys.mjs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,9 @@ import { TestUtils } from "resource://testing-common/TestUtils.sys.mjs";
1313

1414
const lazy = {};
1515

16-
ChromeUtils.defineModuleGetter(
17-
lazy,
18-
"CustomizableUI",
19-
"resource:///modules/CustomizableUI.jsm"
20-
);
16+
ChromeUtils.defineESModuleGetters(lazy, {
17+
CustomizableUI: "resource:///modules/CustomizableUI.sys.mjs",
18+
});
2119

2220
export class CustomizableUITestUtils {
2321
/**

browser/components/customizableui/test/browser_panelUINotifications.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -228,8 +228,8 @@ add_task(async function testInteractionWithBadges() {
228228
await BrowserTestUtils.withNewTab("about:blank", async function (browser) {
229229
// Remove the fxa toolbar button from the navbar to ensure the notification
230230
// is displayed on the app menu button.
231-
let { CustomizableUI } = ChromeUtils.import(
232-
"resource:///modules/CustomizableUI.jsm"
231+
let { CustomizableUI } = ChromeUtils.importESModule(
232+
"resource:///modules/CustomizableUI.sys.mjs"
233233
);
234234
CustomizableUI.removeWidgetFromArea("fxa-toolbar-menu-button");
235235

browser/components/customizableui/test/head.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,11 @@
55
"use strict";
66

77
ChromeUtils.defineESModuleGetters(this, {
8+
CustomizableUI: "resource:///modules/CustomizableUI.sys.mjs",
89
CustomizableUITestUtils:
910
"resource://testing-common/CustomizableUITestUtils.sys.mjs",
1011
});
1112

12-
XPCOMUtils.defineLazyModuleGetters(this, {
13-
CustomizableUI: "resource:///modules/CustomizableUI.jsm",
14-
});
15-
1613
var EventUtils = {};
1714
Services.scriptloader.loadSubScript(
1815
"chrome://mochikit/content/tests/SimpleTest/EventUtils.js",

browser/components/customizableui/test/unit/test_unified_extensions_migration.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ http://creativecommons.org/publicdomain/zero/1.0/ */
66
// We're in an xpcshell test but have an eslint browser test env applied;
77
// We definitely do need to manually import CustomizableUI.
88
// eslint-disable-next-line mozilla/no-redeclare-with-import-autofix
9-
const { CustomizableUI } = ChromeUtils.import(
10-
"resource:///modules/CustomizableUI.jsm"
9+
const { CustomizableUI } = ChromeUtils.importESModule(
10+
"resource:///modules/CustomizableUI.sys.mjs"
1111
);
1212

1313
do_get_profile();

browser/components/enterprisepolicies/Policies.sys.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ XPCOMUtils.defineLazyServiceGetters(lazy, {
2323

2424
ChromeUtils.defineESModuleGetters(lazy, {
2525
BookmarksPolicies: "resource:///modules/policies/BookmarksPolicies.sys.mjs",
26+
CustomizableUI: "resource:///modules/CustomizableUI.sys.mjs",
2627
FileUtils: "resource://gre/modules/FileUtils.sys.mjs",
2728
PdfJsDefaultPreferences: "resource://pdf.js/PdfJsDefaultPreferences.sys.mjs",
2829
ProxyPolicies: "resource:///modules/policies/ProxyPolicies.sys.mjs",
@@ -31,7 +32,6 @@ ChromeUtils.defineESModuleGetters(lazy, {
3132

3233
XPCOMUtils.defineLazyModuleGetters(lazy, {
3334
AddonManager: "resource://gre/modules/AddonManager.jsm",
34-
CustomizableUI: "resource:///modules/CustomizableUI.jsm",
3535
});
3636

3737
const PREF_LOGLEVEL = "browser.policies.loglevel";

0 commit comments

Comments
 (0)