browser/modules/TabCrashReporter.jsm

branch
TOR_BUG_9701
changeset 14
925c144e1f1f
equal deleted inserted replaced
-1:000000000000 0:54a19b4f3db5
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/. */
4
5 "use strict";
6
7 let Cc = Components.classes;
8 let Ci = Components.interfaces;
9 let Cu = Components.utils;
10
11 this.EXPORTED_SYMBOLS = [ "TabCrashReporter" ];
12
13 Cu.import("resource://gre/modules/XPCOMUtils.jsm");
14 Cu.import("resource://gre/modules/Services.jsm");
15
16 XPCOMUtils.defineLazyModuleGetter(this, "CrashSubmit",
17 "resource://gre/modules/CrashSubmit.jsm");
18
19 this.TabCrashReporter = {
20 init: function () {
21 if (this.initialized)
22 return;
23 this.initialized = true;
24
25 Services.obs.addObserver(this, "ipc:content-shutdown", false);
26 Services.obs.addObserver(this, "oop-frameloader-crashed", false);
27
28 this.childMap = new Map();
29 this.browserMap = new WeakMap();
30 },
31
32 observe: function (aSubject, aTopic, aData) {
33 switch (aTopic) {
34 case "ipc:content-shutdown":
35 aSubject.QueryInterface(Ci.nsIPropertyBag2);
36
37 if (!aSubject.get("abnormal"))
38 return;
39
40 this.childMap.set(aSubject.get("childID"), aSubject.get("dumpID"));
41 break;
42
43 case "oop-frameloader-crashed":
44 aSubject.QueryInterface(Ci.nsIFrameLoader);
45
46 let browser = aSubject.ownerElement;
47 if (!browser)
48 return;
49
50 this.browserMap.set(browser, aSubject.childID);
51 break;
52 }
53 },
54
55 submitCrashReport: function (aBrowser) {
56 let childID = this.browserMap.get(aBrowser);
57 let dumpID = this.childMap.get(childID);
58 if (!dumpID)
59 return
60
61 if (CrashSubmit.submit(dumpID)) {
62 this.childMap.set(childID, null); // Avoid resubmission.
63 }
64 },
65
66 onAboutTabCrashedLoad: function (aBrowser) {
67 if (!this.childMap)
68 return;
69
70 let dumpID = this.childMap.get(this.browserMap.get(aBrowser));
71 if (!dumpID)
72 return;
73
74 aBrowser.contentDocument.documentElement.classList.add("crashDumpAvaible");
75 }
76 }

mercurial