2014-04-13 10:47:27 +04: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";
|
|
|
|
|
2015-04-23 12:24:49 +03:00
|
|
|
const { createSystem, connectFront, disconnectFront } = require("gcli/system");
|
2016-06-09 18:28:36 +03:00
|
|
|
const { GcliFront } = require("devtools/shared/fronts/gcli");
|
2014-04-13 10:47:27 +04:00
|
|
|
|
2015-04-23 12:24:49 +03:00
|
|
|
/**
|
|
|
|
* This is the basic list of modules that should be loaded into each
|
|
|
|
* requisition instance whether server side or client side
|
|
|
|
*/
|
|
|
|
exports.baseModules = [
|
|
|
|
"gcli/types/delegate",
|
|
|
|
"gcli/types/selection",
|
|
|
|
"gcli/types/array",
|
|
|
|
|
|
|
|
"gcli/types/boolean",
|
|
|
|
"gcli/types/command",
|
|
|
|
"gcli/types/date",
|
|
|
|
"gcli/types/file",
|
|
|
|
"gcli/types/javascript",
|
|
|
|
"gcli/types/node",
|
|
|
|
"gcli/types/number",
|
|
|
|
"gcli/types/resource",
|
|
|
|
"gcli/types/setting",
|
|
|
|
"gcli/types/string",
|
|
|
|
"gcli/types/union",
|
|
|
|
"gcli/types/url",
|
|
|
|
|
|
|
|
"gcli/fields/fields",
|
|
|
|
"gcli/fields/delegate",
|
|
|
|
"gcli/fields/selection",
|
|
|
|
|
|
|
|
"gcli/ui/focus",
|
|
|
|
"gcli/ui/intro",
|
|
|
|
|
|
|
|
"gcli/converters/converters",
|
|
|
|
"gcli/converters/basic",
|
|
|
|
"gcli/converters/terminal",
|
|
|
|
|
|
|
|
"gcli/languages/command",
|
|
|
|
"gcli/languages/javascript",
|
|
|
|
|
|
|
|
"gcli/commands/clear",
|
|
|
|
"gcli/commands/context",
|
|
|
|
"gcli/commands/help",
|
|
|
|
"gcli/commands/pref",
|
|
|
|
];
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Some commands belong to a tool (see getToolModules). This is a list of the
|
|
|
|
* modules that are *not* owned by a tool.
|
|
|
|
*/
|
|
|
|
exports.devtoolsModules = [
|
2015-09-21 20:04:18 +03:00
|
|
|
"devtools/shared/gcli/commands/addon",
|
|
|
|
"devtools/shared/gcli/commands/appcache",
|
|
|
|
"devtools/shared/gcli/commands/calllog",
|
|
|
|
"devtools/shared/gcli/commands/cmd",
|
|
|
|
"devtools/shared/gcli/commands/cookie",
|
|
|
|
"devtools/shared/gcli/commands/csscoverage",
|
|
|
|
"devtools/shared/gcli/commands/folder",
|
|
|
|
"devtools/shared/gcli/commands/highlight",
|
|
|
|
"devtools/shared/gcli/commands/inject",
|
|
|
|
"devtools/shared/gcli/commands/jsb",
|
|
|
|
"devtools/shared/gcli/commands/listen",
|
2016-01-23 04:59:00 +03:00
|
|
|
"devtools/shared/gcli/commands/mdn",
|
2015-09-28 16:14:00 +03:00
|
|
|
"devtools/shared/gcli/commands/measure",
|
2015-09-21 20:04:18 +03:00
|
|
|
"devtools/shared/gcli/commands/media",
|
|
|
|
"devtools/shared/gcli/commands/pagemod",
|
|
|
|
"devtools/shared/gcli/commands/paintflashing",
|
2015-11-14 17:15:00 +03:00
|
|
|
"devtools/shared/gcli/commands/qsa",
|
2015-09-21 20:04:18 +03:00
|
|
|
"devtools/shared/gcli/commands/restart",
|
|
|
|
"devtools/shared/gcli/commands/rulers",
|
|
|
|
"devtools/shared/gcli/commands/screenshot",
|
|
|
|
"devtools/shared/gcli/commands/security",
|
2014-04-13 10:47:27 +04:00
|
|
|
];
|
|
|
|
|
2015-04-23 12:24:49 +03:00
|
|
|
/**
|
|
|
|
* Register commands from tools with 'command: [ "some/module" ]' definitions.
|
|
|
|
* The map/reduce incantation squashes the array of arrays to a single array.
|
|
|
|
*/
|
2015-05-06 20:34:27 +03:00
|
|
|
try {
|
2016-10-13 00:22:57 +03:00
|
|
|
const { defaultTools } = require("devtools/client/definitions");
|
2015-05-06 20:34:27 +03:00
|
|
|
exports.devtoolsToolModules = defaultTools.map(def => def.commands || [])
|
|
|
|
.reduce((prev, curr) => prev.concat(curr), []);
|
2016-10-13 00:22:57 +03:00
|
|
|
} catch (e) {
|
|
|
|
// "devtools/client/definitions" is only accessible from Firefox
|
2015-05-06 20:34:27 +03:00
|
|
|
exports.devtoolsToolModules = [];
|
|
|
|
}
|
2015-04-23 12:24:49 +03:00
|
|
|
|
2015-05-06 20:34:28 +03:00
|
|
|
/**
|
|
|
|
* Register commands from toolbox buttons with 'command: [ "some/module" ]'
|
|
|
|
* definitions. The map/reduce incantation squashes the array of arrays to a
|
|
|
|
* single array.
|
|
|
|
*/
|
|
|
|
try {
|
2016-10-13 00:22:57 +03:00
|
|
|
const { ToolboxButtons } = require("devtools/client/definitions");
|
2015-05-06 20:34:28 +03:00
|
|
|
exports.devtoolsButtonModules = ToolboxButtons.map(def => def.commands || [])
|
|
|
|
.reduce((prev, curr) => prev.concat(curr), []);
|
2016-10-13 00:22:57 +03:00
|
|
|
} catch (e) {
|
|
|
|
// "devtools/client/definitions" is only accessible from Firefox
|
2015-05-06 20:34:28 +03:00
|
|
|
exports.devtoolsButtonModules = [];
|
|
|
|
}
|
|
|
|
|
2015-04-23 12:24:49 +03:00
|
|
|
/**
|
|
|
|
* Add modules to a system for use in a content process (but don't call load)
|
|
|
|
*/
|
2017-01-04 01:47:28 +03:00
|
|
|
exports.addAllItemsByModule = function (system) {
|
2015-04-23 12:24:49 +03:00
|
|
|
system.addItemsByModule(exports.baseModules, { delayedLoad: true });
|
|
|
|
system.addItemsByModule(exports.devtoolsModules, { delayedLoad: true });
|
|
|
|
system.addItemsByModule(exports.devtoolsToolModules, { delayedLoad: true });
|
2015-05-06 20:34:28 +03:00
|
|
|
system.addItemsByModule(exports.devtoolsButtonModules, { delayedLoad: true });
|
2014-04-13 10:47:27 +04:00
|
|
|
|
2015-09-21 20:04:18 +03:00
|
|
|
const { mozDirLoader } = require("devtools/shared/gcli/commands/cmd");
|
2015-04-23 12:24:49 +03:00
|
|
|
system.addItemsByModule("mozcmd", { delayedLoad: true, loader: mozDirLoader });
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This is WeakMap<Target, Links> where Links is an object that looks like
|
|
|
|
* { refs: number, promise: Promise<System>, front: GcliFront }
|
|
|
|
*/
|
|
|
|
var linksForTarget = new WeakMap();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The toolbox uses the following properties on a command to allow it to be
|
|
|
|
* added to the toolbox toolbar
|
|
|
|
*/
|
|
|
|
var customProperties = [ "buttonId", "buttonClass", "tooltipText" ];
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Create a system which connects to a GCLI in a remote target
|
|
|
|
* @return Promise<System> for the given target
|
|
|
|
*/
|
2017-01-04 01:47:28 +03:00
|
|
|
exports.getSystem = function (target) {
|
2015-04-23 12:24:49 +03:00
|
|
|
const existingLinks = linksForTarget.get(target);
|
|
|
|
if (existingLinks != null) {
|
|
|
|
existingLinks.refs++;
|
|
|
|
return existingLinks.promise;
|
2014-04-13 10:47:27 +04:00
|
|
|
}
|
|
|
|
|
2015-04-23 12:24:49 +03:00
|
|
|
const system = createSystem({ location: "client" });
|
|
|
|
|
|
|
|
exports.addAllItemsByModule(system);
|
|
|
|
|
|
|
|
// Load the client system
|
|
|
|
const links = {
|
|
|
|
refs: 1,
|
|
|
|
system,
|
|
|
|
promise: system.load().then(() => {
|
|
|
|
return GcliFront.create(target).then(front => {
|
|
|
|
links.front = front;
|
|
|
|
return connectFront(system, front, customProperties).then(() => system);
|
|
|
|
});
|
|
|
|
})
|
|
|
|
};
|
2014-04-13 10:47:27 +04:00
|
|
|
|
2015-04-23 12:24:49 +03:00
|
|
|
linksForTarget.set(target, links);
|
|
|
|
return links.promise;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Someone that called getSystem doesn't need it any more, so decrement the
|
|
|
|
* count of users of the system for that target, and destroy if needed
|
|
|
|
*/
|
2017-01-04 01:47:28 +03:00
|
|
|
exports.releaseSystem = function (target) {
|
2015-04-23 12:24:49 +03:00
|
|
|
const links = linksForTarget.get(target);
|
|
|
|
if (links == null) {
|
|
|
|
throw new Error("releaseSystem called for unknown target");
|
|
|
|
}
|
|
|
|
|
|
|
|
links.refs--;
|
|
|
|
if (links.refs === 0) {
|
|
|
|
disconnectFront(links.system, links.front);
|
|
|
|
links.system.destroy();
|
|
|
|
linksForTarget.delete(target);
|
|
|
|
}
|
|
|
|
};
|