mobile/android/chrome/content/aboutFeedback.js

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 2 * License, v. 2.0. If a copy of the MPL was not distributed with this file,
michael@0 3 * You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 4
michael@0 5 "use strict";
michael@0 6
michael@0 7 let Cc = Components.classes;
michael@0 8 let Ci = Components.interfaces;
michael@0 9 let Cu = Components.utils;
michael@0 10
michael@0 11 Cu.import("resource://gre/modules/Services.jsm");
michael@0 12 Cu.import("resource://gre/modules/Messaging.jsm");
michael@0 13 document.addEventListener("DOMContentLoaded", init, false);
michael@0 14
michael@0 15 function dump(a) {
michael@0 16 Services.console.logStringMessage(a);
michael@0 17 }
michael@0 18
michael@0 19 function init() {
michael@0 20 let anchors = document.querySelectorAll(".maybe-later");
michael@0 21 for(let anchor of anchors) {
michael@0 22 anchor.addEventListener("click", maybeLater, false);
michael@0 23 }
michael@0 24 document.getElementById("happy-link").addEventListener("click", function(evt) {
michael@0 25 switchSection("happy");
michael@0 26 }, false);
michael@0 27 document.getElementById("sad-link").addEventListener("click", function(evt) {
michael@0 28 switchSection("sad");
michael@0 29 }, false);
michael@0 30
michael@0 31 window.addEventListener("unload", uninit, false);
michael@0 32
michael@0 33 document.getElementById("open-play-store").addEventListener("click", openPlayStore, false);
michael@0 34 document.forms[0].addEventListener("submit", sendFeedback, false);
michael@0 35 for (let anchor of document.querySelectorAll(".no-thanks")) {
michael@0 36 anchor.addEventListener("click", evt => window.close(), false);
michael@0 37 }
michael@0 38
michael@0 39 let sumoLink = Services.urlFormatter.formatURLPref("app.support.baseURL");
michael@0 40 document.getElementById("sumo-link").href = sumoLink;
michael@0 41
michael@0 42 window.addEventListener("popstate", function (aEvent) {
michael@0 43 updateActiveSection(aEvent.state ? aEvent.state.section : "intro")
michael@0 44 }, false);
michael@0 45
michael@0 46 // Fill "Last visited site" input with most recent history entry URL.
michael@0 47 Services.obs.addObserver(function observer(aSubject, aTopic, aData) {
michael@0 48 document.getElementById("last-url").value = aData;
michael@0 49 }, "Feedback:LastUrl", false);
michael@0 50
michael@0 51 sendMessageToJava({ type: "Feedback:LastUrl" });
michael@0 52 }
michael@0 53
michael@0 54 function uninit() {
michael@0 55 Services.obs.removeObserver(this, "Feedback:LastUrl");
michael@0 56 }
michael@0 57
michael@0 58 function switchSection(aSection) {
michael@0 59 history.pushState({ section: aSection }, aSection);
michael@0 60 updateActiveSection(aSection);
michael@0 61 }
michael@0 62
michael@0 63 function updateActiveSection(aSection) {
michael@0 64 document.querySelector("section[active]").removeAttribute("active");
michael@0 65 document.getElementById(aSection).setAttribute("active", true);
michael@0 66 }
michael@0 67
michael@0 68 function openPlayStore() {
michael@0 69 sendMessageToJava({ type: "Feedback:OpenPlayStore" });
michael@0 70
michael@0 71 window.close();
michael@0 72 }
michael@0 73
michael@0 74 function maybeLater() {
michael@0 75 window.close();
michael@0 76
michael@0 77 sendMessageToJava({ type: "Feedback:MaybeLater" });
michael@0 78 }
michael@0 79
michael@0 80 function sendFeedback(aEvent) {
michael@0 81 // Prevent the page from reloading.
michael@0 82 aEvent.preventDefault();
michael@0 83
michael@0 84 let section = history.state.section;
michael@0 85
michael@0 86 // Sanity check.
michael@0 87 if (section != "sad") {
michael@0 88 Cu.reportError("Trying to send feedback from an invalid section: " + section);
michael@0 89 return;
michael@0 90 }
michael@0 91
michael@0 92 let sectionElement = document.getElementById(section);
michael@0 93 let descriptionElement = sectionElement.querySelector(".description");
michael@0 94
michael@0 95 // Bail if the description value isn't valid. HTML5 form validation will take care
michael@0 96 // of showing an error message for us.
michael@0 97 if (!descriptionElement.validity.valid)
michael@0 98 return;
michael@0 99
michael@0 100 let data = new FormData();
michael@0 101 data.append("description", descriptionElement.value);
michael@0 102 data.append("_type", 2);
michael@0 103
michael@0 104 let urlElement = document.getElementById("last-url");
michael@0 105 // Bail if the URL value isn't valid. HTML5 form validation will take care
michael@0 106 // of showing an error message for us.
michael@0 107 if (!urlElement.validity.valid)
michael@0 108 return;
michael@0 109
michael@0 110 // Only send a URL string if the user provided one.
michael@0 111 if (urlElement.value) {
michael@0 112 data.append("add_url", true);
michael@0 113 data.append("url", urlElement.value);
michael@0 114 }
michael@0 115
michael@0 116 let sysInfo = Cc["@mozilla.org/system-info;1"].getService(Ci.nsIPropertyBag2);
michael@0 117 data.append("device", sysInfo.get("device"));
michael@0 118 data.append("manufacturer", sysInfo.get("manufacturer"));
michael@0 119
michael@0 120 let req = new XMLHttpRequest();
michael@0 121 req.addEventListener("error", function() {
michael@0 122 Cu.reportError("Error sending feedback to input.mozilla.org: " + req.statusText);
michael@0 123 }, false);
michael@0 124 req.addEventListener("abort", function() {
michael@0 125 Cu.reportError("Aborted sending feedback to input.mozilla.org: " + req.statusText);
michael@0 126 }, false);
michael@0 127
michael@0 128 let postURL = Services.urlFormatter.formatURLPref("app.feedback.postURL");
michael@0 129 req.open("POST", postURL, true);
michael@0 130 req.send(data);
michael@0 131
michael@0 132 switchSection("thanks-" + section);
michael@0 133 }

mercurial