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

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

Issue 2466123002: DevTools: reformat front-end code to match chromium style. (Closed)
Patch Set: all done 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 /* 1 /*
2 * Copyright (C) 2007, 2008 Apple Inc. All rights reserved. 2 * Copyright (C) 2007, 2008 Apple Inc. All rights reserved.
3 * Copyright (C) 2008, 2009 Anthony Ricaud <rik@webkit.org> 3 * Copyright (C) 2008, 2009 Anthony Ricaud <rik@webkit.org>
4 * Copyright (C) 2011 Google Inc. All rights reserved. 4 * Copyright (C) 2011 Google Inc. All rights reserved.
5 * 5 *
6 * Redistribution and use in source and binary forms, with or without 6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions 7 * modification, are permitted provided that the following conditions
8 * are met: 8 * are met:
9 * 9 *
10 * 1. Redistributions of source code must retain the above copyright 10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer. 11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright 12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the 13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution. 14 * documentation and/or other materials provided with the distribution.
15 * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of 15 * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of
16 * its contributors may be used to endorse or promote products derived 16 * its contributors may be used to endorse or promote products derived
17 * from this software without specific prior written permission. 17 * from this software without specific prior written permission.
18 * 18 *
19 * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY 19 * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
20 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 20 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
21 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 21 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22 * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY 22 * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
23 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 23 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
24 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 24 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 25 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
26 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
28 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */ 29 */
30
31 /** 30 /**
32 * @constructor
33 * @implements {WebInspector.ContextMenu.Provider} 31 * @implements {WebInspector.ContextMenu.Provider}
34 * @implements {WebInspector.Searchable} 32 * @implements {WebInspector.Searchable}
35 * @extends {WebInspector.Panel} 33 * @unrestricted
36 */ 34 */
37 WebInspector.NetworkPanel = function() 35 WebInspector.NetworkPanel = class extends WebInspector.Panel {
38 { 36 constructor() {
39 WebInspector.Panel.call(this, "network"); 37 super('network');
40 this.registerRequiredCSS("network/networkPanel.css"); 38 this.registerRequiredCSS('network/networkPanel.css');
41 39
42 this._networkLogShowOverviewSetting = WebInspector.settings.createSetting("n etworkLogShowOverview", true); 40 this._networkLogShowOverviewSetting = WebInspector.settings.createSetting('n etworkLogShowOverview', true);
43 this._networkLogLargeRowsSetting = WebInspector.settings.createSetting("netw orkLogLargeRows", false); 41 this._networkLogLargeRowsSetting = WebInspector.settings.createSetting('netw orkLogLargeRows', false);
44 this._networkRecordFilmStripSetting = WebInspector.settings.createSetting("n etworkRecordFilmStripSetting", false); 42 this._networkRecordFilmStripSetting = WebInspector.settings.createSetting('n etworkRecordFilmStripSetting', false);
45 this._toggleRecordAction = /** @type {!WebInspector.Action }*/(WebInspector. actionRegistry.action("network.toggle-recording")); 43 this._toggleRecordAction =
44 /** @type {!WebInspector.Action }*/ (WebInspector.actionRegistry.action( 'network.toggle-recording'));
46 45
47 /** @type {?WebInspector.FilmStripView} */ 46 /** @type {?WebInspector.FilmStripView} */
48 this._filmStripView = null; 47 this._filmStripView = null;
49 /** @type {?WebInspector.NetworkPanel.FilmStripRecorder} */ 48 /** @type {?WebInspector.NetworkPanel.FilmStripRecorder} */
50 this._filmStripRecorder = null; 49 this._filmStripRecorder = null;
51 50
52 this._panelToolbar = new WebInspector.Toolbar("", this.element); 51 this._panelToolbar = new WebInspector.Toolbar('', this.element);
53 this._filterBar = new WebInspector.FilterBar("networkPanel", true); 52 this._filterBar = new WebInspector.FilterBar('networkPanel', true);
54 this._filterBar.show(this.element); 53 this._filterBar.show(this.element);
55 54
56 // Create top overview component. 55 // Create top overview component.
57 this._overviewPane = new WebInspector.TimelineOverviewPane("network"); 56 this._overviewPane = new WebInspector.TimelineOverviewPane('network');
58 this._overviewPane.addEventListener(WebInspector.TimelineOverviewPane.Events .WindowChanged, this._onWindowChanged.bind(this)); 57 this._overviewPane.addEventListener(
59 this._overviewPane.element.id = "network-overview-panel"; 58 WebInspector.TimelineOverviewPane.Events.WindowChanged, this._onWindowCh anged.bind(this));
59 this._overviewPane.element.id = 'network-overview-panel';
60 this._networkOverview = new WebInspector.NetworkOverview(); 60 this._networkOverview = new WebInspector.NetworkOverview();
61 this._overviewPane.setOverviewControls([this._networkOverview]); 61 this._overviewPane.setOverviewControls([this._networkOverview]);
62 this._calculator = new WebInspector.NetworkTransferTimeCalculator(); 62 this._calculator = new WebInspector.NetworkTransferTimeCalculator();
63 63
64 this._splitWidget = new WebInspector.SplitWidget(true, false, "networkPanelS plitViewState"); 64 this._splitWidget = new WebInspector.SplitWidget(true, false, 'networkPanelS plitViewState');
65 this._splitWidget.hideMain(); 65 this._splitWidget.hideMain();
66 66
67 this._splitWidget.show(this.element); 67 this._splitWidget.show(this.element);
68 68
69 this._progressBarContainer = createElement("div"); 69 this._progressBarContainer = createElement('div');
70 this._createToolbarButtons(); 70 this._createToolbarButtons();
71 71
72 this._searchableView = new WebInspector.SearchableView(this); 72 this._searchableView = new WebInspector.SearchableView(this);
73 this._searchableView.setPlaceholder(WebInspector.UIString("Find by filename or path")); 73 this._searchableView.setPlaceholder(WebInspector.UIString('Find by filename or path'));
74 74
75 /** @type {!WebInspector.NetworkLogView} */ 75 /** @type {!WebInspector.NetworkLogView} */
76 this._networkLogView = new WebInspector.NetworkLogView(this._filterBar, this ._progressBarContainer, this._networkLogLargeRowsSetting); 76 this._networkLogView =
77 new WebInspector.NetworkLogView(this._filterBar, this._progressBarContai ner, this._networkLogLargeRowsSetting);
77 this._networkLogView.show(this._searchableView.element); 78 this._networkLogView.show(this._searchableView.element);
78 79
79 this._splitWidget.setSidebarWidget(this._searchableView); 80 this._splitWidget.setSidebarWidget(this._searchableView);
80 81
81 this._detailsWidget = new WebInspector.VBox(); 82 this._detailsWidget = new WebInspector.VBox();
82 this._detailsWidget.element.classList.add("network-details-view"); 83 this._detailsWidget.element.classList.add('network-details-view');
83 this._splitWidget.setMainWidget(this._detailsWidget); 84 this._splitWidget.setMainWidget(this._detailsWidget);
84 85
85 this._closeButtonElement = createElement("div", "dt-close-button"); 86 this._closeButtonElement = createElement('div', 'dt-close-button');
86 this._closeButtonElement.addEventListener("click", this._showRequest.bind(th is, null), false); 87 this._closeButtonElement.addEventListener('click', this._showRequest.bind(th is, null), false);
87 88
88 this._networkLogShowOverviewSetting.addChangeListener(this._toggleShowOvervi ew, this); 89 this._networkLogShowOverviewSetting.addChangeListener(this._toggleShowOvervi ew, this);
89 this._networkLogLargeRowsSetting.addChangeListener(this._toggleLargerRequest s, this); 90 this._networkLogLargeRowsSetting.addChangeListener(this._toggleLargerRequest s, this);
90 this._networkRecordFilmStripSetting.addChangeListener(this._toggleRecordFilm Strip, this); 91 this._networkRecordFilmStripSetting.addChangeListener(this._toggleRecordFilm Strip, this);
91 92
92 this._toggleRecord(true); 93 this._toggleRecord(true);
93 this._toggleShowOverview(); 94 this._toggleShowOverview();
94 this._toggleLargerRequests(); 95 this._toggleLargerRequests();
95 this._toggleRecordFilmStrip(); 96 this._toggleRecordFilmStrip();
96 this._updateUI(); 97 this._updateUI();
97 98
98 WebInspector.targetManager.addModelListener(WebInspector.ResourceTreeModel, WebInspector.ResourceTreeModel.Events.WillReloadPage, this._willReloadPage, this ); 99 WebInspector.targetManager.addModelListener(
99 WebInspector.targetManager.addModelListener(WebInspector.ResourceTreeModel, WebInspector.ResourceTreeModel.Events.Load, this._load, this); 100 WebInspector.ResourceTreeModel, WebInspector.ResourceTreeModel.Events.Wi llReloadPage, this._willReloadPage,
100 this._networkLogView.addEventListener(WebInspector.NetworkLogView.Events.Req uestSelected, this._onRequestSelected, this); 101 this);
101 this._networkLogView.addEventListener(WebInspector.NetworkLogView.Events.Sea rchCountUpdated, this._onSearchCountUpdated, this); 102 WebInspector.targetManager.addModelListener(
102 this._networkLogView.addEventListener(WebInspector.NetworkLogView.Events.Sea rchIndexUpdated, this._onSearchIndexUpdated, this); 103 WebInspector.ResourceTreeModel, WebInspector.ResourceTreeModel.Events.Lo ad, this._load, this);
103 this._networkLogView.addEventListener(WebInspector.NetworkLogView.Events.Upd ateRequest, this._onUpdateRequest, this); 104 this._networkLogView.addEventListener(
105 WebInspector.NetworkLogView.Events.RequestSelected, this._onRequestSelec ted, this);
106 this._networkLogView.addEventListener(
107 WebInspector.NetworkLogView.Events.SearchCountUpdated, this._onSearchCou ntUpdated, this);
108 this._networkLogView.addEventListener(
109 WebInspector.NetworkLogView.Events.SearchIndexUpdated, this._onSearchInd exUpdated, this);
110 this._networkLogView.addEventListener(
111 WebInspector.NetworkLogView.Events.UpdateRequest, this._onUpdateRequest, this);
104 112
105 WebInspector.DataSaverInfobar.maybeShowInPanel(this); 113 WebInspector.DataSaverInfobar.maybeShowInPanel(this);
106 }; 114 }
107 115
108 WebInspector.NetworkPanel.displayScreenshotDelay = 1000; 116 /**
109 117 * @param {!Array<{filterType: !WebInspector.NetworkLogView.FilterType, filter Value: string}>} filters
110 WebInspector.NetworkPanel.prototype = { 118 */
119 static revealAndFilter(filters) {
120 var panel = WebInspector.NetworkPanel._instance();
121 var filterString = '';
122 for (var filter of filters)
123 filterString += `${filter.filterType}:${filter.filterValue} `;
124 panel._networkLogView.setTextFilterValue(filterString);
125 WebInspector.viewManager.showView('network');
126 }
127
128 /**
129 * @return {!WebInspector.NetworkPanel}
130 */
131 static _instance() {
132 return /** @type {!WebInspector.NetworkPanel} */ (self.runtime.sharedInstanc e(WebInspector.NetworkPanel));
133 }
134
135 /**
136 * @param {!WebInspector.Event} event
137 */
138 _onWindowChanged(event) {
139 var startTime = Math.max(this._calculator.minimumBoundary(), event.data.star tTime / 1000);
140 var endTime = Math.min(this._calculator.maximumBoundary(), event.data.endTim e / 1000);
141 this._networkLogView.setWindow(startTime, endTime);
142 }
143
144 _createToolbarButtons() {
145 this._panelToolbar.appendToolbarItem(WebInspector.Toolbar.createActionButton (this._toggleRecordAction));
146
147 this._clearButton = new WebInspector.ToolbarButton(WebInspector.UIString('Cl ear'), 'clear-toolbar-item');
148 this._clearButton.addEventListener('click', this._onClearButtonClicked, this );
149 this._panelToolbar.appendToolbarItem(this._clearButton);
150 this._panelToolbar.appendSeparator();
151 var recordFilmStripButton = new WebInspector.ToolbarSettingToggle(
152 this._networkRecordFilmStripSetting, 'camera-toolbar-item', WebInspector .UIString('Capture screenshots'));
153 this._panelToolbar.appendToolbarItem(recordFilmStripButton);
154
155 this._panelToolbar.appendToolbarItem(this._filterBar.filterButton());
156 this._panelToolbar.appendSeparator();
157
158 this._panelToolbar.appendText(WebInspector.UIString('View:'));
159
160 var largerRequestsButton = new WebInspector.ToolbarSettingToggle(
161 this._networkLogLargeRowsSetting, 'large-list-toolbar-item', WebInspecto r.UIString('Use large request rows'),
162 WebInspector.UIString('Use small request rows'));
163 this._panelToolbar.appendToolbarItem(largerRequestsButton);
164
165 var showOverviewButton = new WebInspector.ToolbarSettingToggle(
166 this._networkLogShowOverviewSetting, 'waterfall-toolbar-item', WebInspec tor.UIString('Show overview'),
167 WebInspector.UIString('Hide overview'));
168 this._panelToolbar.appendToolbarItem(showOverviewButton);
169 this._panelToolbar.appendSeparator();
170
171 this._preserveLogCheckbox = new WebInspector.ToolbarCheckbox(
172 WebInspector.UIString('Preserve log'), WebInspector.UIString('Do not cle ar log on page reload / navigation'));
173 this._preserveLogCheckbox.inputElement.addEventListener(
174 'change', this._onPreserveLogCheckboxChanged.bind(this), false);
175 this._panelToolbar.appendToolbarItem(this._preserveLogCheckbox);
176
177 this._disableCacheCheckbox = new WebInspector.ToolbarCheckbox(
178 WebInspector.UIString('Disable cache'), WebInspector.UIString('Disable c ache (while DevTools is open)'),
179 WebInspector.moduleSetting('cacheDisabled'));
180 this._panelToolbar.appendToolbarItem(this._disableCacheCheckbox);
181
182 this._panelToolbar.appendSeparator();
183 this._panelToolbar.appendToolbarItem(this._createBlockedURLsButton());
184 this._panelToolbar.appendToolbarItem(WebInspector.NetworkConditionsSelector. createOfflineToolbarCheckbox());
185 this._panelToolbar.appendToolbarItem(this._createNetworkConditionsSelect());
186 this._panelToolbar.appendToolbarItem(new WebInspector.ToolbarItem(this._prog ressBarContainer));
187 }
188
189 /**
190 * @return {!WebInspector.ToolbarItem}
191 */
192 _createBlockedURLsButton() {
193 var setting = WebInspector.moduleSetting('blockedURLs');
194 setting.addChangeListener(updateAction);
195 var action = /** @type {!WebInspector.Action }*/ (WebInspector.actionRegistr y.action('network.blocked-urls.show'));
196 var button = WebInspector.Toolbar.createActionButton(action);
197 button.setVisible(Runtime.experiments.isEnabled('requestBlocking'));
198 updateAction();
199 return button;
200
201 function updateAction() {
202 action.setToggled(!!setting.get().length);
203 }
204 }
205
206 /**
207 * @return {!WebInspector.ToolbarComboBox}
208 */
209 _createNetworkConditionsSelect() {
210 var toolbarItem = new WebInspector.ToolbarComboBox(null);
211 toolbarItem.setMaxWidth(140);
212 WebInspector.NetworkConditionsSelector.decorateSelect(toolbarItem.selectElem ent());
213 return toolbarItem;
214 }
215
216 _toggleRecording() {
217 if (!this._preserveLogCheckbox.checked() && !this._toggleRecordAction.toggle d())
218 this._reset();
219 this._toggleRecord(!this._toggleRecordAction.toggled());
220 }
221
222 /**
223 * @param {boolean} toggled
224 */
225 _toggleRecord(toggled) {
226 this._toggleRecordAction.setToggled(toggled);
227 this._networkLogView.setRecording(toggled);
228 if (!toggled && this._filmStripRecorder)
229 this._filmStripRecorder.stopRecording(this._filmStripAvailable.bind(this)) ;
230 }
231
232 /**
233 * @param {?WebInspector.FilmStripModel} filmStripModel
234 */
235 _filmStripAvailable(filmStripModel) {
236 if (!filmStripModel)
237 return;
238 var calculator = this._networkLogView.timeCalculator();
239 this._filmStripView.setModel(filmStripModel, calculator.minimumBoundary() * 1000, calculator.boundarySpan() * 1000);
240 this._networkOverview.setFilmStripModel(filmStripModel);
241 var timestamps = filmStripModel.frames().map(mapTimestamp);
242
111 /** 243 /**
112 * @param {!WebInspector.Event} event 244 * @param {!WebInspector.FilmStripModel.Frame} frame
245 * @return {number}
113 */ 246 */
114 _onWindowChanged: function(event) 247 function mapTimestamp(frame) {
115 { 248 return frame.timestamp / 1000;
116 var startTime = Math.max(this._calculator.minimumBoundary(), event.data. startTime / 1000); 249 }
117 var endTime = Math.min(this._calculator.maximumBoundary(), event.data.en dTime / 1000); 250
118 this._networkLogView.setWindow(startTime, endTime); 251 this._networkLogView.addFilmStripFrames(timestamps);
119 }, 252 }
120 253
121 _createToolbarButtons: function() 254 /**
122 { 255 * @param {!Event} event
123 this._panelToolbar.appendToolbarItem(WebInspector.Toolbar.createActionBu tton(this._toggleRecordAction)); 256 */
124 257 _onPreserveLogCheckboxChanged(event) {
125 this._clearButton = new WebInspector.ToolbarButton(WebInspector.UIString ("Clear"), "clear-toolbar-item"); 258 this._networkLogView.setPreserveLog(this._preserveLogCheckbox.checked());
126 this._clearButton.addEventListener("click", this._onClearButtonClicked, this); 259 }
127 this._panelToolbar.appendToolbarItem(this._clearButton); 260
128 this._panelToolbar.appendSeparator(); 261 /**
129 var recordFilmStripButton = new WebInspector.ToolbarSettingToggle(this._ networkRecordFilmStripSetting, "camera-toolbar-item", WebInspector.UIString("Cap ture screenshots")); 262 * @param {!WebInspector.Event} event
130 this._panelToolbar.appendToolbarItem(recordFilmStripButton); 263 */
131 264 _onClearButtonClicked(event) {
132 this._panelToolbar.appendToolbarItem(this._filterBar.filterButton()); 265 this._reset();
133 this._panelToolbar.appendSeparator(); 266 }
134 267
135 this._panelToolbar.appendText(WebInspector.UIString("View:")); 268 _reset() {
136 269 this._calculator.reset();
137 var largerRequestsButton = new WebInspector.ToolbarSettingToggle(this._n etworkLogLargeRowsSetting, "large-list-toolbar-item", WebInspector.UIString("Use large request rows"), WebInspector.UIString("Use small request rows")); 270 this._overviewPane.reset();
138 this._panelToolbar.appendToolbarItem(largerRequestsButton); 271 this._networkLogView.reset();
139 272 WebInspector.BlockedURLsPane.reset();
140 var showOverviewButton = new WebInspector.ToolbarSettingToggle(this._net workLogShowOverviewSetting, "waterfall-toolbar-item", WebInspector.UIString("Sho w overview"), WebInspector.UIString("Hide overview")); 273 if (this._filmStripView)
141 this._panelToolbar.appendToolbarItem(showOverviewButton); 274 this._resetFilmStripView();
142 this._panelToolbar.appendSeparator(); 275 }
143 276
144 this._preserveLogCheckbox = new WebInspector.ToolbarCheckbox(WebInspecto r.UIString("Preserve log"), WebInspector.UIString("Do not clear log on page relo ad / navigation")); 277 /**
145 this._preserveLogCheckbox.inputElement.addEventListener("change", this._ onPreserveLogCheckboxChanged.bind(this), false); 278 * @param {!WebInspector.Event} event
146 this._panelToolbar.appendToolbarItem(this._preserveLogCheckbox); 279 */
147 280 _willReloadPage(event) {
148 this._disableCacheCheckbox = new WebInspector.ToolbarCheckbox(WebInspect or.UIString("Disable cache"), WebInspector.UIString("Disable cache (while DevToo ls is open)"), WebInspector.moduleSetting("cacheDisabled")); 281 if (!this._preserveLogCheckbox.checked())
149 this._panelToolbar.appendToolbarItem(this._disableCacheCheckbox); 282 this._reset();
150 283 this._toggleRecord(true);
151 this._panelToolbar.appendSeparator(); 284 if (this._pendingStopTimer) {
152 this._panelToolbar.appendToolbarItem(this._createBlockedURLsButton()); 285 clearTimeout(this._pendingStopTimer);
153 this._panelToolbar.appendToolbarItem(WebInspector.NetworkConditionsSelec tor.createOfflineToolbarCheckbox()); 286 delete this._pendingStopTimer;
154 this._panelToolbar.appendToolbarItem(this._createNetworkConditionsSelect ()); 287 }
155 this._panelToolbar.appendToolbarItem(new WebInspector.ToolbarItem(this._ progressBarContainer)); 288 if (this.isShowing() && this._filmStripRecorder)
156 }, 289 this._filmStripRecorder.startRecording();
157 290 }
291
292 /**
293 * @param {!WebInspector.Event} event
294 */
295 _load(event) {
296 if (this._filmStripRecorder && this._filmStripRecorder.isRecording())
297 this._pendingStopTimer =
298 setTimeout(this._stopFilmStripRecording.bind(this), WebInspector.Netwo rkPanel.displayScreenshotDelay);
299 }
300
301 _stopFilmStripRecording() {
302 this._filmStripRecorder.stopRecording(this._filmStripAvailable.bind(this));
303 delete this._pendingStopTimer;
304 }
305
306 _toggleLargerRequests() {
307 this._updateUI();
308 }
309
310 _toggleShowOverview() {
311 var toggled = this._networkLogShowOverviewSetting.get();
312 if (toggled)
313 this._overviewPane.show(this.element, this._splitWidget.element);
314 else
315 this._overviewPane.detach();
316 this.doResize();
317 }
318
319 _toggleRecordFilmStrip() {
320 var toggled = this._networkRecordFilmStripSetting.get();
321 if (toggled && !this._filmStripRecorder) {
322 this._filmStripView = new WebInspector.FilmStripView();
323 this._filmStripView.setMode(WebInspector.FilmStripView.Modes.FrameBased);
324 this._filmStripView.element.classList.add('network-film-strip');
325 this._filmStripRecorder =
326 new WebInspector.NetworkPanel.FilmStripRecorder(this._networkLogView.t imeCalculator(), this._filmStripView);
327 this._filmStripView.show(this.element, this.element.firstElementChild);
328 this._filmStripView.addEventListener(
329 WebInspector.FilmStripView.Events.FrameSelected, this._onFilmFrameSele cted, this);
330 this._filmStripView.addEventListener(WebInspector.FilmStripView.Events.Fra meEnter, this._onFilmFrameEnter, this);
331 this._filmStripView.addEventListener(WebInspector.FilmStripView.Events.Fra meExit, this._onFilmFrameExit, this);
332 this._resetFilmStripView();
333 }
334
335 if (!toggled && this._filmStripRecorder) {
336 this._filmStripView.detach();
337 this._filmStripView = null;
338 this._filmStripRecorder = null;
339 }
340 }
341
342 _resetFilmStripView() {
343 this._filmStripView.reset();
344 this._filmStripView.setStatusText(WebInspector.UIString(
345 'Hit %s to reload and capture filmstrip.',
346 WebInspector.shortcutRegistry.shortcutDescriptorsForAction('main.reload' )[0].name));
347 }
348
349 /**
350 * @override
351 * @return {!Array.<!Element>}
352 */
353 elementsToRestoreScrollPositionsFor() {
354 return this._networkLogView.elementsToRestoreScrollPositionsFor();
355 }
356
357 /**
358 * @override
359 * @return {!WebInspector.SearchableView}
360 */
361 searchableView() {
362 return this._searchableView;
363 }
364
365 /**
366 * @override
367 * @param {!KeyboardEvent} event
368 */
369 handleShortcut(event) {
370 if (this._networkItemView && event.keyCode === WebInspector.KeyboardShortcut .Keys.Esc.code) {
371 this._showRequest(null);
372 event.handled = true;
373 return;
374 }
375
376 super.handleShortcut(event);
377 }
378
379 /**
380 * @override
381 */
382 wasShown() {
383 WebInspector.context.setFlavor(WebInspector.NetworkPanel, this);
384 }
385
386 /**
387 * @override
388 */
389 willHide() {
390 WebInspector.context.setFlavor(WebInspector.NetworkPanel, null);
391 }
392
393 /**
394 * @param {!WebInspector.NetworkRequest} request
395 */
396 revealAndHighlightRequest(request) {
397 this._showRequest(null);
398 if (request)
399 this._networkLogView.revealAndHighlightRequest(request);
400 }
401
402 /**
403 * @param {!WebInspector.Event} event
404 */
405 _onRowSizeChanged(event) {
406 this._updateUI();
407 }
408
409 /**
410 * @param {!WebInspector.Event} event
411 */
412 _onSearchCountUpdated(event) {
413 var count = /** @type {number} */ (event.data);
414 this._searchableView.updateSearchMatchesCount(count);
415 }
416
417 /**
418 * @param {!WebInspector.Event} event
419 */
420 _onSearchIndexUpdated(event) {
421 var index = /** @type {number} */ (event.data);
422 this._searchableView.updateCurrentMatchIndex(index);
423 }
424
425 /**
426 * @param {!WebInspector.Event} event
427 */
428 _onRequestSelected(event) {
429 var request = /** @type {?WebInspector.NetworkRequest} */ (event.data);
430 this._showRequest(request);
431 }
432
433 /**
434 * @param {?WebInspector.NetworkRequest} request
435 */
436 _showRequest(request) {
437 if (this._networkItemView) {
438 this._networkItemView.detach();
439 this._networkItemView = null;
440 }
441
442 if (request) {
443 this._networkItemView = new WebInspector.NetworkItemView(request, this._ne tworkLogView.timeCalculator());
444 this._networkItemView.leftToolbar().appendToolbarItem(new WebInspector.Too lbarItem(this._closeButtonElement));
445 this._networkItemView.show(this._detailsWidget.element);
446 this._splitWidget.showBoth();
447 } else {
448 this._splitWidget.hideMain();
449 this._networkLogView.clearSelection();
450 }
451 this._updateUI();
452 }
453
454 _updateUI() {
455 this._detailsWidget.element.classList.toggle(
456 'network-details-view-tall-header', this._networkLogLargeRowsSetting.get ());
457 this._networkLogView.switchViewMode(!this._splitWidget.isResizable());
458 }
459
460 /**
461 * @override
462 * @param {!WebInspector.SearchableView.SearchConfig} searchConfig
463 * @param {boolean} shouldJump
464 * @param {boolean=} jumpBackwards
465 */
466 performSearch(searchConfig, shouldJump, jumpBackwards) {
467 this._networkLogView.performSearch(searchConfig, shouldJump, jumpBackwards);
468 }
469
470 /**
471 * @override
472 */
473 jumpToPreviousSearchResult() {
474 this._networkLogView.jumpToPreviousSearchResult();
475 }
476
477 /**
478 * @override
479 * @return {boolean}
480 */
481 supportsCaseSensitiveSearch() {
482 return false;
483 }
484
485 /**
486 * @override
487 * @return {boolean}
488 */
489 supportsRegexSearch() {
490 return false;
491 }
492
493 /**
494 * @override
495 */
496 jumpToNextSearchResult() {
497 this._networkLogView.jumpToNextSearchResult();
498 }
499
500 /**
501 * @override
502 */
503 searchCanceled() {
504 this._networkLogView.searchCanceled();
505 }
506
507 /**
508 * @override
509 * @param {!Event} event
510 * @param {!WebInspector.ContextMenu} contextMenu
511 * @param {!Object} target
512 * @this {WebInspector.NetworkPanel}
513 */
514 appendApplicableItems(event, contextMenu, target) {
158 /** 515 /**
159 * @return {!WebInspector.ToolbarItem}
160 */
161 _createBlockedURLsButton: function()
162 {
163 var setting = WebInspector.moduleSetting("blockedURLs");
164 setting.addChangeListener(updateAction);
165 var action = /** @type {!WebInspector.Action }*/(WebInspector.actionRegi stry.action("network.blocked-urls.show"));
166 var button = WebInspector.Toolbar.createActionButton(action);
167 button.setVisible(Runtime.experiments.isEnabled("requestBlocking"));
168 updateAction();
169 return button;
170
171 function updateAction()
172 {
173 action.setToggled(!!setting.get().length);
174 }
175 },
176
177 /**
178 * @return {!WebInspector.ToolbarComboBox}
179 */
180 _createNetworkConditionsSelect: function()
181 {
182 var toolbarItem = new WebInspector.ToolbarComboBox(null);
183 toolbarItem.setMaxWidth(140);
184 WebInspector.NetworkConditionsSelector.decorateSelect(toolbarItem.select Element());
185 return toolbarItem;
186 },
187
188 _toggleRecording: function()
189 {
190 if (!this._preserveLogCheckbox.checked() && !this._toggleRecordAction.to ggled())
191 this._reset();
192 this._toggleRecord(!this._toggleRecordAction.toggled());
193 },
194
195 /**
196 * @param {boolean} toggled
197 */
198 _toggleRecord: function(toggled)
199 {
200 this._toggleRecordAction.setToggled(toggled);
201 this._networkLogView.setRecording(toggled);
202 if (!toggled && this._filmStripRecorder)
203 this._filmStripRecorder.stopRecording(this._filmStripAvailable.bind( this));
204 },
205
206 /**
207 * @param {?WebInspector.FilmStripModel} filmStripModel
208 */
209 _filmStripAvailable: function(filmStripModel)
210 {
211 if (!filmStripModel)
212 return;
213 var calculator = this._networkLogView.timeCalculator();
214 this._filmStripView.setModel(filmStripModel, calculator.minimumBoundary( ) * 1000, calculator.boundarySpan() * 1000);
215 this._networkOverview.setFilmStripModel(filmStripModel);
216 var timestamps = filmStripModel.frames().map(mapTimestamp);
217
218 /**
219 * @param {!WebInspector.FilmStripModel.Frame} frame
220 * @return {number}
221 */
222 function mapTimestamp(frame)
223 {
224 return frame.timestamp / 1000;
225 }
226
227 this._networkLogView.addFilmStripFrames(timestamps);
228 },
229
230 /**
231 * @param {!Event} event
232 */
233 _onPreserveLogCheckboxChanged: function(event)
234 {
235 this._networkLogView.setPreserveLog(this._preserveLogCheckbox.checked()) ;
236 },
237
238 /**
239 * @param {!WebInspector.Event} event
240 */
241 _onClearButtonClicked: function(event)
242 {
243 this._reset();
244 },
245
246 _reset: function()
247 {
248 this._calculator.reset();
249 this._overviewPane.reset();
250 this._networkLogView.reset();
251 WebInspector.BlockedURLsPane.reset();
252 if (this._filmStripView)
253 this._resetFilmStripView();
254 },
255
256 /**
257 * @param {!WebInspector.Event} event
258 */
259 _willReloadPage: function(event)
260 {
261 if (!this._preserveLogCheckbox.checked())
262 this._reset();
263 this._toggleRecord(true);
264 if (this._pendingStopTimer) {
265 clearTimeout(this._pendingStopTimer);
266 delete this._pendingStopTimer;
267 }
268 if (this.isShowing() && this._filmStripRecorder)
269 this._filmStripRecorder.startRecording();
270 },
271
272 /**
273 * @param {!WebInspector.Event} event
274 */
275 _load: function(event)
276 {
277 if (this._filmStripRecorder && this._filmStripRecorder.isRecording())
278 this._pendingStopTimer = setTimeout(this._stopFilmStripRecording.bin d(this), WebInspector.NetworkPanel.displayScreenshotDelay);
279 },
280
281 _stopFilmStripRecording: function()
282 {
283 this._filmStripRecorder.stopRecording(this._filmStripAvailable.bind(this ));
284 delete this._pendingStopTimer;
285 },
286
287 _toggleLargerRequests: function()
288 {
289 this._updateUI();
290 },
291
292 _toggleShowOverview: function()
293 {
294 var toggled = this._networkLogShowOverviewSetting.get();
295 if (toggled)
296 this._overviewPane.show(this.element, this._splitWidget.element);
297 else
298 this._overviewPane.detach();
299 this.doResize();
300 },
301
302 _toggleRecordFilmStrip: function()
303 {
304 var toggled = this._networkRecordFilmStripSetting.get();
305 if (toggled && !this._filmStripRecorder) {
306 this._filmStripView = new WebInspector.FilmStripView();
307 this._filmStripView.setMode(WebInspector.FilmStripView.Modes.FrameBa sed);
308 this._filmStripView.element.classList.add("network-film-strip");
309 this._filmStripRecorder = new WebInspector.NetworkPanel.FilmStripRec order(this._networkLogView.timeCalculator(), this._filmStripView);
310 this._filmStripView.show(this.element, this.element.firstElementChil d);
311 this._filmStripView.addEventListener(WebInspector.FilmStripView.Even ts.FrameSelected, this._onFilmFrameSelected, this);
312 this._filmStripView.addEventListener(WebInspector.FilmStripView.Even ts.FrameEnter, this._onFilmFrameEnter, this);
313 this._filmStripView.addEventListener(WebInspector.FilmStripView.Even ts.FrameExit, this._onFilmFrameExit, this);
314 this._resetFilmStripView();
315 }
316
317 if (!toggled && this._filmStripRecorder) {
318 this._filmStripView.detach();
319 this._filmStripView = null;
320 this._filmStripRecorder = null;
321 }
322 },
323
324 _resetFilmStripView: function()
325 {
326 this._filmStripView.reset();
327 this._filmStripView.setStatusText(WebInspector.UIString("Hit %s to reloa d and capture filmstrip.", WebInspector.shortcutRegistry.shortcutDescriptorsForA ction("main.reload")[0].name));
328 },
329
330 /**
331 * @override
332 * @return {!Array.<!Element>}
333 */
334 elementsToRestoreScrollPositionsFor: function()
335 {
336 return this._networkLogView.elementsToRestoreScrollPositionsFor();
337 },
338
339 /**
340 * @override
341 * @return {!WebInspector.SearchableView}
342 */
343 searchableView: function()
344 {
345 return this._searchableView;
346 },
347
348 /**
349 * @override
350 * @param {!KeyboardEvent} event
351 */
352 handleShortcut: function(event)
353 {
354 if (this._networkItemView && event.keyCode === WebInspector.KeyboardShor tcut.Keys.Esc.code) {
355 this._showRequest(null);
356 event.handled = true;
357 return;
358 }
359
360 WebInspector.Panel.prototype.handleShortcut.call(this, event);
361 },
362
363 wasShown: function()
364 {
365 WebInspector.context.setFlavor(WebInspector.NetworkPanel, this);
366 },
367
368 willHide: function()
369 {
370 WebInspector.context.setFlavor(WebInspector.NetworkPanel, null);
371 },
372
373 /**
374 * @param {!WebInspector.NetworkRequest} request
375 */
376 revealAndHighlightRequest: function(request)
377 {
378 this._showRequest(null);
379 if (request)
380 this._networkLogView.revealAndHighlightRequest(request);
381 },
382
383 /**
384 * @param {!WebInspector.Event} event
385 */
386 _onRowSizeChanged: function(event)
387 {
388 this._updateUI();
389 },
390
391 /**
392 * @param {!WebInspector.Event} event
393 */
394 _onSearchCountUpdated: function(event)
395 {
396 var count = /** @type {number} */ (event.data);
397 this._searchableView.updateSearchMatchesCount(count);
398 },
399
400 /**
401 * @param {!WebInspector.Event} event
402 */
403 _onSearchIndexUpdated: function(event)
404 {
405 var index = /** @type {number} */ (event.data);
406 this._searchableView.updateCurrentMatchIndex(index);
407 },
408
409 /**
410 * @param {!WebInspector.Event} event
411 */
412 _onRequestSelected: function(event)
413 {
414 var request = /** @type {?WebInspector.NetworkRequest} */ (event.data);
415 this._showRequest(request);
416 },
417
418 /**
419 * @param {?WebInspector.NetworkRequest} request
420 */
421 _showRequest: function(request)
422 {
423 if (this._networkItemView) {
424 this._networkItemView.detach();
425 this._networkItemView = null;
426 }
427
428 if (request) {
429 this._networkItemView = new WebInspector.NetworkItemView(request, th is._networkLogView.timeCalculator());
430 this._networkItemView.leftToolbar().appendToolbarItem(new WebInspect or.ToolbarItem(this._closeButtonElement));
431 this._networkItemView.show(this._detailsWidget.element);
432 this._splitWidget.showBoth();
433 } else {
434 this._splitWidget.hideMain();
435 this._networkLogView.clearSelection();
436 }
437 this._updateUI();
438 },
439
440 _updateUI: function()
441 {
442 this._detailsWidget.element.classList.toggle("network-details-view-tall- header", this._networkLogLargeRowsSetting.get());
443 this._networkLogView.switchViewMode(!this._splitWidget.isResizable());
444 },
445
446 /**
447 * @override
448 * @param {!WebInspector.SearchableView.SearchConfig} searchConfig
449 * @param {boolean} shouldJump
450 * @param {boolean=} jumpBackwards
451 */
452 performSearch: function(searchConfig, shouldJump, jumpBackwards)
453 {
454 this._networkLogView.performSearch(searchConfig, shouldJump, jumpBackwar ds);
455 },
456
457 /**
458 * @override
459 */
460 jumpToPreviousSearchResult: function()
461 {
462 this._networkLogView.jumpToPreviousSearchResult();
463 },
464
465 /**
466 * @override
467 * @return {boolean}
468 */
469 supportsCaseSensitiveSearch: function()
470 {
471 return false;
472 },
473
474 /**
475 * @override
476 * @return {boolean}
477 */
478 supportsRegexSearch: function()
479 {
480 return false;
481 },
482
483 /**
484 * @override
485 */
486 jumpToNextSearchResult: function()
487 {
488 this._networkLogView.jumpToNextSearchResult();
489 },
490
491 /**
492 * @override
493 */
494 searchCanceled: function()
495 {
496 this._networkLogView.searchCanceled();
497 },
498
499 /**
500 * @override
501 * @param {!Event} event
502 * @param {!WebInspector.ContextMenu} contextMenu
503 * @param {!Object} target
504 * @this {WebInspector.NetworkPanel} 516 * @this {WebInspector.NetworkPanel}
505 */ 517 */
506 appendApplicableItems: function(event, contextMenu, target) 518 function reveal(request) {
507 { 519 WebInspector.viewManager.showView('network').then(this.revealAndHighlightR equest.bind(this, request));
508 /** 520 }
509 * @this {WebInspector.NetworkPanel}
510 */
511 function reveal(request)
512 {
513 WebInspector.viewManager.showView("network").then(this.revealAndHigh lightRequest.bind(this, request));
514 }
515
516 /**
517 * @this {WebInspector.NetworkPanel}
518 */
519 function appendRevealItem(request)
520 {
521 contextMenu.appendItem(WebInspector.UIString.capitalize("Reveal in N etwork ^panel"), reveal.bind(this, request));
522 }
523
524 if (event.target.isSelfOrDescendant(this.element))
525 return;
526
527 if (target instanceof WebInspector.Resource) {
528 var resource = /** @type {!WebInspector.Resource} */ (target);
529 if (resource.request)
530 appendRevealItem.call(this, resource.request);
531 return;
532 }
533 if (target instanceof WebInspector.UISourceCode) {
534 var uiSourceCode = /** @type {!WebInspector.UISourceCode} */ (target );
535 var resource = WebInspector.resourceForURL(uiSourceCode.url());
536 if (resource && resource.request)
537 appendRevealItem.call(this, resource.request);
538 return;
539 }
540
541 if (!(target instanceof WebInspector.NetworkRequest))
542 return;
543 var request = /** @type {!WebInspector.NetworkRequest} */ (target);
544 if (this._networkItemView && this._networkItemView.isShowing() && this._ networkItemView.request() === request)
545 return;
546
547 appendRevealItem.call(this, request);
548 },
549 521
550 /** 522 /**
551 * @param {!WebInspector.Event} event 523 * @this {WebInspector.NetworkPanel}
552 */ 524 */
553 _onFilmFrameSelected: function(event) 525 function appendRevealItem(request) {
554 { 526 contextMenu.appendItem(WebInspector.UIString.capitalize('Reveal in Network ^panel'), reveal.bind(this, request));
555 var timestamp = /** @type {number} */ (event.data); 527 }
556 this._overviewPane.requestWindowTimes(0, timestamp); 528
557 }, 529 if (event.target.isSelfOrDescendant(this.element))
558 530 return;
559 /** 531
560 * @param {!WebInspector.Event} event 532 if (target instanceof WebInspector.Resource) {
561 */ 533 var resource = /** @type {!WebInspector.Resource} */ (target);
562 _onFilmFrameEnter: function(event) 534 if (resource.request)
563 { 535 appendRevealItem.call(this, resource.request);
564 var timestamp = /** @type {number} */ (event.data); 536 return;
565 this._networkOverview.selectFilmStripFrame(timestamp); 537 }
566 this._networkLogView.selectFilmStripFrame(timestamp / 1000); 538 if (target instanceof WebInspector.UISourceCode) {
567 }, 539 var uiSourceCode = /** @type {!WebInspector.UISourceCode} */ (target);
568 540 var resource = WebInspector.resourceForURL(uiSourceCode.url());
569 /** 541 if (resource && resource.request)
570 * @param {!WebInspector.Event} event 542 appendRevealItem.call(this, resource.request);
571 */ 543 return;
572 _onFilmFrameExit: function(event) 544 }
573 { 545
574 this._networkOverview.clearFilmStripFrame(); 546 if (!(target instanceof WebInspector.NetworkRequest))
575 this._networkLogView.clearFilmStripFrame(); 547 return;
576 }, 548 var request = /** @type {!WebInspector.NetworkRequest} */ (target);
577 549 if (this._networkItemView && this._networkItemView.isShowing() && this._netw orkItemView.request() === request)
578 /** 550 return;
579 * @param {!WebInspector.Event} event 551
580 */ 552 appendRevealItem.call(this, request);
581 _onUpdateRequest: function(event) 553 }
582 { 554
583 var request = /** @type {!WebInspector.NetworkRequest} */ (event.data); 555 /**
584 this._calculator.updateBoundaries(request); 556 * @param {!WebInspector.Event} event
585 // FIXME: Unify all time units across the frontend! 557 */
586 this._overviewPane.setBounds(this._calculator.minimumBoundary() * 1000, this._calculator.maximumBoundary() * 1000); 558 _onFilmFrameSelected(event) {
587 this._networkOverview.updateRequest(request); 559 var timestamp = /** @type {number} */ (event.data);
588 this._overviewPane.scheduleUpdate(); 560 this._overviewPane.requestWindowTimes(0, timestamp);
589 }, 561 }
590 562
591 __proto__: WebInspector.Panel.prototype 563 /**
564 * @param {!WebInspector.Event} event
565 */
566 _onFilmFrameEnter(event) {
567 var timestamp = /** @type {number} */ (event.data);
568 this._networkOverview.selectFilmStripFrame(timestamp);
569 this._networkLogView.selectFilmStripFrame(timestamp / 1000);
570 }
571
572 /**
573 * @param {!WebInspector.Event} event
574 */
575 _onFilmFrameExit(event) {
576 this._networkOverview.clearFilmStripFrame();
577 this._networkLogView.clearFilmStripFrame();
578 }
579
580 /**
581 * @param {!WebInspector.Event} event
582 */
583 _onUpdateRequest(event) {
584 var request = /** @type {!WebInspector.NetworkRequest} */ (event.data);
585 this._calculator.updateBoundaries(request);
586 // FIXME: Unify all time units across the frontend!
587 this._overviewPane.setBounds(this._calculator.minimumBoundary() * 1000, this ._calculator.maximumBoundary() * 1000);
588 this._networkOverview.updateRequest(request);
589 this._overviewPane.scheduleUpdate();
590 }
592 }; 591 };
593 592
593 WebInspector.NetworkPanel.displayScreenshotDelay = 1000;
594
594 /** 595 /**
595 * @constructor
596 * @implements {WebInspector.ContextMenu.Provider} 596 * @implements {WebInspector.ContextMenu.Provider}
597 * @unrestricted
597 */ 598 */
598 WebInspector.NetworkPanel.ContextMenuProvider = function() 599 WebInspector.NetworkPanel.ContextMenuProvider = class {
599 { 600 /**
601 * @override
602 * @param {!Event} event
603 * @param {!WebInspector.ContextMenu} contextMenu
604 * @param {!Object} target
605 */
606 appendApplicableItems(event, contextMenu, target) {
607 WebInspector.NetworkPanel._instance().appendApplicableItems(event, contextMe nu, target);
608 }
600 }; 609 };
601 610
602 WebInspector.NetworkPanel.ContextMenuProvider.prototype = { 611 /**
603 /** 612 * @implements {WebInspector.Revealer}
604 * @override 613 * @unrestricted
605 * @param {!Event} event 614 */
606 * @param {!WebInspector.ContextMenu} contextMenu 615 WebInspector.NetworkPanel.RequestRevealer = class {
607 * @param {!Object} target 616 /**
608 */ 617 * @override
609 appendApplicableItems: function(event, contextMenu, target) 618 * @param {!Object} request
610 { 619 * @return {!Promise}
611 WebInspector.NetworkPanel._instance().appendApplicableItems(event, conte xtMenu, target); 620 */
612 } 621 reveal(request) {
622 if (!(request instanceof WebInspector.NetworkRequest))
623 return Promise.reject(new Error('Internal error: not a network request'));
624 var panel = WebInspector.NetworkPanel._instance();
625 return WebInspector.viewManager.showView('network').then(panel.revealAndHigh lightRequest.bind(panel, request));
626 }
613 }; 627 };
614 628
629
615 /** 630 /**
616 * @constructor 631 * @implements {WebInspector.TracingManagerClient}
617 * @implements {WebInspector.Revealer} 632 * @unrestricted
618 */ 633 */
619 WebInspector.NetworkPanel.RequestRevealer = function() 634 WebInspector.NetworkPanel.FilmStripRecorder = class {
620 { 635 /**
621 }; 636 * @param {!WebInspector.NetworkTimeCalculator} timeCalculator
622 637 * @param {!WebInspector.FilmStripView} filmStripView
623 WebInspector.NetworkPanel.RequestRevealer.prototype = { 638 */
624 /** 639 constructor(timeCalculator, filmStripView) {
625 * @override
626 * @param {!Object} request
627 * @return {!Promise}
628 */
629 reveal: function(request)
630 {
631 if (!(request instanceof WebInspector.NetworkRequest))
632 return Promise.reject(new Error("Internal error: not a network reque st"));
633 var panel = WebInspector.NetworkPanel._instance();
634 return WebInspector.viewManager.showView("network").then(panel.revealAnd HighlightRequest.bind(panel, request));
635 }
636 };
637
638 /**
639 * @param {!Array<{filterType: !WebInspector.NetworkLogView.FilterType, filterVa lue: string}>} filters
640 */
641 WebInspector.NetworkPanel.revealAndFilter = function(filters)
642 {
643 var panel = WebInspector.NetworkPanel._instance();
644 var filterString = "";
645 for (var filter of filters)
646 filterString += `${filter.filterType}:${filter.filterValue} `;
647 panel._networkLogView.setTextFilterValue(filterString);
648 WebInspector.viewManager.showView("network");
649 };
650
651 /**
652 * @return {!WebInspector.NetworkPanel}
653 */
654 WebInspector.NetworkPanel._instance = function()
655 {
656 return /** @type {!WebInspector.NetworkPanel} */ (self.runtime.sharedInstanc e(WebInspector.NetworkPanel));
657 };
658
659 /**
660 * @constructor
661 * @implements {WebInspector.TracingManagerClient}
662 * @param {!WebInspector.NetworkTimeCalculator} timeCalculator
663 * @param {!WebInspector.FilmStripView} filmStripView
664 */
665 WebInspector.NetworkPanel.FilmStripRecorder = function(timeCalculator, filmStrip View)
666 {
667 this._timeCalculator = timeCalculator; 640 this._timeCalculator = timeCalculator;
668 this._filmStripView = filmStripView; 641 this._filmStripView = filmStripView;
642 }
643
644 /**
645 * @override
646 */
647 tracingStarted() {
648 }
649
650 /**
651 * @override
652 * @param {!Array.<!WebInspector.TracingManager.EventPayload>} events
653 */
654 traceEventsCollected(events) {
655 if (this._tracingModel)
656 this._tracingModel.addEvents(events);
657 }
658
659 /**
660 * @override
661 */
662 tracingComplete() {
663 if (!this._tracingModel)
664 return;
665 this._tracingModel.tracingComplete();
666 WebInspector.targetManager.resumeReload(this._target);
667 this._target = null;
668 this._callback(new WebInspector.FilmStripModel(this._tracingModel, this._tim eCalculator.minimumBoundary() * 1000));
669 delete this._callback;
670 }
671
672 /**
673 * @override
674 */
675 tracingBufferUsage() {
676 }
677
678 /**
679 * @override
680 * @param {number} progress
681 */
682 eventsRetrievalProgress(progress) {
683 }
684
685 startRecording() {
686 this._filmStripView.reset();
687 this._filmStripView.setStatusText(WebInspector.UIString('Recording frames... '));
688 if (this._target)
689 return;
690
691 this._target = WebInspector.targetManager.mainTarget();
692 if (this._tracingModel)
693 this._tracingModel.reset();
694 else
695 this._tracingModel = new WebInspector.TracingModel(new WebInspector.TempFi leBackingStorage('tracing'));
696 this._target.tracingManager.start(this, '-*,disabled-by-default-devtools.scr eenshot', '');
697 }
698
699 /**
700 * @return {boolean}
701 */
702 isRecording() {
703 return !!this._target;
704 }
705
706 /**
707 * @param {function(?WebInspector.FilmStripModel)} callback
708 */
709 stopRecording(callback) {
710 if (!this._target)
711 return;
712
713 this._target.tracingManager.stop();
714 WebInspector.targetManager.suspendReload(this._target);
715 this._callback = callback;
716 this._filmStripView.setStatusText(WebInspector.UIString('Fetching frames...' ));
717 }
669 }; 718 };
670 719
671 WebInspector.NetworkPanel.FilmStripRecorder.prototype = { 720 /**
672 /** 721 * @implements {WebInspector.ActionDelegate}
673 * @override 722 * @unrestricted
674 */ 723 */
675 tracingStarted: function() 724 WebInspector.NetworkPanel.RecordActionDelegate = class {
676 { 725 /**
677 }, 726 * @override
678 727 * @param {!WebInspector.Context} context
679 /** 728 * @param {string} actionId
680 * @override 729 * @return {boolean}
681 * @param {!Array.<!WebInspector.TracingManager.EventPayload>} events 730 */
682 */ 731 handleAction(context, actionId) {
683 traceEventsCollected: function(events) 732 var panel = WebInspector.context.flavor(WebInspector.NetworkPanel);
684 { 733 console.assert(panel && panel instanceof WebInspector.NetworkPanel);
685 if (this._tracingModel) 734 panel._toggleRecording();
686 this._tracingModel.addEvents(events); 735 return true;
687 }, 736 }
688
689 /**
690 * @override
691 */
692 tracingComplete: function()
693 {
694 if (!this._tracingModel)
695 return;
696 this._tracingModel.tracingComplete();
697 WebInspector.targetManager.resumeReload(this._target);
698 this._target = null;
699 this._callback(new WebInspector.FilmStripModel(this._tracingModel, this. _timeCalculator.minimumBoundary() * 1000));
700 delete this._callback;
701 },
702
703 /**
704 * @override
705 */
706 tracingBufferUsage: function()
707 {
708 },
709
710 /**
711 * @override
712 * @param {number} progress
713 */
714 eventsRetrievalProgress: function(progress)
715 {
716 },
717
718 startRecording: function()
719 {
720 this._filmStripView.reset();
721 this._filmStripView.setStatusText(WebInspector.UIString("Recording frame s..."));
722 if (this._target)
723 return;
724
725 this._target = WebInspector.targetManager.mainTarget();
726 if (this._tracingModel)
727 this._tracingModel.reset();
728 else
729 this._tracingModel = new WebInspector.TracingModel(new WebInspector. TempFileBackingStorage("tracing"));
730 this._target.tracingManager.start(this, "-*,disabled-by-default-devtools .screenshot", "");
731 },
732
733 /**
734 * @return {boolean}
735 */
736 isRecording: function()
737 {
738 return !!this._target;
739 },
740
741 /**
742 * @param {function(?WebInspector.FilmStripModel)} callback
743 */
744 stopRecording: function(callback)
745 {
746 if (!this._target)
747 return;
748
749 this._target.tracingManager.stop();
750 WebInspector.targetManager.suspendReload(this._target);
751 this._callback = callback;
752 this._filmStripView.setStatusText(WebInspector.UIString("Fetching frames ..."));
753 }
754 }; 737 };
755
756 /**
757 * @constructor
758 * @implements {WebInspector.ActionDelegate}
759 */
760 WebInspector.NetworkPanel.RecordActionDelegate = function()
761 {
762 };
763 WebInspector.NetworkPanel.RecordActionDelegate.prototype = {
764 /**
765 * @override
766 * @param {!WebInspector.Context} context
767 * @param {string} actionId
768 * @return {boolean}
769 */
770 handleAction: function(context, actionId)
771 {
772 var panel = WebInspector.context.flavor(WebInspector.NetworkPanel);
773 console.assert(panel && panel instanceof WebInspector.NetworkPanel);
774 panel._toggleRecording();
775 return true;
776 }
777 };
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698