summaryrefslogtreecommitdiffstats
path: root/toolkit/jetpack/dev/toolbox.js
diff options
context:
space:
mode:
authorMatt A. Tobin <email@mattatobin.com>2018-02-10 02:51:36 -0500
committerMatt A. Tobin <email@mattatobin.com>2018-02-10 02:51:36 -0500
commit37d5300335d81cecbecc99812747a657588c63eb (patch)
tree765efa3b6a56bb715d9813a8697473e120436278 /toolkit/jetpack/dev/toolbox.js
parentb2bdac20c02b12f2057b9ef70b0a946113a00e00 (diff)
parent4fb11cd5966461bccc3ed1599b808237be6b0de9 (diff)
downloadUXP-37d5300335d81cecbecc99812747a657588c63eb.tar
UXP-37d5300335d81cecbecc99812747a657588c63eb.tar.gz
UXP-37d5300335d81cecbecc99812747a657588c63eb.tar.lz
UXP-37d5300335d81cecbecc99812747a657588c63eb.tar.xz
UXP-37d5300335d81cecbecc99812747a657588c63eb.zip
Merge branch 'ext-work'
Diffstat (limited to 'toolkit/jetpack/dev/toolbox.js')
-rw-r--r--toolkit/jetpack/dev/toolbox.js107
1 files changed, 107 insertions, 0 deletions
diff --git a/toolkit/jetpack/dev/toolbox.js b/toolkit/jetpack/dev/toolbox.js
new file mode 100644
index 000000000..43f37759f
--- /dev/null
+++ b/toolkit/jetpack/dev/toolbox.js
@@ -0,0 +1,107 @@
+/* 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";
+
+module.metadata = {
+ "stability": "experimental"
+};
+
+const { Cu, Cc, Ci } = require("chrome");
+const { Class } = require("../sdk/core/heritage");
+const { Disposable, setup } = require("../sdk/core/disposable");
+const { contract, validate } = require("../sdk/util/contract");
+const { each, pairs, values } = require("../sdk/util/sequence");
+const { onEnable, onDisable } = require("../dev/theme/hooks");
+
+const { gDevTools } = Cu.import("resource://devtools/client/framework/gDevTools.jsm", {});
+
+// This is temporary workaround to allow loading of the developer tools client - volcan
+// into a toolbox panel, this hack won't be necessary as soon as devtools patch will be
+// shipped in nightly, after which it can be removed. Bug 1038517
+const registerSDKURI = () => {
+ const ioService = Cc['@mozilla.org/network/io-service;1']
+ .getService(Ci.nsIIOService);
+ const resourceHandler = ioService.getProtocolHandler("resource")
+ .QueryInterface(Ci.nsIResProtocolHandler);
+
+ const uri = module.uri.replace("dev/toolbox.js", "");
+ resourceHandler.setSubstitution("sdk", ioService.newURI(uri, null, null));
+};
+
+registerSDKURI();
+
+const Tool = Class({
+ extends: Disposable,
+ setup: function(params={}) {
+ const { panels } = validate(this, params);
+ const { themes } = validate(this, params);
+
+ this.panels = panels;
+ this.themes = themes;
+
+ each(([key, Panel]) => {
+ const { url, label, tooltip, icon, invertIconForLightTheme,
+ invertIconForDarkTheme } = validate(Panel.prototype);
+ const { id } = Panel.prototype;
+
+ gDevTools.registerTool({
+ id: id,
+ url: "about:blank",
+ label: label,
+ tooltip: tooltip,
+ icon: icon,
+ invertIconForLightTheme: invertIconForLightTheme,
+ invertIconForDarkTheme: invertIconForDarkTheme,
+ isTargetSupported: target => target.isLocalTab,
+ build: (window, toolbox) => {
+ const panel = new Panel();
+ setup(panel, { window: window,
+ toolbox: toolbox,
+ url: url });
+
+ return panel.ready();
+ }
+ });
+ }, pairs(panels));
+
+ each(([key, theme]) => {
+ validate(theme);
+ setup(theme);
+
+ gDevTools.registerTheme({
+ id: theme.id,
+ label: theme.label,
+ stylesheets: theme.getStyles(),
+ classList: theme.getClassList(),
+ onApply: (window, oldTheme) => {
+ onEnable(theme, { window: window,
+ oldTheme: oldTheme });
+ },
+ onUnapply: (window, newTheme) => {
+ onDisable(theme, { window: window,
+ newTheme: newTheme });
+ }
+ });
+ }, pairs(themes));
+ },
+ dispose: function() {
+ each(Panel => gDevTools.unregisterTool(Panel.prototype.id),
+ values(this.panels));
+
+ each(Theme => gDevTools.unregisterTheme(Theme.prototype.id),
+ values(this.themes));
+ }
+});
+
+validate.define(Tool, contract({
+ panels: {
+ is: ["object", "undefined"]
+ },
+ themes: {
+ is: ["object", "undefined"]
+ }
+}));
+
+exports.Tool = Tool;