From 33efe9596e69a5aad93f3a11f8c77eeea3f00410 Mon Sep 17 00:00:00 2001 From: denis Date: Fri, 22 Mar 2013 19:56:20 +0400 Subject: [PATCH] 7123476: DesktopOpenTests:When enter the file path and click the open button,it crash Reviewed-by: art, anthony --- make/sun/xawt/FILES_c_unix.gmk | 3 +- makefiles/CompileNativeLibraries.gmk | 3 +- src/solaris/native/sun/awt/gtk2_interface.c | 35 +++++- src/solaris/native/sun/awt/gtk2_interface.h | 16 ++- src/solaris/native/sun/xawt/awt_Desktop.c | 103 +++++------------- src/solaris/native/sun/xawt/gnome_interface.c | 87 +++++++++++++++ src/solaris/native/sun/xawt/gnome_interface.h | 39 +++++++ 7 files changed, 208 insertions(+), 78 deletions(-) create mode 100644 src/solaris/native/sun/xawt/gnome_interface.c create mode 100644 src/solaris/native/sun/xawt/gnome_interface.h diff --git a/make/sun/xawt/FILES_c_unix.gmk b/make/sun/xawt/FILES_c_unix.gmk index 0ce8bdd11..74ea1cd2c 100644 --- a/make/sun/xawt/FILES_c_unix.gmk +++ b/make/sun/xawt/FILES_c_unix.gmk @@ -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 @@ FILES_c = \ debug_trace.c \ debug_util.c \ awt_Plugin.c \ + gnome_interface.c \ gtk2_interface.c \ swing_GTKEngine.c \ swing_GTKStyle.c \ diff --git a/makefiles/CompileNativeLibraries.gmk b/makefiles/CompileNativeLibraries.gmk index 9df22fe8b..3e3751435 100644 --- a/makefiles/CompileNativeLibraries.gmk +++ b/makefiles/CompileNativeLibraries.gmk @@ -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 @@ LIBAWT_XAWT_FILES:=\ debug_trace.c \ debug_util.c \ awt_Plugin.c \ + gnome_interface.c \ gtk2_interface.c \ swing_GTKEngine.c \ swing_GTKStyle.c \ diff --git a/src/solaris/native/sun/awt/gtk2_interface.c b/src/solaris/native/sun/awt/gtk2_interface.c index cb93366be..daca810e5 100644 --- a/src/solaris/native/sun/awt/gtk2_interface.c +++ b/src/solaris/native/sun/awt/gtk2_interface.c @@ -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 @@ -437,6 +437,39 @@ gboolean gtk2_check_version() } } +/** + * 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 */ diff --git a/src/solaris/native/sun/awt/gtk2_interface.h b/src/solaris/native/sun/awt/gtk2_interface.h index 1b46920a5..22ba24a49 100644 --- a/src/solaris/native/sun/awt/gtk2_interface.h +++ b/src/solaris/native/sun/awt/gtk2_interface.h @@ -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 @@ struct _GSList typedef void GdkColormap; typedef void GdkDrawable; typedef void GdkGC; +typedef void GdkScreen; typedef void GdkPixbuf; typedef void GdkPixmap; typedef void GdkWindow; @@ -663,6 +665,15 @@ gchar* (*fp_gtk_check_version)(guint required_major, guint required_minor, */ 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. @@ -795,4 +806,7 @@ void (*fp_gdk_threads_init)(void); 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 */ diff --git a/src/solaris/native/sun/xawt/awt_Desktop.c b/src/solaris/native/sun/xawt/awt_Desktop.c index b8b250beb..317af3dfa 100644 --- a/src/solaris/native/sun/xawt/awt_Desktop.c +++ b/src/solaris/native/sun/xawt/awt_Desktop.c @@ -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 -#include -#include +#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 @@ int init(){ 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_init 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; diff --git a/src/solaris/native/sun/xawt/gnome_interface.c b/src/solaris/native/sun/xawt/gnome_interface.c new file mode 100644 index 000000000..90d56de93 --- /dev/null +++ b/src/solaris/native/sun/xawt/gnome_interface.c @@ -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; +} diff --git a/src/solaris/native/sun/xawt/gnome_interface.h b/src/solaris/native/sun/xawt/gnome_interface.h new file mode 100644 index 000000000..2ca444725 --- /dev/null +++ b/src/solaris/native/sun/xawt/gnome_interface.h @@ -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 +#include +#include + +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 */ -- GitLab