From 4c8fa254d76f74df9e4543bbb5f96f8ef58eab2e Mon Sep 17 00:00:00 2001 From: "pedemont%us.ibm.com" Date: Wed, 27 Sep 2006 15:16:51 +0000 Subject: [PATCH] Bug 281102 - Allow many Java proxies per XPCOM object. r=darin Original committer: pedemont%us.ibm.com Original revision: 1.8 Original date: 2005/02/24 21:53:45 git-svn-id: svn://10.0.0.236/trunk@212567 18797224-902f-48f8-a5cc-f745e15eee43 --- .../java/xpcom/src/nsJavaXPTCStub.h | 34 ++++++++++--------- 1 file changed, 18 insertions(+), 16 deletions(-) diff --git a/mozilla/extensions/java/xpcom/src/nsJavaXPTCStub.h b/mozilla/extensions/java/xpcom/src/nsJavaXPTCStub.h index b30d1a2ad1e..753b8aa02ca 100644 --- a/mozilla/extensions/java/xpcom/src/nsJavaXPTCStub.h +++ b/mozilla/extensions/java/xpcom/src/nsJavaXPTCStub.h @@ -53,6 +53,8 @@ class nsJavaXPTCStub : public nsXPTCStubBase, public nsSupportsWeakReference { + friend class nsJavaXPTCStubWeakRef; + public: NS_DECL_ISUPPORTS NS_DECL_NSISUPPORTSWEAKREFERENCE @@ -76,14 +78,23 @@ public: jobject GetJavaObject(); private: -// NS_HIDDEN ~JavaStub(); + NS_IMETHOD_(nsrefcnt) AddRefInternal(); + NS_IMETHOD_(nsrefcnt) ReleaseInternal(); + + // Deletes this object and its members. Called by ReleaseInternal() and + // ReleaseWeakRef(). + void Destroy(); + + // When a nsJavaXPTCStubWeakRef associated with this object is released, it + // calls this function to let this object know that there is one less weak + // ref. If there are no more weakrefs referencing this object, and no one + // holds a strong ref, then this function takes care of deleting the object. + void ReleaseWeakRef(); // returns a weak reference to a child supporting the specified interface -// NS_HIDDEN_(JavaStub *) FindStubSupportingIID(const nsID &aIID); nsJavaXPTCStub * FindStubSupportingIID(const nsID &aIID); // returns true if this stub supports the specified interface -// NS_HIDDEN_(PRBool) SupportsIID(const nsID &aIID); PRBool SupportsIID(const nsID &aIID); nsresult SetupJavaParams(const nsXPTParamInfo &aParamInfo, @@ -103,23 +114,14 @@ private: nsresult SetXPCOMRetval(); JNIEnv* mJavaEnv; - jobject mJavaObject; + jweak mJavaWeakRef; + jobject mJavaStrongRef; nsCOMPtr mIInfo; nsVoidArray mChildren; // weak references (cleared by the children) nsJavaXPTCStub *mMaster; // strong reference + + nsAutoRefCnt mWeakRefCnt; // count for number of associated weak refs }; -inline void* SetAsXPTCStub(nsJavaXPTCStub* ptr) - { NS_PRECONDITION(ptr, "null pointer"); - return (void*) (((unsigned long) ptr) | 0x1); } - -inline PRBool IsXPTCStub(void* ptr) - { NS_PRECONDITION(ptr, "null pointer"); - return ((unsigned long) ptr) & 0x1; } - -inline nsJavaXPTCStub* GetXPTCStubAddr(void* ptr) - { NS_PRECONDITION(ptr, "null pointer"); - return (nsJavaXPTCStub*) (((unsigned long) ptr) & ~0x1); } - #endif // _nsJavaXPTCStub_h_