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

Side by Side Diff: webkit/glue/devtools/js/net_agent.js

Issue 56149: DevTools: add support for main resource load tracking. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 8 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 /** 5 /**
6 * @fileoverview 'Net' manages resources along with the corresponding 6 * @fileoverview 'Net' manages resources along with the corresponding
7 * HTTP requests and responses. 7 * HTTP requests and responses.
8 * web inspector. 8 * web inspector.
9 */ 9 */
10 goog.provide('devtools.NetAgent'); 10 goog.provide('devtools.NetAgent');
11 11
12 devtools.NetAgent = function() { 12 devtools.NetAgent = function() {
13 this.resources_ = {}; 13 this.resources_ = {};
14 this.id_for_url_ = {}; 14 this.id_for_url_ = {};
15 15
16 RemoteNetAgent.GetResourceContentResult = 16 RemoteNetAgent.GetResourceContentResult =
17 devtools.Callback.processCallback; 17 devtools.Callback.processCallback;
18 RemoteNetAgent.WillSendRequest = 18 RemoteNetAgent.WillSendRequest =
19 goog.bind(this.willSendRequest, this); 19 goog.bind(this.willSendRequest, this);
20 RemoteNetAgent.DidReceiveResponse = 20 RemoteNetAgent.DidReceiveResponse =
21 goog.bind(this.didReceiveResponse, this); 21 goog.bind(this.didReceiveResponse, this);
22 RemoteNetAgent.DidFinishLoading = 22 RemoteNetAgent.DidFinishLoading =
23 goog.bind(this.didFinishLoading, this); 23 goog.bind(this.didFinishLoading, this);
24 RemoteNetAgent.DidFailLoading = 24 RemoteNetAgent.DidFailLoading =
25 goog.bind(this.didFailLoading, this); 25 goog.bind(this.didFailLoading, this);
26 }; 26 };
27 27
28 28
29 /** 29 /**
30 * Resets dom agent to its initial state.
31 */
32 devtools.NetAgent.prototype.reset = function() {
33 this.resources_ = {};
34 this.id_for_url_ = {};
35 };
36
37
38 /**
30 * Returns resource object for given identifier. 39 * Returns resource object for given identifier.
31 * @param {number} identifier Identifier to get resource for. 40 * @param {number} identifier Identifier to get resource for.
32 * @return {WebInspector.Resouce} Resulting resource. 41 * @return {WebInspector.Resouce} Resulting resource.
33 */ 42 */
34 devtools.NetAgent.prototype.getResource = function(identifier) { 43 devtools.NetAgent.prototype.getResource = function(identifier) {
35 return this.resources_[identifier]; 44 return this.resources_[identifier];
36 }; 45 };
37 46
38 47
39 /** 48 /**
(...skipping 16 matching lines...) Expand all
56 RemoteNetAgent.GetResourceContent( 65 RemoteNetAgent.GetResourceContent(
57 devtools.Callback.wrap(mycallback), identifier, resource.url); 66 devtools.Callback.wrap(mycallback), identifier, resource.url);
58 }; 67 };
59 68
60 69
61 /** 70 /**
62 * @see NetAgentDelegate. 71 * @see NetAgentDelegate.
63 * {@inheritDoc}. 72 * {@inheritDoc}.
64 */ 73 */
65 devtools.NetAgent.prototype.willSendRequest = function(identifier, request) { 74 devtools.NetAgent.prototype.willSendRequest = function(identifier, request) {
75 // Resource object is already created.
76 var resource = this.resources_[identifier];
77 if (resource) {
78 return;
79 }
80
66 var mainResource = false; 81 var mainResource = false;
67 var cached = false; 82 var cached = false;
68 var resource = new WebInspector.Resource(request.requestHeaders, 83 var resource = new WebInspector.Resource(request.requestHeaders,
69 request.url, request.domain, request.path, request.lastPathComponent, 84 request.url, request.domain, request.path, request.lastPathComponent,
70 identifier, mainResource, cached); 85 identifier, mainResource, cached);
71 resource.startTime = request.startTime; 86 resource.startTime = request.startTime;
72 WebInspector.addResource(resource); 87 WebInspector.addResource(resource);
73 this.resources_[identifier] = resource; 88 this.resources_[identifier] = resource;
74 this.id_for_url_[request.url] = identifier; 89 this.id_for_url_[request.url] = identifier;
75 }; 90 };
76 91
77 92
78 /** 93 /**
79 * @see NetAgentDelegate. 94 * @see NetAgentDelegate.
80 * {@inheritDoc}. 95 * {@inheritDoc}.
81 */ 96 */
82 devtools.NetAgent.prototype.didReceiveResponse = function(identifier, response) { 97 devtools.NetAgent.prototype.didReceiveResponse = function(identifier, response) {
83 var resource = this.resources_[identifier]; 98 var resource = this.resources_[identifier];
84 if (!resource) { 99 if (!resource) {
85 return; 100 return;
86 } 101 }
102
87 resource.expectedContentLength = response.expectedContentLength; 103 resource.expectedContentLength = response.expectedContentLength;
88 resource.responseStatusCode = response.responseStatusCode; 104 resource.responseStatusCode = response.responseStatusCode;
89 resource.mimeType = response.mimeType; 105 resource.mimeType = response.mimeType;
90 resource.suggestedFilename = response.suggestedFilename; 106 resource.suggestedFilename = response.suggestedFilename;
91 var mimeType = response.mimeType; 107 var mimeType = response.mimeType;
92 if (mimeType.indexOf("image/") == 0) { 108 if (mimeType.indexOf("image/") == 0) {
93 resource.type = WebInspector.Resource.Type.Image; 109 resource.type = WebInspector.Resource.Type.Image;
94 } else if (mimeType.indexOf("text/html") == 0) { 110 } else if (mimeType.indexOf("text/html") == 0) {
95 resource.type = WebInspector.Resource.Type.Document; 111 resource.type = WebInspector.Resource.Type.Document;
96 } else if (mimeType.indexOf("script") != -1 || 112 } else if (mimeType.indexOf("script") != -1 ||
97 response.url.indexOf(".js") != -1) { 113 response.url.indexOf(".js") != -1) {
98 resource.type = WebInspector.Resource.Type.Script; 114 resource.type = WebInspector.Resource.Type.Script;
99 } else { 115 } else {
100 resource.type = WebInspector.Resource.Type.Other; 116 resource.type = WebInspector.Resource.Type.Other;
101 } 117 }
102 resource.responseReceivedTime = response.responseReceivedTime; 118 resource.responseReceivedTime = response.responseReceivedTime;
103 }; 119 };
104 120
105 121
106 /** 122 /**
107 * @see NetAgentDelegate. 123 * @see NetAgentDelegate.
108 * {@inheritDoc}. 124 * {@inheritDoc}.
109 */ 125 */
110 devtools.NetAgent.prototype.didFinishLoading = function(identifier, value) { 126 devtools.NetAgent.prototype.didFinishLoading = function(identifier, value) {
127 // When loading main resource we are only getting the didFinishLoading
128 // that is happening after the reset. Replay previous commands here.
129 this.willSendRequest(identifier, value);
130 this.didReceiveResponse(identifier, value);
131
111 var resource = this.resources_[identifier]; 132 var resource = this.resources_[identifier];
112 if (!resource) { 133 if (!resource) {
113 return; 134 return;
114 } 135 }
115 resource.endTime = value.endTime; 136 resource.endTime = value.endTime;
116 resource.finished = true; 137 resource.finished = true;
117 resource.failed = false; 138 resource.failed = false;
118 }; 139 };
119 140
120 141
121 /** 142 /**
122 * @see NetAgentDelegate. 143 * @see NetAgentDelegate.
123 * {@inheritDoc}. 144 * {@inheritDoc}.
124 */ 145 */
125 devtools.NetAgent.prototype.didFailLoading = function(identifier, value) { 146 devtools.NetAgent.prototype.didFailLoading = function(identifier, value) {
126 var resource = this.resources_[identifier]; 147 var resource = this.resources_[identifier];
127 if (!resource) { 148 if (!resource) {
128 return; 149 return;
129 } 150 }
130 resource.endTime = value.endTime; 151 resource.endTime = value.endTime;
131 resource.finished = false; 152 resource.finished = false;
132 resource.failed = true; 153 resource.failed = true;
133 }; 154 };
OLDNEW
« no previous file with comments | « webkit/glue/devtools/js/inspector_controller_impl.js ('k') | webkit/glue/devtools/net_agent_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698