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.VBox}
23 WebInspector.ResourceWebSocketFrameView = function(resource)
25 WebInspector.VBox.call(this);
26 this.element.classList.add("resource-websocket");
27 this.resource = resource;
28 this.element.removeChildren();
30 this._dataGrid = new WebInspector.DataGrid([
31 {id: "data", title: WebInspector.UIString("Data"), sortable: false, weight: 88, longText: true},
32 {id: "length", title: WebInspector.UIString("Length"), sortable: false, alig: WebInspector.DataGrid.Align.Right, weight: 5},
33 {id: "time", title: WebInspector.UIString("Time"), weight: 7}
34 ], undefined, undefined, undefined, this._onContextMenu.bind(this));
37 this._dataGrid.setName("ResourceWebSocketFrameView");
38 this._dataGrid.show(this.element);
41 WebInspector.ResourceWebSocketFrameView.OpCodes = {
45 ConnectionCloseFrame: 8,
50 WebInspector.ResourceWebSocketFrameView.prototype = {
51 appendFrame: function(frame)
55 var date = new Date(payload.time * 1000);
58 length: typeof payload.payloadData === "undefined" ? payload.errorMessage.length.toString() : payload.payloadData.length.toString(),
59 time: date.toLocaleTimeString()
63 if (payload.errorMessage) {
65 row.data = payload.errorMessage;
66 } else if (payload.opcode == WebInspector.ResourceWebSocketFrameView.OpCodes.TextFrame) {
68 rowClass = "outcoming";
70 row.data = payload.payloadData;
73 var opcodeMeaning = "";
74 switch (payload.opcode) {
75 case WebInspector.ResourceWebSocketFrameView.OpCodes.ContinuationFrame:
76 opcodeMeaning = WebInspector.UIString("Continuation Frame");
78 case WebInspector.ResourceWebSocketFrameView.OpCodes.BinaryFrame:
79 opcodeMeaning = WebInspector.UIString("Binary Frame");
81 case WebInspector.ResourceWebSocketFrameView.OpCodes.ConnectionCloseFrame:
82 opcodeMeaning = WebInspector.UIString("Connection Close Frame");
84 case WebInspector.ResourceWebSocketFrameView.OpCodes.PingFrame:
85 opcodeMeaning = WebInspector.UIString("Ping Frame");
87 case WebInspector.ResourceWebSocketFrameView.OpCodes.PongFrame:
88 opcodeMeaning = WebInspector.UIString("Pong Frame");
91 row.data = WebInspector.UIString("%s (Opcode %d%s)", opcodeMeaning, payload.opcode, (payload.mask ? ", mask" : ""));
94 var node = new WebInspector.DataGridNode(row, false);
95 this._dataGrid.rootNode().appendChild(node);
98 node.element.classList.add("resource-websocket-row-" + rowClass);
103 this._dataGrid.rootNode().removeChildren();
104 var frames = this.resource.frames();
105 for (var i = frames.length - 1; i >= 0; i--) {
106 this.appendFrame(frames[i]);
110 show: function(parentElement, insertBefore)
113 WebInspector.View.prototype.show.call(this, parentElement, insertBefore);
117 * @param {!WebInspector.ContextMenu} contextMenu
118 * @param {!WebInspector.DataGridNode} node
120 _onContextMenu: function(contextMenu, node)
122 contextMenu.appendItem(WebInspector.UIString(WebInspector.useLowerCaseMenuTitles() ? "Copy message" : "Copy Message"), this._copyMessage.bind(this, node.data));
126 * @param {!Object} row
128 _copyMessage: function(row)
130 InspectorFrontendHost.copyText(row.data);
133 __proto__: WebInspector.VBox.prototype