toolkit/crashreporter/CrashReports.jsm

branch
TOR_BUG_3246
changeset 7
129ffea94266
equal deleted inserted replaced
-1:000000000000 0:ee661ff09cec
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 Components.utils.import("resource://gre/modules/Services.jsm");
6
7 this.EXPORTED_SYMBOLS = [
8 "CrashReports"
9 ];
10
11 this.CrashReports = {
12 pendingDir: null,
13 reportsDir: null,
14 submittedDir: null,
15 getReports: function CrashReports_getReports()
16 {
17 let reports = [];
18
19 try {
20 // Ignore any non http/https urls
21 if (!/^https?:/i.test(Services.prefs.getCharPref("breakpad.reportURL")))
22 return reports;
23 }
24 catch (e) { }
25
26 if (this.submittedDir.exists() && this.submittedDir.isDirectory()) {
27 let entries = this.submittedDir.directoryEntries;
28 while (entries.hasMoreElements()) {
29 let file = entries.getNext().QueryInterface(Components.interfaces.nsIFile);
30 let leaf = file.leafName;
31 if (leaf.startsWith("bp-") &&
32 leaf.endsWith(".txt")) {
33 let entry = {
34 id: leaf.slice(0, -4),
35 date: file.lastModifiedTime,
36 pending: false
37 };
38 reports.push(entry);
39 }
40 }
41 }
42
43 if (this.pendingDir.exists() && this.pendingDir.isDirectory()) {
44 let uuidRegex = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
45 let entries = this.pendingDir.directoryEntries;
46 while (entries.hasMoreElements()) {
47 let file = entries.getNext().QueryInterface(Components.interfaces.nsIFile);
48 let leaf = file.leafName;
49 let id = leaf.slice(0, -4);
50 if (leaf.endsWith(".dmp") && uuidRegex.test(id)) {
51 let entry = {
52 id: id,
53 date: file.lastModifiedTime,
54 pending: true
55 };
56 reports.push(entry);
57 }
58 }
59 }
60
61 // Sort reports descending by date
62 return reports.sort( (a, b) => b.date - a.date);
63 }
64 }
65
66 function CrashReports_pendingDir()
67 {
68 let pendingDir = Services.dirsvc.get("UAppData", Components.interfaces.nsIFile);
69 pendingDir.append("Crash Reports");
70 pendingDir.append("pending");
71 return pendingDir;
72 }
73
74 function CrashReports_reportsDir()
75 {
76 let reportsDir = Services.dirsvc.get("UAppData", Components.interfaces.nsIFile);
77 reportsDir.append("Crash Reports");
78 return reportsDir;
79 }
80
81 function CrashReports_submittedDir()
82 {
83 let submittedDir = Services.dirsvc.get("UAppData", Components.interfaces.nsIFile);
84 submittedDir.append("Crash Reports");
85 submittedDir.append("submitted");
86 return submittedDir;
87 }
88
89 this.CrashReports.pendingDir = CrashReports_pendingDir();
90 this.CrashReports.reportsDir = CrashReports_reportsDir();
91 this.CrashReports.submittedDir = CrashReports_submittedDir();

mercurial