2015-01-17 05:34:47 +03:00
|
|
|
/* -*- mode: js; indent-tabs-mode: nil; js-indent-level: 2 -*- */
|
|
|
|
/* 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";
|
|
|
|
|
2018-02-23 22:50:01 +03:00
|
|
|
var EXPORTED_SYMBOLS = ["ProcessHangMonitor"];
|
2015-01-17 05:34:47 +03:00
|
|
|
|
2018-01-30 02:20:18 +03:00
|
|
|
ChromeUtils.import("resource://gre/modules/AppConstants.jsm");
|
|
|
|
ChromeUtils.import("resource://gre/modules/Services.jsm");
|
2015-01-17 05:34:47 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* This JSM is responsible for observing content process hang reports
|
|
|
|
* and asking the user what to do about them. See nsIHangReport for
|
|
|
|
* the platform interface.
|
|
|
|
*/
|
|
|
|
|
2015-10-26 16:40:28 +03:00
|
|
|
var ProcessHangMonitor = {
|
2015-11-02 15:37:25 +03:00
|
|
|
/**
|
|
|
|
* This timeout is the wait period applied after a user selects "Wait" in
|
|
|
|
* an existing notification.
|
|
|
|
*/
|
|
|
|
get WAIT_EXPIRATION_TIME() {
|
|
|
|
try {
|
|
|
|
return Services.prefs.getIntPref("browser.hangNotification.waitPeriod");
|
|
|
|
} catch (ex) {
|
|
|
|
return 10000;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2017-10-03 01:38:27 +03:00
|
|
|
/**
|
|
|
|
* Should only be set to true once the quit-application-granted notification
|
|
|
|
* has been fired.
|
|
|
|
*/
|
|
|
|
_shuttingDown: false,
|
|
|
|
|
2015-01-17 05:34:47 +03:00
|
|
|
/**
|
|
|
|
* Collection of hang reports that haven't expired or been dismissed
|
2016-04-02 02:54:25 +03:00
|
|
|
* by the user. These are nsIHangReports.
|
2015-01-17 05:34:47 +03:00
|
|
|
*/
|
2016-04-02 02:54:25 +03:00
|
|
|
_activeReports: new Set(),
|
2015-01-17 05:34:47 +03:00
|
|
|
|
2015-11-02 15:37:25 +03:00
|
|
|
/**
|
2016-04-02 02:54:25 +03:00
|
|
|
* Collection of hang reports that have been suppressed for a short
|
|
|
|
* period of time. Value is an nsITimer for when the wait time
|
|
|
|
* expires.
|
2015-11-02 15:37:25 +03:00
|
|
|
*/
|
|
|
|
_pausedReports: new Map(),
|
|
|
|
|
2015-01-17 05:34:47 +03:00
|
|
|
/**
|
|
|
|
* Initialize hang reporting. Called once in the parent process.
|
|
|
|
*/
|
2016-12-30 02:34:54 +03:00
|
|
|
init() {
|
2017-04-14 22:51:38 +03:00
|
|
|
Services.obs.addObserver(this, "process-hang-report");
|
|
|
|
Services.obs.addObserver(this, "clear-hang-report");
|
2017-10-03 01:38:27 +03:00
|
|
|
Services.obs.addObserver(this, "quit-application-granted");
|
2017-04-14 22:51:38 +03:00
|
|
|
Services.obs.addObserver(this, "xpcom-shutdown");
|
2015-01-17 05:34:47 +03:00
|
|
|
Services.ww.registerNotification(this);
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Terminate JavaScript associated with the hang being reported for
|
|
|
|
* the selected browser in |win|.
|
|
|
|
*/
|
2016-12-30 02:34:54 +03:00
|
|
|
terminateScript(win) {
|
2015-01-17 05:34:47 +03:00
|
|
|
this.handleUserInput(win, report => report.terminateScript());
|
|
|
|
},
|
|
|
|
|
2017-04-17 00:01:16 +03:00
|
|
|
/**
|
|
|
|
* Terminate Sandbox globals associated with the hang being reported
|
|
|
|
* for the selected browser in |win|.
|
|
|
|
*/
|
|
|
|
terminateGlobal(win) {
|
|
|
|
this.handleUserInput(win, report => report.terminateGlobal());
|
|
|
|
},
|
|
|
|
|
2015-01-17 05:34:47 +03:00
|
|
|
/**
|
|
|
|
* Start devtools debugger for JavaScript associated with the hang
|
|
|
|
* being reported for the selected browser in |win|.
|
|
|
|
*/
|
2016-12-30 02:34:54 +03:00
|
|
|
debugScript(win) {
|
2015-01-17 05:34:47 +03:00
|
|
|
this.handleUserInput(win, report => {
|
|
|
|
function callback() {
|
|
|
|
report.endStartingDebugger();
|
|
|
|
}
|
|
|
|
|
|
|
|
report.beginStartingDebugger();
|
|
|
|
|
|
|
|
let svc = Cc["@mozilla.org/dom/slow-script-debug;1"].getService(Ci.nsISlowScriptDebug);
|
|
|
|
let handler = svc.remoteActivationHandler;
|
|
|
|
handler.handleSlowScriptDebug(report.scriptBrowser, callback);
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
2015-11-02 15:37:25 +03:00
|
|
|
* Terminate the plugin process associated with a hang being reported
|
|
|
|
* for the selected browser in |win|. Will attempt to generate a combined
|
|
|
|
* crash report for all processes.
|
2015-01-17 05:34:47 +03:00
|
|
|
*/
|
2016-12-30 02:34:54 +03:00
|
|
|
terminatePlugin(win) {
|
2015-01-17 05:34:47 +03:00
|
|
|
this.handleUserInput(win, report => report.terminatePlugin());
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
2015-11-02 15:37:25 +03:00
|
|
|
* Dismiss the browser notification and invoke an appropriate action based on
|
|
|
|
* the hang type.
|
2015-01-17 05:34:47 +03:00
|
|
|
*/
|
2016-12-30 02:34:54 +03:00
|
|
|
stopIt(win) {
|
2015-11-02 15:37:25 +03:00
|
|
|
let report = this.findActiveReport(win.gBrowser.selectedBrowser);
|
|
|
|
if (!report) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (report.hangType) {
|
|
|
|
case report.SLOW_SCRIPT:
|
|
|
|
this.terminateScript(win);
|
|
|
|
break;
|
|
|
|
case report.PLUGIN_HANG:
|
|
|
|
this.terminatePlugin(win);
|
|
|
|
break;
|
|
|
|
}
|
2015-01-17 05:34:47 +03:00
|
|
|
},
|
|
|
|
|
2017-04-17 00:01:16 +03:00
|
|
|
/**
|
|
|
|
* Stop all scripts from running in the Sandbox global attached to
|
|
|
|
* this window.
|
|
|
|
*/
|
|
|
|
stopGlobal(win) {
|
|
|
|
let report = this.findActiveReport(win.gBrowser.selectedBrowser);
|
|
|
|
if (!report) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (report.hangType) {
|
|
|
|
case report.SLOW_SCRIPT:
|
|
|
|
this.terminateGlobal(win);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2017-10-03 01:38:27 +03:00
|
|
|
/**
|
|
|
|
* Terminate whatever is causing this report, be it an add-on, page script,
|
|
|
|
* or plug-in. This is done without updating any report notifications.
|
|
|
|
*/
|
|
|
|
stopHang(report) {
|
|
|
|
switch (report.hangType) {
|
|
|
|
case report.SLOW_SCRIPT: {
|
|
|
|
if (report.addonId) {
|
|
|
|
report.terminateGlobal();
|
|
|
|
} else {
|
|
|
|
report.terminateScript();
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case report.PLUGIN_HANG: {
|
|
|
|
report.terminatePlugin();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2015-01-17 05:34:47 +03:00
|
|
|
/**
|
2015-11-02 15:37:25 +03:00
|
|
|
* Dismiss the notification, clear the report from the active list and set up
|
|
|
|
* a new timer to track a wait period during which we won't notify.
|
2015-01-17 05:34:47 +03:00
|
|
|
*/
|
2016-12-30 02:34:54 +03:00
|
|
|
waitLonger(win) {
|
2015-11-02 15:37:25 +03:00
|
|
|
let report = this.findActiveReport(win.gBrowser.selectedBrowser);
|
2015-01-17 05:34:47 +03:00
|
|
|
if (!report) {
|
|
|
|
return;
|
|
|
|
}
|
2016-04-02 02:54:25 +03:00
|
|
|
// Remove the report from the active list.
|
2015-11-02 15:37:25 +03:00
|
|
|
this.removeActiveReport(report);
|
2015-01-17 05:34:47 +03:00
|
|
|
|
2015-11-02 15:37:25 +03:00
|
|
|
// NOTE, we didn't call userCanceled on nsIHangReport here. This insures
|
|
|
|
// we don't repeatedly generate and cache crash report data for this hang
|
|
|
|
// in the process hang reporter. It already has one report for the browser
|
|
|
|
// process we want it hold onto.
|
2015-10-23 22:39:22 +03:00
|
|
|
|
2015-11-02 15:37:25 +03:00
|
|
|
// Create a new wait timer with notify callback
|
|
|
|
let timer = Cc["@mozilla.org/timer;1"].createInstance(Ci.nsITimer);
|
|
|
|
timer.initWithCallback(() => {
|
|
|
|
for (let [stashedReport, otherTimer] of this._pausedReports) {
|
|
|
|
if (otherTimer === timer) {
|
|
|
|
this.removePausedReport(stashedReport);
|
|
|
|
|
2016-04-02 02:54:25 +03:00
|
|
|
// We're still hung, so move the report back to the active
|
|
|
|
// list and update the UI.
|
|
|
|
this._activeReports.add(report);
|
|
|
|
this.updateWindows();
|
2015-11-02 15:37:25 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}, this.WAIT_EXPIRATION_TIME, timer.TYPE_ONE_SHOT);
|
|
|
|
|
|
|
|
this._pausedReports.set(report, timer);
|
|
|
|
|
|
|
|
// remove the browser notification associated with this hang
|
|
|
|
this.updateWindows();
|
2015-01-17 05:34:47 +03:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* If there is a hang report associated with the selected browser in
|
|
|
|
* |win|, invoke |func| on that report and stop notifying the user
|
|
|
|
* about it.
|
|
|
|
*/
|
2016-12-30 02:34:54 +03:00
|
|
|
handleUserInput(win, func) {
|
2015-11-02 15:37:25 +03:00
|
|
|
let report = this.findActiveReport(win.gBrowser.selectedBrowser);
|
2015-01-17 05:34:47 +03:00
|
|
|
if (!report) {
|
2015-12-17 21:31:08 +03:00
|
|
|
return null;
|
2015-01-17 05:34:47 +03:00
|
|
|
}
|
2015-11-02 15:37:25 +03:00
|
|
|
this.removeActiveReport(report);
|
2015-01-17 05:34:47 +03:00
|
|
|
|
|
|
|
return func(report);
|
|
|
|
},
|
|
|
|
|
2016-12-30 02:34:54 +03:00
|
|
|
observe(subject, topic, data) {
|
2015-01-17 05:34:47 +03:00
|
|
|
switch (topic) {
|
2017-10-03 01:38:27 +03:00
|
|
|
case "xpcom-shutdown": {
|
2015-01-17 05:34:47 +03:00
|
|
|
Services.obs.removeObserver(this, "xpcom-shutdown");
|
|
|
|
Services.obs.removeObserver(this, "process-hang-report");
|
2016-04-02 02:54:25 +03:00
|
|
|
Services.obs.removeObserver(this, "clear-hang-report");
|
2017-10-03 01:38:27 +03:00
|
|
|
Services.obs.removeObserver(this, "quit-application-granted");
|
2015-01-17 05:34:47 +03:00
|
|
|
Services.ww.unregisterNotification(this);
|
|
|
|
break;
|
2017-10-03 01:38:27 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
case "quit-application-granted": {
|
|
|
|
this.onQuitApplicationGranted();
|
|
|
|
break;
|
|
|
|
}
|
2015-01-17 05:34:47 +03:00
|
|
|
|
2017-10-03 01:38:27 +03:00
|
|
|
case "process-hang-report": {
|
2015-01-17 05:34:47 +03:00
|
|
|
this.reportHang(subject.QueryInterface(Ci.nsIHangReport));
|
|
|
|
break;
|
2017-10-03 01:38:27 +03:00
|
|
|
}
|
2015-01-17 05:34:47 +03:00
|
|
|
|
2017-10-03 01:38:27 +03:00
|
|
|
case "clear-hang-report": {
|
2016-04-02 02:54:25 +03:00
|
|
|
this.clearHang(subject.QueryInterface(Ci.nsIHangReport));
|
|
|
|
break;
|
2017-10-03 01:38:27 +03:00
|
|
|
}
|
2016-04-02 02:54:25 +03:00
|
|
|
|
2017-10-03 01:38:27 +03:00
|
|
|
case "domwindowopened": {
|
2015-01-17 05:34:47 +03:00
|
|
|
// Install event listeners on the new window in case one of
|
|
|
|
// its tabs is already hung.
|
|
|
|
let win = subject.QueryInterface(Ci.nsIDOMWindow);
|
|
|
|
let listener = (ev) => {
|
|
|
|
win.removeEventListener("load", listener, true);
|
|
|
|
this.updateWindows();
|
|
|
|
};
|
|
|
|
win.addEventListener("load", listener, true);
|
|
|
|
break;
|
2017-10-03 01:38:27 +03:00
|
|
|
}
|
2017-10-13 23:15:44 +03:00
|
|
|
|
|
|
|
case "domwindowclosed": {
|
|
|
|
let win = subject.QueryInterface(Ci.nsIDOMWindow);
|
|
|
|
this.onWindowClosed(win);
|
|
|
|
break;
|
|
|
|
}
|
2017-10-03 01:38:27 +03:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Called early on in the shutdown sequence. We take this opportunity to
|
|
|
|
* take any pre-existing hang reports, and terminate them. We also put
|
|
|
|
* ourselves in a state so that if any more hang reports show up while
|
|
|
|
* we're shutting down, we terminate them immediately.
|
|
|
|
*/
|
|
|
|
onQuitApplicationGranted() {
|
|
|
|
this._shuttingDown = true;
|
|
|
|
this.stopAllHangs();
|
|
|
|
this.updateWindows();
|
|
|
|
},
|
|
|
|
|
2017-10-13 23:15:44 +03:00
|
|
|
onWindowClosed(win) {
|
|
|
|
let maybeStopHang = (report) => {
|
|
|
|
if (report.hangType == report.SLOW_SCRIPT) {
|
|
|
|
let hungBrowserWindow = null;
|
|
|
|
try {
|
|
|
|
hungBrowserWindow = report.scriptBrowser.ownerGlobal;
|
|
|
|
} catch (e) {
|
|
|
|
// Ignore failures to get the script browser - we'll be
|
|
|
|
// conservative, and assume that if we cannot access the
|
|
|
|
// window that belongs to this report that we should stop
|
|
|
|
// the hang.
|
|
|
|
}
|
|
|
|
if (!hungBrowserWindow || hungBrowserWindow == win) {
|
|
|
|
this.stopHang(report);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
} else if (report.hangType == report.PLUGIN_HANG) {
|
|
|
|
// If any window has closed during a plug-in hang, we'll
|
|
|
|
// do the conservative thing and terminate the plug-in.
|
|
|
|
this.stopHang(report);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
2017-05-28 21:57:46 +03:00
|
|
|
};
|
2017-10-13 23:15:44 +03:00
|
|
|
|
|
|
|
// If there are any script hangs for browsers that are in this window
|
|
|
|
// that is closing, we can stop them now.
|
|
|
|
for (let report of this._activeReports) {
|
|
|
|
if (maybeStopHang(report)) {
|
|
|
|
this._activeReports.delete(report);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-08-31 08:59:17 +03:00
|
|
|
for (let [pausedReport ] of this._pausedReports) {
|
2017-10-13 23:15:44 +03:00
|
|
|
if (maybeStopHang(pausedReport)) {
|
|
|
|
this.removePausedReport(pausedReport);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
this.updateWindows();
|
|
|
|
},
|
|
|
|
|
2017-10-03 01:38:27 +03:00
|
|
|
stopAllHangs() {
|
|
|
|
for (let report of this._activeReports) {
|
|
|
|
this.stopHang(report);
|
|
|
|
}
|
|
|
|
|
|
|
|
this._activeReports = new Set();
|
|
|
|
|
2018-08-31 08:59:17 +03:00
|
|
|
for (let [pausedReport ] of this._pausedReports) {
|
2017-10-03 01:38:27 +03:00
|
|
|
this.stopHang(pausedReport);
|
|
|
|
this.removePausedReport(pausedReport);
|
2015-01-17 05:34:47 +03:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
2015-11-02 15:37:25 +03:00
|
|
|
* Find a active hang report for the given <browser> element.
|
2015-01-17 05:34:47 +03:00
|
|
|
*/
|
2016-12-30 02:34:54 +03:00
|
|
|
findActiveReport(browser) {
|
2017-08-19 23:32:58 +03:00
|
|
|
let frameLoader = browser.frameLoader;
|
2016-04-02 02:54:25 +03:00
|
|
|
for (let report of this._activeReports) {
|
2015-01-17 05:34:47 +03:00
|
|
|
if (report.isReportForBrowser(frameLoader)) {
|
|
|
|
return report;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
},
|
|
|
|
|
2015-11-02 15:37:25 +03:00
|
|
|
/**
|
|
|
|
* Find a paused hang report for the given <browser> element.
|
|
|
|
*/
|
2016-12-30 02:34:54 +03:00
|
|
|
findPausedReport(browser) {
|
2017-08-19 23:32:58 +03:00
|
|
|
let frameLoader = browser.frameLoader;
|
2018-08-31 08:59:17 +03:00
|
|
|
for (let [report ] of this._pausedReports) {
|
2015-11-02 15:37:25 +03:00
|
|
|
if (report.isReportForBrowser(frameLoader)) {
|
|
|
|
return report;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Remove an active hang report from the active list and cancel the timer
|
|
|
|
* associated with it.
|
|
|
|
*/
|
2016-12-30 02:34:54 +03:00
|
|
|
removeActiveReport(report) {
|
2015-11-02 15:37:25 +03:00
|
|
|
this._activeReports.delete(report);
|
|
|
|
this.updateWindows();
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Remove a paused hang report from the paused list and cancel the timer
|
|
|
|
* associated with it.
|
|
|
|
*/
|
2016-12-30 02:34:54 +03:00
|
|
|
removePausedReport(report) {
|
2015-11-02 15:37:25 +03:00
|
|
|
let timer = this._pausedReports.get(report);
|
|
|
|
if (timer) {
|
|
|
|
timer.cancel();
|
|
|
|
}
|
|
|
|
this._pausedReports.delete(report);
|
|
|
|
},
|
|
|
|
|
2015-01-17 05:34:47 +03:00
|
|
|
/**
|
|
|
|
* Iterate over all XUL windows and ensure that the proper hang
|
|
|
|
* reports are shown for each one. Also install event handlers in
|
|
|
|
* each window to watch for events that would cause a different hang
|
|
|
|
* report to be displayed.
|
|
|
|
*/
|
2016-12-30 02:34:54 +03:00
|
|
|
updateWindows() {
|
2015-01-17 05:34:47 +03:00
|
|
|
let e = Services.wm.getEnumerator("navigator:browser");
|
2017-10-03 01:38:27 +03:00
|
|
|
|
|
|
|
// If it turns out we have no windows (this can happen on macOS),
|
|
|
|
// we have no opportunity to ask the user whether or not they want
|
|
|
|
// to stop the hang or wait, so we'll opt for stopping the hang.
|
|
|
|
if (!e.hasMoreElements()) {
|
|
|
|
this.stopAllHangs();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-08-19 05:27:33 +03:00
|
|
|
for (let win of e) {
|
2015-01-17 05:34:47 +03:00
|
|
|
this.updateWindow(win);
|
|
|
|
|
|
|
|
// Only listen for these events if there are active hang reports.
|
|
|
|
if (this._activeReports.size) {
|
|
|
|
this.trackWindow(win);
|
|
|
|
} else {
|
|
|
|
this.untrackWindow(win);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* If there is a hang report for the current tab in |win|, display it.
|
|
|
|
*/
|
2016-12-30 02:34:54 +03:00
|
|
|
updateWindow(win) {
|
2015-11-02 15:37:25 +03:00
|
|
|
let report = this.findActiveReport(win.gBrowser.selectedBrowser);
|
2015-01-17 05:34:47 +03:00
|
|
|
|
|
|
|
if (report) {
|
|
|
|
this.showNotification(win, report);
|
|
|
|
} else {
|
|
|
|
this.hideNotification(win);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Show the notification for a hang.
|
|
|
|
*/
|
2016-12-30 02:34:54 +03:00
|
|
|
showNotification(win, report) {
|
2015-01-17 05:34:47 +03:00
|
|
|
let nb = win.document.getElementById("high-priority-global-notificationbox");
|
|
|
|
let notification = nb.getNotificationWithValue("process-hang");
|
|
|
|
if (notification) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
let bundle = win.gNavigatorBundle;
|
|
|
|
|
|
|
|
let buttons = [{
|
2015-11-02 15:37:25 +03:00
|
|
|
label: bundle.getString("processHang.button_stop.label"),
|
|
|
|
accessKey: bundle.getString("processHang.button_stop.accessKey"),
|
2016-12-30 02:34:54 +03:00
|
|
|
callback() {
|
2015-11-02 15:37:25 +03:00
|
|
|
ProcessHangMonitor.stopIt(win);
|
2018-08-31 08:59:17 +03:00
|
|
|
},
|
2015-11-02 15:37:25 +03:00
|
|
|
},
|
|
|
|
{
|
|
|
|
label: bundle.getString("processHang.button_wait.label"),
|
|
|
|
accessKey: bundle.getString("processHang.button_wait.accessKey"),
|
2016-12-30 02:34:54 +03:00
|
|
|
callback() {
|
2015-11-02 15:37:25 +03:00
|
|
|
ProcessHangMonitor.waitLonger(win);
|
2018-08-31 08:59:17 +03:00
|
|
|
},
|
2015-11-02 15:37:25 +03:00
|
|
|
}];
|
|
|
|
|
2017-08-18 06:17:51 +03:00
|
|
|
let message = bundle.getString("processHang.label");
|
|
|
|
if (report.addonId) {
|
|
|
|
let aps = Cc["@mozilla.org/addons/policy-service;1"].getService(Ci.nsIAddonPolicyService);
|
|
|
|
|
|
|
|
let doc = win.document;
|
|
|
|
let brandBundle = doc.getElementById("bundle_brand");
|
|
|
|
|
|
|
|
let addonName = aps.getExtensionName(report.addonId);
|
|
|
|
|
|
|
|
let label = bundle.getFormattedString("processHang.add-on.label",
|
|
|
|
[addonName, brandBundle.getString("brandShortName")]);
|
|
|
|
|
|
|
|
let linkText = bundle.getString("processHang.add-on.learn-more.text");
|
2017-08-20 11:52:32 +03:00
|
|
|
let linkURL = "https://support.mozilla.org/kb/warning-unresponsive-script#w_other-causes";
|
2017-08-18 06:17:51 +03:00
|
|
|
|
2018-08-25 03:16:27 +03:00
|
|
|
let link = doc.createXULElement("label");
|
2017-08-18 06:17:51 +03:00
|
|
|
link.setAttribute("class", "text-link");
|
|
|
|
link.setAttribute("role", "link");
|
2018-02-21 17:28:48 +03:00
|
|
|
link.setAttribute("onclick", `openTrustedLinkIn(${JSON.stringify(linkURL)}, "tab")`);
|
2017-08-18 06:17:51 +03:00
|
|
|
link.setAttribute("value", linkText);
|
|
|
|
|
|
|
|
message = doc.createDocumentFragment();
|
|
|
|
message.appendChild(doc.createTextNode(label + " "));
|
|
|
|
message.appendChild(link);
|
2017-04-17 00:01:16 +03:00
|
|
|
|
|
|
|
buttons.unshift({
|
|
|
|
label: bundle.getString("processHang.button_stop_sandbox.label"),
|
|
|
|
accessKey: bundle.getString("processHang.button_stop_sandbox.accessKey"),
|
|
|
|
callback() {
|
|
|
|
ProcessHangMonitor.stopGlobal(win);
|
2018-08-31 08:59:17 +03:00
|
|
|
},
|
2017-04-17 00:01:16 +03:00
|
|
|
});
|
2017-08-18 06:17:51 +03:00
|
|
|
}
|
|
|
|
|
2015-12-17 21:31:08 +03:00
|
|
|
if (AppConstants.MOZ_DEV_EDITION && report.hangType == report.SLOW_SCRIPT) {
|
2015-11-02 15:37:25 +03:00
|
|
|
buttons.push({
|
|
|
|
label: bundle.getString("processHang.button_debug.label"),
|
|
|
|
accessKey: bundle.getString("processHang.button_debug.accessKey"),
|
2016-12-30 02:34:54 +03:00
|
|
|
callback() {
|
2015-11-02 15:37:25 +03:00
|
|
|
ProcessHangMonitor.debugScript(win);
|
2018-08-31 08:59:17 +03:00
|
|
|
},
|
2015-11-02 15:37:25 +03:00
|
|
|
});
|
|
|
|
}
|
2015-01-17 05:34:47 +03:00
|
|
|
|
2017-08-18 06:17:51 +03:00
|
|
|
nb.appendNotification(message, "process-hang",
|
2015-01-17 05:34:47 +03:00
|
|
|
"chrome://browser/content/aboutRobots-icon.png",
|
|
|
|
nb.PRIORITY_WARNING_HIGH, buttons);
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Ensure that no hang notifications are visible in |win|.
|
|
|
|
*/
|
2016-12-30 02:34:54 +03:00
|
|
|
hideNotification(win) {
|
2015-01-17 05:34:47 +03:00
|
|
|
let nb = win.document.getElementById("high-priority-global-notificationbox");
|
|
|
|
let notification = nb.getNotificationWithValue("process-hang");
|
|
|
|
if (notification) {
|
|
|
|
nb.removeNotification(notification);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Install event handlers on |win| to watch for events that would
|
|
|
|
* cause a different hang report to be displayed.
|
|
|
|
*/
|
2016-12-30 02:34:54 +03:00
|
|
|
trackWindow(win) {
|
2015-01-17 05:34:47 +03:00
|
|
|
win.gBrowser.tabContainer.addEventListener("TabSelect", this, true);
|
|
|
|
win.gBrowser.tabContainer.addEventListener("TabRemotenessChange", this, true);
|
|
|
|
},
|
|
|
|
|
2016-12-30 02:34:54 +03:00
|
|
|
untrackWindow(win) {
|
2015-01-17 05:34:47 +03:00
|
|
|
win.gBrowser.tabContainer.removeEventListener("TabSelect", this, true);
|
|
|
|
win.gBrowser.tabContainer.removeEventListener("TabRemotenessChange", this, true);
|
|
|
|
},
|
|
|
|
|
2016-12-30 02:34:54 +03:00
|
|
|
handleEvent(event) {
|
2016-07-16 11:20:04 +03:00
|
|
|
let win = event.target.ownerGlobal;
|
2015-01-17 05:34:47 +03:00
|
|
|
|
|
|
|
// If a new tab is selected or if a tab changes remoteness, then
|
|
|
|
// we may need to show or hide a hang notification.
|
|
|
|
|
|
|
|
if (event.type == "TabSelect" || event.type == "TabRemotenessChange") {
|
|
|
|
this.updateWindow(win);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handle a potentially new hang report. If it hasn't been seen
|
|
|
|
* before, show a notification for it in all open XUL windows.
|
|
|
|
*/
|
2016-12-30 02:34:54 +03:00
|
|
|
reportHang(report) {
|
2017-10-03 01:38:27 +03:00
|
|
|
if (this._shuttingDown) {
|
|
|
|
this.stopHang(report);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-11-02 15:37:25 +03:00
|
|
|
// If this hang was already reported reset the timer for it.
|
2015-01-17 05:34:47 +03:00
|
|
|
if (this._activeReports.has(report)) {
|
2015-11-02 15:37:25 +03:00
|
|
|
// if this report is in active but doesn't have a notification associated
|
|
|
|
// with it, display a notification.
|
|
|
|
this.updateWindows();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If this hang was already reported and paused by the user ignore it.
|
|
|
|
if (this._pausedReports.has(report)) {
|
2015-01-17 05:34:47 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-02-06 17:02:37 +03:00
|
|
|
// On e10s this counts slow-script/hanged-plugin notice only once.
|
|
|
|
// This code is not reached on non-e10s.
|
|
|
|
if (report.hangType == report.SLOW_SCRIPT) {
|
|
|
|
// On non-e10s, SLOW_SCRIPT_NOTICE_COUNT is probed at nsGlobalWindow.cpp
|
|
|
|
Services.telemetry.getHistogramById("SLOW_SCRIPT_NOTICE_COUNT").add();
|
|
|
|
} else if (report.hangType == report.PLUGIN_HANG) {
|
|
|
|
// On non-e10s we have sufficient plugin telemetry probes,
|
|
|
|
// so PLUGIN_HANG_NOTICE_COUNT is only probed on e10s.
|
|
|
|
Services.telemetry.getHistogramById("PLUGIN_HANG_NOTICE_COUNT").add();
|
|
|
|
}
|
|
|
|
|
2016-04-02 02:54:25 +03:00
|
|
|
this._activeReports.add(report);
|
2015-01-17 05:34:47 +03:00
|
|
|
this.updateWindows();
|
|
|
|
},
|
|
|
|
|
2016-12-30 02:34:54 +03:00
|
|
|
clearHang(report) {
|
2016-04-02 02:54:25 +03:00
|
|
|
this.removeActiveReport(report);
|
|
|
|
this.removePausedReport(report);
|
|
|
|
report.userCanceled();
|
2015-01-17 05:34:47 +03:00
|
|
|
},
|
|
|
|
};
|