| 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. | 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(). |
| (...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 128 for (var i = 0; i < labels.length; i++) | 128 for (var i = 0; i < labels.length; i++) |
| 129 labels[i].style.width = maxLabelWidth + 'px'; | 129 labels[i].style.width = maxLabelWidth + 'px'; |
| 130 | 130 |
| 131 // Explicitly set the height for each element that wants to be "slid" in and | 131 // Explicitly set the height for each element that wants to be "slid" in and |
| 132 // out when the tmiModeExpanded is toggled. | 132 // out when the tmiModeExpanded is toggled. |
| 133 var slidables = document.getElementsByClassName('show-in-tmi-mode'); | 133 var slidables = document.getElementsByClassName('show-in-tmi-mode'); |
| 134 for (var i = 0; i < slidables.length; i++) | 134 for (var i = 0; i < slidables.length; i++) |
| 135 slidables[i].style.height = slidables[i].offsetHeight + 'px'; | 135 slidables[i].style.height = slidables[i].offsetHeight + 'px'; |
| 136 | 136 |
| 137 // Reset visibility of page based on the current tmi mode. | 137 // Reset visibility of page based on the current tmi mode. |
| 138 $('collapse').style.display = | 138 $('collapse').style.display = tmiModeExpanded ? 'inline' : 'none'; |
| 139 tmiModeExpanded ? 'inline' : 'none'; | 139 $('expand').style.display = tmiModeExpanded ? 'none' : 'inline'; |
| 140 $('expand').style.display = | |
| 141 tmiModeExpanded ? 'none' : 'inline'; | |
| 142 bodyContainer.style.visibility = 'visible'; | 140 bodyContainer.style.visibility = 'visible'; |
| 143 body.className = tmiModeExpanded ? | 141 body.className = |
| 144 'show-tmi-mode-initial' : 'hide-tmi-mode-initial'; | 142 tmiModeExpanded ? 'show-tmi-mode-initial' : 'hide-tmi-mode-initial'; |
| 145 } | 143 } |
| 146 | 144 |
| 147 /* | 145 /* |
| 148 * Toggles visibility of details. | 146 * Toggles visibility of details. |
| 149 */ | 147 */ |
| 150 function toggleTmiMode() { | 148 function toggleTmiMode() { |
| 151 tmiModeExpanded = !tmiModeExpanded; | 149 tmiModeExpanded = !tmiModeExpanded; |
| 152 | 150 |
| 153 $('collapse').style.display = | 151 $('collapse').style.display = tmiModeExpanded ? 'inline' : 'none'; |
| 154 tmiModeExpanded ? 'inline' : 'none'; | 152 $('expand').style.display = tmiModeExpanded ? 'none' : 'inline'; |
| 155 $('expand').style.display = | |
| 156 tmiModeExpanded ? 'none' : 'inline'; | |
| 157 | 153 |
| 158 document.body.className = | 154 document.body.className = tmiModeExpanded ? 'show-tmi-mode' : 'hide-tmi-mode'; |
| 159 tmiModeExpanded ? 'show-tmi-mode' : 'hide-tmi-mode'; | |
| 160 | 155 |
| 161 browserProxy.saveShowDetailsToPrefs(tmiModeExpanded); | 156 browserProxy.saveShowDetailsToPrefs(tmiModeExpanded); |
| 162 } | 157 } |
| 163 | 158 |
| 164 function handleSetPluginAlwaysAllowed(el) { | 159 function handleSetPluginAlwaysAllowed(el) { |
| 165 browserProxy.setPluginAlwaysAllowed(el.identifier, el.checked); | 160 browserProxy.setPluginAlwaysAllowed(el.identifier, el.checked); |
| 166 } | 161 } |
| 167 | 162 |
| 168 /** | 163 /** |
| 169 * @param {Object} plugin An object containing the information about a plugin. | 164 * @param {Object} plugin An object containing the information about a plugin. |
| 170 * See returnPluginsData() for the format of this object. | 165 * See returnPluginsData() for the format of this object. |
| 171 * @return {boolean} Whether the plugin's version should be displayed. | 166 * @return {boolean} Whether the plugin's version should be displayed. |
| 172 */ | 167 */ |
| 173 function shouldDisplayPluginVersion(plugin) { | 168 function shouldDisplayPluginVersion(plugin) { |
| 174 return !!plugin.version && plugin.version != '0'; | 169 return !!plugin.version && plugin.version != '0'; |
| 175 } | 170 } |
| 176 | 171 |
| 177 /** | 172 /** |
| 178 * @param {Object} plugin An object containing the information about a plugin. | 173 * @param {Object} plugin An object containing the information about a plugin. |
| 179 * See returnPluginsData() for the format of this object. | 174 * See returnPluginsData() for the format of this object. |
| 180 * @return {boolean} Whether the plugin's description should be displayed. | 175 * @return {boolean} Whether the plugin's description should be displayed. |
| 181 */ | 176 */ |
| 182 function shouldDisplayPluginDescription(plugin) { | 177 function shouldDisplayPluginDescription(plugin) { |
| 183 // Only display the description if it's not blank and if it's not just the | 178 // Only display the description if it's not blank and if it's not just the |
| 184 // name, version, or combination thereof. | 179 // name, version, or combination thereof. |
| 185 return plugin.description && | 180 return plugin.description && plugin.description != plugin.name && |
| 186 plugin.description != plugin.name && | 181 plugin.description != plugin.version && |
| 187 plugin.description != plugin.version && | 182 plugin.description != 'Version ' + plugin.version && |
| 188 plugin.description != 'Version ' + plugin.version && | 183 plugin.description != plugin.name + ' ' + plugin.version; |
| 189 plugin.description != plugin.name + ' ' + plugin.version; | |
| 190 } | 184 } |
| 191 | 185 |
| 192 /** | 186 /** |
| 193 * @param {Object} plugin An object containing the information about a plugin. | 187 * @param {Object} plugin An object containing the information about a plugin. |
| 194 * See returnPluginsData() for the format of this object. | 188 * See returnPluginsData() for the format of this object. |
| 195 * @return {boolean} Whether the plugin is enabled. | 189 * @return {boolean} Whether the plugin is enabled. |
| 196 */ | 190 */ |
| 197 function isPluginEnabled(plugin) { | 191 function isPluginEnabled(plugin) { |
| 198 return plugin.enabled_mode == 'enabledByUser' || | 192 return plugin.enabled_mode == 'enabledByUser' || |
| 199 plugin.enabled_mode == 'enabledByPolicy'; | 193 plugin.enabled_mode == 'enabledByPolicy'; |
| 200 } | 194 } |
| 201 | 195 |
| 202 /** | 196 /** |
| 203 * @param {Object} plugin An object containing the information about a plugin. | 197 * @param {Object} plugin An object containing the information about a plugin. |
| 204 * See returnPluginsData() for the format of this object. | 198 * See returnPluginsData() for the format of this object. |
| 205 * @return {boolean} Whether the plugin is fully trusted. | 199 * @return {boolean} Whether the plugin is fully trusted. |
| 206 */ | 200 */ |
| 207 function isPluginTrusted(plugin) { | 201 function isPluginTrusted(plugin) { |
| 208 return plugin.trusted == true; | 202 return plugin.trusted == true; |
| 209 } | 203 } |
| 210 | 204 |
| 211 /** | 205 /** |
| 212 * @param {Object} plugin An object containing the information about a plugin. | 206 * @param {Object} plugin An object containing the information about a plugin. |
| 213 * See returnPluginsData() for the format of this object. | 207 * See returnPluginsData() for the format of this object. |
| 214 * @return {boolean} Whether the plugin is marked click to play by policy. | 208 * @return {boolean} Whether the plugin is marked click to play by policy. |
| 215 * | 209 * |
| 216 * This would normally be set by setting the policy DefaultPluginsSetting to 3. | 210 * This would normally be set by setting the policy DefaultPluginsSetting to 3. |
| 217 */ | 211 */ |
| 218 function isPluginPolicyClickToPlay(plugin) { | 212 function isPluginPolicyClickToPlay(plugin) { |
| 219 return plugin.policy_click_to_play == true; | 213 return plugin.policy_click_to_play == true; |
| 220 } | 214 } |
| 221 | 215 |
| 222 // NOTE: Need to keep a global reference to the |pageImpl| such that it is not | 216 // NOTE: Need to keep a global reference to the |pageImpl| such that it is not |
| 223 // garbage collected, which causes the pipe to close and future calls from C++ | 217 // garbage collected, which causes the pipe to close and future calls from C++ |
| 224 // to JS to get dropped. This also allows tests to make direct calls on it. | 218 // to JS to get dropped. This also allows tests to make direct calls on it. |
| 225 var pageImpl = null; | 219 var pageImpl = null; |
| 226 var browserProxy = null; | 220 var browserProxy = null; |
| 227 | 221 |
| 228 function initializeProxies() { | 222 function initializeProxies() { |
| 229 return importModules([ | 223 return importModules([ |
| 230 'mojo/public/js/bindings', | 224 'mojo/public/js/bindings', |
| 231 'chrome/browser/ui/webui/plugins/plugins.mojom', | 225 'chrome/browser/ui/webui/plugins/plugins.mojom', |
| 232 'content/public/renderer/frame_interfaces', | 226 'content/public/renderer/frame_interfaces', |
| 233 ]).then(function(modules) { | 227 ]) |
| 234 var bindings = modules[0]; | 228 .then(function(modules) { |
| 235 var pluginsMojom = modules[1]; | 229 var bindings = modules[0]; |
| 236 var frameInterfaces = modules[2]; | 230 var pluginsMojom = modules[1]; |
| 231 var frameInterfaces = modules[2]; |
| 237 | 232 |
| 238 browserProxy = new pluginsMojom.PluginsPageHandlerPtr( | 233 browserProxy = new pluginsMojom.PluginsPageHandlerPtr( |
| 239 frameInterfaces.getInterface(pluginsMojom.PluginsPageHandler.name)); | 234 frameInterfaces.getInterface(pluginsMojom.PluginsPageHandler.name)); |
| 240 | 235 |
| 241 /** @constructor */ | 236 /** @constructor */ |
| 242 var PluginsPageImpl = function() { | 237 var PluginsPageImpl = function() { |
| 243 this.binding = new bindings.Binding(pluginsMojom.PluginsPage, this); | 238 this.binding = new bindings.Binding(pluginsMojom.PluginsPage, this); |
| 244 }; | 239 }; |
| 245 | 240 |
| 246 PluginsPageImpl.prototype = { | 241 PluginsPageImpl.prototype = { |
| 247 /** @override */ | 242 /** @override */ |
| 248 onPluginsUpdated: function(plugins) { | 243 onPluginsUpdated: function(plugins) { |
| 249 returnPluginsData({plugins: plugins}); | 244 returnPluginsData({plugins: plugins}); |
| 250 }, | 245 }, |
| 251 }; | 246 }; |
| 252 pageImpl = new PluginsPageImpl(); | 247 pageImpl = new PluginsPageImpl(); |
| 253 browserProxy.setClientPage(pageImpl.binding.createInterfacePtrAndBind()); | 248 browserProxy.setClientPage( |
| 254 }); | 249 pageImpl.binding.createInterfacePtrAndBind()); |
| 250 }); |
| 255 } | 251 } |
| 256 | 252 |
| 257 /** | 253 /** |
| 258 * Overriden by tests to give them a chance to setup a fake Mojo browser proxy | 254 * Overriden by tests to give them a chance to setup a fake Mojo browser proxy |
| 259 * before any other code executes. | 255 * before any other code executes. |
| 260 * @return {!Promise} A promise firing once necessary setup has been completed. | 256 * @return {!Promise} A promise firing once necessary setup has been completed. |
| 261 */ | 257 */ |
| 262 var setupFn = setupFn || function() { return Promise.resolve(); }; | 258 var setupFn = setupFn || function() { |
| 259 return Promise.resolve(); |
| 260 }; |
| 263 | 261 |
| 264 function main() { | 262 function main() { |
| 265 setupFn().then(function() { | 263 setupFn() |
| 266 // Add handlers to static HTML elements. | 264 .then(function() { |
| 267 $('collapse').onclick = toggleTmiMode; | 265 // Add handlers to static HTML elements. |
| 268 $('expand').onclick = toggleTmiMode; | 266 $('collapse').onclick = toggleTmiMode; |
| 269 $('details-link').onclick = toggleTmiMode; | 267 $('expand').onclick = toggleTmiMode; |
| 270 return initializeProxies(); | 268 $('details-link').onclick = toggleTmiMode; |
| 271 }).then(function() { | 269 return initializeProxies(); |
| 272 return browserProxy.getShowDetails(); | 270 }) |
| 273 }).then(function(response) { | 271 .then(function() { |
| 274 // Set the |tmiModeExpanded| first otherwise the UI flickers when | 272 return browserProxy.getShowDetails(); |
| 275 // returnPlignsData executes. | 273 }) |
| 276 loadShowDetailsFromPrefs(response.show_details); | 274 .then(function(response) { |
| 277 return browserProxy.getPluginsData(); | 275 // Set the |tmiModeExpanded| first otherwise the UI flickers when |
| 278 }).then(function(pluginsData) { | 276 // returnPlignsData executes. |
| 279 returnPluginsData(pluginsData); | 277 loadShowDetailsFromPrefs(response.show_details); |
| 278 return browserProxy.getPluginsData(); |
| 279 }) |
| 280 .then(function(pluginsData) { |
| 281 returnPluginsData(pluginsData); |
| 280 | 282 |
| 281 // Unfortunately, we don't have notifications for plugin (list) status | 283 // Unfortunately, we don't have notifications for plugin (list) status |
| 282 // changes (yet), so in the meanwhile just update regularly. | 284 // changes (yet), so in the meanwhile just update regularly. |
| 283 setInterval(function() { | 285 setInterval(function() { |
| 284 browserProxy.getPluginsData().then(returnPluginsData); | 286 browserProxy.getPluginsData().then(returnPluginsData); |
| 285 }, 30000); | 287 }, 30000); |
| 286 }); | 288 }); |
| 287 } | 289 } |
| 288 | 290 |
| 289 document.addEventListener('DOMContentLoaded', main); | 291 document.addEventListener('DOMContentLoaded', main); |
| OLD | NEW |