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 * |
| 12 * - Shows how many events have been captured. |
| 13 * @constructor |
| 14 */ |
| 15 function InfoView(mainBoxId) { |
| 16 DivView.call(this, mainBoxId); |
| 17 |
| 18 this.textDiv_ = document.getElementById('infoText'); |
| 19 this.gpuInfo_ = undefined; |
| 20 this.clientInfo_ = undefined; |
| 21 |
| 22 var self = this; |
| 23 |
| 24 // This function begins a request for the ClientInfo. If it comes back |
| 25 // as undefined, then we will issue the request again in 250ms. |
| 26 function beginRequestClientInfo() { |
| 27 g_browser.callAsync('requestClientInfo', undefined, function(data) { |
| 28 self.clientInfo_ = data; |
| 29 self.refresh_(); |
| 30 if(data === undefined) { // try again in 250 ms |
| 31 window.setTimeout(beginRequestClientInfo, 250) |
| 32 } |
| 33 }); |
| 34 } |
| 35 beginRequestClientInfo(); |
| 36 |
| 37 // This function begins a request for the GpuInfo. If it comes back |
| 38 // as undefined, then we will issue the request again in 250ms. |
| 39 function beginRequestGpuInfo() { |
| 40 g_browser.callAsync('requestGpuInfo', undefined, function(data) { |
| 41 self.gpuInfo_ = data; |
| 42 self.refresh_(); |
| 43 if(data === undefined) { // try again in 250 ms |
| 44 window.setTimeout(beginRequestGpuInfo, 250) |
| 45 } |
| 46 }); |
| 47 } |
| 48 beginRequestGpuInfo(); |
| 49 this.refresh_(); |
| 50 } |
| 51 |
| 52 inherits(InfoView, DivView); |
| 53 |
| 54 /** |
| 55 * Updates the view based on its currently known data |
| 56 */ |
| 57 InfoView.prototype.refresh_ = function(data) { |
| 58 var html = []; |
| 59 function separateValues(obj) { |
| 60 var subdicts = {}; |
| 61 var values = {}; |
| 62 for(var k in obj) { |
| 63 var v = obj[k]; |
| 64 if(typeof(v) === 'number' || typeof(v) === 'string') { |
| 65 values[k] = v; |
| 66 } else { |
| 67 subdicts[k] = v; |
| 68 } |
| 69 } |
| 70 return [subdicts,values]; |
| 71 } |
| 72 function outputObject(obj) { |
| 73 var items = separateValues(obj); |
| 74 var subdicts = items[0]; |
| 75 var values = items[1]; |
| 76 html.push("<table>"); |
| 77 for(var k in values) { // output values |
| 78 html.push("<tr><td><strong>"); |
| 79 html.push(k); |
| 80 html.push("</strong></td><td>"); |
| 81 html.push(values[k]); |
| 82 html.push("</td></tr>"); |
| 83 } |
| 84 html.push("</table>"); |
| 85 |
| 86 html.push("<ul>"); |
| 87 for(var k in subdicts) { // output subdicts |
| 88 html.push("<li><strong>" + k + ":</strong> "); |
| 89 outputObject(subdicts[k]); |
| 90 html.push("</li>"); |
| 91 } |
| 92 html.push("</ul>"); |
| 93 } |
| 94 |
| 95 function outputObjectV2(obj) { |
| 96 var all_values = true; |
| 97 for (var k in obj) { // output values |
| 98 var v = obj[k]; |
| 99 if(!(typeof(v) === 'number' || typeof(v) === "string")) { |
| 100 all_values = false; |
| 101 } |
| 102 } |
| 103 if (all_values) |
| 104 html.push("<table class='border'>"); |
| 105 else |
| 106 html.push("<table>"); |
| 107 for (var k in obj) { // output values |
| 108 var v = obj[k]; |
| 109 if (typeof(v) === 'number' || typeof(v) === "string") { |
| 110 html.push("<tr><td><strong>"); |
| 111 html.push(k); |
| 112 html.push("</strong></td><td>"); |
| 113 html.push(v); |
| 114 html.push("</td></tr>"); |
| 115 } else { |
| 116 html.push("<tr><td colspan=2><strong>" + k + ":</strong>"); |
| 117 html.push("<div style=\"padding-left: 8px;\">"); |
| 118 outputObjectV2(v); |
| 119 html.push("</div>"); |
| 120 html.push("</td></tr>"); |
| 121 } |
| 122 } |
| 123 html.push("</table>"); |
| 124 } |
| 125 |
| 126 html.push('<h2>Chrome information</h2>'); |
| 127 if (this.clientInfo_) { |
| 128 var chromeVersion = this.clientInfo_.version + |
| 129 ' (' + this.clientInfo_.official + |
| 130 ' ' + this.clientInfo_.cl + |
| 131 ') ' + this.clientInfo_.version_mod + "</p>"; |
| 132 var data = {'Data exported on' : (new Date()).toLocaleString(), |
| 133 'Chrome version: ' : chromeVersion}; |
| 134 outputObjectV2(data); |
| 135 } else { |
| 136 html.push('... refreshing data ...'); |
| 137 } |
| 138 |
| 139 html.push('<h2>GPU information</h2>'); |
| 140 if (this.gpuInfo_) { |
| 141 outputObjectV2(this.gpuInfo_); |
| 142 } else { |
| 143 html.push('... refreshing data ...'); |
| 144 } |
| 145 |
| 146 // Open a new window to display this text. |
| 147 this.textDiv_.innerHTML = html.join("\n"); |
| 148 }; |
| 149 |
OLD | NEW |