changeset 8028:a275acd8bcae

7123476: DesktopOpenTests:When enter the file path and click the open button,it crash Reviewed-by: art, anthony
author denis
date Fri, 22 Mar 2013 19:56:20 +0400
parents ef948ef2b58f
children 15a2599f470f 96750ebc769b
files make/sun/xawt/FILES_c_unix.gmk makefiles/CompileNativeLibraries.gmk src/solaris/native/sun/awt/gtk2_interface.c src/solaris/native/sun/awt/gtk2_interface.h src/solaris/native/sun/xawt/awt_Desktop.c src/solaris/native/sun/xawt/gnome_interface.c src/solaris/native/sun/xawt/gnome_interface.h
diffstat 7 files changed, 208 insertions(+), 78 deletions(-) [+]
line wrap: on
line diff
--- a/make/sun/xawt/FILES_c_unix.gmk	Thu Mar 21 16:50:35 2013 +0400
+++ b/make/sun/xawt/FILES_c_unix.gmk	Fri Mar 22 19:56:20 2013 +0400
@@ -1,5 +1,5 @@
 #
-# Copyright (c) 2002, 2010, Oracle and/or its affiliates. All rights reserved.
+# Copyright (c) 2002, 2013, Oracle and/or its affiliates. All rights reserved.
 # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
 #
 # This code is free software; you can redistribute it and/or modify it
@@ -76,6 +76,7 @@
 	debug_trace.c \
 	debug_util.c \
 	awt_Plugin.c \
+        gnome_interface.c \
 	gtk2_interface.c \
         swing_GTKEngine.c \
         swing_GTKStyle.c \
--- a/makefiles/CompileNativeLibraries.gmk	Thu Mar 21 16:50:35 2013 +0400
+++ b/makefiles/CompileNativeLibraries.gmk	Fri Mar 22 19:56:20 2013 +0400
@@ -1,5 +1,5 @@
 #
-# Copyright (c) 2011, 2012, Oracle and/or its affiliates. All rights reserved.
+# Copyright (c) 2011, 2013, Oracle and/or its affiliates. All rights reserved.
 # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
 #
 # This code is free software; you can redistribute it and/or modify it
@@ -843,6 +843,7 @@
 	debug_trace.c \
 	debug_util.c \
 	awt_Plugin.c \
+        gnome_interface.c \
 	gtk2_interface.c \
         swing_GTKEngine.c \
         swing_GTKStyle.c \
--- a/src/solaris/native/sun/awt/gtk2_interface.c	Thu Mar 21 16:50:35 2013 +0400
+++ b/src/solaris/native/sun/awt/gtk2_interface.c	Fri Mar 22 19:56:20 2013 +0400
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2005, 2011, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2005, 2013, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -438,6 +438,39 @@
 }
 
 /**
+ * Functions for awt_Desktop.c
+ */
+gboolean gtk2_show_uri_load() {
+     gboolean success = FALSE;
+     dlerror();
+     const char *gtk_version = fp_gtk_check_version(2, 14, 0);
+     if (gtk_version != NULL) {
+         // The gtk_show_uri is available from GTK+ 2.14
+#ifdef INTERNAL_BUILD
+         fprintf (stderr, "The version of GTK is %s. "
+             "The gtk_show_uri function is supported "
+             "since GTK+ 2.14.\n", gtk_version);
+#endif /* INTERNAL_BUILD */
+     } else {
+         // Loading symbols only if the GTK version is 2.14 and higher
+         fp_gtk_show_uri = dl_symbol("gtk_show_uri");
+         const char *dlsym_error = dlerror();
+         if (dlsym_error) {
+#ifdef INTERNAL_BUILD
+             fprintf (stderr, "Cannot load symbol: %s \n", dlsym_error);
+#endif /* INTERNAL_BUILD */
+         } else if (fp_gtk_show_uri == NULL) {
+#ifdef INTERNAL_BUILD
+             fprintf(stderr, "dlsym(gtk_show_uri) returned NULL\n");
+#endif /* INTERNAL_BUILD */
+         } else {
+             success = TRUE;
+         }
+     }
+     return success;
+}
+
+/**
  * Functions for sun_awt_X11_GtkFileDialogPeer.c
  */
 void gtk2_file_chooser_load()
--- a/src/solaris/native/sun/awt/gtk2_interface.h	Thu Mar 21 16:50:35 2013 +0400
+++ b/src/solaris/native/sun/awt/gtk2_interface.h	Fri Mar 22 19:56:20 2013 +0400
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2005, 2011, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2005, 2013, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -42,6 +42,7 @@
 #define GTK_STOCK_CANCEL           "gtk-cancel"
 #define GTK_STOCK_SAVE             "gtk-save"
 #define GTK_STOCK_OPEN             "gtk-open"
+#define GDK_CURRENT_TIME           0L
 
 typedef enum _WidgetType
 {
@@ -280,6 +281,7 @@
 typedef void GdkColormap;
 typedef void GdkDrawable;
 typedef void GdkGC;
+typedef void GdkScreen;
 typedef void GdkPixbuf;
 typedef void GdkPixmap;
 typedef void GdkWindow;
@@ -664,6 +666,15 @@
 gboolean gtk2_load();
 
 /*
+ * Loads fp_gtk_show_uri function pointer. This initialization is
+ * separated because the function is required only
+ * for java.awt.Desktop API. The function relies on initialization in
+ * gtk2_load, so it must be invoked only after a successful gtk2_load
+ * invocation
+ */
+gboolean gtk2_show_uri_load();
+
+/*
  * Unload the gtk2 library.  If the library is already unloaded this method has
  * no effect and returns success.
  * Returns FALSE on failure and TRUE on success.
@@ -795,4 +806,7 @@
 void (*fp_gdk_threads_enter)(void);
 void (*fp_gdk_threads_leave)(void);
 
+gboolean (*fp_gtk_show_uri)(GdkScreen *screen, const gchar *uri,
+    guint32 timestamp, GError **error);
+
 #endif /* !_GTK2_INTERFACE_H */
--- a/src/solaris/native/sun/xawt/awt_Desktop.c	Thu Mar 21 16:50:35 2013 +0400
+++ b/src/solaris/native/sun/xawt/awt_Desktop.c	Fri Mar 22 19:56:20 2013 +0400
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2005, 2011, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2005, 2013, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -23,71 +23,11 @@
  * questions.
  */
 
-#include <jni.h>
-#include <jvm_md.h>
-#include <dlfcn.h>
+#include "gtk2_interface.h"
+#include "gnome_interface.h"
 
-typedef int gboolean;
-
-typedef gboolean (GNOME_URL_SHOW_TYPE)(const char *, void **);
-typedef gboolean (GNOME_VFS_INIT_TYPE)(void);
-
-GNOME_URL_SHOW_TYPE *gnome_url_show;
-GNOME_VFS_INIT_TYPE *gnome_vfs_init;
-
-int init(){
-    void *vfs_handle;
-    void *gnome_handle;
-    const char *errmsg;
-
-    vfs_handle = dlopen(VERSIONED_JNI_LIB_NAME("gnomevfs-2", "0"), RTLD_LAZY);
-    if (vfs_handle == NULL) {
-        vfs_handle = dlopen(JNI_LIB_NAME("gnomevfs-2"), 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 = (GNOME_VFS_INIT_TYPE*)dlsym(vfs_handle, "gnome_vfs_init");
-    if (gnome_vfs_init == NULL){
-#ifdef INTERNAL_BUILD
-        fprintf(stderr, "dlsym( gnome_vfs_init) returned NULL\n");
-#endif
-        return 0;
-    }
-    if ((errmsg = dlerror()) != NULL) {
-#ifdef INTERNAL_BUILD
-        fprintf(stderr, "can not find symbol gnome_vfs_init %s \n", errmsg);
-#endif
-        return 0;
-    }
-    // call gonme_vfs_init()
-    (*gnome_vfs_init)();
-
-    gnome_handle = dlopen(VERSIONED_JNI_LIB_NAME("gnome-2", "0"), RTLD_LAZY);
-    if (gnome_handle == NULL) {
-        gnome_handle = dlopen(JNI_LIB_NAME("gnome-2"), 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 = (GNOME_URL_SHOW_TYPE*)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 1;
-}
+static gboolean gtk_has_been_loaded = FALSE;
+static gboolean gnome_has_been_loaded = FALSE;
 
 /*
  * Class:     sun_awt_X11_XDesktopPeer
@@ -97,8 +37,20 @@
 JNIEXPORT jboolean JNICALL Java_sun_awt_X11_XDesktopPeer_init
   (JNIEnv *env, jclass cls)
 {
-    int init_ok = init();
-    return init_ok ? JNI_TRUE : JNI_FALSE;
+
+    if (gtk_has_been_loaded || gnome_has_been_loaded) {
+        return JNI_TRUE;
+    }
+
+    if (gtk2_load() && gtk2_show_uri_load()) {
+        gtk_has_been_loaded = TRUE;
+        return JNI_TRUE;
+    } else if (gnome_load()) {
+        gnome_has_been_loaded = TRUE;
+        return JNI_TRUE;
+    }
+
+    return JNI_FALSE;
 }
 
 /*
@@ -109,16 +61,19 @@
 JNIEXPORT jboolean JNICALL Java_sun_awt_X11_XDesktopPeer_gnome_1url_1show
   (JNIEnv *env, jobject obj, jbyteArray url_j)
 {
-    gboolean success;
-    const char* url_c;
+    gboolean success = FALSE;
+    const gchar* url_c;
 
-    if (gnome_url_show == NULL) {
-        return JNI_FALSE;
+    url_c = (char*)(*env)->GetByteArrayElements(env, url_j, NULL);
+
+    if (gtk_has_been_loaded) {
+        fp_gdk_threads_enter();
+        success = fp_gtk_show_uri(NULL, url_c, GDK_CURRENT_TIME, NULL);
+        fp_gdk_threads_leave();
+    } else if (gnome_has_been_loaded) {
+        success = (*gnome_url_show)(url_c, NULL);
     }
 
-    url_c = (char*)(*env)->GetByteArrayElements(env, url_j, NULL);
-    // call gnome_url_show(const char* , GError**)
-    success = (*gnome_url_show)(url_c, NULL);
     (*env)->ReleaseByteArrayElements(env, url_j, (signed char*)url_c, 0);
 
     return success ? JNI_TRUE : JNI_FALSE;
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/solaris/native/sun/xawt/gnome_interface.c	Fri Mar 22 19:56:20 2013 +0400
@@ -0,0 +1,87 @@
+/*
+ * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+#include "gnome_interface.h"
+
+GNOME_URL_SHOW_TYPE *gnome_url_show = NULL;
+
+gboolean gnome_load() {
+     void *vfs_handle;
+     void *gnome_handle;
+     const char *errmsg;
+     GNOME_VFS_INIT_TYPE *gnome_vfs_init;
+
+     // trying to open the gnomevfs. VERSIONED_JNI_LIB_NAME
+     // macros formats the library name in a system specific manner
+     // see jdk/src/solaris/javavm/export/jvm_md.h for more details
+     vfs_handle = dlopen(VERSIONED_JNI_LIB_NAME("gnomevfs-2", "0"), RTLD_LAZY);
+     if (vfs_handle == NULL) {
+         // if we cannot load the library using a version assumed by JNI
+         // we are trying to load the library without a version suffix
+         vfs_handle = dlopen(JNI_LIB_NAME("gnomevfs-2"), RTLD_LAZY);
+         if (vfs_handle == NULL) {
+ #ifdef INTERNAL_BUILD
+             fprintf(stderr, "can not load libgnomevfs-2.so\n");
+ #endif
+             return FALSE;
+         }
+     }
+     dlerror(); /* Clear errors */
+     gnome_vfs_init = (GNOME_VFS_INIT_TYPE*)dlsym(vfs_handle, "gnome_vfs_init");
+     if (gnome_vfs_init == NULL){
+ #ifdef INTERNAL_BUILD
+         fprintf(stderr, "dlsym( gnome_vfs_init) returned NULL\n");
+ #endif
+         return FALSE;
+     }
+     if ((errmsg = dlerror()) != NULL) {
+ #ifdef INTERNAL_BUILD
+         fprintf(stderr, "can not find symbol gnome_vfs_init %s \n", errmsg);
+ #endif
+         return FALSE;
+     }
+     // call gonme_vfs_init()
+     (*gnome_vfs_init)();
+
+     gnome_handle = dlopen(VERSIONED_JNI_LIB_NAME("gnome-2", "0"), RTLD_LAZY);
+     if (gnome_handle == NULL) {
+         gnome_handle = dlopen(JNI_LIB_NAME("gnome-2"), RTLD_LAZY);
+         if (gnome_handle == NULL) {
+ #ifdef INTERNAL_BUILD
+             fprintf(stderr, "can not load libgnome-2.so\n");
+ #endif
+             return FALSE;
+         }
+     }
+     dlerror(); /* Clear errors */
+     gnome_url_show = (GNOME_URL_SHOW_TYPE*)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 FALSE;
+     }
+     return TRUE;
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/solaris/native/sun/xawt/gnome_interface.h	Fri Mar 22 19:56:20 2013 +0400
@@ -0,0 +1,39 @@
+/*
+ * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+#ifndef _GNOME_INTERFACE_H
+#define _GNOME_INTERFACE_H
+#include "gtk2_interface.h"
+#include <dlfcn.h>
+#include <jvm_md.h>
+#include <jni.h>
+
+typedef gboolean (GNOME_URL_SHOW_TYPE)(const char *, void **);
+typedef gboolean (GNOME_VFS_INIT_TYPE)(void);
+
+extern GNOME_URL_SHOW_TYPE *gnome_url_show;
+gboolean gnome_load();
+
+#endif /* !_GNOME_INTERFACE_H */