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

  1. /* -*- Mode: C++; tab-width: 8; 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. /* npwin.cpp */
  20.  
  21. //\\// INCLUDE
  22. //#include "StdAfx.h"
  23.  
  24. // netscape
  25. #ifndef _NPAPI_H_
  26. #include "npapi.h"
  27. #endif
  28. #ifndef _NPUPP_H_
  29. #include "npupp.h"
  30. #endif
  31.  
  32. //\\// DEFINE
  33. #ifdef WIN32
  34.     #define NP_EXPORT //__declspec( dllexport )
  35. #else
  36.     #define NP_EXPORT _export
  37. #endif
  38.  
  39. //\\// GLOBAL DATA
  40. NPNetscapeFuncs* g_pNavigatorFuncs = NULL;
  41.  
  42. //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\.
  43. ////\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//.
  44. // Private_GetJavaClass (global function)
  45. //
  46. //    Given a Java class reference (thru NPP_GetJavaClass) inform JRT
  47. //    of this class existence
  48. //
  49. JRIGlobalRef
  50. Private_GetJavaClass(void)
  51. {
  52.     jref clazz = NPP_GetJavaClass();
  53.     if (clazz) {
  54.         JRIEnv* env = NPN_GetJavaEnv();
  55.         return JRI_NewGlobalRef(env, clazz);
  56.     }
  57.     return NULL;
  58. }
  59.  
  60. //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\.
  61. ////\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//.
  62. //                        PLUGIN DLL entry points   
  63. //
  64. // These are the Windows specific DLL entry points. They must be exoprted
  65. //
  66.  
  67. // we need these to be global since we have to fill one of its field
  68. // with a data (class) which requires knowlwdge of the navigator
  69. // jump-table. This jump table is known at Initialize time (NP_Initialize)
  70. // which is called after NP_GetEntryPoint
  71. static NPPluginFuncs* g_pluginFuncs;
  72.  
  73. //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\.
  74. ////\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//.
  75. // NP_GetEntryPoints
  76. //
  77. //    fills in the func table used by Navigator to call entry points in
  78. //  plugin DLL.  Note that these entry points ensure that DS is loaded
  79. //  by using the NP_LOADDS macro, when compiling for Win16
  80. //
  81. NPError WINAPI NP_EXPORT
  82. NP_GetEntryPoints(NPPluginFuncs* pFuncs)
  83. {
  84.     // trap a NULL ptr 
  85.     if(pFuncs == NULL)
  86.         return NPERR_INVALID_FUNCTABLE_ERROR;
  87.  
  88.     // if the plugin's function table is smaller than the plugin expects,
  89.     // then they are incompatible, and should return an error 
  90.  
  91.     pFuncs->version       = (NP_VERSION_MAJOR << 8) | NP_VERSION_MINOR;
  92.     pFuncs->newp          = NPP_New;
  93.     pFuncs->destroy       = NPP_Destroy;
  94.     pFuncs->setwindow     = NPP_SetWindow;
  95.     pFuncs->newstream     = NPP_NewStream;
  96.     pFuncs->destroystream = NPP_DestroyStream;
  97.     pFuncs->asfile        = NPP_StreamAsFile;
  98.     pFuncs->writeready    = NPP_WriteReady;
  99.     pFuncs->write         = NPP_Write;
  100.     pFuncs->print         = NPP_Print;
  101.     pFuncs->event         = NULL;       /// reserved 
  102.  
  103.     g_pluginFuncs          = pFuncs;
  104.  
  105.     return NPERR_NO_ERROR;
  106. }
  107.  
  108. //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\.
  109. ////\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//.
  110. // NP_Initialize
  111. //
  112. //    called immediately after the plugin DLL is loaded
  113. //
  114. NPError WINAPI NP_EXPORT 
  115. NP_Initialize(NPNetscapeFuncs* pFuncs)
  116. {
  117.     // trap a NULL ptr 
  118.     if(pFuncs == NULL)
  119.         return NPERR_INVALID_FUNCTABLE_ERROR;
  120.  
  121.     g_pNavigatorFuncs = pFuncs; // save it for future reference 
  122.  
  123.     // if the plugin's major ver level is lower than the Navigator's,
  124.     // then they are incompatible, and should return an error 
  125.     if(HIBYTE(pFuncs->version) > NP_VERSION_MAJOR)
  126.         return NPERR_INCOMPATIBLE_VERSION_ERROR;
  127.  
  128.     // We have to defer these assignments until g_pNavigatorFuncs is set
  129.     int navMinorVers = g_pNavigatorFuncs->version & 0xFF;
  130.  
  131.  
  132.     if( navMinorVers >= NPVERS_HAS_NOTIFICATION ) {
  133.  
  134.         g_pluginFuncs->urlnotify = NPP_URLNotify;
  135.  
  136.     }
  137.  
  138.     if( navMinorVers >= NPVERS_HAS_LIVECONNECT ) {
  139.  
  140.         g_pluginFuncs->javaClass = Private_GetJavaClass();
  141.  
  142.     }
  143.  
  144.  
  145.     // NPP_Initialize is a standard (cross-platform) initialize function.
  146.     return NPP_Initialize();
  147. }
  148.  
  149. //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\.
  150. ////\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//.
  151. // NP_Shutdown
  152. //
  153. //    called immediately before the plugin DLL is unloaded.
  154. //    This functio shuold check for some ref count on the dll to see if it is
  155. //    unloadable or it needs to stay in memory. 
  156. //
  157. NPError WINAPI NP_EXPORT 
  158. NP_Shutdown()
  159. {
  160.     NPP_Shutdown();
  161.  
  162.     g_pNavigatorFuncs = NULL;
  163.  
  164.     return NPERR_NO_ERROR;
  165. }
  166.  
  167. //                        END - PLUGIN DLL entry points   
  168. ////\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//.
  169. //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\.
  170.  
  171. /*    NAVIGATOR Entry points    */
  172.  
  173. /* These entry points expect to be called from within the plugin.  The
  174.    noteworthy assumption is that DS has already been set to point to the
  175.    plugin's DLL data segment.  Don't call these functions from outside
  176.    the plugin without ensuring DS is set to the DLLs data segment first,
  177.    typically using the NP_LOADDS macro
  178. */
  179.  
  180. /* returns the major/minor version numbers of the Plugin API for the plugin
  181.    and the Navigator
  182. */
  183. void NPN_Version(int* plugin_major, int* plugin_minor, int* netscape_major, int* netscape_minor)
  184. {
  185.     *plugin_major   = NP_VERSION_MAJOR;
  186.     *plugin_minor   = NP_VERSION_MINOR;
  187.     *netscape_major = HIBYTE(g_pNavigatorFuncs->version);
  188.     *netscape_minor = LOBYTE(g_pNavigatorFuncs->version);
  189. }
  190.  
  191. /* causes the specified URL to be fetched and streamed in
  192. */
  193. NPError NPN_GetURLNotify(NPP instance, const char *url, const char *target, void* notifyData)
  194.  
  195. {
  196.  
  197.     int navMinorVers = g_pNavigatorFuncs->version & 0xFF;
  198.  
  199.     NPError err;
  200.  
  201.     if( navMinorVers >= NPVERS_HAS_NOTIFICATION ) {
  202.  
  203.         err = g_pNavigatorFuncs->geturlnotify(instance, url, target, notifyData);
  204.  
  205.     }
  206.  
  207.     else {
  208.  
  209.         err = NPERR_INCOMPATIBLE_VERSION_ERROR;
  210.  
  211.     }
  212.  
  213.     return err;
  214.  
  215. }
  216.  
  217.  
  218. NPError NPN_GetURL(NPP instance, const char *url, const char *target)
  219. {
  220.     return g_pNavigatorFuncs->geturl(instance, url, target);
  221. }
  222.  
  223. NPError NPN_PostURLNotify(NPP instance, const char* url, const char* window, uint32 len, const char* buf, NPBool file, void* notifyData)
  224.  
  225. {
  226.  
  227.     int navMinorVers = g_pNavigatorFuncs->version & 0xFF;
  228.  
  229.     NPError err;
  230.  
  231.     if( navMinorVers >= NPVERS_HAS_NOTIFICATION ) {
  232.  
  233.         err = g_pNavigatorFuncs->posturlnotify(instance, url, window, len, buf, file, notifyData);
  234.  
  235.     }
  236.  
  237.     else {
  238.  
  239.         err = NPERR_INCOMPATIBLE_VERSION_ERROR;
  240.  
  241.     }
  242.  
  243.     return err;
  244.  
  245. }
  246.  
  247.  
  248. NPError NPN_PostURL(NPP instance, const char* url, const char* window, uint32 len, const char* buf, NPBool file)
  249. {
  250.     return g_pNavigatorFuncs->posturl(instance, url, window, len, buf, file);
  251. }
  252.  
  253. /* Requests that a number of bytes be provided on a stream.  Typically
  254.    this would be used if a stream was in "pull" mode.  An optional
  255.    position can be provided for streams which are seekable.
  256. */
  257. NPError NPN_RequestRead(NPStream* stream, NPByteRange* rangeList)
  258. {
  259.     return g_pNavigatorFuncs->requestread(stream, rangeList);
  260. }
  261.  
  262. /* Creates a new stream of data from the plug-in to be interpreted
  263.    by Netscape in the current window.
  264. */
  265. NPError NPN_NewStream(NPP instance, NPMIMEType type, 
  266.                                 const char* target, NPStream** stream)
  267. {
  268.  
  269.     int navMinorVersion = g_pNavigatorFuncs->version & 0xFF;
  270.  
  271.     NPError err;
  272.  
  273.  
  274.     if( navMinorVersion >= NPVERS_HAS_STREAMOUTPUT ) {
  275.  
  276.         err = g_pNavigatorFuncs->newstream(instance, type, target, stream);
  277.  
  278.     }
  279.  
  280.     else {
  281.  
  282.         err = NPERR_INCOMPATIBLE_VERSION_ERROR;
  283.  
  284.     }
  285.  
  286.     return err;
  287. }
  288.  
  289. /* Provides len bytes of data.
  290. */
  291. int32 NPN_Write(NPP instance, NPStream *stream,
  292.                 int32 len, void *buffer)
  293. {
  294.     int navMinorVersion = g_pNavigatorFuncs->version & 0xFF;
  295.  
  296.     int32 result;
  297.  
  298.  
  299.     if( navMinorVersion >= NPVERS_HAS_STREAMOUTPUT ) {
  300.  
  301.         result = g_pNavigatorFuncs->write(instance, stream, len, buffer);
  302.  
  303.     }
  304.  
  305.     else {
  306.         result = -1;
  307.  
  308.     }
  309.  
  310.     return result;
  311.  
  312. }
  313.  
  314. /* Closes a stream object.  
  315. reason indicates why the stream was closed.
  316. */
  317. NPError NPN_DestroyStream(NPP instance, NPStream* stream, NPError reason)
  318. {
  319.     int navMinorVersion = g_pNavigatorFuncs->version & 0xFF;
  320.  
  321.     NPError err;
  322.  
  323.  
  324.     if( navMinorVersion >= NPVERS_HAS_STREAMOUTPUT ) {
  325.  
  326.         err = g_pNavigatorFuncs->destroystream(instance, stream, reason);
  327.  
  328.     }
  329.     else {
  330.  
  331.         err = NPERR_INCOMPATIBLE_VERSION_ERROR;
  332.  
  333.     }
  334.  
  335.     return err;
  336.  
  337. }
  338.  
  339. /* Provides a text status message in the Netscape client user interface
  340. */
  341. void NPN_Status(NPP instance, const char *message)
  342. {
  343.     g_pNavigatorFuncs->status(instance, message);
  344. }
  345.  
  346. /* returns the user agent string of Navigator, which contains version info
  347. */
  348. const char* NPN_UserAgent(NPP instance)
  349. {
  350.     return g_pNavigatorFuncs->uagent(instance);
  351. }
  352.  
  353. /* allocates memory from the Navigator's memory space.  Necessary so that
  354.    saved instance data may be freed by Navigator when exiting.
  355. */
  356.  
  357.  
  358. void* NPN_MemAlloc(uint32 size)
  359. {
  360.     return g_pNavigatorFuncs->memalloc(size);
  361. }
  362.  
  363. /* reciprocal of MemAlloc() above
  364. */
  365. void NPN_MemFree(void* ptr)
  366. {
  367.     g_pNavigatorFuncs->memfree(ptr);
  368. }
  369.  
  370. /* private function to Netscape.  do not use!
  371. */
  372. void NPN_ReloadPlugins(NPBool reloadPages)
  373. {
  374.     g_pNavigatorFuncs->reloadplugins(reloadPages);
  375. }
  376.  
  377. JRIEnv* NPN_GetJavaEnv(void)
  378. {
  379.     return g_pNavigatorFuncs->getJavaEnv();
  380. }
  381.  
  382. jref NPN_GetJavaPeer(NPP instance)
  383. {
  384.     return g_pNavigatorFuncs->getJavaPeer(instance);
  385. }
  386.  
  387.