OLD | NEW |
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 |
11 * copyright notice, this list of conditions and the following disclaimer | 11 * copyright notice, this list of conditions and the following disclaimer |
12 * in the documentation and/or other materials provided with the | 12 * in the documentation and/or other materials provided with the |
13 * distribution. | 13 * distribution. |
14 * * Neither the name of Google Inc. nor the names of its | 14 * * Neither the name of Google Inc. nor the names of its |
15 * contributors may be used to endorse or promote products derived from | 15 * contributors may be used to endorse or promote products derived from |
16 * this software without specific prior written permission. | 16 * this software without specific prior written permission. |
17 * | 17 * |
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | 18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | 19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | 20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | 21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | 22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | 23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
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 | |
31 /** | 30 /** |
32 * @constructor | 31 * @unrestricted |
33 * @extends {WebInspector.SDKModel} | |
34 * @param {!WebInspector.Target} target | |
35 * @param {!WebInspector.ResourceTreeModel} resourceTreeModel | |
36 * @param {!WebInspector.NetworkManager} networkManager | |
37 */ | 32 */ |
38 WebInspector.NetworkLog = function(target, resourceTreeModel, networkManager) | 33 WebInspector.NetworkLog = class extends WebInspector.SDKModel { |
39 { | 34 /** |
40 WebInspector.SDKModel.call(this, WebInspector.NetworkLog, target); | 35 * @param {!WebInspector.Target} target |
| 36 * @param {!WebInspector.ResourceTreeModel} resourceTreeModel |
| 37 * @param {!WebInspector.NetworkManager} networkManager |
| 38 */ |
| 39 constructor(target, resourceTreeModel, networkManager) { |
| 40 super(WebInspector.NetworkLog, target); |
41 | 41 |
42 this._requests = []; | 42 this._requests = []; |
43 this._requestForId = {}; | 43 this._requestForId = {}; |
44 networkManager.addEventListener(WebInspector.NetworkManager.Events.RequestSt
arted, this._onRequestStarted, this); | 44 networkManager.addEventListener(WebInspector.NetworkManager.Events.RequestSt
arted, this._onRequestStarted, this); |
45 resourceTreeModel.addEventListener(WebInspector.ResourceTreeModel.Events.Mai
nFrameNavigated, this._onMainFrameNavigated, this); | 45 resourceTreeModel.addEventListener( |
| 46 WebInspector.ResourceTreeModel.Events.MainFrameNavigated, this._onMainFr
ameNavigated, this); |
46 resourceTreeModel.addEventListener(WebInspector.ResourceTreeModel.Events.Loa
d, this._onLoad, this); | 47 resourceTreeModel.addEventListener(WebInspector.ResourceTreeModel.Events.Loa
d, this._onLoad, this); |
47 resourceTreeModel.addEventListener(WebInspector.ResourceTreeModel.Events.DOM
ContentLoaded, this._onDOMContentLoaded, this); | 48 resourceTreeModel.addEventListener( |
48 }; | 49 WebInspector.ResourceTreeModel.Events.DOMContentLoaded, this._onDOMConte
ntLoaded, this); |
| 50 } |
49 | 51 |
50 /** | 52 /** |
51 * @param {!WebInspector.Target} target | 53 * @param {!WebInspector.Target} target |
52 * @return {?WebInspector.NetworkLog} | 54 * @return {?WebInspector.NetworkLog} |
53 */ | 55 */ |
54 WebInspector.NetworkLog.fromTarget = function(target) | 56 static fromTarget(target) { |
55 { | |
56 return /** @type {?WebInspector.NetworkLog} */ (target.model(WebInspector.Ne
tworkLog)); | 57 return /** @type {?WebInspector.NetworkLog} */ (target.model(WebInspector.Ne
tworkLog)); |
57 }; | 58 } |
58 | 59 |
59 /** | 60 /** |
60 * @param {string} url | 61 * @param {string} url |
61 * @return {?WebInspector.NetworkRequest} | 62 * @return {?WebInspector.NetworkRequest} |
62 */ | 63 */ |
63 WebInspector.NetworkLog.requestForURL = function(url) | 64 static requestForURL(url) { |
64 { | |
65 for (var target of WebInspector.targetManager.targets()) { | 65 for (var target of WebInspector.targetManager.targets()) { |
66 var networkLog = WebInspector.NetworkLog.fromTarget(target); | 66 var networkLog = WebInspector.NetworkLog.fromTarget(target); |
67 var result = networkLog && networkLog.requestForURL(url); | 67 var result = networkLog && networkLog.requestForURL(url); |
68 if (result) | 68 if (result) |
69 return result; | 69 return result; |
70 } | 70 } |
71 return null; | 71 return null; |
72 }; | 72 } |
73 | 73 |
74 /** | 74 /** |
75 * @return {!Array.<!WebInspector.NetworkRequest>} | 75 * @return {!Array.<!WebInspector.NetworkRequest>} |
76 */ | 76 */ |
77 WebInspector.NetworkLog.requests = function() | 77 static requests() { |
78 { | |
79 var result = []; | 78 var result = []; |
80 for (var target of WebInspector.targetManager.targets()) { | 79 for (var target of WebInspector.targetManager.targets()) { |
81 var networkLog = WebInspector.NetworkLog.fromTarget(target); | 80 var networkLog = WebInspector.NetworkLog.fromTarget(target); |
82 if (networkLog) | 81 if (networkLog) |
83 result = result.concat(networkLog.requests()); | 82 result = result.concat(networkLog.requests()); |
84 } | 83 } |
85 return result; | 84 return result; |
86 }; | 85 } |
87 | 86 |
88 WebInspector.NetworkLog.prototype = { | 87 /** |
89 /** | 88 * @return {!Array.<!WebInspector.NetworkRequest>} |
90 * @return {!Array.<!WebInspector.NetworkRequest>} | 89 */ |
91 */ | 90 requests() { |
92 requests: function() | 91 return this._requests; |
93 { | 92 } |
94 return this._requests; | |
95 }, | |
96 | 93 |
97 /** | 94 /** |
98 * @param {string} url | 95 * @param {string} url |
99 * @return {?WebInspector.NetworkRequest} | 96 * @return {?WebInspector.NetworkRequest} |
100 */ | 97 */ |
101 requestForURL: function(url) | 98 requestForURL(url) { |
102 { | 99 for (var i = 0; i < this._requests.length; ++i) { |
103 for (var i = 0; i < this._requests.length; ++i) { | 100 if (this._requests[i].url === url) |
104 if (this._requests[i].url === url) | 101 return this._requests[i]; |
105 return this._requests[i]; | 102 } |
106 } | 103 return null; |
107 return null; | 104 } |
108 }, | |
109 | 105 |
110 /** | 106 /** |
111 * @param {!WebInspector.NetworkRequest} request | 107 * @param {!WebInspector.NetworkRequest} request |
112 * @return {!WebInspector.PageLoad} | 108 * @return {!WebInspector.PageLoad} |
113 */ | 109 */ |
114 pageLoadForRequest: function(request) | 110 pageLoadForRequest(request) { |
115 { | 111 return request.__page; |
116 return request.__page; | 112 } |
117 }, | |
118 | 113 |
119 /** | 114 /** |
120 * @param {!WebInspector.Event} event | 115 * @param {!WebInspector.Event} event |
121 */ | 116 */ |
122 _onMainFrameNavigated: function(event) | 117 _onMainFrameNavigated(event) { |
123 { | 118 var mainFrame = /** type {WebInspector.ResourceTreeFrame} */ event.data; |
124 var mainFrame = /** type {WebInspector.ResourceTreeFrame} */ event.data; | 119 // Preserve requests from the new session. |
125 // Preserve requests from the new session. | 120 this._currentPageLoad = null; |
126 this._currentPageLoad = null; | 121 var oldRequests = this._requests.splice(0, this._requests.length); |
127 var oldRequests = this._requests.splice(0, this._requests.length); | 122 this._requestForId = {}; |
128 this._requestForId = {}; | 123 for (var i = 0; i < oldRequests.length; ++i) { |
129 for (var i = 0; i < oldRequests.length; ++i) { | 124 var request = oldRequests[i]; |
130 var request = oldRequests[i]; | 125 if (request.loaderId === mainFrame.loaderId) { |
131 if (request.loaderId === mainFrame.loaderId) { | 126 if (!this._currentPageLoad) |
132 if (!this._currentPageLoad) | 127 this._currentPageLoad = new WebInspector.PageLoad(request); |
133 this._currentPageLoad = new WebInspector.PageLoad(request); | |
134 this._requests.push(request); | |
135 this._requestForId[request.requestId] = request; | |
136 request.__page = this._currentPageLoad; | |
137 } | |
138 } | |
139 }, | |
140 | |
141 /** | |
142 * @param {!WebInspector.Event} event | |
143 */ | |
144 _onRequestStarted: function(event) | |
145 { | |
146 var request = /** @type {!WebInspector.NetworkRequest} */ (event.data); | |
147 this._requests.push(request); | 128 this._requests.push(request); |
148 this._requestForId[request.requestId] = request; | 129 this._requestForId[request.requestId] = request; |
149 request.__page = this._currentPageLoad; | 130 request.__page = this._currentPageLoad; |
150 }, | 131 } |
| 132 } |
| 133 } |
151 | 134 |
152 /** | 135 /** |
153 * @param {!WebInspector.Event} event | 136 * @param {!WebInspector.Event} event |
154 */ | 137 */ |
155 _onDOMContentLoaded: function(event) | 138 _onRequestStarted(event) { |
156 { | 139 var request = /** @type {!WebInspector.NetworkRequest} */ (event.data); |
157 if (this._currentPageLoad) | 140 this._requests.push(request); |
158 this._currentPageLoad.contentLoadTime = event.data; | 141 this._requestForId[request.requestId] = request; |
159 }, | 142 request.__page = this._currentPageLoad; |
| 143 } |
160 | 144 |
161 /** | 145 /** |
162 * @param {!WebInspector.Event} event | 146 * @param {!WebInspector.Event} event |
163 */ | 147 */ |
164 _onLoad: function(event) | 148 _onDOMContentLoaded(event) { |
165 { | 149 if (this._currentPageLoad) |
166 if (this._currentPageLoad) | 150 this._currentPageLoad.contentLoadTime = event.data; |
167 this._currentPageLoad.loadTime = event.data; | 151 } |
168 }, | |
169 | 152 |
170 /** | 153 /** |
171 * @param {!NetworkAgent.RequestId} requestId | 154 * @param {!WebInspector.Event} event |
172 * @return {?WebInspector.NetworkRequest} | 155 */ |
173 */ | 156 _onLoad(event) { |
174 requestForId: function(requestId) | 157 if (this._currentPageLoad) |
175 { | 158 this._currentPageLoad.loadTime = event.data; |
176 return this._requestForId[requestId]; | 159 } |
177 }, | |
178 | 160 |
179 __proto__: WebInspector.SDKModel.prototype | 161 /** |
| 162 * @param {!NetworkAgent.RequestId} requestId |
| 163 * @return {?WebInspector.NetworkRequest} |
| 164 */ |
| 165 requestForId(requestId) { |
| 166 return this._requestForId[requestId]; |
| 167 } |
180 }; | 168 }; |
181 | 169 |
| 170 |
182 /** | 171 /** |
183 * @constructor | 172 * @unrestricted |
184 * @param {!WebInspector.NetworkRequest} mainRequest | |
185 */ | 173 */ |
186 WebInspector.PageLoad = function(mainRequest) | 174 WebInspector.PageLoad = class { |
187 { | 175 /** |
| 176 * @param {!WebInspector.NetworkRequest} mainRequest |
| 177 */ |
| 178 constructor(mainRequest) { |
188 this.id = ++WebInspector.PageLoad._lastIdentifier; | 179 this.id = ++WebInspector.PageLoad._lastIdentifier; |
189 this.url = mainRequest.url; | 180 this.url = mainRequest.url; |
190 this.startTime = mainRequest.startTime; | 181 this.startTime = mainRequest.startTime; |
| 182 } |
191 }; | 183 }; |
192 | 184 |
193 WebInspector.PageLoad._lastIdentifier = 0; | 185 WebInspector.PageLoad._lastIdentifier = 0; |
OLD | NEW |