Skip to content
This repository was archived by the owner on Aug 13, 2018. It is now read-only.

Commit f15d5c9

Browse files
committed
#36 Display connect and disconnect events in the frame list
1 parent 4962174 commit f15d5c9

File tree

8 files changed

+220
-11
lines changed

8 files changed

+220
-11
lines changed

chrome/locale/en-US/websocket-monitor.properties

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,3 +38,10 @@ websocketmonitor.perspective.tableView=Show Table
3838
# A label and tooltip used for a filter toolbar button displayed in the Network panel.
3939
webSockets.network.filter.label=WS
4040
webSockets.network.filter.tip=Show WebSockets upgrade requests
41+
42+
# LOCALIZATION NOTE (websocketmonitor.event.connected, websocketmonitor.event.disconnected,
43+
# websocketmonitor.event.code): A label used for WS events that are also displayed
44+
# in the frame list.
45+
websocketmonitor.event.connected=Connected to:
46+
websocketmonitor.event.disconnected=Disconnected
47+
websocketmonitor.event.code=code:

data/components/frame-list.js

Lines changed: 81 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ var FrameList = React.createClass({
7878
// Render all frames.
7979
for (var i in frames) {
8080
var frame = frames[i];
81-
output.push(FrameBubble({
81+
output.push(this.getFrameTag(frame)({
8282
key: "frame-" + frame.id,
8383
frame: frame,
8484
selection: this.props.selection,
@@ -99,6 +99,15 @@ var FrameList = React.createClass({
9999
div({}, output)
100100
)
101101
);
102+
},
103+
104+
getFrameTag: function(frame) {
105+
switch (frame.type) {
106+
case "event":
107+
return EventBubble;
108+
case "frame":
109+
return FrameBubble;
110+
}
102111
}
103112
});
104113

@@ -219,6 +228,77 @@ var FrameBubble = React.createFactory(React.createClass({
219228
},
220229
}));
221230

231+
/**
232+
* Template for WS events (connect and disconnect) displayed in the
233+
* frame list (list view)
234+
*/
235+
var EventBubble = React.createFactory(React.createClass({
236+
/** @lends FrameBubble */
237+
238+
displayName: "FrameBubble",
239+
240+
/**
241+
* Frames need to be re-rendered only if the selection changes.
242+
* This is an optimization that makes the list rendering a lot faster.
243+
*/
244+
shouldComponentUpdate: function(nextProps, nextState) {
245+
return this.props.frame == nextProps.selection ||
246+
this.props.frame == this.props.selection;
247+
},
248+
249+
// Event Handlers
250+
251+
onClick: function(event) {
252+
var target = event.target;
253+
254+
event.stopPropagation();
255+
event.preventDefault();
256+
257+
// If a 'memberLabel' is clicked inside the inline preview
258+
// tree, let's process it by the tree, so expansion and
259+
// collapsing works. Otherwise just select the frame.
260+
if (!target.classList.contains("memberLabel")) {
261+
if (this.props.frame != this.props.selection) {
262+
this.props.dispatch(selectFrame(this.props.frame));
263+
}
264+
}
265+
},
266+
267+
render: function() {
268+
var frame = this.props.frame;
269+
270+
// Frame classes
271+
var classNames = ["frameBubble", "eventBubble", frame.type];
272+
if (this.props.selection == frame) {
273+
classNames.push("selected");
274+
}
275+
276+
var label = frame.uri ?
277+
Locale.$STR("websocketmonitor.event.connected") :
278+
Locale.$STR("websocketmonitor.event.disconnected");
279+
280+
var uri = frame.uri ? frame.uri :
281+
Locale.$STR("websocketmonitor.event.code") + " " + frame.code;
282+
283+
var socketIdLabel = Locale.$STR("websocketmonitor.SocketID") +
284+
": " + frame.webSocketSerialID;
285+
286+
return (
287+
div({className: classNames.join(" "), onClick: this.onClick},
288+
div({className: "frameBox"},
289+
div({className: "frameContent"},
290+
div({className: "body"},
291+
div({className: "text"}, label),
292+
div({className: "uri"}, uri),
293+
div({className: "socketId"}, socketIdLabel)
294+
)
295+
)
296+
)
297+
)
298+
);
299+
}
300+
}));
301+
222302
/**
223303
* @template This template is responsible for rendering a message
224304
* at the top of the frame list that informs the user about reaching

data/components/frame-table.js

Lines changed: 64 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ var FrameTable = React.createClass({
5353
summary = filter.summary || summary;
5454

5555
// Render list of frames.
56-
var rows = frames.map(frame => FrameRow({
56+
var rows = frames.map(frame => this.getFrameTag(frame)({
5757
key: frame.id,
5858
selection: this.props.selection,
5959
frame: frame,
@@ -100,6 +100,15 @@ var FrameTable = React.createClass({
100100
tableFooter
101101
)
102102
);
103+
},
104+
105+
getFrameTag: function(frame) {
106+
switch (frame.type) {
107+
case "event":
108+
return EventRow;
109+
case "frame":
110+
return FrameRow;
111+
}
103112
}
104113
});
105114

@@ -167,6 +176,60 @@ var FrameRow = React.createFactory(React.createClass({
167176
}
168177
}));
169178

179+
/**
180+
* Template for WS events (connect and disconnect) displayed in the
181+
* frame list (table view)
182+
*/
183+
var EventRow = React.createFactory(React.createClass({
184+
/** @lends FrameRow */
185+
186+
displayName: "EventRow",
187+
188+
/**
189+
* Frames need to be re-rendered only if the selection changes.
190+
* This is an optimization that makes the list rendering a lot faster.
191+
*/
192+
shouldComponentUpdate: function(nextProps, nextState) {
193+
return this.props.frame == nextProps.selection ||
194+
this.props.frame == this.props.selection;
195+
},
196+
197+
onClick: function() {
198+
if (this.props.frame != this.props.selection) {
199+
this.props.dispatch(selectFrame(this.props.frame));
200+
}
201+
},
202+
203+
render: function() {
204+
var frame = this.props.frame;
205+
var className = "frameRow eventRow";
206+
207+
if (this.props.selection == frame) {
208+
className += " selected";
209+
}
210+
211+
var label = frame.uri ?
212+
Locale.$STR("websocketmonitor.event.connected") :
213+
Locale.$STR("websocketmonitor.event.disconnected");
214+
215+
var uri = frame.uri ? frame.uri :
216+
Locale.$STR("websocketmonitor.event.code") + " " + frame.code;
217+
218+
return (
219+
tr({className: className, onClick: this.onClick},
220+
td({}),
221+
td({className: "socketId"},
222+
frame.webSocketSerialID
223+
),
224+
td({className: "", colSpan: 6},
225+
span({className: "text"}, label),
226+
span({className: "uri"}, uri)
227+
)
228+
)
229+
);
230+
}
231+
}));
232+
170233
/**
171234
* Used to display a warning if "@mozilla.org/websocketevent/service;1"
172235
* needed by this extension isn't available on the platform.

data/css/frame-list.css

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,3 +235,27 @@
235235
width: 10px;
236236
text-align: center;
237237
}
238+
239+
/******************************************************************************/
240+
/* Frame Events */
241+
242+
.frameBubble.event .body {
243+
min-width: 200px;
244+
}
245+
246+
.frameBubble.event {
247+
text-align: center;
248+
}
249+
250+
.frameBubble.event .uri {
251+
color: green;
252+
}
253+
254+
.frameBubble.event .text {
255+
color: black;
256+
font-weight: bold;
257+
}
258+
259+
.frameBubble.event .socketId {
260+
color: gray;
261+
}

data/css/frame-table.css

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,20 @@
6060
padding: 1px;
6161
}
6262

63+
/******************************************************************************/
64+
/* Events */
65+
66+
.eventRow .uri {
67+
color: gray;
68+
padding-left: 5px;
69+
}
70+
71+
.eventRow .text {
72+
color: black;
73+
font-weight: bold;
74+
padding-left: 20px;
75+
}
76+
6377
/******************************************************************************/
6478
/* Frame Columns */
6579

@@ -141,6 +155,8 @@
141155
background: #EFEFEF;
142156
}
143157

158+
.eventRow.selected .text,
159+
.eventRow.selected .uri,
144160
.frameRow.selected td.opcode,
145161
.frameRow.selected td {
146162
background: #3399ff;

data/reducers/frames.js

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -72,10 +72,15 @@ function addFrames(state, newFrames) {
7272
// Update summary info
7373
newFrames.forEach(frame => {
7474
var data = frame.data;
75-
totalSize += data.payload.length;
76-
startTime = startTime ? startTime : data.timeStamp;
77-
endTime = data.timeStamp;
78-
frameCount++;
75+
if (data) {
76+
totalSize += data.payload ? data.payload.length : 0;
77+
startTime = startTime ? startTime : data.timeStamp;
78+
endTime = data.timeStamp;
79+
}
80+
81+
if (frame.type == "frame") {
82+
frameCount++;
83+
}
7984
});
8085

8186
// Return new state
@@ -110,7 +115,7 @@ function filterFrames(state, filter) {
110115
if (filter.text) {
111116
frames = state.frames.filter(frame => {
112117
var data = frame.data;
113-
if (data.payload.indexOf(filter.text) != -1) {
118+
if (data.payload && data.payload.indexOf(filter.text) != -1) {
114119
summary.totalSize += data.payload.length;
115120
summary.startTime = summary.startTime ? summary.startTime : data.timeStamp;
116121
summary.endTime = data.timeStamp;

data/view.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,19 @@ var WebSocketsView = createView(PanelView,
6666

6767
// nsIWebSocketEventService events
6868

69+
webSocketCreated: function(data) {
70+
data.type = "event";
71+
this.lazyAdd(data);
72+
},
73+
74+
webSocketOpened: function(data) {
75+
},
76+
77+
webSocketClosed: function(data) {
78+
data.type = "event";
79+
this.lazyAdd(data);
80+
},
81+
6982
/**
7083
* Event handlers are executed directly according to the
7184
* event types sent from the chrome scope.
@@ -75,12 +88,14 @@ var WebSocketsView = createView(PanelView,
7588
frameReceived: function(frame) {
7689
frame = JSON.parse(frame);
7790
frame.received = true;
91+
frame.type = "frame";
7892
this.lazyAdd(frame);
7993
},
8094

8195
frameSent: function(frame) {
8296
frame = JSON.parse(frame);
8397
frame.sent = true;
98+
frame.type = "frame";
8499
this.lazyAdd(frame);
85100
},
86101

lib/wsm-panel.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -190,19 +190,18 @@ const WsmPanel = Class(
190190
// nsIWebSocketEventService events
191191

192192
onWebSocketCreated: function(data) {
193-
FBTrace.sysout("onWebSocketCreated", data);
193+
this.postContentMessage("webSocketCreated", data);
194194
},
195195

196196
onWebSocketOpened: function(data) {
197-
FBTrace.sysout("onWebSocketOpened", data);
197+
this.postContentMessage("webSocketOpened", data);
198198
},
199199

200200
onWebSocketClosed: function(data) {
201-
FBTrace.sysout("onWebSocketClosed", data);
201+
this.postContentMessage("webSocketClosed", data);
202202
},
203203

204204
onWebSocketMessageAvailable: function(data) {
205-
FBTrace.sysout("onWebSocketMessageAvailable", data);
206205
},
207206

208207
onFrameReceived: function(frame) {

0 commit comments

Comments
 (0)