Bug 1885602 - Part 5: Implement navigating to the SUMO help topic from the menu heade...
[gecko.git] / toolkit / crashreporter / CrashReports.sys.mjs
blob3f66da1ec3e4e7ce1db2659a510709ef664db074
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/. */
5 export var CrashReports = {
6   pendingDir: null,
7   reportsDir: null,
8   submittedDir: null,
9   getReports: function CrashReports_getReports() {
10     let reports = [];
12     try {
13       // Ignore any non http/https urls
14       if (!/^https?:/i.test(Services.prefs.getCharPref("breakpad.reportURL"))) {
15         return reports;
16       }
17     } catch (e) {}
19     if (this.submittedDir.exists() && this.submittedDir.isDirectory()) {
20       let entries = this.submittedDir.directoryEntries;
21       while (entries.hasMoreElements()) {
22         let file = entries.nextFile;
23         let leaf = file.leafName;
24         if (leaf.startsWith("bp-") && leaf.endsWith(".txt")) {
25           let entry = {
26             id: leaf.slice(0, -4),
27             date: file.lastModifiedTime,
28             pending: false,
29           };
30           reports.push(entry);
31         }
32       }
33     }
35     if (this.pendingDir.exists() && this.pendingDir.isDirectory()) {
36       let uuidRegex =
37         /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
38       let entries = this.pendingDir.directoryEntries;
39       while (entries.hasMoreElements()) {
40         let file = entries.nextFile;
41         let leaf = file.leafName;
42         let id = leaf.slice(0, -4);
43         if (leaf.endsWith(".dmp") && uuidRegex.test(id)) {
44           let entry = {
45             id,
46             date: file.lastModifiedTime,
47             pending: true,
48           };
49           reports.push(entry);
50         }
51       }
52     }
54     // Sort reports descending by date
55     return reports.sort((a, b) => b.date - a.date);
56   },
59 function CrashReports_pendingDir() {
60   let pendingDir = Services.dirsvc.get("UAppData", Ci.nsIFile);
61   pendingDir.append("Crash Reports");
62   pendingDir.append("pending");
63   return pendingDir;
66 function CrashReports_reportsDir() {
67   let reportsDir = Services.dirsvc.get("UAppData", Ci.nsIFile);
68   reportsDir.append("Crash Reports");
69   return reportsDir;
72 function CrashReports_submittedDir() {
73   let submittedDir = Services.dirsvc.get("UAppData", Ci.nsIFile);
74   submittedDir.append("Crash Reports");
75   submittedDir.append("submitted");
76   return submittedDir;
79 CrashReports.pendingDir = CrashReports_pendingDir();
80 CrashReports.reportsDir = CrashReports_reportsDir();
81 CrashReports.submittedDir = CrashReports_submittedDir();