OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 /** |
| 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 |
| 8 * to read format for bug reports. |
| 9 * |
| 10 * - Has a button to generate a text report. |
| 11 * - Has a button to generate a raw JSON dump (most useful for testing). |
| 12 * |
| 13 * @constructor |
| 14 */ |
| 15 function DataView(mainBoxId, exportJsonButtonId, exportTextButtonId) { |
| 16 DivView.call(this, mainBoxId); |
| 17 |
| 18 var exportJsonButton = document.getElementById(exportJsonButtonId); |
| 19 var exportTextButton = document.getElementById(exportTextButtonId); |
| 20 |
| 21 exportJsonButton.onclick = this.onExportToJSON_.bind(this); |
| 22 exportTextButton.onclick = this.onExportToText_.bind(this); |
| 23 } |
| 24 |
| 25 inherits(DataView, DivView); |
| 26 |
| 27 /** |
| 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. |
| 87 */ |
| 88 DataView.prototype.onExportToText_ = function() { |
| 89 var text = []; |
| 90 |
| 91 // Print some basic information about our environment. |
| 92 text.push('Data exported on: ' + (new Date()).toLocaleString()); |
| 93 text.push('Number of passively captured events: ' + |
| 94 g_browser.getAllPassivelyCapturedEvents().length); |
| 95 text.push('Number of actively captured events: ' + |
| 96 g_browser.getAllActivelyCapturedEvents().length); |
| 97 text.push('Timetick to timestamp offset: ' + g_browser.timeTickOffset_); |
| 98 text.push(''); |
| 99 // TODO(eroman): fill this with proper values. |
| 100 text.push('Chrome version: ' + 'TODO'); |
| 101 text.push('Command line switches: ' + 'TODO'); |
| 102 |
| 103 text.push(''); |
| 104 text.push('----------------------------------------------'); |
| 105 text.push(' Proxy settings'); |
| 106 text.push('----------------------------------------------'); |
| 107 text.push(''); |
| 108 |
| 109 text.push(g_browser.proxySettings_.currentData_); |
| 110 |
| 111 text.push(''); |
| 112 text.push('----------------------------------------------'); |
| 113 text.push(' Bad proxies'); |
| 114 text.push('----------------------------------------------'); |
| 115 text.push(''); |
| 116 |
| 117 var badProxiesList = g_browser.badProxies_.currentData_; |
| 118 if (badProxiesList.length == 0) { |
| 119 text.push('None'); |
| 120 } else { |
| 121 this.appendPrettyPrintedTable_(badProxiesList, text); |
| 122 } |
| 123 |
| 124 text.push(''); |
| 125 text.push('----------------------------------------------'); |
| 126 text.push(' Host resolver cache'); |
| 127 text.push('----------------------------------------------'); |
| 128 text.push(''); |
| 129 |
| 130 var hostResolverCache = g_browser.hostResolverCache_.currentData_; |
| 131 |
| 132 text.push('Capcity: ' + hostResolverCache.capacity); |
| 133 text.push('Time to live for successful resolves (ms): ' + |
| 134 hostResolverCache.ttl_success_ms); |
| 135 text.push('Time to live for failed resolves (ms): ' + |
| 136 hostResolverCache.ttl_failure_ms); |
| 137 |
| 138 if (hostResolverCache.entries.length > 0) { |
| 139 text.push(''); |
| 140 this.appendPrettyPrintedTable_(hostResolverCache.entries, text); |
| 141 } |
| 142 |
| 143 text.push(''); |
| 144 text.push('----------------------------------------------'); |
| 145 text.push(' URL requests'); |
| 146 text.push('----------------------------------------------'); |
| 147 text.push(''); |
| 148 |
| 149 // TODO(eroman): Output the per-request events. |
| 150 text.push('TODO'); |
| 151 |
| 152 // Open a new window to display this text. |
| 153 this.displayPopupWindow_(text.join('\n')); |
| 154 }; |
| 155 |
| 156 /** |
| 157 * Helper function to open a new window and display |text| in it. |
| 158 */ |
| 159 DataView.prototype.displayPopupWindow_ = function(text) { |
| 160 // Note that we use a data:URL because the chrome:// URL scheme doesn't |
| 161 // allow us to mutate any new windows we open. |
| 162 dataUrl = 'data:text/plain,' + encodeURIComponent(text); |
| 163 window.open(dataUrl, '_blank'); |
| 164 }; |
| 165 |
| 166 /** |
| 167 * Stringifies |arrayData| as JSON-like output, and appends it to the |
| 168 * line buffer |out|. |
| 169 */ |
| 170 DataView.prototype.appendPrettyPrintedJsonArray_ = function(name, |
| 171 arrayData, |
| 172 out) { |
| 173 out.push(name + ' = [];'); |
| 174 for (var i = 0; i < arrayData.length; ++i) { |
| 175 out.push(name + '[' + i + '] = ' + JSON.stringify(arrayData[i]) + ';'); |
| 176 } |
| 177 }; |
| 178 |
| 179 /** |
| 180 * Stringifies |arrayData| to formatted table output, and appends it to the |
| 181 * line buffer |out|. |
| 182 */ |
| 183 DataView.prototype.appendPrettyPrintedTable_ = function(arrayData, out) { |
| 184 for (var i = 0; i < arrayData.length; ++i) { |
| 185 var e = arrayData[i]; |
| 186 var eString = '[' + i + ']: '; |
| 187 for (var key in e) { |
| 188 eString += key + "=" + e[key] + "; "; |
| 189 } |
| 190 out.push(eString); |
| 191 } |
| 192 }; |
| 193 |
OLD | NEW |