OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 // TODO(eroman): put these methods into a namespace. |
| 6 |
| 7 var createLogEntryTablePrinter; |
| 8 var proxySettingsToString; |
| 9 var stripPrivacyInfo; |
| 10 |
| 11 // Start of anonymous namespace. |
| 12 (function() { |
| 13 'use strict'; |
| 14 |
| 15 function canCollapseBeginWithEnd(beginEntry) { |
| 16 return beginEntry && |
| 17 beginEntry.isBegin() && |
| 18 beginEntry.end && |
| 19 beginEntry.end.index == beginEntry.index + 1 && |
| 20 (!beginEntry.orig.params || !beginEntry.end.orig.params); |
| 21 } |
| 22 |
| 23 /** |
| 24 * Creates a TablePrinter for use by the above two functions. baseTime is |
| 25 * the time relative to which other times are displayed. |
| 26 */ |
| 27 createLogEntryTablePrinter = function(logEntries, privacyStripping, |
| 28 baseTime, logCreationTime) { |
| 29 var entries = LogGroupEntry.createArrayFrom(logEntries); |
| 30 var tablePrinter = new TablePrinter(); |
| 31 var parameterOutputter = new ParameterOutputter(tablePrinter); |
| 32 |
| 33 if (entries.length == 0) |
| 34 return tablePrinter; |
| 35 |
| 36 var startTime = timeutil.convertTimeTicksToTime(entries[0].orig.time); |
| 37 |
| 38 for (var i = 0; i < entries.length; ++i) { |
| 39 var entry = entries[i]; |
| 40 |
| 41 // Avoid printing the END for a BEGIN that was immediately before, unless |
| 42 // both have extra parameters. |
| 43 if (!entry.isEnd() || !canCollapseBeginWithEnd(entry.begin)) { |
| 44 var entryTime = timeutil.convertTimeTicksToTime(entry.orig.time); |
| 45 addRowWithTime(tablePrinter, entryTime - baseTime, startTime - baseTime); |
| 46 |
| 47 for (var j = entry.getDepth(); j > 0; --j) |
| 48 tablePrinter.addCell(' '); |
| 49 |
| 50 var eventText = getTextForEvent(entry); |
| 51 // Get the elapsed time, and append it to the event text. |
| 52 if (entry.isBegin()) { |
| 53 var dt = '?'; |
| 54 // Definite time. |
| 55 if (entry.end) { |
| 56 dt = entry.end.orig.time - entry.orig.time; |
| 57 } else if (logCreationTime != undefined) { |
| 58 dt = (logCreationTime - entryTime) + '+'; |
| 59 } |
| 60 eventText += ' [dt=' + dt + ']'; |
| 61 } |
| 62 |
| 63 var mainCell = tablePrinter.addCell(eventText); |
| 64 mainCell.allowOverflow = true; |
| 65 } |
| 66 |
| 67 // Output the extra parameters. |
| 68 if (typeof entry.orig.params == 'object') { |
| 69 // Those 5 skipped cells are: two for "t=", and three for "st=". |
| 70 tablePrinter.setNewRowCellIndent(5 + entry.getDepth()); |
| 71 writeParameters(entry.orig, privacyStripping, parameterOutputter); |
| 72 |
| 73 tablePrinter.setNewRowCellIndent(0); |
| 74 } |
| 75 } |
| 76 |
| 77 // If viewing a saved log file, add row with just the time the log was |
| 78 // created, if the event never completed. |
| 79 var lastEntry = entries[entries.length - 1]; |
| 80 // If the last entry has a non-zero depth or is a begin event, the source is |
| 81 // still active. |
| 82 var isSourceActive = lastEntry.getDepth() != 0 || lastEntry.isBegin(); |
| 83 if (logCreationTime != undefined && isSourceActive) { |
| 84 addRowWithTime(tablePrinter, |
| 85 logCreationTime - baseTime, |
| 86 startTime - baseTime); |
| 87 } |
| 88 |
| 89 return tablePrinter; |
| 90 }; |
| 91 |
| 92 /** |
| 93 * Adds a new row to the given TablePrinter, and adds five cells containing |
| 94 * information about the time an event occured. |
| 95 * Format is '[t=<time of the event in ms>] [st=<ms since the source started>]'. |
| 96 * @param {TablePrinter} tablePrinter The table printer to add the cells to. |
| 97 * @param {number} eventTime The time the event occured, in milliseconds, |
| 98 * relative to some base time. |
| 99 * @param {number} startTime The time the first event for the source occured, |
| 100 * relative to the same base time as eventTime. |
| 101 */ |
| 102 function addRowWithTime(tablePrinter, eventTime, startTime) { |
| 103 tablePrinter.addRow(); |
| 104 tablePrinter.addCell('t='); |
| 105 var tCell = tablePrinter.addCell(eventTime); |
| 106 tCell.alignRight = true; |
| 107 tablePrinter.addCell(' [st='); |
| 108 var stCell = tablePrinter.addCell(eventTime - startTime); |
| 109 stCell.alignRight = true; |
| 110 tablePrinter.addCell('] '); |
| 111 } |
| 112 |
| 113 /** |
| 114 * |hexString| must be a string of hexadecimal characters with no whitespace, |
| 115 * whose length is a multiple of two. Writes multiple lines to |out| with |
| 116 * the hexadecimal characters from |hexString| on the left, in groups of |
| 117 * two, and their corresponding ASCII characters on the right. |
| 118 * |
| 119 * 16 bytes will be placed on each line of the output string, split into two |
| 120 * columns of 8. |
| 121 */ |
| 122 function writeHexString(hexString, out) { |
| 123 var asciiCharsPerLine = 16; |
| 124 // Number of transferred bytes in a line of output. Length of a |
| 125 // line is roughly 4 times larger. |
| 126 var hexCharsPerLine = 2 * asciiCharsPerLine; |
| 127 for (var i = 0; i < hexString.length; i += hexCharsPerLine) { |
| 128 var hexLine = ''; |
| 129 var asciiLine = ''; |
| 130 for (var j = i; j < i + hexCharsPerLine && j < hexString.length; j += 2) { |
| 131 // Split into two columns of 8 bytes each. |
| 132 if (j == i + hexCharsPerLine / 2) |
| 133 hexLine += ' '; |
| 134 var hex = hexString.substr(j, 2); |
| 135 hexLine += hex + ' '; |
| 136 var charCode = parseInt(hex, 16); |
| 137 // For ASCII codes 32 though 126, display the corresponding |
| 138 // characters. Use a space for nulls, and a period for |
| 139 // everything else. |
| 140 if (charCode >= 0x20 && charCode <= 0x7E) { |
| 141 asciiLine += String.fromCharCode(charCode); |
| 142 } else if (charCode == 0x00) { |
| 143 asciiLine += ' '; |
| 144 } else { |
| 145 asciiLine += '.'; |
| 146 } |
| 147 } |
| 148 |
| 149 // Make the ASCII text for the last line of output align with the previous |
| 150 // lines. |
| 151 hexLine += makeRepeatedString(' ', |
| 152 3 * asciiCharsPerLine + 1 - hexLine.length); |
| 153 out.writeLine(' ' + hexLine + ' ' + asciiLine); |
| 154 } |
| 155 } |
| 156 |
| 157 /** |
| 158 * Wrapper around a TablePrinter to simplify outputting lines of text for event |
| 159 * parameters. |
| 160 */ |
| 161 var ParameterOutputter = (function() { |
| 162 /** |
| 163 * @constructor |
| 164 */ |
| 165 function ParameterOutputter(tablePrinter) { |
| 166 this.tablePrinter_ = tablePrinter; |
| 167 } |
| 168 |
| 169 ParameterOutputter.prototype = { |
| 170 /** |
| 171 * Outputs a single line. |
| 172 */ |
| 173 writeLine: function(line) { |
| 174 this.tablePrinter_.addRow(); |
| 175 var cell = this.tablePrinter_.addCell(line); |
| 176 cell.allowOverflow = true; |
| 177 return cell; |
| 178 }, |
| 179 |
| 180 /** |
| 181 * Outputs a key=value line which looks like: |
| 182 * |
| 183 * --> key = value |
| 184 */ |
| 185 writeArrowKeyValue: function(key, value, link) { |
| 186 var cell = this.writeLine(kArrow + key + ' = ' + value); |
| 187 cell.link = link; |
| 188 }, |
| 189 |
| 190 /** |
| 191 * Outputs a key= line which looks like: |
| 192 * |
| 193 * --> key = |
| 194 */ |
| 195 writeArrowKey: function(key) { |
| 196 this.writeLine(kArrow + key + ' ='); |
| 197 }, |
| 198 |
| 199 /** |
| 200 * Outputs multiple lines, each indented by numSpaces. |
| 201 * For instance if numSpaces=8 it might look like this: |
| 202 * |
| 203 * line 1 |
| 204 * line 2 |
| 205 * line 3 |
| 206 */ |
| 207 writeSpaceIndentedLines: function(numSpaces, lines) { |
| 208 var prefix = makeRepeatedString(' ', numSpaces); |
| 209 for (var i = 0; i < lines.length; ++i) |
| 210 this.writeLine(prefix + lines[i]); |
| 211 }, |
| 212 |
| 213 /** |
| 214 * Outputs multiple lines such that the first line has |
| 215 * an arrow pointing at it, and subsequent lines |
| 216 * align with the first one. For example: |
| 217 * |
| 218 * --> line 1 |
| 219 * line 2 |
| 220 * line 3 |
| 221 */ |
| 222 writeArrowIndentedLines: function(lines) { |
| 223 if (lines.length == 0) |
| 224 return; |
| 225 |
| 226 this.writeLine(kArrow + lines[0]); |
| 227 |
| 228 for (var i = 1; i < lines.length; ++i) |
| 229 this.writeLine(kArrowIndentation + lines[i]); |
| 230 } |
| 231 }; |
| 232 |
| 233 var kArrow = ' --> '; |
| 234 var kArrowIndentation = ' '; |
| 235 |
| 236 return ParameterOutputter; |
| 237 })(); // end of ParameterOutputter |
| 238 |
| 239 /** |
| 240 * Formats the parameters for |entry| and writes them to |out|. |
| 241 * Certain event types have custom pretty printers. Everything else will |
| 242 * default to a JSON-like format. |
| 243 */ |
| 244 function writeParameters(entry, privacyStripping, out) { |
| 245 if (privacyStripping) { |
| 246 // If privacy stripping is enabled, remove data as needed. |
| 247 entry = stripPrivacyInfo(entry); |
| 248 } else { |
| 249 // If headers are in an object, convert them to an array for better display. |
| 250 entry = reformatHeaders(entry); |
| 251 } |
| 252 |
| 253 // Use any parameter writer available for this event type. |
| 254 var paramsWriter = getParamaterWriterForEventType(entry.type); |
| 255 var consumedParams = {}; |
| 256 if (paramsWriter) |
| 257 paramsWriter(entry, out, consumedParams); |
| 258 |
| 259 // Write any un-consumed parameters. |
| 260 for (var k in entry.params) { |
| 261 if (consumedParams[k]) |
| 262 continue; |
| 263 defaultWriteParameter(k, entry.params[k], out); |
| 264 } |
| 265 } |
| 266 |
| 267 /** |
| 268 * Finds a writer to format the parameters for events of type |eventType|. |
| 269 * |
| 270 * @return {function} The returned function "writer" can be invoked |
| 271 * as |writer(entry, writer, consumedParams)|. It will |
| 272 * output the parameters of |entry| to |out|, and fill |
| 273 * |consumedParams| with the keys of the parameters |
| 274 * consumed. If no writer is available for |eventType| then |
| 275 * returns null. |
| 276 */ |
| 277 function getParamaterWriterForEventType(eventType) { |
| 278 switch (eventType) { |
| 279 case EventType.HTTP_TRANSACTION_SEND_REQUEST_HEADERS: |
| 280 case EventType.HTTP_TRANSACTION_SEND_TUNNEL_HEADERS: |
| 281 case EventType.TYPE_HTTP_CACHE_CALLER_REQUEST_HEADERS: |
| 282 return writeParamsForRequestHeaders; |
| 283 |
| 284 case EventType.PROXY_CONFIG_CHANGED: |
| 285 return writeParamsForProxyConfigChanged; |
| 286 |
| 287 case EventType.CERT_VERIFIER_JOB: |
| 288 case EventType.SSL_CERTIFICATES_RECEIVED: |
| 289 return writeParamsForCertificates; |
| 290 case EventType.EV_CERT_CT_COMPLIANCE_CHECKED: |
| 291 return writeParamsForCheckedEVCertificates; |
| 292 |
| 293 case EventType.SSL_VERSION_FALLBACK: |
| 294 return writeParamsForSSLVersionFallback; |
| 295 } |
| 296 return null; |
| 297 } |
| 298 |
| 299 /** |
| 300 * Default parameter writer that outputs a visualization of field named |key| |
| 301 * with value |value| to |out|. |
| 302 */ |
| 303 function defaultWriteParameter(key, value, out) { |
| 304 if (key == 'headers' && value instanceof Array) { |
| 305 out.writeArrowIndentedLines(value); |
| 306 return; |
| 307 } |
| 308 |
| 309 // For transferred bytes, display the bytes in hex and ASCII. |
| 310 if (key == 'hex_encoded_bytes' && typeof value == 'string') { |
| 311 out.writeArrowKey(key); |
| 312 writeHexString(value, out); |
| 313 return; |
| 314 } |
| 315 |
| 316 // Handle source_dependency entries - add link and map source type to |
| 317 // string. |
| 318 if (key == 'source_dependency' && typeof value == 'object') { |
| 319 var link = '#events&s=' + value.id; |
| 320 var valueStr = value.id + ' (' + EventSourceTypeNames[value.type] + ')'; |
| 321 out.writeArrowKeyValue(key, valueStr, link); |
| 322 return; |
| 323 } |
| 324 |
| 325 if (key == 'net_error' && typeof value == 'number') { |
| 326 var valueStr = value + ' (' + netErrorToString(value) + ')'; |
| 327 out.writeArrowKeyValue(key, valueStr); |
| 328 return; |
| 329 } |
| 330 |
| 331 if (key == 'quic_error' && typeof value == 'number') { |
| 332 var valueStr = value + ' (' + quicErrorToString(value) + ')'; |
| 333 out.writeArrowKeyValue(key, valueStr); |
| 334 return; |
| 335 } |
| 336 |
| 337 if (key == 'quic_crypto_handshake_message' && typeof value == 'string') { |
| 338 var lines = value.split('\n'); |
| 339 out.writeArrowIndentedLines(lines); |
| 340 return; |
| 341 } |
| 342 |
| 343 if (key == 'quic_rst_stream_error' && typeof value == 'number') { |
| 344 var valueStr = value + ' (' + quicRstStreamErrorToString(value) + ')'; |
| 345 out.writeArrowKeyValue(key, valueStr); |
| 346 return; |
| 347 } |
| 348 |
| 349 if (key == 'load_flags' && typeof value == 'number') { |
| 350 var valueStr = value + ' (' + getLoadFlagSymbolicString(value) + ')'; |
| 351 out.writeArrowKeyValue(key, valueStr); |
| 352 return; |
| 353 } |
| 354 |
| 355 if (key == 'load_state' && typeof value == 'number') { |
| 356 var valueStr = value + ' (' + getKeyWithValue(LoadState, value) + ')'; |
| 357 out.writeArrowKeyValue(key, valueStr); |
| 358 return; |
| 359 } |
| 360 |
| 361 if (key == 'sdch_problem_code' && typeof value == 'number') { |
| 362 var valueStr = value + ' (' + sdchProblemCodeToString(value) + ')'; |
| 363 out.writeArrowKeyValue(key, valueStr); |
| 364 return; |
| 365 } |
| 366 |
| 367 // Otherwise just default to JSON formatting of the value. |
| 368 out.writeArrowKeyValue(key, JSON.stringify(value)); |
| 369 } |
| 370 |
| 371 /** |
| 372 * Returns the set of LoadFlags that make up the integer |loadFlag|. |
| 373 * For example: getLoadFlagSymbolicString( |
| 374 */ |
| 375 function getLoadFlagSymbolicString(loadFlag) { |
| 376 |
| 377 return getSymbolicString(loadFlag, LoadFlag, |
| 378 getKeyWithValue(LoadFlag, loadFlag)); |
| 379 } |
| 380 |
| 381 /** |
| 382 * Returns the set of CertStatusFlags that make up the integer |certStatusFlag| |
| 383 */ |
| 384 function getCertStatusFlagSymbolicString(certStatusFlag) { |
| 385 return getSymbolicString(certStatusFlag, CertStatusFlag, ''); |
| 386 } |
| 387 |
| 388 /** |
| 389 * Returns a string representing the flags composing the given bitmask. |
| 390 */ |
| 391 function getSymbolicString(bitmask, valueToName, zeroName) { |
| 392 var matchingFlagNames = []; |
| 393 |
| 394 for (var k in valueToName) { |
| 395 if (bitmask & valueToName[k]) |
| 396 matchingFlagNames.push(k); |
| 397 } |
| 398 |
| 399 // If no flags were matched, returns a special value. |
| 400 if (matchingFlagNames.length == 0) |
| 401 return zeroName; |
| 402 |
| 403 return matchingFlagNames.join(' | '); |
| 404 } |
| 405 |
| 406 /** |
| 407 * Converts an SSL version number to a textual representation. |
| 408 * For instance, SSLVersionNumberToName(0x0301) returns 'TLS 1.0'. |
| 409 */ |
| 410 function SSLVersionNumberToName(version) { |
| 411 if ((version & 0xFFFF) != version) { |
| 412 // If the version number is more than 2 bytes long something is wrong. |
| 413 // Print it as hex. |
| 414 return 'SSL 0x' + version.toString(16); |
| 415 } |
| 416 |
| 417 // See if it is a known TLS name. |
| 418 var kTLSNames = { |
| 419 0x0301: 'TLS 1.0', |
| 420 0x0302: 'TLS 1.1', |
| 421 0x0303: 'TLS 1.2' |
| 422 }; |
| 423 var name = kTLSNames[version]; |
| 424 if (name) |
| 425 return name; |
| 426 |
| 427 // Otherwise label it as an SSL version. |
| 428 var major = (version & 0xFF00) >> 8; |
| 429 var minor = version & 0x00FF; |
| 430 |
| 431 return 'SSL ' + major + '.' + minor; |
| 432 } |
| 433 |
| 434 /** |
| 435 * TODO(eroman): get rid of this, as it is only used by 1 callsite. |
| 436 * |
| 437 * Indent |lines| by |start|. |
| 438 * |
| 439 * For example, if |start| = ' -> ' and |lines| = ['line1', 'line2', 'line3'] |
| 440 * the output will be: |
| 441 * |
| 442 * " -> line1\n" + |
| 443 * " line2\n" + |
| 444 * " line3" |
| 445 */ |
| 446 function indentLines(start, lines) { |
| 447 return start + lines.join('\n' + makeRepeatedString(' ', start.length)); |
| 448 } |
| 449 |
| 450 /** |
| 451 * If entry.param.headers exists and is an object other than an array, converts |
| 452 * it into an array and returns a new entry. Otherwise, just returns the |
| 453 * original entry. |
| 454 */ |
| 455 function reformatHeaders(entry) { |
| 456 // If there are no headers, or it is not an object other than an array, |
| 457 // return |entry| without modification. |
| 458 if (!entry.params || entry.params.headers === undefined || |
| 459 typeof entry.params.headers != 'object' || |
| 460 entry.params.headers instanceof Array) { |
| 461 return entry; |
| 462 } |
| 463 |
| 464 // Duplicate the top level object, and |entry.params|, so the original object |
| 465 // will not be modified. |
| 466 entry = shallowCloneObject(entry); |
| 467 entry.params = shallowCloneObject(entry.params); |
| 468 |
| 469 // Convert headers to an array. |
| 470 var headers = []; |
| 471 for (var key in entry.params.headers) |
| 472 headers.push(key + ': ' + entry.params.headers[key]); |
| 473 entry.params.headers = headers; |
| 474 |
| 475 return entry; |
| 476 } |
| 477 |
| 478 /** |
| 479 * Removes a cookie or unencrypted login information from a single HTTP header |
| 480 * line, if present, and returns the modified line. Otherwise, just returns |
| 481 * the original line. |
| 482 * |
| 483 * Note: this logic should be kept in sync with |
| 484 * net::ElideHeaderValueForNetLog in net/http/http_log_util.cc. |
| 485 */ |
| 486 function stripCookieOrLoginInfo(line) { |
| 487 var patterns = [ |
| 488 // Cookie patterns |
| 489 /^set-cookie: /i, |
| 490 /^set-cookie2: /i, |
| 491 /^cookie: /i, |
| 492 |
| 493 // Unencrypted authentication patterns |
| 494 /^authorization: \S*\s*/i, |
| 495 /^proxy-authorization: \S*\s*/i]; |
| 496 |
| 497 // Prefix will hold the first part of the string that contains no private |
| 498 // information. If null, no part of the string contains private information. |
| 499 var prefix = null; |
| 500 for (var i = 0; i < patterns.length; i++) { |
| 501 var match = patterns[i].exec(line); |
| 502 if (match != null) { |
| 503 prefix = match[0]; |
| 504 break; |
| 505 } |
| 506 } |
| 507 |
| 508 // Look for authentication information from data received from the server in |
| 509 // multi-round Negotiate authentication. |
| 510 if (prefix === null) { |
| 511 var challengePatterns = [ |
| 512 /^www-authenticate: (\S*)\s*/i, |
| 513 /^proxy-authenticate: (\S*)\s*/i]; |
| 514 for (var i = 0; i < challengePatterns.length; i++) { |
| 515 var match = challengePatterns[i].exec(line); |
| 516 if (!match) |
| 517 continue; |
| 518 |
| 519 // If there's no data after the scheme name, do nothing. |
| 520 if (match[0].length == line.length) |
| 521 break; |
| 522 |
| 523 // Ignore lines with commas, as they may contain lists of schemes, and |
| 524 // the information we want to hide is Base64 encoded, so has no commas. |
| 525 if (line.indexOf(',') >= 0) |
| 526 break; |
| 527 |
| 528 // Ignore Basic and Digest authentication challenges, as they contain |
| 529 // public information. |
| 530 if (/^basic$/i.test(match[1]) || /^digest$/i.test(match[1])) |
| 531 break; |
| 532 |
| 533 prefix = match[0]; |
| 534 break; |
| 535 } |
| 536 } |
| 537 |
| 538 if (prefix) { |
| 539 var suffix = line.slice(prefix.length); |
| 540 // If private information has already been removed, keep the line as-is. |
| 541 // This is often the case when viewing a loaded log. |
| 542 if (suffix.search(/^\[[0-9]+ bytes were stripped\]$/) == -1) { |
| 543 return prefix + '[' + suffix.length + ' bytes were stripped]'; |
| 544 } |
| 545 } |
| 546 |
| 547 return line; |
| 548 } |
| 549 |
| 550 /** |
| 551 * Remove debug data from HTTP/2 GOAWAY frame due to privacy considerations, see |
| 552 * https://httpwg.github.io/specs/rfc7540.html#GOAWAY. |
| 553 * |
| 554 * Note: this logic should be kept in sync with |
| 555 * net::ElideGoAwayDebugDataForNetLog in net/http/http_log_util.cc. |
| 556 */ |
| 557 function stripGoAwayDebugData(value) { |
| 558 return '[' + value.length + ' bytes were stripped]'; |
| 559 } |
| 560 |
| 561 /** |
| 562 * If |entry| has headers, returns a copy of |entry| with all cookie and |
| 563 * unencrypted login text removed. Otherwise, returns original |entry| object. |
| 564 * This is needed so that JSON log dumps can be made without affecting the |
| 565 * source data. Converts headers stored in objects to arrays. |
| 566 */ |
| 567 stripPrivacyInfo = function(entry) { |
| 568 if (!entry.params) { |
| 569 return entry; |
| 570 } |
| 571 |
| 572 if (entry.type == EventType.HTTP2_SESSION_GOAWAY && |
| 573 entry.params.debug_data != undefined) { |
| 574 // Duplicate the top level object, and |entry.params|. All other fields are |
| 575 // just pointers to the original values, as they won't be modified, other |
| 576 // than |entry.params.debug_data|. |
| 577 entry = shallowCloneObject(entry); |
| 578 entry.params = shallowCloneObject(entry.params); |
| 579 entry.params.debug_data = |
| 580 stripGoAwayDebugData(entry.params.debug_data); |
| 581 return entry; |
| 582 } |
| 583 |
| 584 if (entry.params.headers === undefined || |
| 585 !(entry.params.headers instanceof Object)) { |
| 586 return entry; |
| 587 } |
| 588 |
| 589 // Make sure entry's headers are in an array. |
| 590 entry = reformatHeaders(entry); |
| 591 |
| 592 // Duplicate the top level object, and |entry.params|. All other fields are |
| 593 // just pointers to the original values, as they won't be modified, other than |
| 594 // |entry.params.headers|. |
| 595 entry = shallowCloneObject(entry); |
| 596 entry.params = shallowCloneObject(entry.params); |
| 597 |
| 598 entry.params.headers = entry.params.headers.map(stripCookieOrLoginInfo); |
| 599 return entry; |
| 600 }; |
| 601 |
| 602 /** |
| 603 * Outputs the request header parameters of |entry| to |out|. |
| 604 */ |
| 605 function writeParamsForRequestHeaders(entry, out, consumedParams) { |
| 606 var params = entry.params; |
| 607 |
| 608 if (!(typeof params.line == 'string') || !(params.headers instanceof Array)) { |
| 609 // Unrecognized params. |
| 610 return; |
| 611 } |
| 612 |
| 613 // Strip the trailing CRLF that params.line contains. |
| 614 var lineWithoutCRLF = params.line.replace(/\r\n$/g, ''); |
| 615 out.writeArrowIndentedLines([lineWithoutCRLF].concat(params.headers)); |
| 616 |
| 617 consumedParams.line = true; |
| 618 consumedParams.headers = true; |
| 619 } |
| 620 |
| 621 function writeCertificateParam( |
| 622 certs_container, out, consumedParams, paramName) { |
| 623 if (certs_container.certificates instanceof Array) { |
| 624 var certs = certs_container.certificates.reduce( |
| 625 function(previous, current) { |
| 626 return previous.concat(current.split('\n')); |
| 627 }, new Array()); |
| 628 out.writeArrowKey(paramName); |
| 629 out.writeSpaceIndentedLines(8, certs); |
| 630 consumedParams[paramName] = true; |
| 631 } |
| 632 } |
| 633 |
| 634 /** |
| 635 * Outputs the certificate parameters of |entry| to |out|. |
| 636 */ |
| 637 function writeParamsForCertificates(entry, out, consumedParams) { |
| 638 writeCertificateParam(entry.params, out, consumedParams, 'certificates'); |
| 639 |
| 640 if (typeof(entry.params.verified_cert) == 'object') |
| 641 writeCertificateParam( |
| 642 entry.params.verified_cert, out, consumedParams, 'verified_cert'); |
| 643 |
| 644 if (typeof(entry.params.cert_status) == 'number') { |
| 645 var valueStr = entry.params.cert_status + ' (' + |
| 646 getCertStatusFlagSymbolicString(entry.params.cert_status) + ')'; |
| 647 out.writeArrowKeyValue('cert_status', valueStr); |
| 648 consumedParams.cert_status = true; |
| 649 } |
| 650 |
| 651 } |
| 652 |
| 653 function writeParamsForCheckedEVCertificates(entry, out, consumedParams) { |
| 654 if (typeof(entry.params.certificate) == 'object') |
| 655 writeCertificateParam( |
| 656 entry.params.certificate, out, consumedParams, 'certificate'); |
| 657 } |
| 658 |
| 659 /** |
| 660 * Outputs the SSL version fallback parameters of |entry| to |out|. |
| 661 */ |
| 662 function writeParamsForSSLVersionFallback(entry, out, consumedParams) { |
| 663 var params = entry.params; |
| 664 |
| 665 if (typeof params.version_before != 'number' || |
| 666 typeof params.version_after != 'number') { |
| 667 // Unrecognized params. |
| 668 return; |
| 669 } |
| 670 |
| 671 var line = SSLVersionNumberToName(params.version_before) + |
| 672 ' ==> ' + |
| 673 SSLVersionNumberToName(params.version_after); |
| 674 out.writeArrowIndentedLines([line]); |
| 675 |
| 676 consumedParams.version_before = true; |
| 677 consumedParams.version_after = true; |
| 678 } |
| 679 |
| 680 function writeParamsForProxyConfigChanged(entry, out, consumedParams) { |
| 681 var params = entry.params; |
| 682 |
| 683 if (typeof params.new_config != 'object') { |
| 684 // Unrecognized params. |
| 685 return; |
| 686 } |
| 687 |
| 688 if (typeof params.old_config == 'object') { |
| 689 var oldConfigString = proxySettingsToString(params.old_config); |
| 690 // The previous configuration may not be present in the case of |
| 691 // the initial proxy settings fetch. |
| 692 out.writeArrowKey('old_config'); |
| 693 |
| 694 out.writeSpaceIndentedLines(8, oldConfigString.split('\n')); |
| 695 |
| 696 consumedParams.old_config = true; |
| 697 } |
| 698 |
| 699 var newConfigString = proxySettingsToString(params.new_config); |
| 700 out.writeArrowKey('new_config'); |
| 701 out.writeSpaceIndentedLines(8, newConfigString.split('\n')); |
| 702 |
| 703 consumedParams.new_config = true; |
| 704 } |
| 705 |
| 706 function getTextForEvent(entry) { |
| 707 var text = ''; |
| 708 |
| 709 if (entry.isBegin() && canCollapseBeginWithEnd(entry)) { |
| 710 // Don't prefix with '+' if we are going to collapse the END event. |
| 711 text = ' '; |
| 712 } else if (entry.isBegin()) { |
| 713 text = '+' + text; |
| 714 } else if (entry.isEnd()) { |
| 715 text = '-' + text; |
| 716 } else { |
| 717 text = ' '; |
| 718 } |
| 719 |
| 720 text += EventTypeNames[entry.orig.type]; |
| 721 return text; |
| 722 } |
| 723 |
| 724 proxySettingsToString = function(config) { |
| 725 if (!config) |
| 726 return ''; |
| 727 |
| 728 // TODO(eroman): if |config| has unexpected properties, print it as JSON |
| 729 // rather than hide them. |
| 730 |
| 731 function getProxyListString(proxies) { |
| 732 // Older versions of Chrome would set these values as strings, whereas newer |
| 733 // logs use arrays. |
| 734 // TODO(eroman): This behavior changed in M27. Support for older logs can |
| 735 // safely be removed circa M29. |
| 736 if (Array.isArray(proxies)) { |
| 737 var listString = proxies.join(', '); |
| 738 if (proxies.length > 1) |
| 739 return '[' + listString + ']'; |
| 740 return listString; |
| 741 } |
| 742 return proxies; |
| 743 } |
| 744 |
| 745 // The proxy settings specify up to three major fallback choices |
| 746 // (auto-detect, custom pac url, or manual settings). |
| 747 // We enumerate these to a list so we can later number them. |
| 748 var modes = []; |
| 749 |
| 750 // Output any automatic settings. |
| 751 if (config.auto_detect) |
| 752 modes.push(['Auto-detect']); |
| 753 if (config.pac_url) |
| 754 modes.push(['PAC script: ' + config.pac_url]); |
| 755 |
| 756 // Output any manual settings. |
| 757 if (config.single_proxy || config.proxy_per_scheme) { |
| 758 var lines = []; |
| 759 |
| 760 if (config.single_proxy) { |
| 761 lines.push('Proxy server: ' + getProxyListString(config.single_proxy)); |
| 762 } else if (config.proxy_per_scheme) { |
| 763 for (var urlScheme in config.proxy_per_scheme) { |
| 764 if (urlScheme != 'fallback') { |
| 765 lines.push('Proxy server for ' + urlScheme.toUpperCase() + ': ' + |
| 766 getProxyListString(config.proxy_per_scheme[urlScheme])); |
| 767 } |
| 768 } |
| 769 if (config.proxy_per_scheme.fallback) { |
| 770 lines.push('Proxy server for everything else: ' + |
| 771 getProxyListString(config.proxy_per_scheme.fallback)); |
| 772 } |
| 773 } |
| 774 |
| 775 // Output any proxy bypass rules. |
| 776 if (config.bypass_list) { |
| 777 if (config.reverse_bypass) { |
| 778 lines.push('Reversed bypass list: '); |
| 779 } else { |
| 780 lines.push('Bypass list: '); |
| 781 } |
| 782 |
| 783 for (var i = 0; i < config.bypass_list.length; ++i) |
| 784 lines.push(' ' + config.bypass_list[i]); |
| 785 } |
| 786 |
| 787 modes.push(lines); |
| 788 } |
| 789 |
| 790 var result = []; |
| 791 if (modes.length < 1) { |
| 792 // If we didn't find any proxy settings modes, we are using DIRECT. |
| 793 result.push('Use DIRECT connections.'); |
| 794 } else if (modes.length == 1) { |
| 795 // If there was just one mode, don't bother numbering it. |
| 796 result.push(modes[0].join('\n')); |
| 797 } else { |
| 798 // Otherwise concatenate all of the modes into a numbered list |
| 799 // (which correspond with the fallback order). |
| 800 for (var i = 0; i < modes.length; ++i) |
| 801 result.push(indentLines('(' + (i + 1) + ') ', modes[i])); |
| 802 } |
| 803 |
| 804 if (config.source != undefined && config.source != 'UNKNOWN') |
| 805 result.push('Source: ' + config.source); |
| 806 |
| 807 return result.join('\n'); |
| 808 }; |
| 809 |
| 810 // End of anonymous namespace. |
| 811 })(); |
| 812 |
OLD | NEW |