Back to index

lightning-sunbird  0.9+nobinonly
np_entry.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 #include "xp.h"
00039 
00040 #include "npapi.h"
00041 #include "npupp.h"
00042 #include "epmanager.h"
00043 #include "logger.h"
00044 
00045 // we need to keep track of different plugins and different instances
00046 // of the same plugin when we call NPP functions, so that we always
00047 // call the right ones. Entry point manager will take care of it.
00048 NPPEntryPointManager * epManager = NULL;
00049 
00050 Logger * logger = NULL;
00051 
00052 NPNetscapeFuncs NPNFuncs;
00053 
00054 NPError WINAPI NP_GetEntryPoints(NPPluginFuncs* pFuncs)
00055 {
00056   // create the logger
00057   if(!logger)
00058   {
00059     logger = NewLogger();
00060     if(logger)
00061     {
00062       logger->platformInit();
00063       logger->init();
00064     }
00065   }
00066 
00067   if(logger)
00068     logger->logNS_NP_GetEntryPoints();
00069 
00070   if(pFuncs == NULL)
00071     return NPERR_INVALID_FUNCTABLE_ERROR;
00072 
00073   if(pFuncs->size < sizeof(NPPluginFuncs))
00074     return NPERR_INVALID_FUNCTABLE_ERROR;
00075 
00076   pFuncs->version       = (NP_VERSION_MAJOR << 8) | NP_VERSION_MINOR;
00077   pFuncs->newp          = NPP_New;
00078   pFuncs->destroy       = NPP_Destroy;
00079   pFuncs->setwindow     = NPP_SetWindow;
00080   pFuncs->newstream     = NPP_NewStream;
00081   pFuncs->destroystream = NPP_DestroyStream;
00082   pFuncs->asfile        = NPP_StreamAsFile;
00083   pFuncs->writeready    = NPP_WriteReady;
00084   pFuncs->write         = NPP_Write;
00085   pFuncs->print         = NPP_Print;
00086   pFuncs->event         = NPP_HandleEvent;
00087   pFuncs->urlnotify     = NPP_URLNotify;
00088   pFuncs->getvalue      = NPP_GetValue;
00089   pFuncs->setvalue      = NPP_SetValue;
00090   pFuncs->javaClass     = NULL;
00091 
00092   return NPERR_NO_ERROR;
00093 }
00094 
00095 NPError WINAPI NP_Initialize(NPNetscapeFuncs* pFuncs)
00096 {
00097   // create the logger
00098   if(!logger)
00099   {
00100     logger = NewLogger();
00101     if(logger)
00102     {
00103       logger->platformInit();
00104       logger->init();
00105     }
00106   }
00107 
00108   if(logger)
00109     logger->logNS_NP_Initialize();
00110 
00111   if(pFuncs == NULL)
00112     return NPERR_INVALID_FUNCTABLE_ERROR;
00113 
00114   if(HIBYTE(pFuncs->version) > NP_VERSION_MAJOR)
00115     return NPERR_INCOMPATIBLE_VERSION_ERROR;
00116 
00117   if(pFuncs->size < sizeof NPNetscapeFuncs)
00118     return NPERR_INVALID_FUNCTABLE_ERROR;
00119 
00120   NPNFuncs.size             = pFuncs->size;
00121   NPNFuncs.version          = pFuncs->version;
00122   NPNFuncs.geturlnotify     = pFuncs->geturlnotify;
00123   NPNFuncs.geturl           = pFuncs->geturl;
00124   NPNFuncs.posturlnotify    = pFuncs->posturlnotify;
00125   NPNFuncs.posturl          = pFuncs->posturl;
00126   NPNFuncs.requestread      = pFuncs->requestread;
00127   NPNFuncs.newstream        = pFuncs->newstream;
00128   NPNFuncs.write            = pFuncs->write;
00129   NPNFuncs.destroystream    = pFuncs->destroystream;
00130   NPNFuncs.status           = pFuncs->status;
00131   NPNFuncs.uagent           = pFuncs->uagent;
00132   NPNFuncs.memalloc         = pFuncs->memalloc;
00133   NPNFuncs.memfree          = pFuncs->memfree;
00134   NPNFuncs.memflush         = pFuncs->memflush;
00135   NPNFuncs.reloadplugins    = pFuncs->reloadplugins;
00136   NPNFuncs.getJavaEnv       = pFuncs->getJavaEnv;
00137   NPNFuncs.getJavaPeer      = pFuncs->getJavaPeer;
00138   NPNFuncs.getvalue         = pFuncs->getvalue;
00139   NPNFuncs.setvalue         = pFuncs->setvalue;
00140   NPNFuncs.invalidaterect   = pFuncs->invalidaterect;
00141   NPNFuncs.invalidateregion = pFuncs->invalidateregion;
00142   NPNFuncs.forceredraw      = pFuncs->forceredraw;
00143 
00144   // create entry point manager for real plugins
00145   epManager = new NPPEntryPointManager();
00146   if(!epManager)
00147     return NPERR_GENERIC_ERROR;
00148 
00149   return NPERR_NO_ERROR;
00150 }
00151 
00152 NPError WINAPI NP_Shutdown()
00153 {
00154   // should be safe because if they've already been called shutdown procs must be NULL
00155   if(epManager)
00156     epManager->callNP_ShutdownAll(); // this will log the action
00157 
00158   if(logger)
00159   {
00160     logger->shut();
00161     logger->platformShut();
00162     DeleteLogger(logger);
00163     logger = NULL;
00164   }
00165 
00166   delete epManager;
00167 
00168   return NPERR_NO_ERROR;
00169 }