home *** CD-ROM | disk | FTP | other *** search
/ Delphi 5 for Professionals / DELPHI5.iso / AddOns / Components / TEECHART / Delphi1_And_Delphi2 / EXAMPLES / OTHER / NETSCAPE / NPPLUGIN.PAS < prev    next >
Encoding:
Pascal/Delphi Source File  |  1998-10-24  |  50.5 KB  |  1,355 lines

  1. unit NPPlugin;
  2.  
  3. interface
  4.  
  5. uses
  6.   Windows, SysUtils, Classes ;
  7.  
  8. const
  9.   NP_VERSION_MAJOR = 0 ;
  10.   NP_VERSION_MINOR = 9 ;
  11.  
  12. (*
  13.  * Values for mode passed to NPP_New:
  14.  *)
  15.   NP_EMBED = 1 ;
  16.   NP_FULL  = 2 ;
  17.  
  18. (*
  19.  * Values for stream type passed to NPP_NewStream:
  20.  *)
  21.   NP_NORMAL     = 1 ;
  22.   NP_SEEK       = 2 ;
  23.   NP_ASFILE     = 3 ;
  24.   NP_ASFILEONLY = 4 ;
  25.  
  26.   NP_MAXREADY = ( ( cardinal( not 0 ) shl 1 ) shr 1 ) ;
  27.  
  28. (*----------------------------------------------------------------------*/
  29. /*                   Error and Reason Code definitions                  */
  30. /*----------------------------------------------------------------------*)
  31.  
  32. (*
  33.  *    Values of type NPError:
  34.  *)
  35.   NPERR_BASE                       = 0 ;
  36.   NPERR_NO_ERROR                   = NPERR_BASE + 0 ;
  37.   NPERR_GENERIC_ERROR              = NPERR_BASE + 1 ;
  38.   NPERR_INVALID_INSTANCE_ERROR     = NPERR_BASE + 2 ;
  39.   NPERR_INVALID_FUNCTABLE_ERROR    = NPERR_BASE + 3 ;
  40.   NPERR_MODULE_LOAD_FAILED_ERROR   = NPERR_BASE + 4 ;
  41.   NPERR_OUT_OF_MEMORY_ERROR        = NPERR_BASE + 5 ;
  42.   NPERR_INVALID_PLUGIN_ERROR       = NPERR_BASE + 6 ;
  43.   NPERR_INVALID_PLUGIN_DIR_ERROR   = NPERR_BASE + 7 ;
  44.   NPERR_INCOMPATIBLE_VERSION_ERROR = NPERR_BASE + 8 ;
  45.   NPERR_INVALID_PARAM              = NPERR_BASE + 9 ;
  46.   NPERR_INVALID_URL                = NPERR_BASE + 10 ;
  47.   NPERR_FILE_NOT_FOUND             = NPERR_BASE + 11 ;
  48.   NPERR_NO_DATA                    = NPERR_BASE + 12 ;
  49.   NPERR_STREAM_NOT_SEEKABLE        = NPERR_BASE + 13 ;
  50.  
  51. (*
  52.  *    Values of type NPReason:
  53.  *)
  54.   NPRES_BASE        = 0 ;
  55.   NPRES_DONE        = NPRES_BASE + 0 ;
  56.   NPRES_NETWORK_ERR = NPRES_BASE + 1 ;
  57.   NPRES_USER_BREAK  = NPRES_BASE + 2 ;
  58.  
  59. (*
  60.  *    Don't use these obsolete error codes any more.
  61.  *
  62.   NP_NOERR  NP_NOERR_is_obsolete_use_NPERR_NO_ERROR
  63.   NP_EINVAL NP_EINVAL_is_obsolete_use_NPERR_GENERIC_ERROR
  64.   NP_EABORT NP_EABORT_is_obsolete_use_NPRES_USER_BREAK *)
  65.  
  66. (*
  67.  * Version feature information
  68.  *)
  69.   NPVERS_HAS_STREAMOUTPUT      = 8 ;
  70.   NPVERS_HAS_NOTIFICATION      = 9 ;
  71.   NPVERS_HAS_LIVECONNECT       = 9 ;
  72.   NPVERS_WIN16_HAS_LIVECONNECT = 10 ;
  73.  
  74. type
  75.   TJRIRef = pointer ;
  76.   TJRIGlobalRef = pointer ;
  77.   TJRIEnvInterface = record end ;
  78.   PJRIEnvInterface = ^TJRIEnvInterface ;
  79.  
  80.   { synonyms: }
  81.   TJGlobal = TJRIGlobalRef ;
  82.   TJRef    = TJRIRef ;
  83.   PJRIEnv  = PJRIEnvInterface ;
  84.  
  85.   TPCharArray = array[ 0..( Maxint - 16 ) div SizeOf( PChar ) - 1 ] of PChar ;
  86.   TNPBool     = char ;
  87.   TNPMIMEType = PChar ;
  88.   TNPError    = smallint ;
  89.   TNPReason   = smallint ;
  90.   TNPEvent    = pointer ;
  91.  
  92.   PNPP = ^TNPP ;
  93.   TNPP = record
  94.     PData : pointer ; { plug-in private data }
  95.     NData : pointer ; { netscape private data }
  96.   end ;
  97.  
  98.   PNPSavedData = ^TNPSavedData ;
  99.   TNPSavedData = record
  100.     Len : longint ;
  101.     Buf : pointer ;
  102.   end ;
  103.  
  104.   PNPRect = ^TNPRect ;
  105.   TNPRect = record
  106.     Top    : SmallInt ;
  107.     Left   : SmallInt ;
  108.     Bottom : SmallInt ;
  109.     Right  : SmallInt ;
  110.   end ;
  111.  
  112.   PNPWindow = ^TNPWindow ;
  113.   TNPWindow = record
  114.     Window   : longint ; { Platform specific window handle }
  115.     x        : longint ; { Position of top left corner relative }
  116.     y        : longint ; {   to a netscape page.                }
  117.     Width    : longint ; { Maximum window size }
  118.     Height   : longint ;
  119.     ClipRect : TNPRect ; { Clipping rectangle in port coordinates }
  120.                          {                      Used by MAC only. }
  121.   end ;
  122.  
  123.  
  124.   PNPByteRange = ^TNPByteRange ;
  125.   TNPByteRange = record
  126.     Offset : longint ; { negative offset means from the end }
  127.     Length : longint ;
  128.     Next   : PNPByteRange ;
  129.   end ;
  130.  
  131.   PNPStream = ^TNPStream ;
  132.   TNPStream = record
  133.     PData        : pointer ;  { plug-in private data  }
  134.     NData        : pointer ;  { netscape private data }
  135.     URL          : PChar ;
  136.     EndPos       : longint ;
  137.     LastModified : longint ;
  138.     NotifyData   : pointer ;
  139.   end ;
  140.  
  141.   PNPFullPrint = ^TNPFullPrint ;
  142.   TNPFullPrint = record
  143.     PluginPrinted : TNPBool ; { Set TRUE if plugin handled fullscreen }
  144.                               {   printing.                           }
  145.     PrintOne      : TNPBool ; { TRUE if plugin should print one copy  }
  146.                               {   to default printer.                 }
  147.     PlatformPrint : pointer ; { Platform-specific printing info       }
  148.   end ;
  149.  
  150.   PNPEmbedPrint = ^TNPEmbedPrint ;
  151.   TNPEmbedPrint = record
  152.     Window        : TNPWindow ;
  153.     PlatformPrint : pointer ; { Platform-specific printing info       }
  154.   end ;
  155.  
  156.   PNPPrint = ^TNPPrint ;
  157.   TNPPrint = record
  158.     Mode : SmallInt ;  { NP_FULL or NP_EMBED }
  159.     case integer of
  160.       0 : ( FullPrint  : TNPFullPrint ) ; { if mode is NP_FULL }
  161.       1 : ( EmbedPrint : TNPEmbedPrint ) ; { if mode is NP_EMBED }
  162.   end ;
  163.  
  164.   JRIRef = pointer ;
  165.   JRef   = JRIRef ;
  166.  
  167. { PLUGIN API TO NETSCAPE NAVIGATOR
  168.   ================================
  169.   The following are API functions as documented in the Netscape Plugin docs
  170.   as of 23-Oct-96. The actual interface is via a function table. However, you
  171.   should call these wrapper functions which take care of calling into the
  172.   function table and also do some parameter checking.
  173.  
  174.   The function table is accessible and appears after
  175.   the following API routines. }
  176.  
  177. procedure  NPN_Version( var PluginMajor : integer ;
  178.                         var PluginMinor : integer ;
  179.                         var NetscapeMajor : integer ;
  180.                         var NetscapeMinor : integer ) ;
  181. function  NPN_GetURLNotify( Instance : PNPP ;
  182.                             URL      : PChar ;
  183.                             Target   : PChar ;
  184.                             var NotifyData ) : TNPError ;
  185. function  NPN_GetURL( Instance : PNPP ;
  186.                       URL      : PChar ;
  187.                       Target   : PChar ) : TNPError ;
  188. function  NPN_PostURLNotify( Instance : PNPP ;
  189.                              URL      : PChar ;
  190.                              Target   : PChar ;
  191.                              Len      : longint ;
  192.                              var Buf ;
  193.                              IsFile   : TNPBool ;
  194.                              var NotifyData ) : TNPError ;
  195. function  NPN_PostURL( Instance : PNPP ;
  196.                        URL      : PChar ;
  197.                        Window   : PChar ;
  198.                        Len      : longint ;
  199.                        const Buf ;
  200.                        IsFile   : TNPBool ) : TNPError ;
  201. function  NPN_RequestRead( Stream          : PNPStream;
  202.                            const RangeList : TNPByteRange ) : TNPError ;
  203. function  NPN_NewStream( Instance : PNPP ;
  204.                          MimeType : TNPMIMEType ;
  205.                          Target   : PChar ;
  206.                          var Stream : PNPStream ) : TNPError ;
  207. function  NPN_Write( Instance : PNPP ;
  208.                      Stream   : PNPStream ;
  209.                      Len      : longint ;
  210.                      var Buffer ) : longint ;
  211. function  NPN_DestroyStream( Instance : PNPP ;
  212.                              Stream   : PNPStream ;
  213.                              Reason   : TNPReason ) : TNPError ;
  214. procedure NPN_Status( Instance : PNPP ;
  215.                       Message  : PChar ) ;
  216. function  NPN_UserAgent( Instance : PNPP ) : PChar ;
  217. function  NPN_MemAlloc( Size : longint ) : pointer ;
  218. procedure NPN_MemFree( Ptr : pointer ) ;
  219. procedure NPN_ReloadPlugins( ReloadPages : TNPBool ) ;
  220. function  NPN_GetJavaEnv : PJRIEnv ;
  221. function  NPN_GetJavaPeer( Instance : PNPP ) : TJRef ;
  222.  
  223. { End of Plugin API functions to Netscape Navigator }
  224.  
  225. { Netscape function table }
  226.  
  227. type
  228.   TNPN_GetUrl = function( Instance : PNPP ;
  229.                           URL      : PChar ;
  230.                           Target   : PChar ) : TNPError ; cdecl ;
  231.   TNPN_PostUrl = function ( Instance : PNPP ;
  232.                             URL      : PChar ;
  233.                             Target   : PChar ;
  234.                             Len      : longint ;
  235.                             const Buf ;
  236.                             IsFile   : TNPBool ) : TNPError ; cdecl ;
  237.   TNPNRequestRead = function( Stream    : PNPStream;
  238.                               const RangeList : TNPByteRange ) : TNPError ; cdecl ;
  239.   TNPN_NewStream = function( Instance : PNPP ;
  240.                              MimeType : TNPMIMEType ;
  241.                              Target   : PChar ;
  242.                              var Stream : PNPStream ) : TNPError ; cdecl ;
  243.   TNPN_Write = function( Instance : PNPP ;
  244.                          Stream   : PNPStream ;
  245.                          Len      : longint ;
  246.                          var Buffer ) : longint ; cdecl ;
  247.   TNPN_DestroyStream = function( Instance : PNPP ;
  248.                                  Stream   : PNPStream ;
  249.                                  Reason   : TNPReason ) : TNPError ; cdecl ;
  250.   TNPN_Status = procedure( Instance : PNPP ;
  251.                            Message  : PChar ) ; cdecl ;
  252.   TNPN_UserAgent = function( Instance : PNPP ) : PChar ; cdecl ;
  253.   TNPN_MemAlloc = function( Size : longint ) : pointer ; cdecl ;
  254.   TNPN_MemFree = procedure( Ptr : pointer ) ; cdecl ;
  255.   TNPN_MemFlush = function( Size : longint ) : pointer ; cdecl ;
  256.   TNPN_ReloadPlugins = procedure( ReloadPages : TNPBool ) ; cdecl ;
  257.   TNPN_GetJavaEnv = function : PJRIEnv ; cdecl ;
  258.   TNPN_GetJavaPeer = function(Instance : PNPP ) : TJRef ; cdecl ;
  259.   TNPN_GetURLNotify = function( Instance : PNPP ;
  260.                                 URL      : PChar ;
  261.                                 Target   : PChar ;
  262.                                 var NotifyData ) : TNPError ; cdecl ;
  263.   TNPN_PostURLNotify = function( Instance : PNPP ;
  264.                                  URL      : PChar ;
  265.                                  Window   : PChar ;
  266.                                  Len      : longint ;
  267.                                  var Buf ;
  268.                                  IsFile   : TNPBool ;
  269.                                  var NotifyData ) : TNPError ; cdecl ;
  270.  
  271.   PNPNetscapeFuncs = ^TNPNetscapeFuncs ;
  272.   TNPNetscapeFuncs = record
  273.     Size          : word ;
  274.     Version       : word ;
  275.     GetURL        : TNPN_GetUrl ;
  276.     PostURL       : TNPN_PostUrl ;
  277.     RequestRead   : TNPNRequestRead ;
  278.     NewStream     : TNPN_NewStream ;
  279.     Write         : TNPN_Write ;
  280.     DestroyStream : TNPN_DestroyStream ;
  281.     Status        : TNPN_Status ;
  282.     UserAgent     : TNPN_UserAgent ;
  283.     MemAlloc      : TNPN_MemAlloc ;
  284.     MemFree       : TNPN_MemFree ;
  285.     MemFlush      : TNPN_MemFlush ;
  286.     ReloadPlugins : TNPN_ReloadPlugins ;
  287.     GetJavaEnv    : TNPN_GetJavaEnv ;
  288.     GetJavaPeer   : TNPN_GetJavaPeer ;
  289.     GetURLNotify  : TNPN_GetURLNotify ;
  290.     PostURLNotify : TNPN_PostURLNotify ;
  291.   end ;
  292.  
  293. type
  294.   { Plugin function table }
  295.  
  296.   TNPP_New = function( PluginType     : TNPMIMEType ;
  297.                        Instance : PNPP ;
  298.                        Mode           : word ;
  299.                        ArgC           : word ;
  300.                        const Argn     : TPCharArray ;
  301.                        const Argv     : TPCharArray ;
  302.                        const Saved    : TNPSavedData ) : TNPError ; cdecl ;
  303.   TNPP_Destroy = function( Instance : PNPP ;
  304.                            var Save       : PNPSavedData ) : TNPError ; cdecl ;
  305.   TNPP_SetWindow = function( Instance : PNPP ;
  306.                              Window   : PNPWindow ) : TNPError ; cdecl ;
  307.   TNPP_NewStream = function( Instance : PNPP ;
  308.                              MimeType       : TNPMIMEType ;
  309.                  Stream   : PNPStream ;
  310.                              Seekable       : TNPBool ;
  311.                  var SType      : word ) : TNPError ; cdecl ;
  312.   TNPP_DestroyStream = function( Instance : PNPP ;
  313.                                  Stream   : PNPStream ;
  314.                  Reason         : TNPReason ) : TNPError ; cdecl ;
  315.   TNPP_WriteReady = function( Instance : PNPP ;
  316.                               Stream   : PNPStream ) : longint ; cdecl ;
  317.   TNPP_Write = function( Instance : PNPP ;
  318.                          Stream   : PNPStream ;
  319.                          Offset         : longint ;
  320.                          Len            : longint ;
  321.                          var Buffer ) : longint ; cdecl ;
  322.   TNPP_StreamAsFile = procedure( Instance : PNPP ;
  323.                                  Stream   : PNPStream ;
  324.                                  FName          : PChar ) ; cdecl ;
  325.   TNPP_Print = procedure( Instance : PNPP ;
  326.                           PlatformPrint : PNPPrint ) ; cdecl ;
  327.   TNPP_HandleEvent = function( Instance : PNPP ;
  328.                                var Event ) : smallint ; cdecl ;
  329.   TNPP_URLNotify = procedure( Instance : PNPP ;
  330.                               URL            : PChar ;
  331.                               Reason         : TNPReason ;
  332.                               var NotifyData ) ; cdecl ;
  333.  
  334. type
  335.   PNPPluginFuncs = ^TNPPluginFuncs ;
  336.   TNPPluginFuncs = record
  337.     Size          : word ;
  338.     Version       : word ;
  339.     New           : TNPP_New ;
  340.     Destroy       : TNPP_Destroy ;
  341.     SetWindow     : TNPP_SetWindow ;
  342.     NewStream     : TNPP_NewStream ;
  343.     DestroyStream : TNPP_DestroyStream ;
  344.     StreamAsFile  : TNPP_StreamAsFile ;
  345.     WriteReady    : TNPP_WriteReady ;
  346.     Write         : TNPP_Write ;
  347.     Print         : TNPP_Print ;
  348.     HandleEvent   : TNPP_HandleEvent ;
  349.     URLNotify     : TNPP_URLNotify ;
  350.     JavaClass     : TJRIGlobalRef ;
  351.   end ;
  352.  
  353. { Functions exported by the Plugin DLL }
  354.  
  355. function  NP_GetEntryPoints( pFuncs : PNPPluginFuncs ) : TNPError ; stdcall ;
  356. function  NP_Initialize( pFuncs : PNPNetscapeFuncs ) : TNPError ; stdcall ;
  357. function  NP_Shutdown : TNPError ; stdcall ;
  358.  
  359. function  NPP_Initialize : TNPError ; cdecl ;
  360. procedure NPP_Shutdown ; cdecl ;
  361.  
  362. { Plugin functions that have to be supplied to Netscape.         }
  363.  
  364. function  NPP_New( PluginType  : TNPMIMEType ;
  365.                    Instance    : PNPP ;
  366.                    Mode        : word ;
  367.                    ArgC        : word ;
  368.                    const Argn  : TPCharArray ;
  369.                    const Argv  : TPCharArray ;
  370.                    const Saved : TNPSavedData ) : TNPError ; cdecl ;
  371. function  NPP_Destroy( Instance : PNPP ;
  372.                        var Save : PNPSavedData ) : TNPError ; cdecl ;
  373. function  NPP_SetWindow( Instance : PNPP ;
  374.                          Window   : PNPWindow ) : TNPError ; cdecl ;
  375. function  NPP_NewStream( Instance  : PNPP ;
  376.                          MimeType  : TNPMIMEType ;
  377.                          Stream    : PNPStream ;
  378.                          Seekable  : TNPBool ;
  379.                          var SType : word ) : TNPError ; cdecl ;
  380. function  NPP_DestroyStream( Instance : PNPP ;
  381.                              Stream   : PNPStream ;
  382.                              Reason   : TNPReason ) : TNPError ; cdecl ;
  383. function  NPP_WriteReady( Instance : PNPP ;
  384.                           Stream   : PNPStream ) : longint ; cdecl ;
  385. function  NPP_Write( Instance : PNPP ;
  386.                      Stream   : PNPStream ;
  387.                      Offset   : longint ;
  388.                      Len      : longint ;
  389.                      var Buffer ) : longint ; cdecl ;
  390. procedure  NPP_StreamAsFile( Instance : PNPP ;
  391.                              Stream   : PNPStream ;
  392.                              FName    : PChar ) ; cdecl ;
  393. procedure  NPP_Print( Instance      : PNPP ;
  394.                       PlatformPrint : PNPPrint ) ; cdecl ;
  395. function  NPP_HandleEvent( Instance : PNPP ;
  396.                            var Event ) : smallint ; cdecl ;
  397. procedure NPP_URLNotify( Instance : PNPP ;
  398.                          URL      : PChar ;
  399.                          Reason   : TNPReason ;
  400.                          var NotifyData ) ; cdecl ;
  401. function  NPP_GetJavaClass : JRef ; cdecl ;
  402.  
  403. function  Private_GetJavaClass : TJRIGlobalRef ; cdecl ;
  404.  
  405. { OOP Interface to Netscape }
  406.  
  407. type
  408.   TPlugin = class
  409.   private
  410.     FInstance       : PNPP ;
  411.     FWindowHandle   : HWnd ;
  412.     FExtraInfo      : TObject ;
  413.     FPluginType     : string ;
  414.     FParamNames     : TStrings ;
  415.     FParamValues    : TStrings ;
  416.   protected
  417.     procedure WindowHandleChanging ; virtual ;
  418.     procedure WindowHandleChanged ; virtual ;
  419.     procedure WindowChanged ; virtual ;
  420.   public
  421.     constructor Create( AInstance         : PNPP ;
  422.                         AExtraInfo        : TObject ;
  423.                         const APluginType : string ;
  424.                         AMode             : word ;
  425.                         AParamNames       : TStrings ;
  426.                         AParamValues      : TStrings ;
  427.                         const ASaved      : TNPSavedData ) ; virtual ;
  428.     destructor Destroy ; override ;
  429.     property Instance : PNPP read FInstance ;
  430.     property ExtraInfo : TObject read FExtraInfo ;
  431.     property PluginType : string read FPluginType ;
  432.     property ParamNames : TStrings read FParamNames ;
  433.     property ParamValues : TStrings read FParamValues ;
  434.     property WindowHandle : HWnd read FWindowHandle ;
  435.     class procedure Register( const MimeTypes : string ;
  436.                               ExtraInfo       : TObject ) ;
  437.     class function  IsInterested( const ARegisteredMimeTypes : TStrings ;
  438.                                   const APluginType          : string ;
  439.                                   AMode                      : word ;
  440.                                   AParamNames                : TStrings ;
  441.                                   AParamValues               : TStrings ;
  442.                                   const ASaved               : TNPSavedData ) : boolean ;
  443.  
  444.     { Plugin methods - these are called from Netscape Navigator.        }
  445.     { The parameters are more or less the same as the entry points from }
  446.     { Navigator except that there's no Instance parameter since this is }
  447.     { alread available in the Instance property and PChar's have been   }
  448.     { converted to strings.                                             }
  449.     function  SetWindow( Window   : PNPWindow ) : TNPError ; virtual ;
  450.     function  NewStream( MimeType  : TNPMIMEType ;
  451.                          Stream    : PNPStream ;
  452.                          Seekable  : TNPBool ;
  453.                          var SType : word ) : TNPError ; virtual ;
  454.     function  DestroyStream( Stream   : PNPStream ;
  455.                              Reason   : TNPReason ) : TNPError ; virtual ;
  456.     function  WriteReady( Stream   : PNPStream ) : longint ; virtual ;
  457.     function  Write( Stream   : PNPStream ;
  458.                      Offset   : longint ;
  459.                      Len      : longint ;
  460.                      var Buffer ) : longint ; virtual ;
  461.     procedure StreamAsFile( Stream   : PNPStream ;
  462.                             FName    : string ) ; virtual ;
  463.     procedure Print( PlatformPrint : PNPPrint ) ; virtual ;
  464.     procedure URLNotify( URL      : string ;
  465.                          Reason   : TNPReason ;
  466.                          var NotifyData ) ; virtual ;
  467.     function  GetJavaClass : JRef ; virtual ;
  468.   end ;
  469.  
  470.   TPluginClass = class of TPlugin ;
  471.  
  472. implementation
  473.  
  474. const
  475.   Separators = [ '|', ';' ] ;  { MIME type separators within the MIME types string }
  476.  
  477. type
  478.   { TPluginClassInfo }
  479.   { Used by the plugin framework to store information when a TPlugin class
  480.     is registered to handle one or more MIME types. }
  481.   TPluginClassInfo = class
  482.   private
  483.     FMimeTypes   : TStrings ;
  484.     FPluginClass : TPluginClass ;
  485.     FExtraInfo   : TObject ;
  486.   protected
  487.     procedure SetMimeTypes( const AMimeTypes : string ) ;
  488.     procedure SetInfo( const AMimeTypes : string ;
  489.                        APluginClass     : TPluginClass ;
  490.                        AExtraInfo       : TObject ) ;
  491.   public
  492.     constructor Create( const AMimeTypes : string ;
  493.                         APluginClass     : TPluginClass ;
  494.                         AExtraInfo       : TObject ) ;
  495.     destructor Destroy ; override ;
  496.     property MimeTypes : TStrings read FMimeTypes ;
  497.     property PluginClass : TPluginClass read FPluginClass ;
  498.     property ExtraInfo : TObject read FExtraInfo ;
  499.   end ;
  500.  
  501.   { TPlugins }
  502.   { A TList descendant that has additional methods to handle TPluginClassInfo
  503.     objects specifically and to find one given a set of MIME info and plugin
  504.     parameters. Used to hold registered TPlugin classes. }
  505.   TPlugins = class( TList )
  506.   protected
  507.     function  GetItem( Index : integer ) : TPluginClassInfo ;
  508.   public
  509.     destructor Destroy ; override ;
  510.     function  Find( APluginType  : TNPMIMEType ;
  511.                     AMode        : word ;
  512.                     AParamNames  : TStrings ;
  513.                     AParamValues : TStrings ;
  514.                     const ASaved : TNPSavedData ) : TPluginClassInfo ;
  515.     property  Items[ Index : integer ] : TPluginClassInfo read GetItem ; default ;
  516.   end ;
  517.  
  518. var
  519.   Plugins : TPlugins ;
  520.  
  521. { TPluginClassInfo }
  522.  
  523. constructor TPluginClassInfo.Create( const AMimeTypes : string ;
  524.                                      APluginClass     : TPluginClass ;
  525.                                      AExtraInfo       : TObject ) ;
  526. begin
  527.   inherited Create ;
  528.   FMimeTypes := TStringList.Create ;
  529.   SetInfo( AMimeTypes, APluginClass, AExtraInfo ) ;
  530. end ;
  531.  
  532. destructor TPluginClassInfo.Destroy ;
  533. begin
  534.   FExtraInfo.Free ;
  535.   FMimeTypes.Free ;
  536.   inherited Destroy ;
  537. end ;
  538.  
  539. procedure TPluginClassInfo.SetMimeTypes( const AMimeTypes : string ) ;
  540. var i, Start : integer ;
  541. begin
  542.   { Split the MIME types up into a TStrings object for easier processing later }
  543.   { Individual MIME strings can be separated within the whole string either by }
  544.   { pipe characters ('|') or semi-colons.                                      }
  545.   i := 1 ;
  546.   while i <= Length( AMimeTypes ) do begin
  547.     while ( i <= Length( AMimeTypes ) ) and
  548.           ( AMimeTypes[ i ] in Separators ) do
  549.       inc( i ) ;
  550.     Start := i ;
  551.     while ( i <= Length( AMimeTypes ) ) and
  552.           not ( AMimeTypes[ i ] in Separators ) do inc( i ) ;
  553.     if i >= Start then
  554.       FMimeTypes.Add( Copy( AMimeTypes, Start, i - Start ) ) else
  555.       FMimeTypes.Add( '' ) ;
  556.   end ;
  557. end ;
  558.  
  559. procedure TPluginClassInfo.SetInfo( const AMimeTypes : string ;
  560.                                     APluginClass     : TPluginClass ;
  561.                                     AExtraInfo       : TObject ) ;
  562. begin
  563.   { set the plugin info for this plugin class }
  564.   if APluginClass = NIL then
  565.     Raise Exception.Create( 'NIL plugin class not allowed' ) ;
  566.   SetMimeTypes( AMimeTypes ) ;
  567.   FPluginClass := APluginClass ;
  568.   if FExtraInfo <> AExtraInfo then begin
  569.     FExtraInfo.Free ;
  570.     FExtraInfo := AExtraInfo ;
  571.   end ;
  572. end ;
  573.  
  574. { TPlugins }
  575.  
  576. destructor TPlugins.Destroy ;
  577. var i : integer ;
  578. begin
  579.   for i := 0 to Count - 1 do
  580.     Items[ i ].Free ;
  581. end ;
  582.  
  583. function  TPlugins.GetItem( Index : integer ) : TPluginClassInfo ;
  584. begin
  585.   Result := TPluginClassInfo( inherited Items[ Index ] ) ;
  586. end ;
  587.  
  588. function  TPlugins.Find( APluginType  : TNPMIMEType ;
  589.                          AMode        : word ;
  590.                          AParamNames  : TStrings ;
  591.                          AParamValues : TStrings ;
  592.                          const ASaved : TNPSavedData ) : TPluginClassInfo ;
  593. var i : integer ;
  594. begin
  595.   { find a plugin class that wants to handle this plugin type }
  596.   for i := Count - 1 downto 0 do begin
  597.     Result := Items[ i ] ;
  598.     if Result.PluginClass.IsInterested( Result.MimeTypes, StrPas( APluginType ),
  599.                                         AMode, AParamNames, AParamValues, ASaved ) then
  600.       exit ;
  601.   end ;
  602.   Result := NIL ;
  603. end ;
  604.  
  605. { TPlugin }
  606.  
  607. constructor TPlugin.Create( AInstance : PNPP ;
  608.                             AExtraInfo : TObject ;
  609.                             const APluginType : string ;
  610.                             AMode             : word ;
  611.                             AParamNames       : TStrings ;
  612.                             AParamValues      : TStrings ;
  613.                             const ASaved      : TNPSavedData ) ;
  614. begin
  615.   inherited Create ;
  616.   FInstance := AInstance ;
  617.   FExtraInfo := AExtraInfo ;
  618.   FPluginType := PluginType ;
  619.  
  620.   { take ownership of the parameter strings }
  621.   FParamNames := AParamNames ;
  622.   FParamValues := AParamValues ;
  623. end ;
  624.  
  625. destructor TPlugin.Destroy ;
  626. begin
  627.   { free the parameter strings of which we took ownership }
  628.   FParamNames.Free ;
  629.   FParamValues.Free ;
  630.   inherited Destroy ;
  631. end ;
  632.  
  633.  
  634. class procedure TPlugin.Register( const MimeTypes : string ;
  635.                                   ExtraInfo       : TObject ) ;
  636. var Info  : TPluginClassInfo ;
  637. begin
  638.   { Register this plugin class with the plugin framework }
  639.   Info := TPluginClassInfo.Create( MimeTypes, Self, ExtraInfo ) ;
  640.   try
  641.     Plugins.Add( Info ) ;
  642.   except
  643.     Info.Free ;
  644.     Raise ;
  645.   end ;
  646. end ;
  647.  
  648. class function  TPlugin.IsInterested( const ARegisteredMimeTypes : TStrings ;
  649.                                       const APluginType          : string ;
  650.                                       AMode                      : word ;
  651.                                       AParamNames                : TStrings ;
  652.                                       AParamValues               : TStrings ;
  653.                                       const ASaved               : TNPSavedData ) : boolean ;
  654. var i     : integer ;
  655.     AType : string ;
  656. begin
  657.   { Return true if this class is interested in the passed MIME type and parameters. }
  658.   { Default is that class is interested if the requested MIME type is
  659.     in the list of registered MIME types or there are no registered MIME type,
  660.     i.e. an empty string was passed when the class was registered with the framework. }
  661.   Result := true ;
  662.  
  663.   { if no specific strings were registered, then we are interested in all types }
  664.   if ARegisteredMimeTypes.Count = 0 then exit ;
  665.  
  666.   { check type with registered types - again,
  667.     an empty string means interested in all }
  668.   for i := 0 to ARegisteredMimeTypes.Count - 1 do begin
  669.     AType := ARegisteredMimeTypes[ i ] ;
  670.     if ( AType = '' ) or ( CompareText( AType, APluginType ) = 0 ) then
  671.       exit ;
  672.   end ;
  673.   Result := false ;
  674. end ;
  675.  
  676. procedure TPlugin.WindowHandleChanging ;
  677. begin
  678.   { notification method - override if necessary }
  679. end ;
  680.  
  681. procedure TPlugin.WindowHandleChanged ;
  682. begin
  683.   { notification method - override if necessary }
  684. end ;
  685.  
  686. procedure TPlugin.WindowChanged ;
  687. begin
  688.   { Navigator has said that the window has changed size or needs repainted
  689.     but the window handle is still the same.
  690.     Notification method - override if necessary }
  691. end ;
  692.  
  693. function  TPlugin.SetWindow( Window : PNPWindow ) : TNPError ;
  694. var ANewHandle : HWnd ;
  695. begin
  696.   { Netscape has done something with the plugin window, i.e. created one,
  697.     resized one or it simply needs painting. If there's a new window handle,
  698.     call WindowHandleChanging then WindowHandleChanged. In all cases call
  699.     WindowChanged which can be seen as a Paint call if there is no other
  700.     painting mechanism in place. }
  701.   if Window <> NIL then ANewHandle := Window.Window else
  702.     ANewHandle := 0 ;
  703.   if FWindowHandle <> ANewHandle then begin
  704.     WindowHandleChanging ;
  705.     FWindowHandle := ANewHandle ;
  706.     WindowHandleChanged ;
  707.   end ;
  708.   WindowChanged ;
  709.   Result := NPERR_NO_ERROR ;
  710. end ;
  711.  
  712. function  TPlugin.NewStream( MimeType  : TNPMIMEType ;
  713.                              Stream    : PNPStream ;
  714.                              Seekable  : TNPBool ;
  715.                              var SType : word ) : TNPError ;
  716. begin
  717.   Result := NPERR_NO_ERROR ;
  718. end ;
  719.  
  720. function  TPlugin.DestroyStream( Stream : PNPStream ;
  721.                                          Reason : TNPReason ) : TNPError ;
  722. begin
  723.   Result := NPERR_NO_ERROR ;
  724. end ;
  725.  
  726. function  TPlugin.WriteReady( Stream   : PNPStream ) : longint ;
  727. begin
  728.   Result := NPERR_NO_ERROR ;
  729. end ;
  730.  
  731. function  TPlugin.Write( Stream   : PNPStream ;
  732.                          Offset   : longint ;
  733.                          Len      : longint ;
  734.                          var Buffer ) : longint ;
  735. begin
  736.   Result := NPERR_NO_ERROR ;
  737. end ;
  738.  
  739. procedure TPlugin.StreamAsFile( Stream : PNPStream ;
  740.                                 FName  : string ) ;
  741. begin
  742. end ;
  743.  
  744. procedure TPlugin.Print( PlatformPrint : PNPPrint ) ;
  745. begin
  746. end ;
  747.  
  748. procedure TPlugin.URLNotify( URL      : string ;
  749.                              Reason   : TNPReason ;
  750.                              var NotifyData ) ;
  751. begin
  752. end ;
  753.  
  754. function  TPlugin.GetJavaClass : JRef ;
  755. begin
  756.   Result := NIL ;
  757. end ;
  758.  
  759. { Regular Netscape Plugin exports etc. }
  760.  
  761. var
  762.   PluginFuncs     : PNPPluginFuncs ;
  763.   NavigatorFuncs  : PNPNetscapeFuncs ;
  764.  
  765. function  NP_Initialize( pFuncs : PNPNetscapeFuncs ) : TNPError ; stdcall ;
  766. var navMinorVers : integer ;
  767. begin
  768.   if pFuncs = NIL then begin
  769.     Result := NPERR_INVALID_FUNCTABLE_ERROR ;
  770.     exit ;
  771.   end ;
  772.  
  773.   NavigatorFuncs := pFuncs ; { save it for future reference }
  774.  
  775.   { if the plugin's major ver level is lower than the Navigator's, }
  776.   { then they are incompatible, and should return an error         }
  777.   if Hi( pFuncs^.Version ) > NP_VERSION_MAJOR then begin
  778.     Result := NPERR_INCOMPATIBLE_VERSION_ERROR ;
  779.     exit ;
  780.   end ;
  781.  
  782.   {  We have to defer these assignments until NavigatorFuncs is set }
  783.   navMinorVers := NavigatorFuncs^.Version and $FF ;
  784.  
  785.   if navMinorVers >= NPVERS_HAS_NOTIFICATION then
  786.     PluginFuncs^.URLNotify := NPP_URLNotify ;
  787.  
  788.   {$IFDEF WIN32}  { An ugly hack, because Win16 lags behind in Java }
  789.       if navMinorVers >= NPVERS_HAS_LIVECONNECT then
  790.   {$ELSE}
  791.       if navMinorVers >= NPVERS_WIN16_HAS_LIVECONNECT then
  792.   {$ENDIF}
  793.         PluginFuncs^.javaClass := Private_GetJavaClass ;
  794.  
  795.   { NPP_Initialize is a standard (cross-platform) initialize function }
  796.   result := NPP_Initialize ;
  797. end ;
  798.  
  799. (* NP_GetEntryPoints
  800. //
  801. //    fills in the func table used by Navigator to call entry points in
  802. //  plugin DLL.  Note that these entry points ensure that DS is loaded
  803. //  by using the NP_LOADDS macro, when compiling for Win16
  804. *)
  805. function  NP_GetEntryPoints( pFuncs : PNPPluginFuncs ) : TNPError ; stdcall ;
  806. begin
  807.   { trap a NULL ptr }
  808.   if pFuncs = NIL then begin
  809.     result := NPERR_INVALID_FUNCTABLE_ERROR ;
  810.     exit ;
  811.   end ;
  812.  
  813.   { if the plugin's function table is smaller than the plugin expects,
  814.     then they are incompatible, and should return an error }
  815.  
  816.   with pFuncs^ do begin
  817.     Version       := ( NP_VERSION_MAJOR shl 8 ) or NP_VERSION_MINOR ;
  818.     New           := NPP_New ;
  819.     Destroy       := NPP_Destroy ;
  820.     SetWindow     := NPP_SetWindow ;
  821.     NewStream     := NPP_NewStream ;
  822.     DestroyStream := NPP_DestroyStream ;
  823.     StreamAsFile  := NPP_StreamAsFile ;
  824.     WriteReady    := NPP_WriteReady ;
  825.     Write         := NPP_Write ;
  826.     Print         := NPP_Print ;
  827.   end ;
  828.  
  829.   PluginFuncs := pFuncs ;
  830.  
  831.   result := NPERR_NO_ERROR;
  832. end ;
  833.  
  834. (*    called immediately before the plugin DLL is unloaded.
  835. //    This functio shuold check for some ref count on the dll to see if it is
  836. //    unloadable or it needs to stay in memory.
  837. *)
  838. function  NP_Shutdown : TNPError ; stdcall ;
  839. begin
  840.   NPP_Shutdown ;
  841.   NavigatorFuncs := NIL ;
  842.   Result := NPERR_NO_ERROR ;
  843. end ;
  844.  
  845. function  NPP_Initialize : TNPError ; cdecl ;
  846. begin
  847.   { should do any necessary initialization }
  848.   Result := NPERR_NO_ERROR ;
  849. end ;
  850.  
  851. procedure NPP_Shutdown ; cdecl ;
  852. begin
  853.   { should do any necessary tidy-up }
  854. end ;
  855.  
  856. { Given a Java class reference (thru NPP_GetJavaClass) inform JRT
  857.   of this class existence }
  858.  
  859. function  Private_GetJavaClass : TJRIGlobalRef ; cdecl ;
  860. begin
  861.   Result := NIL ;
  862. end ;
  863.  
  864. { Plugin functions that are supplied to Netscape. }
  865. { You implement your plugin by filling in these functions... }
  866.  
  867. {*+++++++++++++++++++++++++++++++++++++++++++++++++
  868.  * NPP_New:
  869.  * Creates a new instance of a plug-in and returns an error value.
  870.  *
  871.  * NPP_New creates a new instance of your plug-in with MIME type specified
  872.  * by pluginType. The parameter mode is NP_EMBED if the instance was created
  873.  * by an EMBED tag, or NP_FULL if the instance was created by a separate file.
  874.  * You can allocate any instance-specific private data in instance->pdata at this
  875.  * time. The NPP pointer is valid until the instance is destroyed.
  876.  +++++++++++++++++++++++++++++++++++++++++++++++++}
  877. function  NPP_New( PluginType     : TNPMIMEType ;
  878.                    Instance       : PNPP ;
  879.                    Mode           : word ;
  880.                    ArgC           : word ;
  881.                    const Argn     : TPCharArray ;
  882.                    const Argv     : TPCharArray ;
  883.                    const Saved    : TNPSavedData ) : TNPError ; cdecl ;
  884.  
  885.   procedure CopyArgs( Count      : integer ;
  886.                       const Args : TPCharArray ;
  887.                       Strings    : TStrings ) ;
  888.   var i : integer ;
  889.   begin
  890.     for i := 0 to Count - 1 do Strings.Add( StrPas( Args[ i ] ) ) ;
  891.   end ;
  892.  
  893. var PluginClassInfo : TPluginClassInfo ;
  894.     ArgNStrings     : TStrings ;
  895.     ArgVStrings     : TStrings ;
  896. begin
  897.   Result := NPERR_GENERIC_ERROR ;
  898.   try
  899.     { move the arguments into TStrings objects }
  900.     ArgVStrings := NIL ;
  901.     ArgNStrings := TStringList.Create ;
  902.     try
  903.       ArgVStrings := TStringList.Create ;
  904.       CopyArgs( ArgC, ArgN, ArgNStrings ) ;
  905.       CopyArgs( ArgC, ArgV, ArgVStrings ) ;
  906.  
  907.       { find a plugin class to handle this instance }
  908.       PluginClassInfo := Plugins.Find( PluginType, Mode, ArgNStrings, ArgVStrings, Saved ) ;
  909.       if PluginClassInfo <> NIL then begin
  910.         Instance.PData := PluginClassInfo.PluginClass.Create( Instance,
  911.                                                               PluginClassInfo.ExtraInfo,
  912.                                                               StrPas( PluginType ),
  913.                                                               Mode,
  914.                                                               ArgNStrings, ArgVStrings,
  915.                                                               Saved ) ;
  916.         Result := NPERR_NO_ERROR ;
  917.       end ;
  918.     finally
  919.       { free the strings if no TPlugin object was created }
  920.       if Instance.PData = NIL then begin
  921.         ArgNStrings.Free ;
  922.         ArgVStrings.Free ;
  923.       end ;
  924.     end ;
  925.   except
  926.     { prevent any exception from leaking out of DLL }
  927.   end ;
  928. end ;
  929.  
  930. {*+++++++++++++++++++++++++++++++++++++++++++++++++
  931.  * NPP_Destroy:
  932.  * Deletes a specific instance of a plug-in and returns an error value.
  933.  
  934.  * NPP_Destroy is called when a plug-in instance is deleted, typically because the
  935.  * user has left the page containing the instance, closed the window, or quit the
  936.  * application. You should delete any private instance-specific information stored
  937.  * in instance->pdata. If the instance being deleted is the last instance created
  938.  * by your plug-in, NPP_Shutdown will subsequently be called, where you can
  939.  * delete any data allocated in NPP_Initialize to be shared by all your plug-in's
  940.  * instances. Note that you should not perform any graphics operations in
  941.  * NPP_Destroy as the instance's window is no longer guaranteed to be valid.
  942.  +++++++++++++++++++++++++++++++++++++++++++++++++}
  943. function  NPP_Destroy( Instance : PNPP ;
  944.                        var Save       : PNPSavedData ) : TNPError ; cdecl ;
  945. begin
  946.   Result := NPERR_GENERIC_ERROR ;
  947.   try
  948.     if ( Instance <> NIL ) and ( Instance.PData <> NIL ) then
  949.       TPlugin( Instance.PData ).Free ;
  950.     Result := NPERR_NO_ERROR ;
  951.   except
  952.     { prevent any exception from leaking out of DLL }
  953.   end ;
  954. end ;
  955.  
  956. {+++++++++++++++++++++++++++++++++++++++++++++++++
  957.  * NPP_SetWindow:
  958.  * Sets the window in which a plug-in draws, and returns an error value.
  959.  *
  960.  * NPP_SetWindow informs the plug-in instance specified by instance of the
  961.  * the window denoted by window in which the instance draws. This NPWindow
  962.  * pointer is valid for the life of the instance, or until NPP_SetWindow is called
  963.  * again with a different value. Subsequent calls to NPP_SetWindow for a given
  964.  * instance typically indicate that the window has been resized. If either window
  965.  * or window->window are NULL, the plug-in must not perform any additional
  966.  * graphics operations on the window and should free any resources associated
  967.  * with the window.
  968.  +++++++++++++++++++++++++++++++++++++++++++++++++}
  969. function  NPP_SetWindow( Instance : PNPP ;
  970.                          Window   : PNPWindow ) : TNPError ; cdecl ;
  971. begin
  972.   Result := NPERR_GENERIC_ERROR ;
  973.   try
  974.     if ( Instance <> NIL ) and ( Instance.PData <> NIL ) then
  975.       TPlugin( Instance.PData ).SetWindow( Window ) ;
  976.   except
  977.     { prevent any exception from leaking out of DLL }
  978.   end ;
  979. end ;
  980.  
  981. {*+++++++++++++++++++++++++++++++++++++++++++++++++
  982.  * NPP_NewStream:
  983.  * Notifies an instance of a new data stream and returns an error value.
  984.  *
  985.  * NPP_NewStream notifies the instance denoted by instance of the creation of
  986.  * a new stream specifed by stream. The NPStream* pointer is valid until the
  987.  * stream is destroyed. The MIME type of the stream is provided by the
  988.  * parameter type.
  989.  +++++++++++++++++++++++++++++++++++++++++++++++++}
  990. function  NPP_NewStream( Instance  : PNPP ;
  991.                          MimeType  : TNPMIMEType ;
  992.                          Stream    : PNPStream ;
  993.                          Seekable  : TNPBool ;
  994.                          var SType : word ) : TNPError ; cdecl ;
  995. begin
  996.   Result := NPERR_GENERIC_ERROR ;
  997.   try
  998.     if ( Instance <> NIL ) and ( Instance.PData <> NIL ) then
  999.       Result := TPlugin( Instance.PData ).NewStream( MimeType, Stream, Seekable, SType ) ;
  1000.   except
  1001.     { prevent any exception from leaking out of DLL }
  1002.   end ;
  1003. end ;
  1004.  
  1005. {*+++++++++++++++++++++++++++++++++++++++++++++++++
  1006.  * NPP_DestroyStream:
  1007.  * Indicates the closure and deletion of a stream, and returns an error value.
  1008.  *
  1009.  * The NPP_DestroyStream function is called when the stream identified by
  1010.  * stream for the plug-in instance denoted by instance will be destroyed. You
  1011.  * should delete any private data allocated in stream->pdata at this time.
  1012.  +++++++++++++++++++++++++++++++++++++++++++++++++}
  1013. function  NPP_DestroyStream( Instance : PNPP ;
  1014.                              Stream   : PNPStream ;
  1015.                              Reason         : TNPReason ) : TNPError ; cdecl ;
  1016. begin
  1017.   Result := NPERR_GENERIC_ERROR ;
  1018.   try
  1019.     if ( Instance <> NIL ) and ( Instance.PData <> NIL ) then
  1020.       Result := TPlugin( Instance.PData ).DestroyStream( Stream, Reason ) ;
  1021.   except
  1022.     { prevent any exception from leaking out of DLL }
  1023.   end ;
  1024. end ;
  1025.  
  1026. {* PLUGIN DEVELOPERS:
  1027.  *    These next 2 functions are directly relevant in a plug-in which
  1028.  *    handles the data in a streaming manner. If you want zero bytes
  1029.  *    because no buffer space is YET available, return 0. As long as
  1030.  *    the stream has not been written to the plugin, Navigator will
  1031.  *    continue trying to send bytes.  If the plugin doesn't want them,
  1032.  *    just return some large number from NPP_WriteReady(), and
  1033.  *    ignore them in NPP_Write().  For a NP_ASFILE stream, they are
  1034.  *    still called but can safely be ignored using this strategy.
  1035.  *}
  1036.  
  1037. const STREAMBUFSIZE : longint = $0FFFFFFF ; {* If we are reading from a file in NPAsFile
  1038.                              * mode so we can take any size stream in our
  1039.                                              * write call (since we ignore it) }
  1040.  
  1041. {*+++++++++++++++++++++++++++++++++++++++++++++++++
  1042.  * NPP_WriteReady:
  1043.  * Returns the maximum number of bytes that an instance is prepared to accept
  1044.  * from the stream.
  1045.  *
  1046.  * NPP_WriteReady determines the maximum number of bytes that the
  1047.  * instance will consume from the stream in a subsequent call NPP_Write. This
  1048.  * function allows Netscape to only send as much data to the instance as the
  1049.  * instance is capable of handling at a time, allowing more efficient use of
  1050.  * resources within both Netscape and the plug-in.
  1051.  +++++++++++++++++++++++++++++++++++++++++++++++++}
  1052. function  NPP_WriteReady( Instance : PNPP ;
  1053.                           Stream   : PNPStream ) : longint ; cdecl ;
  1054. begin
  1055.   Result := NPERR_GENERIC_ERROR ;
  1056.   try
  1057.     if ( Instance <> NIL ) and ( Instance.PData <> NIL ) then
  1058.       Result := TPlugin( Instance.PData ).WriteReady( Stream ) ;
  1059.   except
  1060.     { prevent any exception from leaking out of DLL }
  1061.   end ;
  1062. end ;
  1063.  
  1064. {*+++++++++++++++++++++++++++++++++++++++++++++++++
  1065.  * NPP_Write:
  1066.  * Delivers data from a stream and returns the number of bytes written.
  1067.  *
  1068.  * NPP_Write is called after a call to NPP_NewStream in which the plug-in
  1069.  * requested a normal-mode stream, in which the data in the stream is delivered
  1070.  * progressively over a series of calls to NPP_WriteReady and NPP_Write. The
  1071.  * function delivers a buffer buf of len bytes of data from the stream identified
  1072.  * by stream to the instance. The parameter offset is the logical position of
  1073.  * buf from the beginning of the data in the stream.
  1074.  *
  1075.  * The function returns the number of bytes written (consumed by the instance).
  1076.  * A negative return value causes an error on the stream, which will
  1077.  * subsequently be destroyed via a call to NPP_DestroyStream.
  1078.  *
  1079.  * Note that a plug-in must consume at least as many bytes as it indicated in the
  1080.  * preceeding NPP_WriteReady call. All data consumed must be either processed
  1081.  * immediately or copied to memory allocated by the plug-in: the buf parameter
  1082.  * is not persistent.
  1083.  +++++++++++++++++++++++++++++++++++++++++++++++++}
  1084. function  NPP_Write( Instance : PNPP ;
  1085.                      Stream   : PNPStream ;
  1086.                      Offset         : longint ;
  1087.                      Len            : longint ;
  1088.                      var Buffer ) : longint ; cdecl ;
  1089. begin
  1090.   Result := NPERR_GENERIC_ERROR ;
  1091.   try
  1092.     if ( Instance <> NIL ) and ( Instance.PData <> NIL ) then
  1093.       Result := TPlugin( Instance.PData ).Write( Stream, Offset, Len, Buffer ) ;
  1094.   except
  1095.     { prevent any exception from leaking out of DLL }
  1096.   end ;
  1097. end ;
  1098.  
  1099. {*+++++++++++++++++++++++++++++++++++++++++++++++++
  1100.  * NPP_StreamAsFile:
  1101.  * Provides a local file name for the data from a stream.
  1102.  *
  1103.  * NPP_StreamAsFile provides the instance with a full path to a local file,
  1104.  * identified by fname, for the stream specified by stream. NPP_StreamAsFile is
  1105.  * called as a result of the plug-in requesting mode NP_ASFILEONLY or
  1106.  * NP_ASFILE in a previous call to NPP_NewStream. If an error occurs while
  1107.  * retrieving the data or writing the file, fname may be NULL.
  1108.  +++++++++++++++++++++++++++++++++++++++++++++++++}
  1109. procedure  NPP_StreamAsFile( Instance : PNPP ;
  1110.                              Stream   : PNPStream ;
  1111.                              FName          : PChar ) ; cdecl ;
  1112. begin
  1113.   try
  1114.     if ( Instance <> NIL ) and ( Instance.PData <> NIL ) then
  1115.       TPlugin( Instance.PData ).StreamAsFile( Stream, FName ) ;
  1116.   except
  1117.     { prevent any exception from leaking out of DLL }
  1118.   end ;
  1119. end ;
  1120.  
  1121. {*+++++++++++++++++++++++++++++++++++++++++++++++++
  1122.  * NPP_Print:
  1123.  +++++++++++++++++++++++++++++++++++++++++++++++++}
  1124. procedure  NPP_Print( Instance : PNPP ;
  1125.                       PlatformPrint : PNPPrint ) ; cdecl ;
  1126. begin
  1127.   try
  1128.     if ( Instance <> NIL ) and ( Instance.PData <> NIL ) then
  1129.       TPlugin( Instance.PData ).Print( PlatformPrint ) ;
  1130.   except
  1131.     { prevent any exception from leaking out of DLL }
  1132.   end ;
  1133. end ;
  1134.  
  1135. {*+++++++++++++++++++++++++++++++++++++++++++++++++
  1136.  * NPP_HandleEvent:
  1137.  * Mac-only, but stub must be present for Windows
  1138.  * Delivers a platform-specific event to the instance.
  1139.  *
  1140.  * On the Macintosh, event is a pointer to a standard Macintosh EventRecord.
  1141.  * All standard event types are passed to the instance as appropriate. In general,
  1142.  * return TRUE if you handle the event and FALSE if you ignore the event.
  1143.  +++++++++++++++++++++++++++++++++++++++++++++++++}
  1144. function  NPP_HandleEvent( Instance : PNPP ;
  1145.                            var Event ) : smallint ; cdecl ;
  1146. begin
  1147.   Result := NPERR_NO_ERROR ;
  1148. end ;
  1149.  
  1150. {*+++++++++++++++++++++++++++++++++++++++++++++++++
  1151.  * NPP_URLNotify:
  1152.  * Notifies the instance of the completion of a URL request.
  1153.  *
  1154.  * NPP_URLNotify is called when Netscape completes a NPN_GetURLNotify or
  1155.  * NPN_PostURLNotify request, to inform the plug-in that the request,
  1156.  * identified by url, has completed for the reason specified by reason. The most
  1157.  * common reason code is NPRES_DONE, indicating simply that the request
  1158.  * completed normally. Other possible reason codes are NPRES_USER_BREAK,
  1159.  * indicating that the request was halted due to a user action (for example,
  1160.  * clicking the "Stop" button), and NPRES_NETWORK_ERR, indicating that the
  1161.  * request could not be completed (for example, because the URL could not be
  1162.  * found). The complete list of reason codes is found in npapi.h.
  1163.  *
  1164.  * The parameter notifyData is the same plug-in-private value passed as an
  1165.  * argument to the corresponding NPN_GetURLNotify or NPN_PostURLNotify
  1166.  * call, and can be used by your plug-in to uniquely identify the request.
  1167.  +++++++++++++++++++++++++++++++++++++++++++++++++}
  1168. procedure  NPP_URLNotify( Instance       : PNPP ;
  1169.                           URL            : PChar ;
  1170.                           Reason         : TNPReason ;
  1171.                           var NotifyData ) ; cdecl ;
  1172. begin
  1173.   try
  1174.     if ( Instance <> NIL ) and ( Instance.PData <> NIL ) then
  1175.       TPlugin( Instance.PData ).URLNotify( StrPas( URL ), Reason, NotifyData ) ;
  1176.   except
  1177.     { prevent any exception from leaking out of DLL }
  1178.   end ;
  1179. end ;
  1180.  
  1181. {*+++++++++++++++++++++++++++++++++++++++++++++++++
  1182.  * NPP_GetJavaClass:
  1183.  * New in Netscape Navigator 3.0.
  1184.  *
  1185.  * NPP_GetJavaClass is called during initialization to ask your plugin
  1186.  * what its associated Java class is. If you don't have one, just return
  1187.  * NULL. Otherwise, use the javah-generated "use_" function to both
  1188.  * initialize your class and return it. If you can't find your class, an
  1189.  * error will be signalled by "use_" and will cause the Navigator to
  1190.  * complain to the user.
  1191.  +++++++++++++++++++++++++++++++++++++++++++++++++}
  1192. function  NPP_GetJavaClass : JRef ; cdecl ;
  1193. begin
  1194.   Result := NIL ;
  1195. end ;
  1196.  
  1197. { Netscape Navigator functions }
  1198.  
  1199. procedure  NPN_Version( var PluginMajor : integer ;
  1200.                         var PluginMinor : integer ;
  1201.                         var NetscapeMajor : integer ;
  1202.                         var NetscapeMinor : integer ) ;
  1203. begin
  1204.   PluginMajor := NP_VERSION_MAJOR ;
  1205.   PluginMinor := NP_VERSION_MINOR ;
  1206.   { Netscape C sample doesn't return anything in NetscapeMajor and NetscapeMinor! }
  1207.   { The following is commented out in the samples. }
  1208.   { NetscapeMajor := Hi( NavigatorFuncs.Version ) ; }
  1209.   { NetscapeMinor := Lo( NavigatorFuncs.Version ) ; }
  1210. end ;
  1211.  
  1212. function  NPN_GetURLNotify( Instance : PNPP ;
  1213.                             URL      : PChar ;
  1214.                             Target   : PChar ;
  1215.                             var NotifyData ) : TNPError ;
  1216. begin
  1217.   if ( NavigatorFuncs.Version and $FF >= NPVERS_HAS_NOTIFICATION ) then
  1218.     Result := NavigatorFuncs.GetURLNotify( Instance, URL, Target, NotifyData ) else
  1219.     Result := NPERR_INCOMPATIBLE_VERSION_ERROR ;
  1220. end ;
  1221.  
  1222. function  NPN_GetURL( Instance : PNPP ;
  1223.                       URL      : PChar ;
  1224.                       Target   : PChar ) : TNPError ;
  1225. begin
  1226.   Result := NavigatorFuncs.GetURL( Instance, URL, Target ) ;
  1227. end ;
  1228.  
  1229. function  NPN_PostURLNotify( Instance : PNPP ;
  1230.                              URL      : PChar ;
  1231.                              Target   : PChar ;
  1232.                              Len      : longint ;
  1233.                              var Buf ;
  1234.                              IsFile   : TNPBool ;
  1235.                              var NotifyData ) : TNPError ;
  1236. begin
  1237.   if ( NavigatorFuncs.Version and $FF >= NPVERS_HAS_NOTIFICATION ) then
  1238.     Result := NavigatorFuncs.PostURLNotify( Instance, URL, Target,
  1239.                                                Len, Buf, IsFile, NotifyData )
  1240.   else
  1241.     Result := NPERR_INCOMPATIBLE_VERSION_ERROR ;
  1242. end ;
  1243.  
  1244. function  NPN_PostURL( Instance : PNPP ;
  1245.                        URL      : PChar ;
  1246.                        Window   : PChar ;
  1247.                        Len      : longint ;
  1248.                        const Buf ;
  1249.                        IsFile   : TNPBool ) : TNPError ;
  1250. begin
  1251.   Result := NavigatorFuncs.PostURL( Instance, URL, Window, Len, Buf, IsFile ) ;
  1252. end ;
  1253.  
  1254. {  Requests that a number of bytes be provided on a stream.  Typically
  1255.    this would be used if a stream was in "pull" mode.  An optional
  1256.    position can be provided for streams which are seekable.
  1257. }
  1258. function  NPN_RequestRead( Stream          : PNPStream;
  1259.                            const RangeList : TNPByteRange ) : TNPError ;
  1260. begin
  1261.   Result := NavigatorFuncs.RequestRead( Stream, RangeList ) ;
  1262. end ;
  1263.  
  1264. {  Creates a new stream of data from the plug-in to be interpreted
  1265.    by Netscape in the current window.
  1266. }
  1267. function  NPN_NewStream( Instance : PNPP ;
  1268.                          MimeType : TNPMIMEType ;
  1269.                          Target   : PChar ;
  1270.                          var Stream : PNPStream ) : TNPError ;
  1271. begin
  1272.   if ( NavigatorFuncs.Version and $FF >= NPVERS_HAS_STREAMOUTPUT ) then
  1273.     Result := NavigatorFuncs.NewStream( Instance, MimeType, Target, Stream ) else
  1274.     Result := NPERR_INCOMPATIBLE_VERSION_ERROR ;
  1275. end ;
  1276.  
  1277. {  Provides len bytes of data.
  1278. }
  1279. function  NPN_Write( Instance : PNPP ;
  1280.                      Stream   : PNPStream ;
  1281.                      Len      : longint ;
  1282.                      var Buffer ) : longint ;
  1283. begin
  1284.   if ( NavigatorFuncs.Version and $FF >= NPVERS_HAS_STREAMOUTPUT ) then
  1285.     Result := NavigatorFuncs.Write( Instance, Stream, Len, Buffer ) else
  1286.     Result := -1 ;
  1287. end ;
  1288.  
  1289. { Closes a stream object.
  1290.   reason indicates why the stream was closed.
  1291. }
  1292. function  NPN_DestroyStream( Instance : PNPP ;
  1293.                              Stream   : PNPStream ;
  1294.                              Reason   : TNPReason ) : TNPError ;
  1295. begin
  1296.   if ( NavigatorFuncs.Version and $FF >= NPVERS_HAS_STREAMOUTPUT ) then
  1297.     Result := NavigatorFuncs.DestroyStream( Instance, Stream, Reason ) else
  1298.     Result := NPERR_INCOMPATIBLE_VERSION_ERROR ;
  1299. end ;
  1300.  
  1301. {  Provides a text status message in the Netscape client user interface
  1302. }
  1303. procedure NPN_Status( Instance : PNPP ;
  1304.                       Message  : PChar ) ;
  1305. begin
  1306.   NavigatorFuncs.Status( Instance, Message ) ;
  1307. end ;
  1308.  
  1309. {  returns the user agent string of Navigator, which contains version info
  1310. }
  1311. function  NPN_UserAgent( Instance : PNPP ) : PChar ;
  1312. begin
  1313.   Result := NavigatorFuncs.UserAgent( Instance ) ;
  1314. end ;
  1315.  
  1316. {  allocates memory from the Navigator's memory space.  Necessary so that
  1317.    saved instance data may be freed by Navigator when exiting.
  1318. }
  1319.  
  1320. function  NPN_MemAlloc( Size : longint ) : pointer ;
  1321. begin
  1322.   Result := NavigatorFuncs.MemAlloc( Size ) ;
  1323. end ;
  1324.  
  1325. {  reciprocal of MemAlloc() above
  1326. }
  1327. procedure NPN_MemFree( Ptr : pointer ) ;
  1328. begin
  1329.   NavigatorFuncs.MemFree( Ptr ) ;
  1330. end ;
  1331.  
  1332. { private function to Netscape.  do not use! (so why's it here??? -Mike)
  1333. }
  1334. procedure NPN_ReloadPlugins( ReloadPages : TNPBool ) ;
  1335. begin
  1336.   NavigatorFuncs.ReloadPlugins( ReloadPages ) ;
  1337. end ;
  1338.  
  1339. function  NPN_GetJavaEnv : PJRIEnv ;
  1340. begin
  1341.   Result := NavigatorFuncs.GetJavaEnv ;
  1342. end ;
  1343.  
  1344. function  NPN_GetJavaPeer( Instance : PNPP ) : TJRef ;
  1345. begin
  1346.   Result := NavigatorFuncs.GetJavaPeer( Instance ) ;
  1347. end ;
  1348.  
  1349. initialization
  1350.   Plugins := TPlugins.Create ;
  1351. finalization
  1352.   Plugins.Free ;
  1353. end.
  1354.  
  1355.