Back to index

lightning-sunbird  0.9+nobinonly
nsJVMManager.h
Go to the documentation of this file.
00001 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
00002 /* ***** BEGIN LICENSE BLOCK *****
00003  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00004  *
00005  * The contents of this file are subject to the Mozilla Public License Version
00006  * 1.1 (the "License"); you may not use this file except in compliance with
00007  * the License. You may obtain a copy of the License at
00008  * http://www.mozilla.org/MPL/
00009  *
00010  * Software distributed under the License is distributed on an "AS IS" basis,
00011  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00012  * for the specific language governing rights and limitations under the
00013  * License.
00014  *
00015  * The Original Code is mozilla.org code.
00016  *
00017  * The Initial Developer of the Original Code is
00018  * Netscape Communications Corporation.
00019  * Portions created by the Initial Developer are Copyright (C) 1998
00020  * the Initial Developer. All Rights Reserved.
00021  *
00022  * Contributor(s):
00023  *
00024  * Alternatively, the contents of this file may be used under the terms of
00025  * either the GNU General Public License Version 2 or later (the "GPL"), or
00026  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00027  * in which case the provisions of the GPL or the LGPL are applicable instead
00028  * of those above. If you wish to allow use of your version of this file only
00029  * under the terms of either the GPL or the LGPL, and not to allow others to
00030  * use your version of this file under the terms of the MPL, indicate your
00031  * decision by deleting the provisions above and replace them with the notice
00032  * and other provisions required by the GPL or the LGPL. If you do not delete
00033  * the provisions above, a recipient may use your version of this file under
00034  * the terms of any one of the MPL, the GPL or the LGPL.
00035  *
00036  * ***** END LICENSE BLOCK ***** */
00037 
00038 #ifndef nsJVMManager_h___
00039 #define nsJVMManager_h___
00040 
00041 #include "jvmmgr.h"
00042 #include "prtypes.h"
00043 #include "nscore.h"
00044 #include "jni.h"
00045 #include "jsdbgapi.h"
00046 #include "nsError.h"
00047 
00048 #include "nsjvm.h"
00049 #include "nsAgg.h"
00050 #include "jsjava.h"
00051 #include "nsVoidArray.h"
00052 #include "nsILiveConnectManager.h"
00053 
00054 #include "nsIObserver.h"
00055 
00056 class nsSymantecDebugManager;
00057 class nsIWebBrowserChrome;
00058 
00059 /*******************************************************************************
00060  * NsJVMManager is the interface to the JVM manager that the browser sees. All
00061  * files that want to include java services should include this header file.
00062  * nsIJVMManager is the more limited interface what the JVM plugin sees.
00063  ******************************************************************************/
00064 
00065 struct nsJVMManager : public nsIJVMManager, public nsIThreadManager, public nsILiveConnectManager, public nsIObserver {
00066 public:
00067 
00068     NS_DECL_AGGREGATED
00069 
00070     NS_DECL_NSIJVMMANAGER    
00071 
00072     NS_DECL_NSIOBSERVER
00073 
00074     /* from nsIThreadManager: */
00075     
00079        NS_IMETHOD
00080        GetCurrentThread(PRThread* *threadID);
00081 
00087        NS_IMETHOD
00088        Sleep(PRUint32 milli = 0);
00089 
00094        NS_IMETHOD
00095        EnterMonitor(void* address);
00096        
00100        NS_IMETHOD
00101        ExitMonitor(void* address);
00102        
00107        NS_IMETHOD
00108        Wait(void* address, PRUint32 milli = 0);
00109 
00113        NS_IMETHOD
00114        Notify(void* address);
00115 
00119        NS_IMETHOD
00120        NotifyAll(void* address);
00121        
00125        NS_IMETHOD
00126        CreateThread(PRThread **thread, nsIRunnable* runnable);
00127        
00134        NS_IMETHOD
00135        PostEvent(PRThread *thread, nsIRunnable* runnable, PRBool async);
00136 
00137        /* from nsILiveConnectManager: */
00138 
00142        NS_IMETHOD
00143     StartupLiveConnect(JSRuntime* runtime, PRBool& outStarted)
00144     {
00145        outStarted = MaybeStartupLiveConnect();
00146        return NS_OK;
00147     }
00148     
00152        NS_IMETHOD
00153     ShutdownLiveConnect(JSRuntime* runtime, PRBool& outShutdown)
00154     {
00155        outShutdown = MaybeShutdownLiveConnect();
00156        return NS_OK;
00157     }
00158 
00162        NS_IMETHOD
00163     IsLiveConnectEnabled(PRBool& outEnabled)
00164     {
00165        outEnabled = IsLiveConnectEnabled();
00166        return NS_OK;
00167     }
00168 
00172        NS_IMETHOD
00173     InitLiveConnectClasses(JSContext* context, JSObject* globalObject);
00174 
00178        NS_IMETHOD
00179        WrapJavaObject(JSContext* context, jobject javaObject, JSObject* *outJSObject);
00180 
00181     /* JVMMgr specific methods: */
00182 
00183     /* ====> From here on are things only called by the browser, not the plugin... */
00184     NS_IMETHOD
00185     GetClasspathAdditions(const char* *result);
00186 
00187     static NS_METHOD
00188     Create(nsISupports* outer, const nsIID& aIID, void* *aInstancePtr);
00189 
00190     nsIJVMPlugin* GetJVMPlugin(void) { return fJVM; }
00191 
00192     /* Unlike the nsIJVMPlugin::StartupJVM, this version handles putting
00193      * up any error dialog: */
00194     nsJVMStatus StartupJVM(void);
00195     nsJVMStatus ShutdownJVM(PRBool fullShutdown = PR_FALSE);
00196     nsJVMStatus GetJVMStatus(void);
00197     void SetJVMEnabled(PRBool enabled);
00198 
00199 #if 0    
00200     void        ReportJVMError(nsresult err);
00201     const char* GetJavaErrorString(JNIEnv* env);
00202 #endif
00203 
00204     nsresult    AddToClassPath(const char* dirPath);
00205     PRBool      MaybeStartupLiveConnect(void);
00206     PRBool      MaybeShutdownLiveConnect(void);
00207     PRBool      IsLiveConnectEnabled(void);
00208     JSJavaVM*   GetJSJavaVM(void) { return fJSJavaVM; }
00209 
00210 
00211     nsJVMManager(nsISupports* outer);
00212     virtual ~nsJVMManager(void);
00213 
00214 protected:    
00215 
00223     nsresult    GetChrome(nsIWebBrowserChrome **theChrome);
00224     const char* GetJavaErrorString(JRIEnv* env);
00225 
00226     nsIJVMPlugin*       fJVM;
00227     nsJVMStatus         fStatus;
00228     nsISupports*        fDebugManager;
00229     JSJavaVM *          fJSJavaVM;  
00230     nsVoidArray*        fClassPathAdditions;
00231     char*               fClassPathAdditionsString;
00232     PRBool              fStartupMessagePosted;
00233 };
00234 
00235 /*******************************************************************************
00236  * Symantec Debugger Stuff
00237  ******************************************************************************/
00238 
00239 class nsSymantecDebugManager : public nsISymantecDebugManager {
00240 public:
00241 
00242     NS_DECL_AGGREGATED
00243 
00244     NS_IMETHOD
00245     SetDebugAgentPassword(PRInt32 pwd);
00246 
00247     static NS_METHOD
00248     Create(nsISupports* outer, const nsIID& aIID, void* *aInstancePtr,
00249            nsJVMManager* nsJVMManager);
00250 
00251 protected:
00252     nsSymantecDebugManager(nsISupports* outer, nsJVMManager* nsJVMManager);
00253     virtual ~nsSymantecDebugManager(void);
00254 
00255     nsJVMManager* fJVMMgr;
00256 
00257 };
00258 
00260 
00261 #endif // nsJVMManager_h___