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; |
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'], |
Dan Beam
2016/01/26 20:10:43
[\s -> [
dpapad
2016/01/26 22:34:48
Changed.
| |
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'], | |
Dan Beam
2016/01/26 20:10:43
[\s -> [
dpapad
2016/01/26 22:34:48
Changed.
| |
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'], | |
Dan Beam
2016/01/26 20:10:43
[\s -> [
dpapad
2016/01/26 22:34:48
Changed.
| |
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 ? |
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 | |
264 /** | |
265 * A promise to use for getting a reference to the proxy object allowing | |
266 * communication with the browser side. | |
267 * @type {!Promise} | |
268 */ | |
269 var whenBrowserProxyReady = getBrowserProxy_(); | |
Dan Beam
2016/01/26 20:10:43
creating a method just to call it once here adds n
dpapad
2016/01/26 22:34:48
Changed.
| |
270 | |
271 // NOTE: Need to keep a reference to the stub here such that it is not garbage | |
272 // collected, which causes the pipe to close and future calls from C++ to JS to | |
273 // get dropped. | |
274 var pluginsPageStub = null; | |
275 | |
276 /** | |
277 * Retrieves the proxy object to use for communicating with the browser side. It | |
278 * also performs necessary setup for the C++ side to make calls to JS at will. | |
279 * @return {!Promise} | |
280 */ | |
281 function getBrowserProxy_() { | |
Dan Beam
2016/01/26 20:10:43
only @private methods or members should have a tra
dpapad
2016/01/26 22:34:48
Removed this function.
| |
282 return new Promise(function(resolve, reject) { | |
283 define([ | |
284 'mojo/public/js/bindings', | |
285 'mojo/public/js/core', | |
286 'mojo/public/js/connection', | |
287 'chrome/browser/ui/webui/plugins/plugins.mojom', | |
288 'content/public/renderer/service_provider', | |
289 ], function(bindings, core, connection, pluginsMojom, serviceProvider) { | |
290 var browserProxy = connection.bindHandleToProxy( | |
291 serviceProvider.connectToService( | |
292 pluginsMojom.PluginsHandlerMojo.name), | |
293 pluginsMojom.PluginsHandlerMojo); | |
294 | |
295 // Connect pipe handle to JS code. | |
296 var pipe = core.createMessagePipe(); | |
297 pluginsPageStub = connection.bindHandleToStub( | |
298 pipe.handle0, pluginsMojom.PluginsPageMojo); | |
299 | |
300 /** @constructor */ | |
301 function PluginsPageImpl() {} | |
302 PluginsPageImpl.prototype = { | |
303 __proto__: pluginsMojom.PluginsPageMojo.stubClass.prototype, | |
304 onPluginsUpdated: function(plugins) { | |
305 returnPluginsData({plugins: plugins}); | |
306 }, | |
307 }; | |
308 bindings.StubBindings(pluginsPageStub).delegate = new PluginsPageImpl(); | |
309 | |
310 // Send pipe handle to C++. | |
311 browserProxy.setClientPage(pipe.handle1); | |
312 | |
313 resolve(browserProxy); | |
314 }); | |
315 }); | |
316 } | |
317 | |
318 /** | |
319 * @return {!Promise} A promise firing when DOMContentLoaded event is received. | |
320 */ | |
321 function whenDomContentLoaded() { | |
Dan Beam
2016/01/26 20:10:43
this doesn't need to be a function
dpapad
2016/01/26 22:34:48
Changed.
| |
322 return new Promise(function(resolve, reject) { | |
323 document.addEventListener('DOMContentLoaded', resolve); | |
324 }); | |
325 } | |
326 | |
327 Promise.all([ | |
328 whenDomContentLoaded(), | |
329 whenBrowserProxyReady | |
330 ]).then(function(results) { | |
331 var browserProxy = results[1]; | |
332 browserProxy.getPluginsData().then(returnPluginsData); | |
333 browserProxy.getShowDetails().then(function(response) { | |
334 loadShowDetailsFromPrefs(response.show_details); | |
335 }); | |
336 }); | |
OLD | NEW |