Bug 1236229 - The showInfo API in UITour.jsm should accept JavaScript callbacks rather than callback IDs. r=MattN
authorPaolo Amadini <paolo.mozmail@amadzone.org>
Tue, 05 Jan 2016 14:04:49 +0000
changeset 320158 37795691ec97a85fdb85f2d78d9c13875c0ccbe8
parent 320157 deaf711a7bc8a8cb604666b0e4e7a91edc90018e
child 320159 6fe85dbddb0cc0b3292f28e8cbc64529c8586939
push id9143
push userahunt@mozilla.com
push dateFri, 08 Jan 2016 21:30:53 +0000
reviewersMattN
bugs1236229
milestone46.0a1
Bug 1236229 - The showInfo API in UITour.jsm should accept JavaScript callbacks rather than callback IDs. r=MattN
browser/base/content/browser-trackingprotection.js
browser/components/uitour/UITour.jsm
browser/modules/ReaderParent.jsm
--- a/browser/base/content/browser-trackingprotection.js
+++ b/browser/base/content/browser-trackingprotection.js
@@ -179,17 +179,16 @@ var TrackingProtection = {
 
     // Hide the control center.
     document.getElementById("identity-popup").hidePopup();
 
     BrowserReload();
   },
 
   showIntroPanel: Task.async(function*() {
-    let mm = gBrowser.selectedBrowser.messageManager;
     let brandBundle = document.getElementById("bundle_brand");
     let brandShortName = brandBundle.getString("brandShortName");
 
     let openStep2 = () => {
       // When the user proceeds in the tour, adjust the counter to indicate that
       // the user doesn't need to see the intro anymore.
       gPrefService.setIntPref("privacy.trackingprotection.introCount",
                               this.MAX_INTROS);
@@ -214,15 +213,15 @@ var TrackingProtection = {
         callback: openStep2,
         label: gNavigatorBundle.getString("trackingProtection.intro.nextButton.label"),
         style: "primary",
       },
     ];
 
     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]),
                     undefined, buttons);
   }),
 };
--- a/browser/components/uitour/UITour.jsm
+++ b/browser/components/uitour/UITour.jsm
@@ -525,23 +525,28 @@ this.UITour = {
                   log.warn("showInfo: Reached limit of allowed number of buttons");
                   break;
                 }
               }
             }
           }
 
           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;
       }
 
       case "hideInfo": {
         this.hideInfo(window);
         break;
       }
@@ -1390,27 +1395,27 @@ this.UITour = {
 
     this._setAppMenuStateForAnnotation(aWindow, "highlight", false);
   },
 
   /**
    * 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();
 
       let document = aChromeWindow.document;
       let tooltip = document.getElementById("UITourTooltip");
       let tooltipTitle = document.getElementById("UITourTooltipTitle");
       let tooltipDesc = document.getElementById("UITourTooltipDescription");
       let tooltipIcon = document.getElementById("UITourTooltipIcon");
@@ -1456,36 +1461,37 @@ this.UITour = {
         tooltipButtons.appendChild(el);
       }
 
       tooltipButtons.hidden = !aButtons.length;
 
       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);
 
       let targetCallback = (event) => {
         let details = {
           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);
         }
       });
 
       tooltip.setAttribute("targetName", aAnchor.targetName);
       tooltip.hidden = false;
       let alignment = "bottomcenter topright";
       if (aAnchor.infoPanelPosition) {
--- a/browser/modules/ReaderParent.jsm
+++ b/browser/modules/ReaderParent.jsm
@@ -184,17 +184,17 @@ var ReaderParent = {
     targetPromise.then(target => {
       let browserBundle = Services.strings.createBundle("chrome://browser/locale/browser.properties");
       let icon = "chrome://browser/skin/";
       if (win.devicePixelRatio > 1) {
         icon += "reader-tour@2x.png";
       } 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);
     });
   },
 
   /**
    * Gets an article for a given URL. This method will download and parse a document.