File: crashes.js

package info (click to toggle)
chromium-browser 57.0.2987.98-1~deb8u1
  • links: PTS, VCS
  • area: main
  • in suites: jessie
  • size: 2,637,852 kB
  • ctags: 2,544,394
  • sloc: cpp: 12,815,961; ansic: 3,676,222; python: 1,147,112; asm: 526,608; java: 523,212; xml: 286,794; perl: 92,654; sh: 86,408; objc: 73,271; makefile: 27,698; cs: 18,487; yacc: 13,031; tcl: 12,957; pascal: 4,875; ml: 4,716; lex: 3,904; sql: 3,862; ruby: 1,982; lisp: 1,508; php: 1,368; exp: 404; awk: 325; csh: 117; jsp: 39; sed: 37
file content (177 lines) | stat: -rw-r--r-- 6,564 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

/* Id for tracking automatic refresh of crash list.  */
var refreshCrashListId = undefined;

/**
 * Requests the list of crashes from the backend.
 */
function requestCrashes() {
  chrome.send('requestCrashList');
}

/**
 * Callback from backend with the list of crashes. Builds the UI.
 * @param {boolean} enabled Whether or not crash reporting is enabled.
 * @param {boolean} dynamicBackend Whether the crash backend is dynamic.
 * @param {boolean} manualUploads Whether the manual uploads are supported.
 * @param {array} crashes The list of crashes.
 * @param {string} version The browser version.
 * @param {string} os The OS name and version.
 */
function updateCrashList(
    enabled, dynamicBackend, manualUploads,
    crashes, version, os) {
  $('countBanner').textContent =
      loadTimeData.getStringF('crashCountFormat',
                              crashes.length.toLocaleString());

  var crashSection = $('crashList');

  $('disabledMode').hidden = enabled;
  $('crashUploadStatus').hidden = !enabled || !dynamicBackend;

  // Make the height fixed while clearing the
  // element in order to maintain scroll position.
  crashSection.style.height = getComputedStyle(crashSection).height;
  // Clear any previous list.
  crashSection.textContent = '';

  var productName = loadTimeData.getString('shortProductName');

  for (var i = 0; i < crashes.length; i++) {
    var crash = crashes[i];
    if (crash.local_id == '')
      crash.local_id = productName;

    var crashBlock = document.createElement('div');
    if (crash.state != 'uploaded')
      crashBlock.className = 'notUploaded';

    var title = document.createElement('h3');
    var uploaded = crash.state == 'uploaded';
    if (uploaded) {
      title.textContent = loadTimeData.getStringF('crashHeaderFormat',
                                                  crash.id,
                                                  crash.local_id);
    } else {
      title.textContent = loadTimeData.getStringF('crashHeaderFormatLocalOnly',
                                                  crash.local_id);
    }
    crashBlock.appendChild(title);

    if (uploaded) {
      var date = document.createElement('p');
      date.textContent = ""
      if (crash.capture_time) {
        date.textContent += loadTimeData.getStringF(
            'crashCaptureAndUploadTimeFormat', crash.capture_time,
            crash.upload_time);
      } else {
        date.textContent += loadTimeData.getStringF('crashUploadTimeFormat',
                                                    crash.upload_time);
      }
      crashBlock.appendChild(date);

      var linkBlock = document.createElement('p');
      var link = document.createElement('a');
      var commentLines = [
        'IMPORTANT: Your crash has already been automatically reported ' +
        'to our crash system. Please file this bug only if you can provide ' +
        'more information about it.',
        '',
        '',
        'Chrome Version: ' + version,
        'Operating System: ' + os,
        '',
        'URL (if applicable) where crash occurred:',
        '',
        'Can you reproduce this crash?',
        '',
        'What steps will reproduce this crash? (If it\'s not ' +
        'reproducible, what were you doing just before the crash?)',
        '1.', '2.', '3.',
        '',
        '****DO NOT CHANGE BELOW THIS LINE****',
        'Crash ID: crash/' + crash.id
      ];
      var params = {
        template: 'Crash Report',
        comment: commentLines.join('\n'),
        // TODO(scottmg): Use add_labels to add 'User-Submitted' rather than
        // duplicating the template's labels (the first two) once
        // https://bugs.chromium.org/p/monorail/issues/detail?id=1488 is done.
        labels: 'Restrict-View-EditIssue,Stability-Crash,User-Submitted',
      };
      var href = 'https://code.google.com/p/chromium/issues/entry';
      for (var param in params) {
        href = appendParam(href, param, params[param]);
      }
      link.href = href;
      link.target = '_blank';
      link.textContent = loadTimeData.getString('bugLinkText');
      linkBlock.appendChild(link);
      crashBlock.appendChild(linkBlock);
    } else {
      if (crash.state == 'pending_user_requested')
        var textContentKey = 'crashUserRequested';
      else if (crash.state == 'pending')
        var textContentKey = 'crashPending';
      else if (crash.state == 'not_uploaded')
        var textContentKey = 'crashNotUploaded';
      else
        continue;

      var crashText = document.createElement('p');
      crashText.textContent = loadTimeData.getStringF(textContentKey,
                                                      crash.capture_time);
      crashBlock.appendChild(crashText);

      if (crash.file_size != '') {
        var crashSizeText =  document.createElement('p');
        crashSizeText.textContent = loadTimeData.getStringF('crashSizeMessage',
                                                            crash.file_size);
        crashBlock.appendChild(crashSizeText);
      }

      // Do not show "Send now" link for already requested crashes.
      if (crash.state != 'pending_user_requested' && manualUploads) {
        var uploadNowLinkBlock = document.createElement('p');
        var link = document.createElement('a');
        link.href = '';
        link.textContent = loadTimeData.getString('uploadNowLinkText');
        link.local_id = crash.local_id;
        link.onclick = function() {
          chrome.send('requestSingleCrashUpload', [this.local_id]);
        };
        uploadNowLinkBlock.appendChild(link);
        crashBlock.appendChild(uploadNowLinkBlock);
      }
    }
    crashSection.appendChild(crashBlock);
  }

  // Reset the height, in order to accommodate for the new content.
  crashSection.style.height = "";
  $('noCrashes').hidden = crashes.length != 0;
}

/**
 * Request crashes get uploaded in the background.
 */
function requestCrashUpload() {
  // Don't need locking with this call because the system crash reporter
  // has locking built into itself.
  chrome.send('requestCrashUpload');

  // Trigger a refresh in 5 seconds.  Clear any previous requests.
  clearTimeout(refreshCrashListId);
  refreshCrashListId = setTimeout(requestCrashes, 5000);
}

document.addEventListener('DOMContentLoaded', function() {
  $('uploadCrashes').onclick = requestCrashUpload;
  requestCrashes();
});