fune/mobile/android/chrome/content/Feedback.js
Victor Porof e999ae1989 Bug 1561435 - Format mobile/, a=automatic-formatting
# ignore-this-changeset

Differential Revision: https://phabricator.services.mozilla.com/D35914

--HG--
extra : source : eafb1052afc7712c969e57552da5affc63093e9e
2019-07-05 10:53:35 +02:00

69 lines
2.1 KiB
JavaScript

/* 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.urlFormatter.formatURLPref(
"app.feedbackURL"
));
},
onEvent: function(event, data, callback) {
if (event !== "Feedback:Show") {
return;
}
// Don't prompt for feedback in distribution builds.
try {
Services.prefs.getCharPref("distribution.id");
return;
} catch (e) {}
let url = this._feedbackURL;
let browser = BrowserApp.selectOrAddTab(url, {
parentId: BrowserApp.selectedTab.id,
}).browser;
browser.addEventListener("FeedbackClose", this, false, true);
browser.addEventListener("FeedbackMaybeLater", this, false, true);
// Dispatch a custom event to the page content when feedback is prompted by the browser.
// This will be used by the page to determine it's being loaded directly by the browser,
// instead of by the user visiting the page, e.g. through browser history.
function loadListener(event) {
browser.removeEventListener("DOMContentLoaded", loadListener);
browser.contentDocument.dispatchEvent(
new CustomEvent("FeedbackPrompted")
);
}
browser.addEventListener("DOMContentLoaded", loadListener);
},
handleEvent: function(event) {
if (!this._isAllowed(event.target)) {
return;
}
switch (event.type) {
case "FeedbackClose":
// Do nothing.
break;
case "FeedbackMaybeLater":
GlobalEventDispatcher.sendRequest({ type: "Feedback:MaybeLater" });
break;
}
let win = event.target.ownerGlobal.top;
BrowserApp.closeTab(BrowserApp.getTabForWindow(win));
},
_isAllowed: function(node) {
let uri = node.ownerDocument.documentURIObject;
let feedbackURI = Services.io.newURI(this._feedbackURL);
return uri.prePath === feedbackURI.prePath;
},
};