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

Side by Side Diff: Source/devtools/front_end/sdk/NetworkManager.js

Issue 667743002: DevTools: remove "type" getters in Resource and NetworkRequest. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 6 years, 2 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
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2011 Google Inc. All rights reserved. 2 * Copyright (C) 2011 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 196 matching lines...) Expand 10 before | Expand all | Expand 10 after
207 networkRequest.fetchedViaServiceWorker = true; 207 networkRequest.fetchedViaServiceWorker = true;
208 208
209 if (response.fromDiskCache) 209 if (response.fromDiskCache)
210 networkRequest.setFromDiskCache(); 210 networkRequest.setFromDiskCache();
211 networkRequest.timing = response.timing; 211 networkRequest.timing = response.timing;
212 212
213 if (!this._mimeTypeIsConsistentWithType(networkRequest)) { 213 if (!this._mimeTypeIsConsistentWithType(networkRequest)) {
214 var consoleModel = this._manager._target.consoleModel; 214 var consoleModel = this._manager._target.consoleModel;
215 consoleModel.addMessage(new WebInspector.ConsoleMessage(consoleModel .target(), WebInspector.ConsoleMessage.MessageSource.Network, 215 consoleModel.addMessage(new WebInspector.ConsoleMessage(consoleModel .target(), WebInspector.ConsoleMessage.MessageSource.Network,
216 WebInspector.ConsoleMessage.MessageLevel.Log, 216 WebInspector.ConsoleMessage.MessageLevel.Log,
217 WebInspector.UIString("Resource interpreted as %s but transferre d with MIME type %s: \"%s\".", networkRequest.type.title(), networkRequest.mimeT ype, networkRequest.url), 217 WebInspector.UIString("Resource interpreted as %s but transferre d with MIME type %s: \"%s\".", networkRequest.resourceType().title(), networkReq uest.mimeType, networkRequest.url),
218 WebInspector.ConsoleMessage.MessageType.Log, 218 WebInspector.ConsoleMessage.MessageType.Log,
219 "", 219 "",
220 0, 220 0,
221 0, 221 0,
222 networkRequest.requestId)); 222 networkRequest.requestId));
223 } 223 }
224 }, 224 },
225 225
226 /** 226 /**
227 * @param {!WebInspector.NetworkRequest} networkRequest 227 * @param {!WebInspector.NetworkRequest} networkRequest
228 * @return {boolean} 228 * @return {boolean}
229 */ 229 */
230 _mimeTypeIsConsistentWithType: function(networkRequest) 230 _mimeTypeIsConsistentWithType: function(networkRequest)
231 { 231 {
232 // If status is an error, content is likely to be of an inconsistent typ e, 232 // If status is an error, content is likely to be of an inconsistent typ e,
233 // as it's going to be an error message. We do not want to emit a warnin g 233 // as it's going to be an error message. We do not want to emit a warnin g
234 // for this, though, as this will already be reported as resource loadin g failure. 234 // for this, though, as this will already be reported as resource loadin g failure.
235 // Also, if a URL like http://localhost/wiki/load.php?debug=true&lang=en produces text/css and gets reloaded, 235 // Also, if a URL like http://localhost/wiki/load.php?debug=true&lang=en produces text/css and gets reloaded,
236 // it is 304 Not Modified and its guessed mime-type is text/php, which i s wrong. 236 // it is 304 Not Modified and its guessed mime-type is text/php, which i s wrong.
237 // Don't check for mime-types in 304-resources. 237 // Don't check for mime-types in 304-resources.
238 if (networkRequest.hasErrorStatusCode() || networkRequest.statusCode === 304 || networkRequest.statusCode === 204) 238 if (networkRequest.hasErrorStatusCode() || networkRequest.statusCode === 304 || networkRequest.statusCode === 204)
239 return true; 239 return true;
240 240
241 if (typeof networkRequest.type === "undefined" 241 var resourceType = networkRequest.resourceType();
242 || networkRequest.type === WebInspector.resourceTypes.Other 242 if (resourceType === undefined
243 || networkRequest.type === WebInspector.resourceTypes.Media 243 || resourceType === WebInspector.resourceTypes.Other
244 || networkRequest.type === WebInspector.resourceTypes.XHR 244 || resourceType === WebInspector.resourceTypes.Media
245 || networkRequest.type === WebInspector.resourceTypes.WebSocket) 245 || resourceType === WebInspector.resourceTypes.XHR
246 || resourceType === WebInspector.resourceTypes.WebSocket)
246 return true; 247 return true;
247 248
248 if (!networkRequest.mimeType) 249 if (!networkRequest.mimeType)
249 return true; // Might be not known for cached resources with null re sponses. 250 return true; // Might be not known for cached resources with null re sponses.
250 251
251 if (networkRequest.mimeType in WebInspector.NetworkManager._MIMETypes) 252 if (networkRequest.mimeType in WebInspector.NetworkManager._MIMETypes)
252 return networkRequest.type.name() in WebInspector.NetworkManager._MI METypes[networkRequest.mimeType]; 253 return resourceType.name() in WebInspector.NetworkManager._MIMETypes [networkRequest.mimeType];
253 254
254 return false; 255 return false;
255 }, 256 },
256 257
257 /** 258 /**
258 * @param {!NetworkAgent.RequestId} requestId 259 * @param {!NetworkAgent.RequestId} requestId
259 * @param {!PageAgent.FrameId} frameId 260 * @param {!PageAgent.FrameId} frameId
260 * @param {!NetworkAgent.LoaderId} loaderId 261 * @param {!NetworkAgent.LoaderId} loaderId
261 * @param {string} documentURL 262 * @param {string} documentURL
262 * @param {!NetworkAgent.Request} request 263 * @param {!NetworkAgent.Request} request
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
311 eventData.url = response.url; 312 eventData.url = response.url;
312 eventData.frameId = frameId; 313 eventData.frameId = frameId;
313 eventData.loaderId = loaderId; 314 eventData.loaderId = loaderId;
314 eventData.resourceType = resourceType; 315 eventData.resourceType = resourceType;
315 eventData.mimeType = response.mimeType; 316 eventData.mimeType = response.mimeType;
316 this._manager.dispatchEventToListeners(WebInspector.NetworkManager.E ventTypes.RequestUpdateDropped, eventData); 317 this._manager.dispatchEventToListeners(WebInspector.NetworkManager.E ventTypes.RequestUpdateDropped, eventData);
317 return; 318 return;
318 } 319 }
319 320
320 networkRequest.responseReceivedTime = time; 321 networkRequest.responseReceivedTime = time;
321 networkRequest.type = WebInspector.resourceTypes[resourceType]; 322 networkRequest.setResourceType(WebInspector.resourceTypes[resourceType]) ;
322 323
323 this._updateNetworkRequestWithResponse(networkRequest, response); 324 this._updateNetworkRequestWithResponse(networkRequest, response);
324 325
325 this._updateNetworkRequest(networkRequest); 326 this._updateNetworkRequest(networkRequest);
326 }, 327 },
327 328
328 /** 329 /**
329 * @param {!NetworkAgent.RequestId} requestId 330 * @param {!NetworkAgent.RequestId} requestId
330 * @param {!NetworkAgent.Timestamp} time 331 * @param {!NetworkAgent.Timestamp} time
331 * @param {number} dataLength 332 * @param {number} dataLength
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
365 * @param {string} localizedDescription 366 * @param {string} localizedDescription
366 * @param {boolean=} canceled 367 * @param {boolean=} canceled
367 */ 368 */
368 loadingFailed: function(requestId, time, resourceType, localizedDescription, canceled) 369 loadingFailed: function(requestId, time, resourceType, localizedDescription, canceled)
369 { 370 {
370 var networkRequest = this._inflightRequestsById[requestId]; 371 var networkRequest = this._inflightRequestsById[requestId];
371 if (!networkRequest) 372 if (!networkRequest)
372 return; 373 return;
373 374
374 networkRequest.failed = true; 375 networkRequest.failed = true;
375 networkRequest.type = WebInspector.resourceTypes[resourceType]; 376 networkRequest.setResourceType(WebInspector.resourceTypes[resourceType]) ;
376 networkRequest.canceled = canceled; 377 networkRequest.canceled = canceled;
377 networkRequest.localizedFailDescription = localizedDescription; 378 networkRequest.localizedFailDescription = localizedDescription;
378 this._finishNetworkRequest(networkRequest, time, -1); 379 this._finishNetworkRequest(networkRequest, time, -1);
379 }, 380 },
380 381
381 /** 382 /**
382 * @param {!NetworkAgent.RequestId} requestId 383 * @param {!NetworkAgent.RequestId} requestId
383 * @param {string} requestURL 384 * @param {string} requestURL
384 */ 385 */
385 webSocketCreated: function(requestId, requestURL) 386 webSocketCreated: function(requestId, requestURL)
386 { 387 {
387 // FIXME: WebSocket MUST have initiator info. 388 // FIXME: WebSocket MUST have initiator info.
388 var networkRequest = new WebInspector.NetworkRequest(this._manager._targ et, requestId, requestURL, "", "", "", null); 389 var networkRequest = new WebInspector.NetworkRequest(this._manager._targ et, requestId, requestURL, "", "", "", null);
389 networkRequest.type = WebInspector.resourceTypes.WebSocket; 390 networkRequest.setResourceType(WebInspector.resourceTypes.WebSocket);
390 this._startNetworkRequest(networkRequest); 391 this._startNetworkRequest(networkRequest);
391 }, 392 },
392 393
393 /** 394 /**
394 * @param {!NetworkAgent.RequestId} requestId 395 * @param {!NetworkAgent.RequestId} requestId
395 * @param {!NetworkAgent.Timestamp} time 396 * @param {!NetworkAgent.Timestamp} time
396 * @param {!NetworkAgent.WebSocketRequest} request 397 * @param {!NetworkAgent.WebSocketRequest} request
397 */ 398 */
398 webSocketWillSendHandshakeRequest: function(requestId, time, request) 399 webSocketWillSendHandshakeRequest: function(requestId, time, request)
399 { 400 {
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after
565 * @param {!NetworkAgent.LoaderId} loaderId 566 * @param {!NetworkAgent.LoaderId} loaderId
566 * @param {string} url 567 * @param {string} url
567 * @param {string} documentURL 568 * @param {string} documentURL
568 * @param {?NetworkAgent.Initiator} initiator 569 * @param {?NetworkAgent.Initiator} initiator
569 */ 570 */
570 _createNetworkRequest: function(requestId, frameId, loaderId, url, documentU RL, initiator) 571 _createNetworkRequest: function(requestId, frameId, loaderId, url, documentU RL, initiator)
571 { 572 {
572 return new WebInspector.NetworkRequest(this._manager._target, requestId, url, documentURL, frameId, loaderId, initiator); 573 return new WebInspector.NetworkRequest(this._manager._target, requestId, url, documentURL, frameId, loaderId, initiator);
573 } 574 }
574 } 575 }
OLDNEW
« no previous file with comments | « Source/devtools/front_end/resources/ResourcesPanel.js ('k') | Source/devtools/front_end/sdk/NetworkRequest.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698