summaryrefslogtreecommitdiffstats
path: root/toolkit/content/plugins.js
blob: 676e51a9c651215e014c17fac50898606f275247 (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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
/* 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/. */

/* eslint-env mozilla/remote-page */

"use strict";

/* JavaScript to enumerate and display all installed plug-ins

 * First, refresh plugins in case anything has been changed recently in
 * prefs: (The "false" argument tells refresh not to reload or activate
 * any plug-ins that would be active otherwise.  In contrast, one would
 * use "true" in the case of ASD instead of restarting)
 */
navigator.plugins.refresh(false);

RPMSendQuery("RequestPlugins", {}).then(aPlugins => {
  var fragment = document.createDocumentFragment();

  // "Installed plugins"
  var id, label;
  if (aPlugins.length) {
    id = "plugs";
    label = "installed-plugins-label";
  } else {
    id = "noplugs";
    label = "no-plugins-are-installed-label";
  }
  var enabledplugins = document.createElement("h1");
  enabledplugins.setAttribute("id", id);
  document.l10n.setAttributes(enabledplugins, label);
  fragment.appendChild(enabledplugins);

  let deprecation = document.createElement("message-bar");
  let deprecationLink = document.createElement("a", { is: "moz-support-link" });
  deprecationLink.setAttribute("data-l10n-name", "deprecation-link");
  deprecationLink.setAttribute("support-page", "npapi");
  deprecation.appendChild(deprecationLink);
  document.l10n.setAttributes(deprecation, "deprecation-description");
  fragment.appendChild(deprecation);

  var stateNames = {};
  ["STATE_SOFTBLOCKED", "STATE_BLOCKED"].forEach(function (label) {
    stateNames[Ci.nsIBlocklistService[label]] = label;
  });

  for (var i = 0; i < aPlugins.length; i++) {
    var plugin = aPlugins[i];
    if (plugin) {
      // "Shockwave Flash"
      var plugname = document.createElement("h2");
      plugname.setAttribute("class", "plugname");
      plugname.appendChild(document.createTextNode(plugin.name));
      fragment.appendChild(plugname);

      var dl = document.createElement("dl");
      fragment.appendChild(dl);

      // "File: Flash Player.plugin"
      var fileDd = document.createElement("dd");
      var file = document.createElement("span");
      file.setAttribute("data-l10n-name", "file");
      file.setAttribute("class", "label");
      fileDd.appendChild(file);
      document.l10n.setAttributes(fileDd, "file-dd", {
        pluginLibraries: plugin.pluginLibraries[0] ?? "",
      });
      dl.appendChild(fileDd);

      // "Path: /usr/lib/mozilla/plugins/libtotem-cone-plugin.so"
      var pathDd = document.createElement("dd");
      var path = document.createElement("span");
      path.setAttribute("data-l10n-name", "path");
      path.setAttribute("class", "label");
      pathDd.appendChild(path);
      document.l10n.setAttributes(pathDd, "path-dd", {
        pluginFullPath: plugin.pluginFullpath[0] ?? "",
      });
      dl.appendChild(pathDd);

      // "Version: "
      var versionDd = document.createElement("dd");
      var version = document.createElement("span");
      version.setAttribute("data-l10n-name", "version");
      version.setAttribute("class", "label");
      versionDd.appendChild(version);
      document.l10n.setAttributes(versionDd, "version-dd", {
        version: plugin.version ?? "",
      });
      dl.appendChild(versionDd);

      // "State: "
      var stateDd = document.createElement("dd");
      var state = document.createElement("span");
      state.setAttribute("data-l10n-name", "state");
      state.setAttribute("label", "state");
      stateDd.appendChild(state);
      if (plugin.isActive) {
        if (plugin.blocklistState in stateNames) {
          document.l10n.setAttributes(
            stateDd,
            "state-dd-enabled-block-list-state",
            { blockListState: stateNames[plugin.blocklistState] }
          );
        } else {
          document.l10n.setAttributes(stateDd, "state-dd-enabled");
        }
      } else if (plugin.blocklistState in stateNames) {
        document.l10n.setAttributes(
          stateDd,
          "state-dd-disabled-block-list-state",
          { blockListState: stateNames[plugin.blocklistState] }
        );
      } else {
        document.l10n.setAttributes(stateDd, "state-dd-disabled");
      }
      dl.appendChild(stateDd);

      // Plugin Description
      var descDd = document.createElement("dd");
      descDd.appendChild(document.createTextNode(plugin.description));
      dl.appendChild(descDd);
    }
  }

  document.getElementById("outside").appendChild(fragment);
});