/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* 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.
*/
#import <pthread.h>
#import <objc/runtime.h>
#import <Cocoa/Cocoa.h>
#import <Security/AuthSession.h>
#import <JavaRuntimeSupport/JavaRuntimeSupport.h>
#import "NSApplicationAWT.h"
#import "PropertiesUtilities.h"
#import "ThreadUtilities.h"
#import "AWT_debug.h"
#import "ApplicationDelegate.h"
// The symbol is defined in libosxapp.dylib (ThreadUtilities.m)
// Indicates if AWT is running embedded (in SWT, FX, elsewhere)
// Indicates that the app has been started with -XstartOnFirstThread
// (directly or via WebStart settings), and AWT should not run its
// own event loop in this mode. Even if a loop isn't running yet,
// we expect an embedder (e.g. SWT) to start it some time later.
static bool ShouldPrintVerboseDebugging() {
static int debug = -1;
if (debug == -1) {
}
}
// This is the data necessary to have JNI_OnLoad wait for AppKit to start.
static void setUpAWTAppKit()
{
// Add CFRunLoopObservers to call into AWT so that AWT knows that the
// AWT thread (which is the AppKit main thread) is alive. This way AWT
// will not automatically shutdown.
NULL, // CFAllocator
kCFRunLoopAfterWaiting, // CFOptionFlags
true, // repeats
NSIntegerMax, // order
&BusyObserver, // CFRunLoopObserverCallBack
NULL); // CFRunLoopObserverContext
NULL, // CFAllocator
kCFRunLoopBeforeWaiting, // CFOptionFlags
true, // repeats
NSIntegerMin, // order
&NotBusyObserver, // CFRunLoopObserverCallBack
NULL); // CFRunLoopObserverContext
}
static void setUpAppKitThreadName()
{
// Set the java name of the AppKit main thread appropriately.
jmethodID currentThreadID = (*env)->GetStaticMethodID(env, threadClass, "currentThread", "()Ljava/lang/Thread;");
curThread = (*env)->CallStaticObjectMethod(env, threadClass, currentThreadID); // AWT_THREADING Safe (known object)
if (threadClass != NULL) {
}
}
}
}
}
// Returns true if java believes it is running headless
// Just access the property directly, instead of using GraphicsEnvironment.isHeadless.
// This is because this may be called while AWT is being loaded, and calling AWT
// while it is being loaded will deadlock.
}
NSString *swtWebStart = [PropertiesUtilities javaSystemPropertyForKey:@"com.apple.javaws.usingSWT" withEnv:env];
}
if (busy) {
static JNF_STATIC_MEMBER_CACHE(jm_notifyBusyMethod, jc_AWTAutoShutdown, "notifyToolkitThreadBusy", "()V");
} else {
static JNF_STATIC_MEMBER_CACHE(jm_notifyFreeMethod, jc_AWTAutoShutdown, "notifyToolkitThreadFree", "()V");
}
}
// This is only called with the selector kCFRunLoopAfterWaiting.
assert(what == kCFRunLoopAfterWaiting);
#endif /* PRODUCT_BUILD */
}
// This is only called with the selector kCFRunLoopBeforeWaiting.
assert(what == kCFRunLoopBeforeWaiting);
#endif /* PRODUCT_BUILD */
}
}
// This is an empty Obj-C object just so that -peformSelectorOnMainThread can be used.
@interface AWTStarter : NSObject { }
@end
return YES;
}
+ (BOOL) markAppAsDaemon {
}
// Headless: NO
// Embedded: BOTH
// Multiple Calls: NO
// Callers: AppKit's NSApplicationDidFinishLaunchingNotification or +[AWTStarter startAWT:]
// Signal that AppKit has started (or is already running).
}
{
// Headless: BOTH
// Embedded: BOTH
// Multiple Calls: NO
// Caller: JNI_OnLoad
// onMainThread is NOT the same at SWT mode!
// If the JVM was started on the first thread for SWT, but the SWT loads the AWT on a secondary thread,
// onMainThread here will be false but SWT mode will be true. If we are currently on the main thread, we don't
// need to throw AWT startup over to another thread.
if (verbose) {
NSString *msg = [NSString stringWithFormat:@"+[AWTStarter start headless:%d] { onMainThread:%d }", headless, onMainThread];
}
if (!headless)
{
// Listen for the NSApp to start. This indicates that JNI_OnLoad can proceed.
// It must wait because there is a chance that another java thread will grab
// the AppKit lock before the +[NSApplication sharedApplication] returns.
// See <rdar://problem/3492666> for an example.
if (verbose) NSLog(@"+[AWTStarter start:::]: registered NSApplicationDidFinishLaunchingNotification");
}
nil];
if (onMainThread) {
} else {
}
if (!headless && !onMainThread) {
// Wait here for AppKit to have started (or for AWT to have been loaded into
// an already running NSApplication).
while (sAppKitStarted == NO) {
}
// AWT gets here AFTER +[AWTStarter appKitIsRunning:] is called.
}
if (!headless) {
// Don't set the delegate until the NSApplication has been created and
// its finishLaunching has initialized it.
// ApplicationDelegate is the support code for com.apple.eawt.
}
}];
}
}
// Add the exception handler of last resort
// Headless mode trumps either ordinary AWT or SWT-in-AWT mode. Declare us a daemon and return.
if (headless) {
if (!forceEmbeddedMode) {
}
return;
}
if (forceEmbeddedMode) {
// Init a default NSApplication instance instead of the NSApplicationAWT.
// Note that [NSApp isRunning] will return YES after that, though
// this behavior isn't specified anywhere. We rely on that.
}
// This will create a NSApplicationAWT for standalone AWT programs, unless there is
// already a NSApplication instance. If there is already a NSApplication instance,
// and -[NSApplication isRunning] returns YES, AWT is embedded inside another
// AppKit Application.
if (!isEmbedded) {
// Install run loop observers and set the AppKit Java thread name
}
// AWT gets to this point BEFORE NSApplicationDidFinishLaunchingNotification is sent.
// This is where the AWT AppKit thread parks itself to process events.
} else {
// We're either embedded, or showing a splash screen
if (isEmbedded) {
// We don't track if the runloop is busy, so set it free to let AWT finish when it needs
} else {
}
// Signal so that JNI_OnLoad can proceed.
// Proceed to exit this call as there is no reason to run the NSApplication event loop.
}
}
@end
// Headless: BOTH
// Embedded: BOTH
// Multiple Calls: NO
// Caller: JavaVM classloader
// Keep a static reference for other archives.
// Need JNIEnv for JNF_COCOA_ENTER(env); macro below
AWT_DEBUG_LOG(@"Can't get JNIEnv");
return JNI_VERSION_1_4;
}
// Launcher sets this env variable if -XstartOnFirstThread is specified
char envVar[80];
}
if (isSWTInWebStart(env)) {
}
// We need to let Foundation know that this is a multithreaded application, if it isn't already.
if (![NSThread isMultiThreaded]) {
}
return JNI_VERSION_1_4;
}