mirror of
https://repo.dactyloidae.xyz/Dactyloidae/UXP.git
synced 2026-09-10 02:08:38 +09:00
Merge remote-tracking branch 'origin/tracking' into custom
This commit is contained in:
commit
879ab0d7dc
72 changed files with 81921 additions and 71421 deletions
|
|
@ -10,8 +10,7 @@ var Cu = Components.utils;
|
|||
var Cr = Components.results;
|
||||
|
||||
this.EXPORTED_SYMBOLS = [ "TabCrashHandler",
|
||||
"PluginCrashReporter",
|
||||
"UnsubmittedCrashHandler" ];
|
||||
"PluginCrashReporter" ];
|
||||
|
||||
Cu.import("resource://gre/modules/XPCOMUtils.jsm");
|
||||
Cu.import("resource://gre/modules/Services.jsm");
|
||||
|
|
@ -50,11 +49,6 @@ this.TabCrashHandler = {
|
|||
unseenCrashedChildIDs: [],
|
||||
crashedBrowserQueues: new Map(),
|
||||
|
||||
get prefs() {
|
||||
delete this.prefs;
|
||||
return this.prefs = Services.prefs.getBranch("browser.tabs.crashReporting.");
|
||||
},
|
||||
|
||||
init: function () {
|
||||
if (this.initialized)
|
||||
return;
|
||||
|
|
@ -140,19 +134,16 @@ this.TabCrashHandler = {
|
|||
}
|
||||
|
||||
case "closeTab": {
|
||||
this.maybeSendCrashReport(message);
|
||||
gBrowser.removeTab(tab, { animate: true });
|
||||
break;
|
||||
}
|
||||
|
||||
case "restoreTab": {
|
||||
this.maybeSendCrashReport(message);
|
||||
SessionStore.reviveCrashedTab(tab);
|
||||
break;
|
||||
}
|
||||
|
||||
case "restoreAll": {
|
||||
this.maybeSendCrashReport(message);
|
||||
SessionStore.reviveAllCrashedTabs();
|
||||
break;
|
||||
}
|
||||
|
|
@ -245,20 +236,9 @@ this.TabCrashHandler = {
|
|||
// 1) We are aware that this browser crashed
|
||||
// 2) We know we've never shown the tab crash page for the
|
||||
// crash yet
|
||||
// 3) The user is not configured to automatically submit backlogged
|
||||
// crash reports. If they are, we'll send the crash report
|
||||
// immediately.
|
||||
if (childID &&
|
||||
this.unseenCrashedChildIDs.indexOf(childID) != -1) {
|
||||
if (UnsubmittedCrashHandler.autoSubmit) {
|
||||
let dumpID = this.childMap.get(childID);
|
||||
if (dumpID) {
|
||||
UnsubmittedCrashHandler.submitReports([dumpID]);
|
||||
}
|
||||
} else {
|
||||
this.sendToTabCrashedPage(browser);
|
||||
return true;
|
||||
}
|
||||
if (childID && this.unseenCrashedChildIDs.indexOf(childID) != -1) {
|
||||
this.sendToTabCrashedPage(browser);
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
|
|
@ -286,15 +266,6 @@ this.TabCrashHandler = {
|
|||
tab.setAttribute("crashed", true);
|
||||
},
|
||||
|
||||
/**
|
||||
* Submits a crash report from about:tabcrashed, if the crash
|
||||
* reporter is enabled and a crash report can be found.
|
||||
*/
|
||||
maybeSendCrashReport(message) {
|
||||
/*** STUB ***/
|
||||
return;
|
||||
},
|
||||
|
||||
removeSubmitCheckboxesForSameCrash: function(childID) {
|
||||
let enumerator = Services.wm.getEnumerator("navigator:browser");
|
||||
while (enumerator.hasMoreElements()) {
|
||||
|
|
@ -342,34 +313,10 @@ this.TabCrashHandler = {
|
|||
this.unseenCrashedChildIDs.splice(index, 1);
|
||||
}
|
||||
|
||||
let dumpID = this.getDumpID(browser);
|
||||
if (!dumpID) {
|
||||
message.target.sendAsyncMessage("SetCrashReportAvailable", {
|
||||
hasReport: false,
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
let requestAutoSubmit = !UnsubmittedCrashHandler.autoSubmit;
|
||||
let requestEmail = this.prefs.getBoolPref("requestEmail");
|
||||
let sendReport = this.prefs.getBoolPref("sendReport");
|
||||
let includeURL = this.prefs.getBoolPref("includeURL");
|
||||
let emailMe = this.prefs.getBoolPref("emailMe");
|
||||
|
||||
let data = {
|
||||
hasReport: true,
|
||||
sendReport,
|
||||
includeURL,
|
||||
emailMe,
|
||||
requestAutoSubmit,
|
||||
requestEmail,
|
||||
};
|
||||
|
||||
if (emailMe) {
|
||||
data.email = this.prefs.getCharPref("email", "");
|
||||
}
|
||||
|
||||
message.target.sendAsyncMessage("SetCrashReportAvailable", data);
|
||||
message.target.sendAsyncMessage("SetCrashReportAvailable", {
|
||||
hasReport: false,
|
||||
});
|
||||
return;
|
||||
},
|
||||
|
||||
onAboutTabCrashedUnload(message) {
|
||||
|
|
@ -391,382 +338,8 @@ this.TabCrashHandler = {
|
|||
let childID = this.browserMap.get(browser.permanentKey);
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* For some <xul:browser>, return a crash report dump ID for that browser
|
||||
* if we have been informed of one. Otherwise, return null.
|
||||
*/
|
||||
getDumpID(browser) {
|
||||
/*** STUB ***/
|
||||
return null;
|
||||
},
|
||||
}
|
||||
|
||||
/**
|
||||
* This component is responsible for scanning the pending
|
||||
* crash report directory for reports, and (if enabled), to
|
||||
* prompt the user to submit those reports. It might also
|
||||
* submit those reports automatically without prompting if
|
||||
* the user has opted in.
|
||||
*/
|
||||
this.UnsubmittedCrashHandler = {
|
||||
get prefs() {
|
||||
delete this.prefs;
|
||||
return this.prefs =
|
||||
Services.prefs.getBranch("browser.crashReports.unsubmittedCheck.");
|
||||
},
|
||||
|
||||
get enabled() {
|
||||
return this.prefs.getBoolPref("enabled");
|
||||
},
|
||||
|
||||
// showingNotification is set to true once a notification
|
||||
// is successfully shown, and then set back to false if
|
||||
// the notification is dismissed by an action by the user.
|
||||
showingNotification: false,
|
||||
// suppressed is true if we've determined that we've shown
|
||||
// the notification too many times across too many days without
|
||||
// user interaction, so we're suppressing the notification for
|
||||
// some number of days. See the documentation for
|
||||
// shouldShowPendingSubmissionsNotification().
|
||||
suppressed: false,
|
||||
|
||||
init() {
|
||||
if (this.initialized) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.initialized = true;
|
||||
|
||||
// UnsubmittedCrashHandler can be initialized but still be disabled.
|
||||
// This is intentional, as this makes simulating UnsubmittedCrashHandler's
|
||||
// reactions to browser startup and shutdown easier in test automation.
|
||||
//
|
||||
// UnsubmittedCrashHandler, when initialized but not enabled, is inert.
|
||||
if (this.enabled) {
|
||||
if (this.prefs.prefHasUserValue("suppressUntilDate")) {
|
||||
if (this.prefs.getCharPref("suppressUntilDate") > this.dateString()) {
|
||||
// We'll be suppressing any notifications until after suppressedDate,
|
||||
// so there's no need to do anything more.
|
||||
this.suppressed = true;
|
||||
return;
|
||||
}
|
||||
|
||||
// We're done suppressing, so we don't need this pref anymore.
|
||||
this.prefs.clearUserPref("suppressUntilDate");
|
||||
}
|
||||
|
||||
Services.obs.addObserver(this, "browser-delayed-startup-finished",
|
||||
false);
|
||||
Services.obs.addObserver(this, "profile-before-change",
|
||||
false);
|
||||
}
|
||||
},
|
||||
|
||||
uninit() {
|
||||
if (!this.initialized) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.initialized = false;
|
||||
|
||||
if (!this.enabled) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (this.suppressed) {
|
||||
this.suppressed = false;
|
||||
// No need to do any more clean-up, since we were suppressed.
|
||||
return;
|
||||
}
|
||||
|
||||
if (this.showingNotification) {
|
||||
this.prefs.setBoolPref("shutdownWhileShowing", true);
|
||||
this.showingNotification = false;
|
||||
}
|
||||
|
||||
try {
|
||||
Services.obs.removeObserver(this, "browser-delayed-startup-finished");
|
||||
} catch (e) {
|
||||
// The browser-delayed-startup-finished observer might have already
|
||||
// fired and removed itself, so if this fails, it's okay.
|
||||
if (e.result != Cr.NS_ERROR_FAILURE) {
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
Services.obs.removeObserver(this, "profile-before-change");
|
||||
},
|
||||
|
||||
observe(subject, topic, data) {
|
||||
switch (topic) {
|
||||
case "browser-delayed-startup-finished": {
|
||||
Services.obs.removeObserver(this, topic);
|
||||
this.checkForUnsubmittedCrashReports();
|
||||
break;
|
||||
}
|
||||
case "profile-before-change": {
|
||||
this.uninit();
|
||||
break;
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Scans the profile directory for unsubmitted crash reports
|
||||
* within the past PENDING_CRASH_REPORT_DAYS days. If it
|
||||
* finds any, it will, if necessary, attempt to open a notification
|
||||
* bar to prompt the user to submit them.
|
||||
*
|
||||
* @returns Promise
|
||||
* Resolves with the <xul:notification> after it tries to
|
||||
* show a notification on the most recent browser window.
|
||||
* If a notification cannot be shown, will resolve with null.
|
||||
*/
|
||||
checkForUnsubmittedCrashReports: Task.async(function*() {
|
||||
let dateLimit = new Date();
|
||||
dateLimit.setDate(dateLimit.getDate() - PENDING_CRASH_REPORT_DAYS);
|
||||
|
||||
let reportIDs = [];
|
||||
try {
|
||||
reportIDs = yield CrashSubmit.pendingIDsAsync(dateLimit);
|
||||
} catch (e) {
|
||||
Cu.reportError(e);
|
||||
return null;
|
||||
}
|
||||
|
||||
if (reportIDs.length) {
|
||||
if (this.autoSubmit) {
|
||||
this.submitReports(reportIDs);
|
||||
} else if (this.shouldShowPendingSubmissionsNotification()) {
|
||||
return this.showPendingSubmissionsNotification(reportIDs);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}),
|
||||
|
||||
/**
|
||||
* Returns true if the notification should be shown.
|
||||
* shouldShowPendingSubmissionsNotification makes this decision
|
||||
* by looking at whether or not the user has seen the notification
|
||||
* over several days without ever interacting with it. If this occurs
|
||||
* too many times, we suppress the notification for DAYS_TO_SUPPRESS
|
||||
* days.
|
||||
*
|
||||
* @returns bool
|
||||
*/
|
||||
shouldShowPendingSubmissionsNotification() {
|
||||
if (!this.prefs.prefHasUserValue("shutdownWhileShowing")) {
|
||||
return true;
|
||||
}
|
||||
|
||||
let shutdownWhileShowing = this.prefs.getBoolPref("shutdownWhileShowing");
|
||||
this.prefs.clearUserPref("shutdownWhileShowing");
|
||||
|
||||
if (!this.prefs.prefHasUserValue("lastShownDate")) {
|
||||
// This isn't expected, but we're being defensive here. We'll
|
||||
// opt for showing the notification in this case.
|
||||
return true;
|
||||
}
|
||||
|
||||
let lastShownDate = this.prefs.getCharPref("lastShownDate");
|
||||
if (this.dateString() > lastShownDate && shutdownWhileShowing) {
|
||||
// We're on a newer day then when we last showed the
|
||||
// notification without closing it. We don't want to do
|
||||
// this too many times, so we'll decrement a counter for
|
||||
// this situation. Too many of these, and we'll assume the
|
||||
// user doesn't know or care about unsubmitted notifications,
|
||||
// and we'll suppress the notification for a while.
|
||||
let chances = this.prefs.getIntPref("chancesUntilSuppress");
|
||||
if (--chances < 0) {
|
||||
// We're out of chances!
|
||||
this.prefs.clearUserPref("chancesUntilSuppress");
|
||||
// We'll suppress for DAYS_TO_SUPPRESS days.
|
||||
let suppressUntil =
|
||||
this.dateString(new Date(Date.now() + (DAY * DAYS_TO_SUPPRESS)));
|
||||
this.prefs.setCharPref("suppressUntilDate", suppressUntil);
|
||||
return false;
|
||||
}
|
||||
this.prefs.setIntPref("chancesUntilSuppress", chances);
|
||||
}
|
||||
|
||||
return true;
|
||||
},
|
||||
|
||||
/**
|
||||
* Given an array of unsubmitted crash report IDs, try to open
|
||||
* up a notification asking the user to submit them.
|
||||
*
|
||||
* @param reportIDs (Array<string>)
|
||||
* The Array of report IDs to offer the user to send.
|
||||
* @returns The <xul:notification> if one is shown. null otherwise.
|
||||
*/
|
||||
showPendingSubmissionsNotification(reportIDs) {
|
||||
let count = reportIDs.length;
|
||||
if (!count) {
|
||||
return null;
|
||||
}
|
||||
|
||||
let messageTemplate =
|
||||
gNavigatorBundle.GetStringFromName("pendingCrashReports2.label");
|
||||
|
||||
let message = PluralForm.get(count, messageTemplate).replace("#1", count);
|
||||
|
||||
let notification = this.show({
|
||||
notificationID: "pending-crash-reports",
|
||||
message,
|
||||
reportIDs,
|
||||
onAction: () => {
|
||||
this.showingNotification = false;
|
||||
},
|
||||
});
|
||||
|
||||
if (notification) {
|
||||
this.showingNotification = true;
|
||||
this.prefs.setCharPref("lastShownDate", this.dateString());
|
||||
}
|
||||
|
||||
return notification;
|
||||
},
|
||||
|
||||
/**
|
||||
* Returns a string representation of a Date in the format
|
||||
* YYYYMMDD.
|
||||
*
|
||||
* @param someDate (Date, optional)
|
||||
* The Date to convert to the string. If not provided,
|
||||
* defaults to today's date.
|
||||
* @returns String
|
||||
*/
|
||||
dateString(someDate = new Date()) {
|
||||
let year = String(someDate.getFullYear()).padStart(4, "0");
|
||||
let month = String(someDate.getMonth() + 1).padStart(2, "0");
|
||||
let day = String(someDate.getDate()).padStart(2, "0");
|
||||
return year + month + day;
|
||||
},
|
||||
|
||||
/**
|
||||
* Attempts to show a notification bar to the user in the most
|
||||
* recent browser window asking them to submit some crash report
|
||||
* IDs. If a notification cannot be shown (for example, there
|
||||
* is no browser window), this method exits silently.
|
||||
*
|
||||
* The notification will allow the user to submit their crash
|
||||
* reports. If the user dismissed the notification, the crash
|
||||
* reports will be marked to be ignored (though they can
|
||||
* still be manually submitted via about:crashes).
|
||||
*
|
||||
* @param JS Object
|
||||
* An Object with the following properties:
|
||||
*
|
||||
* notificationID (string)
|
||||
* The ID for the notification to be opened.
|
||||
*
|
||||
* message (string)
|
||||
* The message to be displayed in the notification.
|
||||
*
|
||||
* reportIDs (Array<string>)
|
||||
* The array of report IDs to offer to the user.
|
||||
*
|
||||
* onAction (function, optional)
|
||||
* A callback to fire once the user performs an
|
||||
* action on the notification bar (this includes
|
||||
* dismissing the notification).
|
||||
*
|
||||
* @returns The <xul:notification> if one is shown. null otherwise.
|
||||
*/
|
||||
show({ notificationID, message, reportIDs, onAction }) {
|
||||
let chromeWin = RecentWindow.getMostRecentBrowserWindow();
|
||||
if (!chromeWin) {
|
||||
// Can't show a notification in this case. We'll hopefully
|
||||
// get another opportunity to have the user submit their
|
||||
// crash reports later.
|
||||
return null;
|
||||
}
|
||||
|
||||
let nb = chromeWin.document.getElementById("global-notificationbox");
|
||||
let notification = nb.getNotificationWithValue(notificationID);
|
||||
if (notification) {
|
||||
return null;
|
||||
}
|
||||
|
||||
let buttons = [{
|
||||
label: gNavigatorBundle.GetStringFromName("pendingCrashReports.send"),
|
||||
callback: () => {
|
||||
this.submitReports(reportIDs);
|
||||
if (onAction) {
|
||||
onAction();
|
||||
}
|
||||
},
|
||||
},
|
||||
{
|
||||
label: gNavigatorBundle.GetStringFromName("pendingCrashReports.alwaysSend"),
|
||||
callback: () => {
|
||||
this.autoSubmit = true;
|
||||
this.submitReports(reportIDs);
|
||||
if (onAction) {
|
||||
onAction();
|
||||
}
|
||||
},
|
||||
},
|
||||
{
|
||||
label: gNavigatorBundle.GetStringFromName("pendingCrashReports.viewAll"),
|
||||
callback: function() {
|
||||
chromeWin.openUILinkIn("about:crashes", "tab");
|
||||
return true;
|
||||
},
|
||||
}];
|
||||
|
||||
let eventCallback = (eventType) => {
|
||||
if (eventType == "dismissed") {
|
||||
// The user intentionally dismissed the notification,
|
||||
// which we interpret as meaning that they don't care
|
||||
// to submit the reports. We'll ignore these particular
|
||||
// reports going forward.
|
||||
reportIDs.forEach(function(reportID) {
|
||||
CrashSubmit.ignore(reportID);
|
||||
});
|
||||
if (onAction) {
|
||||
onAction();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
return nb.appendNotification(message, notificationID,
|
||||
"chrome://browser/skin/tab-crashed.svg",
|
||||
nb.PRIORITY_INFO_HIGH, buttons,
|
||||
eventCallback);
|
||||
},
|
||||
|
||||
get autoSubmit() {
|
||||
return Services.prefs
|
||||
.getBoolPref("browser.crashReports.unsubmittedCheck.autoSubmit2");
|
||||
},
|
||||
|
||||
set autoSubmit(val) {
|
||||
Services.prefs.setBoolPref("browser.crashReports.unsubmittedCheck.autoSubmit2",
|
||||
val);
|
||||
},
|
||||
|
||||
/**
|
||||
* Attempt to submit reports to the crash report server. Each
|
||||
* report will have the "SubmittedFromInfobar" extra key set
|
||||
* to true.
|
||||
*
|
||||
* @param reportIDs (Array<string>)
|
||||
* The array of reportIDs to submit.
|
||||
*/
|
||||
submitReports(reportIDs) {
|
||||
for (let reportID of reportIDs) {
|
||||
CrashSubmit.submit(reportID, {
|
||||
extraExtraKeyVals: {
|
||||
"SubmittedFromInfobar": true,
|
||||
},
|
||||
});
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
this.PluginCrashReporter = {
|
||||
/**
|
||||
* Makes the PluginCrashReporter ready to hear about and
|
||||
|
|
|
|||
|
|
@ -608,11 +608,6 @@ PluginContent.prototype = {
|
|||
{ name, pluginTag });
|
||||
},
|
||||
|
||||
submitReport: function submitReport(plugin) {
|
||||
/*** STUB ***/
|
||||
return;
|
||||
},
|
||||
|
||||
reloadPage: function () {
|
||||
this.global.content.location.reload();
|
||||
},
|
||||
|
|
@ -982,7 +977,6 @@ PluginContent.prototype = {
|
|||
.addEventListener("click", (event) => {
|
||||
if (event.button != 0 || !event.isTrusted)
|
||||
return;
|
||||
this.submitReport(plugin);
|
||||
});
|
||||
|
||||
let pref = Services.prefs.getBranch("dom.ipc.plugins.reportCrashURL");
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue