| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 // TODO(eroman): put these methods into a namespace. | 5 // TODO(eroman): put these methods into a namespace. |
| 6 | 6 |
| 7 var printLogEntriesAsText; | 7 var printLogEntriesAsText; |
| 8 var searchLogEntriesForText; |
| 8 var proxySettingsToString; | 9 var proxySettingsToString; |
| 9 var stripCookiesAndLoginInfo; | 10 var stripCookiesAndLoginInfo; |
| 10 | 11 |
| 11 // Start of anonymous namespace. | 12 // Start of anonymous namespace. |
| 12 (function() { | 13 (function() { |
| 13 'use strict'; | 14 'use strict'; |
| 14 | 15 |
| 15 function canCollapseBeginWithEnd(beginEntry) { | 16 function canCollapseBeginWithEnd(beginEntry) { |
| 16 return beginEntry && | 17 return beginEntry && |
| 17 beginEntry.isBegin() && | 18 beginEntry.isBegin() && |
| 18 beginEntry.end && | 19 beginEntry.end && |
| 19 beginEntry.end.index == beginEntry.index + 1 && | 20 beginEntry.end.index == beginEntry.index + 1 && |
| 20 (!beginEntry.orig.params || !beginEntry.end.orig.params); | 21 (!beginEntry.orig.params || !beginEntry.end.orig.params); |
| 21 } | 22 } |
| 22 | 23 |
| 23 /** | 24 /** |
| 24 * Adds a child pre element to the end of |parent|, and writes the | 25 * Adds a child pre element to the end of |parent|, and writes the |
| 25 * formatted contents of |logEntries| to it. | 26 * formatted contents of |logEntries| to it. |
| 26 */ | 27 */ |
| 27 printLogEntriesAsText = function(logEntries, parent, privacyStripping, | 28 printLogEntriesAsText = function(logEntries, parent, privacyStripping, |
| 28 logCreationTime) { | 29 logCreationTime) { |
| 30 var tablePrinter = createTablePrinter(logEntries, privacyStripping, |
| 31 logCreationTime); |
| 32 |
| 33 // Format the table for fixed-width text. |
| 34 tablePrinter.toText(0, parent); |
| 35 } |
| 36 |
| 37 /** |
| 38 * Searches the table that would be output by printLogEntriesAsText for |
| 39 * |searchString|. Returns true if |searchString| would appear entirely within |
| 40 * any field in the table. |searchString| must be lowercase. |
| 41 * |
| 42 * Seperate function from printLogEntriesAsText since TablePrinter.toText |
| 43 * modifies the DOM. |
| 44 */ |
| 45 searchLogEntriesForText = function(searchString, logEntries, privacyStripping) { |
| 46 var tablePrinter = |
| 47 createTablePrinter(logEntries, privacyStripping, undefined); |
| 48 |
| 49 // Format the table for fixed-width text. |
| 50 return tablePrinter.search(searchString); |
| 51 } |
| 52 |
| 53 /** |
| 54 * Creates a TablePrinter for use by the above two functions. |
| 55 */ |
| 56 function createTablePrinter(logEntries, privacyStripping, logCreationTime) { |
| 29 var entries = LogGroupEntry.createArrayFrom(logEntries); | 57 var entries = LogGroupEntry.createArrayFrom(logEntries); |
| 30 var tablePrinter = new TablePrinter(); | 58 var tablePrinter = new TablePrinter(); |
| 31 var parameterOutputter = new ParameterOutputter(tablePrinter); | 59 var parameterOutputter = new ParameterOutputter(tablePrinter); |
| 32 | 60 |
| 33 if (entries.length == 0) | 61 if (entries.length == 0) |
| 34 return; | 62 return tablePrinter; |
| 35 | 63 |
| 36 var startTime = timeutil.convertTimeTicksToTime(entries[0].orig.time); | 64 var startTime = timeutil.convertTimeTicksToTime(entries[0].orig.time); |
| 37 | 65 |
| 38 for (var i = 0; i < entries.length; ++i) { | 66 for (var i = 0; i < entries.length; ++i) { |
| 39 var entry = entries[i]; | 67 var entry = entries[i]; |
| 40 | 68 |
| 41 // Avoid printing the END for a BEGIN that was immediately before, unless | 69 // Avoid printing the END for a BEGIN that was immediately before, unless |
| 42 // both have extra parameters. | 70 // both have extra parameters. |
| 43 if (!entry.isEnd() || !canCollapseBeginWithEnd(entry.begin)) { | 71 if (!entry.isEnd() || !canCollapseBeginWithEnd(entry.begin)) { |
| 44 var entryTime = timeutil.convertTimeTicksToTime(entry.orig.time); | 72 var entryTime = timeutil.convertTimeTicksToTime(entry.orig.time); |
| (...skipping 29 matching lines...) Expand all Loading... |
| 74 } | 102 } |
| 75 } | 103 } |
| 76 | 104 |
| 77 // If viewing a saved log file, add row with just the time the log was | 105 // If viewing a saved log file, add row with just the time the log was |
| 78 // created, if the event never completed. | 106 // created, if the event never completed. |
| 79 if (logCreationTime != undefined && | 107 if (logCreationTime != undefined && |
| 80 entries[entries.length - 1].getDepth() > 0) { | 108 entries[entries.length - 1].getDepth() > 0) { |
| 81 addRowWithTime(tablePrinter, logCreationTime, startTime); | 109 addRowWithTime(tablePrinter, logCreationTime, startTime); |
| 82 } | 110 } |
| 83 | 111 |
| 84 // Format the table for fixed-width text. | 112 return tablePrinter; |
| 85 tablePrinter.toText(0, parent); | |
| 86 } | 113 } |
| 87 | 114 |
| 88 /** | 115 /** |
| 89 * Adds a new row to the given TablePrinter, and adds five cells containing | 116 * Adds a new row to the given TablePrinter, and adds five cells containing |
| 90 * information about the time an event occured. | 117 * information about the time an event occured. |
| 91 * Format is '[t=<UTC time in ms>] [st=<ms since the source started>]'. | 118 * Format is '[t=<UTC time in ms>] [st=<ms since the source started>]'. |
| 92 * @param {TablePrinter} tablePrinter The table printer to add the cells to. | 119 * @param {TablePrinter} tablePrinter The table printer to add the cells to. |
| 93 * @param {number} eventTime The time the event occured, as a UTC time in | 120 * @param {number} eventTime The time the event occured, as a UTC time in |
| 94 * milliseconds. | 121 * milliseconds. |
| 95 * @param {number} startTime The time the first event for the source occured, | 122 * @param {number} startTime The time the first event for the source occured, |
| (...skipping 567 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 663 | 690 |
| 664 if (config.source != undefined && config.source != 'UNKNOWN') | 691 if (config.source != undefined && config.source != 'UNKNOWN') |
| 665 result.push('Source: ' + config.source); | 692 result.push('Source: ' + config.source); |
| 666 | 693 |
| 667 return result.join('\n'); | 694 return result.join('\n'); |
| 668 }; | 695 }; |
| 669 | 696 |
| 670 // End of anonymous namespace. | 697 // End of anonymous namespace. |
| 671 })(); | 698 })(); |
| 672 | 699 |
| OLD | NEW |