Path: blob/master/src/java.desktop/unix/native/libawt_xawt/xawt/awt_Desktop.c
41153 views
/*1* Copyright (c) 2005, 2020, 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#ifdef HEADLESS26#error This file should not be included in headless library27#endif2829#include "jni_util.h"30#include "gtk_interface.h"31#include "gnome_interface.h"3233static gboolean gtk_has_been_loaded = FALSE;34static gboolean gnome_has_been_loaded = FALSE;3536/*37* Class: sun_awt_X11_XDesktopPeer38* Method: init39* Signature: ()Z40*/41JNIEXPORT jboolean JNICALL Java_sun_awt_X11_XDesktopPeer_init42(JNIEnv *env, jclass cls, jint version, jboolean verbose)43{4445if (gtk_has_been_loaded || gnome_has_been_loaded) {46return JNI_TRUE;47}4849if (gtk_load(env, version, verbose) && gtk->show_uri_load(env)) {50gtk_has_been_loaded = TRUE;51return JNI_TRUE;52} else if (gnome_load()) {53gnome_has_been_loaded = TRUE;54return JNI_TRUE;55}5657return JNI_FALSE;58}5960/*61* Class: sun_awt_X11_XDesktopPeer62* Method: gnome_url_show63* Signature: (Ljava/lang/[B;)Z64*/65JNIEXPORT jboolean JNICALL Java_sun_awt_X11_XDesktopPeer_gnome_1url_1show66(JNIEnv *env, jobject obj, jbyteArray url_j)67{68gboolean success = FALSE;69const gchar* url_c;7071url_c = (char*)(*env)->GetByteArrayElements(env, url_j, NULL);72if (url_c == NULL) {73if (!(*env)->ExceptionCheck(env)) {74JNU_ThrowOutOfMemoryError(env, 0);75}76return JNI_FALSE;77}7879if (gtk_has_been_loaded) {80gtk->gdk_threads_enter();81success = gtk->gtk_show_uri(NULL, url_c, GDK_CURRENT_TIME, NULL);82gtk->gdk_threads_leave();83} else if (gnome_has_been_loaded) {84success = (*gnome_url_show)(url_c, NULL);85}8687(*env)->ReleaseByteArrayElements(env, url_j, (signed char*)url_c, 0);8889return success ? JNI_TRUE : JNI_FALSE;90}919293