1// Copyright (c) 2011 The Chromium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5localStrings = new LocalStrings();
6
7/**
8 * Requests the list of crashes from the backend.
9 */
10function requestCrashes() {
11  chrome.send('requestCrashList', [])
12}
13
14/**
15 * Callback from backend with the list of crashes. Builds the UI.
16 * @param {boolean} enabled Whether or not crash reporting is enabled.
17 * @param {array} crashes The list of crashes.
18 * @param {string} version The browser version.
19 */
20function updateCrashList(enabled, crashes, version) {
21  $('countBanner').textContent = localStrings.getStringF('crashCountFormat',
22                                                         crashes.length);
23
24  var crashSection = $('crashList');
25
26  $('enabledMode').hidden = !enabled;
27  $('disabledMode').hidden = enabled;
28
29  if (!enabled)
30    return;
31
32  // Clear any previous list.
33  crashSection.textContent = '';
34
35  for (var i = 0; i < crashes.length; i++) {
36    var crash = crashes[i];
37
38    var crashBlock = document.createElement('div');
39    var title = document.createElement('h3');
40    title.textContent = localStrings.getStringF('crashHeaderFormat',
41                                                crash['id']);
42    crashBlock.appendChild(title);
43    var date = document.createElement('p');
44    date.textContent = localStrings.getStringF('crashTimeFormat',
45                                               crash['time']);
46    crashBlock.appendChild(date);
47    var linkBlock = document.createElement('p');
48    var link = document.createElement('a');
49    link.href = 'http://code.google.com/p/chromium/issues/entry?' +
50        'template=Crash%20Report&comment=' +
51        'Chrome%20Version:%20' + version + '%0A' +
52        'Operating%20System:%20e.g.,%20"Windows%207",%20' +
53        '"Mac%20OS%20X%2010.6"%0A%0A' +
54        'URL%20(if%20applicable)%20where%20crash%20occurred:%20%0A%0A' +
55        'Can%20you%20reproduce%20this%20crash?%0A%0A' +
56        'What%20steps%20will%20reproduce%20this%20crash%20' +
57        '(or%20if%20it\'s%20not%20reproducible,%20what%20were%20you%20doing' +
58        '%20just%20before%20the%20crash)?%0A1.%0A2.%0A3.%0A%0A' +
59        '*Please%20note%20that%20issues%20filed%20with%20no%20information%20' +
60        'filled%20in%20above%20will%20be%20marked%20as%20WontFix*%0A%0A' +
61        '****DO%20NOT%20CHANGE%20BELOW%20THIS%20LINE****%0Areport_id:' +
62        crash['id'];
63    link.target = '_blank';
64    link.textContent = localStrings.getString('bugLinkText');
65    linkBlock.appendChild(link);
66    crashBlock.appendChild(linkBlock);
67    crashSection.appendChild(crashBlock);
68  }
69
70  $('noCrashes').hidden = crashes.length != 0;
71}
72
73document.addEventListener('DOMContentLoaded', requestCrashes);
74