diff --git a/mozilla/java/plugins/classes/org/mozilla/pluglet/Registry.java b/mozilla/java/plugins/classes/org/mozilla/pluglet/Registry.java new file mode 100644 index 00000000000..1d3f5e59f9d --- /dev/null +++ b/mozilla/java/plugins/classes/org/mozilla/pluglet/Registry.java @@ -0,0 +1,45 @@ +/* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * The contents of this file are subject to the Mozilla Public License + * Version 1.0 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * Software distributed under the License is distributed on an "AS IS" + * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See + * the License for the specific language governing rights and limitations + * under the License. + * + * The Initial Developer of the Original Code is Sun Microsystems, + * Inc. Portions created by Sun are Copyright (C) 1999 Sun Microsystems, + * Inc. All Rights Reserved. + */ +package org.mozilla.pluglet; + +import java.util.*; + +public class Registry { + static Hashtable table = null; + public static void setPeer(Object key,long peer) { + if (table == null) { + table = new Hashtable(10); + } + table.put(key, new Long(peer)); + } + public static long getPeer(Object key) { + if (table == null) { + return 0; + } + Object obj = table.get(key); + if (obj == null) { + return 0; + } else { + return ((Long)obj).longValue(); + } + } + public static void remove(Object key) { + if (table != null) { + table.remove(key); + } + } + +} diff --git a/mozilla/java/plugins/src/Pluglet.cpp b/mozilla/java/plugins/src/Pluglet.cpp index d2df9b172db..4a3ab446069 100644 --- a/mozilla/java/plugins/src/Pluglet.cpp +++ b/mozilla/java/plugins/src/Pluglet.cpp @@ -49,7 +49,7 @@ nsresult Pluglet::CreatePluginInstance(const char* aPluginMIMEType, void **aResu nsresult Pluglet::Initialize(void) { JNIEnv *env = PlugletEngine::GetJNIEnv(); if(!env) { - return NS_ERROR_FAILURE; + return NS_ERROR_FAILURE; } if (!initializeMID) { jclass clazz = env->FindClass("org/mozilla/pluglet/Pluglet"); diff --git a/mozilla/java/plugins/src/PlugletInstance.cpp b/mozilla/java/plugins/src/PlugletInstance.cpp index 819cc9d0f30..a1989b8c746 100644 --- a/mozilla/java/plugins/src/PlugletInstance.cpp +++ b/mozilla/java/plugins/src/PlugletInstance.cpp @@ -1,4 +1,4 @@ -/* +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- * The contents of this file are subject to the Mozilla Public License * Version 1.0 (the "License"); you may not use this file except in * compliance with the License. You may obtain a copy of the License at @@ -17,7 +17,7 @@ #include "PlugletEngine.h" #include "PlugletStreamListener.h" #include "PlugletInstancePeer.h" - +#include "Registry.h" jmethodID PlugletInstance::initializeMID = NULL; jmethodID PlugletInstance::startMID = NULL; @@ -37,9 +37,11 @@ PlugletInstance::PlugletInstance(jobject object) { //nb check for null peer = NULL; view = new PlugletInstanceView(); + Registry::SetPeer(jthis,(jlong)this); } PlugletInstance::~PlugletInstance() { + Registry::Remove(jthis); PlugletEngine::GetJNIEnv()->DeleteGlobalRef(jthis); NS_RELEASE(peer); } diff --git a/mozilla/java/plugins/src/PlugletInstance.h b/mozilla/java/plugins/src/PlugletInstance.h index 573b4ea9631..65fbb08bcb7 100644 --- a/mozilla/java/plugins/src/PlugletInstance.h +++ b/mozilla/java/plugins/src/PlugletInstance.h @@ -15,8 +15,8 @@ */ #ifndef __PlugletInstance_h__ #define __PlugletInstance_h__ -#include "jni.h" #include "nsplugin.h" +#include "jni.h" #include "PlugletInstanceView.h" class PlugletInstance : public nsIPluginInstance { diff --git a/mozilla/java/plugins/src/Registry.cpp b/mozilla/java/plugins/src/Registry.cpp new file mode 100644 index 00000000000..1c890cc30e6 --- /dev/null +++ b/mozilla/java/plugins/src/Registry.cpp @@ -0,0 +1,87 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * The contents of this file are subject to the Mozilla Public License + * Version 1.0 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * Software distributed under the License is distributed on an "AS IS" + * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See + * the License for the specific language governing rights and limitations + * under the License. + * + * The Initial Developer of the Original Code is Sun Microsystems, + * Inc. Portions created by Sun are Copyright (C) 1999 Sun Microsystems, + * Inc. All Rights Reserved. + */ + +#include "PlugletEngine.h" +#include "Registry.h" + +jclass Registry::clazz = NULL; +jmethodID Registry::setPeerMID = NULL; +jmethodID Registry::removeMID = NULL; + +void Registry::SetPeer(jobject key, jlong peer) { + if (!clazz) { + Initialize(); + if(!clazz) { + return; + } + } + JNIEnv *env = PlugletEngine::GetJNIEnv(); + env->CallStaticVoidMethod(clazz,setPeerMID,key,peer); + if (env->ExceptionOccurred()) { + env->ExceptionDescribe(); + return; + } +} + +void Registry::Remove(jobject key) { + if (!clazz) { // it is impossible + Initialize(); + if(!clazz) { + return; + } + } + JNIEnv *env = PlugletEngine::GetJNIEnv(); + env->CallStaticVoidMethod(clazz,removeMID,key); + if (env->ExceptionOccurred()) { + env->ExceptionDescribe(); + return; + } +} + +void Registry::Initialize() { + JNIEnv *env = PlugletEngine::GetJNIEnv(); + if(!env) { + return; + } + clazz = env->FindClass("org/mozilla/pluglet/Registry"); + if(!clazz) { + env->ExceptionDescribe(); + return; + } + setPeerMID = env->GetStaticMethodID(clazz,"setPeer","(Ljava/lang/Object;J)V"); + if (!setPeerMID) { + env->ExceptionDescribe(); + clazz = NULL; + return; + } + removeMID = env->GetStaticMethodID(clazz,"remove","(Ljava/lang/Object;)V"); + if (!removeMID) { + env->ExceptionDescribe(); + clazz = NULL; + return; + } +} + + + + + + + + + + + diff --git a/mozilla/java/plugins/src/Registry.h b/mozilla/java/plugins/src/Registry.h new file mode 100644 index 00000000000..9bf3f325139 --- /dev/null +++ b/mozilla/java/plugins/src/Registry.h @@ -0,0 +1,33 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * The contents of this file are subject to the Mozilla Public License + * Version 1.0 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * Software distributed under the License is distributed on an "AS IS" + * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See + * the License for the specific language governing rights and limitations + * under the License. + * + * The Initial Developer of the Original Code is Sun Microsystems, + * Inc. Portions created by Sun are Copyright (C) 1999 Sun Microsystems, + * Inc. All Rights Reserved. + */ +#ifndef __Registry_h__ +#define __Registry_h__ +#include "jni.h" +class Registry { +public: + static void SetPeer(jobject key, jlong peer); + static void Remove(jobject key); +private: + static void Initialize(); + static jclass clazz; + static jmethodID setPeerMID; + static jmethodID removeMID; +}; +#endif /* __Registry_h__ */ + + + + diff --git a/mozilla/java/plugins/src/makefile.win b/mozilla/java/plugins/src/makefile.win index 47e30e577b0..e3d13e78920 100644 --- a/mozilla/java/plugins/src/makefile.win +++ b/mozilla/java/plugins/src/makefile.win @@ -57,7 +57,8 @@ OBJS = \ .\$(OBJDIR)\PlugletInstancePeer.obj \ .\$(OBJDIR)\PlugletManager.obj \ .\$(OBJDIR)\PlugletInputStream.obj \ - .\$(OBJDIR)\PlugletInstanceView.obj + .\$(OBJDIR)\PlugletInstanceView.obj \ + .\$(OBJDIR)\Registry.obj MAKE_OBJ_TYPE = DLL