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

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
(...skipping 26 matching lines...) Expand all
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._clearAllButton = new UI.ToolbarButton(Common.UIString('Clear All'), 'l argeicon-clear');
63 this._splitWidget.setSidebarWidget(view); 62 this._clearAllButton.addEventListener(UI.ToolbarButton.Events.Click, this._c learFrames, this);
63 this._clearFrameOffset = 0;
64
65 this._filterTextInput = new UI.ToolbarInput(Common.UIString('Filter'), 0.4, undefined, true);
66 this._filterTextInput.addEventListener(UI.ToolbarInput.Event.TextChanged, th is._updateFilterSetting, this);
67
68 this._filterTypeCombobox = new UI.ToolbarComboBox(this._updateFilterSetting. bind(this));
69 Network.ResourceWebSocketFrameView._filterTypes.forEach(v => {
allada 2017/05/04 01:41:30 nit: rename "v" to "filterItem"
70 var option = this._filterTypeCombobox.createOption(v.label, v.label, v.nam e);
71 this._filterTypeCombobox.addOption(option);
72 });
73
74 var toolbarItems = [this._clearAllButton, this._filterTypeCombobox, this._fi lterTextInput];
75 this._mainToolbar = new UI.Toolbar('');
76 for (var item of toolbarItems)
allada 2017/05/04 01:41:30 nit: lets do these as separate lines (since it's t
77 this._mainToolbar.appendToolbarItem(item);
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 var regex = this._filterRegex;
146 var type = this._filterType;
147 return (!regex || regex.test(frame.text)) && (!type || frame.type === type);
allada 2017/05/04 01:41:30 nit: lets reverse the logic on this, since type ch
148 }
149
150 _clearFrames() {
151 this._clearFrameOffset = this._request.frames().length;
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 Network.ResourceWebSocketFrameView._filterTypes = [
allada 2017/05/04 01:41:30 nit: Please add this above this line: /** @type {!
243 {name: 'all', label: Common.UIString('All')},
244 {name: 'send', label: Common.UIString('Send')},
245 {name: 'receive', label: Common.UIString('Receive')},
246 ];
188 247
189 /** 248 /**
190 * @unrestricted 249 * @unrestricted
191 */ 250 */
192 Network.ResourceWebSocketFrameNode = class extends DataGrid.SortableDataGridNode { 251 Network.ResourceWebSocketFrameNode = class extends DataGrid.SortableDataGridNode {
193 /** 252 /**
194 * @param {string} url 253 * @param {string} url
195 * @param {!SDK.NetworkRequest.WebSocketFrame} frame 254 * @param {!SDK.NetworkRequest.WebSocketFrame} frame
196 */ 255 */
197 constructor(url, frame) { 256 constructor(url, frame) {
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
246 }; 305 };
247 306
248 /** 307 /**
249 * @param {!Network.ResourceWebSocketFrameNode} a 308 * @param {!Network.ResourceWebSocketFrameNode} a
250 * @param {!Network.ResourceWebSocketFrameNode} b 309 * @param {!Network.ResourceWebSocketFrameNode} b
251 * @return {number} 310 * @return {number}
252 */ 311 */
253 Network.ResourceWebSocketFrameNodeTimeComparator = function(a, b) { 312 Network.ResourceWebSocketFrameNodeTimeComparator = function(a, b) {
254 return a._frame.time - b._frame.time; 313 return a._frame.time - b._frame.time;
255 }; 314 };
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