Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1962)

Side by Side Diff: chrome/browser/resources/plugins.js

Issue 2020463002: Mojo JS: Attempt to simplify bindTo* related code. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | mojo/public/js/connection.js » ('j') | mojo/public/js/connection.js » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 245 matching lines...) Expand 10 before | Expand all | Expand 10 after
256 * @return {!Promise} 256 * @return {!Promise}
257 */ 257 */
258 function importModules(moduleNames) { 258 function importModules(moduleNames) {
259 return new Promise(function(resolve, reject) { 259 return new Promise(function(resolve, reject) {
260 define(moduleNames, function(var_args) { 260 define(moduleNames, function(var_args) {
261 resolve(Array.prototype.slice.call(arguments, 0)); 261 resolve(Array.prototype.slice.call(arguments, 0));
262 }); 262 });
263 }); 263 });
264 } 264 }
265 265
266 // NOTE: Need to keep a reference to the stub here such that it is not garbage 266 // NOTE: Need to keep a global reference to the |pageProxy| such that it is not
267 // collected, which causes the pipe to close and future calls from C++ to JS to 267 // garbage collected, which causes the pipe to close and future calls from C++
268 // get dropped. 268 // to JS to get dropped. This also allows tests to make direct calls on it.
269 var pluginsPageStub = null; 269 var pageProxy = null;
270
271 var browserProxy = null; 270 var browserProxy = null;
272 // Exposed globally such that the tests can make direct calls on it.
273 var pageProxy = null;
274 271
275 function initializeProxies() { 272 function initializeProxies() {
276 return importModules([ 273 return importModules([
277 'mojo/public/js/bindings', 274 'mojo/public/js/bindings',
278 'mojo/public/js/core', 275 'mojo/public/js/core',
279 'mojo/public/js/connection', 276 'mojo/public/js/connection',
280 'chrome/browser/ui/webui/plugins/plugins.mojom', 277 'chrome/browser/ui/webui/plugins/plugins.mojom',
281 'content/public/renderer/frame_service_registry', 278 'content/public/renderer/frame_service_registry',
282 ]).then(function(modules) { 279 ]).then(function(modules) {
283 var bindings = modules[0]; 280 var bindings = modules[0];
284 var core = modules[1]; 281 var core = modules[1];
285 var connection = modules[2]; 282 var connection = modules[2];
286 var pluginsMojom = modules[3]; 283 var pluginsMojom = modules[3];
287 var serviceProvider = modules[4]; 284 var serviceProvider = modules[4];
288 285
289 browserProxy = connection.bindHandleToProxy( 286 browserProxy = connection.bindHandleToProxy(
290 serviceProvider.connectToService(pluginsMojom.PluginsPageHandler.name), 287 serviceProvider.connectToService(pluginsMojom.PluginsPageHandler.name),
291 pluginsMojom.PluginsPageHandler); 288 pluginsMojom.PluginsPageHandler);
292 289
293 // Connect pipe handle to JS code. 290 /** @constructor */
294 var pipe = core.createMessagePipe(); 291 var PluginsPageProxy = function() {};
295 pluginsPageStub = connection.bindHandleToStub(
296 pipe.handle0, pluginsMojom.PluginsPage);
297 292
298 pageProxy = { 293 PluginsPageProxy.prototype = {
299 __proto__: pluginsMojom.PluginsPage.stubClass.prototype, 294 __proto__: pluginsMojom.PluginsPage.stubClass.prototype,
295
296 /** @override */
300 onPluginsUpdated: function(plugins) { 297 onPluginsUpdated: function(plugins) {
301 returnPluginsData({plugins: plugins}); 298 returnPluginsData({plugins: plugins});
302 }, 299 },
303 }; 300 };
301 pageProxy = new PluginsPageProxy();
304 302
305 bindings.StubBindings(pluginsPageStub).delegate = pageProxy; 303 var pipe = core.createMessagePipe();
306 // Send pipe handle to C++. 304 // Connect one end of the pipe to JS.
305 connection.bindHandleToObj(pipe.handle0, pageProxy);
yzshen1 2016/05/27 16:24:45 Does it make sense to name it bindHandleToImpl()?
dpapad 2016/05/27 17:55:37 I found a way to simplify even more by completely
yzshen1 2016/05/27 18:32:46 Okay. I am fine with any name that seems appropria
dpapad 2016/05/27 20:36:56 Ended up renaming to PluginsPageImpl per your sugg
306 // Send the other end of the pipe to C++.
307 browserProxy.setClientPage(pipe.handle1); 307 browserProxy.setClientPage(pipe.handle1);
308 }); 308 });
309 } 309 }
310 310
311 /** 311 /**
312 * Overriden by tests to give them a chance to setup a fake Mojo browser proxy 312 * Overriden by tests to give them a chance to setup a fake Mojo browser proxy
313 * before any other code executes. 313 * before any other code executes.
314 * @return {!Promise} A promise firing once necessary setup has been completed. 314 * @return {!Promise} A promise firing once necessary setup has been completed.
315 */ 315 */
316 var setupFn = setupFn || function() { return Promise.resolve(); }; 316 var setupFn = setupFn || function() { return Promise.resolve(); };
(...skipping 17 matching lines...) Expand all
334 334
335 // Unfortunately, we don't have notifications for plugin (list) status 335 // Unfortunately, we don't have notifications for plugin (list) status
336 // changes (yet), so in the meanwhile just update regularly. 336 // changes (yet), so in the meanwhile just update regularly.
337 setInterval(function() { 337 setInterval(function() {
338 browserProxy.getPluginsData().then(returnPluginsData); 338 browserProxy.getPluginsData().then(returnPluginsData);
339 }, 30000); 339 }, 30000);
340 }); 340 });
341 } 341 }
342 342
343 document.addEventListener('DOMContentLoaded', main); 343 document.addEventListener('DOMContentLoaded', main);
OLDNEW
« no previous file with comments | « no previous file | mojo/public/js/connection.js » ('j') | mojo/public/js/connection.js » ('J')

Powered by Google App Engine
This is Rietveld 408576698