Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(3)

Side by Side Diff: chrome/browser/resources/net_internals/log_view_painter.js

Issue 8890016: Make source_dependencies in about:net-internals clickable. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Fix missed variable name change Created 9 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 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 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 * TODO(eroman): This needs better presentation, and cleaner code. This 6 * TODO(eroman): This needs better presentation, and cleaner code. This
7 * implementation is more of a transitionary step as 7 * implementation is more of a transitionary step as
8 * the old net-internals is replaced. 8 * the old net-internals is replaced.
9 */ 9 */
10 10
11 // TODO(eroman): these functions should use lower-case names. 11 var paintLogView;
12 var PaintLogView; 12 var printLogEntriesAsText;
13 var PrintSourceEntriesAsText;
14 var proxySettingsToString; 13 var proxySettingsToString;
15 var stripCookiesAndLoginInfo; 14 var stripCookiesAndLoginInfo;
16 15
17 // Start of anonymous namespace. 16 // Start of anonymous namespace.
18 (function() { 17 (function() {
19 'use strict'; 18 'use strict';
20 19
21 PaintLogView = function(sourceEntries, node) { 20 paintLogView = function(sourceEntries, node) {
22 for (var i = 0; i < sourceEntries.length; ++i) { 21 for (var i = 0; i < sourceEntries.length; ++i) {
23 if (i != 0) 22 if (i != 0)
24 addNode(node, 'hr'); 23 addNode(node, 'hr');
25 addSourceEntry_(node, sourceEntries[i]); 24 addSourceEntry_(node, sourceEntries[i]);
26 } 25 }
27 } 26 }
28 27
28 /**
29 * Outputs descriptive text for |sourceEntry| and its events to |node|.
30 */
29 function addSourceEntry_(node, sourceEntry) { 31 function addSourceEntry_(node, sourceEntry) {
30 var div = addNode(node, 'div'); 32 var div = addNode(node, 'div');
31 div.className = 'logSourceEntry'; 33 div.className = 'logSourceEntry';
32 34
33 var p = addNode(div, 'p'); 35 var p = addNode(div, 'p');
34 var nobr = addNode(p, 'nobr'); 36 addNodeWithText(p, 'h4',
37 sourceEntry.getSourceId() + ': ' +
38 sourceEntry.getSourceTypeString());
35 39
36 addTextNode(nobr, sourceEntry.getDescription()); 40 if (sourceEntry.getDescription())
37 41 addNodeWithText(p, 'h4', sourceEntry.getDescription());
38 var p2 = addNode(div, 'p');
39 var nobr2 = addNode(p2, 'nobr');
40 42
41 var logEntries = sourceEntry.getLogEntries(); 43 var logEntries = sourceEntry.getLogEntries();
42 var startDate = timeutil.convertTimeTicksToDate(logEntries[0].time); 44 var startDate = timeutil.convertTimeTicksToDate(logEntries[0].time);
43 addTextNode(nobr2, 'Start Time: ' + startDate.toLocaleString()); 45 addNodeWithText(p, 'div', 'Start Time: ' + startDate.toLocaleString());
44 46
45 var pre = addNode(div, 'pre'); 47 sourceEntry.printAsText(div);
46 addTextNode(pre, PrintSourceEntriesAsText(logEntries));
47 } 48 }
48 49
49 function canCollapseBeginWithEnd(beginEntry) { 50 function canCollapseBeginWithEnd(beginEntry) {
50 return beginEntry && 51 return beginEntry &&
51 beginEntry.isBegin() && 52 beginEntry.isBegin() &&
52 beginEntry.end && 53 beginEntry.end &&
53 beginEntry.end.index == beginEntry.index + 1 && 54 beginEntry.end.index == beginEntry.index + 1 &&
54 (!beginEntry.orig.params || !beginEntry.end.orig.params) && 55 (!beginEntry.orig.params || !beginEntry.end.orig.params) &&
55 beginEntry.orig.wasPassivelyCaptured == 56 beginEntry.orig.wasPassivelyCaptured ==
56 beginEntry.end.orig.wasPassivelyCaptured; 57 beginEntry.end.orig.wasPassivelyCaptured;
57 } 58 }
58 59
59 PrintSourceEntriesAsText = function(sourceEntries) { 60 /**
60 var entries = LogGroupEntry.createArrayFrom(sourceEntries); 61 * Adds a child pre element to the end of |parent|, and writes the
62 * formatted contents of |logEntries| to it.
63 */
64 printLogEntriesAsText = function(logEntries, parent) {
65 var entries = LogGroupEntry.createArrayFrom(logEntries);
66 var tablePrinter = new TablePrinter();
67
61 if (entries.length == 0) 68 if (entries.length == 0)
62 return ''; 69 return;
63 70
64 var startDate = timeutil.convertTimeTicksToDate(entries[0].orig.time); 71 var startDate = timeutil.convertTimeTicksToDate(entries[0].orig.time);
65 var startTime = startDate.getTime(); 72 var startTime = startDate.getTime();
66 73
67 var tablePrinter = new TablePrinter();
68
69 for (var i = 0; i < entries.length; ++i) { 74 for (var i = 0; i < entries.length; ++i) {
70 var entry = entries[i]; 75 var entry = entries[i];
71 76
72 // Avoid printing the END for a BEGIN that was immediately before, unless 77 // Avoid printing the END for a BEGIN that was immediately before, unless
73 // both have extra parameters. 78 // both have extra parameters.
74 if (!entry.isEnd() || !canCollapseBeginWithEnd(entry.begin)) { 79 if (!entry.isEnd() || !canCollapseBeginWithEnd(entry.begin)) {
75 tablePrinter.addRow(); 80 tablePrinter.addRow();
76 81
77 // Annotate this entry with "(P)" if it was passively captured. 82 // Annotate this entry with "(P)" if it was passively captured.
78 tablePrinter.addCell(entry.orig.wasPassivelyCaptured ? '(P) ' : ''); 83 tablePrinter.addCell(entry.orig.wasPassivelyCaptured ? '(P) ' : '');
79 84
80 tablePrinter.addCell('t='); 85 tablePrinter.addCell('t=');
81 var date = timeutil.convertTimeTicksToDate(entry.orig.time) ; 86 var date = timeutil.convertTimeTicksToDate(entry.orig.time) ;
82 var tCell = tablePrinter.addCell(date.getTime()); 87 var tCell = tablePrinter.addCell(date.getTime());
83 tCell.alignRight = true; 88 tCell.alignRight = true;
84 tablePrinter.addCell(' [st='); 89 tablePrinter.addCell(' [st=');
85 var stCell = tablePrinter.addCell(date.getTime() - startTime); 90 var stCell = tablePrinter.addCell(date.getTime() - startTime);
86 stCell.alignRight = true; 91 stCell.alignRight = true;
87 tablePrinter.addCell('] '); 92 tablePrinter.addCell('] ');
88 93
89 var indentationStr = makeRepeatedString(' ', entry.getDepth() * 3); 94 for (var j = entry.getDepth(); j > 0; --j)
90 var mainCell = 95 tablePrinter.addCell(' ');
91 tablePrinter.addCell(indentationStr + getTextForEvent(entry));
92 tablePrinter.addCell(' ');
93 96
94 // Get the elapsed time. 97 var eventText = getTextForEvent(entry);
98 // Get the elapsed time, and append it to the event text.
95 if (entry.isBegin()) { 99 if (entry.isBegin()) {
96 tablePrinter.addCell('[dt=');
97 var dt = '?'; 100 var dt = '?';
98 // Definite time. 101 // Definite time.
99 if (entry.end) { 102 if (entry.end) {
100 dt = entry.end.orig.time - entry.orig.time; 103 dt = entry.end.orig.time - entry.orig.time;
101 } 104 }
102 var dtCell = tablePrinter.addCell(dt); 105 eventText += ' [dt=' + dt + ']';
103 dtCell.alignRight = true; 106 }
104 107
105 tablePrinter.addCell(']'); 108 var mainCell = tablePrinter.addCell(eventText);
106 } else { 109 mainCell.allowOverflow = true;
107 mainCell.allowOverflow = true;
108 }
109 } 110 }
110 111
111 // Output the extra parameters. 112 // Output the extra parameters.
112 if (entry.orig.params != undefined) { 113 if (entry.orig.params != undefined) {
113 // Add a continuation row for each line of text from the extra parameters. 114 // Those 6 skipped cells are: passive annotation, two for "t=", and
114 var extraParamsText = getTextForExtraParams( 115 // three for "st=".
115 entry.orig, 116 tablePrinter.setNewRowCellIndent(6 + entry.getDepth());
116 g_browser.sourceTracker.getSecurityStripping()); 117 addRowsForExtraParams(tablePrinter,
117 var extraParamsTextLines = extraParamsText.split('\n'); 118 entry.orig,
118 119 g_browser.sourceTracker.getSecurityStripping());
119 for (var j = 0; j < extraParamsTextLines.length; ++j) { 120 tablePrinter.setNewRowCellIndent(0);
120 tablePrinter.addRow();
121 tablePrinter.addCell(''); // Empty passive annotation.
122 tablePrinter.addCell(''); // No t=.
123 tablePrinter.addCell('');
124 tablePrinter.addCell(''); // No st=.
125 tablePrinter.addCell('');
126 tablePrinter.addCell(' ');
127
128 var mainExtraCell =
129 tablePrinter.addCell(indentationStr + extraParamsTextLines[j]);
130 mainExtraCell.allowOverflow = true;
131 }
132 } 121 }
133 } 122 }
134 123
135 // Format the table for fixed-width text. 124 // Format the table for fixed-width text.
136 return tablePrinter.toText(0); 125 tablePrinter.toText(0, parent);
137 } 126 }
138 127
139 /** 128 /**
140 * |hexString| must be a string of hexadecimal characters with no whitespace, 129 * |hexString| must be a string of hexadecimal characters with no whitespace,
141 * whose length is a multiple of two. Returns a string spanning multiple lines, 130 * whose length is a multiple of two. Returns a string spanning multiple lines,
142 * with the hexadecimal characters from |hexString| on the left, in groups of 131 * with the hexadecimal characters from |hexString| on the left, in groups of
143 * two, and their corresponding ASCII characters on the right. 132 * two, and their corresponding ASCII characters on the right.
144 * 133 *
145 * |asciiCharsPerLine| specifies how many ASCII characters will be put on each 134 * |asciiCharsPerLine| specifies how many ASCII characters will be put on each
146 * line of the output string. 135 * line of the output string.
(...skipping 23 matching lines...) Expand all
170 } 159 }
171 160
172 // Max sure the ASCII text on last line of output lines up with previous 161 // Max sure the ASCII text on last line of output lines up with previous
173 // lines. 162 // lines.
174 hexLine += makeRepeatedString(' ', 3 * asciiCharsPerLine - hexLine.length); 163 hexLine += makeRepeatedString(' ', 3 * asciiCharsPerLine - hexLine.length);
175 out.push(' ' + hexLine + ' ' + asciiLine); 164 out.push(' ' + hexLine + ' ' + asciiLine);
176 } 165 }
177 return out.join('\n'); 166 return out.join('\n');
178 } 167 }
179 168
180 function getTextForExtraParams(entry, enableSecurityStripping) { 169 /**
170 * Splits |text| in shorter strings around linebreaks. For each of the
171 * resulting strings, adds a row to |tablePrinter| with a cell containing
172 * that text, linking to |link|. |link| may be null.
173 */
174 function addTextRows(tablePrinter, text, link) {
175 var textLines = text.split('\n');
176
177 for (var i = 0; i < textLines.length; ++i) {
178 tablePrinter.addRow();
179 var cell = tablePrinter.addCell(textLines[i]);
180 cell.link = link;
181 cell.allowOverflow = true;
182 }
183 }
184
185 /**
186 * Returns a list of FormattedTextInfo objects for |entry|'s |params|.
187 */
188 function addRowsForExtraParams(tablePrinter, entry, enableSecurityStripping) {
181 // Format the extra parameters (use a custom formatter for certain types, 189 // Format the extra parameters (use a custom formatter for certain types,
182 // but default to displaying as JSON). 190 // but default to displaying as JSON).
183 191
184 // If security stripping is enabled, remove data as needed. 192 // If security stripping is enabled, remove data as needed.
185 if (enableSecurityStripping) 193 if (enableSecurityStripping)
186 entry = stripCookiesAndLoginInfo(entry); 194 entry = stripCookiesAndLoginInfo(entry);
187 195
188 switch (entry.type) { 196 switch (entry.type) {
189 case LogEventType.HTTP_TRANSACTION_SEND_REQUEST_HEADERS: 197 case LogEventType.HTTP_TRANSACTION_SEND_REQUEST_HEADERS:
190 case LogEventType.HTTP_TRANSACTION_SEND_TUNNEL_HEADERS: 198 case LogEventType.HTTP_TRANSACTION_SEND_TUNNEL_HEADERS:
191 return getTextForRequestHeadersExtraParam(entry); 199 addTextRows(tablePrinter,
200 getTextForRequestHeadersExtraParam(entry),
201 null);
202 return;
192 203
193 case LogEventType.HTTP_TRANSACTION_READ_RESPONSE_HEADERS: 204 case LogEventType.HTTP_TRANSACTION_READ_RESPONSE_HEADERS:
194 case LogEventType.HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS: 205 case LogEventType.HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS:
195 return getTextForResponseHeadersExtraParam(entry); 206 addTextRows(tablePrinter,
207 getTextForResponseHeadersExtraParam(entry),
208 null);
209 return;
196 210
197 case LogEventType.PROXY_CONFIG_CHANGED: 211 case LogEventType.PROXY_CONFIG_CHANGED:
198 return getTextForProxyConfigChangedExtraParam(entry); 212 addTextRows(tablePrinter,
213 getTextForProxyConfigChangedExtraParam(entry),
214 null);
215 return;
199 216
200 default: 217 default:
201 var out = [];
202 for (var k in entry.params) { 218 for (var k in entry.params) {
203 if (k == 'headers' && entry.params[k] instanceof Array) { 219 if (k == 'headers' && entry.params[k] instanceof Array) {
204 out.push(getTextForResponseHeadersExtraParam(entry)); 220 addTextRows(tablePrinter,
221 getTextForResponseHeadersExtraParam(entry),
222 null);
205 continue; 223 continue;
206 } 224 }
207 var value = entry.params[k]; 225 var value = entry.params[k];
208 // For transferred bytes, display the bytes in hex and ASCII. 226 // For transferred bytes, display the bytes in hex and ASCII.
209 if (k == 'hex_encoded_bytes') { 227 if (k == 'hex_encoded_bytes') {
210 out.push(' --> ' + k + ' ='); 228 addTextRows(tablePrinter, ' --> ' + k + ' =');
211 out.push(formatHexString(value, 20)); 229 addTextRows(tablePrinter, formatHexString(value, 20));
212 continue; 230 continue;
213 } 231 }
214 232
215 var paramStr = ' --> ' + k + ' = ' + JSON.stringify(value); 233 var paramStr = ' --> ' + k + ' = ' + JSON.stringify(value);
216 234
217 // Append the symbolic name for certain constants. (This relies 235 // Append the symbolic name for certain constants. (This relies
218 // on particular naming of event parameters to infer the type). 236 // on particular naming of event parameters to infer the type).
219 if (typeof value == 'number') { 237 if (typeof value == 'number') {
220 if (k == 'net_error') { 238 if (k == 'net_error') {
221 paramStr += ' (' + getNetErrorSymbolicString(value) + ')'; 239 paramStr += ' (' + getNetErrorSymbolicString(value) + ')';
222 } else if (k == 'load_flags') { 240 } else if (k == 'load_flags') {
223 paramStr += ' (' + getLoadFlagSymbolicString(value) + ')'; 241 paramStr += ' (' + getLoadFlagSymbolicString(value) + ')';
224 } 242 }
225 } 243 }
226 244
227 out.push(paramStr); 245 var link = null;
246 // Add link to source_dependency entries.
247 if (k == 'source_dependency' && typeof value == 'object')
248 link = '#events&s=' + value.id;
249
250 addTextRows(tablePrinter, paramStr, link);
228 } 251 }
229 return out.join('\n');
230 } 252 }
231 } 253 }
232 254
233 /** 255 /**
234 * Returns the name for netError. 256 * Returns the name for netError.
235 * 257 *
236 * Example: getNetErrorSymbolicString(-105) would return 258 * Example: getNetErrorSymbolicString(-105) would return
237 * "NAME_NOT_RESOLVED". 259 * "NAME_NOT_RESOLVED".
238 */ 260 */
239 function getNetErrorSymbolicString(netError) { 261 function getNetErrorSymbolicString(netError) {
(...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after
460 var result = []; 482 var result = [];
461 for (var i = 0; i < modes.length; ++i) 483 for (var i = 0; i < modes.length; ++i)
462 result.push(indentLines('(' + (i + 1) + ') ', modes[i])); 484 result.push(indentLines('(' + (i + 1) + ') ', modes[i]));
463 485
464 return result.join('\n'); 486 return result.join('\n');
465 }; 487 };
466 488
467 // End of anonymous namespace. 489 // End of anonymous namespace.
468 })(); 490 })();
469 491
OLDNEW
« no previous file with comments | « chrome/browser/resources/net_internals/events_view.js ('k') | chrome/browser/resources/net_internals/main.css » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698