--- a/browser/components/customizableui/content/panelUI.js
+++ b/browser/components/customizableui/content/panelUI.js
@@ -1,18 +1,16 @@
/* 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/. */
XPCOMUtils.defineLazyModuleGetter(this, "CustomizableUI",
"resource:///modules/CustomizableUI.jsm");
XPCOMUtils.defineLazyModuleGetter(this, "ScrollbarSampler",
"resource:///modules/ScrollbarSampler.jsm");
-XPCOMUtils.defineLazyModuleGetter(this, "Promise",
- "resource://gre/modules/Promise.jsm");
XPCOMUtils.defineLazyModuleGetter(this, "ShortcutUtils",
"resource://gre/modules/ShortcutUtils.jsm");
XPCOMUtils.defineLazyModuleGetter(this, "AppConstants",
"resource://gre/modules/AppConstants.jsm");
/**
* Maintains the state and dispatches events for the main menu panel.
*/
@@ -122,58 +120,56 @@ const PanelUI = {
/**
* Opens the menu panel. If the event target has a child with the
* toolbarbutton-icon attribute, the panel will be anchored on that child.
* Otherwise, the panel is anchored on the event target itself.
*
* @param aEvent the event (if any) that triggers showing the menu.
*/
show: function(aEvent) {
- let deferred = Promise.defer();
-
- this.ensureReady().then(() => {
- if (this.panel.state == "open" ||
- document.documentElement.hasAttribute("customizing")) {
- deferred.resolve();
- return;
- }
+ return new Promise(resolve => {
+ this.ensureReady().then(() => {
+ if (this.panel.state == "open" ||
+ document.documentElement.hasAttribute("customizing")) {
+ resolve();
+ return;
+ }
- let editControlPlacement = CustomizableUI.getPlacementOfWidget("edit-controls");
- if (editControlPlacement && editControlPlacement.area == CustomizableUI.AREA_PANEL) {
- updateEditUIVisibility();
- }
+ let editControlPlacement = CustomizableUI.getPlacementOfWidget("edit-controls");
+ if (editControlPlacement && editControlPlacement.area == CustomizableUI.AREA_PANEL) {
+ updateEditUIVisibility();
+ }
- let personalBookmarksPlacement = CustomizableUI.getPlacementOfWidget("personal-bookmarks");
- if (personalBookmarksPlacement &&
- personalBookmarksPlacement.area == CustomizableUI.AREA_PANEL) {
- PlacesToolbarHelper.customizeChange();
- }
+ let personalBookmarksPlacement = CustomizableUI.getPlacementOfWidget("personal-bookmarks");
+ if (personalBookmarksPlacement &&
+ personalBookmarksPlacement.area == CustomizableUI.AREA_PANEL) {
+ PlacesToolbarHelper.customizeChange();
+ }
- let anchor;
- if (!aEvent ||
- aEvent.type == "command") {
- anchor = this.menuButton;
- } else {
- anchor = aEvent.target;
- }
+ let anchor;
+ if (!aEvent ||
+ aEvent.type == "command") {
+ anchor = this.menuButton;
+ } else {
+ anchor = aEvent.target;
+ }
- this.panel.addEventListener("popupshown", function onPopupShown() {
- this.removeEventListener("popupshown", onPopupShown);
- deferred.resolve();
- });
+ this.panel.addEventListener("popupshown", function onPopupShown() {
+ this.removeEventListener("popupshown", onPopupShown);
+ resolve();
+ });
- let iconAnchor =
- document.getAnonymousElementByAttribute(anchor, "class",
- "toolbarbutton-icon");
- this.panel.openPopup(iconAnchor || anchor);
- }, (reason) => {
- console.error("Error showing the PanelUI menu", reason);
+ let iconAnchor =
+ document.getAnonymousElementByAttribute(anchor, "class",
+ "toolbarbutton-icon");
+ this.panel.openPopup(iconAnchor || anchor);
+ }, (reason) => {
+ console.error("Error showing the PanelUI menu", reason);
+ });
});
-
- return deferred.promise;
},
/**
* If the menu panel is being shown, hide it.
*/
hide: function() {
if (document.documentElement.hasAttribute("customizing")) {
return;
@@ -226,25 +222,25 @@ const PanelUI = {
* @return a Promise that resolves once the panel is ready to roll.
*/
ensureReady: function(aCustomizing=false) {
if (this._readyPromise) {
return this._readyPromise;
}
this._readyPromise = Task.spawn(function*() {
if (!this._initialized) {
- let delayedStartupDeferred = Promise.defer();
- let delayedStartupObserver = (aSubject, aTopic, aData) => {
- if (aSubject == window) {
- Services.obs.removeObserver(delayedStartupObserver, "browser-delayed-startup-finished");
- delayedStartupDeferred.resolve();
- }
- };
- Services.obs.addObserver(delayedStartupObserver, "browser-delayed-startup-finished", false);
- yield delayedStartupDeferred.promise;
+ yield new Promise(resolve => {
+ let delayedStartupObserver = (aSubject, aTopic, aData) => {
+ if (aSubject == window) {
+ Services.obs.removeObserver(delayedStartupObserver, "browser-delayed-startup-finished");
+ resolve();
+ }
+ };
+ Services.obs.addObserver(delayedStartupObserver, "browser-delayed-startup-finished", false);
+ });
}
this.contents.setAttributeNS("http://www.w3.org/XML/1998/namespace", "lang",
getLocale());
if (!this._scrollWidth) {
// In order to properly center the contents of the panel, while ensuring
// that we have enough space on either side to show a scrollbar, we have to
// do a bit of hackery. In particular, we calculate a new width for the