Backed out changeset fa432b23baa5. (Backing out bug 454781 to investigate mochitest...
[wine-gecko.git] / modules / oji / src / nsJVMManager.h
blob679cbed5bbe5c00c878cdbee41a426ac968ae97e
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
13 * License.
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.
22 * Contributor(s):
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___
41 #include "jvmmgr.h"
42 #include "prtypes.h"
43 #include "nscore.h"
44 #include "jni.h"
45 #include "jsdbgapi.h"
46 #include "nsError.h"
48 #include "nsjvm.h"
49 #include "nsAgg.h"
50 #include "jsjava.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 {
67 public:
69 NS_DECL_AGGREGATED
71 NS_DECL_NSIJVMMANAGER
73 NS_DECL_NSIOBSERVER
75 /* from nsIJVMThreadManager: */
77 /**
78 * Returns a unique identifier for the "current" system thread.
80 NS_IMETHOD
81 GetCurrentThread(PRThread* *threadID);
83 /**
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.
88 NS_IMETHOD
89 Sleep(PRUint32 milli = 0);
91 /**
92 * Creates a unique monitor for the specified address, and makes the
93 * current system thread the owner of the monitor.
95 NS_IMETHOD
96 EnterMonitor(void* address);
98 /**
99 * Exits the monitor associated with the address.
101 NS_IMETHOD
102 ExitMonitor(void* address);
105 * Waits on the monitor associated with the address (must be entered already).
106 * If milli is 0, wait indefinitely.
108 NS_IMETHOD
109 Wait(void* address, PRUint32 milli = 0);
112 * Notifies a single thread waiting on the monitor associated with the address (must be entered already).
114 NS_IMETHOD
115 Notify(void* address);
118 * Notifies all threads waiting on the monitor associated with the address (must be entered already).
120 NS_IMETHOD
121 NotifyAll(void* address);
124 * Creates a new thread, calling the specified runnable's Run method (a la Java).
126 NS_IMETHOD
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
135 NS_IMETHOD
136 PostEvent(PRThread *thread, nsIRunnable* runnable, PRBool async);
138 /* from nsILiveConnectManager: */
141 * Attempts to start LiveConnect using the specified JSRuntime.
143 NS_IMETHOD
144 StartupLiveConnect(JSRuntime* runtime, PRBool& outStarted)
146 outStarted = MaybeStartupLiveConnect();
147 return NS_OK;
151 * Attempts to stop LiveConnect using the specified JSRuntime.
153 NS_IMETHOD
154 ShutdownLiveConnect(JSRuntime* runtime, PRBool& outShutdown)
156 outShutdown = MaybeShutdownLiveConnect();
157 return NS_OK;
161 * Indicates whether LiveConnect can be used.
163 NS_IMETHOD
164 IsLiveConnectEnabled(PRBool& outEnabled)
166 outEnabled = IsLiveConnectEnabled();
167 return NS_OK;
171 * Initializes a JSContext with the proper LiveConnect support classes.
173 NS_IMETHOD
174 InitLiveConnectClasses(JSContext* context, JSObject* globalObject);
177 * Creates a JavaScript wrapper for a Java object.
179 NS_IMETHOD
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... */
185 NS_IMETHOD
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);
197 #if 0
198 void ReportJVMError(nsresult err);
199 const char* GetJavaErrorString(JNIEnv* env);
200 #endif
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);
212 protected:
216 * @return conjure up THE nsIWebBrowserChrome instance from thin
217 * air!
221 nsresult GetChrome(nsIWebBrowserChrome **theChrome);
222 const char* GetJavaErrorString(JRIEnv* env);
224 nsIJVMPlugin* fJVM;
225 nsJVMStatus fStatus;
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 {
238 public:
240 NS_DECL_AGGREGATED
242 NS_IMETHOD
243 SetDebugAgentPassword(PRInt32 pwd);
245 static NS_METHOD
246 Create(nsISupports* outer, const nsIID& aIID, void* *aInstancePtr,
247 nsJVMManager* nsJVMManager);
249 protected:
250 nsSymantecDebugManager(nsISupports* outer, nsJVMManager* nsJVMManager);
251 virtual ~nsSymantecDebugManager(void);
253 nsJVMManager* fJVMMgr;
257 ////////////////////////////////////////////////////////////////////////////////
259 #endif // nsJVMManager_h___