Merge Windows and Linux privileged Runtime.exec usage into a method in LWJGLUtil. Linux: Added the recent freedesktop.org standard xdg-open script to the list of possible URL handlers.
This commit is contained in:
parent
d96b284158
commit
45517e96c2
|
@ -380,6 +380,22 @@ public class LWJGLUtil {
|
|||
return paths;
|
||||
}
|
||||
|
||||
static void execPrivileged(final String[] cmd_array) throws Exception {
|
||||
try {
|
||||
Process process = (Process)AccessController.doPrivileged(new PrivilegedExceptionAction() {
|
||||
public Object run() throws Exception {
|
||||
return Runtime.getRuntime().exec(cmd_array);
|
||||
}
|
||||
});
|
||||
// Close unused streams to make sure the child process won't hang
|
||||
process.getInputStream().close();
|
||||
process.getOutputStream().close();
|
||||
process.getErrorStream().close();
|
||||
} catch (PrivilegedActionException e) {
|
||||
throw (Exception)e.getCause();
|
||||
}
|
||||
}
|
||||
|
||||
private static String getPrivilegedProperty(final String property_name) {
|
||||
return (String)AccessController.doPrivileged(new PrivilegedAction() {
|
||||
public Object run() {
|
||||
|
|
|
@ -32,8 +32,6 @@
|
|||
package org.lwjgl;
|
||||
|
||||
import java.security.AccessController;
|
||||
import java.security.PrivilegedActionException;
|
||||
import java.security.PrivilegedExceptionAction;
|
||||
|
||||
/**
|
||||
*
|
||||
|
@ -50,19 +48,14 @@ class LinuxSysImplementation extends J2SESysImplementation {
|
|||
// Linux may as well resort to pure Java hackery, as there's no Linux native way of doing it
|
||||
// right anyway.
|
||||
|
||||
String[] browsers = {"firefox", "mozilla", "opera", "konqueror", "nautilus", "galeon", "netscape"};
|
||||
String[] browsers = {"xdg-open", "firefox", "mozilla", "opera", "konqueror", "nautilus", "galeon", "netscape"};
|
||||
|
||||
for (int i = 0; i < browsers.length; i ++) {
|
||||
final String browser = browsers[i];
|
||||
try {
|
||||
AccessController.doPrivileged(new PrivilegedExceptionAction() {
|
||||
public Object run() throws Exception {
|
||||
Runtime.getRuntime().exec(new String[] { browser, url });
|
||||
return null;
|
||||
}
|
||||
});
|
||||
LWJGLUtil.execPrivileged(new String[] { browser, url });
|
||||
return true;
|
||||
} catch (PrivilegedActionException e) {
|
||||
} catch (Exception e) {
|
||||
// Ignore
|
||||
e.printStackTrace(System.err);
|
||||
}
|
||||
|
|
|
@ -32,8 +32,6 @@
|
|||
package org.lwjgl;
|
||||
|
||||
import java.security.AccessController;
|
||||
import java.security.PrivilegedExceptionAction;
|
||||
import java.security.PrivilegedActionException;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
|
@ -56,15 +54,10 @@ class WindowsSysImplementation extends DefaultSysImplementation {
|
|||
|
||||
public boolean openURL(final String url) {
|
||||
try {
|
||||
AccessController.doPrivileged(new PrivilegedExceptionAction() {
|
||||
public Object run() throws Exception {
|
||||
Runtime.getRuntime().exec(new String[]{"rundll32", "url.dll,FileProtocolHandler", url});
|
||||
return null;
|
||||
}
|
||||
});
|
||||
LWJGLUtil.execPrivileged(new String[]{"rundll32", "url.dll,FileProtocolHandler", url});
|
||||
return true;
|
||||
} catch (PrivilegedActionException e) {
|
||||
LWJGLUtil.log("Failed to open url (" + url + "): " + e.getCause().getMessage());
|
||||
} catch (Exception e) {
|
||||
LWJGLUtil.log("Failed to open url (" + url + "): " + e.getMessage());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue