1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /* ***** BEGIN LICENSE BLOCK *****
3 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
5 * The contents of this file are subject to the Mozilla Public License Version
6 * 1.1 (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 * http://www.mozilla.org/MPL/
10 * Software distributed under the License is distributed on an "AS IS" basis,
11 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 * for the specific language governing rights and limitations under the
15 * The Original Code is mozilla.org code.
17 * The Initial Developer of the Original Code is
18 * Netscape Communications Corporation.
19 * Portions created by the Initial Developer are Copyright (C) 1998
20 * the Initial Developer. All Rights Reserved.
24 * Alternatively, the contents of this file may be used under the terms of
25 * either the GNU General Public License Version 2 or later (the "GPL"), or
26 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
27 * in which case the provisions of the GPL or the LGPL are applicable instead
28 * of those above. If you wish to allow use of your version of this file only
29 * under the terms of either the GPL or the LGPL, and not to allow others to
30 * use your version of this file under the terms of the MPL, indicate your
31 * decision by deleting the provisions above and replace them with the notice
32 * and other provisions required by the GPL or the LGPL. If you do not delete
33 * the provisions above, a recipient may use your version of this file under
34 * the terms of any one of the MPL, the GPL or the LGPL.
36 * ***** END LICENSE BLOCK ***** */
38 #ifndef nsJVMManager_h___
39 #define nsJVMManager_h___
51 #include "nsVoidArray.h"
52 #include "nsILiveConnectManager.h"
54 #include "nsIObserver.h"
56 class nsSymantecDebugManager
;
57 class nsIWebBrowserChrome
;
59 /*******************************************************************************
60 * NsJVMManager is the interface to the JVM manager that the browser sees. All
61 * files that want to include java services should include this header file.
62 * nsIJVMManager is the more limited interface what the JVM plugin sees.
63 ******************************************************************************/
65 struct nsJVMManager
: public nsIJVMManager
, public nsIJVMThreadManager
,
66 public nsILiveConnectManager
, public nsIObserver
{
75 /* from nsIJVMThreadManager: */
78 * Returns a unique identifier for the "current" system thread.
81 GetCurrentThread(PRThread
* *threadID
);
84 * Pauses the current thread for the specified number of milliseconds.
85 * If milli is zero, then merely yields the CPU if another thread of
86 * greater or equal priority.
89 Sleep(PRUint32 milli
= 0);
92 * Creates a unique monitor for the specified address, and makes the
93 * current system thread the owner of the monitor.
96 EnterMonitor(void* address
);
99 * Exits the monitor associated with the address.
102 ExitMonitor(void* address
);
105 * Waits on the monitor associated with the address (must be entered already).
106 * If milli is 0, wait indefinitely.
109 Wait(void* address
, PRUint32 milli
= 0);
112 * Notifies a single thread waiting on the monitor associated with the address (must be entered already).
115 Notify(void* address
);
118 * Notifies all threads waiting on the monitor associated with the address (must be entered already).
121 NotifyAll(void* address
);
124 * Creates a new thread, calling the specified runnable's Run method (a la Java).
127 CreateThread(PRThread
**thread
, nsIRunnable
* runnable
);
130 * Posts an event to specified thread, calling the runnable from that thread.
131 * @param threadID thread to call runnable from
132 * @param runnable object to invoke from thread
133 * @param async if true, won't block current thread waiting for result
136 PostEvent(PRThread
*thread
, nsIRunnable
* runnable
, PRBool async
);
138 /* from nsILiveConnectManager: */
141 * Attempts to start LiveConnect using the specified JSRuntime.
144 StartupLiveConnect(JSRuntime
* runtime
, PRBool
& outStarted
)
146 outStarted
= MaybeStartupLiveConnect();
151 * Attempts to stop LiveConnect using the specified JSRuntime.
154 ShutdownLiveConnect(JSRuntime
* runtime
, PRBool
& outShutdown
)
156 outShutdown
= MaybeShutdownLiveConnect();
161 * Indicates whether LiveConnect can be used.
164 IsLiveConnectEnabled(PRBool
& outEnabled
)
166 outEnabled
= IsLiveConnectEnabled();
171 * Initializes a JSContext with the proper LiveConnect support classes.
174 InitLiveConnectClasses(JSContext
* context
, JSObject
* globalObject
);
177 * Creates a JavaScript wrapper for a Java object.
180 WrapJavaObject(JSContext
* context
, jobject javaObject
, JSObject
* *outJSObject
);
182 /* JVMMgr specific methods: */
184 /* ====> From here on are things only called by the browser, not the plugin... */
186 GetClasspathAdditions(const char* *result
);
188 nsIJVMPlugin
* GetJVMPlugin(void) { return fJVM
; }
190 /* Unlike the nsIJVMPlugin::StartupJVM, this version handles putting
191 * up any error dialog: */
192 nsJVMStatus
StartupJVM(void);
193 nsJVMStatus
ShutdownJVM(PRBool fullShutdown
= PR_FALSE
);
194 nsJVMStatus
GetJVMStatus(void);
195 void SetJVMEnabled(PRBool enabled
);
198 void ReportJVMError(nsresult err
);
199 const char* GetJavaErrorString(JNIEnv
* env
);
202 nsresult
AddToClassPath(const char* dirPath
);
203 PRBool
MaybeStartupLiveConnect(void);
204 PRBool
MaybeShutdownLiveConnect(void);
205 PRBool
IsLiveConnectEnabled(void);
206 JSJavaVM
* GetJSJavaVM(void) { return fJSJavaVM
; }
209 nsJVMManager(nsISupports
* outer
);
210 virtual ~nsJVMManager(void);
216 * @return conjure up THE nsIWebBrowserChrome instance from thin
221 nsresult
GetChrome(nsIWebBrowserChrome
**theChrome
);
222 const char* GetJavaErrorString(JRIEnv
* env
);
226 nsISupports
* fDebugManager
;
227 JSJavaVM
* fJSJavaVM
;
228 nsVoidArray
* fClassPathAdditions
;
229 char* fClassPathAdditionsString
;
230 PRBool fStartupMessagePosted
;
233 /*******************************************************************************
234 * Symantec Debugger Stuff
235 ******************************************************************************/
237 class nsSymantecDebugManager
: public nsISymantecDebugManager
{
243 SetDebugAgentPassword(PRInt32 pwd
);
246 Create(nsISupports
* outer
, const nsIID
& aIID
, void* *aInstancePtr
,
247 nsJVMManager
* nsJVMManager
);
250 nsSymantecDebugManager(nsISupports
* outer
, nsJVMManager
* nsJVMManager
);
251 virtual ~nsSymantecDebugManager(void);
253 nsJVMManager
* fJVMMgr
;
257 ////////////////////////////////////////////////////////////////////////////////
259 #endif // nsJVMManager_h___