Bug 934603 - Include ids of recent crashes in about:support ('Troubleshooting information'). r=Standard8
authorSebastian Hengst <archaeopteryx@coole-files.de>
Mon, 25 Nov 2013 13:30:15 +0100
changeset 16927 8d4803345e7c50bebd7c15e5a8ecfaee6404a995
parent 16926 4852f232b25f46257bf88243bcb8fe7b76a24aa3
child 16928 a430a521cacfdc5c00b603f09941b29bf9d397f0
push id1074
push userbugzilla@standard8.plus.com
push dateMon, 03 Feb 2014 22:47:23 +0000
treeherdercomm-beta@6b791b5369ed [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersStandard8
bugs934603
Bug 934603 - Include ids of recent crashes in about:support ('Troubleshooting information'). r=Standard8 CLOSED TREE
mail/components/about-support/content/aboutSupport.xhtml
mail/components/about-support/content/crashes.js
mail/components/about-support/content/export.js
mail/components/about-support/content/init.js
mail/components/about-support/jar.mn
--- a/mail/components/about-support/content/aboutSupport.xhtml
+++ b/mail/components/about-support/content/aboutSupport.xhtml
@@ -24,16 +24,20 @@
     <!-- Private data is hidden by default. -->
     <link rel="stylesheet" href="chrome://messenger/content/about-support/hide-private.css"
           type="text/css" id="about-support-private"/>
 
     <script type="application/javascript;version=1.7"
             src="chrome://messenger/content/about-support/init.js"/>
     <script type="application/javascript;version=1.7"
             src="chrome://messenger/content/about-support/accounts.js"/>
+#ifdef MOZ_CRASHREPORTER
+    <script type="application/javascript;version=1.7"
+            src="chrome://messenger/content/about-support/crashes.js"/>
+#endif
     <script type="application/javascript;version=1.7"
             src="chrome://messenger/content/about-support/extensions.js"/>
     <script type="application/javascript;version=1.7"
             src="chrome://messenger/content/about-support/prefs.js"/>
     <script type="application/javascript;version=1.7"
             src="chrome://messenger/content/about-support/gfx.js"/>
     <script type="application/javascript;version=1.7"
             src="chrome://messenger/content/about-support/js.js"/>
@@ -163,26 +167,16 @@
 
             <td>
               <a href="about:buildconfig" target="_blank">about:buildconfig</a>
             </td>
           </tr>
 
           <tr>
             <th class="column">
-              &aboutSupport.crashes.title;
-            </th>
-
-            <td>
-              <a href="about:crashes" target="_blank">about:crashes</a>
-            </td>
-          </tr>
-
-          <tr>
-            <th class="column">
               &aboutSupport.appBasicsMemoryUse;
             </th>
 
             <td>
               <a href="about:memory" target="_blank">about:memory</a>
             </td>
           </tr>
         </tbody>
@@ -246,16 +240,43 @@
           </tr>
         </thead>
 
         <tbody id="accounts-tbody">
         </tbody>
       </table>
 
       <!-- - - - - - - - - - - - - - - - - - - - - -->
+#ifdef MOZ_CRASHREPORTER
+
+      <h2 class="major-section">
+        &aboutSupport.crashes.title;
+      </h2>
+
+      <table id="crashes-table">
+        <thead>
+          <tr>
+            <th>
+              &aboutSupport.crashes.id;
+            </th>
+            <th>
+              &aboutSupport.crashes.sendDate;
+            </th>
+          </tr>
+        </thead>
+        <tbody id="crashes-tbody">
+        </tbody>
+      </table>
+      <p id="crashes-allReports" class="data-uionly" style="display: none">
+        <a href="about:crashes" id="crashes-allReportsWithPending" style="display: block" target="_blank">&aboutSupport.crashes.allReports;</a>
+      </p>
+      <p id="crashes-noConfig" class="data-uionly" style="display: none">&aboutSupport.crashes.noConfig;</p>
+
+      <!-- - - - - - - - - - - - - - - - - - - - - -->
+#endif
 
       <h2 class="major-section">
         &aboutSupport.extensionsTitle;
       </h2>
 
       <table id="extensions-table">
         <thead>
           <tr>
new file mode 100644
--- /dev/null
+++ b/mail/components/about-support/content/crashes.js
@@ -0,0 +1,87 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+Components.utils.import("resource://gre/modules/CrashReports.jsm");
+
+/**
+ * Get list of crashes and show 5 most recent.*/
+
+const kCrashesMaxCount = 5;
+
+function populateCrashesSection() {
+  let reportURL;
+  try {
+    reportURL = Services.prefs.getCharPref("breakpad.reportURL");
+    // Ignore any non http/https urls
+    if (!/^https?:/i.test(reportURL))
+      reportURL = null;
+  }
+  catch (e) { }
+  if (!reportURL) {
+    let noConfig = document.getElementById("crashes-noConfig")
+    noConfig.style.display = "block";
+    noConfig.classList.remove("no-copy");
+    return;
+  }
+  else {
+    let allReports = document.getElementById("crashes-allReports")
+    allReports.style.display = "block";
+    allReports.classList.remove("no-copy");
+  }
+
+  let reports = CrashReports.getReports();
+  let reportsSubmitted = [];
+  let reportsPendingCount = 0;
+  for (let report of reports)
+  {
+    if (!report.pending)
+    {
+      reportsSubmitted.push(report);
+      if (reportsSubmitted.length == kCrashesMaxCount)
+        break;
+    }
+    else
+    {
+      reportsPendingCount++;
+    }
+  }
+
+  let dateFormat = Components.classes["@mozilla.org/intl/scriptabledateformat;1"]
+                             .getService(Components.interfaces.nsIScriptableDateFormat);
+  let crashesBody = document.getElementById("crashes-tbody");
+  for (let report of reportsSubmitted)
+  {
+    let tr = document.createElement("tr");
+    let cellCrashLink = document.createElement("td");
+    let anchor = document.createElement("a");
+    anchor.setAttribute("href", reportURL + report.id);
+    anchor.textContent = report.id;
+    cellCrashLink.appendChild(anchor);
+    tr.appendChild(cellCrashLink);
+    let dateSubmitted = new Date(report.date);
+    let cellDate = document.createElement("td");
+    cellDate.textContent = dateFormat.FormatDate("", dateFormat.dateFormatShort,
+                                                 dateSubmitted.getFullYear(),
+                                                 dateSubmitted.getMonth() + 1,
+                                                 dateSubmitted.getDay());
+    tr.appendChild(cellDate);
+    crashesBody.appendChild(tr);
+  }
+}
+
+/**
+ * Returns a plaintext representation of extension data.
+ */
+ 
+function getCrashesText(aIndent) {
+  let crashesData = "";
+  let recentCrashesSubmitted = document.querySelectorAll("#crashes-tbody > tr");
+  for (let i = 0; i < recentCrashesSubmitted.length; i++)
+  {
+    let tds = recentCrashesSubmitted.item(i).querySelectorAll("td");
+    crashesData += aIndent.repeat(2) + tds.item(0).firstChild.href +
+                   " (" + tds.item(1).textContent + ")\n";
+  }
+  return crashesData;
+}
--- a/mail/components/about-support/content/export.js
+++ b/mail/components/about-support/content/export.js
@@ -180,16 +180,24 @@ function generateTextForElement(elem, aH
 
   // If this element is one of our elements to replace with text, do it.
   if (elem.id in gElementsToReplace) {
     let replaceFn = gElementsToReplace[elem.id];
     textFragmentAccumulator.push(replaceFn(aHidePrivateData, indent + "  "));
     return;
   };
 
+#ifdef MOZ_CRASHREPORTER
+  if (elem.id == "crashes-table")
+  {
+    textFragmentAccumulator.push(getCrashesText(indent));
+    return;
+  }
+#endif
+
   let childCount = elem.childElementCount;
 
   // We're not going to spread a two-column <tr> across multiple lines, so
   // handle that separately.
   if (elem.tagName == "tr" && childCount == 2) {
     textFragmentAccumulator.push(indent);
     textFragmentAccumulator.push(elem.children[0].textContent.trim() + ": " +
                                  elem.children[1].textContent.trim());
--- a/mail/components/about-support/content/init.js
+++ b/mail/components/about-support/content/init.js
@@ -58,16 +58,19 @@ window.onload = function () {
     document.getElementById("profile-fs-type-box").textContent = fsText;
   }
 
   document.getElementById("buildid-box").textContent = Services.appinfo.appBuildID;
 
   // Update the other sections.
   populateAccountsSection();
   populatePreferencesSection();
+#ifdef MOZ_CRASHREPORTER
+  populateCrashesSection();
+#endif
   populateExtensionsSection();
   populateGraphicsSection();
   populateJavaScriptSection();
   populateAccessibilitySection();
   populateLibVersionsSection();  
 }
 
 function onShowPrivateDataChange(aCheckbox) {
--- a/mail/components/about-support/jar.mn
+++ b/mail/components/about-support/jar.mn
@@ -1,20 +1,23 @@
 # This Source Code Form is subject to the terms of the Mozilla Public
 # License, v. 2.0. If a copy of the MPL was not distributed with this
 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
 
 messenger.jar:
 %   overlay chrome://messenger/content/messenger.xul           chrome://messenger/content/about-support/overlay.xul
     content/messenger/about-support/hide-private.css           (content/hide-private.css)
     content/messenger/about-support/show-private.css           (content/show-private.css)
-    content/messenger/about-support/init.js                    (content/init.js)
+*   content/messenger/about-support/init.js                    (content/init.js)
     content/messenger/about-support/accounts.js                (content/accounts.js)
+#ifdef MOZ_CRASHREPORTER
+    content/messenger/about-support/crashes.js                 (content/crashes.js)
+#endif
     content/messenger/about-support/extensions.js              (content/extensions.js)
     content/messenger/about-support/prefs.js                   (content/prefs.js)
 *   content/messenger/about-support/gfx.js                     (content/gfx.js)
     content/messenger/about-support/js.js                      (content/js.js)
     content/messenger/about-support/a11y.js                    (content/a11y.js)
     content/messenger/about-support/libversions.js             (content/libversions.js)
-    content/messenger/about-support/export.js                  (content/export.js)
+*   content/messenger/about-support/export.js                  (content/export.js)
 *   content/messenger/about-support/aboutSupport.xhtml         (content/aboutSupport.xhtml)
     content/messenger/about-support/overlay.js                 (content/overlay.js)
     content/messenger/about-support/overlay.xul                (content/overlay.xul)