Bug 1235902 - Support actions from links in hosted feedback page. r=mfinkle
authorMargaret Leibovic <margaret.leibovic@gmail.com>
Wed, 30 Dec 2015 16:38:10 -0500
changeset 320156 f2c54cd55ed5ee6baecfe6b195292ad682167f5f
parent 320155 29b74b9db879bbbd662c38461c10fad3ad22b977
child 320157 deaf711a7bc8a8cb604666b0e4e7a91edc90018e
push id9143
push userahunt@mozilla.com
push dateFri, 08 Jan 2016 21:30:53 +0000
reviewersmfinkle
bugs1235902
milestone46.0a1
Bug 1235902 - Support actions from links in hosted feedback page. r=mfinkle
mobile/android/app/mobile.js
mobile/android/chrome/content/Feedback.js
--- a/mobile/android/app/mobile.js
+++ b/mobile/android/app/mobile.js
@@ -466,18 +466,23 @@ pref("dom.ipc.plugins.enabled", false);
 pref("plugins.click_to_play", true);
 // The default value for nsIPluginTag.enabledState (STATE_CLICKTOPLAY = 1)
 pref("plugin.default.state", 1);
 
 // product URLs
 // The breakpad report server to link to in about:crashes
 pref("breakpad.reportURL", "https://crash-stats.mozilla.com/report/index/");
 pref("app.support.baseURL", "http://support.mozilla.org/1/mobile/%VERSION%/%OS%/%LOCALE%/");
+
 // Used to submit data to input from about:feedback
 pref("app.feedback.postURL", "https://input.mozilla.org/api/v1/feedback/");
+
+// URL for feedback page
+pref("app.feedbackURL", "about:feedback");
+
 pref("app.privacyURL", "https://www.mozilla.org/privacy/firefox/");
 pref("app.creditsURL", "http://www.mozilla.org/credits/");
 pref("app.channelURL", "http://www.mozilla.org/%LOCALE%/firefox/channel/");
 #if MOZ_UPDATE_CHANNEL == aurora
 pref("app.releaseNotesURL", "http://www.mozilla.com/%LOCALE%/mobile/%VERSION%/auroranotes/");
 #elif MOZ_UPDATE_CHANNEL == beta
 pref("app.releaseNotesURL", "http://www.mozilla.com/%LOCALE%/mobile/%VERSION%beta/releasenotes/");
 #else
--- a/mobile/android/chrome/content/Feedback.js
+++ b/mobile/android/chrome/content/Feedback.js
@@ -1,18 +1,60 @@
 /* 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/. */
 "use strict";
 
 var Feedback = {
+
+  get _feedbackURL() {
+    delete this._feedbackURL;
+    return this._feedbackURL = Services.prefs.getCharPref("app.feedbackURL");
+  },
+
   observe: function(aMessage, aTopic, aData) {
-    if (aTopic !== "Feedback:Show")
+    if (aTopic !== "Feedback:Show") {
       return;
+    }
 
-    // Only prompt for feedback if this isn't a distribution build.
+    // Don't prompt for feedback in distribution builds.
     try {
       Services.prefs.getCharPref("distribution.id");
-    } catch (e) {
-      BrowserApp.addTab("about:feedback?source=feedback-prompt", { selected: true, parentId: BrowserApp.selectedTab.id });
+      return;
+    } catch (e) {}
+
+    let url = this._feedbackURL + "?source=feedback-prompt";
+    let browser = BrowserApp.selectOrAddTab(url, { parentId: BrowserApp.selectedTab.id }).browser;
+    browser.addEventListener("FeedbackClose", this, false, true);
+    browser.addEventListener("FeedbackMaybeLater", this, false, true);
+    browser.addEventListener("FeedbackOpenPlay", this, false, true);
+  },
+
+  handleEvent: function(event) {
+    if (!this._isAllowed(event.target)) {
+      return;
     }
+
+    switch (event.type) {
+      case "FeedbackClose":
+        // Do nothing.
+        break;
+
+      case "FeedbackMaybeLater":
+        Messaging.sendRequest({ type: "Feedback:MaybeLater" });
+        break;
+
+      case "FeedbackOpenPlay":
+        Messaging.sendRequest({ type: "Feedback:OpenPlayStore" });
+        break;
+
+    }
+
+    let win = event.target.ownerDocument.defaultView.top;
+    BrowserApp.closeTab(BrowserApp.getTabForWindow(win));
+  },
+
+  _isAllowed: function(node) {
+    let uri = node.ownerDocument.documentURIObject;
+    let feedbackURI = Services.io.newURI(this._feedbackURL, null, null);
+    return uri.prePath === feedbackURI.prePath;
   }
 };