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

Issue 637373002: Mojo JS bindings: simplify mojo.connectToService() usage - Part 2 (Closed)

Created:
6 years, 2 months ago by hansmuller
Modified:
6 years, 2 months ago
CC:
abarth-chromium, Aaron Boodman, ben+mojo_chromium.org, chromium-reviews, darin (slow to review), qsr+mojo_chromium.org, raymes, Sam McNally, viettrungluu+watch_chromium.org, yzshen+watch_chromium.org
Base URL:
https://chromium.googlesource.com/chromium/src.git@master
Project:
chromium
Visibility:
Public.

Description

Mojo JS bindings: simplify mojo.connectToService() usage - Part 2 This is the final step towards the goals listed in crbug.com/419160. It builds on https://codereview.chromium.org/628763002. The trivial NativeViewport application listed there can now be written relatively simply: define("test", [ "mojo/services/public/interfaces/geometry/geometry.mojom", "mojo/services/public/interfaces/native_viewport/native_viewport.mojom", "mojo/apps/js/mojo", "console", ], function(geometry, viewport, mojo, console) { var client = { onDestroyed: mojo.quit, onEvent: function(event) { console.log("event.type=" + event.action); return Promise.resolve(); // This just gates the next event delivery }, }; var viewport = mojo.connectToService( "mojo:mojo_native_viewport_service", viewport.NativeViewport, client); viewport.create(new geometry.Size({width: 256, height: 256})); viewport.show(); }); The mojo connectToService() function now just returns a proxy to the remote interface. The 3rd (optional) connectToService() parameter is an object that implements the client interface for the remote interface. In this version the NativeViewportClient interface implementation is just an object with function properties whose names match the interface. Subclassing isn't needed and it's not necessary to implement all of the client functions. The Mojo JS bindings now generate a subclass of each FooStub class called DelegatingFooStub. The Delegating version just forwards the Stub methods to the value of |this.delegate$|. The ugly "$" suffix avoids collisions with mojom function names. The JS bindings' interface Foo object now includes a delegatingStubClass property whose value is FooDelegatingStub. |mojo.connectToService(url, Foo, client)| only uses Foo.client.delegatingStubClass if a client is specified. The mojo_module has been split into two: a native part, called MojoInternalsModule, which integrates with JSApp, and a JavaScript part that depends on the internals. Apps must now import "mojo/apps/js/mojo", rather than just "mojo". For now, quit and connectToService() are the only functions in the JS mojo module. BUG=419160 Committed: https://crrev.com/76a748ae224d7e646971af023ac6e6b93cdb0a47 Cr-Commit-Position: refs/heads/master@{#299197}

Patch Set 1 : #

Total comments: 6

Patch Set 2 : Renamed the mojo_internals module, made Connection localFactory optional #

Unified diffs Side-by-side diffs Delta from patch set Stats (+89 lines, -102 lines) Patch
M mojo/apps/js/BUILD.gn View 1 1 chunk +1 line, -1 line 0 comments Download
M mojo/apps/js/application_delegate_impl.cc View 1 1 chunk +1 line, -1 line 0 comments Download
M mojo/apps/js/js_app.h View 1 1 chunk +1 line, -1 line 0 comments Download
M mojo/apps/js/js_app.cc View 1 2 chunks +3 lines, -3 lines 0 comments Download
M mojo/apps/js/main.js View 1 chunk +15 lines, -15 lines 0 comments Download
A mojo/apps/js/mojo.js View 1 1 chunk +26 lines, -0 lines 0 comments Download
A + mojo/apps/js/mojo_bridge_module.h View 1 1 chunk +4 lines, -1 line 0 comments Download
A + mojo/apps/js/mojo_bridge_module.cc View 1 2 chunks +4 lines, -5 lines 0 comments Download
D mojo/apps/js/mojo_module.h View 1 chunk +0 lines, -25 lines 0 comments Download
D mojo/apps/js/mojo_module.cc View 1 chunk +0 lines, -47 lines 0 comments Download
M mojo/mojo_apps.gypi View 1 1 chunk +1 line, -1 line 0 comments Download
M mojo/public/js/bindings/connection.js View 1 1 chunk +2 lines, -2 lines 0 comments Download
M mojo/public/tools/bindings/generators/js_templates/interface_definition.tmpl View 2 chunks +19 lines, -0 lines 0 comments Download
M mojo/public/tools/bindings/generators/js_templates/module.js.tmpl View 1 chunk +2 lines, -0 lines 0 comments Download
M mojo/public/tools/bindings/generators/mojom_js_generator.py View 2 chunks +10 lines, -0 lines 0 comments Download

Messages

Total messages: 9 (3 generated)
hansmuller
This patch automatically creates a Mojo client interface stub object that forwards to a user-supplied ...
6 years, 2 months ago (2014-10-09 18:09:25 UTC) #3
abarth-chromium
lgtm https://codereview.chromium.org/637373002/diff/20001/mojo/apps/js/mojo.js File mojo/apps/js/mojo.js (right): https://codereview.chromium.org/637373002/diff/20001/mojo/apps/js/mojo.js#newcode13 mojo/apps/js/mojo.js:13: (client && service.client.delegatingStubClass) || function(){}; var clientClass = ...
6 years, 2 months ago (2014-10-10 17:45:07 UTC) #4
hansmuller
Thanks for the review. https://codereview.chromium.org/637373002/diff/20001/mojo/apps/js/mojo.js File mojo/apps/js/mojo.js (right): https://codereview.chromium.org/637373002/diff/20001/mojo/apps/js/mojo.js#newcode13 mojo/apps/js/mojo.js:13: (client && service.client.delegatingStubClass) || function(){}; ...
6 years, 2 months ago (2014-10-10 20:53:48 UTC) #5
commit-bot: I haz the power
CQ is trying da patch. Follow status at https://chromium-cq-status.appspot.com/patch-status/637373002/190001
6 years, 2 months ago (2014-10-10 20:55:24 UTC) #7
commit-bot: I haz the power
Committed patchset #2 (id:190001)
6 years, 2 months ago (2014-10-10 21:52:07 UTC) #8
commit-bot: I haz the power
6 years, 2 months ago (2014-10-10 21:52:45 UTC) #9
Message was sent while issue was closed.
Patchset 2 (id:??) landed as
https://crrev.com/76a748ae224d7e646971af023ac6e6b93cdb0a47
Cr-Commit-Position: refs/heads/master@{#299197}

Powered by Google App Engine
This is Rietveld 408576698