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 mozilla.org code.
00015  *
00016  * The Initial Developer of the Original Code is
00017  * Netscape Communications Corporation.
00018  * Portions created by the Initial Developer are Copyright (C) 1998
00019  * the Initial Developer. All Rights Reserved.
00020  *
00021  * Contributor(s):
00022  *
00023  * Alternatively, the contents of this file may be used under the terms of
00024  * either of the GNU General Public License Version 2 or later (the "GPL"),
00025  * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00026  * in which case the provisions of the GPL or the LGPL are applicable instead
00027  * of those above. If you wish to allow use of your version of this file only
00028  * under the terms of either the GPL or the LGPL, and not to allow others to
00029  * use your version of this file under the terms of the MPL, indicate your
00030  * decision by deleting the provisions above and replace them with the notice
00031  * and other provisions required by the GPL or the LGPL. If you do not delete
00032  * the provisions above, a recipient may use your version of this file under
00033  * the terms of any one of the MPL, the GPL or the LGPL.
00034  *
00035  * ***** END LICENSE BLOCK ***** */
00036 
00037 /*
00038        MRJPlugin.h
00039        
00040        MRJPlugin encapsulates the global state of the MRJ plugin as a single COM object.
00041        MRJPluginInstance represents an instance of the MRJ plugin.
00042        
00043        by Patrick C. Beard.
00044  */
00045 
00046 #pragma once
00047 
00048 #include "nsIPlugin.h"
00049 #include "nsIJVMPlugin.h"
00050 #include "nsIThreadManager.h"
00051 #include "nsIPluginInstance.h"
00052 #include "nsIJVMPluginInstance.h"
00053 #include "nsIEventHandler.h"
00054 #include "nsIPluginStreamListener.h"
00055 #include "SupportsMixin.h"
00056 
00057 class MRJPlugin;
00058 class MRJPluginInstance;
00059 class MRJSession;
00060 class MRJContext;
00061 class MRJConsole;
00062 
00063 class nsIJVMManager;
00064 
00065 class MRJPlugin :    public nsIPlugin, public nsIJVMPlugin,
00066                                    public nsIRunnable, public SupportsMixin {
00067 public:
00068        MRJPlugin();
00069        virtual ~MRJPlugin();
00070        
00071     static nsresult GetService(const nsCID &aCID, const nsIID& aIID, void* *aService);
00072     static nsresult GetService(const char* aContractID, const nsIID& aIID, void* *aService);
00073 
00074        static const char* PLUGIN_VERSION;
00075        
00076        // Currently, this is a singleton, statically allocated object.
00077        void operator delete(void* ptr) {}
00078 
00079        // NS_DECL_ISUPPORTS
00080        NS_IMETHOD QueryInterface(const nsIID& aIID, void** aInstancePtr);
00081        NS_IMETHOD_(nsrefcnt) AddRef(void) { return addRef(); }
00082        NS_IMETHOD_(nsrefcnt) Release(void) { return release(); }
00083        
00084        // The Release method on NPIPlugin corresponds to NPP_Shutdown.
00085 
00086        // The old NPP_New call has been factored into two plugin instance methods:
00087        //
00088        // NewInstance -- called once, after the plugin instance is created. This 
00089        // method is used to initialize the new plugin instance (although the actual
00090        // plugin instance object will be created by the plugin manager).
00091        //
00092        // NPIPluginInstance::Start -- called when the plugin instance is to be
00093        // started. This happens in two circumstances: (1) after the plugin instance
00094        // is first initialized, and (2) after a plugin instance is returned to
00095        // (e.g. by going back in the window history) after previously being stopped
00096        // by the Stop method. 
00097 
00098        // nsIFactory Methods.
00099        
00100        NS_IMETHOD
00101        CreateInstance(nsISupports *aOuter, const nsIID& aIID, void **aResult);
00102 
00103        NS_IMETHOD
00104        LockFactory(PRBool aLock) { return NS_ERROR_NOT_IMPLEMENTED; }
00105 
00106        // nsIPlugin Methods.
00107        
00113     NS_IMETHOD CreatePluginInstance(nsISupports *aOuter, REFNSIID aIID, 
00114                                     const char* aPluginMIMEType,
00115                                     void **aResult);
00116 
00124     NS_IMETHOD
00125     Initialize(void);
00126 
00135     NS_IMETHOD
00136     Shutdown(void);
00137 
00150     NS_IMETHOD
00151     GetMIMEDescription(const char* *result);
00152 
00162     NS_IMETHOD
00163     GetValue(nsPluginVariable variable, void *value);
00164 
00165     // (Corresponds to NPP_SetValue.)
00166     NS_IMETHOD
00167     SetValue(nsPluginVariable variable, void *value);
00168 
00169        // JVM Plugin Methods.
00170 
00171     // This method us used to start the Java virtual machine.
00172     // It sets up any global state necessary to host Java programs.
00173     // Note that calling this method is distinctly separate from 
00174     // initializing the nsIJVMPlugin object (done by the Initialize
00175     // method).
00176     NS_IMETHOD
00177     StartupJVM(void);
00178 
00179     // This method us used to stop the Java virtual machine.
00180     // It tears down any global state necessary to host Java programs.
00181     // The fullShutdown flag specifies whether the browser is quitting
00182     // (PR_TRUE) or simply whether the JVM is being shut down (PR_FALSE).
00183     NS_IMETHOD
00184     ShutdownJVM(PRBool fullShutdown);
00185 
00186     // Causes the JVM to append a new directory to its classpath.
00187     // If the JVM doesn't support this operation, an error is returned.
00188     NS_IMETHOD
00189     AddToClassPath(const char* dirPath);
00190 
00191     // Causes the JVM to remove a directory from its classpath.
00192     // If the JVM doesn't support this operation, an error is returned.
00193     NS_IMETHOD
00194     RemoveFromClassPath(const char* dirPath)
00195     {
00196        return NS_ERROR_NOT_IMPLEMENTED;
00197     }
00198 
00199     // Returns the current classpath in use by the JVM.
00200     NS_IMETHOD
00201     GetClassPath(const char* *result);
00202 
00203     NS_IMETHOD
00204     GetJavaWrapper(JNIEnv* env, jint jsobj, jobject *jobj);
00205 
00206     NS_IMETHOD
00207     GetJavaVM(JavaVM* *result);
00208 
00209        // nsIJNIPlugin Methods.
00210 
00211     // Find or create a JNIEnv for the current thread.
00212     // Returns NULL if an error occurs.
00213     NS_IMETHOD_(nsrefcnt)
00214     GetJNIEnv(JNIEnv* *result);
00215 
00216     // This method must be called when the caller is done using the JNIEnv.
00217     // This decrements a refcount associated with it may free it.
00218     NS_IMETHOD_(nsrefcnt)
00219     ReleaseJNIEnv(JNIEnv* env);
00220 
00228        NS_IMETHOD
00229        CreateSecureEnv(JNIEnv* proxyEnv, nsISecureEnv* *outSecureEnv);
00230 
00235        NS_IMETHOD
00236        SpendTime(PRUint32 timeMillis);
00237        
00241        NS_IMETHOD
00242        Run();
00243        
00244        // NON-INTERFACE methods, for internal use only.
00245 
00246        MRJSession* getSession();
00247        nsIJVMManager* getManager();
00248        nsIThreadManager* getThreadManager();
00249 
00250        MRJPluginInstance* getPluginInstance(jobject applet);
00251     MRJPluginInstance* getPluginInstance(JNIEnv* jenv);
00252     
00253     Boolean inPluginThread();
00254        
00255        NS_IMETHOD
00256        UnwrapJavaWrapper(JNIEnv* jenv, jobject jobj, jint* obj);
00257 
00258 private:
00259        nsIJVMManager* mManager;
00260        nsIThreadManager* mThreadManager;
00261        MRJSession* mSession;
00262     MRJConsole* mConsole;
00263     nsPluginThread *mPluginThreadID;
00264        Boolean mIsEnabled;
00265        
00266        // support for SupportsMixin.
00267        static const InterfaceInfo sInterfaces[];
00268        static const UInt32 kInterfaceCount;
00269 };
00270 
00271 class MRJPluginInstance :   public nsIPluginInstance, public nsIJVMPluginInstance,
00272                                                  public nsIEventHandler, public nsIPluginStreamListener,
00273                                                  private SupportsMixin {
00274 public:
00275        MRJPluginInstance(MRJPlugin* plugin);
00276        virtual ~MRJPluginInstance();
00277 
00278        // NS_DECL_ISUPPORTS
00279        DECL_SUPPORTS_MIXIN
00280 
00281     // (Corresponds to NPP_HandleEvent.)
00282     NS_IMETHOD
00283     HandleEvent(nsPluginEvent* event, PRBool* handled);
00284 
00292     NS_IMETHOD
00293     Initialize(nsIPluginInstancePeer* peer);
00294 
00304     NS_IMETHOD
00305     GetPeer(nsIPluginInstancePeer* *result);
00306 
00315     NS_IMETHOD
00316     Start(void);
00317 
00326        NS_IMETHOD
00327        Stop(void);
00328 
00337        NS_IMETHOD
00338        Destroy(void);
00339 
00348        NS_IMETHOD
00349        SetWindow(nsPluginWindow* window);
00350 
00360     NS_IMETHOD
00361     NewStream(nsIPluginStreamListener** listener)
00362        {
00363               *listener = this;
00364               AddRef();
00365               return NS_OK;
00366        }
00367 
00376     NS_IMETHOD
00377     Print(nsPluginPrint* platformPrint);
00378 
00386     NS_IMETHOD
00387     GetValue(nsPluginInstanceVariable variable, void *value);
00388 
00389        // nsIJVMPluginInstance methods.
00390 
00391     // This method is called when LiveConnect wants to find the Java object
00392     // associated with this plugin instance, e.g. the Applet or JavaBean object.
00393     NS_IMETHOD
00394     GetJavaObject(jobject *result);
00395 
00396     NS_IMETHOD
00397     GetText(const char* *result)
00398     {
00399         *result = NULL;
00400        return NS_OK;
00401     }
00402 
00403        // nsIPluginStreamListener implementation.
00404        
00412     NS_IMETHOD
00413     OnStartBinding(nsIPluginStreamInfo* pluginInfo)
00414     {
00415        return NS_OK;
00416     }
00417 
00428     NS_IMETHOD
00429     OnDataAvailable(nsIPluginStreamInfo* pluginInfo, nsIInputStream* input, PRUint32 length);
00430 
00431     NS_IMETHOD
00432     OnFileAvailable(nsIPluginStreamInfo* pluginInfo, const char* fileName)
00433     {
00434               return NS_ERROR_NOT_IMPLEMENTED;
00435        }
00436        
00448     NS_IMETHOD
00449     OnStopBinding(nsIPluginStreamInfo* pluginInfo, nsresult status)
00450     {
00451        return NS_OK;
00452     }
00453 
00457     NS_IMETHOD
00458     GetStreamType(nsPluginStreamType *result)
00459     {
00460        *result = nsPluginStreamType_Normal;
00461        return NS_OK;
00462     }
00463 
00464     // Accessing the list of instances.
00465     static MRJPluginInstance* getInstances(void);
00466     MRJPluginInstance* getNextInstance(void);
00467     
00468     MRJContext* getContext(void);
00469     MRJSession* getSession(void);
00470 
00471 private:
00472        void pushInstance(void);
00473        void popInstance(void);
00474        void inspectInstance(Boolean isUpdateEvt);
00475 
00476 private:
00477     nsIPluginInstancePeer* mPeer;
00478     nsIWindowlessPluginInstancePeer* mWindowlessPeer;
00479     MRJPlugin* mPlugin;
00480     MRJSession* mSession;
00481     MRJContext* mContext;
00482     jobject mApplet;
00483     nsPluginWindow* mPluginWindow;
00484     
00485     // maintain a list of instances.
00486     MRJPluginInstance* mNext;
00487 
00488        // support for SupportsMixin.
00489        static const InterfaceInfo sInterfaces[];
00490        static const UInt32 kInterfaceCount;
00491 };