Back to index

lightning-sunbird  0.9+nobinonly
npp_gate.cpp
Go to the documentation of this file.
00001 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 
00039 //
00040 // Implementation of plugin entry points (NPP_*)
00041 // most are just empty stubs for this particular plugin 
00042 //
00043 #include "plugin.h"
00044 
00045 NPError NPP_Initialize(void)
00046 {
00047     return NPERR_NO_ERROR;
00048 }
00049 
00050 void NPP_Shutdown(void)
00051 {
00052 }
00053 
00054 // here the plugin creates an instance of our CPlugin object which 
00055 // will be associated with this newly created plugin instance and 
00056 // will do all the necessary job
00057 NPError NPP_New(NPMIMEType pluginType,
00058                 NPP instance,
00059                 uint16 mode,
00060                 int16 argc,
00061                 char* argn[],
00062                 char* argv[],
00063                 NPSavedData* saved)
00064 {   
00065   if(instance == NULL)
00066     return NPERR_INVALID_INSTANCE_ERROR;
00067 
00068   NPError rv = NPERR_NO_ERROR;
00069 
00070   CPlugin * pPlugin = new CPlugin(instance);
00071   if(pPlugin == NULL)
00072     return NPERR_OUT_OF_MEMORY_ERROR;
00073 
00074   instance->pdata = (void *)pPlugin;
00075   return rv;
00076 }
00077 
00078 // here is the place to clean up and destroy the CPlugin object
00079 NPError NPP_Destroy (NPP instance, NPSavedData** save)
00080 {
00081   if(instance == NULL)
00082     return NPERR_INVALID_INSTANCE_ERROR;
00083 
00084   NPError rv = NPERR_NO_ERROR;
00085 
00086   CPlugin * pPlugin = (CPlugin *)instance->pdata;
00087   if(pPlugin != NULL) {
00088     pPlugin->shut();
00089     delete pPlugin;
00090   }
00091   return rv;
00092 }
00093 
00094 // during this call we know when the plugin window is ready or
00095 // is about to be destroyed so we can do some gui specific
00096 // initialization and shutdown
00097 NPError NPP_SetWindow (NPP instance, NPWindow* pNPWindow)
00098 {    
00099   if(instance == NULL)
00100     return NPERR_INVALID_INSTANCE_ERROR;
00101 
00102   NPError rv = NPERR_NO_ERROR;
00103 
00104   if(pNPWindow == NULL)
00105     return NPERR_GENERIC_ERROR;
00106 
00107   CPlugin * pPlugin = (CPlugin *)instance->pdata;
00108 
00109   if(pPlugin == NULL) 
00110     return NPERR_GENERIC_ERROR;
00111 
00112   // window just created
00113   if(!pPlugin->isInitialized() && (pNPWindow->window != NULL)) { 
00114     if(!pPlugin->init(pNPWindow)) {
00115       delete pPlugin;
00116       pPlugin = NULL;
00117       return NPERR_MODULE_LOAD_FAILED_ERROR;
00118     }
00119   }
00120 
00121   // window goes away
00122   if((pNPWindow->window == NULL) && pPlugin->isInitialized())
00123     return NPERR_NO_ERROR;
00124 
00125   // window resized
00126   if(pPlugin->isInitialized() && (pNPWindow->window != NULL))
00127     return NPERR_NO_ERROR;
00128 
00129   // this should not happen, nothing to do
00130   if((pNPWindow->window == NULL) && !pPlugin->isInitialized())
00131     return NPERR_NO_ERROR;
00132 
00133   return rv;
00134 }
00135 
00136 // ==============================
00137 // ! Scriptability related code !
00138 // ==============================
00139 //
00140 // here the plugin is asked by Mozilla to tell if it is scriptable
00141 // we should return a valid interface id and a pointer to 
00142 // nsScriptablePeer interface which we should have implemented
00143 // and which should be defined in the corressponding *.xpt file
00144 // in the bin/components folder
00145 NPError       NPP_GetValue(NPP instance, NPPVariable variable, void *value)
00146 {
00147   if(instance == NULL)
00148     return NPERR_INVALID_INSTANCE_ERROR;
00149 
00150   NPError rv = NPERR_NO_ERROR;
00151 
00152   if(instance == NULL)
00153     return NPERR_GENERIC_ERROR;
00154 
00155   CPlugin * pPlugin = (CPlugin *)instance->pdata;
00156   if(pPlugin == NULL)
00157     return NPERR_GENERIC_ERROR;
00158 
00159   if (variable == NPPVpluginScriptableInstance) {
00160     // addref happens in getter, so we don't addref here
00161     nsI4xScriptablePlugin * scriptablePeer = pPlugin->getScriptablePeer();
00162     if (scriptablePeer) {
00163       *(nsISupports **)value = scriptablePeer;
00164     } else {
00165       rv = NPERR_OUT_OF_MEMORY_ERROR;
00166     }
00167   }
00168   else if (variable == NPPVpluginScriptableIID) {
00169     static nsIID scriptableIID = NS_I4XSCRIPTABLEPLUGIN_IID;
00170     nsIID* ptr = (nsIID *)NPN_MemAlloc(sizeof(nsIID));
00171     if (ptr) {
00172         *ptr = scriptableIID;
00173         *(nsIID **)value = ptr;
00174     } else {
00175       rv = NPERR_OUT_OF_MEMORY_ERROR;
00176     }
00177   }
00178 
00179   return rv;
00180 }
00181 
00182 NPError NPP_NewStream(NPP instance,
00183                       NPMIMEType type,
00184                       NPStream* stream, 
00185                       NPBool seekable,
00186                       uint16* stype)
00187 {
00188   if(instance == NULL)
00189     return NPERR_INVALID_INSTANCE_ERROR;
00190 
00191   NPError rv = NPERR_NO_ERROR;
00192   return rv;
00193 }
00194 
00195 int32 NPP_WriteReady (NPP instance, NPStream *stream)
00196 {
00197   if(instance == NULL)
00198     return NPERR_INVALID_INSTANCE_ERROR;
00199 
00200   int32 rv = 0x0fffffff;
00201   return rv;
00202 }
00203 
00204 int32 NPP_Write (NPP instance, NPStream *stream, int32 offset, int32 len, void *buffer)
00205 {   
00206   if(instance == NULL)
00207     return NPERR_INVALID_INSTANCE_ERROR;
00208 
00209   int32 rv = len;
00210   return rv;
00211 }
00212 
00213 NPError NPP_DestroyStream (NPP instance, NPStream *stream, NPError reason)
00214 {
00215   if(instance == NULL)
00216     return NPERR_INVALID_INSTANCE_ERROR;
00217 
00218   NPError rv = NPERR_NO_ERROR;
00219   return rv;
00220 }
00221 
00222 void NPP_StreamAsFile (NPP instance, NPStream* stream, const char* fname)
00223 {
00224   if(instance == NULL)
00225     return;
00226 }
00227 
00228 void NPP_Print (NPP instance, NPPrint* printInfo)
00229 {
00230   if(instance == NULL)
00231     return;
00232 }
00233 
00234 void NPP_URLNotify(NPP instance, const char* url, NPReason reason, void* notifyData)
00235 {
00236   if(instance == NULL)
00237     return;
00238 }
00239 
00240 NPError NPP_SetValue(NPP instance, NPNVariable variable, void *value)
00241 {
00242   if(instance == NULL)
00243     return NPERR_INVALID_INSTANCE_ERROR;
00244 
00245   NPError rv = NPERR_NO_ERROR;
00246   return rv;
00247 }
00248 
00249 int16  NPP_HandleEvent(NPP instance, void* event)
00250 {
00251   if(instance == NULL)
00252     return 0;
00253 
00254   int16 rv = 0;
00255   CPlugin * pPlugin = (CPlugin *)instance->pdata;
00256   if (pPlugin)
00257     rv = pPlugin->handleEvent(event);
00258 
00259   return rv;
00260 }
00261 
00262 jref NPP_GetJavaClass (void)
00263 {
00264   return NULL;
00265 }