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 |
11 * copyright notice, this list of conditions and the following disclaimer | 11 * copyright notice, this list of conditions and the following disclaimer |
12 * in the documentation and/or other materials provided with the | 12 * in the documentation and/or other materials provided with the |
13 * distribution. | 13 * distribution. |
14 * * Neither the name of Google Inc. nor the names of its | 14 * * Neither the name of Google Inc. nor the names of its |
15 * contributors may be used to endorse or promote products derived from | 15 * contributors may be used to endorse or promote products derived from |
16 * this software without specific prior written permission. | 16 * this software without specific prior written permission. |
17 * | 17 * |
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | 18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | 19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | 20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | 21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | 22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | 23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
29 */ | 29 */ |
30 | |
31 /** | 30 /** |
32 * @constructor | |
33 * @extends {WebInspector.SDKObject} | |
34 * @implements {WebInspector.ContentProvider} | 31 * @implements {WebInspector.ContentProvider} |
35 * @param {!NetworkAgent.RequestId} requestId | 32 * @unrestricted |
36 * @param {!WebInspector.Target} target | |
37 * @param {string} url | |
38 * @param {string} documentURL | |
39 * @param {!PageAgent.FrameId} frameId | |
40 * @param {!NetworkAgent.LoaderId} loaderId | |
41 * @param {?NetworkAgent.Initiator} initiator | |
42 */ | 33 */ |
43 WebInspector.NetworkRequest = function(target, requestId, url, documentURL, fram
eId, loaderId, initiator) | 34 WebInspector.NetworkRequest = class extends WebInspector.SDKObject { |
44 { | 35 /** |
45 WebInspector.SDKObject.call(this, target); | 36 * @param {!NetworkAgent.RequestId} requestId |
| 37 * @param {!WebInspector.Target} target |
| 38 * @param {string} url |
| 39 * @param {string} documentURL |
| 40 * @param {!PageAgent.FrameId} frameId |
| 41 * @param {!NetworkAgent.LoaderId} loaderId |
| 42 * @param {?NetworkAgent.Initiator} initiator |
| 43 */ |
| 44 constructor(target, requestId, url, documentURL, frameId, loaderId, initiator)
{ |
| 45 super(target); |
46 | 46 |
47 this._networkLog = /** @type {!WebInspector.NetworkLog} */ (WebInspector.Net
workLog.fromTarget(target)); | 47 this._networkLog = /** @type {!WebInspector.NetworkLog} */ (WebInspector.Net
workLog.fromTarget(target)); |
48 this._networkManager = /** @type {!WebInspector.NetworkManager} */ (WebInspe
ctor.NetworkManager.fromTarget(target)); | 48 this._networkManager = /** @type {!WebInspector.NetworkManager} */ (WebInspe
ctor.NetworkManager.fromTarget(target)); |
49 this._requestId = requestId; | 49 this._requestId = requestId; |
50 this.url = url; | 50 this.url = url; |
51 this._documentURL = documentURL; | 51 this._documentURL = documentURL; |
52 this._frameId = frameId; | 52 this._frameId = frameId; |
53 this._loaderId = loaderId; | 53 this._loaderId = loaderId; |
54 /** @type {?NetworkAgent.Initiator} */ | 54 /** @type {?NetworkAgent.Initiator} */ |
55 this._initiator = initiator; | 55 this._initiator = initiator; |
56 this._issueTime = -1; | 56 this._issueTime = -1; |
57 this._startTime = -1; | 57 this._startTime = -1; |
58 this._endTime = -1; | 58 this._endTime = -1; |
59 /** @type {!NetworkAgent.BlockedReason|undefined} */ | 59 /** @type {!NetworkAgent.BlockedReason|undefined} */ |
60 this._blockedReason = undefined; | 60 this._blockedReason = undefined; |
61 | 61 |
62 this.statusCode = 0; | 62 this.statusCode = 0; |
63 this.statusText = ""; | 63 this.statusText = ''; |
64 this.requestMethod = ""; | 64 this.requestMethod = ''; |
65 this.requestTime = 0; | 65 this.requestTime = 0; |
66 this.protocol = ""; | 66 this.protocol = ''; |
67 /** @type {!NetworkAgent.RequestMixedContentType} */ | 67 /** @type {!NetworkAgent.RequestMixedContentType} */ |
68 this.mixedContentType = NetworkAgent.RequestMixedContentType.None; | 68 this.mixedContentType = NetworkAgent.RequestMixedContentType.None; |
69 | 69 |
70 /** @type {?NetworkAgent.ResourcePriority} */ | 70 /** @type {?NetworkAgent.ResourcePriority} */ |
71 this._initialPriority = null; | 71 this._initialPriority = null; |
72 /** @type {?NetworkAgent.ResourcePriority} */ | 72 /** @type {?NetworkAgent.ResourcePriority} */ |
73 this._currentPriority = null; | 73 this._currentPriority = null; |
74 | 74 |
75 /** @type {!WebInspector.ResourceType} */ | 75 /** @type {!WebInspector.ResourceType} */ |
76 this._resourceType = WebInspector.resourceTypes.Other; | 76 this._resourceType = WebInspector.resourceTypes.Other; |
77 this._contentEncoded = false; | 77 this._contentEncoded = false; |
78 this._pendingContentCallbacks = []; | 78 this._pendingContentCallbacks = []; |
79 /** @type {!Array.<!WebInspector.NetworkRequest.WebSocketFrame>} */ | 79 /** @type {!Array.<!WebInspector.NetworkRequest.WebSocketFrame>} */ |
80 this._frames = []; | 80 this._frames = []; |
81 /** @type {!Array.<!WebInspector.NetworkRequest.EventSourceMessage>} */ | 81 /** @type {!Array.<!WebInspector.NetworkRequest.EventSourceMessage>} */ |
82 this._eventSourceMessages = []; | 82 this._eventSourceMessages = []; |
83 | 83 |
84 this._responseHeaderValues = {}; | 84 this._responseHeaderValues = {}; |
85 | 85 |
86 this._remoteAddress = ""; | 86 this._remoteAddress = ''; |
87 | 87 |
88 /** @type {!SecurityAgent.SecurityState} */ | 88 /** @type {!SecurityAgent.SecurityState} */ |
89 this._securityState = SecurityAgent.SecurityState.Unknown; | 89 this._securityState = SecurityAgent.SecurityState.Unknown; |
90 /** @type {?NetworkAgent.SecurityDetails} */ | 90 /** @type {?NetworkAgent.SecurityDetails} */ |
91 this._securityDetails = null; | 91 this._securityDetails = null; |
92 | 92 |
93 /** @type {string} */ | 93 /** @type {string} */ |
94 this.connectionId = "0"; | 94 this.connectionId = '0'; |
| 95 } |
| 96 |
| 97 /** |
| 98 * @param {!WebInspector.NetworkRequest} other |
| 99 * @return {number} |
| 100 */ |
| 101 indentityCompare(other) { |
| 102 if (this._requestId > other._requestId) |
| 103 return 1; |
| 104 if (this._requestId < other._requestId) |
| 105 return -1; |
| 106 return 0; |
| 107 } |
| 108 |
| 109 /** |
| 110 * @return {!NetworkAgent.RequestId} |
| 111 */ |
| 112 get requestId() { |
| 113 return this._requestId; |
| 114 } |
| 115 |
| 116 /** |
| 117 * @param {!NetworkAgent.RequestId} requestId |
| 118 */ |
| 119 set requestId(requestId) { |
| 120 this._requestId = requestId; |
| 121 } |
| 122 |
| 123 /** |
| 124 * @return {string} |
| 125 */ |
| 126 get url() { |
| 127 return this._url; |
| 128 } |
| 129 |
| 130 /** |
| 131 * @param {string} x |
| 132 */ |
| 133 set url(x) { |
| 134 if (this._url === x) |
| 135 return; |
| 136 |
| 137 this._url = x; |
| 138 this._parsedURL = new WebInspector.ParsedURL(x); |
| 139 delete this._queryString; |
| 140 delete this._parsedQueryParameters; |
| 141 delete this._name; |
| 142 delete this._path; |
| 143 } |
| 144 |
| 145 /** |
| 146 * @return {string} |
| 147 */ |
| 148 get documentURL() { |
| 149 return this._documentURL; |
| 150 } |
| 151 |
| 152 get parsedURL() { |
| 153 return this._parsedURL; |
| 154 } |
| 155 |
| 156 /** |
| 157 * @return {!PageAgent.FrameId} |
| 158 */ |
| 159 get frameId() { |
| 160 return this._frameId; |
| 161 } |
| 162 |
| 163 /** |
| 164 * @return {!NetworkAgent.LoaderId} |
| 165 */ |
| 166 get loaderId() { |
| 167 return this._loaderId; |
| 168 } |
| 169 |
| 170 /** |
| 171 * @param {string} ip |
| 172 * @param {number} port |
| 173 */ |
| 174 setRemoteAddress(ip, port) { |
| 175 this._remoteAddress = ip + ':' + port; |
| 176 this.dispatchEventToListeners(WebInspector.NetworkRequest.Events.RemoteAddre
ssChanged, this); |
| 177 } |
| 178 |
| 179 /** |
| 180 * @return {string} |
| 181 */ |
| 182 remoteAddress() { |
| 183 return this._remoteAddress; |
| 184 } |
| 185 |
| 186 /** |
| 187 * @return {!SecurityAgent.SecurityState} |
| 188 */ |
| 189 securityState() { |
| 190 return this._securityState; |
| 191 } |
| 192 |
| 193 /** |
| 194 * @param {!SecurityAgent.SecurityState} securityState |
| 195 */ |
| 196 setSecurityState(securityState) { |
| 197 this._securityState = securityState; |
| 198 } |
| 199 |
| 200 /** |
| 201 * @return {?NetworkAgent.SecurityDetails} |
| 202 */ |
| 203 securityDetails() { |
| 204 return this._securityDetails; |
| 205 } |
| 206 |
| 207 /** |
| 208 * @param {!NetworkAgent.SecurityDetails} securityDetails |
| 209 */ |
| 210 setSecurityDetails(securityDetails) { |
| 211 this._securityDetails = securityDetails; |
| 212 } |
| 213 |
| 214 /** |
| 215 * @return {number} |
| 216 */ |
| 217 get startTime() { |
| 218 return this._startTime || -1; |
| 219 } |
| 220 |
| 221 /** |
| 222 * @param {number} monotonicTime |
| 223 * @param {number} wallTime |
| 224 */ |
| 225 setIssueTime(monotonicTime, wallTime) { |
| 226 this._issueTime = monotonicTime; |
| 227 this._wallIssueTime = wallTime; |
| 228 this._startTime = monotonicTime; |
| 229 } |
| 230 |
| 231 /** |
| 232 * @return {number} |
| 233 */ |
| 234 issueTime() { |
| 235 return this._issueTime; |
| 236 } |
| 237 |
| 238 /** |
| 239 * @param {number} monotonicTime |
| 240 * @return {number} |
| 241 */ |
| 242 pseudoWallTime(monotonicTime) { |
| 243 return this._wallIssueTime ? this._wallIssueTime - this._issueTime + monoton
icTime : monotonicTime; |
| 244 } |
| 245 |
| 246 /** |
| 247 * @return {number} |
| 248 */ |
| 249 get responseReceivedTime() { |
| 250 return this._responseReceivedTime || -1; |
| 251 } |
| 252 |
| 253 /** |
| 254 * @param {number} x |
| 255 */ |
| 256 set responseReceivedTime(x) { |
| 257 this._responseReceivedTime = x; |
| 258 } |
| 259 |
| 260 /** |
| 261 * @return {number} |
| 262 */ |
| 263 get endTime() { |
| 264 return this._endTime || -1; |
| 265 } |
| 266 |
| 267 /** |
| 268 * @param {number} x |
| 269 */ |
| 270 set endTime(x) { |
| 271 if (this.timing && this.timing.requestTime) { |
| 272 // Check against accurate responseReceivedTime. |
| 273 this._endTime = Math.max(x, this.responseReceivedTime); |
| 274 } else { |
| 275 // Prefer endTime since it might be from the network stack. |
| 276 this._endTime = x; |
| 277 if (this._responseReceivedTime > x) |
| 278 this._responseReceivedTime = x; |
| 279 } |
| 280 this.dispatchEventToListeners(WebInspector.NetworkRequest.Events.TimingChang
ed, this); |
| 281 } |
| 282 |
| 283 /** |
| 284 * @return {number} |
| 285 */ |
| 286 get duration() { |
| 287 if (this._endTime === -1 || this._startTime === -1) |
| 288 return -1; |
| 289 return this._endTime - this._startTime; |
| 290 } |
| 291 |
| 292 /** |
| 293 * @return {number} |
| 294 */ |
| 295 get latency() { |
| 296 if (this._responseReceivedTime === -1 || this._startTime === -1) |
| 297 return -1; |
| 298 return this._responseReceivedTime - this._startTime; |
| 299 } |
| 300 |
| 301 /** |
| 302 * @return {number} |
| 303 */ |
| 304 get resourceSize() { |
| 305 return this._resourceSize || 0; |
| 306 } |
| 307 |
| 308 /** |
| 309 * @param {number} x |
| 310 */ |
| 311 set resourceSize(x) { |
| 312 this._resourceSize = x; |
| 313 } |
| 314 |
| 315 /** |
| 316 * @return {number} |
| 317 */ |
| 318 get transferSize() { |
| 319 return this._transferSize || 0; |
| 320 } |
| 321 |
| 322 /** |
| 323 * @param {number} x |
| 324 */ |
| 325 increaseTransferSize(x) { |
| 326 this._transferSize = (this._transferSize || 0) + x; |
| 327 } |
| 328 |
| 329 /** |
| 330 * @param {number} x |
| 331 */ |
| 332 setTransferSize(x) { |
| 333 this._transferSize = x; |
| 334 } |
| 335 |
| 336 /** |
| 337 * @return {boolean} |
| 338 */ |
| 339 get finished() { |
| 340 return this._finished; |
| 341 } |
| 342 |
| 343 /** |
| 344 * @param {boolean} x |
| 345 */ |
| 346 set finished(x) { |
| 347 if (this._finished === x) |
| 348 return; |
| 349 |
| 350 this._finished = x; |
| 351 |
| 352 if (x) { |
| 353 this.dispatchEventToListeners(WebInspector.NetworkRequest.Events.FinishedL
oading, this); |
| 354 if (this._pendingContentCallbacks.length) |
| 355 this._innerRequestContent(); |
| 356 } |
| 357 } |
| 358 |
| 359 /** |
| 360 * @return {boolean} |
| 361 */ |
| 362 get failed() { |
| 363 return this._failed; |
| 364 } |
| 365 |
| 366 /** |
| 367 * @param {boolean} x |
| 368 */ |
| 369 set failed(x) { |
| 370 this._failed = x; |
| 371 } |
| 372 |
| 373 /** |
| 374 * @return {boolean} |
| 375 */ |
| 376 get canceled() { |
| 377 return this._canceled; |
| 378 } |
| 379 |
| 380 /** |
| 381 * @param {boolean} x |
| 382 */ |
| 383 set canceled(x) { |
| 384 this._canceled = x; |
| 385 } |
| 386 |
| 387 /** |
| 388 * @return {!NetworkAgent.BlockedReason|undefined} |
| 389 */ |
| 390 blockedReason() { |
| 391 return this._blockedReason; |
| 392 } |
| 393 |
| 394 /** |
| 395 * @param {!NetworkAgent.BlockedReason} reason |
| 396 */ |
| 397 setBlockedReason(reason) { |
| 398 this._blockedReason = reason; |
| 399 } |
| 400 |
| 401 /** |
| 402 * @return {boolean} |
| 403 */ |
| 404 wasBlocked() { |
| 405 return !!this._blockedReason; |
| 406 } |
| 407 |
| 408 /** |
| 409 * @return {boolean} |
| 410 */ |
| 411 cached() { |
| 412 return (!!this._fromMemoryCache || !!this._fromDiskCache) && !this._transfer
Size; |
| 413 } |
| 414 |
| 415 /** |
| 416 * @return {boolean} |
| 417 */ |
| 418 cachedInMemory() { |
| 419 return !!this._fromMemoryCache && !this._transferSize; |
| 420 } |
| 421 |
| 422 setFromMemoryCache() { |
| 423 this._fromMemoryCache = true; |
| 424 delete this._timing; |
| 425 } |
| 426 |
| 427 setFromDiskCache() { |
| 428 this._fromDiskCache = true; |
| 429 } |
| 430 |
| 431 /** |
| 432 * @return {boolean} |
| 433 */ |
| 434 get fetchedViaServiceWorker() { |
| 435 return this._fetchedViaServiceWorker; |
| 436 } |
| 437 |
| 438 /** |
| 439 * @param {boolean} x |
| 440 */ |
| 441 set fetchedViaServiceWorker(x) { |
| 442 this._fetchedViaServiceWorker = x; |
| 443 } |
| 444 |
| 445 /** |
| 446 * @return {!NetworkAgent.ResourceTiming|undefined} |
| 447 */ |
| 448 get timing() { |
| 449 return this._timing; |
| 450 } |
| 451 |
| 452 /** |
| 453 * @param {!NetworkAgent.ResourceTiming|undefined} x |
| 454 */ |
| 455 set timing(x) { |
| 456 if (x && !this._fromMemoryCache) { |
| 457 // Take startTime and responseReceivedTime from timing data for better acc
uracy. |
| 458 // Timing's requestTime is a baseline in seconds, rest of the numbers ther
e are ticks in millis. |
| 459 this._startTime = x.requestTime; |
| 460 this._responseReceivedTime = x.requestTime + x.receiveHeadersEnd / 1000.0; |
| 461 |
| 462 this._timing = x; |
| 463 this.dispatchEventToListeners(WebInspector.NetworkRequest.Events.TimingCha
nged, this); |
| 464 } |
| 465 } |
| 466 |
| 467 /** |
| 468 * @return {string} |
| 469 */ |
| 470 get mimeType() { |
| 471 return this._mimeType; |
| 472 } |
| 473 |
| 474 /** |
| 475 * @param {string} x |
| 476 */ |
| 477 set mimeType(x) { |
| 478 this._mimeType = x; |
| 479 } |
| 480 |
| 481 /** |
| 482 * @return {string} |
| 483 */ |
| 484 get displayName() { |
| 485 return this._parsedURL.displayName; |
| 486 } |
| 487 |
| 488 /** |
| 489 * @return {string} |
| 490 */ |
| 491 name() { |
| 492 if (this._name) |
| 493 return this._name; |
| 494 this._parseNameAndPathFromURL(); |
| 495 return this._name; |
| 496 } |
| 497 |
| 498 /** |
| 499 * @return {string} |
| 500 */ |
| 501 path() { |
| 502 if (this._path) |
| 503 return this._path; |
| 504 this._parseNameAndPathFromURL(); |
| 505 return this._path; |
| 506 } |
| 507 |
| 508 _parseNameAndPathFromURL() { |
| 509 if (this._parsedURL.isDataURL()) { |
| 510 this._name = this._parsedURL.dataURLDisplayName(); |
| 511 this._path = ''; |
| 512 } else if (this._parsedURL.isAboutBlank()) { |
| 513 this._name = this._parsedURL.url; |
| 514 this._path = ''; |
| 515 } else { |
| 516 this._path = this._parsedURL.host + this._parsedURL.folderPathComponents; |
| 517 |
| 518 var inspectedURL = this.target().inspectedURL().asParsedURL(); |
| 519 this._path = this._path.trimURL(inspectedURL ? inspectedURL.host : ''); |
| 520 if (this._parsedURL.lastPathComponent || this._parsedURL.queryParams) |
| 521 this._name = |
| 522 this._parsedURL.lastPathComponent + (this._parsedURL.queryParams ? '
?' + this._parsedURL.queryParams : ''); |
| 523 else if (this._parsedURL.folderPathComponents) { |
| 524 this._name = |
| 525 this._parsedURL.folderPathComponents.substring(this._parsedURL.folde
rPathComponents.lastIndexOf('/') + 1) + |
| 526 '/'; |
| 527 this._path = this._path.substring(0, this._path.lastIndexOf('/')); |
| 528 } else { |
| 529 this._name = this._parsedURL.host; |
| 530 this._path = ''; |
| 531 } |
| 532 } |
| 533 } |
| 534 |
| 535 /** |
| 536 * @return {string} |
| 537 */ |
| 538 get folder() { |
| 539 var path = this._parsedURL.path; |
| 540 var indexOfQuery = path.indexOf('?'); |
| 541 if (indexOfQuery !== -1) |
| 542 path = path.substring(0, indexOfQuery); |
| 543 var lastSlashIndex = path.lastIndexOf('/'); |
| 544 return lastSlashIndex !== -1 ? path.substring(0, lastSlashIndex) : ''; |
| 545 } |
| 546 |
| 547 /** |
| 548 * @return {!WebInspector.ResourceType} |
| 549 */ |
| 550 resourceType() { |
| 551 return this._resourceType; |
| 552 } |
| 553 |
| 554 /** |
| 555 * @param {!WebInspector.ResourceType} resourceType |
| 556 */ |
| 557 setResourceType(resourceType) { |
| 558 this._resourceType = resourceType; |
| 559 } |
| 560 |
| 561 /** |
| 562 * @return {string} |
| 563 */ |
| 564 get domain() { |
| 565 return this._parsedURL.host; |
| 566 } |
| 567 |
| 568 /** |
| 569 * @return {string} |
| 570 */ |
| 571 get scheme() { |
| 572 return this._parsedURL.scheme; |
| 573 } |
| 574 |
| 575 /** |
| 576 * @return {?WebInspector.NetworkRequest} |
| 577 */ |
| 578 get redirectSource() { |
| 579 if (this.redirects && this.redirects.length > 0) |
| 580 return this.redirects[this.redirects.length - 1]; |
| 581 return this._redirectSource; |
| 582 } |
| 583 |
| 584 /** |
| 585 * @param {?WebInspector.NetworkRequest} x |
| 586 */ |
| 587 set redirectSource(x) { |
| 588 this._redirectSource = x; |
| 589 delete this._initiatorInfo; |
| 590 } |
| 591 |
| 592 /** |
| 593 * @return {!Array.<!WebInspector.NetworkRequest.NameValue>} |
| 594 */ |
| 595 requestHeaders() { |
| 596 return this._requestHeaders || []; |
| 597 } |
| 598 |
| 599 /** |
| 600 * @param {!Array.<!WebInspector.NetworkRequest.NameValue>} headers |
| 601 */ |
| 602 setRequestHeaders(headers) { |
| 603 this._requestHeaders = headers; |
| 604 delete this._requestCookies; |
| 605 |
| 606 this.dispatchEventToListeners(WebInspector.NetworkRequest.Events.RequestHead
ersChanged); |
| 607 } |
| 608 |
| 609 /** |
| 610 * @return {string|undefined} |
| 611 */ |
| 612 requestHeadersText() { |
| 613 return this._requestHeadersText; |
| 614 } |
| 615 |
| 616 /** |
| 617 * @param {string} text |
| 618 */ |
| 619 setRequestHeadersText(text) { |
| 620 this._requestHeadersText = text; |
| 621 |
| 622 this.dispatchEventToListeners(WebInspector.NetworkRequest.Events.RequestHead
ersChanged); |
| 623 } |
| 624 |
| 625 /** |
| 626 * @param {string} headerName |
| 627 * @return {string|undefined} |
| 628 */ |
| 629 requestHeaderValue(headerName) { |
| 630 return this._headerValue(this.requestHeaders(), headerName); |
| 631 } |
| 632 |
| 633 /** |
| 634 * @return {!Array.<!WebInspector.Cookie>} |
| 635 */ |
| 636 get requestCookies() { |
| 637 if (!this._requestCookies) |
| 638 this._requestCookies = WebInspector.CookieParser.parseCookie(this.target()
, this.requestHeaderValue('Cookie')); |
| 639 return this._requestCookies; |
| 640 } |
| 641 |
| 642 /** |
| 643 * @return {string|undefined} |
| 644 */ |
| 645 get requestFormData() { |
| 646 return this._requestFormData; |
| 647 } |
| 648 |
| 649 /** |
| 650 * @param {string|undefined} x |
| 651 */ |
| 652 set requestFormData(x) { |
| 653 this._requestFormData = x; |
| 654 delete this._parsedFormParameters; |
| 655 } |
| 656 |
| 657 /** |
| 658 * @return {string} |
| 659 */ |
| 660 requestHttpVersion() { |
| 661 var headersText = this.requestHeadersText(); |
| 662 if (!headersText) |
| 663 return this.requestHeaderValue('version') || this.requestHeaderValue(':ver
sion') || 'unknown'; |
| 664 var firstLine = headersText.split(/\r\n/)[0]; |
| 665 var match = firstLine.match(/(HTTP\/\d+\.\d+)$/); |
| 666 return match ? match[1] : 'HTTP/0.9'; |
| 667 } |
| 668 |
| 669 /** |
| 670 * @return {!Array.<!WebInspector.NetworkRequest.NameValue>} |
| 671 */ |
| 672 get responseHeaders() { |
| 673 return this._responseHeaders || []; |
| 674 } |
| 675 |
| 676 /** |
| 677 * @param {!Array.<!WebInspector.NetworkRequest.NameValue>} x |
| 678 */ |
| 679 set responseHeaders(x) { |
| 680 this._responseHeaders = x; |
| 681 delete this._sortedResponseHeaders; |
| 682 delete this._serverTimings; |
| 683 delete this._responseCookies; |
| 684 this._responseHeaderValues = {}; |
| 685 |
| 686 this.dispatchEventToListeners(WebInspector.NetworkRequest.Events.ResponseHea
dersChanged); |
| 687 } |
| 688 |
| 689 /** |
| 690 * @return {string} |
| 691 */ |
| 692 get responseHeadersText() { |
| 693 return this._responseHeadersText; |
| 694 } |
| 695 |
| 696 /** |
| 697 * @param {string} x |
| 698 */ |
| 699 set responseHeadersText(x) { |
| 700 this._responseHeadersText = x; |
| 701 |
| 702 this.dispatchEventToListeners(WebInspector.NetworkRequest.Events.ResponseHea
dersChanged); |
| 703 } |
| 704 |
| 705 /** |
| 706 * @return {!Array.<!WebInspector.NetworkRequest.NameValue>} |
| 707 */ |
| 708 get sortedResponseHeaders() { |
| 709 if (this._sortedResponseHeaders !== undefined) |
| 710 return this._sortedResponseHeaders; |
| 711 |
| 712 this._sortedResponseHeaders = this.responseHeaders.slice(); |
| 713 this._sortedResponseHeaders.sort(function(a, b) { |
| 714 return a.name.toLowerCase().compareTo(b.name.toLowerCase()); |
| 715 }); |
| 716 return this._sortedResponseHeaders; |
| 717 } |
| 718 |
| 719 /** |
| 720 * @param {string} headerName |
| 721 * @return {string|undefined} |
| 722 */ |
| 723 responseHeaderValue(headerName) { |
| 724 var value = this._responseHeaderValues[headerName]; |
| 725 if (value === undefined) { |
| 726 value = this._headerValue(this.responseHeaders, headerName); |
| 727 this._responseHeaderValues[headerName] = (value !== undefined) ? value : n
ull; |
| 728 } |
| 729 return (value !== null) ? value : undefined; |
| 730 } |
| 731 |
| 732 /** |
| 733 * @return {!Array.<!WebInspector.Cookie>} |
| 734 */ |
| 735 get responseCookies() { |
| 736 if (!this._responseCookies) |
| 737 this._responseCookies = |
| 738 WebInspector.CookieParser.parseSetCookie(this.target(), this.responseH
eaderValue('Set-Cookie')); |
| 739 return this._responseCookies; |
| 740 } |
| 741 |
| 742 /** |
| 743 * @return {string|undefined} |
| 744 */ |
| 745 responseLastModified() { |
| 746 return this.responseHeaderValue('last-modified'); |
| 747 } |
| 748 |
| 749 /** |
| 750 * @return {?Array.<!WebInspector.ServerTiming>} |
| 751 */ |
| 752 get serverTimings() { |
| 753 if (typeof this._serverTimings === 'undefined') |
| 754 this._serverTimings = WebInspector.ServerTiming.parseHeaders(this.response
Headers); |
| 755 return this._serverTimings; |
| 756 } |
| 757 |
| 758 /** |
| 759 * @return {?string} |
| 760 */ |
| 761 queryString() { |
| 762 if (this._queryString !== undefined) |
| 763 return this._queryString; |
| 764 |
| 765 var queryString = null; |
| 766 var url = this.url; |
| 767 var questionMarkPosition = url.indexOf('?'); |
| 768 if (questionMarkPosition !== -1) { |
| 769 queryString = url.substring(questionMarkPosition + 1); |
| 770 var hashSignPosition = queryString.indexOf('#'); |
| 771 if (hashSignPosition !== -1) |
| 772 queryString = queryString.substring(0, hashSignPosition); |
| 773 } |
| 774 this._queryString = queryString; |
| 775 return this._queryString; |
| 776 } |
| 777 |
| 778 /** |
| 779 * @return {?Array.<!WebInspector.NetworkRequest.NameValue>} |
| 780 */ |
| 781 get queryParameters() { |
| 782 if (this._parsedQueryParameters) |
| 783 return this._parsedQueryParameters; |
| 784 var queryString = this.queryString(); |
| 785 if (!queryString) |
| 786 return null; |
| 787 this._parsedQueryParameters = this._parseParameters(queryString); |
| 788 return this._parsedQueryParameters; |
| 789 } |
| 790 |
| 791 /** |
| 792 * @return {?Array.<!WebInspector.NetworkRequest.NameValue>} |
| 793 */ |
| 794 get formParameters() { |
| 795 if (this._parsedFormParameters) |
| 796 return this._parsedFormParameters; |
| 797 if (!this.requestFormData) |
| 798 return null; |
| 799 var requestContentType = this.requestContentType(); |
| 800 if (!requestContentType || !requestContentType.match(/^application\/x-www-fo
rm-urlencoded\s*(;.*)?$/i)) |
| 801 return null; |
| 802 this._parsedFormParameters = this._parseParameters(this.requestFormData); |
| 803 return this._parsedFormParameters; |
| 804 } |
| 805 |
| 806 /** |
| 807 * @return {string} |
| 808 */ |
| 809 responseHttpVersion() { |
| 810 var headersText = this._responseHeadersText; |
| 811 if (!headersText) |
| 812 return this.responseHeaderValue('version') || this.responseHeaderValue(':v
ersion') || 'unknown'; |
| 813 var firstLine = headersText.split(/\r\n/)[0]; |
| 814 var match = firstLine.match(/^(HTTP\/\d+\.\d+)/); |
| 815 return match ? match[1] : 'HTTP/0.9'; |
| 816 } |
| 817 |
| 818 /** |
| 819 * @param {string} queryString |
| 820 * @return {!Array.<!WebInspector.NetworkRequest.NameValue>} |
| 821 */ |
| 822 _parseParameters(queryString) { |
| 823 function parseNameValue(pair) { |
| 824 var position = pair.indexOf('='); |
| 825 if (position === -1) |
| 826 return {name: pair, value: ''}; |
| 827 else |
| 828 return {name: pair.substring(0, position), value: pair.substring(positio
n + 1)}; |
| 829 } |
| 830 return queryString.split('&').map(parseNameValue); |
| 831 } |
| 832 |
| 833 /** |
| 834 * @param {!Array.<!WebInspector.NetworkRequest.NameValue>} headers |
| 835 * @param {string} headerName |
| 836 * @return {string|undefined} |
| 837 */ |
| 838 _headerValue(headers, headerName) { |
| 839 headerName = headerName.toLowerCase(); |
| 840 |
| 841 var values = []; |
| 842 for (var i = 0; i < headers.length; ++i) { |
| 843 if (headers[i].name.toLowerCase() === headerName) |
| 844 values.push(headers[i].value); |
| 845 } |
| 846 if (!values.length) |
| 847 return undefined; |
| 848 // Set-Cookie values should be separated by '\n', not comma, otherwise cooki
es could not be parsed. |
| 849 if (headerName === 'set-cookie') |
| 850 return values.join('\n'); |
| 851 return values.join(', '); |
| 852 } |
| 853 |
| 854 /** |
| 855 * @return {?string|undefined} |
| 856 */ |
| 857 get content() { |
| 858 return this._content; |
| 859 } |
| 860 |
| 861 /** |
| 862 * @return {?Protocol.Error|undefined} |
| 863 */ |
| 864 contentError() { |
| 865 return this._contentError; |
| 866 } |
| 867 |
| 868 /** |
| 869 * @return {boolean} |
| 870 */ |
| 871 get contentEncoded() { |
| 872 return this._contentEncoded; |
| 873 } |
| 874 |
| 875 /** |
| 876 * @override |
| 877 * @return {string} |
| 878 */ |
| 879 contentURL() { |
| 880 return this._url; |
| 881 } |
| 882 |
| 883 /** |
| 884 * @override |
| 885 * @return {!WebInspector.ResourceType} |
| 886 */ |
| 887 contentType() { |
| 888 return this._resourceType; |
| 889 } |
| 890 |
| 891 /** |
| 892 * @override |
| 893 * @return {!Promise<?string>} |
| 894 */ |
| 895 requestContent() { |
| 896 // We do not support content retrieval for WebSockets at the moment. |
| 897 // Since WebSockets are potentially long-living, fail requests immediately |
| 898 // to prevent caller blocking until resource is marked as finished. |
| 899 if (this._resourceType === WebInspector.resourceTypes.WebSocket) |
| 900 return Promise.resolve(/** @type {?string} */ (null)); |
| 901 if (typeof this._content !== 'undefined') |
| 902 return Promise.resolve(/** @type {?string} */ (this.content || null)); |
| 903 var callback; |
| 904 var promise = new Promise(fulfill => callback = fulfill); |
| 905 this._pendingContentCallbacks.push(callback); |
| 906 if (this.finished) |
| 907 this._innerRequestContent(); |
| 908 return promise; |
| 909 } |
| 910 |
| 911 /** |
| 912 * @override |
| 913 * @param {string} query |
| 914 * @param {boolean} caseSensitive |
| 915 * @param {boolean} isRegex |
| 916 * @param {function(!Array.<!WebInspector.ContentProvider.SearchMatch>)} callb
ack |
| 917 */ |
| 918 searchInContent(query, caseSensitive, isRegex, callback) { |
| 919 callback([]); |
| 920 } |
| 921 |
| 922 /** |
| 923 * @return {boolean} |
| 924 */ |
| 925 isHttpFamily() { |
| 926 return !!this.url.match(/^https?:/i); |
| 927 } |
| 928 |
| 929 /** |
| 930 * @return {string|undefined} |
| 931 */ |
| 932 requestContentType() { |
| 933 return this.requestHeaderValue('Content-Type'); |
| 934 } |
| 935 |
| 936 /** |
| 937 * @return {boolean} |
| 938 */ |
| 939 hasErrorStatusCode() { |
| 940 return this.statusCode >= 400; |
| 941 } |
| 942 |
| 943 /** |
| 944 * @param {!NetworkAgent.ResourcePriority} priority |
| 945 */ |
| 946 setInitialPriority(priority) { |
| 947 this._initialPriority = priority; |
| 948 } |
| 949 |
| 950 /** |
| 951 * @return {?NetworkAgent.ResourcePriority} |
| 952 */ |
| 953 initialPriority() { |
| 954 return this._initialPriority; |
| 955 } |
| 956 |
| 957 /** |
| 958 * @param {!NetworkAgent.ResourcePriority} priority |
| 959 */ |
| 960 setPriority(priority) { |
| 961 this._currentPriority = priority; |
| 962 } |
| 963 |
| 964 /** |
| 965 * @return {?NetworkAgent.ResourcePriority} |
| 966 */ |
| 967 priority() { |
| 968 return this._currentPriority || this._initialPriority || null; |
| 969 } |
| 970 |
| 971 /** |
| 972 * @param {!Element} image |
| 973 */ |
| 974 populateImageSource(image) { |
| 975 /** |
| 976 * @param {?string} content |
| 977 * @this {WebInspector.NetworkRequest} |
| 978 */ |
| 979 function onResourceContent(content) { |
| 980 var imageSrc = WebInspector.ContentProvider.contentAsDataURL(content, this
._mimeType, true); |
| 981 if (imageSrc === null) |
| 982 imageSrc = this._url; |
| 983 image.src = imageSrc; |
| 984 } |
| 985 |
| 986 this.requestContent().then(onResourceContent.bind(this)); |
| 987 } |
| 988 |
| 989 /** |
| 990 * @return {?string} |
| 991 */ |
| 992 asDataURL() { |
| 993 var content = this._content; |
| 994 var charset = null; |
| 995 if (!this._contentEncoded) { |
| 996 content = content.toBase64(); |
| 997 charset = 'utf-8'; |
| 998 } |
| 999 return WebInspector.ContentProvider.contentAsDataURL(content, this.mimeType,
true, charset); |
| 1000 } |
| 1001 |
| 1002 _innerRequestContent() { |
| 1003 if (this._contentRequested) |
| 1004 return; |
| 1005 this._contentRequested = true; |
| 1006 |
| 1007 /** |
| 1008 * @param {?Protocol.Error} error |
| 1009 * @param {string} content |
| 1010 * @param {boolean} contentEncoded |
| 1011 * @this {WebInspector.NetworkRequest} |
| 1012 */ |
| 1013 function onResourceContent(error, content, contentEncoded) { |
| 1014 this._content = error ? null : content; |
| 1015 this._contentError = error; |
| 1016 this._contentEncoded = contentEncoded; |
| 1017 var callbacks = this._pendingContentCallbacks.slice(); |
| 1018 for (var i = 0; i < callbacks.length; ++i) |
| 1019 callbacks[i](this._content); |
| 1020 this._pendingContentCallbacks.length = 0; |
| 1021 delete this._contentRequested; |
| 1022 } |
| 1023 this.target().networkAgent().getResponseBody(this._requestId, onResourceCont
ent.bind(this)); |
| 1024 } |
| 1025 |
| 1026 /** |
| 1027 * @return {?NetworkAgent.Initiator} |
| 1028 */ |
| 1029 initiator() { |
| 1030 return this._initiator; |
| 1031 } |
| 1032 |
| 1033 /** |
| 1034 * @return {!{type: !WebInspector.NetworkRequest.InitiatorType, url: string, l
ineNumber: number, columnNumber: number, scriptId: ?string}} |
| 1035 */ |
| 1036 initiatorInfo() { |
| 1037 if (this._initiatorInfo) |
| 1038 return this._initiatorInfo; |
| 1039 |
| 1040 var type = WebInspector.NetworkRequest.InitiatorType.Other; |
| 1041 var url = ''; |
| 1042 var lineNumber = -Infinity; |
| 1043 var columnNumber = -Infinity; |
| 1044 var scriptId = null; |
| 1045 var initiator = this._initiator; |
| 1046 |
| 1047 if (this.redirectSource) { |
| 1048 type = WebInspector.NetworkRequest.InitiatorType.Redirect; |
| 1049 url = this.redirectSource.url; |
| 1050 } else if (initiator) { |
| 1051 if (initiator.type === NetworkAgent.InitiatorType.Parser) { |
| 1052 type = WebInspector.NetworkRequest.InitiatorType.Parser; |
| 1053 url = initiator.url ? initiator.url : url; |
| 1054 lineNumber = initiator.lineNumber ? initiator.lineNumber : lineNumber; |
| 1055 } else if (initiator.type === NetworkAgent.InitiatorType.Script) { |
| 1056 for (var stack = initiator.stack; stack; stack = stack.parent) { |
| 1057 var topFrame = stack.callFrames.length ? stack.callFrames[0] : null; |
| 1058 if (!topFrame) |
| 1059 continue; |
| 1060 type = WebInspector.NetworkRequest.InitiatorType.Script; |
| 1061 url = topFrame.url || WebInspector.UIString('<anonymous>'); |
| 1062 lineNumber = topFrame.lineNumber; |
| 1063 columnNumber = topFrame.columnNumber; |
| 1064 scriptId = topFrame.scriptId; |
| 1065 break; |
| 1066 } |
| 1067 } |
| 1068 } |
| 1069 |
| 1070 this._initiatorInfo = |
| 1071 {type: type, url: url, lineNumber: lineNumber, columnNumber: columnNumbe
r, scriptId: scriptId}; |
| 1072 return this._initiatorInfo; |
| 1073 } |
| 1074 |
| 1075 /** |
| 1076 * @return {?WebInspector.NetworkRequest} |
| 1077 */ |
| 1078 initiatorRequest() { |
| 1079 if (this._initiatorRequest === undefined) |
| 1080 this._initiatorRequest = this._networkLog.requestForURL(this.initiatorInfo
().url); |
| 1081 return this._initiatorRequest; |
| 1082 } |
| 1083 |
| 1084 /** |
| 1085 * @return {!WebInspector.NetworkRequest.InitiatorGraph} |
| 1086 */ |
| 1087 initiatorGraph() { |
| 1088 var initiated = new Set(); |
| 1089 var requests = this._networkLog.requests(); |
| 1090 for (var request of requests) { |
| 1091 var localInitiators = request._initiatorChain(); |
| 1092 if (localInitiators.has(this)) |
| 1093 initiated.add(request); |
| 1094 } |
| 1095 return {initiators: this._initiatorChain(), initiated: initiated}; |
| 1096 } |
| 1097 |
| 1098 /** |
| 1099 * @return {!Set<!WebInspector.NetworkRequest>} |
| 1100 */ |
| 1101 _initiatorChain() { |
| 1102 if (this._initiatorChainCache) |
| 1103 return this._initiatorChainCache; |
| 1104 this._initiatorChainCache = new Set(); |
| 1105 var request = this; |
| 1106 while (request) { |
| 1107 this._initiatorChainCache.add(request); |
| 1108 request = request.initiatorRequest(); |
| 1109 } |
| 1110 return this._initiatorChainCache; |
| 1111 } |
| 1112 |
| 1113 /** |
| 1114 * @return {!Array.<!WebInspector.NetworkRequest.WebSocketFrame>} |
| 1115 */ |
| 1116 frames() { |
| 1117 return this._frames; |
| 1118 } |
| 1119 |
| 1120 /** |
| 1121 * @param {string} errorMessage |
| 1122 * @param {number} time |
| 1123 */ |
| 1124 addFrameError(errorMessage, time) { |
| 1125 this._addFrame({ |
| 1126 type: WebInspector.NetworkRequest.WebSocketFrameType.Error, |
| 1127 text: errorMessage, |
| 1128 time: this.pseudoWallTime(time), |
| 1129 opCode: -1, |
| 1130 mask: false |
| 1131 }); |
| 1132 } |
| 1133 |
| 1134 /** |
| 1135 * @param {!NetworkAgent.WebSocketFrame} response |
| 1136 * @param {number} time |
| 1137 * @param {boolean} sent |
| 1138 */ |
| 1139 addFrame(response, time, sent) { |
| 1140 var type = sent ? WebInspector.NetworkRequest.WebSocketFrameType.Send : |
| 1141 WebInspector.NetworkRequest.WebSocketFrameType.Receive; |
| 1142 this._addFrame({ |
| 1143 type: type, |
| 1144 text: response.payloadData, |
| 1145 time: this.pseudoWallTime(time), |
| 1146 opCode: response.opcode, |
| 1147 mask: response.mask |
| 1148 }); |
| 1149 } |
| 1150 |
| 1151 /** |
| 1152 * @param {!WebInspector.NetworkRequest.WebSocketFrame} frame |
| 1153 */ |
| 1154 _addFrame(frame) { |
| 1155 this._frames.push(frame); |
| 1156 this.dispatchEventToListeners(WebInspector.NetworkRequest.Events.WebsocketFr
ameAdded, frame); |
| 1157 } |
| 1158 |
| 1159 /** |
| 1160 * @return {!Array.<!WebInspector.NetworkRequest.EventSourceMessage>} |
| 1161 */ |
| 1162 eventSourceMessages() { |
| 1163 return this._eventSourceMessages; |
| 1164 } |
| 1165 |
| 1166 /** |
| 1167 * @param {number} time |
| 1168 * @param {string} eventName |
| 1169 * @param {string} eventId |
| 1170 * @param {string} data |
| 1171 */ |
| 1172 addEventSourceMessage(time, eventName, eventId, data) { |
| 1173 var message = {time: this.pseudoWallTime(time), eventName: eventName, eventI
d: eventId, data: data}; |
| 1174 this._eventSourceMessages.push(message); |
| 1175 this.dispatchEventToListeners(WebInspector.NetworkRequest.Events.EventSource
MessageAdded, message); |
| 1176 } |
| 1177 |
| 1178 replayXHR() { |
| 1179 this.target().networkAgent().replayXHR(this.requestId); |
| 1180 } |
| 1181 |
| 1182 /** |
| 1183 * @return {!WebInspector.NetworkLog} |
| 1184 */ |
| 1185 networkLog() { |
| 1186 return this._networkLog; |
| 1187 } |
| 1188 |
| 1189 /** |
| 1190 * @return {!WebInspector.NetworkManager} |
| 1191 */ |
| 1192 networkManager() { |
| 1193 return this._networkManager; |
| 1194 } |
95 }; | 1195 }; |
96 | 1196 |
97 /** @enum {symbol} */ | 1197 /** @enum {symbol} */ |
98 WebInspector.NetworkRequest.Events = { | 1198 WebInspector.NetworkRequest.Events = { |
99 FinishedLoading: Symbol("FinishedLoading"), | 1199 FinishedLoading: Symbol('FinishedLoading'), |
100 TimingChanged: Symbol("TimingChanged"), | 1200 TimingChanged: Symbol('TimingChanged'), |
101 RemoteAddressChanged: Symbol("RemoteAddressChanged"), | 1201 RemoteAddressChanged: Symbol('RemoteAddressChanged'), |
102 RequestHeadersChanged: Symbol("RequestHeadersChanged"), | 1202 RequestHeadersChanged: Symbol('RequestHeadersChanged'), |
103 ResponseHeadersChanged: Symbol("ResponseHeadersChanged"), | 1203 ResponseHeadersChanged: Symbol('ResponseHeadersChanged'), |
104 WebsocketFrameAdded: Symbol("WebsocketFrameAdded"), | 1204 WebsocketFrameAdded: Symbol('WebsocketFrameAdded'), |
105 EventSourceMessageAdded: Symbol("EventSourceMessageAdded") | 1205 EventSourceMessageAdded: Symbol('EventSourceMessageAdded') |
106 }; | 1206 }; |
107 | 1207 |
108 /** @enum {string} */ | 1208 /** @enum {string} */ |
109 WebInspector.NetworkRequest.InitiatorType = { | 1209 WebInspector.NetworkRequest.InitiatorType = { |
110 Other: "other", | 1210 Other: 'other', |
111 Parser: "parser", | 1211 Parser: 'parser', |
112 Redirect: "redirect", | 1212 Redirect: 'redirect', |
113 Script: "script" | 1213 Script: 'script' |
114 }; | 1214 }; |
115 | 1215 |
116 /** @typedef {!{name: string, value: string}} */ | 1216 /** @typedef {!{name: string, value: string}} */ |
117 WebInspector.NetworkRequest.NameValue; | 1217 WebInspector.NetworkRequest.NameValue; |
118 | 1218 |
119 /** @enum {string} */ | 1219 /** @enum {string} */ |
120 WebInspector.NetworkRequest.WebSocketFrameType = { | 1220 WebInspector.NetworkRequest.WebSocketFrameType = { |
121 Send: "send", | 1221 Send: 'send', |
122 Receive: "receive", | 1222 Receive: 'receive', |
123 Error: "error" | 1223 Error: 'error' |
124 }; | 1224 }; |
125 | 1225 |
126 /** @typedef {!{type: WebInspector.NetworkRequest.WebSocketFrameType, time: numb
er, text: string, opCode: number, mask: boolean}} */ | 1226 /** @typedef {!{type: WebInspector.NetworkRequest.WebSocketFrameType, time: numb
er, text: string, opCode: number, mask: boolean}} */ |
127 WebInspector.NetworkRequest.WebSocketFrame; | 1227 WebInspector.NetworkRequest.WebSocketFrame; |
128 | 1228 |
129 /** @typedef {!{time: number, eventName: string, eventId: string, data: string}}
*/ | 1229 /** @typedef {!{time: number, eventName: string, eventId: string, data: string}}
*/ |
130 WebInspector.NetworkRequest.EventSourceMessage; | 1230 WebInspector.NetworkRequest.EventSourceMessage; |
131 | 1231 |
132 /** @typedef {!{initiators: !Set<!WebInspector.NetworkRequest>, initiated: !Set<
!WebInspector.NetworkRequest>}} */ | 1232 /** @typedef {!{initiators: !Set<!WebInspector.NetworkRequest>, initiated: !Set<
!WebInspector.NetworkRequest>}} */ |
133 WebInspector.NetworkRequest.InitiatorGraph; | 1233 WebInspector.NetworkRequest.InitiatorGraph; |
134 | |
135 WebInspector.NetworkRequest.prototype = { | |
136 /** | |
137 * @param {!WebInspector.NetworkRequest} other | |
138 * @return {number} | |
139 */ | |
140 indentityCompare: function(other) | |
141 { | |
142 if (this._requestId > other._requestId) | |
143 return 1; | |
144 if (this._requestId < other._requestId) | |
145 return -1; | |
146 return 0; | |
147 }, | |
148 | |
149 /** | |
150 * @return {!NetworkAgent.RequestId} | |
151 */ | |
152 get requestId() | |
153 { | |
154 return this._requestId; | |
155 }, | |
156 | |
157 set requestId(requestId) | |
158 { | |
159 this._requestId = requestId; | |
160 }, | |
161 | |
162 /** | |
163 * @return {string} | |
164 */ | |
165 get url() | |
166 { | |
167 return this._url; | |
168 }, | |
169 | |
170 set url(x) | |
171 { | |
172 if (this._url === x) | |
173 return; | |
174 | |
175 this._url = x; | |
176 this._parsedURL = new WebInspector.ParsedURL(x); | |
177 delete this._queryString; | |
178 delete this._parsedQueryParameters; | |
179 delete this._name; | |
180 delete this._path; | |
181 }, | |
182 | |
183 /** | |
184 * @return {string} | |
185 */ | |
186 get documentURL() | |
187 { | |
188 return this._documentURL; | |
189 }, | |
190 | |
191 get parsedURL() | |
192 { | |
193 return this._parsedURL; | |
194 }, | |
195 | |
196 /** | |
197 * @return {!PageAgent.FrameId} | |
198 */ | |
199 get frameId() | |
200 { | |
201 return this._frameId; | |
202 }, | |
203 | |
204 /** | |
205 * @return {!NetworkAgent.LoaderId} | |
206 */ | |
207 get loaderId() | |
208 { | |
209 return this._loaderId; | |
210 }, | |
211 | |
212 /** | |
213 * @param {string} ip | |
214 * @param {number} port | |
215 */ | |
216 setRemoteAddress: function(ip, port) | |
217 { | |
218 this._remoteAddress = ip + ":" + port; | |
219 this.dispatchEventToListeners(WebInspector.NetworkRequest.Events.RemoteA
ddressChanged, this); | |
220 }, | |
221 | |
222 /** | |
223 * @return {string} | |
224 */ | |
225 remoteAddress: function() | |
226 { | |
227 return this._remoteAddress; | |
228 }, | |
229 | |
230 /** | |
231 * @return {!SecurityAgent.SecurityState} | |
232 */ | |
233 securityState: function() | |
234 { | |
235 return this._securityState; | |
236 }, | |
237 | |
238 /** | |
239 * @param {!SecurityAgent.SecurityState} securityState | |
240 */ | |
241 setSecurityState: function(securityState) | |
242 { | |
243 this._securityState = securityState; | |
244 }, | |
245 | |
246 /** | |
247 * @return {?NetworkAgent.SecurityDetails} | |
248 */ | |
249 securityDetails: function() | |
250 { | |
251 return this._securityDetails; | |
252 }, | |
253 | |
254 /** | |
255 * @param {!NetworkAgent.SecurityDetails} securityDetails | |
256 */ | |
257 setSecurityDetails: function(securityDetails) | |
258 { | |
259 this._securityDetails = securityDetails; | |
260 }, | |
261 | |
262 /** | |
263 * @return {number} | |
264 */ | |
265 get startTime() | |
266 { | |
267 return this._startTime || -1; | |
268 }, | |
269 | |
270 /** | |
271 * @param {number} monotonicTime | |
272 * @param {number} wallTime | |
273 */ | |
274 setIssueTime: function(monotonicTime, wallTime) | |
275 { | |
276 this._issueTime = monotonicTime; | |
277 this._wallIssueTime = wallTime; | |
278 this._startTime = monotonicTime; | |
279 }, | |
280 | |
281 /** | |
282 * @return {number} | |
283 */ | |
284 issueTime: function() | |
285 { | |
286 return this._issueTime; | |
287 }, | |
288 | |
289 /** | |
290 * @param {number} monotonicTime | |
291 * @return {number} | |
292 */ | |
293 pseudoWallTime: function(monotonicTime) | |
294 { | |
295 return this._wallIssueTime ? this._wallIssueTime - this._issueTime + mon
otonicTime : monotonicTime; | |
296 }, | |
297 | |
298 /** | |
299 * @return {number} | |
300 */ | |
301 get responseReceivedTime() | |
302 { | |
303 return this._responseReceivedTime || -1; | |
304 }, | |
305 | |
306 set responseReceivedTime(x) | |
307 { | |
308 this._responseReceivedTime = x; | |
309 }, | |
310 | |
311 /** | |
312 * @return {number} | |
313 */ | |
314 get endTime() | |
315 { | |
316 return this._endTime || -1; | |
317 }, | |
318 | |
319 set endTime(x) | |
320 { | |
321 if (this.timing && this.timing.requestTime) { | |
322 // Check against accurate responseReceivedTime. | |
323 this._endTime = Math.max(x, this.responseReceivedTime); | |
324 } else { | |
325 // Prefer endTime since it might be from the network stack. | |
326 this._endTime = x; | |
327 if (this._responseReceivedTime > x) | |
328 this._responseReceivedTime = x; | |
329 } | |
330 this.dispatchEventToListeners(WebInspector.NetworkRequest.Events.TimingC
hanged, this); | |
331 }, | |
332 | |
333 /** | |
334 * @return {number} | |
335 */ | |
336 get duration() | |
337 { | |
338 if (this._endTime === -1 || this._startTime === -1) | |
339 return -1; | |
340 return this._endTime - this._startTime; | |
341 }, | |
342 | |
343 /** | |
344 * @return {number} | |
345 */ | |
346 get latency() | |
347 { | |
348 if (this._responseReceivedTime === -1 || this._startTime === -1) | |
349 return -1; | |
350 return this._responseReceivedTime - this._startTime; | |
351 }, | |
352 | |
353 /** | |
354 * @return {number} | |
355 */ | |
356 get resourceSize() | |
357 { | |
358 return this._resourceSize || 0; | |
359 }, | |
360 | |
361 set resourceSize(x) | |
362 { | |
363 this._resourceSize = x; | |
364 }, | |
365 | |
366 /** | |
367 * @return {number} | |
368 */ | |
369 get transferSize() | |
370 { | |
371 return this._transferSize || 0; | |
372 }, | |
373 | |
374 /** | |
375 * @param {number} x | |
376 */ | |
377 increaseTransferSize: function(x) | |
378 { | |
379 this._transferSize = (this._transferSize || 0) + x; | |
380 }, | |
381 | |
382 /** | |
383 * @param {number} x | |
384 */ | |
385 setTransferSize: function(x) | |
386 { | |
387 this._transferSize = x; | |
388 }, | |
389 | |
390 /** | |
391 * @return {boolean} | |
392 */ | |
393 get finished() | |
394 { | |
395 return this._finished; | |
396 }, | |
397 | |
398 set finished(x) | |
399 { | |
400 if (this._finished === x) | |
401 return; | |
402 | |
403 this._finished = x; | |
404 | |
405 if (x) { | |
406 this.dispatchEventToListeners(WebInspector.NetworkRequest.Events.Fin
ishedLoading, this); | |
407 if (this._pendingContentCallbacks.length) | |
408 this._innerRequestContent(); | |
409 } | |
410 }, | |
411 | |
412 /** | |
413 * @return {boolean} | |
414 */ | |
415 get failed() | |
416 { | |
417 return this._failed; | |
418 }, | |
419 | |
420 set failed(x) | |
421 { | |
422 this._failed = x; | |
423 }, | |
424 | |
425 /** | |
426 * @return {boolean} | |
427 */ | |
428 get canceled() | |
429 { | |
430 return this._canceled; | |
431 }, | |
432 | |
433 set canceled(x) | |
434 { | |
435 this._canceled = x; | |
436 }, | |
437 | |
438 /** | |
439 * @return {!NetworkAgent.BlockedReason|undefined} | |
440 */ | |
441 blockedReason: function() | |
442 { | |
443 return this._blockedReason; | |
444 }, | |
445 | |
446 /** | |
447 * @param {!NetworkAgent.BlockedReason} reason | |
448 */ | |
449 setBlockedReason: function(reason) | |
450 { | |
451 this._blockedReason = reason; | |
452 }, | |
453 | |
454 /** | |
455 * @return {boolean} | |
456 */ | |
457 wasBlocked: function() | |
458 { | |
459 return !!this._blockedReason; | |
460 }, | |
461 | |
462 /** | |
463 * @return {boolean} | |
464 */ | |
465 cached: function() | |
466 { | |
467 return (!!this._fromMemoryCache || !!this._fromDiskCache) && !this._tran
sferSize; | |
468 }, | |
469 | |
470 /** | |
471 * @return {boolean} | |
472 */ | |
473 cachedInMemory: function() | |
474 { | |
475 return !!this._fromMemoryCache && !this._transferSize; | |
476 }, | |
477 | |
478 setFromMemoryCache: function() | |
479 { | |
480 this._fromMemoryCache = true; | |
481 delete this._timing; | |
482 }, | |
483 | |
484 setFromDiskCache: function() | |
485 { | |
486 this._fromDiskCache = true; | |
487 }, | |
488 | |
489 /** | |
490 * @return {boolean} | |
491 */ | |
492 get fetchedViaServiceWorker() | |
493 { | |
494 return this._fetchedViaServiceWorker; | |
495 }, | |
496 | |
497 set fetchedViaServiceWorker(x) | |
498 { | |
499 this._fetchedViaServiceWorker = x; | |
500 }, | |
501 | |
502 /** | |
503 * @return {!NetworkAgent.ResourceTiming|undefined} | |
504 */ | |
505 get timing() | |
506 { | |
507 return this._timing; | |
508 }, | |
509 | |
510 set timing(x) | |
511 { | |
512 if (x && !this._fromMemoryCache) { | |
513 // Take startTime and responseReceivedTime from timing data for bett
er accuracy. | |
514 // Timing's requestTime is a baseline in seconds, rest of the number
s there are ticks in millis. | |
515 this._startTime = x.requestTime; | |
516 this._responseReceivedTime = x.requestTime + x.receiveHeadersEnd / 1
000.0; | |
517 | |
518 this._timing = x; | |
519 this.dispatchEventToListeners(WebInspector.NetworkRequest.Events.Tim
ingChanged, this); | |
520 } | |
521 }, | |
522 | |
523 /** | |
524 * @return {string} | |
525 */ | |
526 get mimeType() | |
527 { | |
528 return this._mimeType; | |
529 }, | |
530 | |
531 set mimeType(x) | |
532 { | |
533 this._mimeType = x; | |
534 }, | |
535 | |
536 /** | |
537 * @return {string} | |
538 */ | |
539 get displayName() | |
540 { | |
541 return this._parsedURL.displayName; | |
542 }, | |
543 | |
544 /** | |
545 * @return {string} | |
546 */ | |
547 name: function() | |
548 { | |
549 if (this._name) | |
550 return this._name; | |
551 this._parseNameAndPathFromURL(); | |
552 return this._name; | |
553 }, | |
554 | |
555 /** | |
556 * @return {string} | |
557 */ | |
558 path: function() | |
559 { | |
560 if (this._path) | |
561 return this._path; | |
562 this._parseNameAndPathFromURL(); | |
563 return this._path; | |
564 }, | |
565 | |
566 _parseNameAndPathFromURL: function() | |
567 { | |
568 if (this._parsedURL.isDataURL()) { | |
569 this._name = this._parsedURL.dataURLDisplayName(); | |
570 this._path = ""; | |
571 } else if (this._parsedURL.isAboutBlank()) { | |
572 this._name = this._parsedURL.url; | |
573 this._path = ""; | |
574 } else { | |
575 this._path = this._parsedURL.host + this._parsedURL.folderPathCompon
ents; | |
576 | |
577 var inspectedURL = this.target().inspectedURL().asParsedURL(); | |
578 this._path = this._path.trimURL(inspectedURL ? inspectedURL.host : "
"); | |
579 if (this._parsedURL.lastPathComponent || this._parsedURL.queryParams
) | |
580 this._name = this._parsedURL.lastPathComponent + (this._parsedUR
L.queryParams ? "?" + this._parsedURL.queryParams : ""); | |
581 else if (this._parsedURL.folderPathComponents) { | |
582 this._name = this._parsedURL.folderPathComponents.substring(this
._parsedURL.folderPathComponents.lastIndexOf("/") + 1) + "/"; | |
583 this._path = this._path.substring(0, this._path.lastIndexOf("/")
); | |
584 } else { | |
585 this._name = this._parsedURL.host; | |
586 this._path = ""; | |
587 } | |
588 } | |
589 }, | |
590 | |
591 /** | |
592 * @return {string} | |
593 */ | |
594 get folder() | |
595 { | |
596 var path = this._parsedURL.path; | |
597 var indexOfQuery = path.indexOf("?"); | |
598 if (indexOfQuery !== -1) | |
599 path = path.substring(0, indexOfQuery); | |
600 var lastSlashIndex = path.lastIndexOf("/"); | |
601 return lastSlashIndex !== -1 ? path.substring(0, lastSlashIndex) : ""; | |
602 }, | |
603 | |
604 /** | |
605 * @return {!WebInspector.ResourceType} | |
606 */ | |
607 resourceType: function() | |
608 { | |
609 return this._resourceType; | |
610 }, | |
611 | |
612 /** | |
613 * @param {!WebInspector.ResourceType} resourceType | |
614 */ | |
615 setResourceType: function(resourceType) | |
616 { | |
617 this._resourceType = resourceType; | |
618 }, | |
619 | |
620 /** | |
621 * @return {string} | |
622 */ | |
623 get domain() | |
624 { | |
625 return this._parsedURL.host; | |
626 }, | |
627 | |
628 /** | |
629 * @return {string} | |
630 */ | |
631 get scheme() | |
632 { | |
633 return this._parsedURL.scheme; | |
634 }, | |
635 | |
636 /** | |
637 * @return {?WebInspector.NetworkRequest} | |
638 */ | |
639 get redirectSource() | |
640 { | |
641 if (this.redirects && this.redirects.length > 0) | |
642 return this.redirects[this.redirects.length - 1]; | |
643 return this._redirectSource; | |
644 }, | |
645 | |
646 set redirectSource(x) | |
647 { | |
648 this._redirectSource = x; | |
649 delete this._initiatorInfo; | |
650 }, | |
651 | |
652 /** | |
653 * @return {!Array.<!WebInspector.NetworkRequest.NameValue>} | |
654 */ | |
655 requestHeaders: function() | |
656 { | |
657 return this._requestHeaders || []; | |
658 }, | |
659 | |
660 /** | |
661 * @param {!Array.<!WebInspector.NetworkRequest.NameValue>} headers | |
662 */ | |
663 setRequestHeaders: function(headers) | |
664 { | |
665 this._requestHeaders = headers; | |
666 delete this._requestCookies; | |
667 | |
668 this.dispatchEventToListeners(WebInspector.NetworkRequest.Events.Request
HeadersChanged); | |
669 }, | |
670 | |
671 /** | |
672 * @return {string|undefined} | |
673 */ | |
674 requestHeadersText: function() | |
675 { | |
676 return this._requestHeadersText; | |
677 }, | |
678 | |
679 /** | |
680 * @param {string} text | |
681 */ | |
682 setRequestHeadersText: function(text) | |
683 { | |
684 this._requestHeadersText = text; | |
685 | |
686 this.dispatchEventToListeners(WebInspector.NetworkRequest.Events.Request
HeadersChanged); | |
687 }, | |
688 | |
689 /** | |
690 * @param {string} headerName | |
691 * @return {string|undefined} | |
692 */ | |
693 requestHeaderValue: function(headerName) | |
694 { | |
695 return this._headerValue(this.requestHeaders(), headerName); | |
696 }, | |
697 | |
698 /** | |
699 * @return {!Array.<!WebInspector.Cookie>} | |
700 */ | |
701 get requestCookies() | |
702 { | |
703 if (!this._requestCookies) | |
704 this._requestCookies = WebInspector.CookieParser.parseCookie(this.ta
rget(), this.requestHeaderValue("Cookie")); | |
705 return this._requestCookies; | |
706 }, | |
707 | |
708 /** | |
709 * @return {string|undefined} | |
710 */ | |
711 get requestFormData() | |
712 { | |
713 return this._requestFormData; | |
714 }, | |
715 | |
716 set requestFormData(x) | |
717 { | |
718 this._requestFormData = x; | |
719 delete this._parsedFormParameters; | |
720 }, | |
721 | |
722 /** | |
723 * @return {string} | |
724 */ | |
725 requestHttpVersion: function() | |
726 { | |
727 var headersText = this.requestHeadersText(); | |
728 if (!headersText) | |
729 return this.requestHeaderValue("version") || this.requestHeaderValue
(":version") || "unknown"; | |
730 var firstLine = headersText.split(/\r\n/)[0]; | |
731 var match = firstLine.match(/(HTTP\/\d+\.\d+)$/); | |
732 return match ? match[1] : "HTTP/0.9"; | |
733 }, | |
734 | |
735 /** | |
736 * @return {!Array.<!WebInspector.NetworkRequest.NameValue>} | |
737 */ | |
738 get responseHeaders() | |
739 { | |
740 return this._responseHeaders || []; | |
741 }, | |
742 | |
743 set responseHeaders(x) | |
744 { | |
745 this._responseHeaders = x; | |
746 delete this._sortedResponseHeaders; | |
747 delete this._serverTimings; | |
748 delete this._responseCookies; | |
749 this._responseHeaderValues = {}; | |
750 | |
751 this.dispatchEventToListeners(WebInspector.NetworkRequest.Events.Respons
eHeadersChanged); | |
752 }, | |
753 | |
754 /** | |
755 * @return {string} | |
756 */ | |
757 get responseHeadersText() | |
758 { | |
759 return this._responseHeadersText; | |
760 }, | |
761 | |
762 set responseHeadersText(x) | |
763 { | |
764 this._responseHeadersText = x; | |
765 | |
766 this.dispatchEventToListeners(WebInspector.NetworkRequest.Events.Respons
eHeadersChanged); | |
767 }, | |
768 | |
769 /** | |
770 * @return {!Array.<!WebInspector.NetworkRequest.NameValue>} | |
771 */ | |
772 get sortedResponseHeaders() | |
773 { | |
774 if (this._sortedResponseHeaders !== undefined) | |
775 return this._sortedResponseHeaders; | |
776 | |
777 this._sortedResponseHeaders = this.responseHeaders.slice(); | |
778 this._sortedResponseHeaders.sort(function(a, b) { return a.name.toLowerC
ase().compareTo(b.name.toLowerCase()); }); | |
779 return this._sortedResponseHeaders; | |
780 }, | |
781 | |
782 /** | |
783 * @param {string} headerName | |
784 * @return {string|undefined} | |
785 */ | |
786 responseHeaderValue: function(headerName) | |
787 { | |
788 var value = this._responseHeaderValues[headerName]; | |
789 if (value === undefined) { | |
790 value = this._headerValue(this.responseHeaders, headerName); | |
791 this._responseHeaderValues[headerName] = (value !== undefined) ? val
ue : null; | |
792 } | |
793 return (value !== null) ? value : undefined; | |
794 }, | |
795 | |
796 /** | |
797 * @return {!Array.<!WebInspector.Cookie>} | |
798 */ | |
799 get responseCookies() | |
800 { | |
801 if (!this._responseCookies) | |
802 this._responseCookies = WebInspector.CookieParser.parseSetCookie(thi
s.target(), this.responseHeaderValue("Set-Cookie")); | |
803 return this._responseCookies; | |
804 }, | |
805 | |
806 /** | |
807 * @return {string|undefined} | |
808 */ | |
809 responseLastModified: function() | |
810 { | |
811 return this.responseHeaderValue("last-modified"); | |
812 }, | |
813 | |
814 /** | |
815 * @return {?Array.<!WebInspector.ServerTiming>} | |
816 */ | |
817 get serverTimings() | |
818 { | |
819 if (typeof this._serverTimings === "undefined") | |
820 this._serverTimings = WebInspector.ServerTiming.parseHeaders(this.re
sponseHeaders); | |
821 return this._serverTimings; | |
822 }, | |
823 | |
824 /** | |
825 * @return {?string} | |
826 */ | |
827 queryString: function() | |
828 { | |
829 if (this._queryString !== undefined) | |
830 return this._queryString; | |
831 | |
832 var queryString = null; | |
833 var url = this.url; | |
834 var questionMarkPosition = url.indexOf("?"); | |
835 if (questionMarkPosition !== -1) { | |
836 queryString = url.substring(questionMarkPosition + 1); | |
837 var hashSignPosition = queryString.indexOf("#"); | |
838 if (hashSignPosition !== -1) | |
839 queryString = queryString.substring(0, hashSignPosition); | |
840 } | |
841 this._queryString = queryString; | |
842 return this._queryString; | |
843 }, | |
844 | |
845 /** | |
846 * @return {?Array.<!WebInspector.NetworkRequest.NameValue>} | |
847 */ | |
848 get queryParameters() | |
849 { | |
850 if (this._parsedQueryParameters) | |
851 return this._parsedQueryParameters; | |
852 var queryString = this.queryString(); | |
853 if (!queryString) | |
854 return null; | |
855 this._parsedQueryParameters = this._parseParameters(queryString); | |
856 return this._parsedQueryParameters; | |
857 }, | |
858 | |
859 /** | |
860 * @return {?Array.<!WebInspector.NetworkRequest.NameValue>} | |
861 */ | |
862 get formParameters() | |
863 { | |
864 if (this._parsedFormParameters) | |
865 return this._parsedFormParameters; | |
866 if (!this.requestFormData) | |
867 return null; | |
868 var requestContentType = this.requestContentType(); | |
869 if (!requestContentType || !requestContentType.match(/^application\/x-ww
w-form-urlencoded\s*(;.*)?$/i)) | |
870 return null; | |
871 this._parsedFormParameters = this._parseParameters(this.requestFormData)
; | |
872 return this._parsedFormParameters; | |
873 }, | |
874 | |
875 /** | |
876 * @return {string} | |
877 */ | |
878 responseHttpVersion: function() | |
879 { | |
880 var headersText = this._responseHeadersText; | |
881 if (!headersText) | |
882 return this.responseHeaderValue("version") || this.responseHeaderVal
ue(":version") || "unknown"; | |
883 var firstLine = headersText.split(/\r\n/)[0]; | |
884 var match = firstLine.match(/^(HTTP\/\d+\.\d+)/); | |
885 return match ? match[1] : "HTTP/0.9"; | |
886 }, | |
887 | |
888 /** | |
889 * @param {string} queryString | |
890 * @return {!Array.<!WebInspector.NetworkRequest.NameValue>} | |
891 */ | |
892 _parseParameters: function(queryString) | |
893 { | |
894 function parseNameValue(pair) | |
895 { | |
896 var position = pair.indexOf("="); | |
897 if (position === -1) | |
898 return {name: pair, value: ""}; | |
899 else | |
900 return {name: pair.substring(0, position), value: pair.substring
(position + 1)}; | |
901 } | |
902 return queryString.split("&").map(parseNameValue); | |
903 }, | |
904 | |
905 /** | |
906 * @param {!Array.<!WebInspector.NetworkRequest.NameValue>} headers | |
907 * @param {string} headerName | |
908 * @return {string|undefined} | |
909 */ | |
910 _headerValue: function(headers, headerName) | |
911 { | |
912 headerName = headerName.toLowerCase(); | |
913 | |
914 var values = []; | |
915 for (var i = 0; i < headers.length; ++i) { | |
916 if (headers[i].name.toLowerCase() === headerName) | |
917 values.push(headers[i].value); | |
918 } | |
919 if (!values.length) | |
920 return undefined; | |
921 // Set-Cookie values should be separated by '\n', not comma, otherwise c
ookies could not be parsed. | |
922 if (headerName === "set-cookie") | |
923 return values.join("\n"); | |
924 return values.join(", "); | |
925 }, | |
926 | |
927 /** | |
928 * @return {?string|undefined} | |
929 */ | |
930 get content() | |
931 { | |
932 return this._content; | |
933 }, | |
934 | |
935 /** | |
936 * @return {?Protocol.Error|undefined} | |
937 */ | |
938 contentError: function() | |
939 { | |
940 return this._contentError; | |
941 }, | |
942 | |
943 /** | |
944 * @return {boolean} | |
945 */ | |
946 get contentEncoded() | |
947 { | |
948 return this._contentEncoded; | |
949 }, | |
950 | |
951 /** | |
952 * @override | |
953 * @return {string} | |
954 */ | |
955 contentURL: function() | |
956 { | |
957 return this._url; | |
958 }, | |
959 | |
960 /** | |
961 * @override | |
962 * @return {!WebInspector.ResourceType} | |
963 */ | |
964 contentType: function() | |
965 { | |
966 return this._resourceType; | |
967 }, | |
968 | |
969 /** | |
970 * @override | |
971 * @return {!Promise<?string>} | |
972 */ | |
973 requestContent: function() | |
974 { | |
975 // We do not support content retrieval for WebSockets at the moment. | |
976 // Since WebSockets are potentially long-living, fail requests immediate
ly | |
977 // to prevent caller blocking until resource is marked as finished. | |
978 if (this._resourceType === WebInspector.resourceTypes.WebSocket) | |
979 return Promise.resolve(/** @type {?string} */(null)); | |
980 if (typeof this._content !== "undefined") | |
981 return Promise.resolve(/** @type {?string} */(this.content || null))
; | |
982 var callback; | |
983 var promise = new Promise(fulfill => callback = fulfill); | |
984 this._pendingContentCallbacks.push(callback); | |
985 if (this.finished) | |
986 this._innerRequestContent(); | |
987 return promise; | |
988 }, | |
989 | |
990 /** | |
991 * @override | |
992 * @param {string} query | |
993 * @param {boolean} caseSensitive | |
994 * @param {boolean} isRegex | |
995 * @param {function(!Array.<!WebInspector.ContentProvider.SearchMatch>)} cal
lback | |
996 */ | |
997 searchInContent: function(query, caseSensitive, isRegex, callback) | |
998 { | |
999 callback([]); | |
1000 }, | |
1001 | |
1002 /** | |
1003 * @return {boolean} | |
1004 */ | |
1005 isHttpFamily: function() | |
1006 { | |
1007 return !!this.url.match(/^https?:/i); | |
1008 }, | |
1009 | |
1010 /** | |
1011 * @return {string|undefined} | |
1012 */ | |
1013 requestContentType: function() | |
1014 { | |
1015 return this.requestHeaderValue("Content-Type"); | |
1016 }, | |
1017 | |
1018 /** | |
1019 * @return {boolean} | |
1020 */ | |
1021 hasErrorStatusCode: function() | |
1022 { | |
1023 return this.statusCode >= 400; | |
1024 }, | |
1025 | |
1026 /** | |
1027 * @param {!NetworkAgent.ResourcePriority} priority | |
1028 */ | |
1029 setInitialPriority: function(priority) | |
1030 { | |
1031 this._initialPriority = priority; | |
1032 }, | |
1033 | |
1034 /** | |
1035 * @return {?NetworkAgent.ResourcePriority} | |
1036 */ | |
1037 initialPriority: function() | |
1038 { | |
1039 return this._initialPriority; | |
1040 }, | |
1041 | |
1042 /** | |
1043 * @param {!NetworkAgent.ResourcePriority} priority | |
1044 */ | |
1045 setPriority: function(priority) | |
1046 { | |
1047 this._currentPriority = priority; | |
1048 }, | |
1049 | |
1050 /** | |
1051 * @return {?NetworkAgent.ResourcePriority} | |
1052 */ | |
1053 priority: function() | |
1054 { | |
1055 return this._currentPriority || this._initialPriority || null; | |
1056 }, | |
1057 | |
1058 /** | |
1059 * @param {!Element} image | |
1060 */ | |
1061 populateImageSource: function(image) | |
1062 { | |
1063 /** | |
1064 * @param {?string} content | |
1065 * @this {WebInspector.NetworkRequest} | |
1066 */ | |
1067 function onResourceContent(content) | |
1068 { | |
1069 var imageSrc = WebInspector.ContentProvider.contentAsDataURL(content
, this._mimeType, true); | |
1070 if (imageSrc === null) | |
1071 imageSrc = this._url; | |
1072 image.src = imageSrc; | |
1073 } | |
1074 | |
1075 this.requestContent().then(onResourceContent.bind(this)); | |
1076 }, | |
1077 | |
1078 /** | |
1079 * @return {?string} | |
1080 */ | |
1081 asDataURL: function() | |
1082 { | |
1083 var content = this._content; | |
1084 var charset = null; | |
1085 if (!this._contentEncoded) { | |
1086 content = content.toBase64(); | |
1087 charset = "utf-8"; | |
1088 } | |
1089 return WebInspector.ContentProvider.contentAsDataURL(content, this.mimeT
ype, true, charset); | |
1090 }, | |
1091 | |
1092 _innerRequestContent: function() | |
1093 { | |
1094 if (this._contentRequested) | |
1095 return; | |
1096 this._contentRequested = true; | |
1097 | |
1098 /** | |
1099 * @param {?Protocol.Error} error | |
1100 * @param {string} content | |
1101 * @param {boolean} contentEncoded | |
1102 * @this {WebInspector.NetworkRequest} | |
1103 */ | |
1104 function onResourceContent(error, content, contentEncoded) | |
1105 { | |
1106 this._content = error ? null : content; | |
1107 this._contentError = error; | |
1108 this._contentEncoded = contentEncoded; | |
1109 var callbacks = this._pendingContentCallbacks.slice(); | |
1110 for (var i = 0; i < callbacks.length; ++i) | |
1111 callbacks[i](this._content); | |
1112 this._pendingContentCallbacks.length = 0; | |
1113 delete this._contentRequested; | |
1114 } | |
1115 this.target().networkAgent().getResponseBody(this._requestId, onResource
Content.bind(this)); | |
1116 }, | |
1117 | |
1118 /** | |
1119 * @return {?NetworkAgent.Initiator} | |
1120 */ | |
1121 initiator: function() | |
1122 { | |
1123 return this._initiator; | |
1124 }, | |
1125 | |
1126 /** | |
1127 * @return {!{type: !WebInspector.NetworkRequest.InitiatorType, url: string,
lineNumber: number, columnNumber: number, scriptId: ?string}} | |
1128 */ | |
1129 initiatorInfo: function() | |
1130 { | |
1131 if (this._initiatorInfo) | |
1132 return this._initiatorInfo; | |
1133 | |
1134 var type = WebInspector.NetworkRequest.InitiatorType.Other; | |
1135 var url = ""; | |
1136 var lineNumber = -Infinity; | |
1137 var columnNumber = -Infinity; | |
1138 var scriptId = null; | |
1139 var initiator = this._initiator; | |
1140 | |
1141 if (this.redirectSource) { | |
1142 type = WebInspector.NetworkRequest.InitiatorType.Redirect; | |
1143 url = this.redirectSource.url; | |
1144 } else if (initiator) { | |
1145 if (initiator.type === NetworkAgent.InitiatorType.Parser) { | |
1146 type = WebInspector.NetworkRequest.InitiatorType.Parser; | |
1147 url = initiator.url ? initiator.url : url; | |
1148 lineNumber = initiator.lineNumber ? initiator.lineNumber : lineN
umber; | |
1149 } else if (initiator.type === NetworkAgent.InitiatorType.Script) { | |
1150 for (var stack = initiator.stack; stack; stack = stack.parent) { | |
1151 var topFrame = stack.callFrames.length ? stack.callFrames[0]
: null; | |
1152 if (!topFrame) | |
1153 continue; | |
1154 type = WebInspector.NetworkRequest.InitiatorType.Script; | |
1155 url = topFrame.url || WebInspector.UIString("<anonymous>"); | |
1156 lineNumber = topFrame.lineNumber; | |
1157 columnNumber = topFrame.columnNumber; | |
1158 scriptId = topFrame.scriptId; | |
1159 break; | |
1160 } | |
1161 } | |
1162 } | |
1163 | |
1164 this._initiatorInfo = {type: type, url: url, lineNumber: lineNumber, col
umnNumber: columnNumber, scriptId: scriptId}; | |
1165 return this._initiatorInfo; | |
1166 }, | |
1167 | |
1168 /** | |
1169 * @return {?WebInspector.NetworkRequest} | |
1170 */ | |
1171 initiatorRequest: function() | |
1172 { | |
1173 if (this._initiatorRequest === undefined) | |
1174 this._initiatorRequest = this._networkLog.requestForURL(this.initiat
orInfo().url); | |
1175 return this._initiatorRequest; | |
1176 }, | |
1177 | |
1178 /** | |
1179 * @return {!WebInspector.NetworkRequest.InitiatorGraph} | |
1180 */ | |
1181 initiatorGraph: function() | |
1182 { | |
1183 var initiated = new Set(); | |
1184 var requests = this._networkLog.requests(); | |
1185 for (var request of requests) { | |
1186 var localInitiators = request._initiatorChain(); | |
1187 if (localInitiators.has(this)) | |
1188 initiated.add(request); | |
1189 } | |
1190 return {initiators: this._initiatorChain(), initiated: initiated}; | |
1191 }, | |
1192 | |
1193 /** | |
1194 * @return {!Set<!WebInspector.NetworkRequest>} | |
1195 */ | |
1196 _initiatorChain: function() | |
1197 { | |
1198 if (this._initiatorChainCache) | |
1199 return this._initiatorChainCache; | |
1200 this._initiatorChainCache = new Set(); | |
1201 var request = this; | |
1202 while (request) { | |
1203 this._initiatorChainCache.add(request); | |
1204 request = request.initiatorRequest(); | |
1205 } | |
1206 return this._initiatorChainCache; | |
1207 }, | |
1208 | |
1209 /** | |
1210 * @return {!Array.<!WebInspector.NetworkRequest.WebSocketFrame>} | |
1211 */ | |
1212 frames: function() | |
1213 { | |
1214 return this._frames; | |
1215 }, | |
1216 | |
1217 /** | |
1218 * @param {string} errorMessage | |
1219 * @param {number} time | |
1220 */ | |
1221 addFrameError: function(errorMessage, time) | |
1222 { | |
1223 this._addFrame({ type: WebInspector.NetworkRequest.WebSocketFrameType.Er
ror, text: errorMessage, time: this.pseudoWallTime(time), opCode: -1, mask: fals
e }); | |
1224 }, | |
1225 | |
1226 /** | |
1227 * @param {!NetworkAgent.WebSocketFrame} response | |
1228 * @param {number} time | |
1229 * @param {boolean} sent | |
1230 */ | |
1231 addFrame: function(response, time, sent) | |
1232 { | |
1233 var type = sent ? WebInspector.NetworkRequest.WebSocketFrameType.Send :
WebInspector.NetworkRequest.WebSocketFrameType.Receive; | |
1234 this._addFrame({ type: type, text: response.payloadData, time: this.pseu
doWallTime(time), opCode: response.opcode, mask: response.mask }); | |
1235 }, | |
1236 | |
1237 /** | |
1238 * @param {!WebInspector.NetworkRequest.WebSocketFrame} frame | |
1239 */ | |
1240 _addFrame: function(frame) | |
1241 { | |
1242 this._frames.push(frame); | |
1243 this.dispatchEventToListeners(WebInspector.NetworkRequest.Events.Websock
etFrameAdded, frame); | |
1244 }, | |
1245 | |
1246 /** | |
1247 * @return {!Array.<!WebInspector.NetworkRequest.EventSourceMessage>} | |
1248 */ | |
1249 eventSourceMessages: function() | |
1250 { | |
1251 return this._eventSourceMessages; | |
1252 }, | |
1253 | |
1254 /** | |
1255 * @param {number} time | |
1256 * @param {string} eventName | |
1257 * @param {string} eventId | |
1258 * @param {string} data | |
1259 */ | |
1260 addEventSourceMessage: function(time, eventName, eventId, data) | |
1261 { | |
1262 var message = {time: this.pseudoWallTime(time), eventName: eventName, ev
entId: eventId, data: data}; | |
1263 this._eventSourceMessages.push(message); | |
1264 this.dispatchEventToListeners(WebInspector.NetworkRequest.Events.EventSo
urceMessageAdded, message); | |
1265 }, | |
1266 | |
1267 replayXHR: function() | |
1268 { | |
1269 this.target().networkAgent().replayXHR(this.requestId); | |
1270 }, | |
1271 | |
1272 /** | |
1273 * @return {!WebInspector.NetworkLog} | |
1274 */ | |
1275 networkLog: function() | |
1276 { | |
1277 return this._networkLog; | |
1278 }, | |
1279 | |
1280 /** | |
1281 * @return {!WebInspector.NetworkManager} | |
1282 */ | |
1283 networkManager: function() | |
1284 { | |
1285 return this._networkManager; | |
1286 }, | |
1287 | |
1288 __proto__: WebInspector.SDKObject.prototype | |
1289 }; | |
OLD | NEW |