Bug 1260718 - use plain promise in CustomizableUI.jsm and ScrollbarSampler.jsm; r?Gijs
MozReview-Commit-ID: 25XS1MEgpe5
--- a/browser/components/customizableui/CustomizableUI.jsm
+++ b/browser/components/customizableui/CustomizableUI.jsm
@@ -14,18 +14,16 @@ Cu.import("resource://gre/modules/AppCon
XPCOMUtils.defineLazyModuleGetter(this, "PanelWideWidgetTracker",
"resource:///modules/PanelWideWidgetTracker.jsm");
XPCOMUtils.defineLazyModuleGetter(this, "CustomizableWidgets",
"resource:///modules/CustomizableWidgets.jsm");
XPCOMUtils.defineLazyModuleGetter(this, "DeferredTask",
"resource://gre/modules/DeferredTask.jsm");
XPCOMUtils.defineLazyModuleGetter(this, "PrivateBrowsingUtils",
"resource://gre/modules/PrivateBrowsingUtils.jsm");
-XPCOMUtils.defineLazyModuleGetter(this, "Promise",
- "resource://gre/modules/Promise.jsm");
XPCOMUtils.defineLazyGetter(this, "gWidgetsBundle", function() {
const kUrl = "chrome://browser/locale/customizableui/customizableWidgets.properties";
return Services.strings.createBundle(kUrl);
});
XPCOMUtils.defineLazyModuleGetter(this, "ShortcutUtils",
"resource://gre/modules/ShortcutUtils.jsm");
XPCOMUtils.defineLazyServiceGetter(this, "gELS",
"@mozilla.org/eventlistenerservice;1", "nsIEventListenerService");
@@ -4104,38 +4102,36 @@ OverflowableToolbar.prototype = {
this._onPanelHiding(aEvent);
break;
case "resize":
this._onResize(aEvent);
}
},
show: function() {
- let deferred = Promise.defer();
if (this._panel.state == "open") {
- deferred.resolve();
- return deferred.promise;
- }
- let doc = this._panel.ownerDocument;
- this._panel.hidden = false;
- let contextMenu = doc.getElementById(this._panel.getAttribute("context"));
- gELS.addSystemEventListener(contextMenu, 'command', this, true);
- let anchor = doc.getAnonymousElementByAttribute(this._chevron, "class", "toolbarbutton-icon");
- this._panel.openPopup(anchor || this._chevron);
- this._chevron.open = true;
-
- let overflowableToolbarInstance = this;
- this._panel.addEventListener("popupshown", function onPopupShown(aEvent) {
- this.removeEventListener("popupshown", onPopupShown);
- this.addEventListener("dragover", overflowableToolbarInstance);
- this.addEventListener("dragend", overflowableToolbarInstance);
- deferred.resolve();
+ return Promise.resolve();
+ }
+ return new Promise(resolve => {
+ let doc = this._panel.ownerDocument;
+ this._panel.hidden = false;
+ let contextMenu = doc.getElementById(this._panel.getAttribute("context"));
+ gELS.addSystemEventListener(contextMenu, 'command', this, true);
+ let anchor = doc.getAnonymousElementByAttribute(this._chevron, "class", "toolbarbutton-icon");
+ this._panel.openPopup(anchor || this._chevron);
+ this._chevron.open = true;
+
+ let overflowableToolbarInstance = this;
+ this._panel.addEventListener("popupshown", function onPopupShown(aEvent) {
+ this.removeEventListener("popupshown", onPopupShown);
+ this.addEventListener("dragover", overflowableToolbarInstance);
+ this.addEventListener("dragend", overflowableToolbarInstance);
+ resolve();
+ });
});
-
- return deferred.promise;
},
_onClickChevron: function(aEvent) {
if (this._chevron.open) {
this._panel.hidePopup();
this._chevron.open = false;
} else {
this.show();
--- a/browser/components/customizableui/ScrollbarSampler.jsm
+++ b/browser/components/customizableui/ScrollbarSampler.jsm
@@ -5,66 +5,61 @@
"use strict";
this.EXPORTED_SYMBOLS = ["ScrollbarSampler"];
const {classes: Cc, interfaces: Ci, utils: Cu, results: Cr} = Components;
Cu.import("resource://gre/modules/Services.jsm");
Cu.import("resource://gre/modules/XPCOMUtils.jsm");
-XPCOMUtils.defineLazyModuleGetter(this, "Promise",
- "resource://gre/modules/Promise.jsm");
var gSystemScrollbarWidth = null;
this.ScrollbarSampler = {
getSystemScrollbarWidth: function() {
- let deferred = Promise.defer();
-
if (gSystemScrollbarWidth !== null) {
- deferred.resolve(gSystemScrollbarWidth);
- return deferred.promise;
+ return Promise.resolve(gSystemScrollbarWidth);
}
- this._sampleSystemScrollbarWidth().then(function(systemScrollbarWidth) {
- gSystemScrollbarWidth = systemScrollbarWidth;
- deferred.resolve(gSystemScrollbarWidth);
+ return new Promise(resolve => {
+ this._sampleSystemScrollbarWidth().then(function(systemScrollbarWidth) {
+ gSystemScrollbarWidth = systemScrollbarWidth;
+ resolve(gSystemScrollbarWidth);
+ });
});
- return deferred.promise;
},
resetSystemScrollbarWidth: function() {
gSystemScrollbarWidth = null;
},
_sampleSystemScrollbarWidth: function() {
- let deferred = Promise.defer();
let hwin = Services.appShell.hiddenDOMWindow;
let hdoc = hwin.document.documentElement;
let iframe = hwin.document.createElementNS("http://www.w3.org/1999/xhtml",
"html:iframe");
iframe.setAttribute("srcdoc", '<body style="overflow-y: scroll"></body>');
hdoc.appendChild(iframe);
let cwindow = iframe.contentWindow;
let utils = cwindow.QueryInterface(Ci.nsIInterfaceRequestor)
.getInterface(Ci.nsIDOMWindowUtils);
- cwindow.addEventListener("load", function onLoad(aEvent) {
- cwindow.removeEventListener("load", onLoad);
- let sbWidth = {};
- try {
- utils.getScrollbarSize(true, sbWidth, {});
- } catch(e) {
- Cu.reportError("Could not sample scrollbar size: " + e + " -- " +
- e.stack);
- sbWidth.value = 0;
- }
- // Minimum width of 10 so that we have enough padding:
- sbWidth.value = Math.max(sbWidth.value, 10);
- deferred.resolve(sbWidth.value);
- iframe.remove();
+ return new Promise(resolve => {
+ cwindow.addEventListener("load", function onLoad(aEvent) {
+ cwindow.removeEventListener("load", onLoad);
+ let sbWidth = {};
+ try {
+ utils.getScrollbarSize(true, sbWidth, {});
+ } catch(e) {
+ Cu.reportError("Could not sample scrollbar size: " + e + " -- " +
+ e.stack);
+ sbWidth.value = 0;
+ }
+ // Minimum width of 10 so that we have enough padding:
+ sbWidth.value = Math.max(sbWidth.value, 10);
+ resolve(sbWidth.value);
+ iframe.remove();
+ });
});
-
- return deferred.promise;
}
};
Object.freeze(this.ScrollbarSampler);