Back to index

lightning-sunbird  0.9+nobinonly
ns4xPlugin.h
Go to the documentation of this file.
00001 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
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 ns4xPlugin_h__
00039 #define ns4xPlugin_h__
00040 
00041 #include "nsIPlugin.h"
00042 #include "nsIPluginInstancePeer.h"
00043 #include "nsIWindowlessPlugInstPeer.h"
00044 #include "prlink.h"  // for PRLibrary
00045 #include "npupp.h"
00046 #include "nsPluginHostImpl.h"
00047 
00049 
00050 /*
00051  * Use this macro before each exported function
00052  * (between the return address and the function
00053  * itself), to ensure that the function has the
00054  * right calling conventions on Win16.
00055  */
00056 
00057 #ifdef XP_OS2
00058 #define NP_EXPORT _System
00059 #else
00060 #define NP_EXPORT
00061 #endif
00062 
00063 #if defined(XP_WIN)
00064 #define NS_4XPLUGIN_CALLBACK(_type, _name) _type (__stdcall * _name)
00065 #elif defined(XP_OS2)
00066 #define NS_4XPLUGIN_CALLBACK(_type, _name) _type (_System * _name)
00067 #else
00068 #define NS_4XPLUGIN_CALLBACK(_type, _name) _type (* _name)
00069 #endif
00070 
00072 
00073 // XXX These are defined in platform specific FE directories right now :-/
00074 
00075 #if defined(XP_WIN) || defined(XP_UNIX) || defined(XP_BEOS) || defined(XP_OS2)
00076 typedef NS_4XPLUGIN_CALLBACK(NPError, NP_GETENTRYPOINTS) (NPPluginFuncs* pCallbacks);
00077 typedef NS_4XPLUGIN_CALLBACK(NPError, NP_PLUGININIT) (const NPNetscapeFuncs* pCallbacks);
00078 typedef NS_4XPLUGIN_CALLBACK(NPError, NP_PLUGINUNIXINIT) (const NPNetscapeFuncs* pCallbacks,NPPluginFuncs* fCallbacks);
00079 typedef NS_4XPLUGIN_CALLBACK(NPError, NP_PLUGINSHUTDOWN) (void);
00080 #endif
00081 
00082 #if defined(XP_MAC) || defined(XP_MACOSX)
00083 typedef NS_4XPLUGIN_CALLBACK(NPError, NP_PLUGINSHUTDOWN) (void);
00084 typedef NS_4XPLUGIN_CALLBACK(NPError, NP_MAIN) (NPNetscapeFuncs* nCallbacks, NPPluginFuncs* pCallbacks, NPP_ShutdownUPP* unloadUpp);
00085 #endif
00086 
00087 class nsIServiceManagerObsolete;
00088 class nsIMemory;
00089 
00091 
00096 class ns4xPlugin : public nsIPlugin
00097 {
00098 public:
00099   ns4xPlugin(NPPluginFuncs* callbacks, PRLibrary* aLibrary,
00100              NP_PLUGINSHUTDOWN aShutdown,
00101              nsIServiceManagerObsolete* serviceMgr);
00102   virtual ~ns4xPlugin(void);
00103 
00104   NS_DECL_ISUPPORTS
00105 
00106   //nsIFactory interface
00107 
00108   NS_IMETHOD CreateInstance(nsISupports *aOuter,
00109                             REFNSIID aIID,
00110                             void **aResult);
00111 
00112   NS_IMETHOD LockFactory(PRBool aLock);
00113 
00114   //nsIPlugin interface
00115 
00121   NS_IMETHOD CreatePluginInstance(nsISupports *aOuter, REFNSIID aIID, 
00122                                   const char* aPluginMIMEType,
00123                                   void **aResult);
00124   
00125   NS_IMETHOD Initialize(void);
00126 
00127   NS_IMETHOD Shutdown(void);
00128 
00129   NS_IMETHOD GetMIMEDescription(const char* *resultingDesc);
00130 
00131   NS_IMETHOD GetValue(nsPluginVariable variable, void *value);
00132 
00134   // ns4xPlugin-specific methods
00135 
00142   static nsresult
00143   CreatePlugin(nsIServiceManagerObsolete* aServiceMgr,
00144                const char* aFileName,
00145                const char* aFullPath,
00146                PRLibrary* aLibrary,
00147                nsIPlugin** aResult);
00148 
00149 #if defined(XP_MAC) || defined(XP_MACOSX)
00150   void
00151   SetPluginRefNum(short aRefNum);
00152 #endif
00153 
00154 protected:
00158   static void CheckClassInitialized(void);
00159 
00160 
00161 #if defined(XP_MAC) || defined(XP_MACOSX)
00162   short fPluginRefNum;
00163 #endif
00164 
00169   NPPluginFuncs fCallbacks;
00170   PRLibrary*    fLibrary;
00171 
00172   NP_PLUGINSHUTDOWN fShutdownEntry;
00173 
00177   static NPNetscapeFuncs CALLBACKS;
00178 };
00179 
00180 
00181 PR_BEGIN_EXTERN_C
00182 NPObject* NP_EXPORT
00183 _getwindowobject(NPP npp);
00184 
00185 NPObject* NP_EXPORT
00186 _getpluginelement(NPP npp);
00187 
00188 NPIdentifier NP_EXPORT
00189 _getstringidentifier(const NPUTF8* name);
00190 
00191 void NP_EXPORT
00192 _getstringidentifiers(const NPUTF8** names, int32_t nameCount,
00193                       NPIdentifier *identifiers);
00194 
00195 bool NP_EXPORT
00196 _identifierisstring(NPIdentifier identifiers);
00197 
00198 NPIdentifier NP_EXPORT
00199 _getintidentifier(int32_t intid);
00200 
00201 NPUTF8* NP_EXPORT
00202 _utf8fromidentifier(NPIdentifier identifier);
00203 
00204 int32_t NP_EXPORT
00205 _intfromidentifier(NPIdentifier identifier);
00206 
00207 NPObject* NP_EXPORT
00208 _createobject(NPP npp, NPClass* aClass);
00209 
00210 NPObject* NP_EXPORT
00211 _retainobject(NPObject* npobj);
00212 
00213 void NP_EXPORT
00214 _releaseobject(NPObject* npobj);
00215 
00216 bool NP_EXPORT
00217 _invoke(NPP npp, NPObject* npobj, NPIdentifier method, const NPVariant *args,
00218         uint32_t argCount, NPVariant *result);
00219 
00220 bool NP_EXPORT
00221 _invokeDefault(NPP npp, NPObject* npobj, const NPVariant *args,
00222                uint32_t argCount, NPVariant *result);
00223 
00224 bool NP_EXPORT
00225 _evaluate(NPP npp, NPObject* npobj, NPString *script, NPVariant *result);
00226 
00227 bool NP_EXPORT
00228 _getproperty(NPP npp, NPObject* npobj, NPIdentifier property,
00229              NPVariant *result);
00230 
00231 bool NP_EXPORT
00232 _setproperty(NPP npp, NPObject* npobj, NPIdentifier property,
00233              const NPVariant *value);
00234 
00235 bool NP_EXPORT
00236 _removeproperty(NPP npp, NPObject* npobj, NPIdentifier property);
00237 
00238 bool NP_EXPORT
00239 _hasproperty(NPP npp, NPObject* npobj, NPIdentifier propertyName);
00240 
00241 bool NP_EXPORT
00242 _hasmethod(NPP npp, NPObject* npobj, NPIdentifier methodName);
00243 
00244 void NP_EXPORT
00245 _releasevariantvalue(NPVariant *variant);
00246 
00247 void NP_EXPORT
00248 _setexception(NPObject* npobj, const NPUTF8 *message);
00249 
00250 PR_END_EXTERN_C
00251 
00252 const char *
00253 PeekException();
00254 
00255 void
00256 PopException();
00257 
00258 class NPPStack
00259 {
00260 public:
00261   static NPP Peek()
00262   {
00263     return sCurrentNPP;
00264   }
00265 
00266 protected:
00267   static NPP sCurrentNPP;
00268 };
00269 
00270 class NPPAutoPusher : public NPPStack
00271 {
00272 public:
00273   NPPAutoPusher(NPP npp)
00274     : mOldNPP(sCurrentNPP)
00275   {
00276     NS_ASSERTION(npp, "Uh, null npp passed to NPPAutoPusher!");
00277 
00278     sCurrentNPP = npp;
00279   }
00280 
00281   ~NPPAutoPusher()
00282   {
00283     sCurrentNPP = mOldNPP;
00284   }
00285 
00286 private:
00287   NPP mOldNPP;
00288 };
00289 
00290 class NPPExceptionAutoHolder
00291 {
00292 public:
00293   NPPExceptionAutoHolder();
00294   ~NPPExceptionAutoHolder();
00295 
00296 protected:
00297   char *mOldException;
00298 };
00299 
00300 #endif // ns4xPlugin_h__