1/* 2 * Copyright (C) 2012 Research In Motion Limited. All rights reserved. 3 * 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. 8 * 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. 13 * 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 17 */ 18 19/** 20 * @constructor 21 * @extends {WebInspector.View} 22 */ 23WebInspector.ResourceWebSocketFrameView = function(resource) 24{ 25 WebInspector.View.call(this); 26 this.element.addStyleClass("resource-websocket"); 27 this.resource = resource; 28 this.element.removeChildren(); 29 30 var dataGrid = new WebInspector.DataGrid([ 31 {id: "data", title: WebInspector.UIString("Data"), sortable: false}, 32 {id: "length", title: WebInspector.UIString("Length"), sortable: false, alig: WebInspector.DataGrid.Align.Right, width: "50px"}, 33 {id: "time", title: WebInspector.UIString("Time"), width: "70px"} 34 ]); 35 36 var frames = this.resource.frames(); 37 for (var i = 0; i < frames.length; i++) { 38 var payload = frames[i]; 39 40 var date = new Date(payload.time * 1000); 41 var row = { 42 data: "", 43 length: typeof payload.payloadData === "undefined" ? payload.errorMessage.length.toString() : payload.payloadData.length.toString(), 44 time: date.toLocaleTimeString() 45 }; 46 47 var rowClass = ""; 48 if (payload.errorMessage) { 49 rowClass = "error"; 50 row.data = payload.errorMessage; 51 } else if (payload.opcode == WebInspector.ResourceWebSocketFrameView.OpCodes.TextFrame) { 52 if (payload.sent) 53 rowClass = "outcoming"; 54 55 row.data = payload.payloadData; 56 } else { 57 rowClass = "opcode"; 58 var opcodeMeaning = ""; 59 switch (payload.opcode) { 60 case WebInspector.ResourceWebSocketFrameView.OpCodes.ContinuationFrame: 61 opcodeMeaning = WebInspector.UIString("Continuation Frame"); 62 break; 63 case WebInspector.ResourceWebSocketFrameView.OpCodes.BinaryFrame: 64 opcodeMeaning = WebInspector.UIString("Binary Frame"); 65 break; 66 case WebInspector.ResourceWebSocketFrameView.OpCodes.ConnectionCloseFrame: 67 opcodeMeaning = WebInspector.UIString("Connection Close Frame"); 68 break; 69 case WebInspector.ResourceWebSocketFrameView.OpCodes.PingFrame: 70 opcodeMeaning = WebInspector.UIString("Ping Frame"); 71 break; 72 case WebInspector.ResourceWebSocketFrameView.OpCodes.PongFrame: 73 opcodeMeaning = WebInspector.UIString("Pong Frame"); 74 break; 75 } 76 row.data = WebInspector.UIString("%s (Opcode %d%s)", opcodeMeaning, payload.opcode, (payload.mask ? ", mask" : "")); 77 } 78 79 var node = new WebInspector.DataGridNode(row, false); 80 dataGrid.rootNode().appendChild(node); 81 82 if (rowClass) 83 node.element.classList.add("resource-websocket-row-" + rowClass); 84 85 } 86 dataGrid.show(this.element); 87} 88 89WebInspector.ResourceWebSocketFrameView.OpCodes = { 90 ContinuationFrame: 0, 91 TextFrame: 1, 92 BinaryFrame: 2, 93 ConnectionCloseFrame: 8, 94 PingFrame: 9, 95 PongFrame: 10 96}; 97 98WebInspector.ResourceWebSocketFrameView.prototype = { 99 __proto__: WebInspector.View.prototype 100} 101