Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 393036

Summary: Opening a window from a plug-in
Product: [ECD] Orion Reporter: Szymon Brandys <Szymon.Brandys>
Component: ClientAssignee: Szymon Brandys <Szymon.Brandys>
Status: RESOLVED FIXED QA Contact:
Severity: normal    
Priority: P3 CC: eclipse, ken_walker, malgorzata.tomczyk, mamacdon, simon_kaegi, susan
Version: 1.0   
Target Milestone: 4.0 M1   
Hardware: All   
OS: All   
Whiteboard:

Description Szymon Brandys CLA 2012-10-29 09:30:00 EDT
This came up when trying to integrate Google Picker with Orion during Orion Hackathon in Krakow. Guys were trying to add an action to html editor that would open Google Picker. Then when something was selected, it would insert a relevant HTML code to the editor.

The problem was that the plug-in can not open any window. They had to disable sandboxing to proceed.
Comment 1 Szymon Brandys CLA 2012-11-06 08:58:18 EST
Commands support callback or hrefCallback. Could they also support returning url of UI, let's call it uiCallback? uiCallback would return a url for Orion to open within an IFrame in a modal dialog.

I could imagine orion.edit.command plugged in this way. It would return url to open in an IFrame. When the editor action is triggered, the url is returned and Orion opens it in a modal dialog. At the end, a message is posted that can be understood only by orion.edit.command handler and Orion closes the dialog.

Can't it work this way?
Comment 2 Susan McCourt CLA 2012-11-06 11:10:50 EST
The internal view of commands (callback, hrefcallback, etc.) will be affected, but I prefer to first focus on the plugin's view of the world.  Right now we have 
     run(selectedText, text, selection, resource)  
which returns an object with
and instead focus on the plugin API.  Right now we don't expose a uriTemplate at all in orion.edit.command so we have the ability
Comment 3 Susan McCourt CLA 2012-11-06 11:13:41 EST
(In reply to comment #2)
Sigh...somehow pushed the button before finishing.  Trying again:

> The internal view of commands (callback, hrefcallback, etc.) will be
> affected, but I prefer to first focus on the plugin's view of the world. 
> Right now we have 
>      run(selectedText, text, selection, resource)  
> which returns an object with
properties "text" and an optional "selection"

So I think that this method would need to take a new property, something like 
uiURITemplate???

Then internally we can make this work inside a modal popup, etc.
We may need additional attributes to control size or position, but we can try some defaults first.

The communication back to the editor from the delegated UI is something we should talk to Simon about.
Comment 4 Susan McCourt CLA 2012-11-08 16:04:47 EST
Szymon and I have been playing with the picker plugin.
We hacked together something that works in the editor, obviously it needs to be generalized.

The plugin is at 
https://raw.github.com/szbra/GPicker4OEdtr/poc/index.html

(this is the "poc" branch of this plugin)

Then you need to checkout the "delegatedUI" branch of org.eclipse.orion.client

Lots of hacks here but it demonstrates the basic premise.  To me the million dollar question is:

what is the shape of the API where the plugin says "hey host page, I have a result."  We implemented this with a raw post message that is handled in the editor page.  Instead I imagine that we have something like

provider.requestPageService("delegatedUIResult", {myResult: "foo", etc....});

This code would use a new plugin registry "method" called "pageService" to dispatch the request to some orion service.  I started hacking in plugin.js and pluginregistry.js to do it this way, but I could not figure out how the plugin registry would know about the service registry, and it seems to me that we need is communicate info from the plug-in to some in-page service.

This would make implementing the progress service trivial (bug 390708) and many other page services that we decided to expose.

Once we defined API for the notification, then we could generalize the delegated UI iframe creation so that it's not just in editor commands, but is actually some general service that can be requested anywhere.
Comment 5 Szymon Brandys CLA 2012-11-09 04:34:33 EST
I'm setting the target to 2.0M1 and I believe we can have something working by this date :)
Comment 6 Szymon Brandys CLA 2012-11-09 09:45:02 EST
(In reply to comment #4)
> This would make implementing the progress service trivial (bug 390708) and
> many other page services that we decided to expose.

See bug 390708, comment 7. I think we should re-think whether progress service should be exposed
in plug-ins or not.
Comment 7 Susan McCourt CLA 2012-11-15 12:01:07 EST
I talked to Simon about this.  He believes we don't need something as generic as what I said in comment 4.  We don't need a "talk to Orion service" api yet.  Instead, we will define the postMessage API that a delegated UI would use and beef up our listener so that we only listen to the iframes we know about.

(I had tried to do the latter with event.target.location but reaching into an iframe's properties is not allowed).

Simon is taking this bug for beefing up the listener and from there I will generalize/add some display properties to the service.
Comment 8 Szymon Brandys CLA 2012-11-16 03:57:52 EST
Great. Susan, when you start adding display properties, I'll update to GPicker example and rework other examples from Orion Hackathon.
Comment 9 Szymon Brandys CLA 2013-01-03 11:17:17 EST
(In reply to comment #8)
> Great. Susan, when you start adding display properties, I'll update to
> GPicker example and rework other examples from Orion Hackathon.

Simon, what do we do with it? I would like to rework other UI examples and document it in the wiki.
Comment 10 Susan McCourt CLA 2013-01-16 13:08:21 EST
per email discussion, I have updated the original proof of concept hack and pushed to master.  Commit is

http://git.eclipse.org/c/orion/org.eclipse.orion.client.git/commit/?id=1e98c7f1b0e68fb60fc26718db3a0389b94fe8bc

Some things to note:

- we decided that for now (2.0) we will only support delegated UI for editor commands, learn how it's working, and then consider generalizing it later.  So for now the implementation is in editorCommands vs. being in some generic module.

- the picker example doesn't care about the selected text, text content, etc.  So this proof of concept hack does not pass any of that information to the iframe.  Simon and I discussed that a better way to do this might be to have the service.run implementation provide the uriTemplate (rather than a service property) so that it could build a URI that includes contextual information about the selection, etc if needed by the UI.  That means we would always call service.run and then check for a uriTemplate passed back instead of a result.  I will wait to hear from Szymon whether this is needed by any of the examples.

- still needs some polish by Simon as far as having a secure message listener.
Comment 11 Susan McCourt CLA 2013-01-16 13:14:55 EST
Also, as discussed in comment 8, we might want some properties to help determine the preferred size of the iframe.  I considered positioning the iframe relative to selected text, but that might not be good for a larger iframe.   Something to think about.  I will assume Szymon will drive the requirements here based on hackathon examples.  Just let me know what is needed.
Comment 12 Szymon Brandys CLA 2013-01-17 08:25:41 EST
(In reply to comment #11)
> Also, as discussed in comment 8, we might want some properties to help
> determine the preferred size of the iframe.  I considered positioning the
> iframe relative to selected text, but that might not be good for a larger
> iframe.   Something to think about.  I will assume Szymon will drive the
> requirements here based on hackathon examples.  Just let me know what is
> needed.

Properties like preferred size would be good to have. Also the picker example doesn't care about the selected text just because we did not have that at the time it was made. If we could pass the selected text, the picker could be populated with the selected text on show.
Comment 13 Susan McCourt CLA 2013-01-18 10:38:08 EST
Simon has cleaned up iframe creation and listener removal.  I'll take this bug now and change the flow so that the run method gets the uritemplate of the delegated UI rather than ahead of time.  This way, the plugin could decide to build selection or content info into the iframe's URL.
Comment 14 Susan McCourt CLA 2013-01-18 11:50:46 EST
http://git.eclipse.org/c/orion/org.eclipse.orion.client.git/commit/?id=2a8bf65768a3ff48b4545e0d262b4a63fda2626f

This commit moves the uri retrieval to the service implementation and allows width and height properties.  I updated the google picker poc branch to use the new API.  However I'm having a problem testing it, the service.run method never runs, and I got lost in the bowels of the plugin startup sequence events.  Szymon said he'd look at the plugin.
Comment 15 Susan McCourt CLA 2013-01-18 12:18:36 EST
Updated doc in
http://wiki.eclipse.org/Orion/Documentation/Developer_Guide/Plugging_into_the_editor#orion.edit.command

However we should eventually point to a full example from this doc.  Szymon is going to work on this.  Moving bug to Szymon for now.
Comment 16 Szymon Brandys CLA 2013-01-24 08:50:29 EST
Examples will be ready by RC1.
Comment 17 Szymon Brandys CLA 2013-02-05 10:09:10 EST
I fixed the problem in editorCommands.js and now it works for me. I will update the doc and write a blog post about this new cool thing. Thanks!
Comment 18 Szymon Brandys CLA 2013-02-06 06:21:28 EST
I made some further changes to the plug-in. Now the welcome page allows to install the plug-in into OrionHub or provided Orion instance.
Moreover the picker is populated with editor selection.
Comment 19 Susan McCourt CLA 2013-02-06 09:54:21 EST
(In reply to comment #18)
> I made some further changes to the plug-in. Now the welcome page allows to
> install the plug-in into OrionHub or provided Orion instance.
> Moreover the picker is populated with editor selection.

cool!
Comment 20 Szymon Brandys CLA 2013-02-06 10:47:29 EST
I added a link to the example and its source code here http://wiki.eclipse.org/Orion/Documentation/Developer_Guide/Plugging_into_the_editor#Google_Picker_example

Feel free to change/update.
Comment 21 Szymon Brandys CLA 2014-04-28 06:42:23 EDT
Fixed.