michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: Components.utils.import("resource://gre/modules/Services.jsm"); michael@0: michael@0: this.EXPORTED_SYMBOLS = [ michael@0: "CrashReports" michael@0: ]; michael@0: michael@0: this.CrashReports = { michael@0: pendingDir: null, michael@0: reportsDir: null, michael@0: submittedDir: null, michael@0: getReports: function CrashReports_getReports() michael@0: { michael@0: let reports = []; michael@0: michael@0: try { michael@0: // Ignore any non http/https urls michael@0: if (!/^https?:/i.test(Services.prefs.getCharPref("breakpad.reportURL"))) michael@0: return reports; michael@0: } michael@0: catch (e) { } michael@0: michael@0: if (this.submittedDir.exists() && this.submittedDir.isDirectory()) { michael@0: let entries = this.submittedDir.directoryEntries; michael@0: while (entries.hasMoreElements()) { michael@0: let file = entries.getNext().QueryInterface(Components.interfaces.nsIFile); michael@0: let leaf = file.leafName; michael@0: if (leaf.startsWith("bp-") && michael@0: leaf.endsWith(".txt")) { michael@0: let entry = { michael@0: id: leaf.slice(0, -4), michael@0: date: file.lastModifiedTime, michael@0: pending: false michael@0: }; michael@0: reports.push(entry); michael@0: } michael@0: } michael@0: } michael@0: michael@0: if (this.pendingDir.exists() && this.pendingDir.isDirectory()) { michael@0: let uuidRegex = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i; michael@0: let entries = this.pendingDir.directoryEntries; michael@0: while (entries.hasMoreElements()) { michael@0: let file = entries.getNext().QueryInterface(Components.interfaces.nsIFile); michael@0: let leaf = file.leafName; michael@0: let id = leaf.slice(0, -4); michael@0: if (leaf.endsWith(".dmp") && uuidRegex.test(id)) { michael@0: let entry = { michael@0: id: id, michael@0: date: file.lastModifiedTime, michael@0: pending: true michael@0: }; michael@0: reports.push(entry); michael@0: } michael@0: } michael@0: } michael@0: michael@0: // Sort reports descending by date michael@0: return reports.sort( (a, b) => b.date - a.date); michael@0: } michael@0: } michael@0: michael@0: function CrashReports_pendingDir() michael@0: { michael@0: let pendingDir = Services.dirsvc.get("UAppData", Components.interfaces.nsIFile); michael@0: pendingDir.append("Crash Reports"); michael@0: pendingDir.append("pending"); michael@0: return pendingDir; michael@0: } michael@0: michael@0: function CrashReports_reportsDir() michael@0: { michael@0: let reportsDir = Services.dirsvc.get("UAppData", Components.interfaces.nsIFile); michael@0: reportsDir.append("Crash Reports"); michael@0: return reportsDir; michael@0: } michael@0: michael@0: function CrashReports_submittedDir() michael@0: { michael@0: let submittedDir = Services.dirsvc.get("UAppData", Components.interfaces.nsIFile); michael@0: submittedDir.append("Crash Reports"); michael@0: submittedDir.append("submitted"); michael@0: return submittedDir; michael@0: } michael@0: michael@0: this.CrashReports.pendingDir = CrashReports_pendingDir(); michael@0: this.CrashReports.reportsDir = CrashReports_reportsDir(); michael@0: this.CrashReports.submittedDir = CrashReports_submittedDir();