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) 2010 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.
/**
* TODO(eroman): This needs better presentation, and cleaner code. This
* implementation is more of a transitionary step as
* the old net-internals is replaced.
*/
var PaintLogView;
var PrintSourceEntriesAsText;
// Start of anonymous namespace.
(function() {
PaintLogView = function(sourceEntries, node) {
for (var i = 0; i < sourceEntries.length; ++i) {
if (i != 0)
addNode(node, 'hr');
addSourceEntry_(node, sourceEntries[i]);
}
}
const INDENTATION_PX = 20;
function addSourceEntry_(node, sourceEntry) {
var div = addNode(node, 'div');
div.className = 'logSourceEntry';
var p = addNode(div, 'p');
var nobr = addNode(p, 'nobr');
addTextNode(nobr, sourceEntry.getDescription());
var pre = addNode(div, 'pre');
addTextNode(pre, PrintSourceEntriesAsText(sourceEntry.getLogEntries()));
}
PrintSourceEntriesAsText = function(sourceEntries) {
var entries = LogGroupEntry.createArrayFrom(sourceEntries);
var tablePrinter = new TablePrinter();
for (var i = 0; i < entries.length; ++i) {
var entry = entries[i];
// Avoid printing the END for a BEGIN that was immediately before.
// (Except if the END contains any extra parameters).
if (entry.isEnd() && !entry.orig.params && entry.begin &&
entry.begin.index == i - 1) {
continue;
}
tablePrinter.addRow();
tablePrinter.addCell('t=');
var tCell = tablePrinter.addCell(
g_browser.convertTimeTicksToDate(entry.orig.time).getTime());
tCell.alignRight = true;
tablePrinter.addCell(' ');
var indentationStr = makeRepeatedString(' ', entry.getDepth() * 3);
var mainCell =
tablePrinter.addCell(indentationStr + getTextForEvent(entry));
tablePrinter.addCell(' ');
// Get the elapsed time.
if (entry.isBegin()) {
tablePrinter.addCell('[dt=');
var dt = '?';
// Definite time.
if (entry.end) {
dt = entry.end.orig.time - entry.orig.time;
}
var dtCell = tablePrinter.addCell(dt);
dtCell.alignRight = true;
tablePrinter.addCell(']');
} else {
mainCell.allowOverflow = true;
}
// Output the extra parameters.
if (entry.orig.params != undefined) {
// Add a continuation row for each line of text from the extra parameters.
var extraParamsText = getTextForExtraParams(entry.orig);
var extraParamsTextLines = extraParamsText.split('\n');
for (var j = 0; j < extraParamsTextLines.length; ++j) {
tablePrinter.addRow();
tablePrinter.addCell(''); // No t=.
tablePrinter.addCell('');
tablePrinter.addCell(' ');
var mainExtraCell =
tablePrinter.addCell(indentationStr + extraParamsTextLines[j]);
mainExtraCell.allowOverflow = true;
}
}
}
// Format the table for fixed-width text.
return tablePrinter.toText();
}
function getTextForExtraParams(entry) {
// Format the extra parameters (use a custom formatter for certain types,
// but default to displaying as JSON).
switch (entry.type) {
case LogEventType.HTTP_TRANSACTION_SEND_REQUEST_HEADERS:
case LogEventType.HTTP_TRANSACTION_SEND_TUNNEL_HEADERS:
return getTextForRequestHeadersExtraParam(entry);
case LogEventType.HTTP_TRANSACTION_READ_RESPONSE_HEADERS:
case LogEventType.HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS:
return getTextForResponseHeadersExtraParam(entry);
default:
var out = [];
for (var k in entry.params) {
out.push(' --> ' + k + ' = ' +
JSON.stringify(entry.params[k]));
}
return out.join('\n');
}
}
/**
* Indent |lines| by |start|.
*
* For example, if |start| = ' -> ' and |lines| = ['line1', 'line2', 'line3']
* the output will be:
*
* " -> line1\n" +
* " line2\n" +
* " line3"
*/
function indentLines(start, lines) {
return start + lines.join('\n' + makeRepeatedString(' ', start.length));
}
function getTextForRequestHeadersExtraParam(entry) {
var params = entry.params;
// Strip the trailing CRLF that params.line contains.
var lineWithoutCRLF = params.line.replace(/\r\n$/g, '');
return indentLines(' --> ', [lineWithoutCRLF].concat(params.headers));
}
function getTextForResponseHeadersExtraParam(entry) {
return indentLines(' --> ', entry.params.headers);
}
function getTextForEvent(entry) {
var text = '';
if (entry.isBegin() && entry.end && entry.end.index == entry.index + 1 &&
!entry.end.orig.params) {
// Don't prefix with '+' if we are going to collapse the END event.
text = ' ';
} else if (entry.isBegin()) {
text = '+' + text;
} else if (entry.isEnd()) {
text = '-' + text;
} else {
text = ' ';
}
text += getKeyWithValue(LogEventType, entry.orig.type);
return text;
}
// End of anonymous namespace.
})();
|