| 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 18 matching lines...) Expand all Loading... |
| 29 */ | 29 */ |
| 30 // See http://www.softwareishard.com/blog/har-12-spec/ | 30 // See http://www.softwareishard.com/blog/har-12-spec/ |
| 31 // for HAR specification. | 31 // for HAR specification. |
| 32 | 32 |
| 33 // FIXME: Some fields are not yet supported due to back-end limitations. | 33 // FIXME: Some fields are not yet supported due to back-end limitations. |
| 34 // See https://bugs.webkit.org/show_bug.cgi?id=58127 for details. | 34 // See https://bugs.webkit.org/show_bug.cgi?id=58127 for details. |
| 35 | 35 |
| 36 /** | 36 /** |
| 37 * @unrestricted | 37 * @unrestricted |
| 38 */ | 38 */ |
| 39 WebInspector.HAREntry = class { | 39 SDK.HAREntry = class { |
| 40 /** | 40 /** |
| 41 * @param {!WebInspector.NetworkRequest} request | 41 * @param {!SDK.NetworkRequest} request |
| 42 */ | 42 */ |
| 43 constructor(request) { | 43 constructor(request) { |
| 44 this._request = request; | 44 this._request = request; |
| 45 } | 45 } |
| 46 | 46 |
| 47 /** | 47 /** |
| 48 * @param {number} time | 48 * @param {number} time |
| 49 * @return {number} | 49 * @return {number} |
| 50 */ | 50 */ |
| 51 static _toMilliseconds(time) { | 51 static _toMilliseconds(time) { |
| 52 return time === -1 ? -1 : time * 1000; | 52 return time === -1 ? -1 : time * 1000; |
| 53 } | 53 } |
| 54 | 54 |
| 55 /** | 55 /** |
| 56 * @return {!Object} | 56 * @return {!Object} |
| 57 */ | 57 */ |
| 58 build() { | 58 build() { |
| 59 var ipAddress = this._request.remoteAddress(); | 59 var ipAddress = this._request.remoteAddress(); |
| 60 var portPositionInString = ipAddress.lastIndexOf(':'); | 60 var portPositionInString = ipAddress.lastIndexOf(':'); |
| 61 if (portPositionInString !== -1) | 61 if (portPositionInString !== -1) |
| 62 ipAddress = ipAddress.substr(0, portPositionInString); | 62 ipAddress = ipAddress.substr(0, portPositionInString); |
| 63 | 63 |
| 64 var entry = { | 64 var entry = { |
| 65 startedDateTime: WebInspector.HARLog.pseudoWallTime(this._request, this._r
equest.startTime), | 65 startedDateTime: SDK.HARLog.pseudoWallTime(this._request, this._request.st
artTime), |
| 66 time: this._request.timing ? WebInspector.HAREntry._toMilliseconds(this._r
equest.duration) : 0, | 66 time: this._request.timing ? SDK.HAREntry._toMilliseconds(this._request.du
ration) : 0, |
| 67 request: this._buildRequest(), | 67 request: this._buildRequest(), |
| 68 response: this._buildResponse(), | 68 response: this._buildResponse(), |
| 69 cache: {}, // Not supported yet. | 69 cache: {}, // Not supported yet. |
| 70 timings: this._buildTimings(), | 70 timings: this._buildTimings(), |
| 71 serverIPAddress: ipAddress | 71 serverIPAddress: ipAddress |
| 72 }; | 72 }; |
| 73 | 73 |
| 74 if (this._request.connectionId !== '0') | 74 if (this._request.connectionId !== '0') |
| 75 entry.connection = this._request.connectionId; | 75 entry.connection = this._request.connectionId; |
| 76 var page = this._request.networkLog().pageLoadForRequest(this._request); | 76 var page = this._request.networkLog().pageLoadForRequest(this._request); |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 159 var dns = -1; | 159 var dns = -1; |
| 160 if (timing.dnsStart >= 0) | 160 if (timing.dnsStart >= 0) |
| 161 dns = firstNonNegative([timing.connectStart, timing.sendStart]) - timing.d
nsStart; | 161 dns = firstNonNegative([timing.connectStart, timing.sendStart]) - timing.d
nsStart; |
| 162 | 162 |
| 163 var connect = -1; | 163 var connect = -1; |
| 164 if (timing.connectStart >= 0) | 164 if (timing.connectStart >= 0) |
| 165 connect = timing.sendStart - timing.connectStart; | 165 connect = timing.sendStart - timing.connectStart; |
| 166 | 166 |
| 167 var send = timing.sendEnd - timing.sendStart; | 167 var send = timing.sendEnd - timing.sendStart; |
| 168 var wait = timing.receiveHeadersEnd - timing.sendEnd; | 168 var wait = timing.receiveHeadersEnd - timing.sendEnd; |
| 169 var receive = WebInspector.HAREntry._toMilliseconds(this._request.duration)
- timing.receiveHeadersEnd; | 169 var receive = SDK.HAREntry._toMilliseconds(this._request.duration) - timing.
receiveHeadersEnd; |
| 170 | 170 |
| 171 var ssl = -1; | 171 var ssl = -1; |
| 172 if (timing.sslStart >= 0 && timing.sslEnd >= 0) | 172 if (timing.sslStart >= 0 && timing.sslEnd >= 0) |
| 173 ssl = timing.sslEnd - timing.sslStart; | 173 ssl = timing.sslEnd - timing.sslStart; |
| 174 | 174 |
| 175 return {blocked: blocked, dns: dns, connect: connect, send: send, wait: wait
, receive: receive, ssl: ssl}; | 175 return {blocked: blocked, dns: dns, connect: connect, send: send, wait: wait
, receive: receive, ssl: ssl}; |
| 176 } | 176 } |
| 177 | 177 |
| 178 /** | 178 /** |
| 179 * @return {!Object} | 179 * @return {!Object} |
| (...skipping 15 matching lines...) Expand all Loading... |
| 195 | 195 |
| 196 /** | 196 /** |
| 197 * @param {string} url | 197 * @param {string} url |
| 198 * @return {string} | 198 * @return {string} |
| 199 */ | 199 */ |
| 200 _buildRequestURL(url) { | 200 _buildRequestURL(url) { |
| 201 return url.split('#', 2)[0]; | 201 return url.split('#', 2)[0]; |
| 202 } | 202 } |
| 203 | 203 |
| 204 /** | 204 /** |
| 205 * @param {!Array.<!WebInspector.Cookie>} cookies | 205 * @param {!Array.<!SDK.Cookie>} cookies |
| 206 * @return {!Array.<!Object>} | 206 * @return {!Array.<!Object>} |
| 207 */ | 207 */ |
| 208 _buildCookies(cookies) { | 208 _buildCookies(cookies) { |
| 209 return cookies.map(this._buildCookie.bind(this)); | 209 return cookies.map(this._buildCookie.bind(this)); |
| 210 } | 210 } |
| 211 | 211 |
| 212 /** | 212 /** |
| 213 * @param {!WebInspector.Cookie} cookie | 213 * @param {!SDK.Cookie} cookie |
| 214 * @return {!Object} | 214 * @return {!Object} |
| 215 */ | 215 */ |
| 216 _buildCookie(cookie) { | 216 _buildCookie(cookie) { |
| 217 var c = { | 217 var c = { |
| 218 name: cookie.name(), | 218 name: cookie.name(), |
| 219 value: cookie.value(), | 219 value: cookie.value(), |
| 220 path: cookie.path(), | 220 path: cookie.path(), |
| 221 domain: cookie.domain(), | 221 domain: cookie.domain(), |
| 222 expires: cookie.expiresDate(WebInspector.HARLog.pseudoWallTime(this._reque
st, this._request.startTime)), | 222 expires: cookie.expiresDate(SDK.HARLog.pseudoWallTime(this._request, this.
_request.startTime)), |
| 223 httpOnly: cookie.httpOnly(), | 223 httpOnly: cookie.httpOnly(), |
| 224 secure: cookie.secure() | 224 secure: cookie.secure() |
| 225 }; | 225 }; |
| 226 if (cookie.sameSite()) | 226 if (cookie.sameSite()) |
| 227 c.sameSite = cookie.sameSite(); | 227 c.sameSite = cookie.sameSite(); |
| 228 return c; | 228 return c; |
| 229 } | 229 } |
| 230 | 230 |
| 231 /** | 231 /** |
| 232 * @return {number} | 232 * @return {number} |
| (...skipping 22 matching lines...) Expand all Loading... |
| 255 if (!this._request.responseHeadersText) | 255 if (!this._request.responseHeadersText) |
| 256 return; | 256 return; |
| 257 return this._request.resourceSize - this.responseBodySize; | 257 return this._request.resourceSize - this.responseBodySize; |
| 258 } | 258 } |
| 259 }; | 259 }; |
| 260 | 260 |
| 261 | 261 |
| 262 /** | 262 /** |
| 263 * @unrestricted | 263 * @unrestricted |
| 264 */ | 264 */ |
| 265 WebInspector.HARLog = class { | 265 SDK.HARLog = class { |
| 266 /** | 266 /** |
| 267 * @param {!Array.<!WebInspector.NetworkRequest>} requests | 267 * @param {!Array.<!SDK.NetworkRequest>} requests |
| 268 */ | 268 */ |
| 269 constructor(requests) { | 269 constructor(requests) { |
| 270 this._requests = requests; | 270 this._requests = requests; |
| 271 } | 271 } |
| 272 | 272 |
| 273 /** | 273 /** |
| 274 * @param {!WebInspector.NetworkRequest} request | 274 * @param {!SDK.NetworkRequest} request |
| 275 * @param {number} monotonicTime | 275 * @param {number} monotonicTime |
| 276 * @return {!Date} | 276 * @return {!Date} |
| 277 */ | 277 */ |
| 278 static pseudoWallTime(request, monotonicTime) { | 278 static pseudoWallTime(request, monotonicTime) { |
| 279 return new Date(request.pseudoWallTime(monotonicTime) * 1000); | 279 return new Date(request.pseudoWallTime(monotonicTime) * 1000); |
| 280 } | 280 } |
| 281 | 281 |
| 282 /** | 282 /** |
| 283 * @return {!Object} | 283 * @return {!Object} |
| 284 */ | 284 */ |
| (...skipping 23 matching lines...) Expand all Loading... |
| 308 var page = request.networkLog().pageLoadForRequest(request); | 308 var page = request.networkLog().pageLoadForRequest(request); |
| 309 if (!page || seenIdentifiers[page.id]) | 309 if (!page || seenIdentifiers[page.id]) |
| 310 continue; | 310 continue; |
| 311 seenIdentifiers[page.id] = true; | 311 seenIdentifiers[page.id] = true; |
| 312 pages.push(this._convertPage(page, request)); | 312 pages.push(this._convertPage(page, request)); |
| 313 } | 313 } |
| 314 return pages; | 314 return pages; |
| 315 } | 315 } |
| 316 | 316 |
| 317 /** | 317 /** |
| 318 * @param {!WebInspector.PageLoad} page | 318 * @param {!SDK.PageLoad} page |
| 319 * @param {!WebInspector.NetworkRequest} request | 319 * @param {!SDK.NetworkRequest} request |
| 320 * @return {!Object} | 320 * @return {!Object} |
| 321 */ | 321 */ |
| 322 _convertPage(page, request) { | 322 _convertPage(page, request) { |
| 323 return { | 323 return { |
| 324 startedDateTime: WebInspector.HARLog.pseudoWallTime(request, page.startTim
e), | 324 startedDateTime: SDK.HARLog.pseudoWallTime(request, page.startTime), |
| 325 id: 'page_' + page.id, | 325 id: 'page_' + page.id, |
| 326 title: page.url, // We don't have actual page title here. URL is probably
better than nothing. | 326 title: page.url, // We don't have actual page title here. URL is probably
better than nothing. |
| 327 pageTimings: { | 327 pageTimings: { |
| 328 onContentLoad: this._pageEventTime(page, page.contentLoadTime), | 328 onContentLoad: this._pageEventTime(page, page.contentLoadTime), |
| 329 onLoad: this._pageEventTime(page, page.loadTime) | 329 onLoad: this._pageEventTime(page, page.loadTime) |
| 330 } | 330 } |
| 331 }; | 331 }; |
| 332 } | 332 } |
| 333 | 333 |
| 334 /** | 334 /** |
| 335 * @param {!WebInspector.NetworkRequest} request | 335 * @param {!SDK.NetworkRequest} request |
| 336 * @return {!Object} | 336 * @return {!Object} |
| 337 */ | 337 */ |
| 338 _convertResource(request) { | 338 _convertResource(request) { |
| 339 return (new WebInspector.HAREntry(request)).build(); | 339 return (new SDK.HAREntry(request)).build(); |
| 340 } | 340 } |
| 341 | 341 |
| 342 /** | 342 /** |
| 343 * @param {!WebInspector.PageLoad} page | 343 * @param {!SDK.PageLoad} page |
| 344 * @param {number} time | 344 * @param {number} time |
| 345 * @return {number} | 345 * @return {number} |
| 346 */ | 346 */ |
| 347 _pageEventTime(page, time) { | 347 _pageEventTime(page, time) { |
| 348 var startTime = page.startTime; | 348 var startTime = page.startTime; |
| 349 if (time === -1 || startTime === -1) | 349 if (time === -1 || startTime === -1) |
| 350 return -1; | 350 return -1; |
| 351 return WebInspector.HAREntry._toMilliseconds(time - startTime); | 351 return SDK.HAREntry._toMilliseconds(time - startTime); |
| 352 } | 352 } |
| 353 }; | 353 }; |
| OLD | NEW |