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 
00038 
00040 //
00041 // Implementation of plugin entry points (NPP_*)
00042 //
00043 #include "pluginbase.h"
00044 
00045 // here the plugin creates a plugin instance object which 
00046 // will be associated with this newly created NPP instance and 
00047 // will do all the necessary job
00048 NPError NPP_New(NPMIMEType pluginType, NPP instance, uint16 mode, int16 argc, char* argn[], char* argv[], NPSavedData* saved)
00049 {   
00050   if(instance == NULL)
00051     return NPERR_INVALID_INSTANCE_ERROR;
00052 
00053   NPError rv = NPERR_NO_ERROR;
00054 
00055   // create a new plugin instance object
00056   // initialization will be done when the associated window is ready
00057   nsPluginCreateData ds;
00058   
00059   ds.instance = instance;
00060   ds.type     = pluginType; 
00061   ds.mode     = mode; 
00062   ds.argc     = argc; 
00063   ds.argn     = argn; 
00064   ds.argv     = argv; 
00065   ds.saved    = saved;
00066 
00067   nsPluginInstanceBase * plugin = NS_NewPluginInstance(&ds);
00068   if(plugin == NULL)
00069     return NPERR_OUT_OF_MEMORY_ERROR;
00070 
00071   // associate the plugin instance object with NPP instance
00072   instance->pdata = (void *)plugin;
00073   return rv;
00074 }
00075 
00076 // here is the place to clean up and destroy the nsPluginInstance object
00077 NPError NPP_Destroy (NPP instance, NPSavedData** save)
00078 {
00079   if(instance == NULL)
00080     return NPERR_INVALID_INSTANCE_ERROR;
00081 
00082   NPError rv = NPERR_NO_ERROR;
00083 
00084   nsPluginInstanceBase * plugin = (nsPluginInstanceBase *)instance->pdata;
00085   if(plugin != NULL) {
00086     plugin->shut();
00087     NS_DestroyPluginInstance(plugin);
00088   }
00089   return rv;
00090 }
00091 
00092 // during this call we know when the plugin window is ready or
00093 // is about to be destroyed so we can do some gui specific
00094 // initialization and shutdown
00095 NPError NPP_SetWindow (NPP instance, NPWindow* pNPWindow)
00096 {    
00097   if(instance == NULL)
00098     return NPERR_INVALID_INSTANCE_ERROR;
00099 
00100   NPError rv = NPERR_NO_ERROR;
00101 
00102   if(pNPWindow == NULL)
00103     return NPERR_GENERIC_ERROR;
00104 
00105   nsPluginInstanceBase * plugin = (nsPluginInstanceBase *)instance->pdata;
00106 
00107   if(plugin == NULL) 
00108     return NPERR_GENERIC_ERROR;
00109 
00110   // window just created
00111   if(!plugin->isInitialized() && (pNPWindow->window != NULL)) { 
00112     if(!plugin->init(pNPWindow)) {
00113       NS_DestroyPluginInstance(plugin);
00114       return NPERR_MODULE_LOAD_FAILED_ERROR;
00115     }
00116   }
00117 
00118   // window goes away
00119   if((pNPWindow->window == NULL) && plugin->isInitialized())
00120     return plugin->SetWindow(pNPWindow);
00121 
00122   // window resized?
00123   if(plugin->isInitialized() && (pNPWindow->window != NULL))
00124     return plugin->SetWindow(pNPWindow);
00125 
00126   // this should not happen, nothing to do
00127   if((pNPWindow->window == NULL) && !plugin->isInitialized())
00128     return plugin->SetWindow(pNPWindow);
00129 
00130   return rv;
00131 }
00132 
00133 NPError NPP_NewStream(NPP instance, NPMIMEType type, NPStream* stream, NPBool seekable, uint16* stype)
00134 {
00135   if(instance == NULL)
00136     return NPERR_INVALID_INSTANCE_ERROR;
00137 
00138   nsPluginInstanceBase * plugin = (nsPluginInstanceBase *)instance->pdata;
00139   if(plugin == NULL) 
00140     return NPERR_GENERIC_ERROR;
00141 
00142   NPError rv = plugin->NewStream(type, stream, seekable, stype);
00143   return rv;
00144 }
00145 
00146 int32 NPP_WriteReady (NPP instance, NPStream *stream)
00147 {
00148   if(instance == NULL)
00149     return 0x0fffffff;
00150 
00151   nsPluginInstanceBase * plugin = (nsPluginInstanceBase *)instance->pdata;
00152   if(plugin == NULL) 
00153     return 0x0fffffff;
00154 
00155   int32 rv = plugin->WriteReady(stream);
00156   return rv;
00157 }
00158 
00159 int32 NPP_Write (NPP instance, NPStream *stream, int32 offset, int32 len, void *buffer)
00160 {   
00161   if(instance == NULL)
00162     return len;
00163 
00164   nsPluginInstanceBase * plugin = (nsPluginInstanceBase *)instance->pdata;
00165   if(plugin == NULL) 
00166     return len;
00167 
00168   int32 rv = plugin->Write(stream, offset, len, buffer);
00169   return rv;
00170 }
00171 
00172 NPError NPP_DestroyStream (NPP instance, NPStream *stream, NPError reason)
00173 {
00174   if(instance == NULL)
00175     return NPERR_INVALID_INSTANCE_ERROR;
00176 
00177   nsPluginInstanceBase * plugin = (nsPluginInstanceBase *)instance->pdata;
00178   if(plugin == NULL) 
00179     return NPERR_GENERIC_ERROR;
00180 
00181   NPError rv = plugin->DestroyStream(stream, reason);
00182   return rv;
00183 }
00184 
00185 void NPP_StreamAsFile (NPP instance, NPStream* stream, const char* fname)
00186 {
00187   if(instance == NULL)
00188     return;
00189 
00190   nsPluginInstanceBase * plugin = (nsPluginInstanceBase *)instance->pdata;
00191   if(plugin == NULL) 
00192     return;
00193 
00194   plugin->StreamAsFile(stream, fname);
00195 }
00196 
00197 void NPP_Print (NPP instance, NPPrint* printInfo)
00198 {
00199   if(instance == NULL)
00200     return;
00201 
00202   nsPluginInstanceBase * plugin = (nsPluginInstanceBase *)instance->pdata;
00203   if(plugin == NULL) 
00204     return;
00205 
00206   plugin->Print(printInfo);
00207 }
00208 
00209 void NPP_URLNotify(NPP instance, const char* url, NPReason reason, void* notifyData)
00210 {
00211   if(instance == NULL)
00212     return;
00213 
00214   nsPluginInstanceBase * plugin = (nsPluginInstanceBase *)instance->pdata;
00215   if(plugin == NULL) 
00216     return;
00217 
00218   plugin->URLNotify(url, reason, notifyData);
00219 }
00220 
00221 NPError       NPP_GetValue(NPP instance, NPPVariable variable, void *value)
00222 {
00223   if(instance == NULL)
00224     return NPERR_INVALID_INSTANCE_ERROR;
00225 
00226   nsPluginInstanceBase * plugin = (nsPluginInstanceBase *)instance->pdata;
00227   if(plugin == NULL) 
00228     return NPERR_GENERIC_ERROR;
00229 
00230   NPError rv = plugin->GetValue(variable, value);
00231   return rv;
00232 }
00233 
00234 NPError NPP_SetValue(NPP instance, NPNVariable variable, void *value)
00235 {
00236   if(instance == NULL)
00237     return NPERR_INVALID_INSTANCE_ERROR;
00238 
00239   nsPluginInstanceBase * plugin = (nsPluginInstanceBase *)instance->pdata;
00240   if(plugin == NULL) 
00241     return NPERR_GENERIC_ERROR;
00242 
00243   NPError rv = plugin->SetValue(variable, value);
00244   return rv;
00245 }
00246 
00247 int16  NPP_HandleEvent(NPP instance, void* event)
00248 {
00249   if(instance == NULL)
00250     return 0;
00251 
00252   nsPluginInstanceBase * plugin = (nsPluginInstanceBase *)instance->pdata;
00253   if(plugin == NULL) 
00254     return 0;
00255 
00256   uint16 rv = plugin->HandleEvent(event);
00257   return rv;
00258 }
00259 
00260 #ifdef OJI
00261 jref NPP_GetJavaClass (void)
00262 {
00263   return NULL;
00264 }
00265 #endif
00266 
00267 /**************************************************/
00268 /*                                                */
00269 /*                     Mac                        */
00270 /*                                                */
00271 /**************************************************/
00272 
00273 // Mac needs these wrappers, see npplat.h for more info
00274 
00275 #ifdef XP_MAC
00276 
00277 NPError       Private_New(NPMIMEType pluginType, NPP instance, uint16 mode, int16 argc, char* argn[], char* argv[], NPSavedData* saved)
00278 {
00279   NPError rv = NPP_New(pluginType, instance, mode, argc, argn, argv, saved);
00280   return rv;  
00281 }
00282 
00283 NPError Private_Destroy(NPP instance, NPSavedData** save)
00284 {
00285   NPError rv = NPP_Destroy(instance, save);
00286   return rv;
00287 }
00288 
00289 NPError Private_SetWindow(NPP instance, NPWindow* window)
00290 {
00291   NPError rv = NPP_SetWindow(instance, window);
00292   return rv;
00293 }
00294 
00295 NPError Private_NewStream(NPP instance, NPMIMEType type, NPStream* stream, NPBool seekable, uint16* stype)
00296 {
00297   NPError rv = NPP_NewStream(instance, type, stream, seekable, stype);
00298   return rv;
00299 }
00300 
00301 int32 Private_WriteReady(NPP instance, NPStream* stream)
00302 {
00303   int32 rv = NPP_WriteReady(instance, stream);
00304   return rv;
00305 }
00306 
00307 int32 Private_Write(NPP instance, NPStream* stream, int32 offset, int32 len, void* buffer)
00308 {
00309   int32 rv = NPP_Write(instance, stream, offset, len, buffer);
00310   return rv;
00311 }
00312 
00313 void Private_StreamAsFile(NPP instance, NPStream* stream, const char* fname)
00314 {
00315   NPP_StreamAsFile(instance, stream, fname);
00316 }
00317 
00318 
00319 NPError Private_DestroyStream(NPP instance, NPStream* stream, NPError reason)
00320 {
00321   NPError rv = NPP_DestroyStream(instance, stream, reason);
00322   return rv;
00323 }
00324 
00325 int16 Private_HandleEvent(NPP instance, void* event)
00326 {
00327   int16 rv = NPP_HandleEvent(instance, event);
00328   return rv;
00329 }
00330 
00331 void Private_Print(NPP instance, NPPrint* platformPrint)
00332 {
00333   NPP_Print(instance, platformPrint);
00334 }
00335 
00336 void Private_URLNotify(NPP instance, const char* url, NPReason reason, void* notifyData)
00337 {
00338   NPP_URLNotify(instance, url, reason, notifyData);
00339 }
00340 
00341 jref Private_GetJavaClass(void)
00342 {
00343   return NULL;
00344 }
00345 
00346 NPError Private_GetValue(NPP instance, NPPVariable variable, void *result)
00347 {
00348   NPError rv = NPP_GetValue(instance, variable, result);
00349   return rv;
00350 }
00351 
00352 NPError Private_SetValue(NPP instance, NPNVariable variable, void *value)
00353 {
00354   NPError rv = NPP_SetValue(instance, variable, value);
00355   return rv;
00356 }
00357 
00358 #endif //XP_MAC