summaryrefslogtreecommitdiffstats
path: root/addon-sdk/source/lib/dev/utils.js
blob: 48db39e04ff31642ac13575f28ffef1ea237ab2f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
/* 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 { Cu } = require("chrome");
const { gDevTools } = Cu.import("resource://devtools/client/framework/gDevTools.jsm", {});
const { devtools } = Cu.import("resource://devtools/shared/Loader.jsm", {});

const { getActiveTab } = require("../sdk/tabs/utils");
const { getMostRecentBrowserWindow } = require("../sdk/window/utils");

const targetFor = target => {
  target = target || getActiveTab(getMostRecentBrowserWindow());
  return devtools.TargetFactory.forTab(target);
};

const getId = id => ((id.prototype && id.prototype.id) || id.id || id);

const getCurrentPanel = toolbox => toolbox.getCurrentPanel();
exports.getCurrentPanel = getCurrentPanel;

const openToolbox = (id, tab) => {
  id = getId(id);
  return gDevTools.showToolbox(targetFor(tab), id);
};
exports.openToolbox = openToolbox;

const closeToolbox = tab => gDevTools.closeToolbox(targetFor(tab));
exports.closeToolbox = closeToolbox;

const getToolbox = tab => gDevTools.getToolbox(targetFor(tab));
exports.getToolbox = getToolbox;

const openToolboxPanel = (id, tab) => {
  id = getId(id);
  return gDevTools.showToolbox(targetFor(tab), id).then(getCurrentPanel);
};
exports.openToolboxPanel = openToolboxPanel;