summaryrefslogtreecommitdiffstats
path: root/comm/mail/components/devtools/tb-root-actor.js
blob: 3f546605f6b8fc123894b3fe3e434631da4a14cc (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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
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);
  }
}