2 * Copyright (C) 2012 Research In Motion Limited. All rights reserved.
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
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
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21 * @extends {WebInspector.SplitView}
22 * @param {!WebInspector.NetworkRequest} request
24 WebInspector.ResourceWebSocketFrameView = function(request)
26 WebInspector.SplitView.call(this, false, true, "resourceWebSocketFrameViewSplitViewState");
27 this.registerRequiredCSS("network/webSocketFrameView.css");
28 this.element.classList.add("websocket-frame-view");
29 this._request = request;
32 {id: "data", title: WebInspector.UIString("Data"), sortable: false, weight: 88},
33 {id: "length", title: WebInspector.UIString("Length"), sortable: false, align: WebInspector.DataGrid.Align.Right, weight: 5},
34 {id: "time", title: WebInspector.UIString("Time"), sortable: true, weight: 7}
37 this._dataGrid = new WebInspector.SortableDataGrid(columns, undefined, undefined, undefined, this._onContextMenu.bind(this));
38 this._dataGrid.setStickToBottom(true);
39 this._dataGrid.setCellClass("websocket-frame-view-td");
40 this._timeComparator = /** @type {!WebInspector.SortableDataGrid.NodeComparator} */ (WebInspector.ResourceWebSocketFrameNodeTimeComparator);
41 this._dataGrid.sortNodes(this._timeComparator, false);
42 this._dataGrid.markColumnAsSortedBy("time", WebInspector.DataGrid.Order.Ascending);
43 this._dataGrid.addEventListener(WebInspector.DataGrid.Events.SortingChanged, this._sortItems, this);
45 this._dataGrid.setName("ResourceWebSocketFrameView");
46 this._dataGrid.addEventListener(WebInspector.DataGrid.Events.SelectedNode, this._onFrameSelected, this);
47 this._dataGrid.show(this.mainElement());
49 this._messageView = new WebInspector.EmptyView("Select frame to browse its content.");
50 this._messageView.show(this.sidebarElement());
54 WebInspector.ResourceWebSocketFrameView.OpCodes = {
58 ConnectionCloseFrame: 8,
63 /** @type {!Array.<string> } */
64 WebInspector.ResourceWebSocketFrameView.opCodeDescriptions = (function()
66 var opCodes = WebInspector.ResourceWebSocketFrameView.OpCodes;
68 map[opCodes.ContinuationFrame] = "Continuation Frame";
69 map[opCodes.TextFrame] = "Text Frame";
70 map[opCodes.BinaryFrame] = "Binary Frame";
71 map[opCodes.ContinuationFrame] = "Connection Close Frame";
72 map[opCodes.PingFrame] = "Ping Frame";
73 map[opCodes.PongFrame] = "Pong Frame";
78 * @param {number} opCode
79 * @param {boolean} mask
82 WebInspector.ResourceWebSocketFrameView.opCodeDescription = function(opCode, mask)
84 var rawDescription = WebInspector.ResourceWebSocketFrameView.opCodeDescriptions[opCode] || "";
85 var localizedDescription = WebInspector.UIString(rawDescription);
86 return WebInspector.UIString("%s (Opcode %d%s)", localizedDescription, opCode, (mask ? ", mask" : ""));
89 WebInspector.ResourceWebSocketFrameView.prototype = {
93 this._request.addEventListener(WebInspector.NetworkRequest.Events.WebsocketFrameAdded, this._frameAdded, this);
98 this._request.removeEventListener(WebInspector.NetworkRequest.Events.WebsocketFrameAdded, this._frameAdded, this);
102 * @param {!WebInspector.Event} event
104 _frameAdded: function(event)
106 var frame = /** @type {!WebInspector.NetworkRequest.WebSocketFrame} */ (event.data);
107 this._dataGrid.insertChild(new WebInspector.ResourceWebSocketFrameNode(frame));
111 * @param {!WebInspector.Event} event
113 _onFrameSelected: function(event)
115 var selectedNode = /** @type {!WebInspector.ResourceWebSocketFrameNode} */ (event.target.selectedNode);
116 if (this._messageView)
117 this._messageView.detach();
119 this._dataView.detach();
120 this._dataView = new WebInspector.ResourceSourceFrame(selectedNode.contentProvider());
121 this._dataView.show(this.sidebarElement());
126 this._dataGrid.rootNode().removeChildren();
127 var frames = this._request.frames();
128 for (var i = 0; i < frames.length; ++i)
129 this._dataGrid.insertChild(new WebInspector.ResourceWebSocketFrameNode(frames[i]));
133 * @param {!WebInspector.ContextMenu} contextMenu
134 * @param {!WebInspector.DataGridNode} node
136 _onContextMenu: function(contextMenu, node)
138 contextMenu.appendItem(WebInspector.UIString(WebInspector.useLowerCaseMenuTitles() ? "Copy message" : "Copy Message"), this._copyMessage.bind(this, node.data));
142 * @param {!Object} row
144 _copyMessage: function(row)
146 InspectorFrontendHost.copyText(row.data);
149 _sortItems: function()
151 this._dataGrid.sortNodes(this._timeComparator, !this._dataGrid.isSortOrderAscending());
154 __proto__: WebInspector.SplitView.prototype
159 * @extends {WebInspector.SortableDataGridNode}
160 * @param {!WebInspector.NetworkRequest.WebSocketFrame} frame
162 WebInspector.ResourceWebSocketFrameNode = function(frame)
165 this._dataText = frame.text;
166 this._length = frame.text.length;
167 this._timeText = (new Date(frame.time * 1000)).toLocaleTimeString();
169 this._isTextFrame = frame.opCode === WebInspector.ResourceWebSocketFrameView.OpCodes.TextFrame;
170 if (!this._isTextFrame)
171 this._dataText = WebInspector.ResourceWebSocketFrameView.opCodeDescription(frame.opCode, frame.mask);
173 WebInspector.SortableDataGridNode.call(this, {data: this._dataText, length: this._length, time: this._timeText});
176 WebInspector.ResourceWebSocketFrameNode.prototype = {
178 createCells: function()
180 var element = this._element;
181 element.classList.toggle("websocket-frame-view-row-error", this._frame.type === WebInspector.NetworkRequest.WebSocketFrameType.Error);
182 element.classList.toggle("websocket-frame-view-row-outcoming", this._frame.type === WebInspector.NetworkRequest.WebSocketFrameType.Send);
183 element.classList.toggle("websocket-frame-view-row-opcode", !this._isTextFrame);
184 WebInspector.SortableDataGridNode.prototype.createCells.call(this);
191 nodeSelfHeight: function()
197 * @return {!WebInspector.ContentProvider}
199 contentProvider: function()
201 return new WebInspector.StaticContentProvider(WebInspector.resourceTypes.WebSocket, this._dataText);
204 __proto__: WebInspector.SortableDataGridNode.prototype
208 * @param {!WebInspector.ResourceWebSocketFrameNode} a
209 * @param {!WebInspector.ResourceWebSocketFrameNode} b
212 WebInspector.ResourceWebSocketFrameNodeTimeComparator = function(a, b)
214 return a._frame.time - b._frame.time;