| 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 * This variable structure is here to document the structure that the template | |
| 7 * expects to correctly populate the page. | |
| 8 */ | |
| 9 var pluginDataFormat = { | |
| 10 plugins: [ | |
| 11 { | |
| 12 name: 'Group Name', | |
| 13 description: 'description', | |
| 14 version: 'version', | |
| 15 update_url: 'http://update/', | |
| 16 critical: true, | |
| 17 enabled: true, | |
| 18 plugin_files: [ | |
| 19 { | |
| 20 path: '/blahblah/blahblah/MyCrappyPlugin.plugin', | |
| 21 name: 'MyCrappyPlugin', | |
| 22 version: '1.2.3', | |
| 23 description: 'My crappy plugin', | |
| 24 mimeTypes: [ | |
| 25 { description: 'Foo Media', | |
| 26 fileExtensions: ['foo'], | |
| 27 mimeType: 'application/x-my-foo' }, | |
| 28 { description: 'Bar Stuff', | |
| 29 fileExtensions: ['bar', 'baz'], | |
| 30 mimeType: 'application/my-bar' } | |
| 31 ], | |
| 32 enabledMode: 'enabledByUser' | |
| 33 }, | |
| 34 { | |
| 35 path: '/tmp/MyFirst.plugin', | |
| 36 name: 'MyFirstPlugin', | |
| 37 version: '3.14r15926', | |
| 38 description: 'My first plugin', | |
| 39 mimeTypes: [ | |
| 40 { description: 'New Guy Media', | |
| 41 fileExtensions: ['mfp'], | |
| 42 mimeType: 'application/x-my-first' } | |
| 43 ], | |
| 44 enabledMode: 'enabledByPolicy' | |
| 45 }, | |
| 46 { | |
| 47 path: '/foobar/baz/YourGreatPlugin.plugin', | |
| 48 name: 'YourGreatPlugin', | |
| 49 version: '4.5', | |
| 50 description: 'Your great plugin', | |
| 51 mimeTypes: [ | |
| 52 { description: 'Baz Stuff', | |
| 53 fileExtensions: ['baz'], | |
| 54 mimeType: 'application/x-your-baz' } | |
| 55 ], | |
| 56 enabledMode: 'disabledByUser' | |
| 57 }, | |
| 58 { | |
| 59 path: '/foobiz/bar/HisGreatPlugin.plugin', | |
| 60 name: 'HisGreatPlugin', | |
| 61 version: '1.2', | |
| 62 description: 'His great plugin', | |
| 63 mimeTypes: [ | |
| 64 { description: 'More baz Stuff', | |
| 65 fileExtensions: ['bor'], | |
| 66 mimeType: 'application/x-his-bor' } | |
| 67 ], | |
| 68 enabledMode: 'disabledByPolicy' | |
| 69 } | |
| 70 ] | |
| 71 } | |
| 72 ] | |
| 73 }; | |
| 74 | |
| 75 /** | |
| 76 * Takes the |pluginsData| input argument which represents data about the | 6 * Takes the |pluginsData| input argument which represents data about the |
| 77 * currently installed/running plugins and populates the html jstemplate with | 7 * currently installed/running plugins and populates the html jstemplate with |
| 78 * that data. It expects an object structure like the above. | 8 * that data. It expects an object structure like the above. |
| 79 * @param {Object} pluginsData Detailed info about installed plugins. See | 9 * @param {Object} pluginsData Detailed info about installed plugins. Same |
| 80 * 'var pluginDataFormat' above. | 10 * expected format as returnPluginsData(). |
| 81 */ | 11 */ |
| 82 function renderTemplate(pluginsData) { | 12 function renderTemplate(pluginsData) { |
| 83 // This is the javascript code that processes the template: | 13 // This is the javascript code that processes the template: |
| 84 var input = new JsEvalContext(pluginsData); | 14 var input = new JsEvalContext(pluginsData); |
| 85 var output = $('pluginTemplate'); | 15 var output = $('pluginTemplate'); |
| 86 jstProcess(input, output); | 16 jstProcess(input, output); |
| 87 } | 17 } |
| 88 | 18 |
| 89 /** | 19 /** |
| 90 * Asks the C++ PluginsDOMHandler to get details about the installed plugins and | 20 * Asks the C++ PluginsDOMHandler to get details about the installed plugins and |
| 91 * return detailed data about the configuration. The PluginsDOMHandler should | 21 * return detailed data about the configuration. The PluginsDOMHandler should |
| 92 * reply to returnPluginsData() (below). | 22 * reply to returnPluginsData() (below). |
| 93 */ | 23 */ |
| 94 function requestPluginsData() { | 24 function requestPluginsData() { |
| 95 chrome.send('requestPluginsData'); | 25 chrome.send('requestPluginsData'); |
| 96 chrome.send('getShowDetails'); | 26 chrome.send('getShowDetails'); |
| 97 } | 27 } |
| 98 | 28 |
| 99 function loadShowDetailsFromPrefs(show_details) { | 29 function loadShowDetailsFromPrefs(show_details) { |
| 100 tmiModeExpanded = show_details; | 30 tmiModeExpanded = show_details; |
| 101 $('collapse').style.display = | 31 $('collapse').style.display = |
| 102 show_details ? 'inline' : 'none'; | 32 show_details ? 'inline' : 'none'; |
| 103 $('expand').style.display = | 33 $('expand').style.display = |
| 104 show_details ? 'none' : 'inline'; | 34 show_details ? 'none' : 'inline'; |
| 105 | 35 |
| 106 document.body.className = show_details ? 'show-tmi-mode' : 'hide-tmi-mode'; | 36 document.body.className = show_details ? 'show-in-tmi-mode' : 'hide-tmi-mode'; |
| 107 } | 37 } |
| 108 | 38 |
| 109 /** | 39 /** |
| 110 * Called by the web_ui_ to re-populate the page with data representing the | 40 * Called by the web_ui_ to re-populate the page with data representing the |
| 111 * current state of installed plugins. | 41 * current state of installed plugins. |
| 112 * @param {Object} pluginsData Detailed info about installed plugins. See | 42 * @param {Object} pluginsData Detailed info about installed plugins. The |
| 113 * 'var pluginDataFormat' above. | 43 * template expects each plugin's format to match the following structure to |
| 44 * correctly populate the page: |
| 45 * { |
| 46 * plugins: [ |
| 47 * { |
| 48 * name: 'Group Name', |
| 49 * description: 'description', |
| 50 * version: 'version', |
| 51 * update_url: 'http://update/', |
| 52 * critical: true, |
| 53 * enabled: true, |
| 54 * plugin_files: [ |
| 55 * { |
| 56 * path: '/blahblah/blahblah/MyCrappyPlugin.plugin', |
| 57 * name: 'MyCrappyPlugin', |
| 58 * version: '1.2.3', |
| 59 * description: 'My crappy plugin', |
| 60 * mimeTypes: [ |
| 61 * { description: 'Foo Media', |
| 62 * fileExtensions: ['foo'], |
| 63 * mimeType: 'application/x-my-foo' }, |
| 64 * { description: 'Bar Stuff', |
| 65 * fileExtensions: ['bar', 'baz'], |
| 66 * mimeType: 'application/my-bar' } |
| 67 * ], |
| 68 * enabledMode: 'enabledByUser' |
| 69 * }, |
| 70 * { |
| 71 * path: '/tmp/MyFirst.plugin', |
| 72 * name: 'MyFirstPlugin', |
| 73 * version: '3.14r15926', |
| 74 * description: 'My first plugin', |
| 75 * mimeTypes: [ |
| 76 * { description: 'New Guy Media', |
| 77 * fileExtensions: ['mfp'], |
| 78 * mimeType: 'application/x-my-first' } |
| 79 * ], |
| 80 * enabledMode: 'enabledByPolicy' |
| 81 * }, |
| 82 * { |
| 83 * path: '/foobar/baz/YourGreatPlugin.plugin', |
| 84 * name: 'YourGreatPlugin', |
| 85 * version: '4.5', |
| 86 * description: 'Your great plugin', |
| 87 * mimeTypes: [ |
| 88 * { description: 'Baz Stuff', |
| 89 * fileExtensions: ['baz'], |
| 90 * mimeType: 'application/x-your-baz' } |
| 91 * ], |
| 92 * enabledMode: 'disabledByUser' |
| 93 * }, |
| 94 * { |
| 95 * path: '/foobiz/bar/HisGreatPlugin.plugin', |
| 96 * name: 'HisGreatPlugin', |
| 97 * version: '1.2', |
| 98 * description: 'His great plugin', |
| 99 * mimeTypes: [ |
| 100 * { description: 'More baz Stuff', |
| 101 * fileExtensions: ['bor'], |
| 102 * mimeType: 'application/x-his-bor' } |
| 103 * ], |
| 104 * enabledMode: 'disabledByPolicy' |
| 105 * } |
| 106 * ] |
| 107 * } |
| 108 * ] |
| 109 * } |
| 114 */ | 110 */ |
| 115 function returnPluginsData(pluginsData) { | 111 function returnPluginsData(pluginsData) { |
| 116 var bodyContainer = $('body-container'); | 112 var bodyContainer = $('body-container'); |
| 117 var body = document.body; | 113 var body = document.body; |
| 118 | 114 |
| 119 // Set all page content to be visible so we can measure heights. | 115 // Set all page content to be visible so we can measure heights. |
| 120 bodyContainer.style.visibility = 'hidden'; | 116 bodyContainer.style.visibility = 'hidden'; |
| 121 body.className = ''; | 117 body.className = ''; |
| 122 var slidables = document.getElementsByClassName('show-in-tmi-mode'); | 118 var slidables = document.getElementsByClassName('show-in-tmi-mode'); |
| 123 for (var i = 0; i < slidables.length; i++) | 119 for (var i = 0; i < slidables.length; i++) |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 224 | 220 |
| 225 chrome.send('saveShowDetailsToPrefs', [String(tmiModeExpanded)]); | 221 chrome.send('saveShowDetailsToPrefs', [String(tmiModeExpanded)]); |
| 226 } | 222 } |
| 227 | 223 |
| 228 function handleSetPluginAlwaysAllowed(el) { | 224 function handleSetPluginAlwaysAllowed(el) { |
| 229 chrome.send('setPluginAlwaysAllowed', [el.identifier, el.checked]); | 225 chrome.send('setPluginAlwaysAllowed', [el.identifier, el.checked]); |
| 230 } | 226 } |
| 231 | 227 |
| 232 /** | 228 /** |
| 233 * @param {Object} plugin An object containing the information about a plugin. | 229 * @param {Object} plugin An object containing the information about a plugin. |
| 234 * See 'var pluginDataFormat' above. | 230 * See returnPluginsData() for the format of this object. |
| 235 * @return {boolean} Whether the plugin's version should be displayed. | 231 * @return {boolean} Whether the plugin's version should be displayed. |
| 236 */ | 232 */ |
| 237 function shouldDisplayPluginVersion(plugin) { | 233 function shouldDisplayPluginVersion(plugin) { |
| 238 return !!plugin.version && plugin.version != '0'; | 234 return !!plugin.version && plugin.version != '0'; |
| 239 } | 235 } |
| 240 | 236 |
| 241 /** | 237 /** |
| 242 * @param {Object} plugin An object containing the information about a plugin. | 238 * @param {Object} plugin An object containing the information about a plugin. |
| 243 * See 'var pluginDataFormat' above. | 239 * See returnPluginsData() for the format of this object. |
| 244 * @return {boolean} Whether the plugin's description should be displayed. | 240 * @return {boolean} Whether the plugin's description should be displayed. |
| 245 */ | 241 */ |
| 246 function shouldDisplayPluginDescription(plugin) { | 242 function shouldDisplayPluginDescription(plugin) { |
| 247 // Only display the description if it's not blank and if it's not just the | 243 // Only display the description if it's not blank and if it's not just the |
| 248 // name, version, or combination thereof. | 244 // name, version, or combination thereof. |
| 249 return plugin.description && | 245 return plugin.description && |
| 250 plugin.description != plugin.name && | 246 plugin.description != plugin.name && |
| 251 plugin.description != plugin.version && | 247 plugin.description != plugin.version && |
| 252 plugin.description != 'Version ' + plugin.version && | 248 plugin.description != 'Version ' + plugin.version && |
| 253 plugin.description != plugin.name + ' ' + plugin.version; | 249 plugin.description != plugin.name + ' ' + plugin.version; |
| 254 } | 250 } |
| 255 | 251 |
| 256 /** | 252 /** |
| 257 * @param {Object} plugin An object containing the information about a plugin. | 253 * @param {Object} plugin An object containing the information about a plugin. |
| 258 * See 'var pluginDataFormat' above. | 254 * See returnPluginsData() for the format of this object. |
| 259 * @return {boolean} Whether the plugin is enabled. | 255 * @return {boolean} Whether the plugin is enabled. |
| 260 */ | 256 */ |
| 261 function isPluginEnabled(plugin) { | 257 function isPluginEnabled(plugin) { |
| 262 return plugin.enabledMode == 'enabledByUser' || | 258 return plugin.enabledMode == 'enabledByUser' || |
| 263 plugin.enabledMode == 'enabledByPolicy'; | 259 plugin.enabledMode == 'enabledByPolicy'; |
| 264 } | 260 } |
| 265 | 261 |
| 266 // Unfortunately, we don't have notifications for plugin (list) status changes | 262 // Unfortunately, we don't have notifications for plugin (list) status changes |
| 267 // (yet), so in the meanwhile just update regularly. | 263 // (yet), so in the meanwhile just update regularly. |
| 268 setInterval(requestPluginsData, 30000); | 264 setInterval(requestPluginsData, 30000); |
| 269 | 265 |
| 270 // Get data and have it displayed upon loading. | 266 // Get data and have it displayed upon loading. |
| 271 document.addEventListener('DOMContentLoaded', requestPluginsData); | 267 document.addEventListener('DOMContentLoaded', requestPluginsData); |
| 272 | 268 |
| 273 // Add handlers to static HTML elements. | 269 // Add handlers to static HTML elements. |
| 274 $('collapse').onclick = toggleTmiMode; | 270 $('collapse').onclick = toggleTmiMode; |
| 275 $('expand').onclick = toggleTmiMode; | 271 $('expand').onclick = toggleTmiMode; |
| 276 $('details-link').onclick = toggleTmiMode; | 272 $('details-link').onclick = toggleTmiMode; |
| OLD | NEW |