openjdk team mailing list archive
-
openjdk team
-
Mailing list archive
-
Message #08664
Bug#686865: openjdk-6-jre: java.awt.Desktop.browse starts gnome-www-browser instead of preferred iceweasel
Package: openjdk-6-jre
Version: 6b24-1.11.4-3
Severity: minor
Tags: patch upstream
Dear Maintainer,
java.awt.Desktop.browse(url) is documented to open users preferred
browser but in my system it opens gnome-www-browser. I have set
iceweasel as my preferred browser.
The problem is in the libmawt.so native library that tries to use
libgnome.so function to open url. I have no idea why that function fails
to open correct browser. Also using gnome library feels a bit wrong in
case someone is using KDE (I'm using gnome).
Based on that I decided to make a patch that would work in any graphical
environment. There is tool xdg-open that works correctly in Gnome and
KDE. Using it is very simple matter of fork and exec.
That of course adds dependency to xdg-utils package. But if xdg-open
isn't present java will report a exception to application that can be
handled gracefully. That makes me thing suggest dependency would be
correct. But I don't know policy details how this kind of dependency
should be handled when it won't be used in headless (server) java.
Attached patch fixes the issue for me making java open correct browser
when java application wants to open a URL in a browser.
I also check openjdk-7 sources if there was better fix. There is some
improvements done but it is still using Gnome specific interfaces. To me
it feels that same change is required for openjdk-7 too. But I haven't
tested what happens with openjdk-7 with or without the patch. Also patch
won't apply cleanly to version 7.
-- System Information:
Debian Release: wheezy/sid
APT prefers unstable
APT policy: (500, 'unstable'), (500, 'testing')
Architecture: amd64 (x86_64)
Foreign Architectures: i386
Kernel: Linux 3.2.23-3-custom02-amd64 (SMP w/4 CPU cores)
Locale: LANG=en_GB.utf8, LC_CTYPE=en_GB.utf8 (charmap=UTF-8)
Shell: /bin/sh linked to /bin/dash
Versions of packages openjdk-6-jre depends on:
ii libasound2 1.0.25-4
ii libatk-wrapper-java-jni 0.30.4-2
ii libc6 2.13-35
ii libgif4 4.1.6-9.1
ii libjpeg8 8d-1
ii libpng12-0 1.2.49-3
ii libpulse0 2.0-6
ii libx11-6 2:1.5.0-1
ii libxext6 2:1.3.1-2
ii libxi6 2:1.6.1-1
ii libxrender1 1:0.9.7-1
ii libxtst6 2:1.2.1-1
ii openjdk-6-jre-headless 6b24-1.11.4-3
ii zlib1g 1:1.2.7.dfsg-13
Versions of packages openjdk-6-jre recommends:
ii icedtea-netx 1.2-2
ii ttf-dejavu-extra 2.33-3
Versions of packages openjdk-6-jre suggests:
ii icedtea-plugin 1.2-2
-- no debconf information
--- openjdk-orig/jdk/src/solaris/native/sun/xawt/awt_Desktop.c 2012-09-06 18:32:22.752257464 +0300
+++ openjdk/jdk/src/solaris/native/sun/xawt/awt_Desktop.c 2012-09-06 19:00:49.764300607 +0300
@@ -24,53 +24,41 @@
*/
#include <jni.h>
-#include <dlfcn.h>
-
-typedef int gboolean;
-
-gboolean (*gnome_url_show) (const char *url, void **error);
-
-int init(){
- void *vfs_handle;
- void *gnome_handle;
- gboolean (*gnome_vfs_init) (void);
- const char *errmsg;
-
- vfs_handle = dlopen("libgnomevfs-2.so.0", RTLD_LAZY);
- if (vfs_handle == NULL) {
-#ifdef INTERNAL_BUILD
- fprintf(stderr, "can not load libgnomevfs-2.so\n");
-#endif
- return 0;
- }
- dlerror(); /* Clear errors */
- gnome_vfs_init = dlsym(vfs_handle, "gnome_vfs_init");
- if ((errmsg = dlerror()) != NULL) {
-#ifdef INTERNAL_BUILD
- fprintf(stderr, "can not find symble gnome_vfs_init\n");
-#endif
- return 0;
+#include <unistd.h>
+#include <stdlib.h>
+#include <sys/wait.h>
+#include <errno.h>
+
+static int run_program(const char *prog, const char *param) {
+ int success = 0;
+
+ pid_t pid = fork();
+
+ if (pid < 0) {
+ success = 1;
+ } else if (pid == 0) {
+ /* Close stdin, stdout and stderr */
+ close(0);
+ close(1);
+ close(2);
+ execlp(prog, prog, param, NULL);
+ exit(2);
+ } else {
+ int status = 0;
+ pid_t r;
+ while ((r = waitpid(pid, &status, 0)) != pid && errno == EINTR) {
+ }
+ if (r != pid) {
+ success = 4;
+ } else if (!WIFEXITED(status)) {
+ success = 5;
+ } else {
+ success = WEXITSTATUS(status);
+ }
}
- // call gonme_vfs_init()
- (*gnome_vfs_init)();
- gnome_handle = dlopen("libgnome-2.so.0", RTLD_LAZY);
- if (gnome_handle == NULL) {
-#ifdef INTERNAL_BUILD
- fprintf(stderr, "can not load libgnome-2.so\n");
-#endif
- return 0;
- }
- dlerror(); /* Clear errors */
- gnome_url_show = dlsym(gnome_handle, "gnome_url_show");
- if ((errmsg = dlerror()) != NULL) {
-#ifdef INTERNAL_BUILD
- fprintf(stderr, "can not find symble gnome_url_show\n");
-#endif
- return 0;
- }
+ return success;
- return 1;
}
/*
@@ -81,8 +69,7 @@
JNIEXPORT jboolean JNICALL Java_sun_awt_X11_XDesktopPeer_init
(JNIEnv *env, jclass cls)
{
- int init_ok = init();
- return init_ok ? JNI_TRUE : JNI_FALSE;
+ return run_program("which", "xdg-open") == 0 ? JNI_TRUE : JNI_FALSE;
}
/*
@@ -93,16 +80,13 @@
JNIEXPORT jboolean JNICALL Java_sun_awt_X11_XDesktopPeer_gnome_1url_1show
(JNIEnv *env, jobject obj, jbyteArray url_j)
{
- gboolean success;
+ jboolean success;
const char* url_c = (*env)->GetByteArrayElements(env, url_j, NULL);
- if (gnome_url_show == NULL) return JNI_FALSE;
-
- // call gnome_url_show(const char* , GError**)
- success = (*gnome_url_show)(url_c, NULL);
+ success = run_program("xdg-open", url_c) == 0 ? JNI_TRUE : JNI_FALSE;
(*env)->ReleaseByteArrayElements(env, url_j, (signed char*)url_c, 0);
- return success ? JNI_TRUE : JNI_FALSE;
+ return success;
}