summaryrefslogtreecommitdiffstats
path: root/comm/mail/components/devtools
diff options
context:
space:
mode:
Diffstat (limited to 'comm/mail/components/devtools')
-rw-r--r--comm/mail/components/devtools/components.conf15
-rw-r--r--comm/mail/components/devtools/devtools-loader.jsm80
-rw-r--r--comm/mail/components/devtools/moz.build13
-rw-r--r--comm/mail/components/devtools/tb-root-actor.js104
4 files changed, 212 insertions, 0 deletions
diff --git a/comm/mail/components/devtools/components.conf b/comm/mail/components/devtools/components.conf
new file mode 100644
index 0000000000..023940a05f
--- /dev/null
+++ b/comm/mail/components/devtools/components.conf
@@ -0,0 +1,15 @@
+# -*- Mode: python; indent-tabs-mode: nil; tab-width: 40 -*-
+# vim: set filetype=python:
+# 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/.
+
+Classes = [
+ {
+ 'cid': '{089694e9-106a-4704-abf7-62a88545e194}',
+ 'contract_ids': ['@mozilla.org/messenger/devtools-startup-clh;1'],
+ 'jsm': 'resource:///modules/devtools-loader.jsm',
+ 'constructor': 'DevToolsStartup',
+ 'categories': {'command-line-handler': 'm-aaa-tb-devtools'},
+ },
+]
diff --git a/comm/mail/components/devtools/devtools-loader.jsm b/comm/mail/components/devtools/devtools-loader.jsm
new file mode 100644
index 0000000000..a951bb2b94
--- /dev/null
+++ b/comm/mail/components/devtools/devtools-loader.jsm
@@ -0,0 +1,80 @@
+/* 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";
+
+function DevToolsStartup() {}
+
+DevToolsStartup.prototype = {
+ QueryInterface: ChromeUtils.generateQI(["nsICommandLineHandler"]),
+
+ helpInfo: "",
+ handle(cmdLine) {
+ this.initialize();
+
+ // We want to overwrite the -devtools flag and open the toolbox instead
+ let devtoolsFlag = cmdLine.handleFlag("devtools", false);
+ if (devtoolsFlag) {
+ this.handleDevToolsFlag(cmdLine);
+ }
+ },
+
+ handleDevToolsFlag(cmdLine) {
+ const { BrowserToolboxLauncher } = ChromeUtils.importESModule(
+ "resource://devtools/client/framework/browser-toolbox/Launcher.sys.mjs"
+ );
+ BrowserToolboxLauncher.init();
+
+ if (cmdLine.state == Ci.nsICommandLine.STATE_REMOTE_AUTO) {
+ cmdLine.preventDefault = true;
+ }
+ },
+
+ initialize() {
+ let { loader, require, DevToolsLoader } = ChromeUtils.importESModule(
+ "resource://devtools/shared/loader/Loader.sys.mjs"
+ );
+ let { DevToolsServer } = require("devtools/server/devtools-server");
+ let { gDevTools } = require("devtools/client/framework/devtools");
+
+ // Set up the client and server chrome window type, make sure it can't be set
+ Object.defineProperty(DevToolsServer, "chromeWindowType", {
+ get: () => "mail:3pane",
+ set: () => {},
+ configurable: true,
+ });
+ Object.defineProperty(gDevTools, "chromeWindowType", {
+ get: () => "mail:3pane",
+ set: () => {},
+ configurable: true,
+ });
+
+ // Make sure our root actor is always registered, no matter how devtools are called.
+ let devtoolsRegisterActors =
+ DevToolsServer.registerActors.bind(DevToolsServer);
+ DevToolsServer.registerActors = function (options) {
+ devtoolsRegisterActors(options);
+ if (options.root) {
+ const {
+ createRootActor,
+ } = require("resource:///modules/tb-root-actor.js");
+ DevToolsServer.setRootActor(createRootActor);
+ }
+ };
+
+ // Make the loader visible to the debugger by default and for the already
+ // loaded instance. Thunderbird now also provides the Browser Toolbox for
+ // chrome debugging, which uses its own separate loader instance.
+ DevToolsLoader.prototype.invisibleToDebugger = false;
+ loader.invisibleToDebugger = false;
+ DevToolsServer.allowChromeProcess = true;
+
+ // Initialize and load the toolkit/browser actors. This will also call above function to set the
+ // Thunderbird root actor
+ DevToolsServer.init();
+ DevToolsServer.registerAllActors();
+ },
+};
+
+var EXPORTED_SYMBOLS = ["DevToolsStartup"];
diff --git a/comm/mail/components/devtools/moz.build b/comm/mail/components/devtools/moz.build
new file mode 100644
index 0000000000..fbe8acc2cb
--- /dev/null
+++ b/comm/mail/components/devtools/moz.build
@@ -0,0 +1,13 @@
+# vim: set filetype=python:
+# 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/.
+
+EXTRA_JS_MODULES += [
+ "devtools-loader.jsm",
+ "tb-root-actor.js",
+]
+
+XPCOM_MANIFESTS += [
+ "components.conf",
+]
diff --git a/comm/mail/components/devtools/tb-root-actor.js b/comm/mail/components/devtools/tb-root-actor.js
new file mode 100644
index 0000000000..3f546605f6
--- /dev/null
+++ b/comm/mail/components/devtools/tb-root-actor.js
@@ -0,0 +1,104 @@
+/* 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/. */
+
+/* globals loader, require, exports */
+
+/**
+ * Actors for Thunderbird Developer Tools, for example the root actor or tab
+ * list actor.
+ */
+
+var { ActorRegistry } = require("devtools/server/actors/utils/actor-registry");
+
+loader.lazyRequireGetter(
+ this,
+ "RootActor",
+ "devtools/server/actors/root",
+ true
+);
+loader.lazyRequireGetter(
+ this,
+ "BrowserTabList",
+ "devtools/server/actors/webbrowser",
+ true
+);
+loader.lazyRequireGetter(
+ this,
+ "BrowserAddonList",
+ "devtools/server/actors/webbrowser",
+ true
+);
+loader.lazyRequireGetter(
+ this,
+ "sendShutdownEvent",
+ "devtools/server/actors/webbrowser",
+ true
+);
+loader.lazyRequireGetter(
+ this,
+ "WorkerDescriptorActorList",
+ "devtools/server/actors/worker/worker-descriptor-actor-list",
+ true
+);
+loader.lazyRequireGetter(
+ this,
+ "ServiceWorkerRegistrationActorList",
+ "devtools/server/actors/worker/service-worker-registration-list",
+ true
+);
+loader.lazyRequireGetter(
+ this,
+ "ProcessActorList",
+ "devtools/server/actors/process",
+ true
+);
+
+/**
+ * Create the root actor for Thunderbird.
+ *
+ * @param aConnection The debugger connection to create the actor for.
+ * @returns The mail actor for the connection.
+ */
+exports.createRootActor = function (aConnection) {
+ let parameters = {
+ tabList: new TBTabList(aConnection),
+ addonList: new BrowserAddonList(aConnection),
+ workerList: new WorkerDescriptorActorList(aConnection, {}),
+ serviceWorkerRegistrationList: new ServiceWorkerRegistrationActorList(
+ aConnection
+ ),
+ processList: new ProcessActorList(),
+ globalActorFactories: ActorRegistry.globalActorFactories,
+ onShutdown: sendShutdownEvent,
+ };
+
+ // Create the root actor and set the application type
+ let rootActor = new RootActor(aConnection, parameters);
+ rootActor.applicationType = "mail";
+
+ return rootActor;
+};
+
+/**
+ * Thunderbird's version of the tab list. We don't have gBrowser, but tabmail has similar functions
+ * that will be helpful. The tabs displayed are those tabs in tabmail that have a browser element.
+ * This is mainly the contentTabs, but can also be others such as the start page.
+ */
+class TBTabList extends BrowserTabList {
+ _getSelectedBrowser(window) {
+ let tabmail = window.document.getElementById("tabmail");
+ return tabmail ? tabmail.selectedBrowser : null;
+ }
+
+ _getChildren(window) {
+ let tabmail = window.document.getElementById("tabmail");
+ if (!tabmail) {
+ return [];
+ }
+
+ return tabmail.tabInfo
+ .map(tab => tabmail.getBrowserForTab(tab))
+ .filter(Boolean);
+ }
+}