Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(547)

Side by Side Diff: third_party/WebKit/Source/devtools/front_end/sdk/NetworkRequest.js

Issue 2628693002: [Devtools] Move initiator data into NetworkLog from NetworkRequest (Closed)
Patch Set: changes Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « third_party/WebKit/Source/devtools/front_end/sdk/NetworkManager.js ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 26 matching lines...) Expand all
37 * @param {!SDK.Target} target 37 * @param {!SDK.Target} target
38 * @param {string} url 38 * @param {string} url
39 * @param {string} documentURL 39 * @param {string} documentURL
40 * @param {!Protocol.Page.FrameId} frameId 40 * @param {!Protocol.Page.FrameId} frameId
41 * @param {!Protocol.Network.LoaderId} loaderId 41 * @param {!Protocol.Network.LoaderId} loaderId
42 * @param {?Protocol.Network.Initiator} initiator 42 * @param {?Protocol.Network.Initiator} initiator
43 */ 43 */
44 constructor(target, requestId, url, documentURL, frameId, loaderId, initiator) { 44 constructor(target, requestId, url, documentURL, frameId, loaderId, initiator) {
45 super(target); 45 super(target);
46 46
47 this._networkLog = /** @type {!SDK.NetworkLog} */ (SDK.NetworkLog.fromTarget (target));
48 this._networkManager = /** @type {!SDK.NetworkManager} */ (SDK.NetworkManage r.fromTarget(target)); 47 this._networkManager = /** @type {!SDK.NetworkManager} */ (SDK.NetworkManage r.fromTarget(target));
49 this._requestId = requestId; 48 this._requestId = requestId;
50 this.setUrl(url); 49 this.setUrl(url);
51 this._documentURL = documentURL; 50 this._documentURL = documentURL;
52 this._frameId = frameId; 51 this._frameId = frameId;
53 this._loaderId = loaderId; 52 this._loaderId = loaderId;
54 /** @type {?Protocol.Network.Initiator} */ 53 /** @type {?Protocol.Network.Initiator} */
55 this._initiator = initiator; 54 this._initiator = initiator;
56 this._issueTime = -1; 55 this._issueTime = -1;
57 this._startTime = -1; 56 this._startTime = -1;
(...skipping 538 matching lines...) Expand 10 before | Expand all | Expand 10 after
596 if (this.redirects && this.redirects.length > 0) 595 if (this.redirects && this.redirects.length > 0)
597 return this.redirects[this.redirects.length - 1]; 596 return this.redirects[this.redirects.length - 1];
598 return this._redirectSource; 597 return this._redirectSource;
599 } 598 }
600 599
601 /** 600 /**
602 * @param {?SDK.NetworkRequest} x 601 * @param {?SDK.NetworkRequest} x
603 */ 602 */
604 set redirectSource(x) { 603 set redirectSource(x) {
605 this._redirectSource = x; 604 this._redirectSource = x;
606 delete this._initiatorInfo;
607 } 605 }
608 606
609 /** 607 /**
610 * @return {!Array.<!SDK.NetworkRequest.NameValue>} 608 * @return {!Array.<!SDK.NetworkRequest.NameValue>}
611 */ 609 */
612 requestHeaders() { 610 requestHeaders() {
613 return this._requestHeaders || []; 611 return this._requestHeaders || [];
614 } 612 }
615 613
616 /** 614 /**
(...skipping 423 matching lines...) Expand 10 before | Expand all | Expand 10 after
1040 } 1038 }
1041 1039
1042 /** 1040 /**
1043 * @return {?Protocol.Network.Initiator} 1041 * @return {?Protocol.Network.Initiator}
1044 */ 1042 */
1045 initiator() { 1043 initiator() {
1046 return this._initiator; 1044 return this._initiator;
1047 } 1045 }
1048 1046
1049 /** 1047 /**
1050 * @return {!{type: !SDK.NetworkRequest.InitiatorType, url: string, lineNumber : number, columnNumber: number, scriptId: ?string}}
1051 */
1052 initiatorInfo() {
1053 if (this._initiatorInfo)
1054 return this._initiatorInfo;
1055
1056 var type = SDK.NetworkRequest.InitiatorType.Other;
1057 var url = '';
1058 var lineNumber = -Infinity;
1059 var columnNumber = -Infinity;
1060 var scriptId = null;
1061 var initiator = this._initiator;
1062
1063 if (this.redirectSource) {
1064 type = SDK.NetworkRequest.InitiatorType.Redirect;
1065 url = this.redirectSource.url();
1066 } else if (initiator) {
1067 if (initiator.type === Protocol.Network.InitiatorType.Parser) {
1068 type = SDK.NetworkRequest.InitiatorType.Parser;
1069 url = initiator.url ? initiator.url : url;
1070 lineNumber = initiator.lineNumber ? initiator.lineNumber : lineNumber;
1071 } else if (initiator.type === Protocol.Network.InitiatorType.Script) {
1072 for (var stack = initiator.stack; stack; stack = stack.parent) {
1073 var topFrame = stack.callFrames.length ? stack.callFrames[0] : null;
1074 if (!topFrame)
1075 continue;
1076 type = SDK.NetworkRequest.InitiatorType.Script;
1077 url = topFrame.url || Common.UIString('<anonymous>');
1078 lineNumber = topFrame.lineNumber;
1079 columnNumber = topFrame.columnNumber;
1080 scriptId = topFrame.scriptId;
1081 break;
1082 }
1083 }
1084 }
1085
1086 this._initiatorInfo =
1087 {type: type, url: url, lineNumber: lineNumber, columnNumber: columnNumbe r, scriptId: scriptId};
1088 return this._initiatorInfo;
1089 }
1090
1091 /**
1092 * @return {?SDK.NetworkRequest}
1093 */
1094 initiatorRequest() {
1095 if (this._initiatorRequest === undefined)
1096 this._initiatorRequest = this._networkLog.requestForURL(this.initiatorInfo ().url);
1097 return this._initiatorRequest;
1098 }
1099
1100 /**
1101 * @return {!SDK.NetworkRequest.InitiatorGraph}
1102 */
1103 initiatorGraph() {
1104 var initiated = new Set();
1105 var requests = this._networkLog.requests();
1106 for (var request of requests) {
1107 var localInitiators = request._initiatorChain();
1108 if (localInitiators.has(this))
1109 initiated.add(request);
1110 }
1111 return {initiators: this._initiatorChain(), initiated: initiated};
1112 }
1113
1114 /**
1115 * @return {!Set<!SDK.NetworkRequest>}
1116 */
1117 _initiatorChain() {
1118 if (this._initiatorChainCache)
1119 return this._initiatorChainCache;
1120 this._initiatorChainCache = new Set();
1121 var request = this;
1122 while (request) {
1123 this._initiatorChainCache.add(request);
1124 request = request.initiatorRequest();
1125 }
1126 return this._initiatorChainCache;
1127 }
1128
1129 /**
1130 * @return {!Array.<!SDK.NetworkRequest.WebSocketFrame>} 1048 * @return {!Array.<!SDK.NetworkRequest.WebSocketFrame>}
1131 */ 1049 */
1132 frames() { 1050 frames() {
1133 return this._frames; 1051 return this._frames;
1134 } 1052 }
1135 1053
1136 /** 1054 /**
1137 * @param {string} errorMessage 1055 * @param {string} errorMessage
1138 * @param {number} time 1056 * @param {number} time
1139 */ 1057 */
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
1188 var message = {time: this.pseudoWallTime(time), eventName: eventName, eventI d: eventId, data: data}; 1106 var message = {time: this.pseudoWallTime(time), eventName: eventName, eventI d: eventId, data: data};
1189 this._eventSourceMessages.push(message); 1107 this._eventSourceMessages.push(message);
1190 this.dispatchEventToListeners(SDK.NetworkRequest.Events.EventSourceMessageAd ded, message); 1108 this.dispatchEventToListeners(SDK.NetworkRequest.Events.EventSourceMessageAd ded, message);
1191 } 1109 }
1192 1110
1193 replayXHR() { 1111 replayXHR() {
1194 this.target().networkAgent().replayXHR(this._requestId); 1112 this.target().networkAgent().replayXHR(this._requestId);
1195 } 1113 }
1196 1114
1197 /** 1115 /**
1198 * @return {!SDK.NetworkLog}
1199 */
1200 networkLog() {
1201 return this._networkLog;
1202 }
1203
1204 /**
1205 * @return {!SDK.NetworkManager} 1116 * @return {!SDK.NetworkManager}
1206 */ 1117 */
1207 networkManager() { 1118 networkManager() {
1208 return this._networkManager; 1119 return this._networkManager;
1209 } 1120 }
1210 }; 1121 };
1211 1122
1212 /** @enum {symbol} */ 1123 /** @enum {symbol} */
1213 SDK.NetworkRequest.Events = { 1124 SDK.NetworkRequest.Events = {
1214 FinishedLoading: Symbol('FinishedLoading'), 1125 FinishedLoading: Symbol('FinishedLoading'),
(...skipping 21 matching lines...) Expand all
1236 Send: 'send', 1147 Send: 'send',
1237 Receive: 'receive', 1148 Receive: 'receive',
1238 Error: 'error' 1149 Error: 'error'
1239 }; 1150 };
1240 1151
1241 /** @typedef {!{type: SDK.NetworkRequest.WebSocketFrameType, time: number, text: string, opCode: number, mask: boolean}} */ 1152 /** @typedef {!{type: SDK.NetworkRequest.WebSocketFrameType, time: number, text: string, opCode: number, mask: boolean}} */
1242 SDK.NetworkRequest.WebSocketFrame; 1153 SDK.NetworkRequest.WebSocketFrame;
1243 1154
1244 /** @typedef {!{time: number, eventName: string, eventId: string, data: string}} */ 1155 /** @typedef {!{time: number, eventName: string, eventId: string, data: string}} */
1245 SDK.NetworkRequest.EventSourceMessage; 1156 SDK.NetworkRequest.EventSourceMessage;
1246
1247 /** @typedef {!{initiators: !Set<!SDK.NetworkRequest>, initiated: !Set<!SDK.Netw orkRequest>}} */
1248 SDK.NetworkRequest.InitiatorGraph;
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/devtools/front_end/sdk/NetworkManager.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698