Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 /** | 5 /** |
| 6 * Takes the |pluginsData| input argument which represents data about the | 6 * Takes the |pluginsData| input argument which represents data about the |
| 7 * currently installed/running plugins and populates the html jstemplate with | 7 * currently installed/running plugins and populates the html jstemplate with |
| 8 * that data. It expects an object structure like the above. | 8 * that data. |
| 9 * @param {Object} pluginsData Detailed info about installed plugins. Same | 9 * @param {Object} pluginsData Detailed info about installed plugins. Same |
| 10 * expected format as returnPluginsData(). | 10 * expected format as returnPluginsData(). |
| 11 */ | 11 */ |
| 12 function renderTemplate(pluginsData) { | 12 function renderTemplate(pluginsData) { |
| 13 // This is the javascript code that processes the template: | 13 // This is the javascript code that processes the template: |
| 14 var input = new JsEvalContext(pluginsData); | 14 var input = new JsEvalContext(pluginsData); |
| 15 var output = $('pluginTemplate'); | 15 var output = $('pluginTemplate'); |
| 16 jstProcess(input, output); | 16 jstProcess(input, output); |
| 17 } | 17 } |
| 18 | 18 |
| 19 /** | 19 /** |
| 20 * Asks the C++ PluginsDOMHandler to get details about the installed plugins and | 20 * @param {boolean} showDetails |
| 21 * return detailed data about the configuration. The PluginsDOMHandler should | |
| 22 * reply to returnPluginsData() (below). | |
| 23 */ | 21 */ |
| 24 function requestPluginsData() { | 22 function loadShowDetailsFromPrefs(showDetails) { |
| 25 chrome.send('requestPluginsData'); | 23 tmiModeExpanded = showDetails; |
|
Dan Beam
2016/01/28 04:25:08
arguably: move the declaration of tmiModeExpanded
dpapad
2016/01/28 18:32:54
Done.
| |
| 26 chrome.send('getShowDetails'); | 24 $('collapse').style.display = |
| 27 } | 25 showDetails ? 'inline' : 'none'; |
| 26 $('expand').style.display = | |
| 27 showDetails ? 'none' : 'inline'; | |
| 28 | 28 |
| 29 function loadShowDetailsFromPrefs(show_details) { | 29 document.body.className = showDetails ? 'show-in-tmi-mode' : 'hide-tmi-mode'; |
| 30 tmiModeExpanded = show_details; | |
| 31 $('collapse').style.display = | |
| 32 show_details ? 'inline' : 'none'; | |
| 33 $('expand').style.display = | |
| 34 show_details ? 'none' : 'inline'; | |
| 35 | |
| 36 document.body.className = show_details ? 'show-in-tmi-mode' : 'hide-tmi-mode'; | |
| 37 } | 30 } |
| 38 | 31 |
| 39 /** | 32 /** |
| 40 * Called by the web_ui_ to re-populate the page with data representing the | 33 * Called by the web_ui_ to re-populate the page with data representing the |
| 41 * current state of installed plugins. | 34 * current state of installed plugins. |
| 42 * @param {Object} pluginsData Detailed info about installed plugins. The | 35 * @param {Object} pluginsData Detailed info about installed plugins. The |
| 43 * template expects each plugin's format to match the following structure to | 36 * template expects each plugin's format to match the following structure to |
| 44 * correctly populate the page: | 37 * correctly populate the page: |
| 45 * { | 38 * { |
| 46 * plugins: [ | 39 * plugins: [ |
| 47 * { | 40 * { |
| 48 * name: 'Group Name', | 41 * name: 'Group Name', |
| 49 * description: 'description', | 42 * description: 'description', |
| 50 * version: 'version', | 43 * version: 'version', |
| 51 * update_url: 'http://update/', | 44 * update_url: 'http://update/', |
| 52 * critical: true, | 45 * critical: true, |
| 53 * enabled: true, | 46 * enabled_mode: 'enabledByUser', |
| 54 * identifier: 'plugin-name', | 47 * id: 'plugin-name', |
| 48 * always_allowed: false, | |
| 55 * plugin_files: [ | 49 * plugin_files: [ |
| 56 * { | 50 * { |
| 57 * path: '/blahblah/blahblah/MyCrappyPlugin.plugin', | 51 * path: '/foo/bar/baz/MyPlugin.plugin', |
| 58 * name: 'MyCrappyPlugin', | 52 * name: 'MyPlugin', |
| 59 * version: '1.2.3', | 53 * version: '1.2,3' |
| 60 * description: 'My crappy plugin', | 54 * description: 'My plugin', |
| 61 * mimeTypes: [ | 55 * type: 'BROWSER PLUGIN', |
| 62 * { description: 'Foo Media', | 56 * mime_types: [ |
| 63 * fileExtensions: ['foo'], | 57 * { |
| 64 * mimeType: 'application/x-my-foo' }, | 58 * description: 'Foo Media', |
| 65 * { description: 'Bar Stuff', | 59 * file_extensions: ['pdf'], |
| 66 * fileExtensions: ['bar', 'baz'], | 60 * mime_type: 'application/x-my-foo' |
| 67 * mimeType: 'application/my-bar' } | 61 * }, |
| 62 * { | |
| 63 * description: 'Bar Stuff', | |
| 64 * file_extensions: ['bar', 'baz'], | |
| 65 * mime_type: 'application/my-bar' | |
| 66 * } | |
| 68 * ], | 67 * ], |
| 69 * enabledMode: 'enabledByUser' | 68 * enabled_mode: 'enabledByUser', |
| 70 * }, | 69 * }, |
| 71 * { | 70 * { |
| 72 * path: '/tmp/MyFirst.plugin', | 71 * path: '/tmp/MyFirst.plugin', |
| 73 * name: 'MyFirstPlugin', | 72 * name: 'MyFirstPlugin', |
| 74 * version: '3.14r15926', | 73 * version: '3.14r15926', |
| 75 * description: 'My first plugin', | 74 * description: 'My first plugin', |
| 76 * mimeTypes: [ | 75 * type: 'BROWSER PLUGIN', |
| 77 * { description: 'New Guy Media', | 76 * mime_types: [ |
| 78 * fileExtensions: ['mfp'], | 77 * { |
| 79 * mimeType: 'application/x-my-first' } | 78 * description: 'New Guy Media', |
| 79 * file_extensions: ['mfp'], | |
| 80 * mime_type: 'application/x-my-first' | |
| 81 * }, | |
| 80 * ], | 82 * ], |
| 81 * enabledMode: 'enabledByPolicy' | 83 * enabled_mode: 'disabledByUser', |
| 82 * }, | 84 * }, |
| 83 * { | 85 * ], |
| 84 * path: '/foobar/baz/YourGreatPlugin.plugin', | 86 * }, |
| 85 * name: 'YourGreatPlugin', | 87 * ], |
| 86 * version: '4.5', | |
| 87 * description: 'Your great plugin', | |
| 88 * mimeTypes: [ | |
| 89 * { description: 'Baz Stuff', | |
| 90 * fileExtensions: ['baz'], | |
| 91 * mimeType: 'application/x-your-baz' } | |
| 92 * ], | |
| 93 * enabledMode: 'disabledByUser' | |
| 94 * }, | |
| 95 * { | |
| 96 * path: '/foobiz/bar/HisGreatPlugin.plugin', | |
| 97 * name: 'HisGreatPlugin', | |
| 98 * version: '1.2', | |
| 99 * description: 'His great plugin', | |
| 100 * mimeTypes: [ | |
| 101 * { description: 'More baz Stuff', | |
| 102 * fileExtensions: ['bor'], | |
| 103 * mimeType: 'application/x-his-bor' } | |
| 104 * ], | |
| 105 * enabledMode: 'disabledByPolicy' | |
| 106 * } | |
| 107 * ] | |
| 108 * } | |
| 109 * ] | |
| 110 * } | 88 * } |
| 111 */ | 89 */ |
| 112 function returnPluginsData(pluginsData) { | 90 function returnPluginsData(pluginsData) { |
| 113 var bodyContainer = $('body-container'); | 91 var bodyContainer = $('body-container'); |
| 114 var body = document.body; | 92 var body = document.body; |
| 115 | 93 |
| 116 // Set all page content to be visible so we can measure heights. | 94 // Set all page content to be visible so we can measure heights. |
| 117 bodyContainer.style.visibility = 'hidden'; | 95 bodyContainer.style.visibility = 'hidden'; |
| 118 body.className = ''; | 96 body.className = ''; |
| 119 var slidables = document.getElementsByClassName('show-in-tmi-mode'); | 97 var slidables = document.getElementsByClassName('show-in-tmi-mode'); |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 193 } | 171 } |
| 194 | 172 |
| 195 /** | 173 /** |
| 196 * Handles a 'enable' or 'disable' button getting clicked. | 174 * Handles a 'enable' or 'disable' button getting clicked. |
| 197 * @param {HTMLElement} node The HTML element for the plugin being changed. | 175 * @param {HTMLElement} node The HTML element for the plugin being changed. |
| 198 * @param {boolean} enable Whether to enable or disable the plugin. | 176 * @param {boolean} enable Whether to enable or disable the plugin. |
| 199 * @param {boolean} isGroup True if we're enabling/disabling a plugin group, | 177 * @param {boolean} isGroup True if we're enabling/disabling a plugin group, |
| 200 * rather than a single plugin. | 178 * rather than a single plugin. |
| 201 */ | 179 */ |
| 202 function handleEnablePlugin(node, enable, isGroup) { | 180 function handleEnablePlugin(node, enable, isGroup) { |
| 203 // Tell the C++ PluginsDOMHandler to enable/disable the plugin. | 181 whenBrowserProxyReady.then(function(browserProxy) { |
| 204 chrome.send('enablePlugin', [String(node.path), String(enable), | 182 isGroup ? |
|
Dan Beam
2016/01/28 04:25:08
don't do this
dpapad
2016/01/28 18:32:54
It's not apparent why you are suggesting not to do
Dan Beam
2016/01/28 19:20:34
if (isGroup)
browserProxy.setPluginGroupEnabled(
dpapad
2016/01/28 20:24:01
Changed per suggestion.
Finding precedent for som
| |
| 205 String(isGroup)]); | 183 browserProxy.setPluginGroupEnabled(node.path, enable) : |
| 184 browserProxy.setPluginEnabled(node.path, enable); | |
| 185 }); | |
| 206 } | 186 } |
| 207 | 187 |
| 208 // Keeps track of whether details have been made visible (expanded) or not. | 188 // Keeps track of whether details have been made visible (expanded) or not. |
| 209 var tmiModeExpanded = false; | 189 var tmiModeExpanded = false; |
| 210 | 190 |
| 211 /* | 191 /* |
| 212 * Toggles visibility of details. | 192 * Toggles visibility of details. |
| 213 */ | 193 */ |
| 214 function toggleTmiMode() { | 194 function toggleTmiMode() { |
| 215 tmiModeExpanded = !tmiModeExpanded; | 195 tmiModeExpanded = !tmiModeExpanded; |
| 216 | 196 |
| 217 $('collapse').style.display = | 197 $('collapse').style.display = |
| 218 tmiModeExpanded ? 'inline' : 'none'; | 198 tmiModeExpanded ? 'inline' : 'none'; |
| 219 $('expand').style.display = | 199 $('expand').style.display = |
| 220 tmiModeExpanded ? 'none' : 'inline'; | 200 tmiModeExpanded ? 'none' : 'inline'; |
| 221 | 201 |
| 222 document.body.className = | 202 document.body.className = |
| 223 tmiModeExpanded ? 'show-tmi-mode' : 'hide-tmi-mode'; | 203 tmiModeExpanded ? 'show-tmi-mode' : 'hide-tmi-mode'; |
| 224 | 204 |
| 225 chrome.send('saveShowDetailsToPrefs', [String(tmiModeExpanded)]); | 205 whenBrowserProxyReady.then(function(browserProxy) { |
| 206 browserProxy.saveShowDetailsToPrefs(tmiModeExpanded); | |
| 207 }); | |
| 226 } | 208 } |
| 227 | 209 |
| 228 function handleSetPluginAlwaysAllowed(el) { | 210 function handleSetPluginAlwaysAllowed(el) { |
| 229 chrome.send('setPluginAlwaysAllowed', [el.identifier, el.checked]); | 211 whenBrowserProxyReady.then(function(browserProxy) { |
| 212 browserProxy.setPluginAlwaysAllowed(el.identifier, el.checked); | |
| 213 }); | |
| 230 } | 214 } |
| 231 | 215 |
| 232 /** | 216 /** |
| 233 * @param {Object} plugin An object containing the information about a plugin. | 217 * @param {Object} plugin An object containing the information about a plugin. |
| 234 * See returnPluginsData() for the format of this object. | 218 * See returnPluginsData() for the format of this object. |
| 235 * @return {boolean} Whether the plugin's version should be displayed. | 219 * @return {boolean} Whether the plugin's version should be displayed. |
| 236 */ | 220 */ |
| 237 function shouldDisplayPluginVersion(plugin) { | 221 function shouldDisplayPluginVersion(plugin) { |
| 238 return !!plugin.version && plugin.version != '0'; | 222 return !!plugin.version && plugin.version != '0'; |
| 239 } | 223 } |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 252 plugin.description != 'Version ' + plugin.version && | 236 plugin.description != 'Version ' + plugin.version && |
| 253 plugin.description != plugin.name + ' ' + plugin.version; | 237 plugin.description != plugin.name + ' ' + plugin.version; |
| 254 } | 238 } |
| 255 | 239 |
| 256 /** | 240 /** |
| 257 * @param {Object} plugin An object containing the information about a plugin. | 241 * @param {Object} plugin An object containing the information about a plugin. |
| 258 * See returnPluginsData() for the format of this object. | 242 * See returnPluginsData() for the format of this object. |
| 259 * @return {boolean} Whether the plugin is enabled. | 243 * @return {boolean} Whether the plugin is enabled. |
| 260 */ | 244 */ |
| 261 function isPluginEnabled(plugin) { | 245 function isPluginEnabled(plugin) { |
| 262 return plugin.enabledMode == 'enabledByUser' || | 246 return plugin.enabled_mode == 'enabledByUser' || |
| 263 plugin.enabledMode == 'enabledByPolicy'; | 247 plugin.enabled_mode == 'enabledByPolicy'; |
| 264 } | 248 } |
| 265 | 249 |
| 266 // Unfortunately, we don't have notifications for plugin (list) status changes | 250 // Unfortunately, we don't have notifications for plugin (list) status changes |
| 267 // (yet), so in the meanwhile just update regularly. | 251 // (yet), so in the meanwhile just update regularly. |
| 268 setInterval(requestPluginsData, 30000); | 252 setInterval(function() { |
| 269 | 253 whenBrowserProxyReady.then(function(browserProxy) { |
| 270 // Get data and have it displayed upon loading. | 254 return browserProxy.getPluginsData(); |
| 271 document.addEventListener('DOMContentLoaded', requestPluginsData); | 255 }).then(returnPluginsData); |
| 256 }, 30000); | |
| 272 | 257 |
| 273 // Add handlers to static HTML elements. | 258 // Add handlers to static HTML elements. |
| 274 $('collapse').onclick = toggleTmiMode; | 259 $('collapse').onclick = toggleTmiMode; |
| 275 $('expand').onclick = toggleTmiMode; | 260 $('expand').onclick = toggleTmiMode; |
| 276 $('details-link').onclick = toggleTmiMode; | 261 $('details-link').onclick = toggleTmiMode; |
| 262 | |
| 263 // NOTE: Need to keep a reference to the stub here such that it is not garbage | |
| 264 // collected, which causes the pipe to close and future calls from C++ to JS to | |
| 265 // get dropped. | |
| 266 var pluginsPageStub = null; | |
| 267 | |
| 268 /** | |
| 269 * A promise to use for getting a reference to the proxy object allowing | |
| 270 * communication with the browser side. | |
| 271 * @type {!Promise} | |
| 272 */ | |
| 273 var whenBrowserProxyReady = new Promise(function(resolve, reject) { | |
| 274 define([ | |
| 275 'mojo/public/js/bindings', | |
| 276 'mojo/public/js/core', | |
| 277 'mojo/public/js/connection', | |
| 278 'chrome/browser/ui/webui/plugins/plugins.mojom', | |
| 279 'content/public/renderer/service_provider', | |
| 280 ], function(bindings, core, connection, pluginsMojom, serviceProvider) { | |
| 281 var browserProxy = connection.bindHandleToProxy( | |
| 282 serviceProvider.connectToService( | |
| 283 pluginsMojom.PluginsHandlerMojo.name), | |
| 284 pluginsMojom.PluginsHandlerMojo); | |
| 285 | |
| 286 // Perform necessary setup for the C++ side to make calls to JS at will. | |
| 287 | |
| 288 // Connect pipe handle to JS code. | |
| 289 var pipe = core.createMessagePipe(); | |
| 290 pluginsPageStub = connection.bindHandleToStub( | |
| 291 pipe.handle0, pluginsMojom.PluginsPageMojo); | |
| 292 | |
| 293 /** @constructor */ | |
| 294 function PluginsPageImpl() {} | |
| 295 PluginsPageImpl.prototype = { | |
| 296 __proto__: pluginsMojom.PluginsPageMojo.stubClass.prototype, | |
| 297 onPluginsUpdated: function(plugins) { | |
| 298 returnPluginsData({plugins: plugins}); | |
| 299 }, | |
| 300 }; | |
| 301 bindings.StubBindings(pluginsPageStub).delegate = new PluginsPageImpl(); | |
|
Dan Beam
2016/01/28 04:25:08
nit: this seems to be simpler (and mildly akin to
dpapad
2016/01/28 18:32:54
Done.
This is not compiled yet. See https://code.
| |
| 302 | |
| 303 // Send pipe handle to C++. | |
| 304 browserProxy.setClientPage(pipe.handle1); | |
| 305 | |
| 306 resolve(browserProxy); | |
| 307 }); | |
| 308 }); | |
| 309 | |
| 310 /** | |
| 311 * @type {!Promise} A promise firing when DOMContentLoaded event is received. | |
| 312 */ | |
| 313 var whenDomContentLoaded = new Promise(function(resolve, reject) { | |
| 314 document.addEventListener('DOMContentLoaded', resolve); | |
| 315 }); | |
| 316 | |
| 317 Promise.all([ | |
| 318 whenDomContentLoaded, | |
| 319 whenBrowserProxyReady | |
| 320 ]).then(function(results) { | |
| 321 var browserProxy = results[1]; | |
| 322 browserProxy.getPluginsData().then(returnPluginsData); | |
| 323 browserProxy.getShowDetails().then(function(response) { | |
| 324 loadShowDetailsFromPrefs(response.show_details); | |
| 325 }); | |
| 326 }); | |
| OLD | NEW |