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

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

Issue 2806993002: DevTools: WebSocketFrameView - Add frames display control toolbar (Closed)
Patch Set: wip Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « AUTHORS ('k') | third_party/WebKit/Source/devtools/front_end/network/webSocketFrameView.css » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2012 Research In Motion Limited. All rights reserved. 2 * Copyright (C) 2012 Research In Motion Limited. All rights reserved.
3 * 3 *
4 * This library is free software; you can redistribute it and/or 4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public 5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either 6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version. 7 * version 2 of the License, or (at your option) any later version.
8 * 8 *
9 * This library is distributed in the hope that it will be useful, 9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details. 12 * Lesser General Public License for more details.
13 * 13 *
14 * You should have received a copy of the GNU Lesser General Public 14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software 15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 US A 16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 US A
17 */ 17 */
18 18
19 /** 19 /**
20 * @unrestricted 20 * @unrestricted
21 */ 21 */
22 Network.ResourceWebSocketFrameView = class extends UI.VBox { 22 Network.ResourceWebSocketFrameView = class extends UI.VBox {
23 /** 23 /**
24 * @param {!SDK.NetworkRequest} request 24 * @param {!SDK.NetworkRequest} request
25 */ 25 */
26 constructor(request) { 26 constructor(request) {
dgozman 2017/05/04 17:55:32 When I switch to another request, and then back to
27 super(); 27 super();
28 this.registerRequiredCSS('network/webSocketFrameView.css'); 28 this.registerRequiredCSS('network/webSocketFrameView.css');
29 this.element.classList.add('websocket-frame-view'); 29 this.element.classList.add('websocket-frame-view');
30 this._request = request; 30 this._request = request;
31 31
32 this._splitWidget = new UI.SplitWidget(false, true, 'resourceWebSocketFrameS plitViewState'); 32 this._splitWidget = new UI.SplitWidget(false, true, 'resourceWebSocketFrameS plitViewState');
33 this._splitWidget.show(this.element); 33 this._splitWidget.show(this.element);
34 34
35 var columns = /** @type {!Array<!DataGrid.DataGrid.ColumnDescriptor>} */ ([ 35 var columns = /** @type {!Array<!DataGrid.DataGrid.ColumnDescriptor>} */ ([
36 {id: 'data', title: Common.UIString('Data'), sortable: false, weight: 88}, { 36 {id: 'data', title: Common.UIString('Data'), sortable: false, weight: 88}, {
37 id: 'length', 37 id: 'length',
38 title: Common.UIString('Length'), 38 title: Common.UIString('Length'),
39 sortable: false, 39 sortable: false,
40 align: DataGrid.DataGrid.Align.Right, 40 align: DataGrid.DataGrid.Align.Right,
41 weight: 5 41 weight: 5
42 }, 42 },
43 {id: 'time', title: Common.UIString('Time'), sortable: true, weight: 7} 43 {id: 'time', title: Common.UIString('Time'), sortable: true, weight: 7}
44 ]); 44 ]);
45 45
46 this._dataGrid = new DataGrid.SortableDataGrid(columns); 46 this._dataGrid = new DataGrid.SortableDataGrid(columns);
47 this._dataGrid.setRowContextMenuCallback(onRowContextMenu); 47 this._dataGrid.setRowContextMenuCallback(onRowContextMenu.bind(this));
48 this._dataGrid.setStickToBottom(true); 48 this._dataGrid.setStickToBottom(true);
49 this._dataGrid.setCellClass('websocket-frame-view-td'); 49 this._dataGrid.setCellClass('websocket-frame-view-td');
50 this._timeComparator = 50 this._timeComparator =
51 /** @type {function(!Network.ResourceWebSocketFrameNode, !Network.Resour ceWebSocketFrameNode):number} */ ( 51 /** @type {function(!Network.ResourceWebSocketFrameNode, !Network.Resour ceWebSocketFrameNode):number} */ (
52 Network.ResourceWebSocketFrameNodeTimeComparator); 52 Network.ResourceWebSocketFrameNodeTimeComparator);
53 this._dataGrid.sortNodes(this._timeComparator, false); 53 this._dataGrid.sortNodes(this._timeComparator, false);
54 this._dataGrid.markColumnAsSortedBy('time', DataGrid.DataGrid.Order.Ascendin g); 54 this._dataGrid.markColumnAsSortedBy('time', DataGrid.DataGrid.Order.Ascendin g);
55 this._dataGrid.addEventListener(DataGrid.DataGrid.Events.SortingChanged, thi s._sortItems, this); 55 this._dataGrid.addEventListener(DataGrid.DataGrid.Events.SortingChanged, thi s._sortItems, this);
56 56
57 this._dataGrid.setName('ResourceWebSocketFrameView'); 57 this._dataGrid.setName('ResourceWebSocketFrameView');
58 this._dataGrid.addEventListener(DataGrid.DataGrid.Events.SelectedNode, this. _onFrameSelected, this); 58 this._dataGrid.addEventListener(DataGrid.DataGrid.Events.SelectedNode, this. _onFrameSelected, this);
59 this._dataGrid.addEventListener(DataGrid.DataGrid.Events.DeselectedNode, thi s._onFrameDeselected, this); 59 this._dataGrid.addEventListener(DataGrid.DataGrid.Events.DeselectedNode, thi s._onFrameDeselected, this);
60 this._splitWidget.setMainWidget(this._dataGrid.asWidget());
61 60
62 var view = new UI.EmptyWidget('Select frame to browse its content.'); 61 this._mainToolbar = new UI.Toolbar('');
63 this._splitWidget.setSidebarWidget(view); 62
63 this._clearAllButton = new UI.ToolbarButton(Common.UIString('Clear All'), 'l argeicon-clear');
64 this._clearAllButton.addEventListener(UI.ToolbarButton.Events.Click, this._c learFrames, this);
65 this._mainToolbar.appendToolbarItem(this._clearAllButton);
66 this._clearFrameOffset = 0;
67
68 this._filterTypeCombobox = new UI.ToolbarComboBox(this._updateFilterSetting. bind(this));
69 Network.ResourceWebSocketFrameView._filterTypes.forEach(filterItem => {
dgozman 2017/05/04 17:55:32 nit: for (var filterItem of Network.ResourceWebSo
70 var option = this._filterTypeCombobox.createOption(filterItem.label, filte rItem.label, filterItem.name);
71 this._filterTypeCombobox.addOption(option);
72 });
73 this._mainToolbar.appendToolbarItem(this._filterTypeCombobox);
74
75 this._filterTextInput = new UI.ToolbarInput(Common.UIString('Filter'), 0.4, undefined, true);
dgozman 2017/05/04 17:55:32 Let's have a placeholder mentioning it's a regex.
76 this._filterTextInput.addEventListener(UI.ToolbarInput.Event.TextChanged, th is._updateFilterSetting, this);
77 this._mainToolbar.appendToolbarItem(this._filterTextInput);
78
79 var mainContainer = new UI.VBox();
80 mainContainer.element.appendChild(this._mainToolbar.element);
81 this._dataGrid.asWidget().show(mainContainer.element);
82 this._splitWidget.setMainWidget(mainContainer);
83
84 this._frameEmptyWidget = new UI.EmptyWidget(Common.UIString('Select frame to browse its content.'));
85 this._splitWidget.setSidebarWidget(this._frameEmptyWidget);
64 86
65 /** @type {?Network.ResourceWebSocketFrameNode} */ 87 /** @type {?Network.ResourceWebSocketFrameNode} */
66 this._selectedNode = null; 88 this._selectedNode = null;
67 89
68 /** 90 /**
69 * @param {!UI.ContextMenu} contextMenu 91 * @param {!UI.ContextMenu} contextMenu
70 * @param {!DataGrid.DataGridNode} node 92 * @param {!DataGrid.DataGridNode} node
93 * @this {Network.ResourceWebSocketFrameView}
71 */ 94 */
72 function onRowContextMenu(contextMenu, node) { 95 function onRowContextMenu(contextMenu, node) {
73 contextMenu.appendItem( 96 contextMenu.appendItem(
74 Common.UIString.capitalize('Copy ^message'), 97 Common.UIString.capitalize('Copy ^message'),
75 InspectorFrontendHost.copyText.bind(InspectorFrontendHost, node.data.d ata)); 98 InspectorFrontendHost.copyText.bind(InspectorFrontendHost, node.data.d ata));
99 contextMenu.appendSeparator();
100 contextMenu.appendItem(Common.UIString.capitalize('Clear ^all'), this._cle arFrames.bind(this));
76 } 101 }
77 } 102 }
78 103
79 /** 104 /**
80 * @param {number} opCode 105 * @param {number} opCode
81 * @param {boolean} mask 106 * @param {boolean} mask
82 * @return {string} 107 * @return {string}
83 */ 108 */
84 static opCodeDescription(opCode, mask) { 109 static opCodeDescription(opCode, mask) {
85 var rawDescription = Network.ResourceWebSocketFrameView.opCodeDescriptions[o pCode] || ''; 110 var rawDescription = Network.ResourceWebSocketFrameView.opCodeDescriptions[o pCode] || '';
(...skipping 14 matching lines...) Expand all
100 */ 125 */
101 willHide() { 126 willHide() {
102 this._request.removeEventListener(SDK.NetworkRequest.Events.WebsocketFrameAd ded, this._frameAdded, this); 127 this._request.removeEventListener(SDK.NetworkRequest.Events.WebsocketFrameAd ded, this._frameAdded, this);
103 } 128 }
104 129
105 /** 130 /**
106 * @param {!Common.Event} event 131 * @param {!Common.Event} event
107 */ 132 */
108 _frameAdded(event) { 133 _frameAdded(event) {
109 var frame = /** @type {!SDK.NetworkRequest.WebSocketFrame} */ (event.data); 134 var frame = /** @type {!SDK.NetworkRequest.WebSocketFrame} */ (event.data);
135 if (!this._frameFilter(frame))
136 return;
110 this._dataGrid.insertChild(new Network.ResourceWebSocketFrameNode(this._requ est.url(), frame)); 137 this._dataGrid.insertChild(new Network.ResourceWebSocketFrameNode(this._requ est.url(), frame));
111 } 138 }
112 139
113 /** 140 /**
114 * @param {!Common.Event} event 141 * @param {!SDK.NetworkRequest.WebSocketFrame} frame
142 * @return {boolean}
143 */
144 _frameFilter(frame) {
145 if (this._filterType && frame.type !== this._filterType)
146 return false;
147 return !this._filterRegex || this._filterRegex.test(frame.text);
148 }
149
150 _clearFrames() {
151 this._clearFrameOffset = this._request.frames().length;
dgozman 2017/05/04 17:55:32 // TODO(allada): actually remove frames from reque
dgozman 2017/05/05 19:04:44 What about this one?
152 this.refresh();
153 }
154
155 _updateFilterSetting() {
156 var text = this._filterTextInput.value();
157 var type = this._filterTypeCombobox.selectedOption().value;
158 this._filterRegex = text ? new RegExp(text.escapeForRegExp(), 'i') : null;
159 this._filterType = type === 'all' ? null : type;
160 this.refresh();
161 }
162
163 /**
164 * @param {!Common.Event} event
115 */ 165 */
116 _onFrameSelected(event) { 166 _onFrameSelected(event) {
117 var selectedNode = /** @type {!Network.ResourceWebSocketFrameNode} */ (event .data); 167 var selectedNode = /** @type {!Network.ResourceWebSocketFrameNode} */ (event .data);
118 this._currentSelectedNode = selectedNode; 168 this._currentSelectedNode = selectedNode;
119 var contentProvider = selectedNode.contentProvider(); 169 var contentProvider = selectedNode.contentProvider();
120 contentProvider.requestContent().then(contentHandler.bind(this)); 170 contentProvider.requestContent().then(contentHandler.bind(this));
121 171
122 /** 172 /**
123 * @param {(string|null)} content 173 * @param {(string|null)} content
124 * @this {Network.ResourceWebSocketFrameView} 174 * @this {Network.ResourceWebSocketFrameView}
(...skipping 16 matching lines...) Expand all
141 else 191 else
142 this._splitWidget.setSidebarWidget(new SourceFrame.ResourceSourceFrame(c ontentProvider)); 192 this._splitWidget.setSidebarWidget(new SourceFrame.ResourceSourceFrame(c ontentProvider));
143 } 193 }
144 } 194 }
145 195
146 /** 196 /**
147 * @param {!Common.Event} event 197 * @param {!Common.Event} event
148 */ 198 */
149 _onFrameDeselected(event) { 199 _onFrameDeselected(event) {
150 this._currentSelectedNode = null; 200 this._currentSelectedNode = null;
201 this._splitWidget.setSidebarWidget(this._frameEmptyWidget);
151 } 202 }
152 203
153 refresh() { 204 refresh() {
154 this._dataGrid.rootNode().removeChildren(); 205 this._dataGrid.rootNode().removeChildren();
206
207 var url = this._request.url();
155 var frames = this._request.frames(); 208 var frames = this._request.frames();
156 for (var i = 0; i < frames.length; ++i) 209 frames = frames.slice(this._clearFrameOffset);
157 this._dataGrid.insertChild(new Network.ResourceWebSocketFrameNode(this._re quest.url(), frames[i])); 210 frames = frames.filter(this._frameFilter.bind(this));
211 frames.forEach(frame => this._dataGrid.insertChild(new Network.ResourceWebSo cketFrameNode(url, frame)));
158 } 212 }
159 213
160 _sortItems() { 214 _sortItems() {
161 this._dataGrid.sortNodes(this._timeComparator, !this._dataGrid.isSortOrderAs cending()); 215 this._dataGrid.sortNodes(this._timeComparator, !this._dataGrid.isSortOrderAs cending());
162 } 216 }
163 }; 217 };
164 218
165 /** @enum {number} */ 219 /** @enum {number} */
166 Network.ResourceWebSocketFrameView.OpCodes = { 220 Network.ResourceWebSocketFrameView.OpCodes = {
167 ContinuationFrame: 0, 221 ContinuationFrame: 0,
(...skipping 10 matching lines...) Expand all
178 var map = []; 232 var map = [];
179 map[opCodes.ContinuationFrame] = 'Continuation Frame'; 233 map[opCodes.ContinuationFrame] = 'Continuation Frame';
180 map[opCodes.TextFrame] = 'Text Frame'; 234 map[opCodes.TextFrame] = 'Text Frame';
181 map[opCodes.BinaryFrame] = 'Binary Frame'; 235 map[opCodes.BinaryFrame] = 'Binary Frame';
182 map[opCodes.ContinuationFrame] = 'Connection Close Frame'; 236 map[opCodes.ContinuationFrame] = 'Connection Close Frame';
183 map[opCodes.PingFrame] = 'Ping Frame'; 237 map[opCodes.PingFrame] = 'Ping Frame';
184 map[opCodes.PongFrame] = 'Pong Frame'; 238 map[opCodes.PongFrame] = 'Pong Frame';
185 return map; 239 return map;
186 })(); 240 })();
187 241
242 /** @type {!Array<!UI.NamedBitSetFilterUI.Item>} */
243 Network.ResourceWebSocketFrameView._filterTypes = [
244 {name: 'all', label: Common.UIString('All')},
245 {name: 'send', label: Common.UIString('Send')},
246 {name: 'receive', label: Common.UIString('Receive')},
247 ];
188 248
189 /** 249 /**
190 * @unrestricted 250 * @unrestricted
191 */ 251 */
192 Network.ResourceWebSocketFrameNode = class extends DataGrid.SortableDataGridNode { 252 Network.ResourceWebSocketFrameNode = class extends DataGrid.SortableDataGridNode {
193 /** 253 /**
194 * @param {string} url 254 * @param {string} url
195 * @param {!SDK.NetworkRequest.WebSocketFrame} frame 255 * @param {!SDK.NetworkRequest.WebSocketFrame} frame
196 */ 256 */
197 constructor(url, frame) { 257 constructor(url, frame) {
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
246 }; 306 };
247 307
248 /** 308 /**
249 * @param {!Network.ResourceWebSocketFrameNode} a 309 * @param {!Network.ResourceWebSocketFrameNode} a
250 * @param {!Network.ResourceWebSocketFrameNode} b 310 * @param {!Network.ResourceWebSocketFrameNode} b
251 * @return {number} 311 * @return {number}
252 */ 312 */
253 Network.ResourceWebSocketFrameNodeTimeComparator = function(a, b) { 313 Network.ResourceWebSocketFrameNodeTimeComparator = function(a, b) {
254 return a._frame.time - b._frame.time; 314 return a._frame.time - b._frame.time;
255 }; 315 };
OLDNEW
« no previous file with comments | « AUTHORS ('k') | third_party/WebKit/Source/devtools/front_end/network/webSocketFrameView.css » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698