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

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: Rename Created 4 years, 6 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 | chrome/test/data/webui/plugins_browsertest.js » ('j') | no next file with comments »
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 |pageImpl| 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 pageImpl = 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',
278 'mojo/public/js/core',
279 'mojo/public/js/connection', 274 'mojo/public/js/connection',
280 'chrome/browser/ui/webui/plugins/plugins.mojom', 275 'chrome/browser/ui/webui/plugins/plugins.mojom',
281 'content/public/renderer/frame_service_registry', 276 'content/public/renderer/frame_service_registry',
282 ]).then(function(modules) { 277 ]).then(function(modules) {
283 var bindings = modules[0]; 278 var connection = modules[0];
284 var core = modules[1]; 279 var pluginsMojom = modules[1];
285 var connection = modules[2]; 280 var serviceRegistry = modules[2];
286 var pluginsMojom = modules[3];
287 var serviceProvider = modules[4];
288 281
289 browserProxy = connection.bindHandleToProxy( 282 browserProxy = connection.bindHandleToProxy(
290 serviceProvider.connectToService(pluginsMojom.PluginsPageHandler.name), 283 serviceRegistry.connectToService(pluginsMojom.PluginsPageHandler.name),
291 pluginsMojom.PluginsPageHandler); 284 pluginsMojom.PluginsPageHandler);
292 285
293 // Connect pipe handle to JS code. 286 /** @constructor */
294 var pipe = core.createMessagePipe(); 287 var PluginsPageImpl = function() {};
295 pluginsPageStub = connection.bindHandleToStub(
296 pipe.handle0, pluginsMojom.PluginsPage);
297 288
298 pageProxy = { 289 PluginsPageImpl.prototype = {
299 __proto__: pluginsMojom.PluginsPage.stubClass.prototype, 290 __proto__: pluginsMojom.PluginsPage.stubClass.prototype,
291
292 /** @override */
300 onPluginsUpdated: function(plugins) { 293 onPluginsUpdated: function(plugins) {
301 returnPluginsData({plugins: plugins}); 294 returnPluginsData({plugins: plugins});
302 }, 295 },
303 }; 296 };
297 pageImpl = new PluginsPageImpl();
304 298
305 bindings.StubBindings(pluginsPageStub).delegate = pageProxy; 299 // Create a message pipe, with one end of the pipe already connected to JS.
306 // Send pipe handle to C++. 300 var handle = connection.bindStubDerivedImpl(pageImpl);
307 browserProxy.setClientPage(pipe.handle1); 301 // Send the other end of the pipe to C++.
302 browserProxy.setClientPage(handle);
308 }); 303 });
309 } 304 }
310 305
311 /** 306 /**
312 * Overriden by tests to give them a chance to setup a fake Mojo browser proxy 307 * Overriden by tests to give them a chance to setup a fake Mojo browser proxy
313 * before any other code executes. 308 * before any other code executes.
314 * @return {!Promise} A promise firing once necessary setup has been completed. 309 * @return {!Promise} A promise firing once necessary setup has been completed.
315 */ 310 */
316 var setupFn = setupFn || function() { return Promise.resolve(); }; 311 var setupFn = setupFn || function() { return Promise.resolve(); };
317 312
(...skipping 16 matching lines...) Expand all
334 329
335 // Unfortunately, we don't have notifications for plugin (list) status 330 // Unfortunately, we don't have notifications for plugin (list) status
336 // changes (yet), so in the meanwhile just update regularly. 331 // changes (yet), so in the meanwhile just update regularly.
337 setInterval(function() { 332 setInterval(function() {
338 browserProxy.getPluginsData().then(returnPluginsData); 333 browserProxy.getPluginsData().then(returnPluginsData);
339 }, 30000); 334 }, 30000);
340 }); 335 });
341 } 336 }
342 337
343 document.addEventListener('DOMContentLoaded', main); 338 document.addEventListener('DOMContentLoaded', main);
OLDNEW
« no previous file with comments | « no previous file | chrome/test/data/webui/plugins_browsertest.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698