diff --git a/mobile/android/chrome/content/WebcompatReporter.js b/mobile/android/chrome/content/WebcompatReporter.js new file mode 100644 index 000000000000..264553e62898 --- /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"); +}); diff --git a/mobile/android/chrome/content/browser.js b/mobile/android/chrome/content/browser.js index 169febfc3bb1..08ed579ea878 100644 --- a/mobile/android/chrome/content/browser.js +++ b/mobile/android/chrome/content/browser.js @@ -112,6 +112,9 @@ XPCOMUtils.defineLazyModuleGetter(this, "SharedPreferences", ["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() { @@ -334,6 +337,9 @@ var BrowserApp = { // 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); @@ -858,6 +864,9 @@ var BrowserApp = { CastingApps.uninit(); Distribution.uninit(); Tabs.uninit(); +#ifdef NIGHTLY_BUILD + WebcompatReporter.uninit(); +#endif }, // This function returns false during periods where the browser displayed document is diff --git a/mobile/android/chrome/jar.mn b/mobile/android/chrome/jar.mn index bcb130999b3b..652cad785bc0 100644 --- a/mobile/android/chrome/jar.mn +++ b/mobile/android/chrome/jar.mn @@ -62,6 +62,9 @@ chrome.jar: 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/ diff --git a/mobile/android/locales/en-US/chrome/webcompatReporter.properties b/mobile/android/locales/en-US/chrome/webcompatReporter.properties new file mode 100644 index 000000000000..cce28981dd4c --- /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 diff --git a/mobile/android/locales/jar.mn b/mobile/android/locales/jar.mn index 51fe85d9c372..d7d8e5b6a113 100644 --- a/mobile/android/locales/jar.mn +++ b/mobile/android/locales/jar.mn @@ -39,6 +39,9 @@ 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: