Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/src/solaris/native/sun/xawt/awt_Desktop.c
32287 views
/*1* Copyright (c) 2005, 2018, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425#include "jni_util.h"26#include "gtk_interface.h"27#include "gnome_interface.h"2829static gboolean gtk_has_been_loaded = FALSE;30static gboolean gnome_has_been_loaded = FALSE;3132/*33* Class: sun_awt_X11_XDesktopPeer34* Method: init35* Signature: ()Z36*/37JNIEXPORT jboolean JNICALL Java_sun_awt_X11_XDesktopPeer_init38(JNIEnv *env, jclass cls, jint version, jboolean verbose)39{4041if (gtk_has_been_loaded || gnome_has_been_loaded) {42return JNI_TRUE;43}4445if (gtk_load(env, version, verbose) && gtk->show_uri_load(env)) {46gtk_has_been_loaded = TRUE;47return JNI_TRUE;48} else if (gnome_load()) {49gnome_has_been_loaded = TRUE;50return JNI_TRUE;51}5253return JNI_FALSE;54}5556/*57* Class: sun_awt_X11_XDesktopPeer58* Method: gnome_url_show59* Signature: (Ljava/lang/[B;)Z60*/61JNIEXPORT jboolean JNICALL Java_sun_awt_X11_XDesktopPeer_gnome_1url_1show62(JNIEnv *env, jobject obj, jbyteArray url_j)63{64gboolean success = FALSE;65const gchar* url_c;6667url_c = (char*)(*env)->GetByteArrayElements(env, url_j, NULL);68if (url_c == NULL) {69if (!(*env)->ExceptionCheck(env)) {70JNU_ThrowOutOfMemoryError(env, 0);71}72return JNI_FALSE;73}7475if (gtk_has_been_loaded) {76gtk->gdk_threads_enter();77success = gtk->gtk_show_uri(NULL, url_c, GDK_CURRENT_TIME, NULL);78gtk->gdk_threads_leave();79} else if (gnome_has_been_loaded) {80success = (*gnome_url_show)(url_c, NULL);81}8283(*env)->ReleaseByteArrayElements(env, url_j, (signed char*)url_c, 0);8485return success ? JNI_TRUE : JNI_FALSE;86}878889