You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@pivot.apache.org by Greg Brown <gk...@mac.com> on 2009/03/15 18:00:54 UTC

Pivot/DOM interaction

Hi Noel,

Sorry for the delay in responding to your message - it was posted to the user mailing list before we had subscribed.  :-)

> A couple of topics I find interesting:
> Topic #1: How might Pivot manipulate the DOM for the page on which it sits?

This can be done via LiveConnect, which is a feature of the Java plugin. Prior to J6u10, it wasn't universally supported, but now is. 

We had previously exposed LiveConnect via a static eval() method in the pivot.wtk.BrowserApplicationContext class, but this was problematic because only one applet instance could set the static member that provided access to LiveConnect. As a result, all applets from the same origin would appear to be running within the same page. Since this isn't necessarily true, behavior would be ambiguous, and we removed the feature.

However, I can think of a couple workarounds:

1) Pass some reference to LiveConnect directly to the application (non-static). For example, we could add a non-static, abstract eval() method to ApplicationContext and pass the application context to the application. However, this would be a no-op for DesktopApplicationContext, which could be confusing. 

A better approach along these lines might be to pass a "page context" object to the application. DesktopApplicationContext could pass null, and BrowserApplicationContext could pass an inner class instance that delegated to the applet itself. If the page context is null, it would be clear that the application is not running in a browser and doesn't have access to the DOM.

2) Revert to the static approach and require the applet to set the separate_jvm parameter to true. This parameter requires J6u10, but since LiveConnect isn't reliably supported in prior releases anyways, it is arguably OK. This way, there would be no ambiguity about which page the application is running in.

Thoughts?

> Topic #2: How might Pivot respond to JavaScript events on its page?

I think Todd did some prototyping in this area - Todd, can you comment on this one?

Greg



Re: Pivot/DOM interaction

Posted by Greg Brown <gk...@mac.com>.
>2) Revert to the static approach and require the applet to set the separate_jvm parameter to true. This parameter requires J6u10, but since LiveConnect isn't reliably supported in prior releases anyways, it is arguably OK. This way, there would be no ambiguity about which page the application is running in.

I think this approach is probably the cleanest and have implemented it as described. Unless there are any significant objections, I'll go ahead and check it in.

G



Re: Pivot/DOM interaction

Posted by Greg Brown <gk...@mac.com>.
>adding a
>getApplication() method would be trivial, which would then give you a
>hook into your your application's API.  Greg's in that class now --
>Greg, you want to add that method?

Done.



Re: Pivot/DOM interaction

Posted by Todd Volkert <tv...@gmail.com>.
>> Topic #2: How might Pivot respond to JavaScript events on its page?
>
> I think Todd did some prototyping in this area - Todd, can you comment on this one?
>

This is super simple (again, with 6u10, it becomes reliable enough to
use) -- you just obtain a JS reference to the <applet> DOM object,
then you can access any public API of the associated applet Java
instance.  In Pivot, this will be an instance of
pivot.wtk.BrowserApplicationContext$HostApplet.  Right now, the
HostApplet class doesn't provide anything interesting, but adding a
getApplication() method would be trivial, which would then give you a
hook into your your application's API.  Greg's in that class now --
Greg, you want to add that method?

-T

Re: Pivot/DOM interaction

Posted by Todd Volkert <tv...@gmail.com>.
>> Topic #2: How might Pivot respond to JavaScript events on its page?
>
> I think Todd did some prototyping in this area - Todd, can you comment on this one?
>

This is super simple (again, with 6u10, it becomes reliable enough to
use) -- you just obtain a JS reference to the <applet> DOM object,
then you can access any public API of the associated applet Java
instance.  In Pivot, this will be an instance of
pivot.wtk.BrowserApplicationContext$HostApplet.  Right now, the
HostApplet class doesn't provide anything interesting, but adding a
getApplication() method would be trivial, which would then give you a
hook into your your application's API.  Greg's in that class now --
Greg, you want to add that method?

-T

Re: Pivot/DOM interaction

Posted by Greg Brown <gk...@mac.com>.
>> A better approach along these lines might be to pass a "page context"
>> object to the application.
>
> I prefer something along these lines, and would like to suggest the  
> use of a
> annotation.

Interesting, though I'm having trouble visualizing how annotations  
might be used here. Do you have any thoughts on what such an  
annotation might look like?


RE: Pivot/DOM interaction

Posted by "Noel J. Bergman" <no...@devtech.com>.
Greg,

> Sorry for the delay in responding to your message

No worries.  :-)

> > Topic #1: How might Pivot manipulate the DOM for the page on which it
sits?

> This can be done via LiveConnect, which is a feature of the Java plugin.
> Prior to J6u10, it wasn't universally supported, but now is.

I am looking at https://jdk6.dev.java.net/plugin2/liveconnect/ now.  Good to
see that this is no longer non-portable.

> We had previously exposed LiveConnect via a static eval() method
> in the pivot.wtk.BrowserApplicationContext class, but this was
> problematic because only one applet instance could set the static
> member that provided access to LiveConnect.

> However, I can think of a couple workarounds

> 1) Pass some reference to LiveConnect directly to the application

> A better approach along these lines might be to pass a "page context"
> object to the application.

I prefer something along these lines, and would like to suggest the use of a
annotation.

> 2) Revert to the static approach and require the applet to set the
> separate_jvm parameter to true.

Again, I'd prefer to see an annotation supported approach, and not a static
method.

> > Topic #2: How might Pivot respond to JavaScript events on its page?
> I think Todd did some prototyping in this area

Again, as I've started to think about it, there might be some very cool
analogies to what we have in JSR-286 in the way of annotation-based
programming.

	--- Noel