Path: blob/master/src/java.desktop/macosx/native/libawt_lwawt/awt/CDesktopPeer.m
41152 views
/*1* Copyright (c) 2011, 2013, 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*/242526#import "JNIUtilities.h"27#import <CoreFoundation/CoreFoundation.h>28#import <ApplicationServices/ApplicationServices.h>2930/*31* Class: sun_lwawt_macosx_CDesktopPeer32* Method: _lsOpenURI33* Signature: (Ljava/lang/String;)I;34*/35JNIEXPORT jint JNICALL Java_sun_lwawt_macosx_CDesktopPeer__1lsOpenURI36(JNIEnv *env, jclass clz, jstring uri)37{38OSStatus status = noErr;39JNI_COCOA_ENTER(env);4041// I would love to use NSWorkspace here, but it's not thread safe. Why? I don't know.42// So we use LaunchServices directly.4344NSURL *url = [NSURL URLWithString:JavaStringToNSString(env, uri)];4546LSLaunchFlags flags = kLSLaunchDefaults;4748LSApplicationParameters params = {0, flags, NULL, NULL, NULL, NULL, NULL};49status = LSOpenURLsWithRole((CFArrayRef)[NSArray arrayWithObject:url], kLSRolesAll, NULL, ¶ms, NULL, 0);5051JNI_COCOA_EXIT(env);52return status;53}5455/*56* Class: sun_lwawt_macosx_CDesktopPeer57* Method: _lsOpenFile58* Signature: (Ljava/lang/String;Z)I;59*/60JNIEXPORT jint JNICALL Java_sun_lwawt_macosx_CDesktopPeer__1lsOpenFile61(JNIEnv *env, jclass clz, jstring jpath, jboolean print)62{63OSStatus status = noErr;64JNI_COCOA_ENTER(env);6566// I would love to use NSWorkspace here, but it's not thread safe. Why? I don't know.67// So we use LaunchServices directly.6869NSString *path = NormalizedPathNSStringFromJavaString(env, jpath);7071NSURL *url = [NSURL fileURLWithPath:(NSString *)path];7273// This byzantine workaround is necesary, or else directories won't open in Finder74url = (NSURL *)CFURLCreateWithFileSystemPath(NULL, (CFStringRef)[url path], kCFURLPOSIXPathStyle, false);7576LSLaunchFlags flags = kLSLaunchDefaults;77if (print) flags |= kLSLaunchAndPrint;7879LSApplicationParameters params = {0, flags, NULL, NULL, NULL, NULL, NULL};80status = LSOpenURLsWithRole((CFArrayRef)[NSArray arrayWithObject:url], kLSRolesAll, NULL, ¶ms, NULL, 0);81[url release];8283JNI_COCOA_EXIT(env);84return status;85}86878889