OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2016 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 * @constructor | |
7 * @param {!WebInspector.NetworkLogView} networkLogView | |
8 * @param {!WebInspector.Setting} networkLogLargeRowsSetting | |
9 */ | |
10 WebInspector.NetworkLogViewColumns = function(networkLogView, networkLogLargeRow sSetting) | |
11 { | |
12 this._networkLogView = networkLogView; | |
13 | |
14 var defaultColumnsVisibility = WebInspector.NetworkLogViewColumns._defaultCo lumnsVisibility; | |
15 /** @type {!WebInspector.Setting} */ | |
16 this._columnsVisibilitySetting = WebInspector.settings.createSetting("networ kLogColumnsVisibility", defaultColumnsVisibility); | |
17 var savedColumnsVisibility = this._columnsVisibilitySetting.get(); | |
18 /** @type {!Object.<boolean>} */ | |
19 var columnsVisibility = {}; | |
20 for (var columnId in defaultColumnsVisibility) | |
21 columnsVisibility[columnId] = savedColumnsVisibility.hasOwnProperty(colu mnId) ? savedColumnsVisibility[columnId] : defaultColumnsVisibility[columnId]; | |
22 this._columnsVisibilitySetting.set(columnsVisibility); | |
23 | |
24 networkLogLargeRowsSetting.addChangeListener(this._updateRowsSize, this); | |
25 | |
26 /** @type {!Array<{time: number, element: !Element}>} */ | |
27 this._eventDividers = []; | |
28 | |
29 this._gridMode = true; | |
30 | |
31 /** @type {?WebInspector.DataGrid} */ | |
32 this._dataGrid = null; | |
33 /** @type {!Array.<!WebInspector.ColumnConfig>} */ | |
34 this._columns = []; | |
35 /** @type {!Object.<string, function(!WebInspector.NetworkDataGridNode, !Web Inspector.NetworkDataGridNode) : number>} */ | |
36 this._sortingFunctions = {}; | |
37 /** @type {!Object.<string, !WebInspector.NetworkTimeCalculator>} */ | |
38 this._calculators = {}; | |
39 /** @type {?Element} */ | |
40 this._timelineSortSelector = null; | |
41 | |
42 /** @type {?WebInspector.TimelineGrid} */ | |
43 this._timelineGrid = null; | |
44 | |
45 /** @type {!WebInspector.Linkifier} */ | |
46 this._popupLinkifier = new WebInspector.Linkifier(); | |
47 } | |
48 | |
49 WebInspector.NetworkLogViewColumns._responseHeaderColumns = ["Cache-Control", "C onnection", "Content-Encoding", "Content-Length", "ETag", "Keep-Alive", "Last-Mo dified", "Server", "Vary"]; | |
50 WebInspector.NetworkLogViewColumns._defaultColumnsVisibility = { | |
51 method: false, status: true, protocol: false, scheme: false, domain: false, remoteAddress: false, type: true, initiator: true, cookies: false, setCookies: f alse, size: true, time: true, priority: false, connectionId: false, | |
52 "Cache-Control": false, "Connection": false, "Content-Encoding": false, "Con tent-Length": false, "ETag": false, "Keep-Alive": false, "Last-Modified": false, "Server": false, "Vary": false | |
53 }; | |
54 | |
55 /** | |
56 * @typedef {{ | |
57 * id: string, | |
58 * title: string, | |
59 * titleDOMFragment: !DocumentFragment, | |
60 * sortable: boolean, | |
61 * weight: number, | |
62 * sort: (?WebInspector.DataGrid.Order|undefined), | |
63 * align: (?WebInspector.DataGrid.Align|undefined), | |
64 * }} | |
65 */ | |
66 WebInspector.ColumnConfig; | |
67 | |
68 /** @type {!Object.<string, string>} */ | |
69 WebInspector.NetworkLogViewColumns._columnTitles = { | |
70 "name": WebInspector.UIString("Name"), | |
71 "method": WebInspector.UIString("Method"), | |
72 "status": WebInspector.UIString("Status"), | |
73 "protocol": WebInspector.UIString("Protocol"), | |
74 "scheme": WebInspector.UIString("Scheme"), | |
75 "domain": WebInspector.UIString("Domain"), | |
76 "remoteAddress": WebInspector.UIString("Remote Address"), | |
77 "type": WebInspector.UIString("Type"), | |
78 "initiator": WebInspector.UIString("Initiator"), | |
79 "cookies": WebInspector.UIString("Cookies"), | |
80 "setCookies": WebInspector.UIString("Set-Cookies"), | |
81 "size": WebInspector.UIString("Size"), | |
82 "time": WebInspector.UIString("Time"), | |
83 "connectionId": WebInspector.UIString("Connection Id"), | |
84 "priority": WebInspector.UIString("Priority"), | |
85 "timeline": WebInspector.UIString("Timeline"), | |
86 | |
87 // Response header columns | |
88 "Cache-Control": WebInspector.UIString("Cache-Control"), | |
89 "Connection": WebInspector.UIString("Connection"), | |
90 "Content-Encoding": WebInspector.UIString("Content-Encoding"), | |
91 "Content-Length": WebInspector.UIString("Content-Length"), | |
92 "ETag": WebInspector.UIString("ETag"), | |
93 "Keep-Alive": WebInspector.UIString("Keep-Alive"), | |
94 "Last-Modified": WebInspector.UIString("Last-Modified"), | |
95 "Server": WebInspector.UIString("Server"), | |
96 "Vary": WebInspector.UIString("Vary") | |
97 }; | |
98 | |
99 WebInspector.NetworkLogViewColumns.prototype = { | |
100 willHide: function() | |
101 { | |
102 this._popoverHelper.hidePopover(); | |
103 }, | |
104 | |
105 reset: function() | |
106 { | |
107 if (this._popoverHelper) | |
108 this._popoverHelper.hidePopover(); | |
109 this._timelineGrid.removeEventDividers(); | |
110 this.updateDividersIfNeeded(); | |
111 }, | |
112 | |
113 /** | |
114 * @return {!WebInspector.SortableDataGrid} dataGrid | |
115 */ | |
116 createGrid: function(timeCalculator, durationCalculator) | |
dgozman
2016/07/07 16:21:24
Annotate the parameters please.
allada
2016/07/07 16:46:45
Done.
| |
117 { | |
118 this._createSortingFunctions(); | |
119 this._popoverHelper = new WebInspector.PopoverHelper(this._networkLogVie w.element, this._getPopoverAnchor.bind(this), this._showPopover.bind(this), this ._onHidePopover.bind(this)); | |
120 | |
121 this._calculators.timeline = timeCalculator; | |
122 this._calculators.startTime = timeCalculator; | |
123 this._calculators.endTime = timeCalculator; | |
124 this._calculators.responseTime = timeCalculator; | |
125 this._calculators.duration = durationCalculator; | |
126 this._calculators.latency = durationCalculator; | |
127 | |
128 var columns = []; | |
129 columns.push({ | |
130 id: "name", | |
131 titleDOMFragment: this._makeHeaderFragment(WebInspector.UIString("Na me"), WebInspector.UIString("Path")), | |
132 title: WebInspector.NetworkLogViewColumns._columnTitles["name"], | |
133 weight: 20 | |
134 }); | |
135 | |
136 columns.push({ | |
137 id: "method", | |
138 title: WebInspector.NetworkLogViewColumns._columnTitles["method"], | |
139 weight: 6 | |
140 }); | |
141 | |
142 columns.push({ | |
143 id: "status", | |
144 titleDOMFragment: this._makeHeaderFragment(WebInspector.UIString("St atus"), WebInspector.UIString("Text")), | |
145 title: WebInspector.NetworkLogViewColumns._columnTitles["status"], | |
146 weight: 6 | |
147 }); | |
148 | |
149 columns.push({ | |
150 id: "protocol", | |
151 title: WebInspector.NetworkLogViewColumns._columnTitles["protocol"], | |
152 weight: 6 | |
153 }); | |
154 | |
155 columns.push({ | |
156 id: "scheme", | |
157 title: WebInspector.NetworkLogViewColumns._columnTitles["scheme"], | |
158 weight: 6 | |
159 }); | |
160 | |
161 columns.push({ | |
162 id: "domain", | |
163 title: WebInspector.NetworkLogViewColumns._columnTitles["domain"], | |
164 weight: 6 | |
165 }); | |
166 | |
167 columns.push({ | |
168 id: "remoteAddress", | |
169 title: WebInspector.NetworkLogViewColumns._columnTitles["remoteAddre ss"], | |
170 weight: 10, | |
171 align: WebInspector.DataGrid.Align.Right | |
172 }); | |
173 | |
174 columns.push({ | |
175 id: "type", | |
176 title: WebInspector.NetworkLogViewColumns._columnTitles["type"], | |
177 weight: 6 | |
178 }); | |
179 | |
180 columns.push({ | |
181 id: "initiator", | |
182 title: WebInspector.NetworkLogViewColumns._columnTitles["initiator"] , | |
183 weight: 10 | |
184 }); | |
185 | |
186 columns.push({ | |
187 id: "cookies", | |
188 title: WebInspector.NetworkLogViewColumns._columnTitles["cookies"], | |
189 weight: 6, | |
190 align: WebInspector.DataGrid.Align.Right | |
191 }); | |
192 | |
193 columns.push({ | |
194 id: "setCookies", | |
195 title: WebInspector.NetworkLogViewColumns._columnTitles["setCookies" ], | |
196 weight: 6, | |
197 align: WebInspector.DataGrid.Align.Right | |
198 }); | |
199 | |
200 columns.push({ | |
201 id: "size", | |
202 titleDOMFragment: this._makeHeaderFragment(WebInspector.UIString("Si ze"), WebInspector.UIString("Content")), | |
203 title: WebInspector.NetworkLogViewColumns._columnTitles["size"], | |
204 weight: 6, | |
205 align: WebInspector.DataGrid.Align.Right | |
206 }); | |
207 | |
208 columns.push({ | |
209 id: "time", | |
210 titleDOMFragment: this._makeHeaderFragment(WebInspector.UIString("Ti me"), WebInspector.UIString("Latency")), | |
211 title: WebInspector.NetworkLogViewColumns._columnTitles["time"], | |
212 weight: 6, | |
213 align: WebInspector.DataGrid.Align.Right | |
214 }); | |
215 | |
216 columns.push({ | |
217 id: "priority", | |
218 title: WebInspector.NetworkLogViewColumns._columnTitles["priority"], | |
219 weight: 6 | |
220 }); | |
221 | |
222 columns.push({ | |
223 id: "connectionId", | |
224 title: WebInspector.NetworkLogViewColumns._columnTitles["connectionI d"], | |
225 weight: 6 | |
226 }); | |
227 | |
228 var responseHeaderColumns = WebInspector.NetworkLogViewColumns._response HeaderColumns; | |
229 for (var i = 0; i < responseHeaderColumns.length; ++i) { | |
230 var headerName = responseHeaderColumns[i]; | |
231 var descriptor = { | |
232 id: headerName, | |
233 title: WebInspector.NetworkLogViewColumns._columnTitles[headerNa me], | |
234 weight: 6 | |
235 }; | |
236 if (headerName === "Content-Length") | |
237 descriptor.align = WebInspector.DataGrid.Align.Right; | |
238 columns.push(descriptor); | |
239 } | |
240 | |
241 columns.push({ | |
242 id: "timeline", | |
243 title: WebInspector.NetworkLogViewColumns._columnTitles["timeline"], | |
244 sortable: false, | |
245 weight: 40, | |
246 sort: WebInspector.DataGrid.Order.Ascending | |
247 }); | |
248 | |
249 for (var column of columns) { | |
250 column.sortable = column.id !== "timeline"; | |
251 column.nonSelectable = column.id !== "name"; | |
252 } | |
253 this._columns = columns; | |
254 | |
255 this._networkLogView.switchViewMode(true); | |
256 | |
257 this._dataGrid = new WebInspector.SortableDataGrid(this._columns); | |
258 | |
259 this._dataGrid.asWidget().show(this._networkLogView.element); | |
260 | |
261 this._timelineGrid = new WebInspector.TimelineGrid(); | |
262 this._timelineGrid.element.classList.add("network-timeline-grid"); | |
263 this._dataGrid.element.appendChild(this._timelineGrid.element); | |
264 | |
265 this._updateColumns(); | |
266 this._dataGrid.addEventListener(WebInspector.DataGrid.Events.SortingChan ged, this._sortItems, this); | |
267 this._dataGrid.sortNodes(this._sortingFunctions.startTime, false); | |
268 this._patchTimelineHeader(); | |
269 | |
270 this._dataGrid.addEventListener(WebInspector.DataGrid.Events.ColumnsResi zed, this.updateDividersIfNeeded, this); | |
271 | |
272 return this._dataGrid; | |
273 }, | |
274 | |
275 _createSortingFunctions: function() | |
276 { | |
277 this._sortingFunctions.name = WebInspector.NetworkDataGridNode.NameCompa rator; | |
278 this._sortingFunctions.method = WebInspector.NetworkDataGridNode.Request PropertyComparator.bind(null, "requestMethod"); | |
279 this._sortingFunctions.status = WebInspector.NetworkDataGridNode.Request PropertyComparator.bind(null, "statusCode"); | |
280 this._sortingFunctions.protocol = WebInspector.NetworkDataGridNode.Reque stPropertyComparator.bind(null, "protocol"); | |
281 this._sortingFunctions.scheme = WebInspector.NetworkDataGridNode.Request PropertyComparator.bind(null, "scheme"); | |
282 this._sortingFunctions.domain = WebInspector.NetworkDataGridNode.Request PropertyComparator.bind(null, "domain"); | |
283 this._sortingFunctions.remoteAddress = WebInspector.NetworkDataGridNode. RemoteAddressComparator; | |
284 this._sortingFunctions.type = WebInspector.NetworkDataGridNode.TypeCompa rator; | |
285 this._sortingFunctions.initiator = WebInspector.NetworkDataGridNode.Init iatorComparator; | |
286 this._sortingFunctions.cookies = WebInspector.NetworkDataGridNode.Reques tCookiesCountComparator; | |
287 this._sortingFunctions.setCookies = WebInspector.NetworkDataGridNode.Res ponseCookiesCountComparator; | |
288 this._sortingFunctions.size = WebInspector.NetworkDataGridNode.SizeCompa rator; | |
289 this._sortingFunctions.time = WebInspector.NetworkDataGridNode.RequestPr opertyComparator.bind(null, "duration"); | |
290 this._sortingFunctions.connectionId = WebInspector.NetworkDataGridNode.R equestPropertyComparator.bind(null, "connectionId"); | |
291 this._sortingFunctions.priority = WebInspector.NetworkDataGridNode.Initi alPriorityComparator; | |
292 this._sortingFunctions.timeline = WebInspector.NetworkDataGridNode.Reque stPropertyComparator.bind(null, "startTime"); | |
293 this._sortingFunctions.startTime = WebInspector.NetworkDataGridNode.Requ estPropertyComparator.bind(null, "startTime"); | |
294 this._sortingFunctions.endTime = WebInspector.NetworkDataGridNode.Reques tPropertyComparator.bind(null, "endTime"); | |
295 this._sortingFunctions.responseTime = WebInspector.NetworkDataGridNode.R equestPropertyComparator.bind(null, "responseReceivedTime"); | |
296 this._sortingFunctions.duration = WebInspector.NetworkDataGridNode.Reque stPropertyComparator.bind(null, "duration"); | |
297 this._sortingFunctions.latency = WebInspector.NetworkDataGridNode.Reques tPropertyComparator.bind(null, "latency"); | |
298 | |
299 this._sortingFunctions["Cache-Control"] = WebInspector.NetworkDataGridNo de.ResponseHeaderStringComparator.bind(null, "Cache-Control"); | |
300 this._sortingFunctions["Connection"] = WebInspector.NetworkDataGridNode. ResponseHeaderStringComparator.bind(null, "Connection"); | |
301 this._sortingFunctions["Content-Encoding"] = WebInspector.NetworkDataGri dNode.ResponseHeaderStringComparator.bind(null, "Content-Encoding"); | |
302 this._sortingFunctions["Content-Length"] = WebInspector.NetworkDataGridN ode.ResponseHeaderNumberComparator.bind(null, "Content-Length"); | |
303 this._sortingFunctions["ETag"] = WebInspector.NetworkDataGridNode.Respon seHeaderStringComparator.bind(null, "ETag"); | |
304 this._sortingFunctions["Keep-Alive"] = WebInspector.NetworkDataGridNode. ResponseHeaderStringComparator.bind(null, "Keep-Alive"); | |
305 this._sortingFunctions["Last-Modified"] = WebInspector.NetworkDataGridNo de.ResponseHeaderDateComparator.bind(null, "Last-Modified"); | |
306 this._sortingFunctions["Server"] = WebInspector.NetworkDataGridNode.Resp onseHeaderStringComparator.bind(null, "Server"); | |
307 this._sortingFunctions["Vary"] = WebInspector.NetworkDataGridNode.Respon seHeaderStringComparator.bind(null, "Vary"); | |
308 }, | |
309 | |
310 _sortItems: function() | |
311 { | |
312 this._networkLogView.removeAllNodeHighlights(); | |
313 var columnIdentifier = this._dataGrid.sortColumnIdentifier(); | |
314 if (!columnIdentifier) | |
315 return; | |
316 if (columnIdentifier === "timeline") { | |
317 this._sortByTimeline(); | |
318 return; | |
319 } | |
320 var sortingFunction = this._sortingFunctions[columnIdentifier]; | |
321 if (!sortingFunction) | |
322 return; | |
323 | |
324 this._dataGrid.sortNodes(sortingFunction, !this._dataGrid.isSortOrderAsc ending()); | |
325 this._timelineSortSelector.selectedIndex = 0; | |
326 this._networkLogView.dataGridSorted(); | |
327 }, | |
328 | |
329 _sortByTimeline: function() | |
330 { | |
331 this._networkLogView.removeAllNodeHighlights(); | |
332 var selectedIndex = this._timelineSortSelector.selectedIndex; | |
333 if (!selectedIndex) | |
334 selectedIndex = 1; // Sort by start time by default. | |
335 var selectedOption = this._timelineSortSelector[selectedIndex]; | |
336 var value = selectedOption.value; | |
337 | |
338 this._networkLogView.setCalculator(this._calculators[value]); | |
339 var sortingFunction = this._sortingFunctions[value]; | |
340 this._dataGrid.sortNodes(sortingFunction); | |
341 | |
342 this._networkLogView.dataGridSorted(); | |
343 | |
344 this._dataGrid.markColumnAsSortedBy("timeline", selectedOption.sortOrder ); | |
345 }, | |
346 | |
347 _patchTimelineHeader: function() | |
348 { | |
349 var timelineSorting = createElement("select"); | |
350 | |
351 var option = createElement("option"); | |
352 option.value = "startTime"; | |
353 option.label = WebInspector.UIString("Timeline"); | |
354 option.disabled = true; | |
355 timelineSorting.appendChild(option); | |
356 | |
357 option = createElement("option"); | |
358 option.value = "startTime"; | |
359 option.label = WebInspector.UIString("Timeline \u2013 Start Time"); | |
360 option.sortOrder = WebInspector.DataGrid.Order.Ascending; | |
361 timelineSorting.appendChild(option); | |
362 | |
363 option = createElement("option"); | |
364 option.value = "responseTime"; | |
365 option.label = WebInspector.UIString("Timeline \u2013 Response Time"); | |
366 option.sortOrder = WebInspector.DataGrid.Order.Ascending; | |
367 timelineSorting.appendChild(option); | |
368 | |
369 option = createElement("option"); | |
370 option.value = "endTime"; | |
371 option.label = WebInspector.UIString("Timeline \u2013 End Time"); | |
372 option.sortOrder = WebInspector.DataGrid.Order.Ascending; | |
373 timelineSorting.appendChild(option); | |
374 | |
375 option = createElement("option"); | |
376 option.value = "duration"; | |
377 option.label = WebInspector.UIString("Timeline \u2013 Total Duration"); | |
378 option.sortOrder = WebInspector.DataGrid.Order.Descending; | |
379 timelineSorting.appendChild(option); | |
380 | |
381 option = createElement("option"); | |
382 option.value = "latency"; | |
383 option.label = WebInspector.UIString("Timeline \u2013 Latency"); | |
384 option.sortOrder = WebInspector.DataGrid.Order.Descending; | |
385 timelineSorting.appendChild(option); | |
386 | |
387 var header = this._dataGrid.headerTableHeader("timeline"); | |
388 header.replaceChild(timelineSorting, header.firstChild); | |
389 header.createChild("div", "sort-order-icon-container").createChild("div" , "sort-order-icon"); | |
390 | |
391 timelineSorting.selectedIndex = 1; | |
392 timelineSorting.addEventListener("click", function(event) { event.consum e(); }, false); | |
393 timelineSorting.addEventListener("change", this._sortByTimeline.bind(thi s), false); | |
394 this._timelineSortSelector = timelineSorting; | |
395 }, | |
396 | |
397 _updateColumns: function() | |
398 { | |
399 if (!this._dataGrid) | |
400 return; | |
401 var gridMode = this._gridMode; | |
402 var visibleColumns = {"name": true}; | |
403 if (gridMode) | |
404 visibleColumns["timeline"] = true; | |
405 if (gridMode) { | |
406 var columnsVisibility = this._columnsVisibilitySetting.get(); | |
407 for (var columnIdentifier in columnsVisibility) | |
408 visibleColumns[columnIdentifier] = columnsVisibility[columnIdent ifier]; | |
409 } | |
410 | |
411 this._dataGrid.setColumnsVisiblity(visibleColumns); | |
412 }, | |
413 | |
414 /** | |
415 * @param {boolean} gridMode | |
416 */ | |
417 switchViewMode: function(gridMode) | |
418 { | |
419 if (this._gridMode === gridMode) | |
420 return; | |
421 this._gridMode = gridMode; | |
422 | |
423 if (gridMode) { | |
424 if (this._dataGrid.selectedNode) | |
425 this._dataGrid.selectedNode.selected = false; | |
426 } else { | |
427 this._networkLogView.removeAllNodeHighlights(); | |
428 this._popoverHelper.hidePopover(); | |
429 } | |
430 | |
431 this._networkLogView.element.classList.toggle("brief-mode", !gridMode); | |
432 this._updateColumns(); | |
433 }, | |
434 | |
435 /** | |
436 * @param {string} columnIdentifier | |
437 */ | |
438 _toggleColumnVisibility: function(columnIdentifier) | |
439 { | |
440 var columnsVisibility = this._columnsVisibilitySetting.get(); | |
441 columnsVisibility[columnIdentifier] = !columnsVisibility[columnIdentifie r]; | |
442 this._columnsVisibilitySetting.set(columnsVisibility); | |
443 | |
444 this._updateColumns(); | |
445 }, | |
446 | |
447 /** | |
448 * @return {!Array.<string>} | |
449 */ | |
450 _getConfigurableColumnIDs: function() | |
451 { | |
452 if (this._configurableColumnIDs) | |
453 return this._configurableColumnIDs; | |
454 | |
455 var columnTitles = WebInspector.NetworkLogViewColumns._columnTitles; | |
456 function compare(id1, id2) | |
457 { | |
458 return columnTitles[id1].compareTo(columnTitles[id2]); | |
459 } | |
460 | |
461 var columnIDs = Object.keys(this._columnsVisibilitySetting.get()); | |
462 this._configurableColumnIDs = columnIDs.sort(compare); | |
463 return this._configurableColumnIDs; | |
464 }, | |
465 | |
466 /** | |
467 * @param {string} title | |
468 * @param {string} subtitle | |
469 * @return {!DocumentFragment} | |
470 */ | |
471 _makeHeaderFragment: function(title, subtitle) | |
472 { | |
473 var fragment = createDocumentFragment(); | |
474 fragment.createTextChild(title); | |
475 var subtitleDiv = fragment.createChild("div", "network-header-subtitle") ; | |
476 subtitleDiv.createTextChild(subtitle); | |
477 return fragment; | |
478 }, | |
479 | |
480 /** | |
481 * @param {!Event} event | |
482 * @return {boolean} | |
483 */ | |
484 contextMenu: function(event) | |
485 { | |
486 if (!this._gridMode || !event.target.isSelfOrDescendant(this._dataGrid.h eaderTableBody)) | |
487 return false; | |
488 | |
489 var contextMenu = new WebInspector.ContextMenu(event); | |
490 | |
491 var columnsVisibility = this._columnsVisibilitySetting.get(); | |
492 var columnIDs = this._getConfigurableColumnIDs(); | |
493 var columnTitles = WebInspector.NetworkLogViewColumns._columnTitles; | |
494 for (var i = 0; i < columnIDs.length; ++i) { | |
495 var columnIdentifier = columnIDs[i]; | |
496 contextMenu.appendCheckboxItem(columnTitles[columnIdentifier], this. _toggleColumnVisibility.bind(this, columnIdentifier), !!columnsVisibility[column Identifier]); | |
497 } | |
498 contextMenu.show(); | |
499 return true; | |
500 }, | |
501 | |
502 updateDividersIfNeeded: function() | |
503 { | |
504 if (!this._networkLogView.isShowing()) { | |
505 this._networkLogView.scheduleRefresh(); | |
506 return; | |
507 } | |
508 | |
509 var timelineOffset = this._dataGrid.columnOffset("timeline"); | |
510 // Position timline grid location. | |
511 if (timelineOffset) | |
512 this._timelineGrid.element.style.left = timelineOffset + "px"; | |
513 | |
514 var calculator = this._networkLogView.calculator(); | |
515 calculator.setDisplayWindow(this._timelineGrid.dividersElement.clientWid th); | |
516 this._timelineGrid.updateDividers(calculator, 75); | |
517 | |
518 if (calculator.startAtZero) { | |
519 // If our current sorting method starts at zero, that means it shows all | |
520 // requests starting at the same point, and so onLoad event and DOMC ontent | |
521 // event lines really wouldn't make much sense here, so don't render them. | |
522 return; | |
523 } | |
524 | |
525 this._updateEventDividers(); | |
526 }, | |
527 | |
528 /** | |
529 * @param {!Element} element | |
530 * @param {!Event} event | |
531 * @return {!Element|!AnchorBox|undefined} | |
532 */ | |
533 _getPopoverAnchor: function(element, event) | |
534 { | |
535 if (!this._gridMode) | |
536 return; | |
537 var anchor = element.enclosingNodeOrSelfWithClass("network-graph-bar") | | element.enclosingNodeOrSelfWithClass("network-graph-label"); | |
538 if (anchor && anchor.parentElement.request && anchor.parentElement.reque st.timing) | |
539 return anchor; | |
540 anchor = element.enclosingNodeOrSelfWithClass("network-script-initiated" ); | |
541 if (anchor && anchor.request) { | |
542 var initiator = /** @type {!WebInspector.NetworkRequest} */ (anchor. request).initiator(); | |
543 if (initiator && initiator.stack) | |
544 return anchor; | |
545 } | |
546 }, | |
547 | |
548 /** | |
549 * @param {!Element} anchor | |
550 * @param {!WebInspector.Popover} popover | |
551 */ | |
552 _showPopover: function(anchor, popover) | |
553 { | |
554 var content; | |
555 if (anchor.classList.contains("network-script-initiated")) { | |
556 var request = /** @type {!WebInspector.NetworkRequest} */ (anchor.re quest); | |
557 var initiator = /** @type {!NetworkAgent.Initiator} */ (request.init iator()); | |
558 content = WebInspector.DOMPresentationUtils.buildStackTracePreviewCo ntents(request.target(), this._popupLinkifier, initiator.stack); | |
559 popover.setCanShrink(true); | |
560 } else { | |
561 content = WebInspector.RequestTimingView.createTimingTable(anchor.pa rentElement.request, this._networkLogView.timeCalculator().minimumBoundary()); | |
562 popover.setCanShrink(false); | |
563 } | |
564 popover.showForAnchor(content, anchor); | |
565 }, | |
566 | |
567 _onHidePopover: function() | |
568 { | |
569 this._popupLinkifier.reset(); | |
570 }, | |
571 | |
572 /** | |
573 * @param {!Array<number>} times | |
574 * @param {string} className | |
575 */ | |
576 addEventDividers: function(times, className) | |
577 { | |
578 for (var i = 0; i < times.length; ++i) { | |
579 var element = createElementWithClass("div", "network-event-divider " + className); | |
580 this._timelineGrid.addEventDivider(element); | |
581 this._eventDividers.push({time: times[i], element: element}); | |
582 } | |
583 // Update event dividers immediately | |
584 this._updateEventDividers(); | |
585 // Schedule refresh in case dividers change the calculator span. | |
586 this._networkLogView.scheduleRefresh(); | |
587 }, | |
588 | |
589 _updateEventDividers: function() | |
590 { | |
591 var calculator = this._networkLogView.calculator(); | |
592 for (var divider of this._eventDividers) { | |
593 var timePercent = calculator.computePercentageFromEventTime(divider. time); | |
594 divider.element.classList.toggle("invisible", timePercent < 0); | |
595 divider.element.style.left = timePercent + "%"; | |
596 } | |
597 }, | |
598 | |
599 hideEventDividers: function() | |
600 { | |
601 this._timelineGrid.hideEventDividers(); | |
602 }, | |
603 | |
604 showEventDividers: function() | |
605 { | |
606 this._timelineGrid.showEventDividers(); | |
607 }, | |
608 | |
609 /** | |
610 * @param {!WebInspector.Event} event | |
611 */ | |
612 _updateRowsSize: function(event) | |
613 { | |
614 this._timelineGrid.element.classList.toggle("small", !event.data); | |
615 } | |
616 } | |
OLD | NEW |