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

Side by Side Diff: third_party/WebKit/Source/devtools/front_end/network/NetworkOverview.js

Issue 2493373002: DevTools: rename WebInspector into modules. (Closed)
Patch Set: for bots Created 4 years, 1 month 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 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 * @unrestricted 5 * @unrestricted
6 */ 6 */
7 WebInspector.NetworkOverview = class extends WebInspector.TimelineOverviewBase { 7 Network.NetworkOverview = class extends UI.TimelineOverviewBase {
8 constructor() { 8 constructor() {
9 super(); 9 super();
10 this.element.classList.add('network-overview'); 10 this.element.classList.add('network-overview');
11 11
12 /** @type {number} */ 12 /** @type {number} */
13 this._numBands = 1; 13 this._numBands = 1;
14 /** @type {number} */ 14 /** @type {number} */
15 this._windowStart = 0; 15 this._windowStart = 0;
16 /** @type {number} */ 16 /** @type {number} */
17 this._windowEnd = 0; 17 this._windowEnd = 0;
18 /** @type {boolean} */ 18 /** @type {boolean} */
19 this._restoringWindow = false; 19 this._restoringWindow = false;
20 /** @type {boolean} */ 20 /** @type {boolean} */
21 this._updateScheduled = false; 21 this._updateScheduled = false;
22 /** @type {number} */ 22 /** @type {number} */
23 this._canvasWidth = 0; 23 this._canvasWidth = 0;
24 /** @type {number} */ 24 /** @type {number} */
25 this._canvasHeight = 0; 25 this._canvasHeight = 0;
26 26
27 WebInspector.targetManager.addModelListener( 27 SDK.targetManager.addModelListener(
28 WebInspector.ResourceTreeModel, WebInspector.ResourceTreeModel.Events.Lo ad, this._loadEventFired, this); 28 SDK.ResourceTreeModel, SDK.ResourceTreeModel.Events.Load, this._loadEven tFired, this);
29 WebInspector.targetManager.addModelListener( 29 SDK.targetManager.addModelListener(
30 WebInspector.ResourceTreeModel, WebInspector.ResourceTreeModel.Events.DO MContentLoaded, 30 SDK.ResourceTreeModel, SDK.ResourceTreeModel.Events.DOMContentLoaded,
31 this._domContentLoadedEventFired, this); 31 this._domContentLoadedEventFired, this);
32 32
33 this.reset(); 33 this.reset();
34 } 34 }
35 35
36 /** 36 /**
37 * @param {?WebInspector.FilmStripModel} filmStripModel 37 * @param {?Components.FilmStripModel} filmStripModel
38 */ 38 */
39 setFilmStripModel(filmStripModel) { 39 setFilmStripModel(filmStripModel) {
40 this._filmStripModel = filmStripModel; 40 this._filmStripModel = filmStripModel;
41 this.scheduleUpdate(); 41 this.scheduleUpdate();
42 } 42 }
43 43
44 /** 44 /**
45 * @param {number} time 45 * @param {number} time
46 */ 46 */
47 selectFilmStripFrame(time) { 47 selectFilmStripFrame(time) {
48 this._selectedFilmStripTime = time; 48 this._selectedFilmStripTime = time;
49 this.scheduleUpdate(); 49 this.scheduleUpdate();
50 } 50 }
51 51
52 clearFilmStripFrame() { 52 clearFilmStripFrame() {
53 this._selectedFilmStripTime = -1; 53 this._selectedFilmStripTime = -1;
54 this.scheduleUpdate(); 54 this.scheduleUpdate();
55 } 55 }
56 56
57 /** 57 /**
58 * @param {!WebInspector.Event} event 58 * @param {!Common.Event} event
59 */ 59 */
60 _loadEventFired(event) { 60 _loadEventFired(event) {
61 var data = /** @type {number} */ (event.data); 61 var data = /** @type {number} */ (event.data);
62 if (data) 62 if (data)
63 this._loadEvents.push(data * 1000); 63 this._loadEvents.push(data * 1000);
64 this.scheduleUpdate(); 64 this.scheduleUpdate();
65 } 65 }
66 66
67 /** 67 /**
68 * @param {!WebInspector.Event} event 68 * @param {!Common.Event} event
69 */ 69 */
70 _domContentLoadedEventFired(event) { 70 _domContentLoadedEventFired(event) {
71 var data = /** @type {number} */ (event.data); 71 var data = /** @type {number} */ (event.data);
72 if (data) 72 if (data)
73 this._domContentLoadedEvents.push(data * 1000); 73 this._domContentLoadedEvents.push(data * 1000);
74 this.scheduleUpdate(); 74 this.scheduleUpdate();
75 } 75 }
76 76
77 /** 77 /**
78 * @param {string} connectionId 78 * @param {string} connectionId
79 * @return {number} 79 * @return {number}
80 */ 80 */
81 _bandId(connectionId) { 81 _bandId(connectionId) {
82 if (!connectionId || connectionId === '0') 82 if (!connectionId || connectionId === '0')
83 return -1; 83 return -1;
84 if (this._bandMap.has(connectionId)) 84 if (this._bandMap.has(connectionId))
85 return /** @type {number} */ (this._bandMap.get(connectionId)); 85 return /** @type {number} */ (this._bandMap.get(connectionId));
86 var result = this._nextBand++; 86 var result = this._nextBand++;
87 this._bandMap.set(connectionId, result); 87 this._bandMap.set(connectionId, result);
88 return result; 88 return result;
89 } 89 }
90 90
91 /** 91 /**
92 * @param {!WebInspector.NetworkRequest} request 92 * @param {!SDK.NetworkRequest} request
93 */ 93 */
94 updateRequest(request) { 94 updateRequest(request) {
95 if (!this._requestsSet.has(request)) { 95 if (!this._requestsSet.has(request)) {
96 this._requestsSet.add(request); 96 this._requestsSet.add(request);
97 this._requestsList.push(request); 97 this._requestsList.push(request);
98 } 98 }
99 this.scheduleUpdate(); 99 this.scheduleUpdate();
100 } 100 }
101 101
102 /** 102 /**
103 * @override 103 * @override
104 */ 104 */
105 wasShown() { 105 wasShown() {
106 this.onResize(); 106 this.onResize();
107 } 107 }
108 108
109 /** 109 /**
110 * @override 110 * @override
111 */ 111 */
112 onResize() { 112 onResize() {
113 var width = this.element.offsetWidth; 113 var width = this.element.offsetWidth;
114 var height = this.element.offsetHeight; 114 var height = this.element.offsetHeight;
115 this._calculator.setDisplayWindow(width); 115 this._calculator.setDisplayWindow(width);
116 this.resetCanvas(); 116 this.resetCanvas();
117 var numBands = (((height - 1) / WebInspector.NetworkOverview._bandHeight) - 1) | 0; 117 var numBands = (((height - 1) / Network.NetworkOverview._bandHeight) - 1) | 0;
118 this._numBands = (numBands > 0) ? numBands : 1; 118 this._numBands = (numBands > 0) ? numBands : 1;
119 this.scheduleUpdate(); 119 this.scheduleUpdate();
120 } 120 }
121 121
122 /** 122 /**
123 * @override 123 * @override
124 */ 124 */
125 reset() { 125 reset() {
126 this._windowStart = 0; 126 this._windowStart = 0;
127 this._windowEnd = 0; 127 this._windowEnd = 0;
128 /** @type {?WebInspector.FilmStripModel} */ 128 /** @type {?Components.FilmStripModel} */
129 this._filmStripModel = null; 129 this._filmStripModel = null;
130 130
131 /** @type {number} */ 131 /** @type {number} */
132 this._span = 1; 132 this._span = 1;
133 /** @type {?WebInspector.NetworkTimeBoundary} */ 133 /** @type {?Network.NetworkTimeBoundary} */
134 this._lastBoundary = null; 134 this._lastBoundary = null;
135 /** @type {number} */ 135 /** @type {number} */
136 this._nextBand = 0; 136 this._nextBand = 0;
137 /** @type {!Map.<string, number>} */ 137 /** @type {!Map.<string, number>} */
138 this._bandMap = new Map(); 138 this._bandMap = new Map();
139 /** @type {!Array.<!WebInspector.NetworkRequest>} */ 139 /** @type {!Array.<!SDK.NetworkRequest>} */
140 this._requestsList = []; 140 this._requestsList = [];
141 /** @type {!Set.<!WebInspector.NetworkRequest>} */ 141 /** @type {!Set.<!SDK.NetworkRequest>} */
142 this._requestsSet = new Set(); 142 this._requestsSet = new Set();
143 /** @type {!Array.<number>} */ 143 /** @type {!Array.<number>} */
144 this._loadEvents = []; 144 this._loadEvents = [];
145 /** @type {!Array.<number>} */ 145 /** @type {!Array.<number>} */
146 this._domContentLoadedEvents = []; 146 this._domContentLoadedEvents = [];
147 147
148 // Clear screen. 148 // Clear screen.
149 this.resetCanvas(); 149 this.resetCanvas();
150 } 150 }
151 151
152 /** 152 /**
153 * @protected 153 * @protected
154 */ 154 */
155 scheduleUpdate() { 155 scheduleUpdate() {
156 if (this._updateScheduled || !this.isShowing()) 156 if (this._updateScheduled || !this.isShowing())
157 return; 157 return;
158 this._updateScheduled = true; 158 this._updateScheduled = true;
159 this.element.window().requestAnimationFrame(this.update.bind(this)); 159 this.element.window().requestAnimationFrame(this.update.bind(this));
160 } 160 }
161 161
162 /** 162 /**
163 * @override 163 * @override
164 */ 164 */
165 update() { 165 update() {
166 this._updateScheduled = false; 166 this._updateScheduled = false;
167 167
168 var newBoundary = 168 var newBoundary =
169 new WebInspector.NetworkTimeBoundary(this._calculator.minimumBoundary(), this._calculator.maximumBoundary()); 169 new Network.NetworkTimeBoundary(this._calculator.minimumBoundary(), this ._calculator.maximumBoundary());
170 if (!this._lastBoundary || !newBoundary.equals(this._lastBoundary)) { 170 if (!this._lastBoundary || !newBoundary.equals(this._lastBoundary)) {
171 var span = this._calculator.boundarySpan(); 171 var span = this._calculator.boundarySpan();
172 while (this._span < span) 172 while (this._span < span)
173 this._span *= 1.25; 173 this._span *= 1.25;
174 this._calculator.setBounds(this._calculator.minimumBoundary(), this._calcu lator.minimumBoundary() + this._span); 174 this._calculator.setBounds(this._calculator.minimumBoundary(), this._calcu lator.minimumBoundary() + this._span);
175 this._lastBoundary = 175 this._lastBoundary =
176 new WebInspector.NetworkTimeBoundary(this._calculator.minimumBoundary( ), this._calculator.maximumBoundary()); 176 new Network.NetworkTimeBoundary(this._calculator.minimumBoundary(), th is._calculator.maximumBoundary());
177 if (this._windowStart || this._windowEnd) { 177 if (this._windowStart || this._windowEnd) {
178 this._restoringWindow = true; 178 this._restoringWindow = true;
179 var startTime = this._calculator.minimumBoundary(); 179 var startTime = this._calculator.minimumBoundary();
180 var totalTime = this._calculator.boundarySpan(); 180 var totalTime = this._calculator.boundarySpan();
181 var left = (this._windowStart - startTime) / totalTime; 181 var left = (this._windowStart - startTime) / totalTime;
182 var right = (this._windowEnd - startTime) / totalTime; 182 var right = (this._windowEnd - startTime) / totalTime;
183 this._restoringWindow = false; 183 this._restoringWindow = false;
184 } 184 }
185 } 185 }
186 186
187 var context = this._canvas.getContext('2d'); 187 var context = this._canvas.getContext('2d');
188 var calculator = this._calculator; 188 var calculator = this._calculator;
189 var linesByType = {}; 189 var linesByType = {};
190 var paddingTop = 2; 190 var paddingTop = 2;
191 191
192 /** 192 /**
193 * @param {string} type 193 * @param {string} type
194 * @param {string} strokeStyle 194 * @param {string} strokeStyle
195 */ 195 */
196 function drawLines(type, strokeStyle) { 196 function drawLines(type, strokeStyle) {
197 var lines = linesByType[type]; 197 var lines = linesByType[type];
198 if (!lines) 198 if (!lines)
199 return; 199 return;
200 var n = lines.length; 200 var n = lines.length;
201 context.beginPath(); 201 context.beginPath();
202 context.strokeStyle = strokeStyle; 202 context.strokeStyle = strokeStyle;
203 for (var i = 0; i < n;) { 203 for (var i = 0; i < n;) {
204 var y = lines[i++] * WebInspector.NetworkOverview._bandHeight + paddingT op; 204 var y = lines[i++] * Network.NetworkOverview._bandHeight + paddingTop;
205 var startTime = lines[i++]; 205 var startTime = lines[i++];
206 var endTime = lines[i++]; 206 var endTime = lines[i++];
207 if (endTime === Number.MAX_VALUE) 207 if (endTime === Number.MAX_VALUE)
208 endTime = calculator.maximumBoundary(); 208 endTime = calculator.maximumBoundary();
209 context.moveTo(calculator.computePosition(startTime), y); 209 context.moveTo(calculator.computePosition(startTime), y);
210 context.lineTo(calculator.computePosition(endTime) + 1, y); 210 context.lineTo(calculator.computePosition(endTime) + 1, y);
211 } 211 }
212 context.stroke(); 212 context.stroke();
213 } 213 }
214 214
(...skipping 12 matching lines...) Expand all
227 lines.push(y, start, end); 227 lines.push(y, start, end);
228 } 228 }
229 229
230 var requests = this._requestsList; 230 var requests = this._requestsList;
231 var n = requests.length; 231 var n = requests.length;
232 for (var i = 0; i < n; ++i) { 232 for (var i = 0; i < n; ++i) {
233 var request = requests[i]; 233 var request = requests[i];
234 var band = this._bandId(request.connectionId); 234 var band = this._bandId(request.connectionId);
235 var y = (band === -1) ? 0 : (band % this._numBands + 1); 235 var y = (band === -1) ? 0 : (band % this._numBands + 1);
236 var timeRanges = 236 var timeRanges =
237 WebInspector.RequestTimingView.calculateRequestTimeRanges(request, thi s._calculator.minimumBoundary()); 237 Network.RequestTimingView.calculateRequestTimeRanges(request, this._ca lculator.minimumBoundary());
238 for (var j = 0; j < timeRanges.length; ++j) { 238 for (var j = 0; j < timeRanges.length; ++j) {
239 var type = timeRanges[j].name; 239 var type = timeRanges[j].name;
240 if (band !== -1 || type === WebInspector.RequestTimeRangeNames.Total) 240 if (band !== -1 || type === Network.RequestTimeRangeNames.Total)
241 addLine(type, y, timeRanges[j].start * 1000, timeRanges[j].end * 1000) ; 241 addLine(type, y, timeRanges[j].start * 1000, timeRanges[j].end * 1000) ;
242 } 242 }
243 } 243 }
244 244
245 context.clearRect(0, 0, this._canvas.width, this._canvas.height); 245 context.clearRect(0, 0, this._canvas.width, this._canvas.height);
246 context.save(); 246 context.save();
247 context.scale(window.devicePixelRatio, window.devicePixelRatio); 247 context.scale(window.devicePixelRatio, window.devicePixelRatio);
248 context.lineWidth = 2; 248 context.lineWidth = 2;
249 drawLines(WebInspector.RequestTimeRangeNames.Total, '#CCCCCC'); 249 drawLines(Network.RequestTimeRangeNames.Total, '#CCCCCC');
250 drawLines(WebInspector.RequestTimeRangeNames.Blocking, '#AAAAAA'); 250 drawLines(Network.RequestTimeRangeNames.Blocking, '#AAAAAA');
251 drawLines(WebInspector.RequestTimeRangeNames.Connecting, '#FF9800'); 251 drawLines(Network.RequestTimeRangeNames.Connecting, '#FF9800');
252 drawLines(WebInspector.RequestTimeRangeNames.ServiceWorker, '#FF9800'); 252 drawLines(Network.RequestTimeRangeNames.ServiceWorker, '#FF9800');
253 drawLines(WebInspector.RequestTimeRangeNames.ServiceWorkerPreparation, '#FF9 800'); 253 drawLines(Network.RequestTimeRangeNames.ServiceWorkerPreparation, '#FF9800') ;
254 drawLines(WebInspector.RequestTimeRangeNames.Push, '#8CDBff'); 254 drawLines(Network.RequestTimeRangeNames.Push, '#8CDBff');
255 drawLines(WebInspector.RequestTimeRangeNames.Proxy, '#A1887F'); 255 drawLines(Network.RequestTimeRangeNames.Proxy, '#A1887F');
256 drawLines(WebInspector.RequestTimeRangeNames.DNS, '#009688'); 256 drawLines(Network.RequestTimeRangeNames.DNS, '#009688');
257 drawLines(WebInspector.RequestTimeRangeNames.SSL, '#9C27B0'); 257 drawLines(Network.RequestTimeRangeNames.SSL, '#9C27B0');
258 drawLines(WebInspector.RequestTimeRangeNames.Sending, '#B0BEC5'); 258 drawLines(Network.RequestTimeRangeNames.Sending, '#B0BEC5');
259 drawLines(WebInspector.RequestTimeRangeNames.Waiting, '#00C853'); 259 drawLines(Network.RequestTimeRangeNames.Waiting, '#00C853');
260 drawLines(WebInspector.RequestTimeRangeNames.Receiving, '#03A9F4'); 260 drawLines(Network.RequestTimeRangeNames.Receiving, '#03A9F4');
261 261
262 var height = this.element.offsetHeight; 262 var height = this.element.offsetHeight;
263 context.lineWidth = 1; 263 context.lineWidth = 1;
264 context.beginPath(); 264 context.beginPath();
265 context.strokeStyle = '#8080FF'; // Keep in sync with .network-blue-divider CSS rule. 265 context.strokeStyle = '#8080FF'; // Keep in sync with .network-blue-divider CSS rule.
266 for (var i = this._domContentLoadedEvents.length - 1; i >= 0; --i) { 266 for (var i = this._domContentLoadedEvents.length - 1; i >= 0; --i) {
267 var x = Math.round(calculator.computePosition(this._domContentLoadedEvents [i])) + 0.5; 267 var x = Math.round(calculator.computePosition(this._domContentLoadedEvents [i])) + 0.5;
268 context.moveTo(x, 0); 268 context.moveTo(x, 0);
269 context.lineTo(x, height); 269 context.lineTo(x, height);
270 } 270 }
(...skipping 15 matching lines...) Expand all
286 var x = Math.round(calculator.computePosition(this._selectedFilmStripTime) ); 286 var x = Math.round(calculator.computePosition(this._selectedFilmStripTime) );
287 context.moveTo(x, 0); 287 context.moveTo(x, 0);
288 context.lineTo(x, height); 288 context.lineTo(x, height);
289 context.stroke(); 289 context.stroke();
290 } 290 }
291 context.restore(); 291 context.restore();
292 } 292 }
293 }; 293 };
294 294
295 /** @type {number} */ 295 /** @type {number} */
296 WebInspector.NetworkOverview._bandHeight = 3; 296 Network.NetworkOverview._bandHeight = 3;
297 297
298 /** @typedef {{start: number, end: number}} */ 298 /** @typedef {{start: number, end: number}} */
299 WebInspector.NetworkOverview.Window; 299 Network.NetworkOverview.Window;
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698