Bug 1782750 [wpt PR 35307] - Implement "fire a toggle activation" and "change a toggl...
[gecko.git] / toolkit / content / plugins.js
blob75f1d83fb9234cfc49c3960fe574f5c5f4ce794b
1 /* This Source Code Form is subject to the terms of the Mozilla Public
2  * License, v. 2.0. If a copy of the MPL was not distributed with this
3  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5 /* eslint-env mozilla/remote-page */
7 "use strict";
9 /* JavaScript to enumerate and display all installed plug-ins
11  * First, refresh plugins in case anything has been changed recently in
12  * prefs: (The "false" argument tells refresh not to reload or activate
13  * any plug-ins that would be active otherwise.  In contrast, one would
14  * use "true" in the case of ASD instead of restarting)
15  */
16 navigator.plugins.refresh(false);
18 RPMSendQuery("RequestPlugins", {}).then(aPlugins => {
19   var fragment = document.createDocumentFragment();
21   // "Installed plugins"
22   var id, label;
23   if (aPlugins.length) {
24     id = "plugs";
25     label = "installed-plugins-label";
26   } else {
27     id = "noplugs";
28     label = "no-plugins-are-installed-label";
29   }
30   var enabledplugins = document.createElement("h1");
31   enabledplugins.setAttribute("id", id);
32   document.l10n.setAttributes(enabledplugins, label);
33   fragment.appendChild(enabledplugins);
35   var deprecation = document.createElement("p");
36   var deprecationLink = document.createElement("a");
37   let deprecationLink_href =
38     Services.urlFormatter.formatURLPref("app.support.baseURL") + "npapi";
39   deprecationLink.setAttribute("data-l10n-name", "deprecation-link");
40   deprecationLink.setAttribute("href", deprecationLink_href);
41   deprecation.appendChild(deprecationLink);
42   deprecation.setAttribute("class", "notice");
43   document.l10n.setAttributes(deprecation, "deprecation-description");
44   fragment.appendChild(deprecation);
46   var stateNames = {};
47   ["STATE_SOFTBLOCKED", "STATE_BLOCKED"].forEach(function(label) {
48     stateNames[Ci.nsIBlocklistService[label]] = label;
49   });
51   for (var i = 0; i < aPlugins.length; i++) {
52     var plugin = aPlugins[i];
53     if (plugin) {
54       // "Shockwave Flash"
55       var plugname = document.createElement("h2");
56       plugname.setAttribute("class", "plugname");
57       plugname.appendChild(document.createTextNode(plugin.name));
58       fragment.appendChild(plugname);
60       var dl = document.createElement("dl");
61       fragment.appendChild(dl);
63       // "File: Flash Player.plugin"
64       var fileDd = document.createElement("dd");
65       var file = document.createElement("span");
66       file.setAttribute("data-l10n-name", "file");
67       file.setAttribute("class", "label");
68       fileDd.appendChild(file);
69       document.l10n.setAttributes(fileDd, "file-dd", {
70         pluginLibraries: plugin.pluginLibraries[0],
71       });
72       dl.appendChild(fileDd);
74       // "Path: /usr/lib/mozilla/plugins/libtotem-cone-plugin.so"
75       var pathDd = document.createElement("dd");
76       var path = document.createElement("span");
77       path.setAttribute("data-l10n-name", "path");
78       path.setAttribute("class", "label");
79       pathDd.appendChild(path);
80       document.l10n.setAttributes(pathDd, "path-dd", {
81         pluginFullPath: plugin.pluginFullpath[0],
82       });
83       dl.appendChild(pathDd);
85       // "Version: "
86       var versionDd = document.createElement("dd");
87       var version = document.createElement("span");
88       version.setAttribute("data-l10n-name", "version");
89       version.setAttribute("class", "label");
90       versionDd.appendChild(version);
91       document.l10n.setAttributes(versionDd, "version-dd", {
92         version: plugin.version,
93       });
94       dl.appendChild(versionDd);
96       // "State: "
97       var stateDd = document.createElement("dd");
98       var state = document.createElement("span");
99       state.setAttribute("data-l10n-name", "state");
100       state.setAttribute("label", "state");
101       stateDd.appendChild(state);
102       if (plugin.isActive) {
103         if (plugin.blocklistState in stateNames) {
104           document.l10n.setAttributes(
105             stateDd,
106             "state-dd-enabled-block-list-state",
107             { blockListState: stateNames[plugin.blocklistState] }
108           );
109         } else {
110           document.l10n.setAttributes(stateDd, "state-dd-enabled");
111         }
112       } else if (plugin.blocklistState in stateNames) {
113         document.l10n.setAttributes(
114           stateDd,
115           "state-dd-disabled-block-list-state",
116           { blockListState: stateNames[plugin.blocklistState] }
117         );
118       } else {
119         document.l10n.setAttributes(stateDd, "state-dd-disabled");
120       }
121       dl.appendChild(stateDd);
123       // Plugin Description
124       var descDd = document.createElement("dd");
125       descDd.appendChild(document.createTextNode(plugin.description));
126       dl.appendChild(descDd);
127     }
128   }
130   document.getElementById("outside").appendChild(fragment);