mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-21 01:05:45 +00:00
Bug 1636417
- Implement EventSourceActor. r=Honza,bomsy
Differential Revision: https://phabricator.services.mozilla.com/D75066
This commit is contained in:
parent
dd59a74cce
commit
2340728c04
88
devtools/server/actors/network-monitor/eventsource-actor.js
Normal file
88
devtools/server/actors/network-monitor/eventsource-actor.js
Normal file
@ -0,0 +1,88 @@
|
||||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
"use strict";
|
||||
|
||||
const { Cc, Ci } = require("chrome");
|
||||
const { Actor, ActorClassWithSpec } = require("devtools/shared/protocol");
|
||||
const { eventSourceSpec } = require("devtools/shared/specs/eventsource");
|
||||
const { LongStringActor } = require("devtools/server/actors/string");
|
||||
|
||||
const eventSourceEventService = Cc[
|
||||
"@mozilla.org/eventsourceevent/service;1"
|
||||
].getService(Ci.nsIEventSourceEventService);
|
||||
|
||||
/**
|
||||
* This actor intercepts EventSource traffic for a specific window.
|
||||
* @see devtools/shared/spec/eventsource.js for documentation.
|
||||
*/
|
||||
const EventSourceActor = ActorClassWithSpec(eventSourceSpec, {
|
||||
initialize(conn, targetActor) {
|
||||
Actor.prototype.initialize.call(this, conn);
|
||||
|
||||
this.targetActor = targetActor;
|
||||
this.innerWindowID = null;
|
||||
|
||||
// Register for backend events.
|
||||
this.onWindowReady = this.onWindowReady.bind(this);
|
||||
this.targetActor.on("window-ready", this.onWindowReady);
|
||||
},
|
||||
|
||||
onWindowReady({ isTopLevel }) {
|
||||
if (isTopLevel) {
|
||||
this.startListening();
|
||||
}
|
||||
},
|
||||
|
||||
destroy: function() {
|
||||
this.targetActor.off("window-ready", this.onWindowReady);
|
||||
|
||||
this.stopListening();
|
||||
Actor.prototype.destroy.call(this);
|
||||
},
|
||||
|
||||
// Actor API.
|
||||
|
||||
startListening: function() {
|
||||
this.stopListening();
|
||||
this.innerWindowID = this.targetActor.window.windowUtils.currentInnerWindowID;
|
||||
eventSourceEventService.addListener(this.innerWindowID, this);
|
||||
},
|
||||
|
||||
stopListening() {
|
||||
if (!this.innerWindowID) {
|
||||
return;
|
||||
}
|
||||
if (eventSourceEventService.hasListenerFor(this.innerWindowID)) {
|
||||
eventSourceEventService.removeListener(this.innerWindowID, this);
|
||||
}
|
||||
|
||||
this.innerWindowID = null;
|
||||
},
|
||||
|
||||
// Implement functions of nsIEventSourceEventService.
|
||||
|
||||
eventSourceConnectionOpened(httpChannelId) {
|
||||
this.emit("serverEventSourceConnectionOpened", httpChannelId);
|
||||
},
|
||||
|
||||
eventSourceConnectionClosed(httpChannelId) {
|
||||
this.emit("serverEventSourceConnectionClosed", httpChannelId);
|
||||
},
|
||||
|
||||
eventReceived(httpChannelId, eventName, lastEventId, data, retry, timeStamp) {
|
||||
let payload = new LongStringActor(this.conn, data);
|
||||
this.manage(payload);
|
||||
payload = payload.form();
|
||||
this.emit("serverEventReceived", httpChannelId, {
|
||||
payload,
|
||||
eventName,
|
||||
lastEventId,
|
||||
retry,
|
||||
timeStamp,
|
||||
});
|
||||
},
|
||||
});
|
||||
|
||||
exports.EventSourceActor = EventSourceActor;
|
@ -10,6 +10,7 @@ DIRS += [
|
||||
|
||||
DevToolsModules(
|
||||
'channel-event-sink.js',
|
||||
'eventsource-actor.js',
|
||||
'network-event.js',
|
||||
'network-monitor.js',
|
||||
'network-observer.js',
|
||||
|
@ -263,6 +263,14 @@ const ActorRegistry = {
|
||||
type: { target: true },
|
||||
}
|
||||
);
|
||||
this.registerModule(
|
||||
"devtools/server/actors/network-monitor/eventsource-actor",
|
||||
{
|
||||
prefix: "eventSource",
|
||||
constructor: "EventSourceActor",
|
||||
type: { target: true },
|
||||
}
|
||||
);
|
||||
this.registerModule("devtools/server/actors/manifest", {
|
||||
prefix: "manifest",
|
||||
constructor: "ManifestActor",
|
||||
|
43
devtools/shared/specs/eventsource.js
Normal file
43
devtools/shared/specs/eventsource.js
Normal file
@ -0,0 +1,43 @@
|
||||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
"use strict";
|
||||
|
||||
const { Arg, generateActorSpec } = require("devtools/shared/protocol");
|
||||
|
||||
const eventSourceSpec = generateActorSpec({
|
||||
typeName: "eventSource",
|
||||
|
||||
/**
|
||||
* The set of events the EventSourceActor emits over RDP.
|
||||
*/
|
||||
events: {
|
||||
// In order to avoid a naming collision, we rename the server event.
|
||||
serverEventSourceConnectionOpened: {
|
||||
type: "eventSourceConnectionOpened",
|
||||
httpChannelId: Arg(0, "number"),
|
||||
},
|
||||
serverEventSourceConnectionClosed: {
|
||||
type: "eventSourceConnectionClosed",
|
||||
httpChannelId: Arg(0, "number"),
|
||||
},
|
||||
serverEventReceived: {
|
||||
type: "eventReceived",
|
||||
httpChannelId: Arg(0, "number"),
|
||||
data: Arg(1, "json"),
|
||||
},
|
||||
},
|
||||
|
||||
methods: {
|
||||
startListening: {
|
||||
request: {},
|
||||
oneway: true,
|
||||
},
|
||||
stopListening: {
|
||||
request: {},
|
||||
oneway: true,
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
exports.eventSourceSpec = eventSourceSpec;
|
@ -20,6 +20,7 @@ DevToolsModules(
|
||||
'css-properties.js',
|
||||
'device.js',
|
||||
'environment.js',
|
||||
'eventsource.js',
|
||||
'frame.js',
|
||||
'framerate.js',
|
||||
'heap-snapshot-file.js',
|
||||
|
Loading…
Reference in New Issue
Block a user