Bug 1236229 - The showInfo API in UITour.jsm should accept JavaScript callbacks rather than callback IDs. r=MattN

This commit is contained in:
Paolo Amadini 2016-01-05 14:04:49 +00:00
parent deb85627fc
commit af796680a8
3 changed files with 23 additions and 18 deletions

View File

@ -184,7 +184,6 @@ var TrackingProtection = {
},
showIntroPanel: Task.async(function*() {
let mm = gBrowser.selectedBrowser.messageManager;
let brandBundle = document.getElementById("bundle_brand");
let brandShortName = brandBundle.getString("brandShortName");
@ -219,7 +218,7 @@ var TrackingProtection = {
let panelTarget = yield UITour.getTarget(window, "trackingProtection");
UITour.initForBrowser(gBrowser.selectedBrowser, window);
UITour.showInfo(window, mm, panelTarget,
UITour.showInfo(window, panelTarget,
gNavigatorBundle.getString("trackingProtection.intro.title"),
gNavigatorBundle.getFormattedString("trackingProtection.intro.description",
[brandShortName]),

View File

@ -530,13 +530,18 @@ this.UITour = {
}
let infoOptions = {};
if (typeof data.closeButtonCallbackID == "string") {
infoOptions.closeButtonCallback = () => {
this.sendPageCallback(messageManager, data.closeButtonCallbackID);
};
}
if (typeof data.targetCallbackID == "string") {
infoOptions.targetCallback = details => {
this.sendPageCallback(messageManager, data.targetCallbackID, details);
};
}
if (typeof data.closeButtonCallbackID == "string")
infoOptions.closeButtonCallbackID = data.closeButtonCallbackID;
if (typeof data.targetCallbackID == "string")
infoOptions.targetCallbackID = data.targetCallbackID;
this.showInfo(window, messageManager, target, data.title, data.text, iconURL, buttons, infoOptions);
this.showInfo(window, target, data.title, data.text, iconURL, buttons, infoOptions);
}).catch(log.error);
break;
}
@ -1395,17 +1400,17 @@ this.UITour = {
* Show an info panel.
*
* @param {ChromeWindow} aChromeWindow
* @param {nsIMessageSender} aMessageManager
* @param {Node} aAnchor
* @param {String} [aTitle=""]
* @param {String} [aDescription=""]
* @param {String} [aIconURL=""]
* @param {Object[]} [aButtons=[]]
* @param {Object} [aOptions={}]
* @param {String} [aOptions.closeButtonCallbackID]
* @param {String} [aOptions.closeButtonCallback]
* @param {String} [aOptions.targetCallback]
*/
showInfo: function(aChromeWindow, aMessageManager, aAnchor, aTitle = "", aDescription = "", aIconURL = "",
aButtons = [], aOptions = {}) {
showInfo(aChromeWindow, aAnchor, aTitle = "", aDescription = "",
aIconURL = "", aButtons = [], aOptions = {}) {
function showInfoPanel(aAnchorEl) {
aAnchorEl.focus();
@ -1461,8 +1466,9 @@ this.UITour = {
let tooltipClose = document.getElementById("UITourTooltipClose");
let closeButtonCallback = (event) => {
this.hideInfo(document.defaultView);
if (aOptions && aOptions.closeButtonCallbackID)
this.sendPageCallback(aMessageManager, aOptions.closeButtonCallbackID);
if (aOptions && aOptions.closeButtonCallback) {
aOptions.closeButtonCallback();
}
};
tooltipClose.addEventListener("command", closeButtonCallback);
@ -1471,16 +1477,16 @@ this.UITour = {
target: aAnchor.targetName,
type: event.type,
};
this.sendPageCallback(aMessageManager, aOptions.targetCallbackID, details);
aOptions.targetCallback(details);
};
if (aOptions.targetCallbackID && aAnchor.addTargetListener) {
if (aOptions.targetCallback && aAnchor.addTargetListener) {
aAnchor.addTargetListener(document, targetCallback);
}
tooltip.addEventListener("popuphiding", function tooltipHiding(event) {
tooltip.removeEventListener("popuphiding", tooltipHiding);
tooltipClose.removeEventListener("command", closeButtonCallback);
if (aOptions.targetCallbackID && aAnchor.removeTargetListener) {
if (aOptions.targetCallback && aAnchor.removeTargetListener) {
aAnchor.removeTargetListener(document, targetCallback);
}
});

View File

@ -189,7 +189,7 @@ var ReaderParent = {
} else {
icon += "reader-tour.png";
}
UITour.showInfo(win, browser.messageManager, target,
UITour.showInfo(win, target,
browserBundle.GetStringFromName("readingList.promo.firstUse.readerView.title"),
browserBundle.GetStringFromName("readingList.promo.firstUse.readerView.body"),
icon);