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"
cusax-fix
Boris Grozev 12 years ago
parent 15cd77cd11
commit 85c52a2753

@ -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

@ -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 <tt>BundleActivator</tt> for the browserlauncher bundle.
@ -19,6 +21,15 @@
public class BrowserLauncherActivator
extends SimpleServiceActivator<BrowserLauncherImpl>
{
/**
* The <tt>BundleContext</tt>
*/
private static BundleContext bundleContext = null;
/**
* The <tt>ServiceConfiguration</tt> to be used by this service.
*/
private static ConfigurationService configService = null;
/**
* Creates new instance of <tt>BrowserLauncherActivator</tt>.
@ -36,4 +47,39 @@ protected BrowserLauncherImpl createServiceImpl()
{
return new BrowserLauncherImpl();
}
/**
* {@inheritDoc}
*
* Saves <tt>bundleContext</tt> locally.
*/
@Override
public void start(BundleContext bundleContext)
throws Exception
{
BrowserLauncherActivator.bundleContext = bundleContext;
super.start(bundleContext);
}
/**
* Returns the <tt>ConfigurationService</tt> obtained from the
* the <tt>BundleContext</tt>
*
* @return the <tt>ConfigurationService</tt> obtained from the
* the <tt>BundleContext</tt>
*/
public static ConfigurationService getConfigurationService()
{
if (configService == null && bundleContext != null)
{
ServiceReference serviceReference = bundleContext
.getServiceReference(ConfigurationService.class.getName());
configService = (ConfigurationService)bundleContext
.getService(serviceReference);
}
return configService;
}
}

@ -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 <tt>Logger</tt> instance used by the <tt>BrowserLauncherImpl</tt>
* 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 <tt>Runtime.exec()</tt>
*/
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

@ -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,

Loading…
Cancel
Save