1// Copyright (c) 2016 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'use strict'; 7 8// TODO(rayraymond): This is a big hack that accounts for the 9// following problem in the NetLog viewer code: There are 10// several constants in Chromium that the web app does not have 11// initial values for until a log is loaded. Originally, 12// chrome://net-internals got values for these constants from 13// the browser when about:net-internals was first loaded. This 14// is no longer the case in this web app. However, certain test 15// files in the NetLog viewer code 16// (i.e. log_view_painter_test.html and events_view_test.html) 17// rely on these constants to be defined globally, rather than 18// them being passed around as input to the functions that need 19// them. This file defines two functions which set and unset 20// initial values for the constants that are used in the test 21// files. Comments are provided for what specific files within 22// Chromium these constants are taken from. 23 24function setNetLogConstantsForTest() { 25 // See net/log/net_log_util.cc in Chromium. 26 Constants = { 27 clientInfo: { 28 numericDate: '' 29 } 30 }; 31 32 // See net/log/net_log.h in Chromium. 33 EventPhase = { 34 PHASE_BEGIN: 0, 35 PHASE_END: 1, 36 PHASE_NONE: 2 37 }; 38 39 // See net/log/net_log_event_type_list.h in Chromium. 40 EventSourceType = { 41 NONE: 0, 42 URL_REQUEST: 1, 43 CONNECT_JOB: 2, 44 SOCKET: 3, 45 HOST_RESOLVER_IMPL_JOB: 4, 46 HTTP_STREAM_JOB: 5, 47 CERT_VERIFIER_JOB: 6 48 }; 49 50 EventSourceTypeNames = makeInverseMap(EventSourceType); 51 52 // See net/log/net_log_event_type_list.h in Chromium. 53 EventType = { 54 REQUEST_ALIVE: 0, 55 HOST_RESOLVER_IMPL_JOB: 1, 56 PROXY_CONFIG_CHANGED: 2, 57 SOCKET_ALIVE: 3, 58 TCP_CONNECT: 4, 59 TCP_CONNECT_ATTEMPT: 5, 60 SOCKET_IN_USE: 6, 61 SSL_VERSION_FALLBACK: 7, 62 SOCKET_BYTES_SENT: 8, 63 SOCKET_BYTES_RECEIVED: 9, 64 UDP_BYTES_SENT: 10, 65 URL_REQUEST_START_JOB: 11, 66 HTTP_CACHE_GET_BACKEND: 12, 67 HTTP_CACHE_OPEN_ENTRY: 13, 68 HTTP_CACHE_CREATE_ENTRY: 14, 69 HTTP_CACHE_ADD_TO_ENTRY: 15, 70 HTTP_CACHE_READ_INFO: 16, 71 HTTP_CACHE_WRITE_INFO: 17, 72 HTTP_CACHE_WRITE_DATA: 18, 73 ENTRY_READ_DATA: 19, 74 ENTRY_WRITE_DATA: 20, 75 HTTP_STREAM_REQUEST: 21, 76 HTTP_STREAM_REQUEST_BOUND_TO_JOB: 22, 77 HTTP_TRANSACTION_SEND_REQUEST: 23, 78 HTTP_TRANSACTION_SEND_REQUEST_HEADERS: 24, 79 HTTP_TRANSACTION_HTTP2_SEND_REQUEST_HEADERS: 25, 80 HTTP_TRANSACTION_READ_HEADERS: 26, 81 HTTP_TRANSACTION_READ_RESPONSE_HEADERS: 27, 82 HTTP_TRANSACTION_READ_BODY: 28, 83 HTTP2_SESSION_SEND_HEADERS: 29, 84 HTTP2_SESSION_RECV_HEADERS: 30, 85 HTTP2_SESSION_GOAWAY: 31, 86 QUIC_SESSION: 32, 87 QUIC_SESSION_RST_STREAM_FRAME_RECEIVED: 33, 88 QUIC_SESSION_CONNECTION_CLOSE_FRAME_RECEIVED: 34, 89 QUIC_SESSION_CRYPTO_HANDSHAKE_MESSAGE_SENT: 35, 90 HTTP_STREAM_PARSER_READ_HEADERS: 36, 91 CERT_VERIFIER_JOB: 37 92 }; 93 94 EventTypeNames = makeInverseMap(EventType); 95 96 // These flags provide metadata about the type of the load request. 97 // See net/base/load_flags.h in Chromium. 98 LoadFlag = { 99 NORMAL: 0, 100 MAIN_FRAME: 1 << 12, 101 MAYBE_USER_GESTURE: 1 << 15, 102 VERIFY_EV_CERT: 1 << 8 103 }; 104 105 // These states correspond to the lengthy periods of time that a 106 // resource load may be blocked and unable to make progress. 107 // See net/base/load_states.h in Chromium. 108 LoadState = { 109 READING_RESPONSE: 15 110 }; 111 112 // Bitmask of status flags of a certificate, representing any 113 // errors, as well as other non-error status information such 114 // as whether the certificate is EV. 115 // See net/cert/cert_status_flags.h in Chromium. 116 CertStatusFlag = { 117 AUTHORITY_INVALID: 1 << 2, 118 COMMON_NAME_INVALID: 1 << 0 119 }; 120 121 // See net/quic/core/quic_protocol.h in Chromium. 122 QuicRstStreamError = { 123 QUIC_BAD_APPLICATION_PAYLOAD: 0 124 }; 125 126 // See net/quic/core/quic_protocol.h in Chromium. 127 QuicError = { 128 QUIC_NETWORK_IDLE_TIMEOUT: 25 129 }; 130 131 // Error domain of the net module's error codes. 132 // See net/base/net_errors.h in Chromium. 133 NetError = { 134 ERR_FAILED: -2, 135 ERR_NAME_NOT_RESOLVED: -105, 136 ERR_SSL_PROTOCOL_ERROR: -107 137 }; 138} 139 140function unsetNetLogConstantsForTest() { 141 Constants = null; 142 143 EventType = null; 144 EventTypeNames = null; 145 EventPhase = null; 146 EventSourceType = null; 147 EventSourceTypeNames = null; 148 NetError = null; 149 QuicError = null; 150 QuicRstStreamError = null; 151 LoadFlag = null; 152 CertStatusFlag = null; 153 LoadState = null; 154} 155 156