| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 /** | |
| 6 * @fileoverview 'Net' manages resources along with the corresponding | |
| 7 * HTTP requests and responses. | |
| 8 * web inspector. | |
| 9 */ | |
| 10 goog.provide('devtools.NetAgent'); | |
| 11 | |
| 12 devtools.NetAgent = function() { | |
| 13 this.id_for_url_ = {}; | |
| 14 | |
| 15 RemoteNetAgent.GetResourceContentResult = | |
| 16 devtools.Callback.processCallback; | |
| 17 RemoteNetAgent.WillSendRequest = | |
| 18 goog.bind(this.willSendRequest, this); | |
| 19 RemoteNetAgent.DidReceiveResponse = | |
| 20 goog.bind(this.didReceiveResponse, this); | |
| 21 RemoteNetAgent.DidFinishLoading = | |
| 22 goog.bind(this.didFinishLoading, this); | |
| 23 }; | |
| 24 | |
| 25 | |
| 26 /** | |
| 27 * Resets dom agent to its initial state. | |
| 28 */ | |
| 29 devtools.NetAgent.prototype.reset = function() { | |
| 30 this.id_for_url_ = {}; | |
| 31 }; | |
| 32 | |
| 33 | |
| 34 /** | |
| 35 * Asynchronously queries for the resource content. | |
| 36 * @param {number} identifier Resource identifier. | |
| 37 * @param {function(string):undefined} opt_callback Callback to call when | |
| 38 * result is available. | |
| 39 */ | |
| 40 devtools.NetAgent.prototype.getResourceContentAsync = function(identifier, | |
| 41 opt_callback) { | |
| 42 var resource = WebInspector.resources[identifier]; | |
| 43 if (!resource) { | |
| 44 return; | |
| 45 } | |
| 46 var mycallback = function(content) { | |
| 47 if (opt_callback) { | |
| 48 opt_callback(content); | |
| 49 } | |
| 50 }; | |
| 51 RemoteNetAgent.GetResourceContent( | |
| 52 devtools.Callback.wrap(mycallback), identifier, resource.url); | |
| 53 }; | |
| 54 | |
| 55 | |
| 56 /** | |
| 57 * @see NetAgentDelegate. | |
| 58 * {@inheritDoc}. | |
| 59 */ | |
| 60 devtools.NetAgent.prototype.willSendRequest = function(identifier, request) { | |
| 61 // Resource object is already created. | |
| 62 var resource = WebInspector.resources[identifier]; | |
| 63 if (resource) { | |
| 64 return; | |
| 65 } | |
| 66 | |
| 67 WebInspector.addResource(identifier, request); | |
| 68 var resource = WebInspector.resources[identifier]; | |
| 69 resource.startTime = request.startTime; | |
| 70 this.id_for_url_[resource.url] = identifier; | |
| 71 }; | |
| 72 | |
| 73 | |
| 74 /** | |
| 75 * @see NetAgentDelegate. | |
| 76 * {@inheritDoc}. | |
| 77 */ | |
| 78 devtools.NetAgent.prototype.didReceiveResponse = function(identifier, response)
{ | |
| 79 var resource = WebInspector.resources[identifier]; | |
| 80 if (!resource) { | |
| 81 return; | |
| 82 } | |
| 83 | |
| 84 resource.expectedContentLength = response.expectedContentLength; | |
| 85 resource.responseStatusCode = response.responseStatusCode; | |
| 86 resource.responseHeaders = response.responseHeaders; | |
| 87 resource.mimeType = response.mimeType; | |
| 88 resource.suggestedFilename = response.suggestedFilename; | |
| 89 var mimeType = response.mimeType; | |
| 90 if (mimeType.indexOf('image/') == 0) { | |
| 91 resource.type = WebInspector.Resource.Type.Image; | |
| 92 } else if (mimeType.indexOf('text/html') == 0) { | |
| 93 resource.type = WebInspector.Resource.Type.Document; | |
| 94 } else if (mimeType.indexOf('script') != -1 || | |
| 95 resource.url.indexOf('.js') == resource.url.length - 3) { | |
| 96 resource.type = WebInspector.Resource.Type.Script; | |
| 97 } else if (mimeType.indexOf('text/css') == 0) { | |
| 98 resource.type = WebInspector.Resource.Type.Stylesheet; | |
| 99 } else { | |
| 100 resource.type = WebInspector.Resource.Type.Other; | |
| 101 } | |
| 102 resource.responseReceivedTime = response.responseReceivedTime; | |
| 103 }; | |
| 104 | |
| 105 | |
| 106 /** | |
| 107 * @see NetAgentDelegate. | |
| 108 * {@inheritDoc}. | |
| 109 */ | |
| 110 devtools.NetAgent.prototype.didFinishLoading = function(identifier, value) { | |
| 111 // When loading main resource we are only getting the didFinishLoading | |
| 112 // that is happening after the reset. Replay previous commands here. | |
| 113 this.willSendRequest(identifier, value); | |
| 114 this.didReceiveResponse(identifier, value); | |
| 115 | |
| 116 var resource = WebInspector.resources[identifier]; | |
| 117 if (!resource) { | |
| 118 return; | |
| 119 } | |
| 120 resource.endTime = value.endTime; | |
| 121 resource.finished = true; | |
| 122 resource.failed = !!value.errorCode; | |
| 123 if (resource.mainResource) { | |
| 124 document.title = 'Developer Tools - ' + resource.url; | |
| 125 } | |
| 126 }; | |
| OLD | NEW |