home *** CD-ROM | disk | FTP | other *** search
/ Tools / WinSN5.0Ver.iso / NETSCAP.50 / WIN1998.ZIP / ns / cmd / xfe / plugins / ImAlive / ImAlive.c next >
Encoding:
C/C++ Source or Header  |  1998-04-08  |  8.0 KB  |  331 lines

  1. /* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
  2.  *
  3.  * The contents of this file are subject to the Netscape Public License
  4.  * Version 1.0 (the "NPL"); you may not use this file except in
  5.  * compliance with the NPL.  You may obtain a copy of the NPL at
  6.  * http://www.mozilla.org/NPL/
  7.  *
  8.  * Software distributed under the NPL is distributed on an "AS IS" basis,
  9.  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
  10.  * for the specific language governing rights and limitations under the
  11.  * NPL.
  12.  *
  13.  * The Initial Developer of this code under the NPL is Netscape
  14.  * Communications Corporation.  Portions created by Netscape are
  15.  * Copyright (C) 1998 Netscape Communications Corporation.  All Rights
  16.  * Reserved.
  17.  */
  18.  
  19.  
  20. /*
  21.  * UnixShell.c
  22.  *
  23.  * Netscape Client Plugin API
  24.  * - Function that need to be implemented by plugin developers
  25.  *
  26.  * This file defines a "Template" plugin that plugin developers can use
  27.  * as the basis for a real plugin.  This shell just provides empty
  28.  * implementations of all functions that the plugin can implement
  29.  * that will be called by Netscape (the NPP_xxx methods defined in 
  30.  * npapi.h). 
  31.  *
  32.  * dp Suresh <dp@netscape.com>
  33.  *
  34.  */
  35.  
  36. #include <stdio.h>
  37. #include "npapi.h"
  38.  
  39. /***********************************************************************
  40.  * Instance state information about the plugin.
  41.  *
  42.  * PLUGIN DEVELOPERS:
  43.  *    Use this struct to hold per-instance information that you'll
  44.  *    need in the various functions in this file.
  45.  ***********************************************************************/
  46.  
  47. typedef struct _PluginInstance
  48. {
  49.     int nothing;
  50. } PluginInstance;
  51.  
  52.  
  53. /***********************************************************************
  54.  *
  55.  * Empty implementations of plugin API functions
  56.  *
  57.  * PLUGIN DEVELOPERS:
  58.  *    You will need to implement these functions as required by your
  59.  *    plugin.
  60.  *
  61.  ***********************************************************************/
  62.  
  63. char*
  64. NPP_GetMIMEDescription(void)
  65. {
  66.     return("Testing/ImAlive:testing:ImAlive");
  67. }
  68.  
  69. NPError
  70. NPP_GetValue(void *future, NPPVariable variable, void *value)
  71. {
  72.     NPError err = NPERR_NO_ERROR;
  73.  
  74.     switch (variable) {
  75.         case NPPVpluginNameString:
  76.             *((char **)value) = "Template plugin";
  77.             break;
  78.         case NPPVpluginDescriptionString:
  79.             *((char **)value) =
  80.                 "This plugins handles nothing. This is only"
  81.                 " a template.";
  82.             break;
  83.         default:
  84.             err = NPERR_GENERIC_ERROR;
  85.     }
  86.     return err;
  87. }
  88.  
  89. NPError
  90. NPP_Initialize(void)
  91. {
  92.     FILE *fp = NULL;
  93.  
  94.     if( (fp = fopen("Worked.nscp", "w+")) == NULL)
  95.     {
  96.      printf( "WE FAILED");
  97.     return NPERR_GENERIC_ERROR;
  98.     }
  99.     else {
  100.        fprintf(fp, "Loaded successfully");
  101.        fclose(fp);
  102.     }
  103.  
  104.     return NPERR_NO_ERROR;
  105. }
  106.  
  107.  
  108. jref
  109. NPP_GetJavaClass()
  110. {
  111.     return NULL;
  112. }
  113.  
  114. void
  115. NPP_Shutdown(void)
  116. {
  117. }
  118.  
  119.  
  120. NPError 
  121. NPP_New(NPMIMEType pluginType,
  122.     NPP instance,
  123.     uint16 mode,
  124.     int16 argc,
  125.     char* argn[],
  126.     char* argv[],
  127.     NPSavedData* saved)
  128. {
  129.         PluginInstance* This;
  130.  
  131.     if (instance == NULL)
  132.         return NPERR_INVALID_INSTANCE_ERROR;
  133.         
  134.     instance->pdata = NPN_MemAlloc(sizeof(PluginInstance));
  135.     
  136.     This = (PluginInstance*) instance->pdata;
  137.  
  138.     if (This != NULL)
  139.         return NPERR_NO_ERROR;
  140.     else
  141.         return NPERR_OUT_OF_MEMORY_ERROR;
  142. }
  143.  
  144.  
  145. NPError 
  146. NPP_Destroy(NPP instance, NPSavedData** save)
  147. {
  148.     PluginInstance* This;
  149.  
  150.     if (instance == NULL)
  151.         return NPERR_INVALID_INSTANCE_ERROR;
  152.  
  153.     This = (PluginInstance*) instance->pdata;
  154.  
  155.     /* PLUGIN DEVELOPERS:
  156.      *    If desired, call NP_MemAlloc to create a
  157.      *    NPSavedDate structure containing any state information
  158.      *    that you want restored if this plugin instance is later
  159.      *    recreated.
  160.      */
  161.  
  162.     if (This != NULL) {
  163.         NPN_MemFree(instance->pdata);
  164.         instance->pdata = NULL;
  165.     }
  166.  
  167.     return NPERR_NO_ERROR;
  168. }
  169.  
  170.  
  171.  
  172. NPError 
  173. NPP_SetWindow(NPP instance, NPWindow* window)
  174. {
  175.     PluginInstance* This;
  176.  
  177.     if (instance == NULL)
  178.         return NPERR_INVALID_INSTANCE_ERROR;
  179.  
  180.     if (window == NULL)
  181.         return NPERR_NO_ERROR;
  182.  
  183.     This = (PluginInstance*) instance->pdata;
  184.  
  185.     /*
  186.      * PLUGIN DEVELOPERS:
  187.      *    Before setting window to point to the
  188.      *    new window, you may wish to compare the new window
  189.      *    info to the previous window (if any) to note window
  190.      *    size changes, etc.
  191.      */
  192.  
  193.     return NPERR_NO_ERROR;
  194. }
  195.  
  196.  
  197. NPError 
  198. NPP_NewStream(NPP instance,
  199.               NPMIMEType type,
  200.               NPStream *stream, 
  201.               NPBool seekable,
  202.               uint16 *stype)
  203. {
  204.     NPByteRange range;
  205.     PluginInstance* This;
  206.  
  207.     if (instance == NULL)
  208.         return NPERR_INVALID_INSTANCE_ERROR;
  209.  
  210.     This = (PluginInstance*) instance->pdata;
  211.  
  212.     return NPERR_NO_ERROR;
  213. }
  214.  
  215.  
  216. /* PLUGIN DEVELOPERS:
  217.  *    These next 2 functions are directly relevant in a plug-in which
  218.  *    handles the data in a streaming manner. If you want zero bytes
  219.  *    because no buffer space is YET available, return 0. As long as
  220.  *    the stream has not been written to the plugin, Navigator will
  221.  *    continue trying to send bytes.  If the plugin doesn't want them,
  222.  *    just return some large number from NPP_WriteReady(), and
  223.  *    ignore them in NPP_Write().  For a NP_ASFILE stream, they are
  224.  *    still called but can safely be ignored using this strategy.
  225.  */
  226.  
  227. int32 STREAMBUFSIZE = 0X0FFFFFFF; /* If we are reading from a file in NPAsFile
  228.                    * mode so we can take any size stream in our
  229.                    * write call (since we ignore it) */
  230.  
  231. int32 
  232. NPP_WriteReady(NPP instance, NPStream *stream)
  233. {
  234.     PluginInstance* This;
  235.     if (instance != NULL)
  236.         This = (PluginInstance*) instance->pdata;
  237.  
  238.     return STREAMBUFSIZE;
  239. }
  240.  
  241.  
  242. int32 
  243. NPP_Write(NPP instance, NPStream *stream, int32 offset, int32 len, void *buffer)
  244. {
  245.     if (instance != NULL)
  246.     {
  247.         PluginInstance* This = (PluginInstance*) instance->pdata;
  248.     }
  249.  
  250.     return len;        /* The number of bytes accepted */
  251. }
  252.  
  253.  
  254. NPError 
  255. NPP_DestroyStream(NPP instance, NPStream *stream, NPError reason)
  256. {
  257.     PluginInstance* This;
  258.  
  259.     if (instance == NULL)
  260.         return NPERR_INVALID_INSTANCE_ERROR;
  261.     This = (PluginInstance*) instance->pdata;
  262.  
  263.     return NPERR_NO_ERROR;
  264. }
  265.  
  266.  
  267. void 
  268. NPP_StreamAsFile(NPP instance, NPStream *stream, const char* fname)
  269. {
  270.     PluginInstance* This;
  271.     if (instance != NULL)
  272.         This = (PluginInstance*) instance->pdata;
  273. }
  274.  
  275.  
  276. void 
  277. NPP_Print(NPP instance, NPPrint* printInfo)
  278. {
  279.     if(printInfo == NULL)
  280.         return;
  281.  
  282.     if (instance != NULL) {
  283.         PluginInstance* This = (PluginInstance*) instance->pdata;
  284.     
  285.         if (printInfo->mode == NP_FULL) {
  286.             /*
  287.              * PLUGIN DEVELOPERS:
  288.              *    If your plugin would like to take over
  289.              *    printing completely when it is in full-screen mode,
  290.              *    set printInfo->pluginPrinted to TRUE and print your
  291.              *    plugin as you see fit.  If your plugin wants Netscape
  292.              *    to handle printing in this case, set
  293.              *    printInfo->pluginPrinted to FALSE (the default) and
  294.              *    do nothing.  If you do want to handle printing
  295.              *    yourself, printOne is true if the print button
  296.              *    (as opposed to the print menu) was clicked.
  297.              *    On the Macintosh, platformPrint is a THPrint; on
  298.              *    Windows, platformPrint is a structure
  299.              *    (defined in npapi.h) containing the printer name, port,
  300.              *    etc.
  301.              */
  302.  
  303.             void* platformPrint =
  304.                 printInfo->print.fullPrint.platformPrint;
  305.             NPBool printOne =
  306.                 printInfo->print.fullPrint.printOne;
  307.             
  308.             /* Do the default*/
  309.             printInfo->print.fullPrint.pluginPrinted = FALSE;
  310.         }
  311.         else {    /* If not fullscreen, we must be embedded */
  312.             /*
  313.              * PLUGIN DEVELOPERS:
  314.              *    If your plugin is embedded, or is full-screen
  315.              *    but you returned false in pluginPrinted above, NPP_Print
  316.              *    will be called with mode == NP_EMBED.  The NPWindow
  317.              *    in the printInfo gives the location and dimensions of
  318.              *    the embedded plugin on the printed page.  On the
  319.              *    Macintosh, platformPrint is the printer port; on
  320.              *    Windows, platformPrint is the handle to the printing
  321.              *    device context.
  322.              */
  323.  
  324.             NPWindow* printWindow =
  325.                 &(printInfo->print.embedPrint.window);
  326.             void* platformPrint =
  327.                 printInfo->print.embedPrint.platformPrint;
  328.         }
  329.     }
  330. }
  331.