Bug 536589: Add support of new uriScheme extension point

This adds an uri scheme handler for the custom uri scheme
"eclipse-mpc".

Marketplace client currently get's URLs in the form
http://marketplace.eclipse.org/marketplace-client-intro?mpc_install=311881
"eclipse-mpc"-URLs are exactly the same only the "http" is exchanged
with "eclipse.-mpc". The idea is that the marketplace website renders
links with the "eclipse-mpc" URI scheme.

The implementation is quite easy. It just replaces the "eclipse-mpc"
back to "https" and just calls the existing facilities in the
MarketplaceUrlHandler class.

Change-Id: I6934c35e0188288ffa6962bf0d6f62e369e9a05c
Signed-off-by: Matthias Becker <ma.becker@sap.com>
diff --git a/org.eclipse.epp.mpc-target/staging.target b/org.eclipse.epp.mpc-target/staging.target
index ede98cc..23907e0 100644
--- a/org.eclipse.epp.mpc-target/staging.target
+++ b/org.eclipse.epp.mpc-target/staging.target
@@ -7,7 +7,7 @@
 <unit id="org.eclipse.equinox.p2.sdk.feature.group" version="0.0.0"/>
 <unit id="org.eclipse.equinox.ds" version="0.0.0"/>
 <unit id="org.eclipse.sdk.feature.group" version="0.0.0"/>
-<repository location="http://download.eclipse.org/eclipse/updates/4.12-I-builds"/>
+<repository location="http://download.eclipse.org/eclipse/updates/4.13-I-builds"/>
 </location>
 <location includeAllPlatforms="false" includeConfigurePhase="true" includeMode="planner" includeSource="true" type="InstallableUnit">
 <unit id="org.hamcrest" version="0.0.0"/>
diff --git a/org.eclipse.epp.mpc.ui/META-INF/MANIFEST.MF b/org.eclipse.epp.mpc.ui/META-INF/MANIFEST.MF
index d634e11..3a47323 100644
--- a/org.eclipse.epp.mpc.ui/META-INF/MANIFEST.MF
+++ b/org.eclipse.epp.mpc.ui/META-INF/MANIFEST.MF
@@ -28,7 +28,8 @@
  org.eclipse.ui.ide;bundle-version="[3.13.0,4.0.0)",
  org.eclipse.core.resources;bundle-version="[3.12.0,4.0.0)",
  org.eclipse.e4.ui.css.core;bundle-version="[0.12.200,1.0.0)",
- org.eclipse.e4.ui.css.swt;bundle-version="[0.13.100,1.0.0)"
+ org.eclipse.e4.ui.css.swt;bundle-version="[0.13.100,1.0.0)",
+ org.eclipse.urischeme;bundle-version="[1.0.300,2.0.0)"
 Export-Package: org.eclipse.epp.internal.mpc.ui;x-internal:=true,
  org.eclipse.epp.internal.mpc.ui.actions;x-internal:=true,
  org.eclipse.epp.internal.mpc.ui.catalog;x-internal:=true,
diff --git a/org.eclipse.epp.mpc.ui/plugin.xml b/org.eclipse.epp.mpc.ui/plugin.xml
index dacd566..9106f09 100644
--- a/org.eclipse.epp.mpc.ui/plugin.xml
+++ b/org.eclipse.epp.mpc.ui/plugin.xml
@@ -188,4 +188,12 @@
             </widget>
          </provider>
       </extension>
+      <extension
+            point="org.eclipse.urischeme.uriSchemeHandlers">
+         <uriSchemeHandler
+               class="org.eclipse.epp.mpc.ui.MarketPlaceUirSchemeHandler"
+               uriScheme="eclipse-mpc"
+               uriSchemeDescription="Eclipse Marketplace">
+         </uriSchemeHandler>
+      </extension>
 </plugin>
diff --git a/org.eclipse.epp.mpc.ui/src/org/eclipse/epp/mpc/ui/MarketPlaceUirSchemeHandler.java b/org.eclipse.epp.mpc.ui/src/org/eclipse/epp/mpc/ui/MarketPlaceUirSchemeHandler.java
new file mode 100644
index 0000000..9c0d8b8
--- /dev/null
+++ b/org.eclipse.epp.mpc.ui/src/org/eclipse/epp/mpc/ui/MarketPlaceUirSchemeHandler.java
@@ -0,0 +1,60 @@
+/*******************************************************************************
+ * Copyright (c) 2018 The Eclipse Foundation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v2.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-2.0/
+ *
+ * SPDX-License-Identifier: EPL-2.0
+ *
+ * Contributors:
+ *     The Eclipse Foundation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.epp.mpc.ui;
+
+import org.eclipse.epp.internal.mpc.ui.MarketplaceClientUiPlugin;
+import org.eclipse.epp.mpc.ui.MarketplaceUrlHandler.SolutionInstallationInfo;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.urischeme.IUriSchemeHandler;
+
+public class MarketPlaceUirSchemeHandler implements IUriSchemeHandler {
+
+	public MarketPlaceUirSchemeHandler() {
+		// ignore
+	}
+
+	@Override
+	public void handle(String mpcUri) {
+		String uri = mpcUri.replaceFirst("eclipse-mpc://", "https://"); //$NON-NLS-1$ //$NON-NLS-2$
+
+		Display display = Display.getDefault();
+		if (MarketplaceUrlHandler.isPotentialSolution(uri)) {
+			//https://marketplace.eclipse.org/marketplace-client-intro?mpc_install=1640500
+			display.asyncExec(() -> proceedInstallation(uri));
+		} else if (MarketplaceUrlHandler.isPotentialFavoritesList(uri)) {
+			//https://marketplace.eclipse.org/user/xxx/favorites
+			display.asyncExec(() -> proceedFavorites(uri));
+		} else {
+			traceInvalidUrl(uri);
+		}
+	}
+
+	private void proceedInstallation(String url) {
+		SolutionInstallationInfo info = MarketplaceUrlHandler.createSolutionInstallInfo(url);
+		if (info != null) {
+			MarketplaceUrlHandler.triggerInstall(info);
+		}
+	}
+
+	private void proceedFavorites(String url) {
+		MarketplaceUrlHandler.triggerFavorites(url);
+	}
+
+	private void traceInvalidUrl(String url) {
+		if (MarketplaceClientUiPlugin.DEBUG) {
+			MarketplaceClientUiPlugin.trace(MarketplaceClientUiPlugin.DROP_ADAPTER_DEBUG_OPTION,
+					"Drop event: Data is not a solution url: {0}", url, new Throwable()); //$NON-NLS-1$
+		}
+	}
+
+}