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 15 matching lines...) Expand all Loading... | |
| 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 /** | 30 /** |
| 31 * @implements {Common.ContentProvider} | 31 * @implements {Common.ContentProvider} |
| 32 * @unrestricted | 32 * @unrestricted |
| 33 */ | 33 */ |
| 34 SDK.NetworkRequest = class extends Common.Object { | 34 SDK.NetworkRequest = class extends Common.Object { |
| 35 /** | 35 /** |
| 36 * @param {!SDK.NetworkManager} networkManager | |
| 37 * @param {!Protocol.Network.RequestId} requestId | 36 * @param {!Protocol.Network.RequestId} requestId |
| 38 * @param {string} url | 37 * @param {string} url |
| 39 * @param {string} documentURL | 38 * @param {string} documentURL |
| 40 * @param {!Protocol.Page.FrameId} frameId | 39 * @param {!Protocol.Page.FrameId} frameId |
| 41 * @param {!Protocol.Network.LoaderId} loaderId | 40 * @param {!Protocol.Network.LoaderId} loaderId |
| 42 * @param {?Protocol.Network.Initiator} initiator | 41 * @param {?Protocol.Network.Initiator} initiator |
| 43 */ | 42 */ |
| 44 constructor(networkManager, requestId, url, documentURL, frameId, loaderId, in itiator) { | 43 constructor(requestId, url, documentURL, frameId, loaderId, initiator) { |
| 45 super(); | 44 super(); |
| 46 | 45 |
| 47 this._networkManager = networkManager; | |
| 48 this._requestId = requestId; | 46 this._requestId = requestId; |
| 49 this.setUrl(url); | 47 this.setUrl(url); |
| 50 this._documentURL = documentURL; | 48 this._documentURL = documentURL; |
| 51 this._frameId = frameId; | 49 this._frameId = frameId; |
| 52 this._loaderId = loaderId; | 50 this._loaderId = loaderId; |
| 53 /** @type {?Protocol.Network.Initiator} */ | 51 /** @type {?Protocol.Network.Initiator} */ |
| 54 this._initiator = initiator; | 52 this._initiator = initiator; |
| 55 /** @type {?SDK.NetworkRequest} */ | 53 /** @type {?SDK.NetworkRequest} */ |
| 56 this._redirectSource = null; | 54 this._redirectSource = null; |
| 57 this._issueTime = -1; | 55 this._issueTime = -1; |
| (...skipping 468 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 526 _parseNameAndPathFromURL() { | 524 _parseNameAndPathFromURL() { |
| 527 if (this._parsedURL.isDataURL()) { | 525 if (this._parsedURL.isDataURL()) { |
| 528 this._name = this._parsedURL.dataURLDisplayName(); | 526 this._name = this._parsedURL.dataURLDisplayName(); |
| 529 this._path = ''; | 527 this._path = ''; |
| 530 } else if (this._parsedURL.isAboutBlank()) { | 528 } else if (this._parsedURL.isAboutBlank()) { |
| 531 this._name = this._parsedURL.url; | 529 this._name = this._parsedURL.url; |
| 532 this._path = ''; | 530 this._path = ''; |
| 533 } else { | 531 } else { |
| 534 this._path = this._parsedURL.host + this._parsedURL.folderPathComponents; | 532 this._path = this._parsedURL.host + this._parsedURL.folderPathComponents; |
| 535 | 533 |
| 536 var inspectedURL = this._networkManager.target().inspectedURL().asParsedUR L(); | 534 var networkManager = SDK.NetworkManager.managerForRequest(this); |
| 535 var inspectedURL = networkManager ? networkManager.target().inspectedURL() .asParsedURL() : null; | |
| 537 this._path = this._path.trimURL(inspectedURL ? inspectedURL.host : ''); | 536 this._path = this._path.trimURL(inspectedURL ? inspectedURL.host : ''); |
| 538 if (this._parsedURL.lastPathComponent || this._parsedURL.queryParams) { | 537 if (this._parsedURL.lastPathComponent || this._parsedURL.queryParams) { |
| 539 this._name = | 538 this._name = |
| 540 this._parsedURL.lastPathComponent + (this._parsedURL.queryParams ? ' ?' + this._parsedURL.queryParams : ''); | 539 this._parsedURL.lastPathComponent + (this._parsedURL.queryParams ? ' ?' + this._parsedURL.queryParams : ''); |
| 541 } else if (this._parsedURL.folderPathComponents) { | 540 } else if (this._parsedURL.folderPathComponents) { |
| 542 this._name = | 541 this._name = |
| 543 this._parsedURL.folderPathComponents.substring(this._parsedURL.folde rPathComponents.lastIndexOf('/') + 1) + | 542 this._parsedURL.folderPathComponents.substring(this._parsedURL.folde rPathComponents.lastIndexOf('/') + 1) + |
| 544 '/'; | 543 '/'; |
| 545 this._path = this._path.substring(0, this._path.lastIndexOf('/')); | 544 this._path = this._path.substring(0, this._path.lastIndexOf('/')); |
| 546 } else { | 545 } else { |
| (...skipping 462 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1009 if (!this._contentEncoded) { | 1008 if (!this._contentEncoded) { |
| 1010 content = content.toBase64(); | 1009 content = content.toBase64(); |
| 1011 charset = 'utf-8'; | 1010 charset = 'utf-8'; |
| 1012 } | 1011 } |
| 1013 return Common.ContentProvider.contentAsDataURL(content, this.mimeType, true, charset); | 1012 return Common.ContentProvider.contentAsDataURL(content, this.mimeType, true, charset); |
| 1014 } | 1013 } |
| 1015 | 1014 |
| 1016 _innerRequestContent() { | 1015 _innerRequestContent() { |
| 1017 if (this._contentRequested) | 1016 if (this._contentRequested) |
| 1018 return; | 1017 return; |
| 1018 var networkManager = SDK.NetworkManager.managerForRequest(this); | |
| 1019 if (!networkManager) | |
| 1020 return; | |
| 1019 this._contentRequested = true; | 1021 this._contentRequested = true; |
| 1022 // TODO(allada) This should be moved into NetworkManager. | |
|
dgozman
2017/06/06 20:54:41
This should actually be abstracted away to work wi
allada
2017/06/08 00:42:06
Well HAR import will set the content of the reques
| |
| 1023 networkManager.target().networkAgent().getResponseBody(this._requestId, onRe sourceContent.bind(this)); | |
| 1020 | 1024 |
| 1021 /** | 1025 /** |
| 1022 * @param {?Protocol.Error} error | 1026 * @param {?Protocol.Error} error |
| 1023 * @param {string} content | 1027 * @param {string} content |
| 1024 * @param {boolean} contentEncoded | 1028 * @param {boolean} contentEncoded |
| 1025 * @this {SDK.NetworkRequest} | 1029 * @this {SDK.NetworkRequest} |
| 1026 */ | 1030 */ |
| 1027 function onResourceContent(error, content, contentEncoded) { | 1031 function onResourceContent(error, content, contentEncoded) { |
| 1028 this._content = error ? null : content; | 1032 this._content = error ? null : content; |
| 1029 this._contentError = error; | 1033 this._contentError = error; |
| 1030 this._contentEncoded = contentEncoded; | 1034 this._contentEncoded = contentEncoded; |
| 1031 var callbacks = this._pendingContentCallbacks.slice(); | 1035 var callbacks = this._pendingContentCallbacks.slice(); |
| 1032 for (var i = 0; i < callbacks.length; ++i) | 1036 for (var i = 0; i < callbacks.length; ++i) |
| 1033 callbacks[i](this._content); | 1037 callbacks[i](this._content); |
| 1034 this._pendingContentCallbacks.length = 0; | 1038 this._pendingContentCallbacks.length = 0; |
| 1035 delete this._contentRequested; | 1039 delete this._contentRequested; |
| 1036 } | 1040 } |
| 1037 this._networkManager.target().networkAgent().getResponseBody(this._requestId , onResourceContent.bind(this)); | |
| 1038 } | 1041 } |
| 1039 | 1042 |
| 1040 /** | 1043 /** |
| 1041 * @return {?Protocol.Network.Initiator} | 1044 * @return {?Protocol.Network.Initiator} |
| 1042 */ | 1045 */ |
| 1043 initiator() { | 1046 initiator() { |
| 1044 return this._initiator; | 1047 return this._initiator; |
| 1045 } | 1048 } |
| 1046 | 1049 |
| 1047 /** | 1050 /** |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1100 * @param {number} time | 1103 * @param {number} time |
| 1101 * @param {string} eventName | 1104 * @param {string} eventName |
| 1102 * @param {string} eventId | 1105 * @param {string} eventId |
| 1103 * @param {string} data | 1106 * @param {string} data |
| 1104 */ | 1107 */ |
| 1105 addEventSourceMessage(time, eventName, eventId, data) { | 1108 addEventSourceMessage(time, eventName, eventId, data) { |
| 1106 var message = {time: this.pseudoWallTime(time), eventName: eventName, eventI d: eventId, data: data}; | 1109 var message = {time: this.pseudoWallTime(time), eventName: eventName, eventI d: eventId, data: data}; |
| 1107 this._eventSourceMessages.push(message); | 1110 this._eventSourceMessages.push(message); |
| 1108 this.dispatchEventToListeners(SDK.NetworkRequest.Events.EventSourceMessageAd ded, message); | 1111 this.dispatchEventToListeners(SDK.NetworkRequest.Events.EventSourceMessageAd ded, message); |
| 1109 } | 1112 } |
| 1110 | |
| 1111 /** | |
| 1112 * @return {!SDK.NetworkManager} | |
| 1113 */ | |
| 1114 networkManager() { | |
| 1115 return this._networkManager; | |
| 1116 } | |
| 1117 }; | 1113 }; |
| 1118 | 1114 |
| 1119 /** @enum {symbol} */ | 1115 /** @enum {symbol} */ |
| 1120 SDK.NetworkRequest.Events = { | 1116 SDK.NetworkRequest.Events = { |
| 1121 FinishedLoading: Symbol('FinishedLoading'), | 1117 FinishedLoading: Symbol('FinishedLoading'), |
| 1122 TimingChanged: Symbol('TimingChanged'), | 1118 TimingChanged: Symbol('TimingChanged'), |
| 1123 RemoteAddressChanged: Symbol('RemoteAddressChanged'), | 1119 RemoteAddressChanged: Symbol('RemoteAddressChanged'), |
| 1124 RequestHeadersChanged: Symbol('RequestHeadersChanged'), | 1120 RequestHeadersChanged: Symbol('RequestHeadersChanged'), |
| 1125 ResponseHeadersChanged: Symbol('ResponseHeadersChanged'), | 1121 ResponseHeadersChanged: Symbol('ResponseHeadersChanged'), |
| 1126 WebsocketFrameAdded: Symbol('WebsocketFrameAdded'), | 1122 WebsocketFrameAdded: Symbol('WebsocketFrameAdded'), |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 1144 Send: 'send', | 1140 Send: 'send', |
| 1145 Receive: 'receive', | 1141 Receive: 'receive', |
| 1146 Error: 'error' | 1142 Error: 'error' |
| 1147 }; | 1143 }; |
| 1148 | 1144 |
| 1149 /** @typedef {!{type: SDK.NetworkRequest.WebSocketFrameType, time: number, text: string, opCode: number, mask: boolean}} */ | 1145 /** @typedef {!{type: SDK.NetworkRequest.WebSocketFrameType, time: number, text: string, opCode: number, mask: boolean}} */ |
| 1150 SDK.NetworkRequest.WebSocketFrame; | 1146 SDK.NetworkRequest.WebSocketFrame; |
| 1151 | 1147 |
| 1152 /** @typedef {!{time: number, eventName: string, eventId: string, data: string}} */ | 1148 /** @typedef {!{time: number, eventName: string, eventId: string, data: string}} */ |
| 1153 SDK.NetworkRequest.EventSourceMessage; | 1149 SDK.NetworkRequest.EventSourceMessage; |
| OLD | NEW |