Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright (C) 2012 Google Inc. All rights reserved. | 2 * Copyright (C) 2012 Google Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
| 6 * met: | 6 * met: |
| 7 * | 7 * |
| 8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 42 { | 42 { |
| 43 this._request = request; | 43 this._request = request; |
| 44 } | 44 } |
| 45 | 45 |
| 46 WebInspector.HAREntry.prototype = { | 46 WebInspector.HAREntry.prototype = { |
| 47 /** | 47 /** |
| 48 * @return {Object} | 48 * @return {Object} |
| 49 */ | 49 */ |
| 50 build: function() | 50 build: function() |
| 51 { | 51 { |
| 52 var entry = { | 52 var entry = { |
| 53 startedDateTime: new Date(this._request.startTime * 1000), | 53 startedDateTime: new Date(this._request.startTime * 1000), |
| 54 time: WebInspector.HAREntry._toMilliseconds(this._request.duration), | 54 time: this._request.timing ? WebInspector.HAREntry._toMilliseconds(t his._request.duration) : 0, |
| 55 request: this._buildRequest(), | 55 request: this._buildRequest(), |
| 56 response: this._buildResponse(), | 56 response: this._buildResponse(), |
| 57 cache: { }, // Not supported yet. | 57 cache: { }, // Not supported yet. |
| 58 timings: this._buildTimings() | 58 timings: this._buildTimings() |
| 59 }; | 59 }; |
| 60 | |
| 60 if (this._request.connectionId) | 61 if (this._request.connectionId) |
| 61 entry.connection = String(this._request.connectionId); | 62 entry.connection = String(this._request.connectionId); |
| 62 var page = WebInspector.networkLog.pageLoadForRequest(this._request); | 63 var page = WebInspector.networkLog.pageLoadForRequest(this._request); |
| 63 if (page) | 64 if (page) |
| 64 entry.pageref = "page_" + page.id; | 65 entry.pageref = "page_" + page.id; |
| 65 return entry; | 66 return entry; |
| 66 }, | 67 }, |
| 67 | 68 |
| 68 /** | 69 /** |
| 69 * @return {Object} | 70 * @return {Object} |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 118 if (typeof compression === "number") | 119 if (typeof compression === "number") |
| 119 content.compression = compression; | 120 content.compression = compression; |
| 120 return content; | 121 return content; |
| 121 }, | 122 }, |
| 122 | 123 |
| 123 /** | 124 /** |
| 124 * @return {Object} | 125 * @return {Object} |
| 125 */ | 126 */ |
| 126 _buildTimings: function() | 127 _buildTimings: function() |
| 127 { | 128 { |
| 128 var waitForConnection = this._interval("connectStart", "connectEnd"); | 129 // Order of events: request_start = 0, [proxy], [dns], [connect [ssl]], [send], receive_headers_end |
| 129 var blocked = 0; | 130 // HAR 'blocked' time is time before first network activity. |
| 131 | |
| 132 var timing = this._request.timing; | |
| 133 if (!timing) | |
| 134 return {blocked: -1, dns: -1, connect: -1, send: 0, wait: 0, receive : 0, ssl: -1}; | |
| 135 | |
| 136 function firstNonNegative(values) | |
| 137 { | |
| 138 for (var i = 0; i < values.length; ++i) { | |
| 139 if (values[i] >= 0) | |
| 140 return values[i]; | |
| 141 } | |
| 142 return -1; | |
|
caseq
2013/09/18 13:49:40
nit: console.assert(false, ...) here, as the call-
eustas
2013/09/18 16:25:51
Done.
| |
| 143 } | |
| 144 | |
| 145 var blocked = firstNonNegative([timing.dnsStart, timing.connectStart, ti ming.sendStart]); | |
| 146 | |
| 147 var dns = -1; | |
| 148 if (timing.dnsStart >= 0) | |
| 149 dns = firstNonNegative([timing.connectStart, timing.sendStart]) - ti ming.dnsStart; | |
| 150 | |
| 130 var connect = -1; | 151 var connect = -1; |
| 152 if (timing.connectStart >= 0) | |
| 153 connect = timing.sendStart - timing.connectStart; | |
| 131 | 154 |
| 132 if (this._request.connectionReused) | 155 var send = timing.sendEnd - timing.sendStart; |
| 133 blocked = waitForConnection; | 156 var wait = timing.receiveHeadersEnd - timing.sendEnd; |
| 134 else | 157 var receive = WebInspector.HAREntry._toMilliseconds(this._request.durati on) - timing.receiveHeadersEnd; |
| 135 connect = waitForConnection; | |
| 136 | 158 |
| 137 return { | 159 var ssl = -1; |
| 138 blocked: blocked, | 160 if (timing.sslStart >= 0 && timing.sslEnd >= 0) |
| 139 dns: this._interval("dnsStart", "dnsEnd"), | 161 ssl = timing.sslEnd - timing.sslStart; |
| 140 connect: connect, | 162 |
| 141 send: this._interval("sendStart", "sendEnd"), | 163 return {blocked: blocked, dns: dns, connect: connect, send: send, wait: wait, receive: receive, ssl: ssl}; |
| 142 wait: this._interval("sendEnd", "receiveHeadersEnd"), | |
| 143 receive: WebInspector.HAREntry._toMilliseconds(this._request.receive Duration), | |
| 144 ssl: this._interval("sslStart", "sslEnd") | |
| 145 }; | |
| 146 }, | 164 }, |
| 147 | 165 |
| 148 /** | 166 /** |
| 149 * @return {Object} | 167 * @return {Object} |
| 150 */ | 168 */ |
| 151 _buildPostData: function() | 169 _buildPostData: function() |
| 152 { | 170 { |
| 153 var res = { | 171 var res = { |
| 154 mimeType: this._request.requestHeaderValue("Content-Type"), | 172 mimeType: this._request.requestHeaderValue("Content-Type"), |
| 155 text: this._request.requestFormData | 173 text: this._request.requestFormData |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 197 value: cookie.value(), | 215 value: cookie.value(), |
| 198 path: cookie.path(), | 216 path: cookie.path(), |
| 199 domain: cookie.domain(), | 217 domain: cookie.domain(), |
| 200 expires: cookie.expiresDate(new Date(this._request.startTime * 1000) ), | 218 expires: cookie.expiresDate(new Date(this._request.startTime * 1000) ), |
| 201 httpOnly: cookie.httpOnly(), | 219 httpOnly: cookie.httpOnly(), |
| 202 secure: cookie.secure() | 220 secure: cookie.secure() |
| 203 }; | 221 }; |
| 204 }, | 222 }, |
| 205 | 223 |
| 206 /** | 224 /** |
| 207 * @param {string} start | |
| 208 * @param {string} end | |
| 209 * @return {number} | |
| 210 */ | |
| 211 _interval: function(start, end) | |
| 212 { | |
| 213 var timing = this._request.timing; | |
| 214 if (!timing) | |
| 215 return -1; | |
| 216 var startTime = timing[start]; | |
| 217 return typeof startTime !== "number" || startTime === -1 ? -1 : Math.rou nd(timing[end] - startTime); | |
| 218 }, | |
| 219 | |
| 220 /** | |
| 221 * @return {number} | 225 * @return {number} |
| 222 */ | 226 */ |
| 223 get requestBodySize() | 227 get requestBodySize() |
| 224 { | 228 { |
| 225 return !this._request.requestFormData ? 0 : this._request.requestFormDat a.length; | 229 return !this._request.requestFormData ? 0 : this._request.requestFormDat a.length; |
| 226 }, | 230 }, |
| 227 | 231 |
| 228 /** | 232 /** |
| 229 * @return {number} | 233 * @return {number} |
| 230 */ | 234 */ |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 245 return this._request.resourceSize - this.responseBodySize; | 249 return this._request.resourceSize - this.responseBodySize; |
| 246 } | 250 } |
| 247 } | 251 } |
| 248 | 252 |
| 249 /** | 253 /** |
| 250 * @param {number} time | 254 * @param {number} time |
| 251 * @return {number} | 255 * @return {number} |
| 252 */ | 256 */ |
| 253 WebInspector.HAREntry._toMilliseconds = function(time) | 257 WebInspector.HAREntry._toMilliseconds = function(time) |
| 254 { | 258 { |
| 255 return time === -1 ? -1 : Math.round(time * 1000); | 259 return time === -1 ? -1 : time * 1000; |
| 256 } | 260 } |
| 257 | 261 |
| 258 /** | 262 /** |
| 259 * @constructor | 263 * @constructor |
| 260 * @param {Array.<WebInspector.NetworkRequest>} requests | 264 * @param {Array.<WebInspector.NetworkRequest>} requests |
| 261 */ | 265 */ |
| 262 WebInspector.HARLog = function(requests) | 266 WebInspector.HARLog = function(requests) |
| 263 { | 267 { |
| 264 this._requests = requests; | 268 this._requests = requests; |
| 265 } | 269 } |
| (...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 421 this._writeProgress.done(); | 425 this._writeProgress.done(); |
| 422 return; | 426 return; |
| 423 } | 427 } |
| 424 const chunkSize = 100000; | 428 const chunkSize = 100000; |
| 425 var text = this._text.substring(this._bytesWritten, this._bytesWritten + chunkSize); | 429 var text = this._text.substring(this._bytesWritten, this._bytesWritten + chunkSize); |
| 426 this._bytesWritten += text.length; | 430 this._bytesWritten += text.length; |
| 427 stream.write(text, this._writeNextChunk.bind(this)); | 431 stream.write(text, this._writeNextChunk.bind(this)); |
| 428 this._writeProgress.setWorked(this._bytesWritten); | 432 this._writeProgress.setWorked(this._bytesWritten); |
| 429 } | 433 } |
| 430 } | 434 } |
| OLD | NEW |