LCOV - code coverage report
Current view: top level - libreoffice/np_sdk/mozsrc - npunix.c (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 129 0.0 %
Date: 2012-12-27 Functions: 0 34 0.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
       2             :  *
       3             :  * ***** BEGIN LICENSE BLOCK *****
       4             :  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
       5             :  *
       6             :  * The contents of this file are subject to the Mozilla Public License Version
       7             :  * 1.1 (the "License"); you may not use this file except in compliance with
       8             :  * the License. You may obtain a copy of the License at
       9             :  * http://www.mozilla.org/MPL/
      10             :  *
      11             :  * Software distributed under the License is distributed on an "AS IS" basis,
      12             :  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
      13             :  * for the specific language governing rights and limitations under the
      14             :  * License.
      15             :  *
      16             :  * The Original Code is mozilla.org code.
      17             :  *
      18             :  * The Initial Developer of the Original Code is
      19             :  * Netscape Communications Corporation.
      20             :  * Portions created by the Initial Developer are Copyright (C) 1998
      21             :  * the Initial Developer. All Rights Reserved.
      22             :  *
      23             :  * Contributor(s):
      24             :  *   Stephen Mak <smak@sun.com>
      25             :  *
      26             :  * Alternatively, the contents of this file may be used under the terms of
      27             :  * either of the GNU General Public License Version 2 or later (the "GPL"),
      28             :  * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
      29             :  * in which case the provisions of the GPL or the LGPL are applicable instead
      30             :  * of those above. If you wish to allow use of your version of this file only
      31             :  * under the terms of either the GPL or the LGPL, and not to allow others to
      32             :  * use your version of this file under the terms of the MPL, indicate your
      33             :  * decision by deleting the provisions above and replace them with the notice
      34             :  * and other provisions required by the GPL or the LGPL. If you do not delete
      35             :  * the provisions above, a recipient may use your version of this file under
      36             :  * the terms of any one of the MPL, the GPL or the LGPL.
      37             :  *
      38             :  * ***** END LICENSE BLOCK ***** */
      39             : 
      40             : /*
      41             :  * npunix.c
      42             :  *
      43             :  * Netscape Client Plugin API
      44             :  * - Wrapper function to interface with the Netscape Navigator
      45             :  *
      46             :  * dp Suresh <dp@netscape.com>
      47             :  *
      48             :  *----------------------------------------------------------------------
      49             :  * PLUGIN DEVELOPERS:
      50             :  *  YOU WILL NOT NEED TO EDIT THIS FILE.
      51             :  *----------------------------------------------------------------------
      52             :  */
      53             : 
      54             : #include <sal/types.h> // just for SAL_DLLPUBLIC_EXPORT
      55             : 
      56             : #define XP_UNIX 1
      57             : 
      58             : #include <stdio.h>
      59             : #include "npapi.h"
      60             : #include "npupp.h"
      61             : #include "plugin.h"
      62             : 
      63             : /*
      64             :  * Define PLUGIN_TRACE to have the wrapper functions print
      65             :  * messages to stderr whenever they are called.
      66             :  */
      67             : 
      68             : #ifdef PLUGIN_TRACE
      69             : #include <stdio.h>
      70             : #define PLUGINDEBUGSTR(msg) fprintf(stderr, "%s\n", msg)
      71             : #else
      72             : #define PLUGINDEBUGSTR(msg)
      73             : #endif
      74             : 
      75             : 
      76             : /***********************************************************************
      77             :  *
      78             :  * Globals
      79             :  *
      80             :  ***********************************************************************/
      81             : 
      82             : static NPNetscapeFuncs   gNetscapeFuncs;    /* Netscape Function table */
      83             : 
      84             : 
      85             : /***********************************************************************
      86             :  *
      87             :  * Wrapper functions : plugin calling Netscape Navigator
      88             :  *
      89             :  * These functions let the plugin developer just call the APIs
      90             :  * as documented and defined in npapi.h, without needing to know
      91             :  * about the function table and call macros in npupp.h.
      92             :  *
      93             :  ***********************************************************************/
      94             : 
      95             : void
      96           0 : NPN_Version(int* plugin_major, int* plugin_minor,
      97             :          int* netscape_major, int* netscape_minor)
      98             : {
      99           0 :     *plugin_major = NP_VERSION_MAJOR;
     100           0 :     *plugin_minor = NP_VERSION_MINOR;
     101             : 
     102             :     /* Major version is in high byte */
     103           0 :     *netscape_major = gNetscapeFuncs.version >> 8;
     104             :     /* Minor version is in low byte */
     105           0 :     *netscape_minor = gNetscapeFuncs.version & 0xFF;
     106           0 : }
     107             : 
     108             : NPError
     109           0 : NPN_GetValue(NPP instance, NPNVariable variable, void *r_value)
     110             : {
     111           0 :     return CallNPN_GetValueProc(gNetscapeFuncs.getvalue,
     112             :                     instance, variable, r_value);
     113             : }
     114             : 
     115             : NPError
     116           0 : NPN_SetValue(NPP instance, NPPVariable variable, void *value)
     117             : {
     118           0 :     return CallNPN_SetValueProc(gNetscapeFuncs.setvalue,
     119             :                     instance, variable, value);
     120             : }
     121             : 
     122             : NPError
     123           0 : NPN_GetURL(NPP instance, const char* url, const char* window)
     124             : {
     125           0 :     return CallNPN_GetURLProc(gNetscapeFuncs.geturl, instance, url, window);
     126             : }
     127             : 
     128             : NPError
     129           0 : NPN_GetURLNotify(NPP instance, const char* url, const char* window, void* notifyData)
     130             : {
     131           0 :     return CallNPN_GetURLNotifyProc(gNetscapeFuncs.geturlnotify, instance, url, window, notifyData);
     132             : }
     133             : 
     134             : NPError
     135           0 : NPN_PostURL(NPP instance, const char* url, const char* window,
     136             :          uint32_t len, const char* buf, NPBool file)
     137             : {
     138           0 :     return CallNPN_PostURLProc(gNetscapeFuncs.posturl, instance,
     139             :                     url, window, len, buf, file);
     140             : }
     141             : 
     142             : NPError
     143           0 : NPN_PostURLNotify(NPP instance, const char* url, const char* window, uint32_t len,
     144             :                   const char* buf, NPBool file, void* notifyData)
     145             : {
     146           0 :     return CallNPN_PostURLNotifyProc(gNetscapeFuncs.posturlnotify,
     147             :             instance, url, window, len, buf, file, notifyData);
     148             : }
     149             : 
     150             : NPError
     151           0 : NPN_RequestRead(NPStream* stream, NPByteRange* rangeList)
     152             : {
     153           0 :     return CallNPN_RequestReadProc(gNetscapeFuncs.requestread,
     154             :                     stream, rangeList);
     155             : }
     156             : 
     157             : NPError
     158           0 : NPN_NewStream(NPP instance, NPMIMEType type, const char *window,
     159             :           NPStream** stream_ptr)
     160             : {
     161           0 :     return CallNPN_NewStreamProc(gNetscapeFuncs.newstream, instance,
     162             :                     type, window, stream_ptr);
     163             : }
     164             : 
     165             : int32_t
     166           0 : NPN_Write(NPP instance, NPStream* stream, int32_t len, void* buffer)
     167             : {
     168           0 :     return CallNPN_WriteProc(gNetscapeFuncs.write, instance,
     169             :                     stream, len, buffer);
     170             : }
     171             : 
     172             : NPError
     173           0 : NPN_DestroyStream(NPP instance, NPStream* stream, NPError reason)
     174             : {
     175           0 :     return CallNPN_DestroyStreamProc(gNetscapeFuncs.destroystream,
     176             :                         instance, stream, reason);
     177             : }
     178             : 
     179             : void
     180           0 : NPN_Status(NPP instance, const char* message)
     181             : {
     182           0 :     CallNPN_StatusProc(gNetscapeFuncs.status, instance, message);
     183           0 : }
     184             : 
     185             : const char*
     186           0 : NPN_UserAgent(NPP instance)
     187             : {
     188           0 :     return CallNPN_UserAgentProc(gNetscapeFuncs.uagent, instance);
     189             : }
     190             : 
     191             : void*
     192           0 : NPN_MemAlloc(uint32_t size)
     193             : {
     194           0 :     return CallNPN_MemAllocProc(gNetscapeFuncs.memalloc, size);
     195             : }
     196             : 
     197           0 : void NPN_MemFree(void* ptr)
     198             : {
     199           0 :     CallNPN_MemFreeProc(gNetscapeFuncs.memfree, ptr);
     200           0 : }
     201             : 
     202           0 : uint32_t NPN_MemFlush(uint32_t size)
     203             : {
     204           0 :     return CallNPN_MemFlushProc(gNetscapeFuncs.memflush, size);
     205             : }
     206             : 
     207           0 : void NPN_ReloadPlugins(NPBool reloadPages)
     208             : {
     209           0 :     CallNPN_ReloadPluginsProc(gNetscapeFuncs.reloadplugins, reloadPages);
     210           0 : }
     211             : 
     212             : #ifdef OJI
     213             : JRIEnv* NPN_GetJavaEnv()
     214             : {
     215             :     return CallNPN_GetJavaEnvProc(gNetscapeFuncs.getJavaEnv);
     216             : }
     217             : 
     218             : jref NPN_GetJavaPeer(NPP instance)
     219             : {
     220             :     return CallNPN_GetJavaPeerProc(gNetscapeFuncs.getJavaPeer,
     221             :                        instance);
     222             : }
     223             : #endif
     224             : 
     225             : void
     226           0 : NPN_InvalidateRect(NPP instance, NPRect *invalidRect)
     227             : {
     228           0 :     CallNPN_InvalidateRectProc(gNetscapeFuncs.invalidaterect, instance,
     229             :         invalidRect);
     230           0 : }
     231             : 
     232             : void
     233           0 : NPN_InvalidateRegion(NPP instance, NPRegion invalidRegion)
     234             : {
     235           0 :     CallNPN_InvalidateRegionProc(gNetscapeFuncs.invalidateregion, instance,
     236             :         invalidRegion);
     237           0 : }
     238             : 
     239             : void
     240           0 : NPN_ForceRedraw(NPP instance)
     241             : {
     242           0 :     CallNPN_ForceRedrawProc(gNetscapeFuncs.forceredraw, instance);
     243           0 : }
     244             : 
     245             : /***********************************************************************
     246             :  *
     247             :  * Wrapper functions : Netscape Navigator -> plugin
     248             :  *
     249             :  * These functions let the plugin developer just create the APIs
     250             :  * as documented and defined in npapi.h, without needing to
     251             :  * install those functions in the function table or worry about
     252             :  * setting up globals for 68K plugins.
     253             :  *
     254             :  ***********************************************************************/
     255             : 
     256             : NPError
     257           0 : Private_New(NPMIMEType pluginType, NPP instance, uint16_t mode,
     258             :         int16_t argc, char* argn[], char* argv[], NPSavedData* saved)
     259             : {
     260             :     NPError ret;
     261             :     PLUGINDEBUGSTR("New");
     262           0 :     ret = NPP_New(pluginType, instance, mode, argc, argn, argv, saved);
     263           0 :     return ret;
     264             : }
     265             : 
     266             : NPError
     267           0 : Private_Destroy(NPP instance, NPSavedData** save)
     268             : {
     269             :     PLUGINDEBUGSTR("Destroy");
     270           0 :     return NPP_Destroy(instance, save);
     271             : }
     272             : 
     273             : NPError
     274           0 : Private_SetWindow(NPP instance, NPWindow* window)
     275             : {
     276             :     NPError err;
     277             :     PLUGINDEBUGSTR("SetWindow");
     278           0 :     err = NPP_SetWindow(instance, window);
     279           0 :     return err;
     280             : }
     281             : 
     282             : NPError
     283           0 : Private_NewStream(NPP instance, NPMIMEType type, NPStream* stream,
     284             :             NPBool seekable, uint16_t* stype)
     285             : {
     286             :     NPError err;
     287             :     PLUGINDEBUGSTR("NewStream");
     288           0 :     err = NPP_NewStream(instance, type, stream, seekable, stype);
     289           0 :     return err;
     290             : }
     291             : 
     292             : int32_t
     293           0 : Private_WriteReady(NPP instance, NPStream* stream)
     294             : {
     295             :     unsigned int result;
     296             :     PLUGINDEBUGSTR("WriteReady");
     297           0 :     result = NPP_WriteReady(instance, stream);
     298           0 :     return result;
     299             : }
     300             : 
     301             : int32_t
     302           0 : Private_Write(NPP instance, NPStream* stream, int32_t offset, int32_t len,
     303             :         void* buffer)
     304             : {
     305             :     unsigned int result;
     306             :     PLUGINDEBUGSTR("Write");
     307           0 :     result = NPP_Write(instance, stream, offset, len, buffer);
     308           0 :     return result;
     309             : }
     310             : 
     311             : void
     312           0 : Private_StreamAsFile(NPP instance, NPStream* stream, const char* fname)
     313             : {
     314             :     PLUGINDEBUGSTR("StreamAsFile");
     315           0 :     NPP_StreamAsFile(instance, stream, fname);
     316           0 : }
     317             : 
     318             : 
     319             : NPError
     320           0 : Private_DestroyStream(NPP instance, NPStream* stream, NPError reason)
     321             : {
     322             :     NPError err;
     323             :     PLUGINDEBUGSTR("DestroyStream");
     324           0 :     err = NPP_DestroyStream(instance, stream, reason);
     325           0 :     return err;
     326             : }
     327             : 
     328             : void
     329           0 : Private_URLNotify(NPP instance, const char* url,
     330             :                 NPReason reason, void* notifyData)
     331             : 
     332             : {
     333             :     PLUGINDEBUGSTR("URLNotify");
     334           0 :     NPP_URLNotify(instance, url, reason, notifyData);
     335           0 : }
     336             : 
     337             : 
     338             : 
     339             : void
     340           0 : Private_Print(NPP instance, NPPrint* platformPrint)
     341             : {
     342             :     PLUGINDEBUGSTR("Print");
     343           0 :     NPP_Print(instance, platformPrint);
     344           0 : }
     345             : 
     346             : #ifdef OJI
     347             : JRIGlobalRef
     348             : Private_GetJavaClass(void)
     349             : {
     350             :     jref clazz = NPP_GetJavaClass();
     351             :     if (clazz) {
     352             :     JRIEnv* env = NPN_GetJavaEnv();
     353             :     return JRI_NewGlobalRef(env, clazz);
     354             :     }
     355             :     return NULL;
     356             : }
     357             : #endif
     358             : 
     359             : /***********************************************************************
     360             :  *
     361             :  * These functions are located automagically by netscape.
     362             :  *
     363             :  ***********************************************************************/
     364             : 
     365             : /*
     366             :  * NP_GetMIMEDescription
     367             :  *  - Netscape needs to know about this symbol
     368             :  *  - Netscape uses the return value to identify when an object instance
     369             :  *    of this plugin should be created.
     370             :  */
     371             : SAL_DLLPUBLIC_EXPORT char *
     372           0 : NP_GetMIMEDescription(void)
     373             : {
     374           0 :     return (char *)NPP_GetMIMEDescription();
     375             : }
     376             : 
     377             : /*
     378             :  * NP_GetValue [optional]
     379             :  *  - Netscape needs to know about this symbol.
     380             :  *  - Interfaces with plugin to get values for predefined variables
     381             :  *    that the navigator needs.
     382             :  */
     383             : SAL_DLLPUBLIC_EXPORT NPError
     384           0 : NP_GetValue(void* future, NPPVariable variable, void *value)
     385             : {
     386           0 :     return NPP_GetValue(future, variable, value);
     387             : }
     388             : 
     389             : /*
     390             :  * NP_Initialize
     391             :  *  - Netscape needs to know about this symbol.
     392             :  *  - It calls this function after looking up its symbol before it
     393             :  *    is about to create the first ever object of this kind.
     394             :  *
     395             :  * PARAMETERS
     396             :  *    nsTable   - The netscape function table. If developers just use these
     397             :  *        wrappers, they dont need to worry about all these function
     398             :  *        tables.
     399             :  * RETURN
     400             :  *    pluginFuncs
     401             :  *      - This functions needs to fill the plugin function table
     402             :  *        pluginFuncs and return it. Netscape Navigator plugin
     403             :  *        library will use this function table to call the plugin.
     404             :  *
     405             :  */
     406             : SAL_DLLPUBLIC_EXPORT NPError
     407           0 : NP_Initialize(NPNetscapeFuncs* nsTable, NPPluginFuncs* pluginFuncs)
     408             : {
     409           0 :     NPError err = NPERR_NO_ERROR;
     410             : 
     411             :     PLUGINDEBUGSTR("NP_Initialize");
     412             : 
     413             :     /* validate input parameters */
     414             : 
     415           0 :     if ((nsTable == NULL) || (pluginFuncs == NULL))
     416           0 :         err = NPERR_INVALID_FUNCTABLE_ERROR;
     417             : 
     418             :     /*
     419             :      * Check the major version passed in Netscape's function table.
     420             :      * We won't load if the major version is newer than what we expect.
     421             :      * Also check that the function tables passed in are big enough for
     422             :      * all the functions we need (they could be bigger, if Netscape added
     423             :      * new APIs, but that's OK with us -- we'll just ignore them).
     424             :      *
     425             :      */
     426             : 
     427           0 :     if (err == NPERR_NO_ERROR) {
     428           0 :         if ((nsTable->version >> 8) > NP_VERSION_MAJOR)
     429           0 :             err = NPERR_INCOMPATIBLE_VERSION_ERROR;
     430           0 :         if (nsTable->size < sizeof(NPNetscapeFuncs))
     431           0 :             err = NPERR_INVALID_FUNCTABLE_ERROR;
     432           0 :         if (pluginFuncs->size < sizeof(NPPluginFuncs))
     433           0 :             err = NPERR_INVALID_FUNCTABLE_ERROR;
     434             :     }
     435             : 
     436             : 
     437           0 :     if (err == NPERR_NO_ERROR) {
     438             :         /*
     439             :          * Copy all the fields of Netscape function table into our
     440             :          * copy so we can call back into Netscape later.  Note that
     441             :          * we need to copy the fields one by one, rather than assigning
     442             :          * the whole structure, because the Netscape function table
     443             :          * could actually be bigger than what we expect.
     444             :          */
     445           0 :         gNetscapeFuncs.version       = nsTable->version;
     446           0 :         gNetscapeFuncs.size          = nsTable->size;
     447           0 :         gNetscapeFuncs.posturl       = nsTable->posturl;
     448           0 :         gNetscapeFuncs.geturl        = nsTable->geturl;
     449           0 :         gNetscapeFuncs.geturlnotify  = nsTable->geturlnotify;
     450           0 :         gNetscapeFuncs.requestread   = nsTable->requestread;
     451           0 :         gNetscapeFuncs.newstream     = nsTable->newstream;
     452           0 :         gNetscapeFuncs.write         = nsTable->write;
     453           0 :         gNetscapeFuncs.destroystream = nsTable->destroystream;
     454           0 :         gNetscapeFuncs.status        = nsTable->status;
     455           0 :         gNetscapeFuncs.uagent        = nsTable->uagent;
     456           0 :         gNetscapeFuncs.memalloc      = nsTable->memalloc;
     457           0 :         gNetscapeFuncs.memfree       = nsTable->memfree;
     458           0 :         gNetscapeFuncs.memflush      = nsTable->memflush;
     459           0 :         gNetscapeFuncs.reloadplugins = nsTable->reloadplugins;
     460             : #ifdef OJI
     461             :         gNetscapeFuncs.getJavaEnv    = nsTable->getJavaEnv;
     462             :         gNetscapeFuncs.getJavaPeer   = nsTable->getJavaPeer;
     463             : #endif
     464           0 :         gNetscapeFuncs.getvalue      = nsTable->getvalue;
     465             : 
     466             :         /*
     467             :          * Set up the plugin function table that Netscape will use to
     468             :          * call us.  Netscape needs to know about our version and size
     469             :          * and have a UniversalProcPointer for every function we
     470             :          * implement.
     471             :          */
     472           0 :         pluginFuncs->version    = (NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR;
     473           0 :         pluginFuncs->size       = sizeof(NPPluginFuncs);
     474           0 :         pluginFuncs->newp       = NewNPP_NewProc(Private_New);
     475           0 :         pluginFuncs->destroy    = NewNPP_DestroyProc(Private_Destroy);
     476           0 :         pluginFuncs->setwindow  = NewNPP_SetWindowProc(Private_SetWindow);
     477           0 :         pluginFuncs->newstream  = NewNPP_NewStreamProc(Private_NewStream);
     478           0 :         pluginFuncs->destroystream = NewNPP_DestroyStreamProc(Private_DestroyStream);
     479           0 :         pluginFuncs->asfile     = NewNPP_StreamAsFileProc(Private_StreamAsFile);
     480           0 :         pluginFuncs->writeready = NewNPP_WriteReadyProc(Private_WriteReady);
     481           0 :         pluginFuncs->write      = NewNPP_WriteProc(Private_Write);
     482           0 :         pluginFuncs->print      = NewNPP_PrintProc(Private_Print);
     483           0 :         pluginFuncs->urlnotify  = NewNPP_URLNotifyProc(Private_URLNotify);
     484           0 :         pluginFuncs->event      = NULL;
     485             : #ifdef OJI
     486             :         pluginFuncs->javaClass  = Private_GetJavaClass();
     487             : #endif
     488             : 
     489           0 :         err = NPP_Initialize();
     490             :     }
     491             : 
     492           0 :     return err;
     493             : }
     494             : 
     495             : /*
     496             :  * NP_Shutdown [optional]
     497             :  *  - Netscape needs to know about this symbol.
     498             :  *  - It calls this function after looking up its symbol after
     499             :  *    the last object of this kind has been destroyed.
     500             :  *
     501             :  */
     502             : SAL_DLLPUBLIC_EXPORT void
     503           0 : NP_Shutdown(void)
     504             : {
     505             :     PLUGINDEBUGSTR("NP_Shutdown");
     506           0 :     NPP_Shutdown();
     507           0 : }

Generated by: LCOV version 1.10