Bug 1024807 - Add "Report Site Issue" menu item (for Nightly users). r=wesj

This commit is contained in:
Mike Taylor 2014-10-16 12:26:00 +02:00
parent 2d45d84d72
commit fc6b39abf5
5 changed files with 114 additions and 0 deletions

View File

@ -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");
});

View File

@ -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

View File

@ -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/

View File

@ -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

View File

@ -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: