From 85c52a2753e5023c36c0addc35c725ac30d7adbd Mon Sep 17 00:00:00 2001 From: Boris Grozev Date: Wed, 15 Jan 2014 09:41:23 +0100 Subject: [PATCH] Adds the "net.java.sip.communicator.impl.browserlauncher.LINUX_BROWSERS" property which holds the list of browsers on linux. It should contain a colon-separated list of browsers to try. Entries are tested using which(1), so either names of executables in PATH or absolute paths can be used. The first one that works is used. Example: net.java.sip.communicator.impl.browserlauncher.LINUX_BROWSERS="chromium-browser:/opt/custom-firefox-install/bin/firefox" --- lib/jitsi-defaults.properties | 13 +++ .../BrowserLauncherActivator.java | 46 +++++++++++ .../browserlauncher/BrowserLauncherImpl.java | 80 +++++++++++++------ .../browserlauncher.manifest.mf | 1 + 4 files changed, 116 insertions(+), 24 deletions(-) diff --git a/lib/jitsi-defaults.properties b/lib/jitsi-defaults.properties index ac2f01f19..c9987ed87 100644 --- a/lib/jitsi-defaults.properties +++ b/lib/jitsi-defaults.properties @@ -179,3 +179,16 @@ net.java.sip.communicator.plugin.pluginmanager.SYSTEM_BUNDLES=\ gnu.java.zrtp4j,\ SDES4J,\ log4j + +#a colon-separated list of commands to be tried as browsers on linux +net.java.sip.communicator.impl.browserlauncher.LINUX_BROWSERS=xdg-open\ + :gnome-open\ + :iceweasel\ + :firefox\ + :chromium-browser\ + :google-chrome\ + :opera\ + :konqueror\ + :epiphany\ + :mozilla\ + :netscape diff --git a/src/net/java/sip/communicator/impl/browserlauncher/BrowserLauncherActivator.java b/src/net/java/sip/communicator/impl/browserlauncher/BrowserLauncherActivator.java index b3e2c946c..3dabdc802 100644 --- a/src/net/java/sip/communicator/impl/browserlauncher/BrowserLauncherActivator.java +++ b/src/net/java/sip/communicator/impl/browserlauncher/BrowserLauncherActivator.java @@ -8,6 +8,8 @@ import net.java.sip.communicator.service.browserlauncher.*; import net.java.sip.communicator.util.*; +import org.jitsi.service.configuration.*; +import org.osgi.framework.*; /** * Implements BundleActivator for the browserlauncher bundle. @@ -19,6 +21,15 @@ public class BrowserLauncherActivator extends SimpleServiceActivator { + /** + * The BundleContext + */ + private static BundleContext bundleContext = null; + + /** + * The ServiceConfiguration to be used by this service. + */ + private static ConfigurationService configService = null; /** * Creates new instance of BrowserLauncherActivator. @@ -36,4 +47,39 @@ protected BrowserLauncherImpl createServiceImpl() { return new BrowserLauncherImpl(); } + + /** + * {@inheritDoc} + * + * Saves bundleContext locally. + */ + @Override + public void start(BundleContext bundleContext) + throws Exception + { + BrowserLauncherActivator.bundleContext = bundleContext; + + super.start(bundleContext); + } + + /** + * Returns the ConfigurationService obtained from the + * the BundleContext + * + * @return the ConfigurationService obtained from the + * the BundleContext + */ + public static ConfigurationService getConfigurationService() + { + if (configService == null && bundleContext != null) + { + ServiceReference serviceReference = bundleContext + .getServiceReference(ConfigurationService.class.getName()); + + configService = (ConfigurationService)bundleContext + .getService(serviceReference); + } + + return configService; + } } diff --git a/src/net/java/sip/communicator/impl/browserlauncher/BrowserLauncherImpl.java b/src/net/java/sip/communicator/impl/browserlauncher/BrowserLauncherImpl.java index 0a0912de3..2f7df15f7 100644 --- a/src/net/java/sip/communicator/impl/browserlauncher/BrowserLauncherImpl.java +++ b/src/net/java/sip/communicator/impl/browserlauncher/BrowserLauncherImpl.java @@ -9,6 +9,7 @@ import net.java.sip.communicator.service.browserlauncher.*; import net.java.sip.communicator.util.Logger; +import org.jitsi.service.configuration.*; import org.jitsi.util.*; import com.apple.eio.*; @@ -23,7 +24,12 @@ public class BrowserLauncherImpl implements BrowserLauncherService { - + /** + * The name of the property which holds the colon-separated list of browsers + * to try on linux. + */ + private static String LINUX_BROWSERS_PROP_NAME + = "net.java.sip.communicator.impl.browserlauncher.LINUX_BROWSERS"; /** * The Logger instance used by the BrowserLauncherImpl * class and its instances for logging output. @@ -31,6 +37,11 @@ public class BrowserLauncherImpl private static final Logger logger = Logger.getLogger(BrowserLauncherImpl.class); + /** + * The name of the browser executable to use on linux + */ + private static String linuxBrowser = null; + /** * Opens the specified URL in an OS-specific associated browser. * @@ -56,35 +67,56 @@ else if (OSUtils.IS_WINDOWS) } else { - String[] browsers - = new String[] - { - "google-chrome", - "chromium-browser", - "firefox", - "iceweasel", - "opera", - "konqueror", - "epiphany", - "mozilla", - "netscape", - "gnome-open" - }; - - Runtime runtime = Runtime.getRuntime(); - String browser = null; - - for (String b : browsers) - if (runtime.exec(new String[] { "which", b }).waitFor() == 0) - browser = b; + String browser = getLinuxBrowser(); if (browser == null) - throw new Exception("Could not find web browser"); + logger.error("Could not find web browser"); else - runtime.exec(new String[] { browser, url }); + Runtime.getRuntime().exec(new String[]{browser, url}); } } + /** + * Gets the name (or absolute path) to the executable to use as a browser + * on linux. + * + * @return the name (or absolute path) to the executable to use as a browser + * on linux. + * + * @throws Exception on failure from Runtime.exec() + */ + private String getLinuxBrowser() + throws Exception + { + if (linuxBrowser == null) + { + ConfigurationService cfg + = BrowserLauncherActivator.getConfigurationService(); + if (cfg != null) + { + String browsers= cfg.getString(LINUX_BROWSERS_PROP_NAME); + if (browsers== null) + { + logger.error("Required property not set: " + + LINUX_BROWSERS_PROP_NAME); + return null; + } + + Runtime runtime = Runtime.getRuntime(); + for (String b : browsers.split(":")) + { + if (runtime.exec(new String[] { "which", b }).waitFor() == 0) + { + linuxBrowser = b; + break; + } + } + } + } + + return linuxBrowser; + } + /** * Tries to open the specified URL in a browser. The attempt is asynchronously * executed and does not wait for possible errors related to the launching diff --git a/src/net/java/sip/communicator/impl/browserlauncher/browserlauncher.manifest.mf b/src/net/java/sip/communicator/impl/browserlauncher/browserlauncher.manifest.mf index c093bcfc4..5a79b05b3 100644 --- a/src/net/java/sip/communicator/impl/browserlauncher/browserlauncher.manifest.mf +++ b/src/net/java/sip/communicator/impl/browserlauncher/browserlauncher.manifest.mf @@ -6,6 +6,7 @@ Bundle-Version: 0.0.1 Bundle-SymbolicName: net.java.sip.communicator.browserlauncher Export-Package: net.java.sip.communicator.service.browserlauncher Import-Package: org.osgi.framework, + org.jitsi.service.configuration, org.jitsi.util, net.java.sip.communicator.util, net.java.sip.communicator.service.browserlauncher,