From dcb61be6c12075506b08ac9f6fec3dd522a705d7 Mon Sep 17 00:00:00 2001 From: "beard%netscape.com" Date: Wed, 7 Nov 2001 03:58:00 +0000 Subject: [PATCH] [not part of build] Implemented getApplet() for LiveConnect scripting of applets. git-svn-id: svn://10.0.0.236/trunk@107549 18797224-902f-48f8-a5cc-f745e15eee43 --- .../oji/MRJCarbon/plugin/Source/MRJContext.cp | 46 +++++++++++++++++-- .../oji/MRJCarbon/plugin/Source/MRJContext.h | 1 + 2 files changed, 44 insertions(+), 3 deletions(-) diff --git a/mozilla/plugin/oji/MRJCarbon/plugin/Source/MRJContext.cp b/mozilla/plugin/oji/MRJCarbon/plugin/Source/MRJContext.cp index 482e0dcd3d2..5f4778e55f8 100644 --- a/mozilla/plugin/oji/MRJCarbon/plugin/Source/MRJContext.cp +++ b/mozilla/plugin/oji/MRJCarbon/plugin/Source/MRJContext.cp @@ -116,7 +116,7 @@ MRJContext::MRJContext(MRJSession* session, MRJPluginInstance* instance) mPluginWindow(NULL), mPluginClipping(NULL), mPluginPort(NULL), mDocumentBase(NULL), mAppletHTML(NULL), mPage(NULL), mSecurityContext(NULL) #if TARGET_CARBON - , mAppletFrame(NULL), mAppletControl(NULL), mScrollCounter(0) + , mAppletFrame(NULL), mAppletObject(NULL), mAppletControl(NULL), mScrollCounter(0) #endif { instance->GetPeer(&mPeer); @@ -191,6 +191,10 @@ MRJContext::~MRJContext() #if TARGET_CARBON if (mSession) { JNIEnv* env = mSession->getCurrentEnv(); + if (mAppletObject != NULL) { + env->DeleteGlobalRef(mAppletObject); + mAppletObject = NULL; + } if (mAppletFrame != NULL) { OSStatus status; @@ -1240,10 +1244,47 @@ void MRJContext::resumeApplet() #endif } +static const char* getAttribute(nsIPluginInstancePeer* peer, const char* name) +{ + const char* value = NULL; + nsIPluginTagInfo* tagInfo = NULL; + if (NS_SUCCEEDED(peer->QueryInterface(NS_GET_IID(nsIPluginTagInfo), (void**)&tagInfo))) { + tagInfo->GetAttribute(name, &value); + NS_RELEASE(tagInfo); + } + return value; +} + jobject MRJContext::getApplet() { #if TARGET_CARBON - // we'll have a member variable for this. + if (appletLoaded() && mAppletObject == NULL) { + // mAppletFrame implements the interface java.applet.AppletContext, as of Mac OS X 10.1. + // This code simply looks for the getApplet(String) accessor method of whatever class the object happens + // to be. Hopefully Apple will maintain this level of compatibility. + JNIEnv* env = mSession->getCurrentEnv(); + jclass frameClass = env->GetObjectClass(mAppletFrame); + if (frameClass) { + jmethodID getAppletMethod = env->GetMethodID(frameClass, "getApplet", "(Ljava/lang/String;)Ljava/applet/Applet;"); + if (getAppletMethod) { + jstring name = env->NewStringUTF(getAttribute(mPeer, "name")); + if (name) { + jobject applet = env->CallObjectMethod(mAppletFrame, getAppletMethod, name); + env->DeleteLocalRef(name); + if (applet) { + mAppletObject = env->NewGlobalRef(applet); + env->DeleteLocalRef(applet); + } + } else { + // FIXME: use the getApplets() call when we don't have the name of the apple in question. + } + } else { + env->ExceptionClear(); + } + env->DeleteLocalRef(frameClass); + } + } + return mAppletObject; #else if (appletLoaded() && &::JMGetAppletJNIObject != NULL) { JNIEnv* env = ::JMGetCurrentEnv(mSessionRef); @@ -1275,7 +1316,6 @@ jobject MRJContext::getApplet() return appletObject; } #endif - return NULL; } nsIPluginInstance* MRJContext::getInstance() diff --git a/mozilla/plugin/oji/MRJCarbon/plugin/Source/MRJContext.h b/mozilla/plugin/oji/MRJCarbon/plugin/Source/MRJContext.h index 0c4cf2aadc3..de0ad6ea9d0 100644 --- a/mozilla/plugin/oji/MRJCarbon/plugin/Source/MRJContext.h +++ b/mozilla/plugin/oji/MRJCarbon/plugin/Source/MRJContext.h @@ -181,6 +181,7 @@ private: MRJSecurityContext* mSecurityContext; #ifdef TARGET_CARBON jobject mAppletFrame; + jobject mAppletObject; ControlRef mAppletControl; UInt32 mScrollCounter; #endif