CDesktopPeer.m revision 4632
b716b9cddcf2924b83c5ba2c21142cb4c626061fEvan Hunt/*
b716b9cddcf2924b83c5ba2c21142cb4c626061fEvan Hunt * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
5d52a1fe1b8ea396fb5ae7f6f1567c8383445113Tinderbox User * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
b716b9cddcf2924b83c5ba2c21142cb4c626061fEvan Hunt *
0c27b3fe77ac1d5094ba3521e8142d9e7973133fMark Andrews * This code is free software; you can redistribute it and/or modify it
0c27b3fe77ac1d5094ba3521e8142d9e7973133fMark Andrews * under the terms of the GNU General Public License version 2 only, as
0c27b3fe77ac1d5094ba3521e8142d9e7973133fMark Andrews * published by the Free Software Foundation. Oracle designates this
b716b9cddcf2924b83c5ba2c21142cb4c626061fEvan Hunt * particular file as subject to the "Classpath" exception as provided
b716b9cddcf2924b83c5ba2c21142cb4c626061fEvan Hunt * by Oracle in the LICENSE file that accompanied this code.
b716b9cddcf2924b83c5ba2c21142cb4c626061fEvan Hunt *
b716b9cddcf2924b83c5ba2c21142cb4c626061fEvan Hunt * This code is distributed in the hope that it will be useful, but WITHOUT
b716b9cddcf2924b83c5ba2c21142cb4c626061fEvan Hunt * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
b716b9cddcf2924b83c5ba2c21142cb4c626061fEvan Hunt * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
b716b9cddcf2924b83c5ba2c21142cb4c626061fEvan Hunt * version 2 for more details (a copy is included in the LICENSE file that
b716b9cddcf2924b83c5ba2c21142cb4c626061fEvan Hunt * accompanied this code).
b716b9cddcf2924b83c5ba2c21142cb4c626061fEvan Hunt *
b716b9cddcf2924b83c5ba2c21142cb4c626061fEvan Hunt * You should have received a copy of the GNU General Public License version
b716b9cddcf2924b83c5ba2c21142cb4c626061fEvan Hunt * 2 along with this work; if not, write to the Free Software Foundation,
9689922a0d936b04feb418fbaf4c1420f745ea58Mark Andrews * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
b716b9cddcf2924b83c5ba2c21142cb4c626061fEvan Hunt *
b716b9cddcf2924b83c5ba2c21142cb4c626061fEvan Hunt * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
9689922a0d936b04feb418fbaf4c1420f745ea58Mark Andrews * or visit www.oracle.com if you need additional information or have any
10966da999f8f7f364418aa446d8ead9c8a761cfMark Andrews * questions.
10966da999f8f7f364418aa446d8ead9c8a761cfMark Andrews */
9689922a0d936b04feb418fbaf4c1420f745ea58Mark Andrews
b716b9cddcf2924b83c5ba2c21142cb4c626061fEvan Hunt
b716b9cddcf2924b83c5ba2c21142cb4c626061fEvan Hunt#import <CoreFoundation/CoreFoundation.h>
9689922a0d936b04feb418fbaf4c1420f745ea58Mark Andrews#import <ApplicationServices/ApplicationServices.h>
b716b9cddcf2924b83c5ba2c21142cb4c626061fEvan Hunt#import <JavaNativeFoundation/JavaNativeFoundation.h>
b716b9cddcf2924b83c5ba2c21142cb4c626061fEvan Hunt
/*
* Class: sun_lwawt_macosx_CDesktopPeer
* Method: _lsOpenURI
* Signature: (Ljava/lang/String;)I;
*/
JNIEXPORT jint JNICALL Java_sun_lwawt_macosx_CDesktopPeer__1lsOpenURI
(JNIEnv *env, jclass clz, jstring uri)
{
// AWT_ASSERT_ANY_THREAD
OSStatus status = noErr;
JNF_COCOA_ENTER(env);
// I would love to use NSWorkspace here, but it's not thread safe. Why? I don't know.
// So we use LaunchServices directly.
NSURL *url = [NSURL URLWithString:JNFJavaToNSString(env, uri)];
LSLaunchFlags flags = kLSLaunchDefaults;
LSApplicationParameters params = {0, flags, NULL, NULL, NULL, NULL, NULL};
status = LSOpenURLsWithRole((CFArrayRef)[NSArray arrayWithObject:url], kLSRolesAll, NULL, &params, NULL, 0);
JNF_COCOA_EXIT(env);
return status;
}
/*
* Class: sun_lwawt_macosx_CDesktopPeer
* Method: _lsOpenFile
* Signature: (Ljava/lang/String;Z)I;
*/
JNIEXPORT jint JNICALL Java_sun_lwawt_macosx_CDesktopPeer__1lsOpenFile
(JNIEnv *env, jclass clz, jstring jpath, jboolean print)
{
// AWT_ASSERT_ANY_THREAD
OSStatus status = noErr;
JNF_COCOA_ENTER(env);
// I would love to use NSWorkspace here, but it's not thread safe. Why? I don't know.
// So we use LaunchServices directly.
NSString *path = JNFNormalizedNSStringForPath(env, jpath);
NSURL *url = [NSURL fileURLWithPath:(NSString *)path];
// This byzantine workaround is necesary, or else directories won't open in Finder
url = (NSURL *)CFURLCreateWithFileSystemPath(NULL, (CFStringRef)[url path], kCFURLPOSIXPathStyle, false);
LSLaunchFlags flags = kLSLaunchDefaults;
if (print) flags |= kLSLaunchAndPrint;
LSApplicationParameters params = {0, flags, NULL, NULL, NULL, NULL, NULL};
status = LSOpenURLsWithRole((CFArrayRef)[NSArray arrayWithObject:url], kLSRolesAll, NULL, &params, NULL, 0);
CFRelease(url);
JNF_COCOA_EXIT(env);
return status;
}