1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/browser/modules/TabCrashReporter.jsm Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,76 @@ 1.4 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.5 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.6 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.7 + 1.8 +"use strict"; 1.9 + 1.10 +let Cc = Components.classes; 1.11 +let Ci = Components.interfaces; 1.12 +let Cu = Components.utils; 1.13 + 1.14 +this.EXPORTED_SYMBOLS = [ "TabCrashReporter" ]; 1.15 + 1.16 +Cu.import("resource://gre/modules/XPCOMUtils.jsm"); 1.17 +Cu.import("resource://gre/modules/Services.jsm"); 1.18 + 1.19 +XPCOMUtils.defineLazyModuleGetter(this, "CrashSubmit", 1.20 + "resource://gre/modules/CrashSubmit.jsm"); 1.21 + 1.22 +this.TabCrashReporter = { 1.23 + init: function () { 1.24 + if (this.initialized) 1.25 + return; 1.26 + this.initialized = true; 1.27 + 1.28 + Services.obs.addObserver(this, "ipc:content-shutdown", false); 1.29 + Services.obs.addObserver(this, "oop-frameloader-crashed", false); 1.30 + 1.31 + this.childMap = new Map(); 1.32 + this.browserMap = new WeakMap(); 1.33 + }, 1.34 + 1.35 + observe: function (aSubject, aTopic, aData) { 1.36 + switch (aTopic) { 1.37 + case "ipc:content-shutdown": 1.38 + aSubject.QueryInterface(Ci.nsIPropertyBag2); 1.39 + 1.40 + if (!aSubject.get("abnormal")) 1.41 + return; 1.42 + 1.43 + this.childMap.set(aSubject.get("childID"), aSubject.get("dumpID")); 1.44 + break; 1.45 + 1.46 + case "oop-frameloader-crashed": 1.47 + aSubject.QueryInterface(Ci.nsIFrameLoader); 1.48 + 1.49 + let browser = aSubject.ownerElement; 1.50 + if (!browser) 1.51 + return; 1.52 + 1.53 + this.browserMap.set(browser, aSubject.childID); 1.54 + break; 1.55 + } 1.56 + }, 1.57 + 1.58 + submitCrashReport: function (aBrowser) { 1.59 + let childID = this.browserMap.get(aBrowser); 1.60 + let dumpID = this.childMap.get(childID); 1.61 + if (!dumpID) 1.62 + return 1.63 + 1.64 + if (CrashSubmit.submit(dumpID)) { 1.65 + this.childMap.set(childID, null); // Avoid resubmission. 1.66 + } 1.67 + }, 1.68 + 1.69 + onAboutTabCrashedLoad: function (aBrowser) { 1.70 + if (!this.childMap) 1.71 + return; 1.72 + 1.73 + let dumpID = this.childMap.get(this.browserMap.get(aBrowser)); 1.74 + if (!dumpID) 1.75 + return; 1.76 + 1.77 + aBrowser.contentDocument.documentElement.classList.add("crashDumpAvaible"); 1.78 + } 1.79 +}