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

Issue 6716005: A proposal and implementation for an initial postMessage interface. These in... (Closed)

Created:
9 years, 9 months ago by dmichael(do not use this one)
Modified:
9 years, 7 months ago
CC:
chromium-reviews, darin-cc_chromium.org
Visibility:
Public.

Description

A proposal and implementation for an initial postMessage interface. These interfaces will allow JavaScript to send data asynchronously to a module instance, and the module instance to asynchronously send data to a JavaScript message handler. Note, I did something differently from other per-instance interfaces. While the C interface has 'PPB_Messaging' and 'PPP_Messaging' separate from the Instance interfaces, I stuck the per-instance messaging in to pp::Instance. It seems more intuitive to me, and doesn't have the drawbacks of having too many functions in the C layer instance interfaces. Happy to back off of that position, but it's worth a shot. Overview: From JavaScript, you can invoke 'postMessage' on the embedded module. That results in a call to 'PPP_Messaging::HandleMessage'. From Native Code, you can invoke 'PPB_Messaging::PostMessage', which results in a call to an 'onmessage' function on the DOM element for the module instance in the JavaScript code (if one has been registered). Please see the included example or the examples in the comments of PPB_Messaging and PPP_Messaging. Restrictions: - This implementation is synchronous. A later CL will make it asynchronous. - This implementation supports only intrinsic values and strings (all types that PP_Var supports except for objects). Object & array support will come later. - This implementation only allows for 1 channel per instance. You can not expose other 'channels' or 'ports'. Future CLs will add support for MessagePorts. BUG=None TEST=test_post_message.h/.cc (This CL replaces http://codereview.chromium.org/6538028/ ) Committed: http://src.chromium.org/viewvc/chrome?view=rev&revision=79178

Patch Set 1 : '' #

Total comments: 23

Patch Set 2 : '' #

Total comments: 36

Patch Set 3 : '' #

Total comments: 22

Patch Set 4 : '' #

Total comments: 3
Unified diffs Side-by-side diffs Delta from patch set Stats (+1090 lines, -19 lines) Patch
A ppapi/c/dev/ppb_messaging_dev.h View 1 2 3 1 chunk +82 lines, -0 lines 0 comments Download
A ppapi/c/dev/ppp_messaging_dev.h View 1 2 3 1 chunk +63 lines, -0 lines 0 comments Download
M ppapi/cpp/instance.h View 1 2 1 chunk +10 lines, -0 lines 2 comments Download
M ppapi/cpp/instance.cc View 1 4 chunks +16 lines, -0 lines 0 comments Download
M ppapi/cpp/module.cc View 1 3 chunks +18 lines, -0 lines 0 comments Download
A ppapi/examples/scripting/post_message.cc View 1 chunk +57 lines, -0 lines 0 comments Download
A ppapi/examples/scripting/post_message.html View 1 2 3 1 chunk +50 lines, -0 lines 0 comments Download
M ppapi/ppapi_cpp.gypi View 1 2 chunks +2 lines, -0 lines 0 comments Download
M ppapi/ppapi_tests.gypi View 1 2 chunks +11 lines, -0 lines 0 comments Download
M ppapi/tests/test_case.h View 1 4 chunks +16 lines, -4 lines 0 comments Download
M ppapi/tests/test_case.cc View 1 1 chunk +2 lines, -0 lines 0 comments Download
A ppapi/tests/test_post_message.h View 1 chunk +53 lines, -0 lines 0 comments Download
A ppapi/tests/test_post_message.cc View 1 2 3 1 chunk +166 lines, -0 lines 0 comments Download
M ppapi/tests/testing_instance.h View 1 4 chunks +9 lines, -4 lines 0 comments Download
M ppapi/tests/testing_instance.cc View 1 5 chunks +11 lines, -6 lines 0 comments Download
M webkit/glue/webkit_glue.gypi View 1 1 chunk +2 lines, -0 lines 0 comments Download
A webkit/plugins/ppapi/message_channel.h View 1 1 chunk +93 lines, -0 lines 0 comments Download
A webkit/plugins/ppapi/message_channel.cc View 1 1 chunk +350 lines, -0 lines 0 comments Download
M webkit/plugins/ppapi/plugin_module.cc View 1 2 chunks +3 lines, -0 lines 0 comments Download
M webkit/plugins/ppapi/ppapi_plugin_instance.h View 1 2 7 chunks +19 lines, -0 lines 0 comments Download
M webkit/plugins/ppapi/ppapi_plugin_instance.cc View 1 2 11 chunks +48 lines, -2 lines 0 comments Download
M webkit/plugins/ppapi/ppapi_webplugin_impl.cc View 1 2 chunks +9 lines, -3 lines 1 comment Download

Messages

Total messages: 17 (0 generated)
dmichael(do not use this one)
9 years, 9 months ago (2011-03-21 21:44:13 UTC) #1
brettw
http://codereview.chromium.org/6716005/diff/8001/ppapi/tests/test_post_message.cc File ppapi/tests/test_post_message.cc (right): http://codereview.chromium.org/6716005/diff/8001/ppapi/tests/test_post_message.cc#newcode16 ppapi/tests/test_post_message.cc:16: namespace { Blank lines on both sides of namespace ...
9 years, 9 months ago (2011-03-22 05:59:11 UTC) #2
dmichael(do not use this one)
http://codereview.chromium.org/6716005/diff/8001/ppapi/tests/test_post_message.cc File ppapi/tests/test_post_message.cc (right): http://codereview.chromium.org/6716005/diff/8001/ppapi/tests/test_post_message.cc#newcode16 ppapi/tests/test_post_message.cc:16: namespace { On 2011/03/22 05:59:11, brettw wrote: > Blank ...
9 years, 9 months ago (2011-03-22 15:39:00 UTC) #3
brettw
http://codereview.chromium.org/6716005/diff/118/webkit/plugins/ppapi/ppapi_plugin_instance.cc File webkit/plugins/ppapi/ppapi_plugin_instance.cc (right): http://codereview.chromium.org/6716005/diff/118/webkit/plugins/ppapi/ppapi_plugin_instance.cc#newcode877 webkit/plugins/ppapi/ppapi_plugin_instance.cc:877: static bool checked_interface(false); This won't work since there can ...
9 years, 9 months ago (2011-03-22 21:39:06 UTC) #4
dmichael(do not use this one)
http://codereview.chromium.org/6716005/diff/118/webkit/plugins/ppapi/ppapi_plugin_instance.cc File webkit/plugins/ppapi/ppapi_plugin_instance.cc (right): http://codereview.chromium.org/6716005/diff/118/webkit/plugins/ppapi/ppapi_plugin_instance.cc#newcode877 webkit/plugins/ppapi/ppapi_plugin_instance.cc:877: static bool checked_interface(false); On 2011/03/22 21:39:06, brettw wrote: > ...
9 years, 9 months ago (2011-03-22 21:59:01 UTC) #5
polina
Thanks for moving this to a separate interface. http://codereview.chromium.org/6716005/diff/118/ppapi/c/dev/ppb_messaging_dev.h File ppapi/c/dev/ppb_messaging_dev.h (right): http://codereview.chromium.org/6716005/diff/118/ppapi/c/dev/ppb_messaging_dev.h#newcode13 ppapi/c/dev/ppb_messaging_dev.h:13: #define ...
9 years, 9 months ago (2011-03-22 22:00:59 UTC) #6
brettw
http://codereview.chromium.org/6716005/diff/118/ppapi/c/dev/ppb_messaging_dev.h File ppapi/c/dev/ppb_messaging_dev.h (right): http://codereview.chromium.org/6716005/diff/118/ppapi/c/dev/ppb_messaging_dev.h#newcode31 ppapi/c/dev/ppb_messaging_dev.h:31: * @a PostMessage is a pointer to a function ...
9 years, 9 months ago (2011-03-23 01:59:17 UTC) #7
dmichael(do not use this one)
http://codereview.chromium.org/6716005/diff/118/ppapi/c/dev/ppb_messaging_dev.h File ppapi/c/dev/ppb_messaging_dev.h (right): http://codereview.chromium.org/6716005/diff/118/ppapi/c/dev/ppb_messaging_dev.h#newcode13 ppapi/c/dev/ppb_messaging_dev.h:13: #define PPB_MESSAGING_DEV_INTERFACE PPB_MESSAGING_DEV_INTERFACE_0_1 On 2011/03/22 22:00:59, polina wrote: > ...
9 years, 9 months ago (2011-03-23 17:03:18 UTC) #8
neb
http://codereview.chromium.org/6716005/diff/20015/ppapi/c/dev/ppb_messaging_dev.h File ppapi/c/dev/ppb_messaging_dev.h (right): http://codereview.chromium.org/6716005/diff/20015/ppapi/c/dev/ppb_messaging_dev.h#newcode13 ppapi/c/dev/ppb_messaging_dev.h:13: #define PPB_MESSAGING_DEV_INTERFACE PPB_MESSAGING_DEV_INTERFACE_0_1 I agree with Polina - I'm ...
9 years, 9 months ago (2011-03-23 17:45:30 UTC) #9
brettw
http://codereview.chromium.org/6716005/diff/20015/ppapi/c/dev/ppb_messaging_dev.h File ppapi/c/dev/ppb_messaging_dev.h (right): http://codereview.chromium.org/6716005/diff/20015/ppapi/c/dev/ppb_messaging_dev.h#newcode13 ppapi/c/dev/ppb_messaging_dev.h:13: #define PPB_MESSAGING_DEV_INTERFACE PPB_MESSAGING_DEV_INTERFACE_0_1 Let's change this in a separate ...
9 years, 9 months ago (2011-03-23 17:51:39 UTC) #10
dmichael(do not use this one)
http://codereview.chromium.org/6716005/diff/20015/ppapi/c/dev/ppb_messaging_dev.h File ppapi/c/dev/ppb_messaging_dev.h (right): http://codereview.chromium.org/6716005/diff/20015/ppapi/c/dev/ppb_messaging_dev.h#newcode13 ppapi/c/dev/ppb_messaging_dev.h:13: #define PPB_MESSAGING_DEV_INTERFACE PPB_MESSAGING_DEV_INTERFACE_0_1 On 2011/03/23 17:51:39, brettw wrote: > ...
9 years, 9 months ago (2011-03-23 18:48:04 UTC) #11
neb
LGTM. I'll take my documentation beef up with the doc team, it's in shambles as ...
9 years, 9 months ago (2011-03-23 20:14:30 UTC) #12
polina
http://codereview.chromium.org/6716005/diff/118/ppapi/c/dev/ppb_messaging_dev.h File ppapi/c/dev/ppb_messaging_dev.h (right): http://codereview.chromium.org/6716005/diff/118/ppapi/c/dev/ppb_messaging_dev.h#newcode13 ppapi/c/dev/ppb_messaging_dev.h:13: #define PPB_MESSAGING_DEV_INTERFACE PPB_MESSAGING_DEV_INTERFACE_0_1 On 2011/03/23 17:03:18, dmichael wrote: > ...
9 years, 9 months ago (2011-03-24 05:42:33 UTC) #13
dmichael(do not use this one)
http://codereview.chromium.org/6716005/diff/118/ppapi/c/dev/ppb_messaging_dev.h File ppapi/c/dev/ppb_messaging_dev.h (right): http://codereview.chromium.org/6716005/diff/118/ppapi/c/dev/ppb_messaging_dev.h#newcode13 ppapi/c/dev/ppb_messaging_dev.h:13: #define PPB_MESSAGING_DEV_INTERFACE PPB_MESSAGING_DEV_INTERFACE_0_1 On 2011/03/24 05:42:33, polina wrote: > ...
9 years, 9 months ago (2011-03-25 20:21:05 UTC) #14
piman
http://codereview.chromium.org/6716005/diff/21015/webkit/plugins/ppapi/ppapi_webplugin_impl.cc File webkit/plugins/ppapi/ppapi_webplugin_impl.cc (right): http://codereview.chromium.org/6716005/diff/21015/webkit/plugins/ppapi/ppapi_webplugin_impl.cc#newcode101 webkit/plugins/ppapi/ppapi_webplugin_impl.cc:101: return instance_->message_channel().np_object(); Mmmh.... This CL is causing http://code.google.com/p/chromium-os/issues/detail?id=13605 to ...
9 years, 8 months ago (2011-03-29 04:40:22 UTC) #15
dmichael(do not use this one)
On Mon, Mar 28, 2011 at 10:40 PM, <piman@chromium.org> wrote: > > > http://codereview.chromium.org/6716005/diff/21015/webkit/plugins/ppapi/ppapi_webplugin_impl.cc > ...
9 years, 8 months ago (2011-03-29 16:07:03 UTC) #16
piman
9 years, 8 months ago (2011-03-29 16:28:19 UTC) #17
On Tue, Mar 29, 2011 at 9:06 AM, David Michael <dmichael@google.com> wrote:

>
>
> On Mon, Mar 28, 2011 at 10:40 PM, <piman@chromium.org> wrote:
>
>>
>>
>>
http://codereview.chromium.org/6716005/diff/21015/webkit/plugins/ppapi/ppapi_...
>> File webkit/plugins/ppapi/ppapi_webplugin_impl.cc (right):
>>
>>
>>
http://codereview.chromium.org/6716005/diff/21015/webkit/plugins/ppapi/ppapi_...
>> webkit/plugins/ppapi/ppapi_webplugin_impl.cc:101: return
>> instance_->message_channel().np_object();
>> Mmmh.... This CL is causing
>> http://code.google.com/p/chromium-os/issues/detail?id=13605 to appear.
>>
>> WebPluginImpl::scriptableObject is supposed to add a refcount to the
>> npobject (see the NPAPI implementation).
>>
>> The previous code was wrong, but worked because of 2 bugs and luck:
>> PluginObject::Create leaks a reference, and this function failed to add
>> one, and is called only once. It all cancels out.
>> Unfortunately the new code passes an object on which a reference is
>> never added,
>
> See MessageChannel's constructor, where WebBindings::createObject is
> called.  That initializes the reference count to 1.  So we need to also
> increment it when scriptableObject is called, to get the ref count up to 2?
>
>

Yes. WebKit will release() the np object you return.


> My intent was for MessageChannel's np_object_ to be retained as long as the
> plugin instance is around.
>

Understood, and that's perfectly fine.

>
> so when the JS engine is done with it and garbage collects
>> it, it destroys it keeping garbage pointers all around.
>
> I didn't realize the JS engine could decide it was done with it while the
> plugin instance was still around.  Do you have any suggestions on how to
> reproduce this in an automated test?
>

Well it won't if the refcount is correct. Right now it is incorrect (missing
one ref) so when the JS engine releases its reference, the object goes away.

>
> Similarly, the instance's object's npobject doesn't get released any
>> more.
>
> Yeah, I fixed that in http://codereview.chromium.org/6733026/
>
> I meant what you call the "passthrough object"

>
>>
>> http://codereview.chromium.org/6716005/
>>
>
> While I do think it's my mistake, is it possible that the problem is
> actually in how I'm dealing with the passthrough_object_?  That's the object
> to which MessageChannel forwards all non-'postMessage' calls.  It occurs to
> me looking at the code that at the end of WebPluginImpl::scriptableObject,
> the scoped_refptr 'object' goes out of scope, so I think MessageChannel's
> passthrough_object_ is invalid.
>

It is not invalid because of the separate bug that leaks a reference in
PluginObject::Create. That needs to be fixed too, at which point you'll
indeed also have to retain/release the passthrough object.

>
> In any case, sorry for the rookie mistakes :-(
>

No worries, the code that was there before was also incorrect, it only
worked because of the combination of 2 bugs and luck.

>
> I'll work on an automated test to reproduce, to make sure I'm fixing it.
>

I don't know of any test. Writing one would be good. However it's slightly
tricky because it depends on the JS garbage collector to make sure WebKit
drops its own reference.


>   Or if you have really high confidence that it's just the need to retain
> MessageChannel's np_object(), I have a CL ready:
> http://codereview.chromium.org/6731051/
>

I added some comments there.

Antoine

Powered by Google App Engine
This is Rietveld 408576698