| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 /** | 5 /** |
| 6 * This view displays options for importing/exporting the captured data. Its | 6 * This view displays options for importing/exporting the captured data. Its |
| 7 * primarily usefulness is to allow users to copy-paste their data in an easy | 7 * primarily usefulness is to allow users to copy-paste their data in an easy |
| 8 * to read format for bug reports. | 8 * to read format for bug reports. |
| 9 * | 9 * |
| 10 * - Has a button to generate a text report. | 10 * - Has a button to generate a text report. |
| 11 * - Has a button to generate a raw JSON dump (most useful for testing). | 11 * - Has a button to generate a raw JSON dump (most useful for testing). |
| 12 * | 12 * |
| 13 * @constructor | 13 * @constructor |
| 14 */ | 14 */ |
| 15 function DataView(mainBoxId, exportJsonButtonId, exportTextButtonId) { | 15 function DataView(mainBoxId, outputTextBoxId, exportTextButtonId) { |
| 16 DivView.call(this, mainBoxId); | 16 DivView.call(this, mainBoxId); |
| 17 | 17 |
| 18 var exportJsonButton = document.getElementById(exportJsonButtonId); | 18 this.textPre_ = document.getElementById(outputTextBoxId); |
| 19 var exportTextButton = document.getElementById(exportTextButtonId); | 19 var exportTextButton = document.getElementById(exportTextButtonId); |
| 20 | 20 |
| 21 exportJsonButton.onclick = this.onExportToJSON_.bind(this); | |
| 22 exportTextButton.onclick = this.onExportToText_.bind(this); | 21 exportTextButton.onclick = this.onExportToText_.bind(this); |
| 23 } | 22 } |
| 24 | 23 |
| 25 inherits(DataView, DivView); | 24 inherits(DataView, DivView); |
| 26 | 25 |
| 27 /** | 26 /** |
| 28 * Very simple output format which directly displays the internally captured | |
| 29 * data in its javascript format. | |
| 30 */ | |
| 31 DataView.prototype.onExportToJSON_ = function() { | |
| 32 // Format some text describing the data we have captured. | |
| 33 var text = []; // Lines of text. | |
| 34 | |
| 35 text.push('//----------------------------------------------'); | |
| 36 text.push('// Proxy settings'); | |
| 37 text.push('//----------------------------------------------'); | |
| 38 text.push(''); | |
| 39 | |
| 40 text.push('proxySettings = ' + | |
| 41 JSON.stringify(g_browser.proxySettings_.currentData_)); | |
| 42 | |
| 43 text.push(''); | |
| 44 text.push('//----------------------------------------------'); | |
| 45 text.push('// Bad proxies'); | |
| 46 text.push('//----------------------------------------------'); | |
| 47 text.push(''); | |
| 48 | |
| 49 text.push('badProxies = ' + | |
| 50 JSON.stringify(g_browser.badProxies_.currentData_)); | |
| 51 | |
| 52 text.push(''); | |
| 53 text.push('//----------------------------------------------'); | |
| 54 text.push('// Host resolver cache'); | |
| 55 text.push('//----------------------------------------------'); | |
| 56 text.push(''); | |
| 57 | |
| 58 text.push('hostResolverCache = ' + | |
| 59 JSON.stringify(g_browser.hostResolverCache_.currentData_)); | |
| 60 | |
| 61 text.push(''); | |
| 62 text.push('//----------------------------------------------'); | |
| 63 text.push('// Passively captured events'); | |
| 64 text.push('//----------------------------------------------'); | |
| 65 text.push(''); | |
| 66 | |
| 67 this.appendPrettyPrintedJsonArray_('passive', | |
| 68 g_browser.getAllPassivelyCapturedEvents(), | |
| 69 text); | |
| 70 | |
| 71 text.push(''); | |
| 72 text.push('//----------------------------------------------'); | |
| 73 text.push('// Actively captured events'); | |
| 74 text.push('//----------------------------------------------'); | |
| 75 text.push(''); | |
| 76 | |
| 77 this.appendPrettyPrintedJsonArray_('active', | |
| 78 g_browser.getAllActivelyCapturedEvents(), | |
| 79 text); | |
| 80 | |
| 81 // Open a new window to display this text. | |
| 82 this.displayPopupWindow_(text.join('\n')); | |
| 83 }; | |
| 84 | |
| 85 /** | |
| 86 * Presents the captured data as formatted text. | 27 * Presents the captured data as formatted text. |
| 87 */ | 28 */ |
| 88 DataView.prototype.onExportToText_ = function() { | 29 DataView.prototype.onExportToText_ = function() { |
| 30 this.setText_("Generating..."); |
| 31 |
| 89 var text = []; | 32 var text = []; |
| 90 | 33 |
| 91 // Print some basic information about our environment. | 34 // Print some basic information about our environment. |
| 92 text.push('Data exported on: ' + (new Date()).toLocaleString()); | 35 text.push('Data exported on: ' + (new Date()).toLocaleString()); |
| 93 text.push(''); | 36 text.push(''); |
| 94 text.push('Number of passively captured events: ' + | 37 text.push('Number of passively captured events: ' + |
| 95 g_browser.getAllPassivelyCapturedEvents().length); | 38 g_browser.getAllPassivelyCapturedEvents().length); |
| 96 text.push('Number of actively captured events: ' + | 39 text.push('Number of actively captured events: ' + |
| 97 g_browser.getAllActivelyCapturedEvents().length); | 40 g_browser.getAllActivelyCapturedEvents().length); |
| 98 text.push('Timetick to timestamp offset: ' + g_browser.timeTickOffset_); | 41 text.push('Timetick to timestamp offset: ' + g_browser.timeTickOffset_); |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 143 | 86 |
| 144 text.push(''); | 87 text.push(''); |
| 145 text.push('----------------------------------------------'); | 88 text.push('----------------------------------------------'); |
| 146 text.push(' Requests'); | 89 text.push(' Requests'); |
| 147 text.push('----------------------------------------------'); | 90 text.push('----------------------------------------------'); |
| 148 text.push(''); | 91 text.push(''); |
| 149 | 92 |
| 150 this.appendRequestsPrintedAsText_(text); | 93 this.appendRequestsPrintedAsText_(text); |
| 151 | 94 |
| 152 // Open a new window to display this text. | 95 // Open a new window to display this text. |
| 153 this.displayPopupWindow_(text.join('\n')); | 96 this.setText_(text.join('\n')); |
| 154 }; | 97 }; |
| 155 | 98 |
| 156 DataView.prototype.appendRequestsPrintedAsText_ = function(out) { | 99 DataView.prototype.appendRequestsPrintedAsText_ = function(out) { |
| 157 // Concatenate the passively captured events with the actively captured events | 100 // Concatenate the passively captured events with the actively captured events |
| 158 // into a single array. | 101 // into a single array. |
| 159 var allEvents = g_browser.getAllPassivelyCapturedEvents().concat( | 102 var allEvents = g_browser.getAllPassivelyCapturedEvents().concat( |
| 160 g_browser.getAllActivelyCapturedEvents()); | 103 g_browser.getAllActivelyCapturedEvents()); |
| 161 | 104 |
| 162 // Group the events into buckets by source ID, and buckets by source type. | 105 // Group the events into buckets by source ID, and buckets by source type. |
| 163 var sourceIds = []; | 106 var sourceIds = []; |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 195 out.push('------------------------------'); | 138 out.push('------------------------------'); |
| 196 out.push(getKeyWithValue(LogSourceType, sourceType) + | 139 out.push(getKeyWithValue(LogSourceType, sourceType) + |
| 197 ' (id=' + sourceId + ')'); | 140 ' (id=' + sourceId + ')'); |
| 198 out.push('------------------------------'); | 141 out.push('------------------------------'); |
| 199 | 142 |
| 200 out.push(PrintSourceEntriesAsText(eventList)); | 143 out.push(PrintSourceEntriesAsText(eventList)); |
| 201 } | 144 } |
| 202 }; | 145 }; |
| 203 | 146 |
| 204 /** | 147 /** |
| 205 * Helper function to open a new window and display |text| in it. | 148 * Helper function to set this view's content to |text|. |
| 206 */ | 149 */ |
| 207 DataView.prototype.displayPopupWindow_ = function(text) { | 150 DataView.prototype.setText_ = function(text) { |
| 208 // Note that we use a data:URL because the chrome:// URL scheme doesn't | 151 this.textPre_.innerHTML = ''; |
| 209 // allow us to mutate any new windows we open. | 152 addTextNode(this.textPre_, text); |
| 210 dataUrl = 'data:text/plain,' + encodeURIComponent(text); | |
| 211 window.open(dataUrl, '_blank'); | |
| 212 }; | |
| 213 | |
| 214 /** | |
| 215 * Stringifies |arrayData| as JSON-like output, and appends it to the | |
| 216 * line buffer |out|. | |
| 217 */ | |
| 218 DataView.prototype.appendPrettyPrintedJsonArray_ = function(name, | |
| 219 arrayData, | |
| 220 out) { | |
| 221 out.push(name + ' = [];'); | |
| 222 for (var i = 0; i < arrayData.length; ++i) { | |
| 223 out.push(name + '[' + i + '] = ' + JSON.stringify(arrayData[i]) + ';'); | |
| 224 } | |
| 225 }; | 153 }; |
| 226 | 154 |
| 227 /** | 155 /** |
| 228 * Stringifies |arrayData| to formatted table output, and appends it to the | 156 * Stringifies |arrayData| to formatted table output, and appends it to the |
| 229 * line buffer |out|. | 157 * line buffer |out|. |
| 230 */ | 158 */ |
| 231 DataView.prototype.appendPrettyPrintedTable_ = function(arrayData, out) { | 159 DataView.prototype.appendPrettyPrintedTable_ = function(arrayData, out) { |
| 232 for (var i = 0; i < arrayData.length; ++i) { | 160 for (var i = 0; i < arrayData.length; ++i) { |
| 233 var e = arrayData[i]; | 161 var e = arrayData[i]; |
| 234 var eString = '[' + i + ']: '; | 162 var eString = '[' + i + ']: '; |
| 235 for (var key in e) { | 163 for (var key in e) { |
| 236 eString += key + "=" + e[key] + "; "; | 164 eString += key + "=" + e[key] + "; "; |
| 237 } | 165 } |
| 238 out.push(eString); | 166 out.push(eString); |
| 239 } | 167 } |
| 240 }; | 168 }; |
| 241 | 169 |
| OLD | NEW |