Thu, 22 Jan 2015 13:21:57 +0100
Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6
michael@0 | 1 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 2 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 3 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 4 | |
michael@0 | 5 | "use strict"; |
michael@0 | 6 | |
michael@0 | 7 | let Cc = Components.classes; |
michael@0 | 8 | let Ci = Components.interfaces; |
michael@0 | 9 | let Cu = Components.utils; |
michael@0 | 10 | |
michael@0 | 11 | this.EXPORTED_SYMBOLS = [ "TabCrashReporter" ]; |
michael@0 | 12 | |
michael@0 | 13 | Cu.import("resource://gre/modules/XPCOMUtils.jsm"); |
michael@0 | 14 | Cu.import("resource://gre/modules/Services.jsm"); |
michael@0 | 15 | |
michael@0 | 16 | XPCOMUtils.defineLazyModuleGetter(this, "CrashSubmit", |
michael@0 | 17 | "resource://gre/modules/CrashSubmit.jsm"); |
michael@0 | 18 | |
michael@0 | 19 | this.TabCrashReporter = { |
michael@0 | 20 | init: function () { |
michael@0 | 21 | if (this.initialized) |
michael@0 | 22 | return; |
michael@0 | 23 | this.initialized = true; |
michael@0 | 24 | |
michael@0 | 25 | Services.obs.addObserver(this, "ipc:content-shutdown", false); |
michael@0 | 26 | Services.obs.addObserver(this, "oop-frameloader-crashed", false); |
michael@0 | 27 | |
michael@0 | 28 | this.childMap = new Map(); |
michael@0 | 29 | this.browserMap = new WeakMap(); |
michael@0 | 30 | }, |
michael@0 | 31 | |
michael@0 | 32 | observe: function (aSubject, aTopic, aData) { |
michael@0 | 33 | switch (aTopic) { |
michael@0 | 34 | case "ipc:content-shutdown": |
michael@0 | 35 | aSubject.QueryInterface(Ci.nsIPropertyBag2); |
michael@0 | 36 | |
michael@0 | 37 | if (!aSubject.get("abnormal")) |
michael@0 | 38 | return; |
michael@0 | 39 | |
michael@0 | 40 | this.childMap.set(aSubject.get("childID"), aSubject.get("dumpID")); |
michael@0 | 41 | break; |
michael@0 | 42 | |
michael@0 | 43 | case "oop-frameloader-crashed": |
michael@0 | 44 | aSubject.QueryInterface(Ci.nsIFrameLoader); |
michael@0 | 45 | |
michael@0 | 46 | let browser = aSubject.ownerElement; |
michael@0 | 47 | if (!browser) |
michael@0 | 48 | return; |
michael@0 | 49 | |
michael@0 | 50 | this.browserMap.set(browser, aSubject.childID); |
michael@0 | 51 | break; |
michael@0 | 52 | } |
michael@0 | 53 | }, |
michael@0 | 54 | |
michael@0 | 55 | submitCrashReport: function (aBrowser) { |
michael@0 | 56 | let childID = this.browserMap.get(aBrowser); |
michael@0 | 57 | let dumpID = this.childMap.get(childID); |
michael@0 | 58 | if (!dumpID) |
michael@0 | 59 | return |
michael@0 | 60 | |
michael@0 | 61 | if (CrashSubmit.submit(dumpID)) { |
michael@0 | 62 | this.childMap.set(childID, null); // Avoid resubmission. |
michael@0 | 63 | } |
michael@0 | 64 | }, |
michael@0 | 65 | |
michael@0 | 66 | onAboutTabCrashedLoad: function (aBrowser) { |
michael@0 | 67 | if (!this.childMap) |
michael@0 | 68 | return; |
michael@0 | 69 | |
michael@0 | 70 | let dumpID = this.childMap.get(this.browserMap.get(aBrowser)); |
michael@0 | 71 | if (!dumpID) |
michael@0 | 72 | return; |
michael@0 | 73 | |
michael@0 | 74 | aBrowser.contentDocument.documentElement.classList.add("crashDumpAvaible"); |
michael@0 | 75 | } |
michael@0 | 76 | } |