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 * TODO(eroman): This needs better presentation, and cleaner code. This |
| 7 * implementation is more of a transitionary step as |
| 8 * the old net-internals is replaced. |
| 9 */ |
| 10 |
| 11 var PaintLogView; |
| 12 |
| 13 // Start of anonymous namespace. |
| 14 (function() { |
| 15 |
| 16 PaintLogView = function(sourceEntries, node) { |
| 17 for (var i = 0; i < sourceEntries.length; ++i) { |
| 18 if (i != 0) |
| 19 addNode(node, 'hr'); |
| 20 addSourceEntry_(node, sourceEntries[i]); |
| 21 } |
| 22 } |
| 23 |
| 24 const INDENTATION_PX = 20; |
| 25 |
| 26 function addSourceEntry_(node, sourceEntry) { |
| 27 var div = addNode(node, 'div'); |
| 28 div.className = 'logSourceEntry'; |
| 29 |
| 30 var p = addNode(div, 'p'); |
| 31 var nobr = addNode(p, 'nobr'); |
| 32 |
| 33 addTextNode(nobr, sourceEntry.getDescription()); |
| 34 |
| 35 var groupedEntries = LogGroupEntry.createArrayFrom( |
| 36 sourceEntry.getLogEntries()); |
| 37 |
| 38 makeLoadLogTable_(div, groupedEntries); |
| 39 } |
| 40 |
| 41 function makeLoadLogTable_(node, entries) { |
| 42 var table = addNode(node, 'table'); |
| 43 var tbody = addNode(node, 'tbody'); |
| 44 |
| 45 for (var i = 0; i < entries.length; ++i) { |
| 46 var entry = entries[i]; |
| 47 |
| 48 // Avoid printing the END for a BEGIN that was immediately before. |
| 49 if (entry.isEnd() && entry.begin && entry.begin.index == i - 1) { |
| 50 continue; |
| 51 } |
| 52 |
| 53 var tr = addNode(node, 'tr'); |
| 54 |
| 55 var timeLabelCell = addNode(tr, 'td'); |
| 56 addTextNode(timeLabelCell, 't='); |
| 57 |
| 58 var timeCell = addNode(tr, 'td'); |
| 59 timeCell.style.textAlign = 'right'; |
| 60 timeCell.style.paddingRight = '5px'; |
| 61 addTextNode(timeCell, entry.orig.time); |
| 62 |
| 63 var mainCell = addNode(tr, 'td'); |
| 64 mainCell.style.paddingRight = '5px'; |
| 65 var dtLabelCell = addNode(tr, 'td'); |
| 66 var dtCell = addNode(tr, 'td'); |
| 67 dtCell.style.textAlign = 'right'; |
| 68 |
| 69 mainCell.style.paddingLeft = (INDENTATION_PX * entry.getDepth()) + "px"; |
| 70 |
| 71 if (entry.orig.type == LogEntryType.TYPE_EVENT) { |
| 72 addTextNode(mainCell, getTextForEvent(entry)); |
| 73 |
| 74 // Get the elapsed time. |
| 75 if (entry.isBegin()) { |
| 76 addTextNode(dtLabelCell, '[dt='); |
| 77 |
| 78 // Definite time. |
| 79 if (entry.end) { |
| 80 var dt = entry.end.orig.time - entry.orig.time; |
| 81 addTextNode(dtCell, dt + ']'); |
| 82 } else { |
| 83 addTextNode(dtCell, '?]'); |
| 84 } |
| 85 } |
| 86 } else { |
| 87 mainCell.colSpan = '3'; |
| 88 if (entry.orig.type == LogEntryType.TYPE_STRING) { |
| 89 addTextNode(mainCell, entry.orig.string); |
| 90 } else if (entry.orig.type == LogEntryType.TYPE_ERROR_CODE) { |
| 91 // TODO(eroman): print symbolic name of error code. |
| 92 addTextNode(mainCell, "Network error: " + entry.orig.error_code); |
| 93 } else { |
| 94 addTextNode(mainCell, "Unrecognized entry type: " + entry.orig.type); |
| 95 } |
| 96 } |
| 97 } |
| 98 } |
| 99 |
| 100 function getTextForEvent(entry) { |
| 101 var text = ''; |
| 102 |
| 103 if (entry.isBegin()) { |
| 104 text = '+' + text; |
| 105 } else if (entry.isEnd()) { |
| 106 text = '-' + text; |
| 107 } else { |
| 108 text = '.'; |
| 109 } |
| 110 |
| 111 text += getKeyWithValue(LogEventType, entry.orig.event.type); |
| 112 return text; |
| 113 } |
| 114 |
| 115 // End of anonymous namespace. |
| 116 })(); |
| 117 |
OLD | NEW |