2019-01-29 18:18:42 +03:00
|
|
|
/* 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";
|
|
|
|
|
|
|
|
var EXPORTED_SYMBOLS = ["Session"];
|
|
|
|
|
2019-02-22 02:04:13 +03:00
|
|
|
const { ParentProcessDomains } = ChromeUtils.import(
|
|
|
|
"chrome://remote/content/domains/ParentProcessDomains.jsm"
|
|
|
|
);
|
|
|
|
const { Domains } = ChromeUtils.import(
|
|
|
|
"chrome://remote/content/domains/Domains.jsm"
|
2019-05-27 14:39:16 +03:00
|
|
|
);
|
2019-01-29 18:18:42 +03:00
|
|
|
|
2019-03-08 01:11:11 +03:00
|
|
|
/**
|
|
|
|
* A session represents exactly one client WebSocket connection.
|
|
|
|
*
|
|
|
|
* Every new WebSocket connections is associated with one session that
|
2019-04-04 14:29:31 +03:00
|
|
|
* deals with dispatching incoming command requests to the right
|
2019-03-08 01:11:11 +03:00
|
|
|
* target, sending back responses, and propagating events originating
|
|
|
|
* from domains.
|
2019-04-04 14:29:31 +03:00
|
|
|
* Then, some subsequent Sessions may be created over a single WebSocket
|
|
|
|
* connection. In this case, the subsequent session will have an `id`
|
|
|
|
* being passed to their constructor and each packet of these sessions
|
|
|
|
* will have a `sessionId` attribute in order to filter the packets
|
|
|
|
* by session both on client and server side.
|
2019-03-08 01:11:11 +03:00
|
|
|
*/
|
2019-02-12 16:58:23 +03:00
|
|
|
class Session {
|
2019-04-04 14:29:31 +03:00
|
|
|
/**
|
|
|
|
* @param Connection connection
|
|
|
|
* The connection used to communicate with the server.
|
|
|
|
* @param Target target
|
|
|
|
* The target to which this session communicates with.
|
|
|
|
* @param Number id (optional)
|
|
|
|
* If this session isn't the default one used for the HTTP endpoint we
|
|
|
|
* connected to, the session requires an id to distinguish it from the default
|
|
|
|
* one. This id is used to filter our request, responses and events between
|
2019-07-11 20:45:29 +03:00
|
|
|
* all active sessions. For now, this is only passed by `Target.attachToTarget()`.
|
2019-04-04 14:29:31 +03:00
|
|
|
*/
|
2019-03-10 15:51:09 +03:00
|
|
|
constructor(connection, target, id) {
|
2019-01-29 18:18:42 +03:00
|
|
|
this.connection = connection;
|
2019-02-23 19:12:03 +03:00
|
|
|
this.target = target;
|
2019-03-10 15:51:09 +03:00
|
|
|
this.id = id;
|
2019-01-29 18:18:42 +03:00
|
|
|
|
2019-03-10 15:51:09 +03:00
|
|
|
this.domains = new Domains(this, ParentProcessDomains);
|
2019-01-29 18:18:42 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
destructor() {
|
2019-02-23 19:12:03 +03:00
|
|
|
this.domains.clear();
|
2019-01-29 18:18:42 +03:00
|
|
|
}
|
|
|
|
|
2019-07-11 20:45:29 +03:00
|
|
|
execute(id, domain, command, params) {
|
|
|
|
return this.domains.execute(domain, command, params);
|
2019-02-23 19:38:41 +03:00
|
|
|
}
|
|
|
|
|
2019-07-11 20:45:29 +03:00
|
|
|
/**
|
|
|
|
* Domains event listener. Called when an event is fired
|
|
|
|
* by any Domain and has to be sent to the client.
|
|
|
|
*/
|
2019-02-23 21:59:31 +03:00
|
|
|
onEvent(eventName, params) {
|
2019-07-11 20:45:29 +03:00
|
|
|
this.connection.onEvent(eventName, params, this.id);
|
2019-02-23 21:59:31 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
toString() {
|
2019-03-10 15:51:09 +03:00
|
|
|
return `[object ${this.constructor.name} ${this.connection.id}]`;
|
2019-02-22 02:04:13 +03:00
|
|
|
}
|
2019-02-12 17:44:54 +03:00
|
|
|
}
|