Skip to content

Instantly share code, notes, and snippets.

@gregtatum
Last active January 17, 2018 19:22
Show Gist options
  • Save gregtatum/c8ce94601bc68c8020b4b7bad744db30 to your computer and use it in GitHub Desktop.
Save gregtatum/c8ce94601bc68c8020b4b7bad744db30 to your computer and use it in GitHub Desktop.
changeset: 392160:39c32b684ff7
user: Greg Tatum <gtatum@mozilla.com>
date: Wed Nov 15 11:27:47 2017 -0600
summary: Flow typing devtools/server/main.js
diff --git a/.hgignore b/.hgignore
--- a/.hgignore
+++ b/.hgignore
@@ -81,17 +81,17 @@
# Git repositories
.git/
# Ignore chrome.manifest files from the devtools loader
^devtools/client/chrome.manifest$
^devtools/shared/chrome.manifest$
# Ignore node_modules directories in devtools
-^devtools/.*/node_modules/
+^devtools.*/node_modules/
# git checkout of libstagefright
^media/libstagefright/android$
# Tag files generated by GNU Global
GTAGS
GRTAGS
GSYMS
diff --git a/devtools/.flowconfig b/devtools/.flowconfig
new file mode 100644
--- /dev/null
+++ b/devtools/.flowconfig
@@ -0,0 +1,10 @@
+[ignore]
+client/jsonview/test/invalid_json.json
+client/aboutdebugging/test/addons/bad/manifest.json
+
+[libs]
+types/flow-typed
+
+[options]
+module.name_mapper='^devtools/\(.*\)$' -> '<PROJECT_ROOT>/\1'
+suppress_comment= \\(.\\|\n\\)*\\flowIgnore
diff --git a/devtools/package.json b/devtools/package.json
new file mode 100644
--- /dev/null
+++ b/devtools/package.json
@@ -0,0 +1,7 @@
+{
+ "name": "devtools",
+ "version": "0.0.0",
+ "dependencies": {
+ "flow-bin": "^0.58.0"
+ }
+}
diff --git a/devtools/server/main.js b/devtools/server/main.js
--- a/devtools/server/main.js
+++ b/devtools/server/main.js
@@ -1,60 +1,110 @@
/* 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/. */
+// @flow
"use strict";
/**
* Toolkit glue for the remote debugging protocol, loaded into the
* debugging global.
*/
var { Ci, Cc, CC, Cu, Cr } = require("chrome");
-var Services = require("Services");
+var Services/* : Object */ = require("Services");
var { ActorPool, OriginalLocation, RegisteredActorFactory,
ObservedActorFactory } = require("devtools/server/actors/common");
var { LocalDebuggerTransport, ChildDebuggerTransport, WorkerDebuggerTransport } =
require("devtools/shared/transport/transport");
var DevToolsUtils = require("devtools/shared/DevToolsUtils");
var { dumpn, dumpv } = DevToolsUtils;
var flags = require("devtools/shared/flags");
var OldEventEmitter = require("devtools/shared/old-event-emitter");
var SyncPromise = require("devtools/shared/deprecated-sync-thenables");
DevToolsUtils.defineLazyGetter(this, "DebuggerSocket", () => {
let { DebuggerSocket } = require("devtools/shared/security/socket");
return DebuggerSocket;
});
+
DevToolsUtils.defineLazyGetter(this, "Authentication", () => {
return require("devtools/shared/security/auth");
});
+
DevToolsUtils.defineLazyGetter(this, "generateUUID", () => {
let { generateUUID } = Cc["@mozilla.org/uuid-generator;1"]
.getService(Ci.nsIUUIDGenerator);
return generateUUID;
});
-// On B2G, `this` != Global scope, so `Ci` won't be binded on `this`
-// (i.e. this.Ci is undefined) Then later, when using loadSubScript,
-// Ci,... won't be defined for sub scripts.
-this.Ci = Ci;
-this.Cc = Cc;
-this.CC = CC;
-this.Cu = Cu;
-this.Cr = Cr;
-this.Services = Services;
-this.ActorPool = ActorPool;
-this.DevToolsUtils = DevToolsUtils;
-this.dumpn = dumpn;
-this.dumpv = dumpv;
+/* ::
+// Define lazy getters for Flow.
+declare var generateUUID: () => { toString: () => string };
+let Authentication = require("devtools/shared/security/auth");
+let { DebuggerSocket } = require("devtools/shared/security/socket");
+const SocketListener = require("devtools/shared/security/socket");
+const DebuggerTransport = require("devtools/shared/transport/transport");
-// Overload `Components` to prevent SDK loader exception on Components
-// object usage
-Object.defineProperty(this, "Components", {
+import type { MessageManager } from 'devtools/types/services';
+
+// The following types should eventually be migrated to their own files and properly
+// typed. They exist here to help with the initial typing.
+declare class BrowserTabActor extends Actor {}
+declare class Actor {
+ constructor(connection: DebuggerServerConnection, aTab: ?BrowserTabActor): void;
+ name: string,
+ id: string,
+ actorPrefix: string
+}
+type BrowserSwapEvent = {
+ detail: XULBrowser,
+ bubbles: boolean
+};
+// See the RegisteredActorFactory constructor in devtools/server/actors/common.js
+// for the definition of this object.
+type RegisteredActorFactoryOptions = Object;
+type ActorFactory = DebuggerServerConnection => Actor
+// This definition belongs in: devtools/shared/transport/transport.js
+type TransportHeader = Object;
+// This definition belongs in: devtools/server/actors/common.js
+declare class ActorPool {
+ constructor(DebuggerServerConnection): {},
+ destroy: () => void,
+ addActor: Actor => void,
+ removeActor: Actor => void,
+ get: string => ?Actor,
+ has: string => boolean,
+ isEmpty: () => boolean,
+ unmanage: Actor => void,
+ forEach: (Actor => void) => void,
+}
+
+*/
+
+{
+ // On B2G, `this` != Global scope, so `Ci` won't be bound on `this`
+ // (i.e. this.Ci is undefined) Then later, when using loadSubScript,
+ // Ci,... won't be defined for sub scripts.
+ const global = (this/* : Object */);
+ global.Ci = Ci;
+ global.Cc = Cc;
+ global.CC = CC;
+ global.Cu = Cu;
+ global.Cr = Cr;
+ global.Services = Services;
+ global.ActorPool = ActorPool;
+ global.DevToolsUtils = DevToolsUtils;
+ global.dumpn = dumpn;
+ global.dumpv = dumpv;
+}
+
+// Overload `Components` to prevent SDK loader exception on Components object usage.
+// Flow doesn't handle defineProperty correctly. Override it here.
+(Object/* : any */).defineProperty(this, "Components", {
get() {
return require("chrome").components;
}
});
if (isWorker) {
flags.wantLogging = true;
flags.wantVerbose = true;
@@ -82,16 +132,24 @@ function loadSubScript(url) {
e + " - " + e.stack + "\n";
dump(errorStr);
reportError(errorStr);
throw e;
}
}
loader.lazyRequireGetter(this, "EventEmitter", "devtools/shared/event-emitter");
+/* ::
+declare var EventEmitter: {
+ on: (target: Object, type: string, listener: * => *) => void,
+ off: (target: Object, type: string, listener: * => *) => void,
+ once: (target: Object, type: string, listener: * => *) => void,
+ emit: (target: Object, type: string, event: *) => void
+}
+*/
var gRegisteredModules = Object.create(null);
/**
* The ModuleAPI object is passed to modules loaded using the
* DebuggerServer.registerModule() API. Modules can use this
* object to register actor factories.
* Factories registered through the module API will be removed
@@ -131,42 +189,98 @@ function ModuleAPI() {
},
// Destroy the module API object, unregistering any
// factories registered by the module.
destroy() {
for (let factory of activeTabActors) {
DebuggerServer.removeTabActor(factory);
}
- activeTabActors = null;
+ activeTabActors = new Set();
for (let factory of activeGlobalActors) {
DebuggerServer.removeGlobalActor(factory);
}
- activeGlobalActors = null;
+ activeGlobalActors = new Set();
}
};
}
+/* ::
+// These are the options for how to register actors.
+type RegisterActorOptions = {
+ // Registers the root actor from webbrowser module, which is used to
+ // connect to and fetch any other actor.
+ root?: boolean,
+ // Registers all the parent process actors useful for debugging the
+ // runtime itself, like preferences and addons actors.
+ browser?: boolean,
+ // Registers all the tab actors like console, script, ... all useful
+ // for debugging a target context.
+ tab?: boolean,
+ // "windowtype" attribute of the main chrome windows. Used by some
+ // actors to retrieve them.
+ windowType?: string
+};
+
+// These are the options for registering a module.
+type RegisterModuleOptions = {|
+ // The prefix of an actor is used to compute:
+ // - the `actorID` of each new actor instance (ex: prefix1). (See ActorPool.addActor)
+ // - the actor name in the listTabs request. Sending a listTabs request to the root
+ // actor returns actor IDs. IDs are in dictionaries, with actor names as keys and
+ // actor IDs as values. The actor name is the prefix to which the "Actor" string is
+ // appended. So for an actor with the `console` prefix, the actor
+ // name will be `consoleActor`.
+ prefix: string,
+
+ // The name of the exported symbol to be used as the actor constructor.
+ constructor: string,
+
+ type: {|
+ // If true, registers a global actor instance. A global actor has the root actor as
+ // its parent.
+ global: boolean,
+
+ // If true, it registers a tab actor instance. A new actor will be created for each
+ // tab and each app.
+ tab: boolean
+ |}
+|};
+*/
+
/** *
* Public API
*/
var DebuggerServer = {
+ /* ::
+ // Let Flow know about the EventEmitter being added on to this object. It would
+ // probably be nice to migrate this to a class.
+ emit: OldEventEmitter.emit,
+ on: OldEventEmitter.on,
+ once: OldEventEmitter.once,
+ off: OldEventEmitter.off,
+ */
_listeners: [],
_initialized: false,
+ _connections: {},
+ _nextConnID: 0,
+
// Flag to check if the content process debugger server script was already loaded.
_contentProcessScriptLoaded: false,
// Map of global actor names to actor constructors provided by extensions.
globalActorFactories: {},
// Map of tab actor names to actor constructors provided by extensions.
tabActorFactories: {},
LONG_STRING_LENGTH: 10000,
LONG_STRING_INITIAL_LENGTH: 1000,
LONG_STRING_READ_LENGTH: 65 * 1024,
+ createRootActor: (null/* :ActorFactory | null*/),
+
/**
* The windowtype of the chrome window to use for actors that use the global
* window (i.e the global style editor). Set this to your main window type,
* for example "navigator:browser".
*/
chromeWindowType: "navigator:browser",
/**
@@ -174,16 +288,17 @@ var DebuggerServer = {
*/
allowChromeProcess: false,
/**
* We run a special server in child process whose main actor is an instance
* of ContentActor, but that isn't a root actor. Instead there is no root
* actor registered on DebuggerServer.
*/
+ // flowIgnore: getters and setters don't work yet.
get rootlessServer() {
return !this.isModuleRegistered("devtools/server/actors/webbrowser");
},
/**
* Initialize the debugger server.
*/
init() {
@@ -192,32 +307,36 @@ var DebuggerServer = {
}
this._connections = {};
this._nextConnID = 0;
this._initialized = true;
},
+ /* :: protocol: require("devtools/shared/protocol"), */
+ // flowIgnore: getters and setters don't work yet.
get protocol() {
return require("devtools/shared/protocol");
},
+ /* :: initialized: false, */
+ // flowIgnore: getters and setters don't work yet.
get initialized() {
return this._initialized;
},
/**
* Performs cleanup tasks before shutting down the debugger server. Such tasks
* include clearing any actor constructors added at runtime. This method
* should be called whenever a debugger server is no longer useful, to avoid
* memory leaks. After this method returns, the debugger server must be
* initialized again before use.
*/
- destroy() {
+ destroy()/* :void */ {
if (!this._initialized) {
return;
}
for (let connID of Object.getOwnPropertyNames(this._connections)) {
this._connections[connID].close();
}
@@ -232,46 +351,42 @@ var DebuggerServer = {
this._initialized = false;
dumpn("Debugger server is shut down.");
},
/**
* Raises an exception if the server has not been properly initialized.
*/
- _checkInit() {
+ _checkInit()/* :void */ {
if (!this._initialized) {
throw new Error("DebuggerServer has not been initialized.");
}
if (!this.rootlessServer && !this.createRootActor) {
throw new Error("Use DebuggerServer.addActors() to add a root actor " +
"implementation.");
}
},
/**
* Register all type of actors. Only register the one that are not already
* registered.
- *
- * @param root boolean
- * Registers the root actor from webbrowser module, which is used to
- * connect to and fetch any other actor.
- * @param browser boolean
- * Registers all the parent process actors useful for debugging the
- * runtime itself, like preferences and addons actors.
- * @param tab boolean
- * Registers all the tab actors like console, script, ... all useful
- * for debugging a target context.
- * @param windowType string
- * "windowtype" attribute of the main chrome windows. Used by some
- * actors to retrieve them.
*/
- registerActors({ root = true, browser = true, tab = true,
- windowType = null }) {
+ registerActors(
+ options/* : RegisterActorOptions */
+ )/* :void */ {
+ // Set the default values.
+ const {windowType, browser, root, tab} = Object.assign({}, {
+ root: true,
+ browser: true,
+ tab: true,
+ windowType: null,
+ }, options);
+
if (windowType) {
this.chromeWindowType = windowType;
}
if (browser) {
this.addBrowserActors(this.chromeWindowType);
}
@@ -280,63 +395,41 @@ var DebuggerServer = {
}
if (tab) {
this.addTabActors();
}
},
/**
- * Load a subscript into the debugging global.
- *
- * @param url string A url that will be loaded as a subscript into the
- * debugging global. The user must load at least one script
- * that implements a createRootActor() function to create the
- * server's root actor.
+ * The provided url will be loaded as a subscript into the debugging global. The user
+ * must load at least one script that implements a createRootActor() function to create
+ * the server's root actor.
*/
- addActors(url) {
+ addActors(url/* : string*/)/* :void */ {
loadSubScript.call(this, url);
},
/**
- * Register a CommonJS module with the debugger server.
- * @param id string
- * The ID of a CommonJS module. This module must export 'register'
- * and 'unregister' functions if no `options` argument is given.
- * If `options` is set, the actor is going to be registered
- * immediately, but loaded only when a client starts sending packets
- * to an actor with the same id.
+ * Register a CommonJS module with the debugger server. The provided ID must be a
+ * CommonJS module. This module must export 'register' and 'unregister' functions
+ * if no `options` argument is given. If `options` is set, the actor is going to be
+ * registered immediately, but loaded only when a client starts sending packets to an
+ * actor with the same id.
*
- * @param options object (optional)
- * This parameter is still optional, but not providing it is
- * deprecated and will result in eagerly loading the actor module
- * with the memory overhead that entails.
- * An object with 3 mandatory attributes:
- * - prefix (string):
- * The prefix of an actor is used to compute:
- * - the `actorID` of each new actor instance (ex: prefix1).
- * (See ActorPool.addActor)
- * - the actor name in the listTabs request. Sending a listTabs
- * request to the root actor returns actor IDs. IDs are in
- * dictionaries, with actor names as keys and actor IDs as values.
- * The actor name is the prefix to which the "Actor" string is
- * appended. So for an actor with the `console` prefix, the actor
- * name will be `consoleActor`.
- * - constructor (string):
- * the name of the exported symbol to be used as the actor
- * constructor.
- * - type (a dictionary of booleans with following attribute names):
- * - "global"
- * registers a global actor instance, if true.
- * A global actor has the root actor as its parent.
- * - "tab"
- * registers a tab actor instance, if true.
- * A new actor will be created for each tab and each app.
+ * This options parameter is still optional, but not providing it is deprecated and
+ * will result in eagerly loading the actor module with the memory overhead that
+ * entails.
+ *
+ * See the type definition of `RegisterModuleOptions` for full configuration details.
*/
- registerModule(id, options) {
+ registerModule(
+ id/* : string */,
+ options/* : ?RegisterModuleOptions */
+ )/* :void */ {
if (id in gRegisteredModules) {
return;
}
if (options) {
// Lazy loaded actors
let {prefix, constructor, type} = options;
if (typeof (prefix) !== "string") {
@@ -365,36 +458,38 @@ var DebuggerServer = {
this.addTabActor(mod, name);
}
if (mod.globalActor) {
this.addGlobalActor(mod, name);
}
} else {
// Deprecated actors being loaded at startup
let moduleAPI = ModuleAPI();
- let mod = require(id);
+ // Flow doesn't want dynamic require calls yet, cast it into a generic function.
+ let flowRequire = (require/* : string => Object */);
+ let mod = flowRequire(id);
mod.register(moduleAPI);
gRegisteredModules[id] = {
module: mod,
api: moduleAPI
};
}
},
/**
* Returns true if a module id has been registered.
*/
- isModuleRegistered(id) {
+ isModuleRegistered(id/* :string */)/* :boolean */ {
return (id in gRegisteredModules);
},
/**
* Unregister a previously-loaded CommonJS module from the debugger server.
*/
- unregisterModule(id) {
+ unregisterModule(id/* :string */)/* :void */ {
let mod = gRegisteredModules[id];
if (!mod) {
throw new Error("Tried to unregister a module that was not previously registered.");
}
// Lazy actors
if (mod.tabActor) {
this.removeTabActor(mod);
@@ -417,17 +512,20 @@ var DebuggerServer = {
*
* /!\ Be careful when adding a new actor, especially global actors.
* Any new global actor will be exposed and returned by the root actor.
*
* That's the reason why tab actors aren't loaded on demand via
* restrictPrivileges=true, to prevent exposing them on b2g parent process's
* root actor.
*/
- addBrowserActors(windowType = null, restrictPrivileges = false) {
+ addBrowserActors(
+ windowType/* :?string */,
+ restrictPrivileges/* :boolean */ = false
+ )/* :void */ {
if (windowType) {
this.chromeWindowType = windowType;
}
this.registerModule("devtools/server/actors/webbrowser");
if (!restrictPrivileges) {
this.addTabActors();
this.registerModule("devtools/server/actors/preference", {
@@ -456,17 +554,17 @@ var DebuggerServer = {
constructor: "HeapSnapshotFileActor",
type: { global: true }
});
},
/**
* Install tab actors.
*/
- addTabActors() {
+ addTabActors()/* :void */ {
this.registerModule("devtools/server/actors/webconsole", {
prefix: "console",
constructor: "WebConsoleActor",
type: { tab: true }
});
this.registerModule("devtools/server/actors/inspector", {
prefix: "inspector",
constructor: "InspectorActor",
@@ -577,39 +675,37 @@ var DebuggerServer = {
this.registerModule("devtools/server/actors/accessibility", {
prefix: "accessibility",
constructor: "AccessibilityActor",
type: { tab: true }
});
},
/**
- * Passes a set of options to the BrowserAddonActors for the given ID.
- *
- * @param id string
- * The ID of the add-on to pass the options to
- * @param options object
- * The options.
- * @return a promise that will be resolved when complete.
+ * Passes a set of options to the BrowserAddonActors for the given ID of the add-on.
*/
- setAddonOptions(id, options) {
+ setAddonOptions(
+ id/* :string */,
+ options/* :Object */
+ )/* :Promise<void> */ {
if (!this._initialized) {
return Promise.resolve();
}
let promises = [];
// Pass to all connections
for (let connID of Object.getOwnPropertyNames(this._connections)) {
promises.push(this._connections[connID].setAddonOptions(id, options));
}
return SyncPromise.all(promises);
},
+ // flowIgnore: getters and setters don't work yet.
get listeningSockets() {
return this._listeners.length;
},
/**
* Creates a socket listener for remote debugger connections.
*
* After calling this, set some socket options, such as the port / path to
@@ -631,25 +727,25 @@ var DebuggerServer = {
this._checkInit();
return DebuggerSocket.createListener();
},
/**
* Add a SocketListener instance to the server's set of active
* SocketListeners. This is called by a SocketListener after it is opened.
*/
- _addListener(listener) {
+ _addListener(listener/* : typeof SocketListener*/) {
this._listeners.push(listener);
},
/**
* Remove a SocketListener instance from the server's set of active
* SocketListeners. This is called by a SocketListener after it is closed.
*/
- _removeListener(listener) {
+ _removeListener(listener/* : typeof SocketListener*/) {
this._listeners = this._listeners.filter(l => l !== listener);
},
/**
* Closes and forgets all previously opened listeners.
*
* @return boolean
* Whether any listeners were actually closed.
@@ -662,27 +758,24 @@ var DebuggerServer = {
for (let listener of this._listeners) {
listener.close();
}
return true;
},
/**
- * Creates a new connection to the local debugger speaking over a fake
- * transport. This connection results in straightforward calls to the onPacket
- * handlers of each side.
- *
- * @param prefix string [optional]
- * If given, all actors in this connection will have names starting
- * with |prefix + '/'|.
- * @returns a client-side DebuggerTransport for communicating with
- * the newly-created connection.
+ * Creates a new connection to the local debugger speaking over a fake transport.
+ * This connection results in straightforward calls to the onPacket handlers of each
+ * side. If a string is given, all actors in this connection will have names starting
+ * with |prefix + '/'|.
*/
- connectPipe(prefix) {
+ connectPipe(
+ prefix/* :?string */
+ )/* :DebuggerTransport */ {
this._checkInit();
let serverTransport = new LocalDebuggerTransport();
let clientTransport = new LocalDebuggerTransport(serverTransport);
serverTransport.other = clientTransport;
let connection = this._onConnection(serverTransport, prefix);
// I'm putting this here because I trust you.
@@ -701,36 +794,41 @@ var DebuggerServer = {
// But every time you use this, you will feel the shame of having
// used a property that starts with a '_'.
clientTransport._serverConnection = connection;
return clientTransport;
},
/**
- * In a content child process, create a new connection that exchanges
- * nsIMessageSender messages with our parent process.
+ * In a content child process, create a new connection that exchanges nsIMessageSender
+ * messages with our parent process.
*
- * @param prefix
- * The prefix we should use in our nsIMessageSender message names and
- * actor names. This connection will use messages named
- * "debug:<prefix>:packet", and all its actors will have names
- * beginning with "<prefix>/".
+ * The nsIMessageSender connection will use the given prefix to send messages named
+ * "debug:<prefix>:packet", and all its actors will have names beginning with
+ * "<prefix>/".
*/
- connectToParent(prefix, scopeOrManager) {
+ connectToParent(
+ prefix/* : string */,
+ scopeOrManager/* : mixed */
+ ) {
this._checkInit();
let transport = isWorker ?
new WorkerDebuggerTransport(scopeOrManager, prefix) :
new ChildDebuggerTransport(scopeOrManager, prefix);
return this._onConnection(transport, prefix, true);
},
- connectToContent(connection, mm, onDestroy) {
+ connectToContent(
+ connection/* :DebuggerServerConnection */,
+ mm/* :MessageManager<*> */,
+ onDestroy/* :(MessageManager<*>) => void */
+ )/* :void */ {
let deferred = SyncPromise.defer();
let prefix = connection.allocID("content-process");
let actor, childTransport;
mm.addMessageListener("debug:content-process-actor", function listener(msg) {
// Arbitrarily choose the first content process to reply
// XXX: This code needs to be updated if we use more than one content process
@@ -798,17 +896,22 @@ var DebuggerServer = {
Services.obs.addObserver(onMessageManagerClose,
"message-manager-close");
EventEmitter.on(connection, "closed", onClose);
return deferred.promise;
},
- connectToWorker(connection, dbg, id, options) {
+ connectToWorker(
+ connection/* :DebuggerServerConnection */,
+ dbg/* : Object */,
+ id/* :string */,
+ options/* : Object */
+ )/* :Promise<*> */ {
return new Promise((resolve, reject) => {
// Step 1: Ensure the worker debugger is initialized.
if (!dbg.isInitialized) {
dbg.initialize("resource://devtools/server/worker.js");
// Create a listener for rpc requests from the worker debugger. Only do
// this once, when the worker debugger is first initialized, rather than
// for each connection.
@@ -932,34 +1035,43 @@ var DebuggerServer = {
};
dbg.addListener(listener);
});
},
/**
* Check if the server is running in the child process.
*/
+ // flowIgnore: getters and setters don't work yet.
get isInChildProcess() {
return Services.appinfo.processType != Ci.nsIXULRuntime.PROCESS_TYPE_DEFAULT;
},
/**
* In a chrome parent process, ask all content child processes
* to execute a given module setup helper.
- *
- * @param module
- * The module to be required
- * @param setupChild
- * The name of the setup helper exported by the above module
- * (setup helper signature: function ({mm}) { ... })
- * @param waitForEval (optional)
- * If true, the returned promise only resolves once code in child
- * is evaluated
*/
- setupInChild({ module, setupChild, args, waitForEval }) {
+ setupInChild(
+ options /* : {
+ // The id of the module to be required.
+ module: string,
+
+ // The name of the setup helper exported by the above module
+ setupChild: string,
+
+ // The serializable args applied to the setupChild method.
+ args?: Array<mixed>,
+
+ // The arguments applied to the setupChild method.
+ // If true, the returned promise only resolves once code in child
+ // is evaluated
+ waitForEval?: boolean,
+ }*/
+ )/* : Promise<void> */ {
+ let { module, setupChild, args, waitForEval } = options;
if (this._childMessageManagers.size == 0) {
return Promise.resolve();
}
return new Promise(done => {
// If waitForEval is set, pass a unique id and expect child.js to send
// a message back once the code in child is evaluated.
if (typeof (waitForEval) != "boolean") {
waitForEval = false;
@@ -993,34 +1105,33 @@ var DebuggerServer = {
done();
}
});
},
/**
* Live list of all currenctly attached child's message managers.
*/
- _childMessageManagers: new Set(),
+ _childMessageManagers: (new Set() /* : Set<MessageManager<*>> */),
/**
- * Connect to a child process.
- *
- * @param object connection
- * The debugger server connection to use.
- * @param nsIDOMElement frame
- * The browser element that holds the child process.
- * @param function [onDestroy]
- * Optional function to invoke when the child process closes
- * or the connection shuts down. (Need to forget about the
- * related TabActor)
- * @return object
- * A promise object that is resolved once the connection is
- * established.
+ * Connect to a child process. The promise resolves when the connection is established.
*/
- connectToChild(connection, frame, onDestroy, {addonId} = {}) {
+ connectToChild(
+ connection/* :DebuggerServerConnection */,
+ // The frame holds the child process.
+ // TODO - This XULBrowser type should be further evaluated make sure it's correctly
+ // typed.
+ frame/* :XULBrowser */,
+ // This optional function is invoked when the child process closes or the connection
+ // shuts down. (Need to forget about the related TabActor)
+ onDestroy/* : ?(MessageManager<*>) => void */,
+ objWithAddonId /* :?{ addonId: string } */
+ )/* :Promise<void> */ {
+ let {addonId} = objWithAddonId || {};
let deferred = SyncPromise.defer();
// Get messageManager from XUL browser (which might be a specialized tunnel for RDM)
// or else fallback to asking the frameLoader itself.
let mm = frame.messageManager || frame.frameLoader.messageManager;
mm.loadFrameScript("resource://devtools/server/child.js", false);
let trackMessageManager = () => {
@@ -1052,19 +1163,20 @@ var DebuggerServer = {
let onSetupInParent = function (msg) {
// We may have multiple connectToChild instance running for the same tab
// and need to filter the messages.
if (msg.json.prefix != connPrefix) {
return false;
}
let { module, setupParent } = msg.json;
- let m;
+ let m/* :Object */;
try {
+ // flowIgnore: Flow does not understand dynamic requires.
m = require(module);
if (!(setupParent in m)) {
dumpn(`ERROR: module '${module}' does not export '${setupParent}'`);
return false;
}
parentModules.push(m[setupParent]({ mm, prefix: connPrefix }));
@@ -1098,17 +1210,18 @@ var DebuggerServer = {
dumpn("establishing forwarding for app with prefix " + prefix);
actor = msg.json.actor;
deferred.resolve(actor);
}).bind(this);
// Listen for browser frame swap
- let onBrowserSwap = ({ detail: newFrame }) => {
+ let onBrowserSwap = (event/* :BrowserSwapEvent */) => {
+ const newFrame = event.detail;
// Remove listeners from old frame and mm
untrackMessageManager();
// Update frame and mm to point to the new browser frame
frame = newFrame;
// Get messageManager from XUL browser (which might be a specialized tunnel for RDM)
// or else fallback to asking the frameLoader itself.
mm = frame.messageManager || frame.frameLoader.messageManager;
// Add listeners to new frame and mm
@@ -1205,17 +1318,21 @@ var DebuggerServer = {
* connectPipe(), from connectToParent, or from an incoming socket
* connection handler.
*
* If present, |forwardingPrefix| is a forwarding prefix that a parent
* server is using to recognizes messages intended for this server. Ensure
* that all our actors have names beginning with |forwardingPrefix + '/'|.
* In particular, the root actor's name will be |forwardingPrefix + '/root'|.
*/
- _onConnection(transport, forwardingPrefix, noRootActor = false) {
+ _onConnection(
+ transport/* :DebuggerTransport */,
+ forwardingPrefix/* :string */,
+ noRootActor/* :boolean */ = false
+ ) {
let connID;
if (forwardingPrefix) {
connID = forwardingPrefix + "/";
} else {
// Multiple servers can be started at the same time, and when that's the
// case, they are loaded in separate devtools loaders.
// So, use the current loader ID to prefix the connection ID and make it
// unique.
@@ -1240,72 +1357,59 @@ var DebuggerServer = {
this.emit("connectionchange", "opened", conn);
return conn;
},
/**
* Remove the connection from the debugging server.
*/
- _connectionClosed(connection) {
+ _connectionClosed(connection/* :DebuggerServerConnection */) {
+ // Flow does not understand this dynamic deletion, but even if it's
+ // wrong, it shouldn't throw an error.
+ // flowIgnore
delete this._connections[connection.prefix];
this.emit("connectionchange", "closed", connection);
},
// DebuggerServer extension API.
- setRootActor(actorFactory) {
+ setRootActor(actorFactory/* :DebuggerServerConnection => Actor */) {
this.createRootActor = actorFactory;
},
/**
- * Registers handlers for new tab-scoped request types defined dynamically.
- * This is used for example by add-ons to augment the functionality of the tab
- * actor. Note that the name or actorPrefix of the request type is not allowed
- * to clash with existing protocol packet properties, like 'title', 'url' or
- * 'actor', since that would break the protocol.
+ * Registers handlers for new tab-scoped request types defined dynamically. This is
+ * used for example by add-ons to augment the functionality of the tab actor. Note that
+ * the name or actorPrefix of the request type is not allowed to clash with existing
+ * protocol packet properties, like 'title', 'url' or 'actor', since that would break
+ * the protocol.
*
- * @param actor function, object
- * In case of function:
- * The constructor function for this request type. This expects to be
- * called as a constructor (i.e. with 'new'), and passed two
- * arguments: the DebuggerServerConnection, and the BrowserTabActor
- * with which it will be associated.
- * Only used for deprecated eagerly loaded actors.
- * In case of object:
- * First argument of RegisteredActorFactory constructor.
- * See the it's definition for more info.
- *
- * @param name string [optional]
- * The name of the new request type. If this is not present, the
- * actorPrefix property of the constructor prototype is used.
+ * /!\ Passing Actors directly in is deprecated as they are not lazily loaded.
*/
- addTabActor(actor, name = actor.prototype.actorPrefix) {
+ addTabActor(
+ actor/* :typeof Actor | RegisteredActorFactoryOptions */,
+ name/* :string */ = actor.prototype.actorPrefix
+ ) {
if (["title", "url", "actor"].indexOf(name) != -1) {
throw Error(name + " is not allowed");
}
if (DebuggerServer.tabActorFactories.hasOwnProperty(name)) {
throw Error(name + " already exists");
}
DebuggerServer.tabActorFactories[name] = new RegisteredActorFactory(actor, name);
},
/**
* Unregisters the handler for the specified tab-scoped request type.
* This may be used for example by add-ons when shutting down or upgrading.
* When unregistering an existing tab actor remove related tab factory
* as well as all existing instances of the actor.
- *
- * @param actor function, object
- * In case of function:
- * The constructor function for this request type.
- * In case of object:
- * Same object being given to related addTabActor call.
*/
- removeTabActor(actor) {
+ removeTabActor(actor/* :Actor | RegisteredActorFactoryOptions */)/* :void */ {
for (let name in DebuggerServer.tabActorFactories) {
let handler = DebuggerServer.tabActorFactories[name];
if ((handler.name && handler.name == actor.name) ||
(handler.id && handler.id == actor.id)) {
delete DebuggerServer.tabActorFactories[name];
for (let connID of Object.getOwnPropertyNames(this._connections)) {
// DebuggerServerConnection in child process don't have rootActor
if (this._connections[connID].rootActor) {
@@ -1319,54 +1423,38 @@ var DebuggerServer = {
/**
* Registers handlers for new browser-scoped request types defined
* dynamically. This is used for example by add-ons to augment the
* functionality of the root actor. Note that the name or actorPrefix of the
* request type is not allowed to clash with existing protocol packet
* properties, like 'from', 'tabs' or 'selected', since that would break the
* protocol.
*
- * @param actor function, object
- * In case of function:
- * The constructor function for this request type. This expects to be
- * called as a constructor (i.e. with 'new'), and passed two
- * arguments: the DebuggerServerConnection, and the BrowserRootActor
- * with which it will be associated.
- * Only used for deprecated eagerly loaded actors.
- * In case of object:
- * First argument of RegisteredActorFactory constructor.
- * See the it's definition for more info.
- *
- * @param name string [optional]
- * The name of the new request type. If this is not present, the
- * actorPrefix property of the constructor prototype is used.
+ * /!\ Passing Actors directly in is deprecated as they are not lazily loaded.
*/
- addGlobalActor(actor, name = actor.prototype.actorPrefix) {
+ addGlobalActor(
+ actor/* :typeof Actor | RegisteredActorFactoryOptions */,
+ name/* :string */ = actor.prototype.actorPrefix
+ )/* :void */ {
if (["from", "tabs", "selected"].indexOf(name) != -1) {
throw Error(name + " is not allowed");
}
if (DebuggerServer.globalActorFactories.hasOwnProperty(name)) {
throw Error(name + " already exists");
}
DebuggerServer.globalActorFactories[name] = new RegisteredActorFactory(actor, name);
},
/**
* Unregisters the handler for the specified browser-scoped request type.
* This may be used for example by add-ons when shutting down or upgrading.
* When unregistering an existing global actor remove related global factory
* as well as all existing instances of the actor.
- *
- * @param actor function, object
- * In case of function:
- * The constructor function for this request type.
- * In case of object:
- * Same object being given to related addGlobalActor call.
*/
- removeGlobalActor(actor) {
+ removeGlobalActor(actor/* :Actor | RegisteredActorFactoryOptions */) {
for (let name in DebuggerServer.globalActorFactories) {
let handler = DebuggerServer.globalActorFactories[name];
if ((handler.name && handler.name == actor.name) ||
(handler.id && handler.id == actor.id)) {
delete DebuggerServer.globalActorFactories[name];
for (let connID of Object.getOwnPropertyNames(this._connections)) {
this._connections[connID].rootActor.removeActorByName(name);
}
@@ -1374,17 +1462,17 @@ var DebuggerServer = {
}
},
/**
* Called when DevTools are unloaded to remove the contend process server script for the
* list of scripts loaded for each new content process. Will also remove message
* listeners from already loaded scripts.
*/
- removeContentServerScript() {
+ removeContentServerScript()/* :void */ {
Services.ppmm.removeDelayedProcessScript(CONTENT_PROCESS_DBG_SERVER_SCRIPT);
try {
Services.ppmm.broadcastAsyncMessage("debug:close-content-server");
} catch (e) {
// Nothing to do
}
},
@@ -1393,31 +1481,43 @@ var DebuggerServer = {
*
* ⚠ TO BE USED ONLY FROM SERVER CODE OR TESTING ONLY! ⚠`
*
* This is helpful for some tests which depend on reaching into the server to check some
* properties of an actor, and it is also used by the actors related to the
* DevTools WebExtensions API to be able to interact with the actors created for the
* panels natively provided by the DevTools Toolbox.
*/
- searchAllConnectionsForActor(actorID) {
+ searchAllConnectionsForActor(actorID/* :string */)/* :Actor | null */ {
// NOTE: the actor IDs are generated with the following format:
//
// `server${loaderID}.conn${ConnectionID}${ActorPrefix}${ActorID}`
//
// as an optimization we can come up with a regexp to query only
// the right connection via its id.
for (let connID of Object.getOwnPropertyNames(this._connections)) {
let actor = this._connections[connID].getActor(actorID);
if (actor) {
return actor;
}
}
return null;
},
+
+ // When using DebuggerServer.addActors, some symbols are expected to be in
+ // the scope of the added actor even before the corresponding modules are
+ // loaded, so let's explicitly bind the expected symbols here.
+ Components: Components,
+ Ci: Ci,
+ Cu: Cu,
+ require: require,
+ Services: Services,
+ DebuggerServer: DebuggerServer,
+ ActorPool: ActorPool,
+ DevToolsUtils: DevToolsUtils,
};
// Expose these to save callers the trouble of importing DebuggerSocket
DevToolsUtils.defineLazyGetter(DebuggerServer, "Authenticators", () => {
return Authentication.Authenticators;
});
DevToolsUtils.defineLazyGetter(DebuggerServer, "AuthenticationResult", () => {
return Authentication.AuthenticationResult;
@@ -1426,77 +1526,70 @@ DevToolsUtils.defineLazyGetter(DebuggerS
OldEventEmitter.decorate(DebuggerServer);
if (this.exports) {
exports.DebuggerServer = DebuggerServer;
exports.ActorPool = ActorPool;
exports.OriginalLocation = OriginalLocation;
}
-// Needed on B2G (See header note)
-this.DebuggerServer = DebuggerServer;
-this.ActorPool = ActorPool;
-this.OriginalLocation = OriginalLocation;
-
-// When using DebuggerServer.addActors, some symbols are expected to be in
-// the scope of the added actor even before the corresponding modules are
-// loaded, so let's explicitly bind the expected symbols here.
-var includes = ["Components", "Ci", "Cu", "require", "Services", "DebuggerServer",
- "ActorPool", "DevToolsUtils"];
-includes.forEach(name => {
- DebuggerServer[name] = this[name];
-});
+{
+ // Needed on B2G (See header note)
+ const global = (this/* :Object */);
+ global.DebuggerServer = DebuggerServer;
+ global.ActorPool = ActorPool;
+ global.OriginalLocation = OriginalLocation;
+}
/**
- * Creates a DebuggerServerConnection.
- *
- * Represents a connection to this debugging global from a client.
- * Manages a set of actors and actor pools, allocates actor ids, and
- * handles incoming requests.
- *
- * @param prefix string
- * All actor IDs created by this connection should be prefixed
- * with prefix.
- * @param transport transport
- * Packet transport for the debugging protocol.
+ * Represents a connection to this debugging global from a client. Manages a set of
+ * actors and actor pools, allocates actor ids, and handles incoming requests.
*/
-function DebuggerServerConnection(prefix, transport) {
+function DebuggerServerConnection(
+ // This string will be used as a prefix for all actor IDs created by this connection.
+ prefix/* :string */,
+ transport/* :DebuggerTransport */
+) {
this._prefix = prefix;
this._transport = transport;
this._transport.hooks = this;
this._nextID = 1;
this._actorPool = new ActorPool(this);
this._extraPools = [this._actorPool];
- // Responses to a given actor must be returned the the client
- // in the same order as the requests that they're replying to, but
- // Implementations might finish serving requests in a different
- // order. To keep things in order we generate a promise for each
- // request, chained to the promise for the request before it.
- // This map stores the latest request promise in the chain, keyed
- // by an actor ID string.
- this._actorResponses = new Map();
+ // Responses to a given actor must be returned the the client in the same order as the
+ // requests that they're replying to, but implementations might finish serving requests
+ // in a different order. To keep things in order we generate a promise for each
+ // request, chained to the promise for the request before it. This map stores the
+ // latest request promise in the chain, keyed by an actor ID string.
+ this._actorResponses = (new Map()/* : Map<string, mixed> */);
/*
* We can forward packets to other servers, if the actors on that server
* all use a distinct prefix on their names. This is a map from prefixes
* to transports: it maps a prefix P to a transport T if T conveys
* packets to the server whose actors' names all begin with P + "/".
*/
- this._forwardingPrefixes = new Map();
+ this._forwardingPrefixes = (new Map()/* :Map<string, DebuggerTransport> */);
}
DebuggerServerConnection.prototype = {
_prefix: null,
+ /* ::
+ prefix: ('': string | null),
+ */
+ // flowIgnore: getters and setters don't work yet.
get prefix() {
return this._prefix;
},
_transport: null,
+ /* :: transport: DebuggerTransport, */
+ // flowIgnore: getters and setters don't work yet.
get transport() {
return this._transport;
},
/**
* Message manager used to communicate with the parent process,
* set by child.js. Is only defined for connections instantiated
* within a child process.
@@ -1512,41 +1605,43 @@ DebuggerServerConnection.prototype = {
send(packet) {
this.transport.send(packet);
},
/**
* Used when sending a bulk reply from an actor.
* @see DebuggerTransport.prototype.startBulkSend
*/
- startBulkSend(header) {
+ startBulkSend(header/* :TransportHeader */)/* :Promise<void> */ {
return this.transport.startBulkSend(header);
},
- allocID(prefix) {
- return this.prefix + (prefix || "") + this._nextID++;
+ allocID(prefix/* :string */)/* :string */ {
+ const connectionPrefix = this.prefix;
+ if (connectionPrefix === null) {
+ throw new Error("The connection's prefix cannot be null.");
+ }
+ return connectionPrefix + (prefix || "") + this._nextID++;
},
/**
* Add a map of actor IDs to the connection.
*/
- addActorPool(actorPool) {
+ addActorPool(actorPool/* :ActorPool */)/* :void */ {
this._extraPools.push(actorPool);
},
/**
* Remove a previously-added pool of actors to the connection.
- *
- * @param ActorPool actorPool
- * The ActorPool instance you want to remove.
- * @param boolean noCleanup [optional]
- * True if you don't want to destroy each actor from the pool, false
- * otherwise.
*/
- removeActorPool(actorPool, noCleanup) {
+ removeActorPool(
+ actorPool/* :ActorPool */,
+ // Set to true if you don't want to destroy each actor from the pool
+ noCleanup/* :boolean */
+ )/* :void */ {
// When a connection is closed, it removes each of its actor pools. When an
// actor pool is removed, it calls the destroy method on each of its
// actors. Some actors, such as ThreadActor, manage their own actor pools.
// When the destroy method is called on these actors, they manually
// remove their actor pools. Consequently, this method is reentrant.
//
// In addition, some actors, such as ThreadActor, perform asynchronous work
// (in the case of ThreadActor, because they need to resume), before they
@@ -1569,55 +1664,52 @@ DebuggerServerConnection.prototype = {
pool.forEach(p => p.destroy());
}
}
},
/**
* Add an actor to the default actor pool for this connection.
*/
- addActor(actor) {
+ addActor(actor/* :Actor */)/* :void */ {
this._actorPool.addActor(actor);
},
/**
* Remove an actor to the default actor pool for this connection.
*/
- removeActor(actor) {
+ removeActor(actor/* :Actor */)/* :void */ {
this._actorPool.removeActor(actor);
},
/**
* Match the api expected by the protocol library.
*/
- unmanage(actor) {
+ unmanage(actor/* :Actor */)/* :void */ {
return this.removeActor(actor);
},
/**
* Look up an actor implementation for an actorID. Will search
* all the actor pools registered with the connection.
- *
- * @param actorID string
- * Actor ID to look up.
*/
- getActor(actorID) {
+ getActor(actorID/* :string */)/* :Actor | null */ {
let pool = this.poolFor(actorID);
if (pool) {
return pool.get(actorID);
}
if (actorID === "root") {
return this.rootActor;
}
return null;
},
- _getOrCreateActor(actorID) {
+ _getOrCreateActor(actorID/* :string */)/* :Actor | null */ {
let actor = this.getActor(actorID);
if (!actor) {
this.transport.send({ from: actorID ? actorID : "root",
error: "noSuchActor",
message: "No such actor for ID: " + actorID });
return null;
}
@@ -1635,36 +1727,43 @@ DebuggerServerConnection.prototype = {
// or ObservedActorFactory instances.
throw new Error("Unexpected actor constructor/function in ActorPool " +
"for actorID=" + actorID + ".");
}
return actor;
},
- poolFor(actorID) {
+ poolFor(actorID/* :string */)/* :ActorPool | null */ {
for (let pool of this._extraPools) {
if (pool.has(actorID)) {
return pool;
}
}
return null;
},
- _unknownError(prefix, error) {
+ _unknownError(
+ prefix/* :string */,
+ error/* :Error */
+ )/* : {error: string, message: string } */ {
let errorString = prefix + ": " + DevToolsUtils.safeErrorString(error);
reportError(errorString);
dumpn(errorString);
return {
error: "unknownError",
message: errorString
};
},
- _queueResponse: function (from, type, responseOrPromise) {
+ _queueResponse(
+ from/* :string */,
+ type/* :string */,
+ responseOrPromise
+ ) {
let pendingResponse = this._actorResponses.get(from) || SyncPromise.resolve(null);
let responsePromise = pendingResponse.then(() => {
return responseOrPromise;
}).then(response => {
if (!response.from) {
response.from = from;
}
this.transport.send(response);
diff --git a/devtools/shared/security/socket.js b/devtools/shared/security/socket.js
--- a/devtools/shared/security/socket.js
+++ b/devtools/shared/security/socket.js
@@ -788,8 +788,9 @@ ServerSocketConnection.prototype = {
};
DebuggerSocket.createListener = function () {
return new SocketListener();
};
exports.DebuggerSocket = DebuggerSocket;
+exports.SocketListener = SocketListener;
diff --git a/devtools/types/flow-typed/Services.js b/devtools/types/flow-typed/Services.js
new file mode 100644
--- /dev/null
+++ b/devtools/types/flow-typed/Services.js
@@ -0,0 +1,9 @@
+/* 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/. */
+// @flow
+/* ::
+declare module 'Services' {
+ declare module.exports: Object;
+}
+*/
diff --git a/devtools/types/flow-typed/chrome.js b/devtools/types/flow-typed/chrome.js
new file mode 100644
--- /dev/null
+++ b/devtools/types/flow-typed/chrome.js
@@ -0,0 +1,9 @@
+/* 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/. */
+// @flow
+/* ::
+declare module 'chrome' {
+ declare module.exports: Object;
+}
+*/
diff --git a/devtools/types/flow-typed/globals.js b/devtools/types/flow-typed/globals.js
new file mode 100644
--- /dev/null
+++ b/devtools/types/flow-typed/globals.js
@@ -0,0 +1,22 @@
+/* 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/. */
+// @flow
+/* ::
+declare var isWorker: boolean;
+declare var dump: string => void;
+declare var reportError: any => void;
+declare var uneval: (any) => string;
+declare var Components: Boolean;
+
+// TODO - Hook this up properly to devtools/shared/Loader.jsm
+declare var loader: {
+ lazyRequireGetter: (
+ scope: Object,
+ property: string,
+ module: string,
+ destructure: any
+ ) => void;
+ id: string,
+};
+*/
diff --git a/devtools/types/flow-typed/xul.js b/devtools/types/flow-typed/xul.js
new file mode 100644
--- /dev/null
+++ b/devtools/types/flow-typed/xul.js
@@ -0,0 +1,27 @@
+/* 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/. */
+// @flow
+
+/* ::
+import type { MessageManager } from 'devtools/types/services';
+
+declare class XULBrowser {
+ // Sometimes we send arbitrary events across browsers. Overload the built-in listeners.
+ // This should probably be explicitly typed.
+ addEventListener(
+ type: string,
+ listener: * => *,
+ optionsOrUseCapture?: EventListenerOptionsOrUseCapture
+ ): void;
+ removeEventListener(
+ type: string,
+ listener: * => *,
+ optionsOrUseCapture?: EventListenerOptionsOrUseCapture
+ ): void;
+ messageManager: MessageManager<*>,
+ frameLoader: {
+ messageManager: MessageManager<*>
+ }
+}
+*/
diff --git a/devtools/types/services.js b/devtools/types/services.js
new file mode 100644
--- /dev/null
+++ b/devtools/types/services.js
@@ -0,0 +1,38 @@
+/* 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/. */
+// @flow
+
+/* ::
+export type nsIMessageListenerPayload<Payload> = {
+ target: mixed,
+ name: string,
+ sync: boolean,
+ data: Payload,
+ json: Payload,
+ objects: mixed,
+ principal: mixed,
+}
+
+// https://developer.mozilla.org/en-US/docs/Mozilla/Tech/XPCOM/Reference/Interface/nsIMessageListener
+export type nsIMessageListener<Payload> = nsIMessageListenerPayload<Payload> => void
+
+// https://developer.mozilla.org/en-US/Firefox/Multiprocess_Firefox/Message_Manager/Message_manager_overview
+export interface MessageManager<Payload> {
+ childCount: number,
+ getChildAt: (index: number) => MessageManager<*>,
+ loadFrameScript: (
+ aURL: string,
+ aAllowDelayedLoad: boolean,
+ aRunInGlobalScope: boolean
+ ) => void,
+ broadcastAsyncMessage: (messageName: string, payload: Object, objects?: Object) => void,
+ sendAsyncMessage: (messageName: string, payload?: Object, objects?: Object) => void,
+ addMessageListener: (
+ messageName: string,
+ listener: nsIMessageListener<Payload>,
+ listenWhenClosed?: boolean
+ ) => void,
+ removeMessageListener: (messageName: string, mixed => void) => void
+};
+*/
diff --git a/devtools/yarn.lock b/devtools/yarn.lock
new file mode 100644
--- /dev/null
+++ b/devtools/yarn.lock
@@ -0,0 +1,7 @@
+# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
+# yarn lockfile v1
+
+
+flow-bin@^0.58.0:
+ version "0.58.0"
+ resolved "https://registry.yarnpkg.com/flow-bin/-/flow-bin-0.58.0.tgz#62d5a776589419e5656800a0e5230a5e585ca65e"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment