Bug 1024807 - Add "Report Site Issue" menu item (for Nightly users). r=wesj
new file mode 100644
--- /dev/null
+++ b/mobile/android/chrome/content/WebcompatReporter.js
@@ -0,0 +1,87 @@
+/* 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/. */
+
+const { classes: Cc, interfaces: Ci, utils: Cu } = Components;
+
+Cu.import("resource://gre/modules/Services.jsm");
+Cu.import("resource://gre/modules/XPCOMUtils.jsm");
+
+var WebcompatReporter = {
+ menuItem: null,
+ menuItemEnabled: null,
+ init: function() {
+ Services.obs.addObserver(this, "DesktopMode:Change", false);
+ Services.obs.addObserver(this, "content-page-shown", false);
+ this.addMenuItem();
+ },
+
+ uninit: function() {
+ Services.obs.removeObserver(this, "DesktopMode:Change");
+
+ if (this.menuItem) {
+ NativeWindow.menu.remove(this.menuItem);
+ this.menuItem = null;
+ }
+ },
+
+ observe: function(subject, topic, data) {
+ if (topic === "content-page-shown") {
+ let currentURI = subject.documentURI;
+ if (!this.menuItemEnabled && this.isReportableUrl(currentURI)) {
+ NativeWindow.menu.update(this.menuItem, {enabled: true});
+ this.menuItemEnabled = true;
+ } else if (this.menuItemEnabled && !this.isReportableUrl(currentURI)) {
+ NativeWindow.menu.update(this.menuItem, {enabled: false});
+ this.menuItemEnabled = false;
+ }
+ } else if (topic === "DesktopMode:Change") {
+ let args = JSON.parse(data);
+ let tab = BrowserApp.getTabForId(args.tabId);
+ if (args.desktopMode && tab !== null) {
+ this.reportDesktopModePrompt();
+ }
+ }
+ },
+
+ addMenuItem: function() {
+ this.menuItem = NativeWindow.menu.add({
+ name: this.strings.GetStringFromName("webcompat.menu.name"),
+ callback: () => {
+ let currentURI = BrowserApp.selectedTab.browser.currentURI.spec;
+ this.reportIssue(currentURI);
+ },
+ enabled: false,
+ });
+ },
+
+ isReportableUrl: function(url) {
+ return url !== null && !(url.startsWith("about") ||
+ url.startsWith("chrome") ||
+ url.startsWith("file") ||
+ url.startsWith("resource"));
+ },
+
+ reportDesktopModePrompt: function() {
+ let currentURI = BrowserApp.selectedTab.browser.currentURI.spec;
+ let message = this.strings.GetStringFromName("webcompat.reportDesktopMode.message");
+ let options = {
+ button: {
+ label: this.strings.GetStringFromName("webcompat.reportDesktopModeYes.label"),
+ callback: () => this.reportIssue(currentURI)
+ }
+ };
+ NativeWindow.toast.show(message, "long", options);
+ },
+
+ reportIssue: function(url) {
+ let webcompatURL = new URL("http://webcompat.com/");
+ webcompatURL.searchParams.append("open", "1");
+ webcompatURL.searchParams.append("url", url);
+ BrowserApp.addTab(webcompatURL.href);
+ }
+};
+
+XPCOMUtils.defineLazyGetter(WebcompatReporter, "strings", function() {
+ return Services.strings.createBundle("chrome://browser/locale/webcompatReporter.properties");
+});
--- a/mobile/android/chrome/content/browser.js
+++ b/mobile/android/chrome/content/browser.js
@@ -107,16 +107,19 @@ XPCOMUtils.defineLazyModuleGetter(this,
["InputWidgetHelper", "chrome://browser/content/InputWidgetHelper.js"],
["AboutReader", "chrome://browser/content/aboutReader.js"],
["MasterPassword", "chrome://browser/content/MasterPassword.js"],
["PluginHelper", "chrome://browser/content/PluginHelper.js"],
["OfflineApps", "chrome://browser/content/OfflineApps.js"],
["Linkifier", "chrome://browser/content/Linkify.js"],
["ZoomHelper", "chrome://browser/content/ZoomHelper.js"],
["CastingApps", "chrome://browser/content/CastingApps.js"],
+#ifdef NIGHTLY_BUILD
+ ["WebcompatReporter", "chrome://browser/content/WebcompatReporter.js"],
+#endif
].forEach(function (aScript) {
let [name, script] = aScript;
XPCOMUtils.defineLazyGetter(window, name, function() {
let sandbox = {};
Services.scriptloader.loadSubScript(script, sandbox);
return sandbox[name];
});
});
@@ -330,16 +333,19 @@ var BrowserApp = {
}, Ci.nsIThread.DISPATCH_NORMAL);
#ifdef MOZ_SAFE_BROWSING
Services.tm.mainThread.dispatch(function() {
// Bug 778855 - Perf regression if we do this here. To be addressed in bug 779008.
SafeBrowsing.init();
}, Ci.nsIThread.DISPATCH_NORMAL);
#endif
+#ifdef NIGHTLY_BUILD
+ WebcompatReporter.init();
+#endif
} catch(ex) { console.log(ex); }
}, false);
BrowserEventHandler.init();
ViewportHandler.init();
Services.androidBridge.browserApp = this;
@@ -853,16 +859,19 @@ var BrowserApp = {
RemoteDebugger.uninit();
Reader.uninit();
UserAgentOverrides.uninit();
DesktopUserAgent.uninit();
ExternalApps.uninit();
CastingApps.uninit();
Distribution.uninit();
Tabs.uninit();
+#ifdef NIGHTLY_BUILD
+ WebcompatReporter.uninit();
+#endif
},
// This function returns false during periods where the browser displayed document is
// different from the browser content document, so user actions and some kinds of viewport
// updates should be ignored. This period starts when we start loading a new page or
// switch tabs, and ends when the new browser content document has been drawn and handed
// off to the compositor.
isBrowserContentDocumentDisplayed: function() {
--- a/mobile/android/chrome/jar.mn
+++ b/mobile/android/chrome/jar.mn
@@ -57,14 +57,17 @@ chrome.jar:
#ifdef MOZ_SERVICES_HEALTHREPORT
content/aboutHealthReport.xhtml (content/aboutHealthReport.xhtml)
* content/aboutHealthReport.js (content/aboutHealthReport.js)
#endif
#ifdef MOZ_DEVICES
content/aboutDevices.xhtml (content/aboutDevices.xhtml)
content/aboutDevices.js (content/aboutDevices.js)
#endif
+#ifdef NIGHTLY_BUILD
+ content/WebcompatReporter.js (content/WebcompatReporter.js)
+#endif
% content branding %content/branding/
% override chrome://global/content/config.xul chrome://browser/content/config.xhtml
% override chrome://global/content/netError.xhtml chrome://browser/content/netError.xhtml
% override chrome://mozapps/content/extensions/extensions.xul chrome://browser/content/aboutAddons.xhtml
new file mode 100644
--- /dev/null
+++ b/mobile/android/locales/en-US/chrome/webcompatReporter.properties
@@ -0,0 +1,12 @@
+# 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/.
+
+# LOCALIZATION NOTE (webcompat.menu.name): A "site issue" is a bug, display,
+# or functionality problem with a webpage in the browser.
+webcompat.menu.name=Report Site Issue
+
+# LOCALIZATION NOTE (webcompat.reportDesktopMode.message): A " site issue" is a
+# bug, display, or functionality problem with a webpage in the browser.
+webcompat.reportDesktopMode.message=Report site issue?
+webcompat.reportDesktopModeYes.label=Report
--- a/mobile/android/locales/jar.mn
+++ b/mobile/android/locales/jar.mn
@@ -34,16 +34,19 @@
locale/@AB_CD@/browser/sync.dtd (%chrome/sync.dtd)
locale/@AB_CD@/browser/sync.properties (%chrome/sync.properties)
locale/@AB_CD@/browser/prompt.dtd (%chrome/prompt.dtd)
locale/@AB_CD@/browser/feedback.dtd (%chrome/feedback.dtd)
locale/@AB_CD@/browser/phishing.dtd (%chrome/phishing.dtd)
locale/@AB_CD@/browser/payments.properties (%chrome/payments.properties)
locale/@AB_CD@/browser/handling.properties (%chrome/handling.properties)
locale/@AB_CD@/browser/webapp.properties (%chrome/webapp.properties)
+#ifdef NIGHTLY_BUILD
+ locale/@AB_CD@/browser/webcompatReporter.properties (%chrome/webcompatReporter.properties)
+#endif
# overrides for toolkit l10n, also for en-US
relativesrcdir toolkit/locales:
locale/@AB_CD@/browser/overrides/about.dtd (%chrome/global/about.dtd)
locale/@AB_CD@/browser/overrides/aboutAbout.dtd (%chrome/global/aboutAbout.dtd)
locale/@AB_CD@/browser/overrides/aboutRights.dtd (%chrome/global/aboutRights.dtd)
locale/@AB_CD@/browser/overrides/charsetMenu.properties (%chrome/global/charsetMenu.properties)
locale/@AB_CD@/browser/overrides/commonDialogs.properties (%chrome/global/commonDialogs.properties)