Bug 562049 - Some eclipse+command:// URI handler to use as link browsers and help
Summary: Some eclipse+command:// URI handler to use as link browsers and help
Status: RESOLVED FIXED
Alias: None
Product: Platform
Classification: Eclipse Project
Component: UI (show other bugs)
Version: 4.16   Edit
Hardware: All All
: P3 enhancement (vote)
Target Milestone: 4.16 M3   Edit
Assignee: Mickael Istria CLA
QA Contact:
URL:
Whiteboard:
Keywords: noteworthy
Depends on:
Blocks:
 
Reported: 2020-04-12 17:37 EDT by Mickael Istria CLA
Modified: 2020-04-22 16:32 EDT (History)
5 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Mickael Istria CLA 2020-04-12 17:37:20 EDT
Eclipse Help has the "internal" executeCommand(...) JavaScript function built-in to trigger commands from inside internal Eclipse Help. However, this doesn't work when using Help externally.
We could imagine Eclipse providing a handler for eclipse+command:// and allowing to register it with the OS. Then, help could be switched to this new URI form and when using Help from external web browser, the eclipse+command:// URI will be handled by the Eclipse IDE, detected by OS, starting or showing the Eclipse IDE and then running the command.
This eclipse+command:// URI handler could also be used to replace other formats like links in welcome page or to simplify integration with some JS-based UIs in RCP apps.
Comment 1 Rolf Theunissen CLA 2020-04-14 03:29:43 EDT
Would this impose an security issue? Could some 'bad' code be executed/inserted from any page opened in the browser?

Having such an URI handler for inside Eclipse could be useful though.
Comment 2 Mickael Istria CLA 2020-04-14 04:06:09 EDT
(In reply to Rolf Theunissen from comment #1)
> Would this impose an security issue? Could some 'bad' code be
> executed/inserted from any page opened in the browser?

Good point. So the URI handler should show a confirmation message then?
Comment 3 Eclipse Genie CLA 2020-04-17 10:59:16 EDT
New Gerrit change created: https://git.eclipse.org/r/161152
Comment 4 Matthias Becker CLA 2020-04-19 06:46:06 EDT
Regarding the discussion in Gerrit:

The UriHander stuff is not dependent on the IDE. *But* there's the preference page on which a user has to enable handling of a concrete URI scheme. This is IDE dependent. The reason for this is, that we only needed it there (at the time of development). I know that Oomph in the meantime also has link handler and needed to re-implement the enabling of that in Oomph's code. So maybe there is potential for re-use.
Comment 5 Matthias Becker CLA 2020-04-19 06:50:29 EDT
(In reply to Mickael Istria from comment #0)
> Eclipse Help has the "internal" executeCommand(...) JavaScript function
> built-in to trigger commands from inside internal Eclipse Help. However,
> this doesn't work when using Help externally.
> We could imagine Eclipse providing a handler for eclipse+command:// and
> allowing to register it with the OS. Then, help could be switched to this
> new URI form and when using Help from external web browser, the
> eclipse+command:// URI will be handled by the Eclipse IDE, detected by OS,
> starting or showing the Eclipse IDE and then running the command.
> This eclipse+command:// URI handler could also be used to replace other
> formats like links in welcome page or to simplify integration with some
> JS-based UIs in RCP apps.

Pls. keep in mind that only *one* application (os-wide) can handle an URI scheme. So if  a user has multiple eclipse based applications this will cause issues.
Also keep in mind that currently link handlers have to be enabled pro-actively by the user. So this will only work once the user has activated this on the link handlers pref page. The current JavaScript solution just works.

Also see this bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=537324

When multiple eclipse instances are running clicking on a link with such a URI scheme might end up in the wrong eclipse instance (that does not have the link handler at all)
Comment 6 Mickael Istria CLA 2020-04-19 07:38:12 EDT
(In reply to Matthias Becker from comment #4)
> Regarding the discussion in Gerrit:
> The UriHander stuff is not dependent on the IDE. *But* there's the
> preference page on which a user has to enable handling of a concrete URI
> scheme. This is IDE dependent. The reason for this is, that we only needed
> it there (at the time of development). I know that Oomph in the meantime
> also has link handler and needed to re-implement the enabling of that in
> Oomph's code. So maybe there is potential for re-use.

So do you think the handler should be defined in the org.eclipse.ui.workbench bundl? I'd be ok with that.

About the help, it's just one example of xhat such handler could enable as workflow, I don't plan changing help at the moment. Don't worry ;)
Another example can be, having a GitHub "badge" with "open in Eclipse IDE" referencing the EGit clone command, or to write documentation automatically opening the right preference page for users who'd allow that is great.
Comment 7 Alexander Fedorov CLA 2020-04-19 10:50:08 EDT
(In reply to Matthias Becker from comment #5)

> 
> Pls. keep in mind that only *one* application (os-wide) can handle an URI
> scheme. So if  a user has multiple eclipse based applications this will
> cause issues.

Great point, I totally missed that. Do we expect a user to have one and only one eclipse-based application installed? It is hardly possible to imagine.
Comment 8 Mickael Istria CLA 2020-04-19 11:00:11 EDT
(In reply to Alexander Fedorov from comment #7)
> Great point, I totally missed that. Do we expect a user to have one and only
> one eclipse-based application installed? It is hardly possible to imagine.

When opening an external link (eg a magnet://) from Firefox, I get a popup that let me chose which application should handle it. There is a default one, but I'm also free to pick some other one.
So I think the OS and browser seem to give the ability to select one application or another. So when bug 537324 gets fixed, users will be able to chose the application they want to run an eclipse+command:// link (not that your concerns are already try with mpc:// links).
I don't think this issue of selecting between multiple RCP apps shouldn't be seen as a blocker for the user story here.
Comment 9 Alexander Fedorov CLA 2020-04-19 11:23:04 EDT
(In reply to Mickael Istria from comment #6)
> 
> So do you think the handler should be defined in the
> org.eclipse.ui.workbench bundl? I'd be ok with that.
> 

Placing it to a bundle with name org.eclipse.e4.ui.* can make it available for more applications :)


Technically for command/handler execution it is enough to have it in org.eclipse.e4.core.*: 

	private Object executeCommand(String commandId, Map<String, Object> parameters) {
		EclipseContextFactory.getServiceContext(FrameworkUtil.getBundle(getClass()).getBundleContext());
		ECommandService commandService = context.get(ECommandService.class);
		Command command = commandService.getCommand(commandId);
		ParameterizedCommand parametrizedCommand = ParameterizedCommand.generateCommand(command, parameters);
		EHandlerService eHandlerService = context.get(EHandlerService.class);
		return eHandlerService.executeHandler(parametrizedCommand);
	}

Dialog-based interaction with user may require jface dependency.
Comment 10 Mickael Istria CLA 2020-04-19 12:04:32 EDT
(In reply to Alexander Fedorov from comment #9)
> Placing it to a bundle with name org.eclipse.e4.ui.* can make it available
> for more applications :)
> [...]
> Dialog-based interaction with user may require jface dependency.

So org.eclipse.ui.workbench.swt seems to be the most relevant place. Or do you have a better one to suggest?
Comment 11 Alexander Fedorov CLA 2020-04-19 12:10:06 EDT
(In reply to Mickael Istria from comment #10)
> (In reply to Alexander Fedorov from comment #9)
> > Placing it to a bundle with name org.eclipse.e4.ui.* can make it available
> > for more applications :)
> > [...]
> > Dialog-based interaction with user may require jface dependency.
> 
> So org.eclipse.ui.workbench.swt seems to be the most relevant place. Or do
> you have a better one to suggest?

Yes, "org.eclipse.e4.ui.workbench.swt" looks good to me.
Comment 12 Matthias Becker CLA 2020-04-20 02:38:48 EDT
(In reply to Mickael Istria from comment #6)
> Another example can be, having a GitHub "badge" with "open in Eclipse IDE"
> referencing the EGit clone command, or to write documentation automatically
> opening the right preference page for users who'd allow that is great.

That would be cool.
Comment 13 Matthias Becker CLA 2020-04-20 02:40:19 EDT
(In reply to Mickael Istria from comment #8)
> When opening an external link (eg a magnet://) from Firefox, I get a popup
> that let me chose which application should handle it. There is a default
> one, but I'm also free to pick some other one.
> So I think the OS and browser seem to give the ability to select one
> application or another. 

I am not sure if this is firefox or the OS in your case. Browsers seem also to have some kind of uri scheme registry...

I think on Linux one can test with xdg-open from the command line.
Comment 14 Matthias Becker CLA 2020-04-20 02:41:32 EDT
(In reply to Alexander Fedorov from comment #11)
> Yes, "org.eclipse.e4.ui.workbench.swt" looks good to me.

What about an alternative to the "Link Handlers" pref page? I think this currently is IDE specific.
Comment 15 Mickael Istria CLA 2020-04-20 03:02:09 EDT
(In reply to Matthias Becker from comment #14)
> What about an alternative to the "Link Handlers" pref page? I think this
> currently is IDE specific.

Why nit. However, I think it'd be better to track it in a separate ticket.
Comment 16 Alexander Fedorov CLA 2020-04-20 03:54:49 EDT
(In reply to Matthias Becker from comment #14)
> (In reply to Alexander Fedorov from comment #11)
> > Yes, "org.eclipse.e4.ui.workbench.swt" looks good to me.
> 
> What about an alternative to the "Link Handlers" pref page? I think this
> currently is IDE specific.

Let me describe the scenario I have for Eclipse Passage Operator, that is E4 RCP without any IDE specific functionality:
 1) end user launches a product and receives a dialog with functionality constraint (done)
 2) end user requests a license via saving .eml file that contains an attachment with all the required data (in progress)
 3) operator opens an email with license request and navigates via "eclipse+command" URL to an existing "Issue License" wizard that can be already fulfilled in this case (very nice to have)

So, an alternative to configure and call link handlers for E4 RCP would be good.

(In reply to Mickael Istria from comment #15)
> (In reply to Matthias Becker from comment #14)
> > What about an alternative to the "Link Handlers" pref page? I think this
> > currently is IDE specific.
> 
> Why nit. However, I think it'd be better to track it in a separate ticket.

+1
Comment 17 Mickael Istria CLA 2020-04-20 04:47:52 EDT
(In reply to Alexander Fedorov from comment #9)
> 	EclipseContextFactory.getServiceContext(FrameworkUtil.getBundle(getClass()).
> getBundleContext());
> 	ECommandService commandService = context.get(ECommandService.class);

The commandService is null here. Am I missing something, or os the BundleContext for org.eclipse.e4.ui.workbench.swt too "small" to include those services?
If you prefer, I can submit a Gerrit review and we continue there.
Comment 18 Alexander Fedorov CLA 2020-04-20 05:08:17 EDT
(In reply to Mickael Istria from comment #17)
> (In reply to Alexander Fedorov from comment #9)
> > 	EclipseContextFactory.getServiceContext(FrameworkUtil.getBundle(getClass()).
> > getBundleContext());
> > 	ECommandService commandService = context.get(ECommandService.class);
> 
> The commandService is null here. Am I missing something, or os the
> BundleContext for org.eclipse.e4.ui.workbench.swt too "small" to include
> those services?
> If you prefer, I can submit a Gerrit review and we continue there.

Yes, please, it would be great. May be we are near a defect of e4 workbench.
Comment 19 Mickael Istria CLA 2020-04-20 05:22:32 EDT
Testing can be achieved opening an HTML file in the Eclipse Internal Browser, with content
```
<html>
<body>
<a href="eclipse+command://org.eclipse.ui.window.preferences?preferencePageId=org.eclipse.ui.browser.preferencePage">command (open browser preference page)</a>
</body>
</html>
```
and clicking the link.
Comment 20 Matthias Becker CLA 2020-04-20 05:32:50 EDT
(In reply to Mickael Istria from comment #19)
> Testing can be achieved opening an HTML file in the Eclipse Internal
> Browser, with content
> ```
> <html>
> <body>
> <a
> href="eclipse+command://org.eclipse.ui.window.
> preferences?preferencePageId=org.eclipse.ui.browser.preferencePage">command
> (open browser preference page)</a>
> </body>
> </html>
> ```
> and clicking the link.

Or just paste 
eclipse+command://org.eclipse.ui.window.preferences?preferencePageId=org.eclipse.ui.browser.preferencePage

into the address bar of the browser
Comment 21 Mickael Istria CLA 2020-04-20 05:38:06 EDT
(In reply to Matthias Becker from comment #20)
> Or just paste 
> eclipse+command://org.eclipse.ui.window.preferences?preferencePageId=org.
> eclipse.ui.browser.preferencePage
> 
> into the address bar of the browser

This doesn't work for me as setting URL in the browser address bar automatically adds `http://` if the URL isn't http or https. So it ends up trying to open `http://eclipse+command//org.eclipse.ui.window.preferences?preferencePageId=org.eclipse.ui.browser.preferencePage` which results in "Error resolving “eclipse+command”: Name or service not known"
Comment 23 Eclipse Genie CLA 2020-04-21 04:59:21 EDT
New Gerrit change created: https://git.eclipse.org/r/161275
Comment 24 Eclipse Genie CLA 2020-04-21 05:24:47 EDT
New Gerrit change created: https://git.eclipse.org/r/161279
Comment 27 Mickael Istria CLA 2020-04-22 16:32:17 EDT
Here is a demo how it looks like in actionL https://www.screencast.com/t/lVKvUaxu5fMl