// my_custom_element.js
Polymer({
apiWrapper_: new FooPrivateApi(this),
...
doSomething_: function() { this.apiWrapper_.chromeDoSomething() },
myDelegateMethod1: function() {...},
myDelegateMethod2: function() {...},
});
// foo_private_api.js
var FooPrivateApi(delegate) {
this.delegate_ = delegate; // callback delegate
};
FooPrivateApi.prototype.chromeDoSomething = function() {
chrome.send('doSomething');
// C++ will call myDelegateMethod1, then myDelegateMethod2.
};
// Called from C++
FooPrivateApi.prototype.myDelegateMethod1 = function(result) {
this.myDelegateMethod1(result);
};
// Called from C++
FooPrivateApi.prototype.myDelegateMethod2 = function(result) {
this.myDelegateMethod2(result);
};
Thank you,Demetrios
Polymer({
properties: {
data: {
type: Array,
value: function() { return []; },
notify: true
},
},
loadData: function() {
chrome.send('data1');
},
// Called from C++
dataCallback(data) {
this.data = data;
},
});
To view this discussion on the web visit https://groups.google.com/a/chromium.org/d/msgid/chromium-settings/71ee3508-1f23-41d9-9d97-eedd1503bd20%40chromium.org.--
You received this message because you are subscribed to the Google Groups "Chromium Settings" group.
To unsubscribe from this group and stop receiving emails from it, send an email to chromium-setti...@chromium.org.
To post to this group, send email to chromium...@chromium.org.
To unsubscribe from this group and stop receiving emails from it, send an email to chromium-settings+unsubscribe@chromium.org.
Demetrios, what is the JS-end of the Mojo system likely to look like? Is there value it trying to make a wrapper that resembles using mojo (would it make it easier to switch later without being too cumbersome now)?
To unsubscribe from this group and stop receiving emails from it, send an email to chromium-setti...@chromium.org.
To view this discussion on the web visit https://groups.google.com/a/chromium.org/d/msgid/chromium-settings/71ee3508-1f23-41d9-9d97-eedd1503bd20%40chromium.org.
--
You received this message because you are subscribed to the Google Groups "Chromium Settings" group.
To unsubscribe from this group and stop receiving emails from it, send an email to chromium-setti...@chromium.org.
To view this discussion on the web visit https://groups.google.com/a/chromium.org/d/msgid/chromium-settings/d98896b2-96d4-4223-87bf-348ee255ce8f%40chromium.org.
To unsubscribe from this group and stop receiving emails from it, send an email to chromium-settings+unsubscribe@chromium.org.
To view this discussion on the web visit https://groups.google.com/a/chromium.org/d/msgid/chromium-settings/71ee3508-1f23-41d9-9d97-eedd1503bd20%40chromium.org.
--
You received this message because you are subscribed to the Google Groups "Chromium Settings" group.
To unsubscribe from this group and stop receiving emails from it, send an email to chromium-settings+unsubscribe@chromium.org.
To unsubscribe from this group and stop receiving emails from it, send an email to chromium-setti...@chromium.org.
To view this discussion on the web visit https://groups.google.com/a/chromium.org/d/msgid/chromium-settings/71ee3508-1f23-41d9-9d97-eedd1503bd20%40chromium.org.
--
You received this message because you are subscribed to the Google Groups "Chromium Settings" group.
To unsubscribe from this group and stop receiving emails from it, send an email to chromium-setti...@chromium.org.
To view this discussion on the web visit https://groups.google.com/a/chromium.org/d/msgid/chromium-settings/d98896b2-96d4-4223-87bf-348ee255ce8f%40chromium.org.
--
You received this message because you are subscribed to the Google Groups "Chromium Settings" group.
To unsubscribe from this group and stop receiving emails from it, send an email to chromium-setti...@chromium.org.
To post to this group, send email to chromium...@chromium.org.
To view this discussion on the web visit https://groups.google.com/a/chromium.org/d/msgid/chromium-settings/7c79e086-ec7f-4f42-9ddf-c92e494d5a86%40chromium.org.
// my_custom_element.jsPolymer({doSomething_: function() { this.apiWrapper_.chromeDoSomething() },myNativeMethod1: function(foo) {...},myNativeMethod2: function() {...},attached: function() {FooPrivateApi.nativeDelegate = this;},detached: function() {FooPrivateApi.nativeDelegate = null;},});// foo_private_api.jsFooPrivateApi.chromeDoSomething = function() {chrome.send('doSomething');// C++ will call myNativeMethod1, then myNativeMethod2.};/*** Defines Foo C++ => JS interface.* @public {{* myNativeMethod1: function(string),* myNativeMethod2: function(string, boolean),* }}*/FooPrivateApi.nativeDelegate = null;// foo_handler.ccCallJS("settings.FooPrivateApi.nativeDelegate.myNativeMethod1", args);
To unsubscribe from this group and stop receiving emails from it, send an email to chromium-setti...@chromium.org.
To view this discussion on the web visit https://groups.google.com/a/chromium.org/d/msgid/chromium-settings/71ee3508-1f23-41d9-9d97-eedd1503bd20%40chromium.org.
--
You received this message because you are subscribed to the Google Groups "Chromium Settings" group.
To unsubscribe from this group and stop receiving emails from it, send an email to chromium-setti...@chromium.org.
To view this discussion on the web visit https://groups.google.com/a/chromium.org/d/msgid/chromium-settings/d98896b2-96d4-4223-87bf-348ee255ce8f%40chromium.org.
Although I like Promises, I wonder if they are too incompatible with chrome.send to be used?Assuming you called:var promise1 = FooPrivateApi.doSomething();var promise2 = FooPrivateApi.doSomething();
FooPrivateApi would now have to store both promises. When the C++ calls JS, are the promises fulfilled FIFO or FILO?
To view this discussion on the web visit https://groups.google.com/a/chromium.org/d/msgid/chromium-settings/CAMWG5%3D73M%3Do-RstANuJsA8NF3Z%3DVz8EpDL6Npc2FTR1Z4re3tQ%40mail.gmail.com.
To unsubscribe from this group and stop receiving emails from it, send an email to chromium-settings+unsubscribe@chromium.org.
To view this discussion on the web visit https://groups.google.com/a/chromium.org/d/msgid/chromium-settings/71ee3508-1f23-41d9-9d97-eedd1503bd20%40chromium.org.
--
You received this message because you are subscribed to the Google Groups "Chromium Settings" group.
To unsubscribe from this group and stop receiving emails from it, send an email to chromium-settings+unsubscribe@chromium.org.
To unsubscribe from this group and stop receiving emails from it, send an email to chromium-setti...@chromium.org.
To view this discussion on the web visit https://groups.google.com/a/chromium.org/d/msgid/chromium-settings/71ee3508-1f23-41d9-9d97-eedd1503bd20%40chromium.org.
--
You received this message because you are subscribed to the Google Groups "Chromium Settings" group.
To unsubscribe from this group and stop receiving emails from it, send an email to chromium-setti...@chromium.org.
To view this discussion on the web visit https://groups.google.com/a/chromium.org/d/msgid/chromium-settings/d98896b2-96d4-4223-87bf-348ee255ce8f%40chromium.org.
--
You received this message because you are subscribed to the Google Groups "Chromium Settings" group.
To unsubscribe from this group and stop receiving emails from it, send an email to chromium-setti...@chromium.org.
To view this discussion on the web visit https://groups.google.com/a/chromium.org/d/msgid/chromium-settings/6889c9b7-1436-4332-a4f3-23c7f7688ed7%40chromium.org.
To view this discussion on the web visit https://groups.google.com/a/chromium.org/d/msgid/chromium-settings/CAMWG5%3D6c9d0KfHCPZ6aM-hnirzyYm1qLHdhU%2BX_GmKxL8AuCfw%40mail.gmail.com.
I've only been asking for this abstraction to make testing WebUI easier or possible (and hence, more prevalent).
I like Hector's proposal very much and the advantages that it brings (listed above). But I think we need to do something to support multiple elements using the API singleton.Right now I have an element implemented as per Hector's proposal. It works really well, but only because currently there is a *single* consumer of the API.I see this breaking down in at least two ways:Someone in the future adds another consumer to my API, perhaps unintentionally without realizing it by simply re-using my element. This would cause the |instance| variable to be overwritten in the singleton.
But there's a bigger issue, because in some cases we will need to support multiple instances, for example:In the near future I need to create a content_settings utility API that replaces my current usage of the |prefs| object (because we're supposed to go through the HostContentSettingsMap and not prefs, as per previous email to this group). I foresee those functions (being utility functions) will need to be re-usable between different Polymer elements so a single instance model won't cut it there.
I'll add some comments on Hector's proposal.On Wed, Jan 20, 2016 at 6:05 PM Tommy Li <tomm...@chromium.org> wrote:Hi Hector,I think I'm on board with your proposal. Your general pattern seems to be:<foo-element> embeds <foo-private-api-invisible-element> links itself to FooPrivateApi singleton right?If that's the case, that seems the most legit of the proposals so far.TommyOn Tue, Jan 19, 2016 at 6:56 PM, Hector Carmona <hcar...@chromium.org> wrote:I wanted to post a proof of concept for my proposal: http://crrev.com/1609923003Advantages of this approach:
- chrome.send and callbacks are in the same file
- no element needs to know about or register for the callbacks
- updates its own polymer settings, so we get callbacks in any element that wants to listen and no callbacks on elements that just want data to be bound w/o effort
- supports updating from c++ without calling the chrome.send for those places we need to refresh the user's data
- testing is easy because the api and objects that care about the data are completely decoupled
- when it's time to replace chrome.send with something else, all we have to do is replace the type of instance from the HTML.
On Tuesday, January 19, 2016 at 6:36:47 PM UTC-8, Rachel Blum wrote:On Tue, Jan 19, 2016 at 6:18 PM, Dan Beam <db...@chromium.org> wrote:I've only been asking for this abstraction to make testing WebUI easier or possible (and hence, more prevalent).
In that case, it'd be worth pointing out how individual proposals actually bring us closer to that goal, and how they differ in light of that goal.Also: how high is the price we'll pay for each solution? (IOW: If they're all roughly equal in cost, a mojo polyfill makes sense. If they aren't, "cheap" is a major factor, given this is an interim step)
--
You received this message because you are subscribed to the Google Groups "Chromium Settings" group.
To unsubscribe from this group and stop receiving emails from it, send an email to chromium-setti...@chromium.org.
To post to this group, send email to chromium...@chromium.org.
To view this discussion on the web visit https://groups.google.com/a/chromium.org/d/msgid/chromium-settings/CAB2L5-bvRGnM_VbFm9Wk7Z6_W68pw%2ByGMg0yTdVzWDSH5aLesQ%40mail.gmail.com.
To view this discussion on the web visit https://groups.google.com/a/chromium.org/d/msgid/chromium-settings/CACi5S_3bTB5BQoQ_h3BvWmSbu7vGDj8rqN1UQswWEe%2Bj33aZ2A%40mail.gmail.com.
To view this discussion on the web visit https://groups.google.com/a/chromium.org/d/msgid/chromium-settings/CANpe7K1B2yp-bL_aJP9GYSGe0yc5N-S0qgmR8%3Db9trqUsqgfQw%40mail.gmail.com.
FWIW, in favor:* Saves us from having to ship promises to C++* type safety right around the corner.* allows us to switch in mojo in a fairly straightforward way.* API is a pure controller, the underlying model is still separated out into cr.Send/extension APITwo questions:* TODO around aborting in-flight requests. Isn't promise.abort still open for debate? (https://github.com/promises-aplus/cancellation-spec/issues/14)
* How do we handle update notifications from the C++ side? (I.e. 'onFrobberChanged')
Seems like using it is fairly trivial as well, see your example's C++ counterpart. Dan, mind if your proposal included this?On Thu, Jan 28, 2016 at 4:55 PM, Demetrios Papadopoulos <dpa...@chromium.org> wrote:FWIW, there is this related helper function in cr.js . It is being used in one place from md-settings (guessing from the early days?), see example. Maybe we can revive that helper method and avoid the global callbacks all together? Not sure how much work is required on the c++ side though to make use of that helper.
Regarding cr.addWebUIListener, I am noticing that there is no equivalent removeWebUIListener, which I think is needed. For example when a sub-section that had registered a listener is closed, the listener should be removed.
If so, I suggest modifying addWebUIListener to return a value (numeric ID maybe?), that can be used to later remove the listener. Unregistering listeners by passing the listener function itself is very error prone (I've seen this happening a few times). Better explained with an example// Example1: Registered listener is NOT removed.addListener('some-event', myFunction.bind(this));...removeListener('some-event', myFunction.bind(this));The two calls above use a different function reference to each call, so removeEventListener() never finds the listener to be removed.
// Exmaple2: Registered listener removed, but not intuitive.var myListener = myFunction.bind(this);addListener('some-event', myListener);...removeListener('some-event', myListener);I think the more robust approach is the following// Example 3: Return an ID from addEventListener, used to later remove the listener.var listenerId = addEventListener('some-event', function() {...});...removeListener('some-event', listenerId);
FWIW, there is this related helper function in cr.js . It is being used in one place from md-settings (guessing from the early days?), see example. Maybe we can revive that helper method and avoid the global callbacks all together? Not sure how much work is required on the c++ side though to make use of that helper.
On Thu, Jan 28, 2016 at 4:50 PM, Rachel Blum <gr...@chromium.org> wrote:
I was thinking about observers, specifically. I.e. "onUpdated". I suppose a global + route_id will do. I'd love addObserver/registerCallback, but not sure it's worth the effort.
On Thu, Jan 28, 2016 at 4:46 PM, Dan Beam <db...@chromium.org> wrote:
On Thu, Jan 28, 2016 at 2:21 PM, Rachel Blum <gr...@chromium.org> wrote:FWIW, in favor:* Saves us from having to ship promises to C++* type safety right around the corner.* allows us to switch in mojo in a fairly straightforward way.* API is a pure controller, the underlying model is still separated out into cr.Send/extension APITwo questions:* TODO around aborting in-flight requests. Isn't promise.abort still open for debate? (https://github.com/promises-aplus/cancellation-spec/issues/14)We set a configurable timeout in JS and allow C++ to reject the held Promise faster. @interface returned Promises can detect these rejections with catch() as per their needs.* How do we handle update notifications from the C++ side? (I.e. 'onFrobberChanged')That's the "Response to a specific request -> no" branch from C++. If a purely C++ -> JS notification happens (that's not request-specific), a global JS name must be exposed to handle this. That global will need find it's own way to route the data (i.e. getting a reference from the DOM, finding a specific element to modify).
-- Dan
On Wed, Jan 27, 2016 at 7:50 PM, Dan Beam <db...@chromium.org> wrote:
Hey y'all,Here's what I propose to handle C++ <-> JS communication more robustly:
Is there any way to codify these strings so they can't be misspelled in JavaScript/C++, or left behind in JavaScript when the event is deleted from the C++ handler?
-- Dan
To unsubscribe from this group and stop receiving emails from it, send an email to chromium-settings+unsubscribe@chromium.org.
To post to this group, send email to chromium...@chromium.org.
To view this discussion on the web visit https://groups.google.com/a/chromium.org/d/msgid/chromium-settings/CAB2L5-bvRGnM_VbFm9Wk7Z6_W68pw%2ByGMg0yTdVzWDSH5aLesQ%40mail.gmail.com.
--
You received this message because you are subscribed to the Google Groups "Chromium Settings" group.
To unsubscribe from this group and stop receiving emails from it, send an email to chromium-settings+unsubscribe@chromium.org.
To view this discussion on the web visit https://groups.google.com/a/chromium.org/d/msgid/chromium-settings/CACi5S_3bTB5BQoQ_h3BvWmSbu7vGDj8rqN1UQswWEe%2Bj33aZ2A%40mail.gmail.com.
--
You received this message because you are subscribed to the Google Groups "Chromium Settings" group.
To unsubscribe from this group and stop receiving emails from it, send an email to chromium-settings+unsubscribe@chromium.org.
but repeating some strings across C++ and JS is not much different than our previous approach of calling JS functions by name from C++
Thank you,Demetrios
-- Dan
I like the use of cr.sendWithPromise and thought this matter was resolved. But from this CL, it looks like the strategy we are using now has an extra component:1. when your object/elements need to use cr.addWebUIListener, just call cr.addWebUIListener directly, as discussed
2. when your object/element needs to use chrome.send or cr.sendWithPromise, create a "proxy" for that element and wrap the calls in that proxy
With the rationale being:1. cr.addWebUIListener works fine in tests2. cr.sendWithPromise and chrome.send don't work well in testsWhy the distinction? If we are already comfortable having our tests "manually" trigger WebUI events, why should we write a standalone proxy every time we need to call chrome.send/cr.sendWithPromise?
Thank you,Demetrios
-- Dan
To unsubscribe from this group and stop receiving emails from it, send an email to chromium-settings+unsubscribe@chromium.org.
To post to this group, send email to chromium...@chromium.org.
To view this discussion on the web visit https://groups.google.com/a/chromium.org/d/msgid/chromium-settings/CAB2L5-bvRGnM_VbFm9Wk7Z6_W68pw%2ByGMg0yTdVzWDSH5aLesQ%40mail.gmail.com.
--
You received this message because you are subscribed to the Google Groups "Chromium Settings" group.
To unsubscribe from this group and stop receiving emails from it, send an email to chromium-settings+unsubscribe@chromium.org.
To view this discussion on the web visit https://groups.google.com/a/chromium.org/d/msgid/chromium-settings/CACi5S_3bTB5BQoQ_h3BvWmSbu7vGDj8rqN1UQswWEe%2Bj33aZ2A%40mail.gmail.com.
--
You received this message because you are subscribed to the Google Groups "Chromium Settings" group.
To unsubscribe from this group and stop receiving emails from it, send an email to chromium-settings+unsubscribe@chromium.org.