1 /* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 let Cc = Components.classes;
8 let Ci = Components.interfaces;
9 let Cu = Components.utils;
11 this.EXPORTED_SYMBOLS = [ "TabCrashReporter" ];
13 Cu.import("resource://gre/modules/XPCOMUtils.jsm");
14 Cu.import("resource://gre/modules/Services.jsm");
16 XPCOMUtils.defineLazyModuleGetter(this, "CrashSubmit",
17 "resource://gre/modules/CrashSubmit.jsm");
19 this.TabCrashReporter = {
23 this.initialized = true;
25 Services.obs.addObserver(this, "ipc:content-shutdown", false);
26 Services.obs.addObserver(this, "oop-frameloader-crashed", false);
28 this.childMap = new Map();
29 this.browserMap = new WeakMap();
32 observe: function (aSubject, aTopic, aData) {
34 case "ipc:content-shutdown":
35 aSubject.QueryInterface(Ci.nsIPropertyBag2);
37 if (!aSubject.get("abnormal"))
40 this.childMap.set(aSubject.get("childID"), aSubject.get("dumpID"));
43 case "oop-frameloader-crashed":
44 aSubject.QueryInterface(Ci.nsIFrameLoader);
46 let browser = aSubject.ownerElement;
50 this.browserMap.set(browser, aSubject.childID);
55 submitCrashReport: function (aBrowser) {
56 let childID = this.browserMap.get(aBrowser);
57 let dumpID = this.childMap.get(childID);
61 if (CrashSubmit.submit(dumpID, { recordSubmission: true })) {
62 this.childMap.set(childID, null); // Avoid resubmission.
66 reloadCrashedTabs: function () {
67 let enumerator = Services.wm.getEnumerator("navigator:browser");
68 while (enumerator.hasMoreElements()) {
69 let window = enumerator.getNext();
70 if (!window.gMultiProcessBrowser)
73 for (let browser of window.gBrowser.browsers) {
74 if (browser.isRemoteBrowser)
77 let doc = browser.contentDocument;
78 if (!doc.documentURI.startsWith("about:tabcrashed"))
81 let url = browser.currentURI.spec;
82 window.gBrowser.updateBrowserRemotenessByURL(browser, url);
83 browser.loadURIWithFlags(url, Ci.nsIWebNavigation.LOAD_FLAGS_NONE, null, null, null);
88 onAboutTabCrashedLoad: function (aBrowser) {
92 let dumpID = this.childMap.get(this.browserMap.get(aBrowser));
96 aBrowser.contentDocument.documentElement.classList.add("crashDumpAvaible");