Home | History | Annotate | Download | only in common
      1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
      2 /* ***** BEGIN LICENSE BLOCK *****
      3  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
      4  *
      5  * The contents of this file are subject to the Mozilla Public License Version
      6  * 1.1 (the "License"); you may not use this file except in compliance with
      7  * the License. You may obtain a copy of the License at
      8  * http://www.mozilla.org/MPL/
      9  *
     10  * Software distributed under the License is distributed on an "AS IS" basis,
     11  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
     12  * for the specific language governing rights and limitations under the
     13  * License.
     14  *
     15  * The Original Code is mozilla.org code.
     16  *
     17  * The Initial Developer of the Original Code is
     18  * Netscape Communications Corporation.
     19  * Portions created by the Initial Developer are Copyright (C) 1998
     20  * the Initial Developer. All Rights Reserved.
     21  *
     22  * Contributor(s):
     23  *
     24  * Alternatively, the contents of this file may be used under the terms of
     25  * either the GNU General Public License Version 2 or later (the "GPL"), or
     26  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
     27  * in which case the provisions of the GPL or the LGPL are applicable instead
     28  * of those above. If you wish to allow use of your version of this file only
     29  * under the terms of either the GPL or the LGPL, and not to allow others to
     30  * use your version of this file under the terms of the MPL, indicate your
     31  * decision by deleting the provisions above and replace them with the notice
     32  * and other provisions required by the GPL or the LGPL. If you do not delete
     33  * the provisions above, a recipient may use your version of this file under
     34  * the terms of any one of the MPL, the GPL or the LGPL.
     35  *
     36  * ***** END LICENSE BLOCK ***** */
     37 
     38 #include "xp.h"
     39 
     40 #include "npapi.h"
     41 #include "npupp.h"
     42 #include "epmanager.h"
     43 #include "logger.h"
     44 
     45 // we need to keep track of different plugins and different instances
     46 // of the same plugin when we call NPP functions, so that we always
     47 // call the right ones. Entry point manager will take care of it.
     48 NPPEntryPointManager * epManager = NULL;
     49 
     50 Logger * logger = NULL;
     51 
     52 NPNetscapeFuncs NPNFuncs;
     53 
     54 NPError WINAPI NP_GetEntryPoints(NPPluginFuncs* pFuncs)
     55 {
     56   // create the logger
     57   if(!logger)
     58   {
     59     logger = NewLogger();
     60     if(logger)
     61     {
     62       logger->platformInit();
     63       logger->init();
     64     }
     65   }
     66 
     67   if(logger)
     68     logger->logNS_NP_GetEntryPoints();
     69 
     70   if(pFuncs == NULL)
     71     return NPERR_INVALID_FUNCTABLE_ERROR;
     72 
     73   if(pFuncs->size < sizeof(NPPluginFuncs))
     74     return NPERR_INVALID_FUNCTABLE_ERROR;
     75 
     76   pFuncs->version       = (NP_VERSION_MAJOR << 8) | NP_VERSION_MINOR;
     77   pFuncs->newp          = NPP_New;
     78   pFuncs->destroy       = NPP_Destroy;
     79   pFuncs->setwindow     = NPP_SetWindow;
     80   pFuncs->newstream     = NPP_NewStream;
     81   pFuncs->destroystream = NPP_DestroyStream;
     82   pFuncs->asfile        = NPP_StreamAsFile;
     83   pFuncs->writeready    = NPP_WriteReady;
     84   pFuncs->write         = NPP_Write;
     85   pFuncs->print         = NPP_Print;
     86   pFuncs->event         = NPP_HandleEvent;
     87   pFuncs->urlnotify     = NPP_URLNotify;
     88   pFuncs->getvalue      = NPP_GetValue;
     89   pFuncs->setvalue      = NPP_SetValue;
     90   pFuncs->javaClass     = NULL;
     91 
     92   return NPERR_NO_ERROR;
     93 }
     94 
     95 NPError WINAPI NP_Initialize(NPNetscapeFuncs* pFuncs)
     96 {
     97    // DebugBreak();
     98 
     99   // create the logger
    100   if(!logger)
    101   {
    102     logger = NewLogger();
    103     if(logger)
    104     {
    105       logger->platformInit();
    106       logger->init();
    107     }
    108   }
    109 
    110   if(logger)
    111     logger->logNS_NP_Initialize();
    112 
    113   if(pFuncs == NULL) {
    114     logger->logMessage("NP_Initialize: NULL functable!\r\n");
    115     return NPERR_INVALID_FUNCTABLE_ERROR;
    116   }
    117 
    118   if(HIBYTE(pFuncs->version) > NP_VERSION_MAJOR) {
    119     logger->logMessage("NP_Initialize: incompatible version!\r\n");
    120     return NPERR_INCOMPATIBLE_VERSION_ERROR;
    121   }
    122 
    123   /*
    124    *
    125    * Removing this check so that we can work with older versions
    126    * of servers (which may provide fewer functions)
    127    *
    128   if(pFuncs->size < sizeof NPNetscapeFuncs) {
    129     logger->logReturn(NPERR_INVALID_FUNCTABLE_ERROR);
    130     char msg[512];
    131     sprintf(msg, "functable is %d, expected %d", pFuncs->size, sizeof(NPNetscapeFuncs));
    132     logger->logMessage(msg);
    133     return NPERR_INVALID_FUNCTABLE_ERROR;
    134   }
    135    *
    136    */
    137 
    138   NPNFuncs.size             = pFuncs->size;
    139   NPNFuncs.version          = pFuncs->version;
    140   NPNFuncs.geturlnotify     = pFuncs->geturlnotify;
    141   NPNFuncs.geturl           = pFuncs->geturl;
    142   NPNFuncs.posturlnotify    = pFuncs->posturlnotify;
    143   NPNFuncs.posturl          = pFuncs->posturl;
    144   NPNFuncs.requestread      = pFuncs->requestread;
    145   NPNFuncs.newstream        = pFuncs->newstream;
    146   NPNFuncs.write            = pFuncs->write;
    147   NPNFuncs.destroystream    = pFuncs->destroystream;
    148   NPNFuncs.status           = pFuncs->status;
    149   NPNFuncs.uagent           = pFuncs->uagent;
    150   NPNFuncs.memalloc         = pFuncs->memalloc;
    151   NPNFuncs.memfree          = pFuncs->memfree;
    152   NPNFuncs.memflush         = pFuncs->memflush;
    153   NPNFuncs.reloadplugins    = pFuncs->reloadplugins;
    154   NPNFuncs.getJavaEnv       = pFuncs->getJavaEnv;
    155   NPNFuncs.getJavaPeer      = pFuncs->getJavaPeer;
    156   NPNFuncs.getvalue         = pFuncs->getvalue;
    157   NPNFuncs.setvalue         = pFuncs->setvalue;
    158   NPNFuncs.invalidaterect   = pFuncs->invalidaterect;
    159   NPNFuncs.invalidateregion = pFuncs->invalidateregion;
    160   NPNFuncs.forceredraw      = pFuncs->forceredraw;
    161   NPNFuncs.getstringidentifier      = pFuncs->getstringidentifier;
    162   NPNFuncs.getstringidentifiers      = pFuncs->getstringidentifiers;
    163   NPNFuncs.identifierisstring      = pFuncs->identifierisstring;
    164   NPNFuncs.utf8fromidentifier      = pFuncs->utf8fromidentifier;
    165   NPNFuncs.intfromidentifier      = pFuncs->intfromidentifier;
    166   NPNFuncs.createobject      = pFuncs->createobject;
    167   NPNFuncs.retainobject      = pFuncs->retainobject;
    168   NPNFuncs.releaseobject      = pFuncs->releaseobject;
    169   NPNFuncs.invoke      = pFuncs->invoke;
    170   NPNFuncs.invokeDefault      = pFuncs->invokeDefault;
    171   NPNFuncs.evaluate      = pFuncs->evaluate;
    172   NPNFuncs.getproperty      = pFuncs->getproperty;
    173   NPNFuncs.setproperty      = pFuncs->setproperty;
    174   NPNFuncs.removeproperty      = pFuncs->removeproperty;
    175   NPNFuncs.hasproperty      = pFuncs->hasproperty;
    176   NPNFuncs.hasmethod      = pFuncs->hasmethod;
    177   NPNFuncs.releasevariantvalue      = pFuncs->releasevariantvalue;
    178   NPNFuncs.setexception      = pFuncs->setexception;
    179   NPNFuncs.pushpopupsenabledstate      = pFuncs->pushpopupsenabledstate;
    180   NPNFuncs.poppopupsenabledstate      = pFuncs->poppopupsenabledstate;
    181   NPNFuncs.enumerate      = pFuncs->enumerate;
    182 
    183   // create entry point manager for real plugins
    184   epManager = new NPPEntryPointManager();
    185   if(!epManager) {
    186     logger->logMessage("NP_Initialize: could not create EntryPointManager\r\n");
    187     return NPERR_GENERIC_ERROR;
    188   }
    189 
    190   logger->logMessage("NP_Initialize: success\r\n");
    191   return NPERR_NO_ERROR;
    192 }
    193 
    194 NPError WINAPI NP_Shutdown()
    195 {
    196   // should be safe because if they've already been called shutdown procs must be NULL
    197   if(epManager)
    198     epManager->callNP_ShutdownAll(); // this will log the action
    199 
    200   if(logger)
    201   {
    202     logger->shut();
    203     logger->platformShut();
    204     DeleteLogger(logger);
    205     logger = NULL;
    206   }
    207 
    208   delete epManager;
    209 
    210   return NPERR_NO_ERROR;
    211 }
    212