Back to index

lightning-sunbird  0.9+nobinonly
MRJPlugin.h
Go to the documentation of this file.
00001 /* ***** BEGIN LICENSE BLOCK *****
00002  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00003  *
00004  * The contents of this file are subject to the Mozilla Public License Version
00005  * 1.1 (the "License"); you may not use this file except in compliance with
00006  * the License. You may obtain a copy of the License at
00007  * http://www.mozilla.org/MPL/
00008  *
00009  * Software distributed under the License is distributed on an "AS IS" basis,
00010  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00011  * for the specific language governing rights and limitations under the
00012  * License.
00013  *
00014  * The Original Code is the MRJ Carbon OJI Plugin.
00015  *
00016  * The Initial Developer of the Original Code is
00017  * Netscape Communications Corp.
00018  * Portions created by the Initial Developer are Copyright (C) 2001
00019  * the Initial Developer. All Rights Reserved.
00020  *
00021  * Contributor(s):
00022  *   Patrick C. Beard <beard@netscape.com>
00023  *
00024  * Alternatively, the contents of this file may be used under the terms of
00025  * either of the GNU General Public License Version 2 or later (the "GPL"),
00026  * or 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 /*
00039     MRJPlugin.h
00040     
00041     MRJPlugin encapsulates the global state of the MRJ plugin as a single COM object.
00042     MRJPluginInstance represents an instance of the MRJ plugin.
00043     
00044     by Patrick C. Beard.
00045  */
00046 
00047 #pragma once
00048 
00049 #include "nsIPlugin.h"
00050 #include "nsIPluginInstance.h"
00051 #include "nsIJVMPlugin.h"
00052 #include "nsIJVMConsole.h"
00053 #include "nsIJVMPluginInstance.h"
00054 #include "nsIThreadManager.h"
00055 #include "nsIEventHandler.h"
00056 #include "nsIPluginStreamListener.h"
00057 #include "SupportsMixin.h"
00058 
00059 class MRJPlugin;
00060 class MRJPluginInstance;
00061 class MRJSession;
00062 class MRJContext;
00063 class MRJConsole;
00064 
00065 class nsIJVMManager;
00066 
00067 class MRJPlugin :   public nsIPlugin, public nsIJVMPlugin,
00068                     public nsIJVMConsole, public nsIRunnable,
00069                     public SupportsMixin {
00070 public:
00071     MRJPlugin();
00072     virtual ~MRJPlugin();
00073 
00074     static nsresult GetService(const nsCID &aCID, const nsIID& aIID, void* *aService);
00075     static nsresult GetService(const char* aContractID, const nsIID& aIID, void* *aService);
00076     
00077     // NS_DECL_ISUPPORTS
00078 #if USE_SYSTEM_CONSOLE
00079     DECL_SUPPORTS_MIXIN
00080 #else
00081     NS_IMETHOD QueryInterface(const nsIID& aIID, void** aInstancePtr);
00082     NS_IMETHOD_(nsrefcnt) AddRef(void) { return addRef(); }
00083     NS_IMETHOD_(nsrefcnt) Release(void) { return release(); }
00084 #endif
00085 
00086     // The Release method on NPIPlugin corresponds to NPP_Shutdown.
00087 
00088     // The old NPP_New call has been factored into two plugin instance methods:
00089     //
00090     // NewInstance -- called once, after the plugin instance is created. This 
00091     // method is used to initialize the new plugin instance (although the actual
00092     // plugin instance object will be created by the plugin manager).
00093     //
00094     // NPIPluginInstance::Start -- called when the plugin instance is to be
00095     // started. This happens in two circumstances: (1) after the plugin instance
00096     // is first initialized, and (2) after a plugin instance is returned to
00097     // (e.g. by going back in the window history) after previously being stopped
00098     // by the Stop method. 
00099 
00100     // nsIFactory Methods.
00101     
00102     NS_IMETHOD
00103     CreateInstance(nsISupports *aOuter, const nsIID& aIID, void **aResult);
00104 
00105     NS_IMETHOD
00106     LockFactory(PRBool aLock) { return NS_ERROR_NOT_IMPLEMENTED; }
00107 
00108     // nsIPlugin Methods.
00109     
00115     NS_IMETHOD CreatePluginInstance(nsISupports *aOuter, REFNSIID aIID, 
00116                                     const char* aPluginMIMEType,
00117                                     void **aResult);
00118 
00126     NS_IMETHOD
00127     Initialize(void);
00128 
00137     NS_IMETHOD
00138     Shutdown(void);
00139 
00152     NS_IMETHOD
00153     GetMIMEDescription(const char* *result);
00154 
00164     NS_IMETHOD
00165     GetValue(nsPluginVariable variable, void *value);
00166 
00167     // nsIJVMPlugin Methods.
00168 
00169     // This method us used to start the Java virtual machine.
00170     // It sets up any global state necessary to host Java programs.
00171     // Note that calling this method is distinctly separate from 
00172     // initializing the nsIJVMPlugin object (done by the Initialize
00173     // method).
00174     nsresult
00175     StartupJVM(void);
00176 
00177     // Causes the JVM to append a new directory to its classpath.
00178     // If the JVM doesn't support this operation, an error is returned.
00179     NS_IMETHOD
00180     AddToClassPath(const char* dirPath);
00181 
00182     // Causes the JVM to remove a directory from its classpath.
00183     // If the JVM doesn't support this operation, an error is returned.
00184     NS_IMETHOD
00185     RemoveFromClassPath(const char* dirPath)
00186     {
00187         return NS_ERROR_NOT_IMPLEMENTED;
00188     }
00189 
00190     // Returns the current classpath in use by the JVM.
00191     NS_IMETHOD
00192     GetClassPath(const char* *result);
00193 
00194     NS_IMETHOD
00195     GetJavaWrapper(JNIEnv* env, jint jsobj, jobject *jobj);
00196 
00204     NS_IMETHOD
00205     CreateSecureEnv(JNIEnv* proxyEnv, nsISecureEnv* *outSecureEnv);
00206 
00211     NS_IMETHOD
00212     SpendTime(PRUint32 timeMillis);
00213     
00214     NS_IMETHOD
00215     UnwrapJavaWrapper(JNIEnv* jenv, jobject jobj, jint* obj);
00216 
00217 
00218     // nsIJVMConsole methods
00219 
00220     NS_IMETHOD
00221     Show(void);
00222 
00223     NS_IMETHOD
00224     Hide(void);
00225 
00226     NS_IMETHOD
00227     IsVisible(PRBool *result);
00228     
00229     NS_IMETHOD
00230     Print(const char* msg, const char* encodingName = NULL);
00231 
00232     // nsIRunnable methods
00233 
00237     NS_IMETHOD
00238     Run();
00239     
00240     // NON-INTERFACE methods, for internal use only.
00241 
00242     MRJSession* getSession();
00243     nsIJVMManager* getManager();
00244     nsIThreadManager* getThreadManager();
00245 
00246     MRJPluginInstance* getPluginInstance(jobject applet);
00247     MRJPluginInstance* getPluginInstance(JNIEnv* jenv);
00248     
00249     Boolean inPluginThread();
00250     
00251 private:
00252     nsIJVMManager* mManager;
00253     nsIThreadManager* mThreadManager;
00254     MRJSession* mSession;
00255     MRJConsole* mConsole;
00256     nsPluginThread *mPluginThreadID;
00257     Boolean mIsEnabled;
00258     
00259     // support for SupportsMixin.
00260     static const InterfaceInfo sInterfaces[];
00261     static const UInt32 kInterfaceCount;
00262 };
00263 
00264 class MRJPluginInstance :   public nsIPluginInstance, public nsIJVMPluginInstance,
00265                             public nsIEventHandler, public nsIPluginStreamListener,
00266                             private SupportsMixin {
00267 public:
00268     MRJPluginInstance(MRJPlugin* plugin);
00269     virtual ~MRJPluginInstance();
00270 
00271     // NS_DECL_ISUPPORTS
00272     DECL_SUPPORTS_MIXIN
00273 
00274     // (Corresponds to NPP_HandleEvent.)
00275     NS_IMETHOD
00276     HandleEvent(nsPluginEvent* event, PRBool* handled);
00277 
00285     NS_IMETHOD
00286     Initialize(nsIPluginInstancePeer* peer);
00287 
00297     NS_IMETHOD
00298     GetPeer(nsIPluginInstancePeer* *result);
00299 
00308     NS_IMETHOD
00309     Start(void);
00310 
00319     NS_IMETHOD
00320     Stop(void);
00321 
00330     NS_IMETHOD
00331     Destroy(void);
00332 
00341     NS_IMETHOD
00342     SetWindow(nsPluginWindow* window);
00343 
00353     NS_IMETHOD
00354     NewStream(nsIPluginStreamListener** listener)
00355     {
00356         *listener = this;
00357         AddRef();
00358         return NS_OK;
00359     }
00360 
00369     NS_IMETHOD
00370     Print(nsPluginPrint* platformPrint);
00371 
00379     NS_IMETHOD
00380     GetValue(nsPluginInstanceVariable variable, void *value);
00381 
00382     // nsIJVMPluginInstance methods.
00383 
00384     // This method is called when LiveConnect wants to find the Java object
00385     // associated with this plugin instance, e.g. the Applet or JavaBean object.
00386     NS_IMETHOD
00387     GetJavaObject(jobject *result);
00388 
00389     NS_IMETHOD
00390     GetText(const char* *result)
00391     {
00392         *result = NULL;
00393         return NS_OK;
00394     }
00395 
00396     // nsIPluginStreamListener implementation.
00397     
00405     NS_IMETHOD
00406     OnStartBinding(nsIPluginStreamInfo* pluginInfo)
00407     {
00408         return NS_OK;
00409     }
00410 
00421     NS_IMETHOD
00422     OnDataAvailable(nsIPluginStreamInfo* pluginInfo, nsIInputStream* input, PRUint32 length);
00423 
00424     NS_IMETHOD
00425     OnFileAvailable(nsIPluginStreamInfo* pluginInfo, const char* fileName)
00426     {
00427         return NS_ERROR_NOT_IMPLEMENTED;
00428     }
00429     
00441     NS_IMETHOD
00442     OnStopBinding(nsIPluginStreamInfo* pluginInfo, nsresult status)
00443     {
00444         return NS_OK;
00445     }
00446 
00450     NS_IMETHOD
00451     GetStreamType(nsPluginStreamType *result)
00452     {
00453         *result = nsPluginStreamType_Normal;
00454         return NS_OK;
00455     }
00456 
00457     // Accessing the list of instances.
00458     static MRJPluginInstance* getInstances(void);
00459     MRJPluginInstance* getNextInstance(void);
00460     
00461     MRJContext* getContext(void);
00462     MRJSession* getSession(void);
00463 
00464 private:
00465     void pushInstance(void);
00466     void popInstance(void);
00467     void inspectInstance(Boolean isUpdateEvt);
00468 
00469 private:
00470     nsIPluginInstancePeer* mPeer;
00471     nsIWindowlessPluginInstancePeer* mWindowlessPeer;
00472     MRJPlugin* mPlugin;
00473     MRJSession* mSession;
00474     MRJContext* mContext;
00475     jobject mApplet;
00476     nsPluginWindow* mPluginWindow;
00477     
00478     // maintain a list of instances.
00479     MRJPluginInstance* mNext;
00480 
00481     // support for SupportsMixin.
00482     static const InterfaceInfo sInterfaces[];
00483     static const UInt32 kInterfaceCount;
00484 };