toolkit/crashreporter/content/crashes.js

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 2 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 4
michael@0 5 const { classes: Cc, utils: Cu, interfaces: Ci } = Components;
michael@0 6
michael@0 7 var reportURL;
michael@0 8
michael@0 9 Cu.import("resource://gre/modules/CrashReports.jsm");
michael@0 10 Cu.import("resource://gre/modules/Services.jsm");
michael@0 11 Cu.import("resource://gre/modules/XPCOMUtils.jsm");
michael@0 12 Cu.import("resource://gre/modules/Task.jsm");
michael@0 13 Cu.import("resource://gre/modules/osfile.jsm");
michael@0 14
michael@0 15 XPCOMUtils.defineLazyModuleGetter(this, "CrashSubmit",
michael@0 16 "resource://gre/modules/CrashSubmit.jsm");
michael@0 17
michael@0 18 const buildID = Services.appinfo.appBuildID;
michael@0 19
michael@0 20 function submitSuccess(dumpid, ret) {
michael@0 21 let link = document.getElementById(dumpid);
michael@0 22 if (link) {
michael@0 23 link.className = "";
michael@0 24 // reset the link to point at our new crash report. this way, if the
michael@0 25 // user clicks "Back", the link will be correct.
michael@0 26 let CrashID = ret.CrashID;
michael@0 27 link.firstChild.textContent = CrashID;
michael@0 28 link.setAttribute("id", CrashID);
michael@0 29 link.removeEventListener("click", submitPendingReport, true);
michael@0 30
michael@0 31 if (reportURL) {
michael@0 32 link.setAttribute("href", reportURL + CrashID);
michael@0 33 // redirect the user to their brand new crash report
michael@0 34 window.location.href = reportURL + CrashID;
michael@0 35 }
michael@0 36 }
michael@0 37 }
michael@0 38
michael@0 39 function submitError(dumpid) {
michael@0 40 //XXX: do something more useful here
michael@0 41 let link = document.getElementById(dumpid);
michael@0 42 if (link)
michael@0 43 link.className = "";
michael@0 44 // dispatch an event, useful for testing
michael@0 45 let event = document.createEvent("Events");
michael@0 46 event.initEvent("CrashSubmitFailed", true, false);
michael@0 47 document.dispatchEvent(event);
michael@0 48 }
michael@0 49
michael@0 50 function submitPendingReport(event) {
michael@0 51 var link = event.target;
michael@0 52 var id = link.firstChild.textContent;
michael@0 53 if (CrashSubmit.submit(id, { submitSuccess: submitSuccess,
michael@0 54 submitError: submitError,
michael@0 55 noThrottle: true })) {
michael@0 56 link.className = "submitting";
michael@0 57 }
michael@0 58 event.preventDefault();
michael@0 59 return false;
michael@0 60 }
michael@0 61
michael@0 62 function populateReportList() {
michael@0 63 var prefService = Cc["@mozilla.org/preferences-service;1"].
michael@0 64 getService(Ci.nsIPrefBranch);
michael@0 65
michael@0 66 try {
michael@0 67 reportURL = prefService.getCharPref("breakpad.reportURL");
michael@0 68 // Ignore any non http/https urls
michael@0 69 if (!/^https?:/i.test(reportURL))
michael@0 70 reportURL = null;
michael@0 71 }
michael@0 72 catch (e) { }
michael@0 73 if (!reportURL) {
michael@0 74 document.getElementById("clear-reports").style.display = "none";
michael@0 75 document.getElementById("reportList").style.display = "none";
michael@0 76 document.getElementById("noConfig").style.display = "block";
michael@0 77 return;
michael@0 78 }
michael@0 79 let reports = CrashReports.getReports();
michael@0 80
michael@0 81 if (reports.length == 0) {
michael@0 82 document.getElementById("clear-reports").style.display = "none";
michael@0 83 document.getElementById("reportList").style.display = "none";
michael@0 84 document.getElementById("noReports").style.display = "block";
michael@0 85 return;
michael@0 86 }
michael@0 87
michael@0 88 var formatter = Cc["@mozilla.org/intl/scriptabledateformat;1"].
michael@0 89 createInstance(Ci.nsIScriptableDateFormat);
michael@0 90 var body = document.getElementById("tbody");
michael@0 91 var ios = Cc["@mozilla.org/network/io-service;1"].
michael@0 92 getService(Ci.nsIIOService);
michael@0 93 var reportURI = ios.newURI(reportURL, null, null);
michael@0 94 // resolving this URI relative to /report/index
michael@0 95 var aboutThrottling = ios.newURI("../../about/throttling", null, reportURI);
michael@0 96
michael@0 97 for (var i = 0; i < reports.length; i++) {
michael@0 98 var row = document.createElement("tr");
michael@0 99 var cell = document.createElement("td");
michael@0 100 row.appendChild(cell);
michael@0 101 var link = document.createElement("a");
michael@0 102 if (reports[i].pending) {
michael@0 103 link.setAttribute("href", aboutThrottling.spec);
michael@0 104 link.addEventListener("click", submitPendingReport, true);
michael@0 105 }
michael@0 106 else {
michael@0 107 link.setAttribute("href", reportURL + reports[i].id);
michael@0 108 }
michael@0 109 link.setAttribute("id", reports[i].id);
michael@0 110 link.appendChild(document.createTextNode(reports[i].id));
michael@0 111 cell.appendChild(link);
michael@0 112
michael@0 113 var date = new Date(reports[i].date);
michael@0 114 cell = document.createElement("td");
michael@0 115 var datestr = formatter.FormatDate("",
michael@0 116 Ci.nsIScriptableDateFormat.dateFormatShort,
michael@0 117 date.getFullYear(),
michael@0 118 date.getMonth() + 1,
michael@0 119 date.getDate());
michael@0 120 cell.appendChild(document.createTextNode(datestr));
michael@0 121 row.appendChild(cell);
michael@0 122 cell = document.createElement("td");
michael@0 123 var timestr = formatter.FormatTime("",
michael@0 124 Ci.nsIScriptableDateFormat.timeFormatNoSeconds,
michael@0 125 date.getHours(),
michael@0 126 date.getMinutes(),
michael@0 127 date.getSeconds());
michael@0 128 cell.appendChild(document.createTextNode(timestr));
michael@0 129 row.appendChild(cell);
michael@0 130 body.appendChild(row);
michael@0 131 }
michael@0 132 }
michael@0 133
michael@0 134 let clearReports = Task.async(function*() {
michael@0 135 let bundle = Services.strings.createBundle("chrome://global/locale/crashes.properties");
michael@0 136
michael@0 137 if (!Services.
michael@0 138 prompt.confirm(window,
michael@0 139 bundle.GetStringFromName("deleteconfirm.title"),
michael@0 140 bundle.GetStringFromName("deleteconfirm.description"))) {
michael@0 141 return;
michael@0 142 }
michael@0 143
michael@0 144 let cleanupFolder = Task.async(function*(path, filter) {
michael@0 145 let iterator = new OS.File.DirectoryIterator(path);
michael@0 146 try {
michael@0 147 yield iterator.forEach(Task.async(function*(aEntry) {
michael@0 148 if (!filter || (yield filter(aEntry))) {
michael@0 149 yield OS.File.remove(aEntry.path);
michael@0 150 }
michael@0 151 }));
michael@0 152 } catch (e if e instanceof OS.File.Error && e.becauseNoSuchFile) {
michael@0 153 } finally {
michael@0 154 iterator.close();
michael@0 155 }
michael@0 156 });
michael@0 157
michael@0 158 yield cleanupFolder(CrashReports.submittedDir.path, function*(aEntry) {
michael@0 159 return aEntry.name.startsWith("bp-") && aEntry.name.endsWith(".txt");
michael@0 160 });
michael@0 161
michael@0 162 let oneYearAgo = Date.now() - 31586000000;
michael@0 163 yield cleanupFolder(CrashReports.reportsDir.path, function*(aEntry) {
michael@0 164 if (!aEntry.name.startsWith("InstallTime") ||
michael@0 165 aEntry.name == "InstallTime" + buildID) {
michael@0 166 return false;
michael@0 167 }
michael@0 168
michael@0 169 let date = aEntry.winLastWriteDate;
michael@0 170 if (!date) {
michael@0 171 let stat = yield OS.File.stat(aEntry.path);
michael@0 172 date = stat.lastModificationDate;
michael@0 173 }
michael@0 174
michael@0 175 return (date < oneYearAgo);
michael@0 176 });
michael@0 177
michael@0 178 yield cleanupFolder(CrashReports.pendingDir.path);
michael@0 179
michael@0 180 document.getElementById("clear-reports").style.display = "none";
michael@0 181 document.getElementById("reportList").style.display = "none";
michael@0 182 document.getElementById("noReports").style.display = "block";
michael@0 183 });

mercurial