ResourceWebSocketFrameView.js 3.8 KB

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