From 9739090d03164909403869713216427bf2adede4 Mon Sep 17 00:00:00 2001 From: Neil Bleasdale Date: Mon, 6 Jan 2014 15:18:01 -0500 Subject: [PATCH] Bug 948897 - Move inline scripts and styles into separate file for mobile/android/chrome/content/aboutFeedback.xhtml. r=mbrubeck --- .../android/chrome/content/aboutFeedback.js | 116 ++++++++++++++++++ .../chrome/content/aboutFeedback.xhtml | 114 +---------------- mobile/android/chrome/jar.mn | 1 + 3 files changed, 118 insertions(+), 113 deletions(-) create mode 100644 mobile/android/chrome/content/aboutFeedback.js diff --git a/mobile/android/chrome/content/aboutFeedback.js b/mobile/android/chrome/content/aboutFeedback.js new file mode 100644 index 00000000000..2e57cc441f1 --- /dev/null +++ b/mobile/android/chrome/content/aboutFeedback.js @@ -0,0 +1,116 @@ +/* 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"; + +let Cc = Components.classes; +let Ci = Components.interfaces; +let Cu = Components.utils; + +Cu.import("resource://gre/modules/Services.jsm"); + +function dump(a) { + Services.console.logStringMessage(a); +} + +function sendMessageToJava(aMessage) { + Services.androidBridge.handleGeckoMessage(JSON.stringify(aMessage)); +} + +function init() { + let sumoLink = Services.urlFormatter.formatURLPref("app.support.baseURL"); + document.getElementById("sumo-link").href = sumoLink; + + window.addEventListener("popstate", function (aEvent) { + updateActiveSection(aEvent.state ? aEvent.state.section : "intro") + }, false); + + // Fill "Last visited site" input with most recent history entry URL. + Services.obs.addObserver(function observer(aSubject, aTopic, aData) { + document.getElementById("last-url").value = aData; + }, "Feedback:LastUrl", false); + + sendMessageToJava({ type: "Feedback:LastUrl" }); +} + +function uninit() { + Services.obs.removeObserver(this, "Feedback:LastUrl"); +} + +function switchSection(aSection) { + history.pushState({ section: aSection }, aSection); + updateActiveSection(aSection); +} + +function updateActiveSection(aSection) { + document.querySelector("section[active]").removeAttribute("active"); + document.getElementById(aSection).setAttribute("active", true); +} + +function openPlayStore() { + sendMessageToJava({ type: "Feedback:OpenPlayStore" }); + + window.close(); +} + +function maybeLater() { + window.close(); + + sendMessageToJava({ type: "Feedback:MaybeLater" }); +} + +function sendFeedback(aEvent) { + // Prevent the page from reloading. + aEvent.preventDefault(); + + let section = history.state.section; + + // Sanity check. + if (section != "sad") { + Cu.reportError("Trying to send feedback from an invalid section: " + section); + return; + } + + let sectionElement = document.getElementById(section); + let descriptionElement = sectionElement.querySelector(".description"); + + // Bail if the description value isn't valid. HTML5 form validation will take care + // of showing an error message for us. + if (!descriptionElement.validity.valid) + return; + + let data = new FormData(); + data.append("description", descriptionElement.value); + data.append("_type", 2); + + let urlElement = document.getElementById("last-url"); + // Bail if the URL value isn't valid. HTML5 form validation will take care + // of showing an error message for us. + if (!urlElement.validity.valid) + return; + + // Only send a URL string if the user provided one. + if (urlElement.value) { + data.append("add_url", true); + data.append("url", urlElement.value); + } + + let sysInfo = Cc["@mozilla.org/system-info;1"].getService(Ci.nsIPropertyBag2); + data.append("device", sysInfo.get("device")); + data.append("manufacturer", sysInfo.get("manufacturer")); + + let req = new XMLHttpRequest(); + req.addEventListener("error", function() { + Cu.reportError("Error sending feedback to input.mozilla.org: " + req.statusText); + }, false); + req.addEventListener("abort", function() { + Cu.reportError("Aborted sending feedback to input.mozilla.org: " + req.statusText); + }, false); + + let postURL = Services.urlFormatter.formatURLPref("app.feedback.postURL"); + req.open("POST", postURL, true); + req.send(data); + + switchSection("thanks-" + section); +} diff --git a/mobile/android/chrome/content/aboutFeedback.xhtml b/mobile/android/chrome/content/aboutFeedback.xhtml index a21763bf6e2..d503c6845ef 100644 --- a/mobile/android/chrome/content/aboutFeedback.xhtml +++ b/mobile/android/chrome/content/aboutFeedback.xhtml @@ -74,118 +74,6 @@ - - + diff --git a/mobile/android/chrome/jar.mn b/mobile/android/chrome/jar.mn index a10da62f647..dd84e304dee 100644 --- a/mobile/android/chrome/jar.mn +++ b/mobile/android/chrome/jar.mn @@ -16,6 +16,7 @@ chrome.jar: content/aboutDownloads.xhtml (content/aboutDownloads.xhtml) content/aboutDownloads.js (content/aboutDownloads.js) content/aboutFeedback.xhtml (content/aboutFeedback.xhtml) + content/aboutFeedback.js (content/aboutFeedback.js) content/aboutPrivateBrowsing.xhtml (content/aboutPrivateBrowsing.xhtml) content/aboutReader.html (content/aboutReader.html) content/aboutReader.js (content/aboutReader.js)