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