toolkit/crashreporter/CrashReports.jsm

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/toolkit/crashreporter/CrashReports.jsm	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,91 @@
     1.4 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.5 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.6 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.7 +
     1.8 +Components.utils.import("resource://gre/modules/Services.jsm");
     1.9 +
    1.10 +this.EXPORTED_SYMBOLS = [
    1.11 +  "CrashReports"
    1.12 +];
    1.13 +
    1.14 +this.CrashReports = {
    1.15 +  pendingDir: null,
    1.16 +  reportsDir: null,
    1.17 +  submittedDir: null,
    1.18 +  getReports: function CrashReports_getReports()
    1.19 +  {
    1.20 +    let reports = [];
    1.21 +
    1.22 +    try {
    1.23 +      // Ignore any non http/https urls
    1.24 +      if (!/^https?:/i.test(Services.prefs.getCharPref("breakpad.reportURL")))
    1.25 +        return reports;
    1.26 +    }
    1.27 +    catch (e) { }
    1.28 +
    1.29 +    if (this.submittedDir.exists() && this.submittedDir.isDirectory()) {
    1.30 +      let entries = this.submittedDir.directoryEntries;
    1.31 +      while (entries.hasMoreElements()) {
    1.32 +        let file = entries.getNext().QueryInterface(Components.interfaces.nsIFile);
    1.33 +        let leaf = file.leafName;
    1.34 +        if (leaf.startsWith("bp-") &&
    1.35 +            leaf.endsWith(".txt")) {
    1.36 +          let entry = {
    1.37 +            id: leaf.slice(0, -4),
    1.38 +            date: file.lastModifiedTime,
    1.39 +            pending: false
    1.40 +          };
    1.41 +          reports.push(entry);
    1.42 +        }
    1.43 +      }
    1.44 +    }
    1.45 +
    1.46 +    if (this.pendingDir.exists() && this.pendingDir.isDirectory()) {
    1.47 +      let uuidRegex = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
    1.48 +      let entries = this.pendingDir.directoryEntries;
    1.49 +      while (entries.hasMoreElements()) {
    1.50 +        let file = entries.getNext().QueryInterface(Components.interfaces.nsIFile);
    1.51 +        let leaf = file.leafName;
    1.52 +        let id = leaf.slice(0, -4);
    1.53 +        if (leaf.endsWith(".dmp") && uuidRegex.test(id)) {
    1.54 +          let entry = {
    1.55 +            id: id,
    1.56 +            date: file.lastModifiedTime,
    1.57 +            pending: true
    1.58 +          };
    1.59 +          reports.push(entry);
    1.60 +        }
    1.61 +      }
    1.62 +    }
    1.63 +
    1.64 +    // Sort reports descending by date
    1.65 +    return reports.sort( (a, b) => b.date - a.date);
    1.66 +  }
    1.67 +}
    1.68 +
    1.69 +function CrashReports_pendingDir()
    1.70 +{
    1.71 +  let pendingDir = Services.dirsvc.get("UAppData", Components.interfaces.nsIFile);
    1.72 +  pendingDir.append("Crash Reports");
    1.73 +  pendingDir.append("pending");
    1.74 +  return pendingDir;
    1.75 +}
    1.76 +
    1.77 +function CrashReports_reportsDir()
    1.78 +{
    1.79 +  let reportsDir = Services.dirsvc.get("UAppData", Components.interfaces.nsIFile);
    1.80 +  reportsDir.append("Crash Reports");
    1.81 +  return reportsDir;
    1.82 +}
    1.83 +
    1.84 +function CrashReports_submittedDir()
    1.85 +{
    1.86 +  let submittedDir = Services.dirsvc.get("UAppData", Components.interfaces.nsIFile);
    1.87 +  submittedDir.append("Crash Reports");
    1.88 +  submittedDir.append("submitted");
    1.89 +  return submittedDir;
    1.90 +}
    1.91 +
    1.92 +this.CrashReports.pendingDir = CrashReports_pendingDir();
    1.93 +this.CrashReports.reportsDir = CrashReports_reportsDir();
    1.94 +this.CrashReports.submittedDir = CrashReports_submittedDir();

mercurial