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 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276
|
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
/**
* Takes the |pluginsData| input argument which represents data about the
* currently installed/running plugins and populates the html jstemplate with
* that data. It expects an object structure like the above.
* @param {Object} pluginsData Detailed info about installed plugins. Same
* expected format as returnPluginsData().
*/
function renderTemplate(pluginsData) {
// This is the javascript code that processes the template:
var input = new JsEvalContext(pluginsData);
var output = $('pluginTemplate');
jstProcess(input, output);
}
/**
* Asks the C++ PluginsDOMHandler to get details about the installed plugins and
* return detailed data about the configuration. The PluginsDOMHandler should
* reply to returnPluginsData() (below).
*/
function requestPluginsData() {
chrome.send('requestPluginsData');
chrome.send('getShowDetails');
}
function loadShowDetailsFromPrefs(show_details) {
tmiModeExpanded = show_details;
$('collapse').style.display =
show_details ? 'inline' : 'none';
$('expand').style.display =
show_details ? 'none' : 'inline';
document.body.className = show_details ? 'show-in-tmi-mode' : 'hide-tmi-mode';
}
/**
* Called by the web_ui_ to re-populate the page with data representing the
* current state of installed plugins.
* @param {Object} pluginsData Detailed info about installed plugins. The
* template expects each plugin's format to match the following structure to
* correctly populate the page:
* {
* plugins: [
* {
* name: 'Group Name',
* description: 'description',
* version: 'version',
* update_url: 'http://update/',
* critical: true,
* enabled: true,
* identifier: 'plugin-name',
* plugin_files: [
* {
* path: '/blahblah/blahblah/MyCrappyPlugin.plugin',
* name: 'MyCrappyPlugin',
* version: '1.2.3',
* description: 'My crappy plugin',
* mimeTypes: [
* { description: 'Foo Media',
* fileExtensions: ['foo'],
* mimeType: 'application/x-my-foo' },
* { description: 'Bar Stuff',
* fileExtensions: ['bar', 'baz'],
* mimeType: 'application/my-bar' }
* ],
* enabledMode: 'enabledByUser'
* },
* {
* path: '/tmp/MyFirst.plugin',
* name: 'MyFirstPlugin',
* version: '3.14r15926',
* description: 'My first plugin',
* mimeTypes: [
* { description: 'New Guy Media',
* fileExtensions: ['mfp'],
* mimeType: 'application/x-my-first' }
* ],
* enabledMode: 'enabledByPolicy'
* },
* {
* path: '/foobar/baz/YourGreatPlugin.plugin',
* name: 'YourGreatPlugin',
* version: '4.5',
* description: 'Your great plugin',
* mimeTypes: [
* { description: 'Baz Stuff',
* fileExtensions: ['baz'],
* mimeType: 'application/x-your-baz' }
* ],
* enabledMode: 'disabledByUser'
* },
* {
* path: '/foobiz/bar/HisGreatPlugin.plugin',
* name: 'HisGreatPlugin',
* version: '1.2',
* description: 'His great plugin',
* mimeTypes: [
* { description: 'More baz Stuff',
* fileExtensions: ['bor'],
* mimeType: 'application/x-his-bor' }
* ],
* enabledMode: 'disabledByPolicy'
* }
* ]
* }
* ]
* }
*/
function returnPluginsData(pluginsData) {
var bodyContainer = $('body-container');
var body = document.body;
// Set all page content to be visible so we can measure heights.
bodyContainer.style.visibility = 'hidden';
body.className = '';
var slidables = document.getElementsByClassName('show-in-tmi-mode');
for (var i = 0; i < slidables.length; i++)
slidables[i].style.height = 'auto';
renderTemplate(pluginsData);
// Add handlers to dynamically created HTML elements.
var links = document.getElementsByClassName('disable-plugin-link');
for (var i = 0; i < links.length; i++) {
links[i].onclick = function() {
handleEnablePlugin(this, false, false);
return false;
};
}
links = document.getElementsByClassName('enable-plugin-link');
for (var i = 0; i < links.length; i++) {
links[i].onclick = function() {
handleEnablePlugin(this, true, false);
return false;
};
}
links = document.getElementsByClassName('disable-group-link');
for (var i = 0; i < links.length; i++) {
links[i].onclick = function() {
handleEnablePlugin(this, false, true);
return false;
};
}
links = document.getElementsByClassName('enable-group-link');
for (var i = 0; i < links.length; i++) {
links[i].onclick = function() {
handleEnablePlugin(this, true, true);
return false;
};
}
var checkboxes = document.getElementsByClassName('always-allow');
for (var i = 0; i < checkboxes.length; i++) {
checkboxes[i].onclick = function() {
handleSetPluginAlwaysAllowed(this);
};
}
if (cr.isChromeOS) {
// Disable some controls for Guest in ChromeOS.
uiAccountTweaks.UIAccountTweaks.applyGuestSessionVisibility(document);
// Disable some controls for Public session in ChromeOS.
uiAccountTweaks.UIAccountTweaks.applyPublicSessionVisibility(document);
}
// Make sure the left column (with "Description:", "Location:", etc.) is the
// same size for all plugins.
var labels = document.getElementsByClassName('plugin-details-label');
var maxLabelWidth = 0;
for (var i = 0; i < labels.length; i++)
labels[i].style.width = 'auto';
for (var i = 0; i < labels.length; i++)
maxLabelWidth = Math.max(maxLabelWidth, labels[i].offsetWidth);
for (var i = 0; i < labels.length; i++)
labels[i].style.width = maxLabelWidth + 'px';
// Explicitly set the height for each element that wants to be "slid" in and
// out when the tmiModeExpanded is toggled.
var slidables = document.getElementsByClassName('show-in-tmi-mode');
for (var i = 0; i < slidables.length; i++)
slidables[i].style.height = slidables[i].offsetHeight + 'px';
// Reset visibility of page based on the current tmi mode.
$('collapse').style.display =
tmiModeExpanded ? 'inline' : 'none';
$('expand').style.display =
tmiModeExpanded ? 'none' : 'inline';
bodyContainer.style.visibility = 'visible';
body.className = tmiModeExpanded ?
'show-tmi-mode-initial' : 'hide-tmi-mode-initial';
}
/**
* Handles a 'enable' or 'disable' button getting clicked.
* @param {HTMLElement} node The HTML element for the plugin being changed.
* @param {boolean} enable Whether to enable or disable the plugin.
* @param {boolean} isGroup True if we're enabling/disabling a plugin group,
* rather than a single plugin.
*/
function handleEnablePlugin(node, enable, isGroup) {
// Tell the C++ PluginsDOMHandler to enable/disable the plugin.
chrome.send('enablePlugin', [String(node.path), String(enable),
String(isGroup)]);
}
// Keeps track of whether details have been made visible (expanded) or not.
var tmiModeExpanded = false;
/*
* Toggles visibility of details.
*/
function toggleTmiMode() {
tmiModeExpanded = !tmiModeExpanded;
$('collapse').style.display =
tmiModeExpanded ? 'inline' : 'none';
$('expand').style.display =
tmiModeExpanded ? 'none' : 'inline';
document.body.className =
tmiModeExpanded ? 'show-tmi-mode' : 'hide-tmi-mode';
chrome.send('saveShowDetailsToPrefs', [String(tmiModeExpanded)]);
}
function handleSetPluginAlwaysAllowed(el) {
chrome.send('setPluginAlwaysAllowed', [el.identifier, el.checked]);
}
/**
* @param {Object} plugin An object containing the information about a plugin.
* See returnPluginsData() for the format of this object.
* @return {boolean} Whether the plugin's version should be displayed.
*/
function shouldDisplayPluginVersion(plugin) {
return !!plugin.version && plugin.version != '0';
}
/**
* @param {Object} plugin An object containing the information about a plugin.
* See returnPluginsData() for the format of this object.
* @return {boolean} Whether the plugin's description should be displayed.
*/
function shouldDisplayPluginDescription(plugin) {
// Only display the description if it's not blank and if it's not just the
// name, version, or combination thereof.
return plugin.description &&
plugin.description != plugin.name &&
plugin.description != plugin.version &&
plugin.description != 'Version ' + plugin.version &&
plugin.description != plugin.name + ' ' + plugin.version;
}
/**
* @param {Object} plugin An object containing the information about a plugin.
* See returnPluginsData() for the format of this object.
* @return {boolean} Whether the plugin is enabled.
*/
function isPluginEnabled(plugin) {
return plugin.enabledMode == 'enabledByUser' ||
plugin.enabledMode == 'enabledByPolicy';
}
// Unfortunately, we don't have notifications for plugin (list) status changes
// (yet), so in the meanwhile just update regularly.
setInterval(requestPluginsData, 30000);
// Get data and have it displayed upon loading.
document.addEventListener('DOMContentLoaded', requestPluginsData);
// Add handlers to static HTML elements.
$('collapse').onclick = toggleTmiMode;
$('expand').onclick = toggleTmiMode;
$('details-link').onclick = toggleTmiMode;
|