summaryrefslogtreecommitdiffstats
path: root/devtools/client/aboutdebugging/src/middleware/process-component-data.js
blob: c4947453a0cdcdc7b17c1741e6e68739fde02e25 (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
/* 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 {
  l10n,
} = require("resource://devtools/client/aboutdebugging/src/modules/l10n.js");

const {
  DEBUG_TARGETS,
  REQUEST_PROCESSES_SUCCESS,
} = require("resource://devtools/client/aboutdebugging/src/constants.js");

/**
 * This middleware converts tabs object that get from DevToolsClient.listProcesses() to
 * data which is used in DebugTargetItem.
 */
const processComponentDataMiddleware = () => next => action => {
  switch (action.type) {
    case REQUEST_PROCESSES_SUCCESS: {
      const mainProcessComponentData = toMainProcessComponentData(
        action.mainProcess
      );
      action.processes = [mainProcessComponentData];
      break;
    }
  }

  return next(action);
};

function toMainProcessComponentData() {
  const type = DEBUG_TARGETS.PROCESS;
  const icon = "chrome://devtools/skin/images/aboutdebugging-process-icon.svg";

  // For now, we assume there is only one process and this is the main process
  // So the name and title are for a remote (multiprocess) browser toolbox.
  const name = l10n.getString("about-debugging-multiprocess-toolbox-name");
  const description = l10n.getString(
    "about-debugging-multiprocess-toolbox-description"
  );

  return {
    name,
    icon,
    type,
    details: {
      description,
    },
  };
}

module.exports = processComponentDataMiddleware;