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
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
|
// Copyright (c) 2011 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.
/**
* Each row in the filtered items list is backed by a SourceEntry. This
* instance contains all of the data pertaining to that row, and notifies
* its parent view (the EventsView) whenever its data changes.
*
* @constructor
*/
function SourceEntry(parentView, maxPreviousSourceId) {
this.maxPreviousSourceId_ = maxPreviousSourceId;
this.entries_ = [];
this.parentView_ = parentView;
this.isSelected_ = false;
this.isMatchedByFilter_ = false;
// Used to set CSS class for display. Must only be modified by calling
// corresponding set functions.
this.isSelected_ = false;
this.isMouseOver_ = false;
// Set to true on most net errors.
this.isError_ = false;
// If the first entry is a BEGIN_PHASE, set to false.
// Set to true when an END_PHASE matching the first entry is encountered.
this.isInactive_ = true;
}
SourceEntry.prototype.isSelected = function() {
return this.isSelected_;
};
/**
* Changes |row_|'s class based on currently set flags. Clears any previous
* class set by this method. This method is needed so that some styles
* override others.
*/
SourceEntry.prototype.updateClass_ = function() {
if (!this.row_)
return;
// Each element of this list contains a property of |this| and the
// corresponding class name to set if that property is true. Entries earlier
// in the list take precedence.
var propertyNames = [
['isSelected_', 'selected'],
['isMouseOver_', 'mouseover'],
['isError_', 'error'],
['isInactive_', 'inactive']];
// Loop through |propertyNames| in order, checking if each property
// is true. For the first such property found, if any, add the
// corresponding class to the SourceEntry's row. Remove classes
// that correspond to any other property.
var noStyleSet = true;
for (var i = 0; i < propertyNames.length; ++i) {
var setStyle = noStyleSet && this[propertyNames[i][0]];
changeClassName(this.row_, propertyNames[i][1], setStyle);
if (setStyle)
noStyleSet = false;
}
};
SourceEntry.prototype.setInactive_ = function(isInactive) {
this.isInactive_ = isInactive;
this.updateClass_();
};
SourceEntry.prototype.setError_ = function(isError) {
this.isError_ = isError;
this.updateClass_();
};
SourceEntry.prototype.setSelectedStyles = function(isSelected) {
this.isSelected_ = isSelected;
this.getSelectionCheckbox().checked = isSelected;
this.updateClass_();
};
SourceEntry.prototype.setMouseoverStyle = function(isMouseOver) {
this.isMouseOver_ = isMouseOver;
this.updateClass_();
};
SourceEntry.prototype.setIsMatchedByFilter = function(isMatchedByFilter) {
if (this.isMatchedByFilter() == isMatchedByFilter)
return; // No change.
this.isMatchedByFilter_ = isMatchedByFilter;
this.setFilterStyles(isMatchedByFilter);
if (isMatchedByFilter) {
this.parentView_.incrementPostfilterCount(1);
} else {
this.parentView_.incrementPostfilterCount(-1);
// If we are filtering an entry away, make sure it is no longer
// part of the selection.
this.setSelected(false);
}
};
SourceEntry.prototype.isMatchedByFilter = function() {
return this.isMatchedByFilter_;
};
SourceEntry.prototype.setFilterStyles = function(isMatchedByFilter) {
// Hide rows which have been filtered away.
if (isMatchedByFilter) {
this.row_.style.display = '';
} else {
this.row_.style.display = 'none';
}
};
SourceEntry.prototype.update = function(logEntry) {
if (logEntry.phase == LogEventPhase.PHASE_BEGIN &&
this.entries_.length == 0) {
this.setInactive_(false);
}
// Only the last event should have the same type first event,
if (!this.isInactive_ &&
logEntry.phase == LogEventPhase.PHASE_END &&
logEntry.type == this.entries_[0].type) {
this.setInactive_(true);
}
// If we have a net error code, update |this.isError_| if apporpriate.
if (logEntry.params) {
var netErrorCode = logEntry.params.net_error;
// Skip both cases where netErrorCode is undefined, and cases where it is
// 0, indicating no actual error occurred.
if (netErrorCode) {
// Ignore error code caused by not finding an entry in the cache.
if (logEntry.type != LogEventType.HTTP_CACHE_OPEN_ENTRY ||
netErrorCode != NetError.FAILED) {
this.setError_(true);
}
}
}
var prevStartEntry = this.getStartEntry_();
this.entries_.push(logEntry);
var curStartEntry = this.getStartEntry_();
// If we just got the first entry for this source.
if (prevStartEntry != curStartEntry) {
if (!prevStartEntry)
this.createRow_();
else
this.updateDescription_();
}
// Update filters.
var matchesFilter = this.matchesFilter(this.parentView_.currentFilter_);
this.setIsMatchedByFilter(matchesFilter);
};
SourceEntry.prototype.onCheckboxToggled_ = function() {
this.setSelected(this.getSelectionCheckbox().checked);
};
SourceEntry.prototype.matchesFilter = function(filter) {
// Safety check.
if (this.row_ == null)
return false;
if (filter.isActive && this.isInactive_)
return false;
if (filter.isInactive && !this.isInactive_)
return false;
if (filter.isError && !this.isError_)
return false;
if (filter.isNotError && this.isError_)
return false;
// Check source type, if needed.
if (filter.type) {
var sourceType = this.getSourceTypeString().toLowerCase();
if (filter.type.indexOf(sourceType) == -1)
return false;
}
// Check source ID, if needed.
if (filter.id) {
if (filter.id.indexOf(this.getSourceId() + '') == -1)
return false;
}
if (filter.text == '')
return true;
var filterText = filter.text;
var entryText = PrintSourceEntriesAsText(this.entries_).toLowerCase();
return entryText.indexOf(filterText) != -1;
};
SourceEntry.prototype.setSelected = function(isSelected) {
if (isSelected == this.isSelected())
return;
this.isSelected_ = isSelected;
this.setSelectedStyles(isSelected);
this.parentView_.modifySelectionArray(this, isSelected);
this.parentView_.onSelectionChanged();
};
SourceEntry.prototype.onClicked_ = function() {
this.parentView_.clearSelection();
this.setSelected(true);
};
SourceEntry.prototype.onMouseover_ = function() {
this.setMouseoverStyle(true);
};
SourceEntry.prototype.onMouseout_ = function() {
this.setMouseoverStyle(false);
};
SourceEntry.prototype.updateDescription_ = function() {
this.descriptionCell_.innerHTML = '';
addTextNode(this.descriptionCell_, this.getDescription());
};
SourceEntry.prototype.createRow_ = function() {
// Create a row.
var tr = addNode(this.parentView_.tableBody_, 'tr');
tr._id = this.getSourceId();
tr.style.display = 'none';
this.row_ = tr;
var selectionCol = addNode(tr, 'td');
var checkbox = addNode(selectionCol, 'input');
checkbox.type = 'checkbox';
var idCell = addNode(tr, 'td');
idCell.style.textAlign = 'right';
var typeCell = addNode(tr, 'td');
var descriptionCell = addNode(tr, 'td');
this.descriptionCell_ = descriptionCell;
// Connect listeners.
checkbox.onchange = this.onCheckboxToggled_.bind(this);
var onclick = this.onClicked_.bind(this);
idCell.onclick = onclick;
typeCell.onclick = onclick;
descriptionCell.onclick = onclick;
tr.onmouseover = this.onMouseover_.bind(this);
tr.onmouseout = this.onMouseout_.bind(this);
// Set the cell values to match this source's data.
if (this.getSourceId() >= 0)
addTextNode(idCell, this.getSourceId());
else
addTextNode(idCell, '-');
var sourceTypeString = this.getSourceTypeString();
addTextNode(typeCell, sourceTypeString);
this.updateDescription_();
// Add a CSS classname specific to this source type (so CSS can specify
// different stylings for different types).
changeClassName(this.row_, 'source_' + sourceTypeString, true);
this.updateClass_();
};
/**
* Returns a description for this source log stream, which will be displayed
* in the list view. Most often this is a URL that identifies the request,
* or a hostname for a connect job, etc...
*/
SourceEntry.prototype.getDescription = function() {
var e = this.getStartEntry_();
if (!e)
return '';
if (e.source.type == LogSourceType.NONE) {
// NONE is what we use for global events that aren't actually grouped
// by a "source ID", so we will just stringize the event's type.
return getKeyWithValue(LogEventType, e.type);
}
if (e.params == undefined)
return '';
var description = '';
switch (e.source.type) {
case LogSourceType.URL_REQUEST:
case LogSourceType.SOCKET_STREAM:
case LogSourceType.HTTP_STREAM_JOB:
description = e.params.url;
break;
case LogSourceType.CONNECT_JOB:
description = e.params.group_name;
break;
case LogSourceType.HOST_RESOLVER_IMPL_REQUEST:
case LogSourceType.HOST_RESOLVER_IMPL_JOB:
description = e.params.host;
break;
case LogSourceType.DISK_CACHE_ENTRY:
case LogSourceType.MEMORY_CACHE_ENTRY:
description = e.params.key;
break;
case LogSourceType.SPDY_SESSION:
if (e.params.host)
description = e.params.host + ' (' + e.params.proxy + ')';
break;
case LogSourceType.SOCKET:
if (e.params.source_dependency != undefined) {
var connectJobSourceEntry =
this.parentView_.getSourceEntry(e.params.source_dependency.id);
if (connectJobSourceEntry)
description = connectJobSourceEntry.getDescription();
}
break;
case LogSourceType.DNS_TRANSACTION:
description = e.params.hostname;
break;
}
if (description == undefined)
return '';
return description;
};
/**
* Returns the starting entry for this source. Conceptually this is the
* first entry that was logged to this source. However, we skip over the
* TYPE_REQUEST_ALIVE entries which wrap TYPE_URL_REQUEST_START_JOB /
* TYPE_SOCKET_STREAM_CONNECT.
*/
SourceEntry.prototype.getStartEntry_ = function() {
if (this.entries_.length < 1)
return undefined;
if (this.entries_.length >= 2) {
if (this.entries_[0].type == LogEventType.REQUEST_ALIVE ||
this.entries_[0].type == LogEventType.SOCKET_POOL_CONNECT_JOB)
return this.entries_[1];
}
return this.entries_[0];
};
SourceEntry.prototype.getLogEntries = function() {
return this.entries_;
};
SourceEntry.prototype.getSourceTypeString = function() {
return getKeyWithValue(LogSourceType, this.entries_[0].source.type);
};
SourceEntry.prototype.getSelectionCheckbox = function() {
return this.row_.childNodes[0].firstChild;
};
SourceEntry.prototype.getSourceId = function() {
return this.entries_[0].source.id;
};
/**
* Returns the largest source ID seen before this object was received.
* Used only for sorting SourceEntries without a source by source ID.
*/
SourceEntry.prototype.getMaxPreviousEntrySourceId = function() {
return this.maxPreviousSourceId_;
};
SourceEntry.prototype.isActive = function() {
return !this.isInactive_;
};
/**
* Returns time of last event if inactive. Returns current time otherwise.
*/
SourceEntry.prototype.getEndTime = function() {
if (!this.isInactive_) {
return (new Date()).getTime();
}
else {
var endTicks = this.entries_[this.entries_.length - 1].time;
return g_browser.convertTimeTicksToDate(endTicks).getTime();
}
};
/**
* Returns the time between the first and last events with a matching
* source ID. If source is still active, uses the current time for the
* last event.
*/
SourceEntry.prototype.getDuration = function() {
var startTicks = this.entries_[0].time;
var startTime = g_browser.convertTimeTicksToDate(startTicks).getTime();
var endTime = this.getEndTime();
return endTime - startTime;
};
/**
* Returns source ID of the entry whose row is currently above this one's.
* Returns null if no such node exists.
*/
SourceEntry.prototype.getPreviousNodeSourceId = function() {
if (!this.hasRow())
return null;
var prevNode = this.row_.previousSibling;
if (prevNode == null)
return null;
return prevNode._id;
};
/**
* Returns source ID of the entry whose row is currently below this one's.
* Returns null if no such node exists.
*/
SourceEntry.prototype.getNextNodeSourceId = function() {
if (!this.hasRow())
return null;
var nextNode = this.row_.nextSibling;
if (nextNode == null)
return null;
return nextNode._id;
};
SourceEntry.prototype.hasRow = function() {
return this.row_ != null;
};
/**
* Moves current object's row before |entry|'s row.
*/
SourceEntry.prototype.moveBefore = function(entry) {
if (this.hasRow() && entry.hasRow()) {
this.row_.parentNode.insertBefore(this.row_, entry.row_);
}
};
/**
* Moves current object's row after |entry|'s row.
*/
SourceEntry.prototype.moveAfter = function(entry) {
if (this.hasRow() && entry.hasRow()) {
this.row_.parentNode.insertBefore(this.row_, entry.row_.nextSibling);
}
};
SourceEntry.prototype.remove = function() {
this.setSelected(false);
this.setIsMatchedByFilter(false);
this.row_.parentNode.removeChild(this.row_);
};
|