home *** CD-ROM | disk | FTP | other *** search
/ Tools / WinSN5.0Ver.iso / NETSCAP.50 / WIN1998.ZIP / ns / lib / plugin / npglue.h < prev    next >
Encoding:
C/C++ Source or Header  |  1998-04-08  |  14.8 KB  |  567 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. #ifndef npglue_h__
  20. #define npglue_h__
  21.  
  22. #if defined(__cplusplus)
  23. extern "C" {
  24. #endif
  25.  
  26. #include "net.h"
  27. #include "np.h"
  28. #include "nppg.h"
  29. #include "client.h"
  30. #include "xpassert.h" 
  31. #include "ntypes.h"
  32. #include "fe_proto.h"
  33. #include "cvactive.h"
  34. #include "gui.h"            /* For XP_AppCodeName */
  35. #include "merrors.h"
  36. #include "xpgetstr.h"
  37. #include "java.h"
  38. #include "nppriv.h"
  39. #include "shist.h"
  40.  
  41. #include "prefapi.h"
  42. #include "proto.h"
  43.  
  44. #ifdef MOCHA
  45. #include "libmocha.h"
  46. #include "libevent.h"
  47. #include "layout.h"         /* XXX From ../layout */
  48. #endif
  49.  
  50. #ifdef LAYERS
  51. #include "layers.h"
  52. #endif /* LAYERS */
  53.  
  54. #include "nsAgg.h"      // nsPluginManager aggregates nsJVMManager
  55. #include "nsjvm.h"
  56.  
  57. extern int XP_PLUGIN_LOADING_PLUGIN;
  58. extern int MK_BAD_CONNECT;
  59. extern int XP_PLUGIN_NOT_FOUND;
  60. extern int XP_PLUGIN_CANT_LOAD_PLUGIN;
  61. extern int XP_PROGRESS_STARTING_JAVA;
  62.  
  63. #define NP_LOCK    1
  64. #define NP_UNLOCK  0
  65.  
  66. #define NPTRACE(n, msg)    TRACEMSG(msg)
  67.  
  68. #define RANGE_EQUALS  "bytes="
  69.  
  70. /* @@@@ steal the private call from netlib */
  71. extern void NET_SetCallNetlibAllTheTime(MWContext *context, char *caller);
  72. extern void NET_ClearCallNetlibAllTheTime(MWContext *context, char *caller);
  73.  
  74. #if defined(XP_WIN) || defined(XP_OS2)
  75. /* Can't include FEEMBED.H because it's full of C++ */
  76. extern NET_StreamClass *EmbedStream(int iFormatOut, void *pDataObj, URL_Struct *pUrlData, MWContext *pContext);
  77. extern void EmbedUrlExit(URL_Struct *pUrl, int iStatus, MWContext *pContext);
  78. #endif
  79.  
  80. extern void NET_RegisterAllEncodingConverters(char* format_in, FO_Present_Types format_out);
  81.  
  82.  
  83. /* Internal prototypes */
  84.  
  85. void
  86. NPL_EmbedURLExit(URL_Struct *urls, int status, MWContext *cx);
  87.  
  88. void
  89. NPL_URLExit(URL_Struct *urls, int status, MWContext *cx);
  90.  
  91. void
  92. np_streamAsFile(np_stream* stream);
  93.  
  94. NPError
  95. np_switchHandlers(np_instance* instance,
  96.                   np_handle* newHandle,
  97.                   np_mimetype* newMimeType,
  98.                   char* requestedType);
  99.  
  100. NET_StreamClass*
  101. np_newstream(URL_Struct *urls, np_handle *handle, np_instance *instance);
  102.  
  103. void
  104. np_findPluginType(NPMIMEType type, void* pdesc, np_handle** outHandle, np_mimetype** outMimetype);
  105.  
  106. void 
  107. np_enablePluginType(np_handle* handle, np_mimetype* mimetype, XP_Bool enabled);
  108.  
  109. void
  110. np_bindContext(NPEmbeddedApp* app, MWContext* cx);
  111.  
  112. void
  113. np_unbindContext(NPEmbeddedApp* app, MWContext* cx);
  114.  
  115. void
  116. np_deleteapp(MWContext* cx, NPEmbeddedApp* app);
  117.  
  118. np_instance*
  119. np_newinstance(np_handle *handle, MWContext *cx, NPEmbeddedApp *app,
  120.                np_mimetype *mimetype, char *requestedType);
  121.                                
  122. void
  123. np_delete_instance(np_instance *instance);
  124.  
  125. void
  126. np_recover_mochaWindow(JRIEnv * env, np_instance * instance);
  127.  
  128. XP_Bool
  129. np_FakeHTMLStream(URL_Struct* urls, MWContext* cx, char * fakehtml);
  130.  
  131. /* Navigator plug-in API function prototypes */
  132.  
  133. /*
  134.  * Use this macro before each exported function
  135.  * (between the return address and the function
  136.  * itself), to ensure that the function has the
  137.  * right calling conventions on Win16.
  138.  */
  139. #ifdef XP_WIN16
  140. #define NP_EXPORT __export
  141. #elif defined(XP_OS2)
  142. #define NP_EXPORT _System
  143. #else
  144. #define NP_EXPORT
  145. #endif
  146.  
  147. NPError NP_EXPORT
  148. npn_requestread(NPStream *pstream, NPByteRange *rangeList);
  149.  
  150. NPError NP_EXPORT
  151. npn_geturlnotify(NPP npp, const char* relativeURL, const char* target, void* notifyData);
  152.  
  153. NPError NP_EXPORT
  154. npn_getvalue(NPP npp, NPNVariable variable, void *r_value);
  155.  
  156. NPError NP_EXPORT
  157. npn_setvalue(NPP npp, NPPVariable variable, void *r_value);
  158.  
  159. NPError NP_EXPORT
  160. npn_geturl(NPP npp, const char* relativeURL, const char* target);
  161.  
  162. NPError NP_EXPORT
  163. npn_posturlnotify(NPP npp, const char* relativeURL, const char *target,
  164.                   uint32 len, const char *buf, NPBool file, void* notifyData);
  165.  
  166. NPError NP_EXPORT
  167. npn_posturl(NPP npp, const char* relativeURL, const char *target, uint32 len,
  168.             const char *buf, NPBool file);
  169.  
  170. NPError
  171. np_geturlinternal(NPP npp, const char* relativeURL, const char* target, 
  172.                   const char* altHost, const char* referer, PRBool forceJSEnabled,
  173.                   NPBool notify, void* notifyData);
  174.  
  175. NPError
  176. np_posturlinternal(NPP npp, const char* relativeURL, const char *target, 
  177.                    const char* altHost, const char* referer, PRBool forceJSEnabled,
  178.                    uint32 len, const char *buf, NPBool file, NPBool notify, void* notifyData);
  179.  
  180. NPError NP_EXPORT
  181. npn_newstream(NPP npp, NPMIMEType type, const char* window, NPStream** pstream);
  182.  
  183. int32 NP_EXPORT
  184. npn_write(NPP npp, NPStream *pstream, int32 len, void *buffer);
  185.  
  186. NPError NP_EXPORT
  187. npn_destroystream(NPP npp, NPStream *pstream, NPError reason);
  188.  
  189. void NP_EXPORT
  190. npn_status(NPP npp, const char *message);
  191.  
  192. void NP_EXPORT
  193. npn_registerwindow(NPP npp, void* window);
  194.  
  195. void NP_EXPORT
  196. npn_unregisterwindow(NPP npp, void* window);
  197.  
  198. #if defined(XP_MAC) && !defined(powerc)
  199. #pragma pointers_in_D0
  200. #endif
  201. const char* NP_EXPORT
  202. npn_useragent(NPP npp);
  203. #if defined(XP_MAC) && !defined(powerc)
  204. #pragma pointers_in_A0
  205. #endif
  206.  
  207. #if defined(XP_MAC) && !defined(powerc)
  208. #pragma pointers_in_D0
  209. #endif
  210. void* NP_EXPORT
  211. npn_memalloc (uint32 size);
  212. #if defined(XP_MAC) && !defined(powerc)
  213. #pragma pointers_in_A0
  214. #endif
  215.  
  216.  
  217. void NP_EXPORT
  218. npn_memfree (void *ptr);
  219.  
  220. uint32 NP_EXPORT
  221. npn_memflush(uint32 size);
  222.  
  223. void NP_EXPORT
  224. npn_reloadplugins(NPBool reloadPages);
  225.  
  226. void NP_EXPORT
  227. npn_invalidaterect(NPP npp, NPRect *invalidRect);
  228.  
  229. void NP_EXPORT
  230. npn_invalidateregion(NPP npp, NPRegion invalidRegion);
  231.  
  232. void NP_EXPORT
  233. npn_forceredraw(NPP npp);
  234.  
  235. #if defined(XP_MAC) && !defined(powerc)
  236. #pragma pointers_in_D0
  237. #endif
  238. JRIEnv* NP_EXPORT
  239. npn_getJavaEnv(void);
  240. #if defined(XP_MAC) && !defined(powerc)
  241. #pragma pointers_in_A0
  242. #endif
  243.  
  244.  
  245. #if defined(XP_MAC) && !defined(powerc)
  246. #pragma pointers_in_D0
  247. #endif
  248. jref NP_EXPORT
  249. npn_getJavaPeer(NPP npp);
  250. #if defined(XP_MAC) && !defined(powerc)
  251. #pragma pointers_in_A0
  252. #endif
  253.  
  254.  
  255. /* End of function prototypes */
  256.  
  257.  
  258. /* this is a hack for now */
  259. #define NP_MAXBUF (0xE000)
  260.  
  261. ////////////////////////////////////////////////////////////////////////////////
  262.  
  263. typedef NPPluginError
  264. (PR_CALLBACK* NP_CREATEPLUGIN)(NPIPluginManager* mgr, NPIPlugin* *result);
  265.  
  266. class nsPluginManager : public NPIPluginManager {
  267. public:
  268.  
  269.     // QueryInterface may be used to obtain a JRIEnv or JNIEnv
  270.     // from an NPIPluginManager.
  271.     // (Corresponds to NPN_GetJavaEnv.)
  272.  
  273.     ////////////////////////////////////////////////////////////////////////////
  274.     // from NPIPluginManager:
  275.  
  276.     // (Corresponds to NPN_ReloadPlugins.)
  277.     NS_IMETHOD_(void)
  278.     ReloadPlugins(PRBool reloadPages);
  279.  
  280.     // (Corresponds to NPN_MemAlloc.)
  281.     NS_IMETHOD_(void*)
  282.     MemAlloc(PRUint32 size);
  283.  
  284.     // (Corresponds to NPN_MemFree.)
  285.     NS_IMETHOD_(void)
  286.     MemFree(void* ptr);
  287.  
  288.     // (Corresponds to NPN_MemFlush.)
  289.     NS_IMETHOD_(PRUint32)
  290.     MemFlush(PRUint32 size);
  291.  
  292.     ////////////////////////////////////////////////////////////////////////////
  293.     // nsPluginManager specific methods:
  294.  
  295.     NS_DECL_AGGREGATED
  296.  
  297.     static NS_METHOD
  298.     Create(nsISupports* outer, const nsIID& aIID, void* *aInstancePtr);
  299.  
  300. protected:
  301.     nsPluginManager(nsISupports* outer);
  302.     virtual ~nsPluginManager(void);
  303.  
  304.     // aggregated sub-intefaces:
  305.     NPIJVMPluginManager* GetJVMMgr(const nsIID& aIID);
  306.     nsISupports* fJVMMgr;
  307.  
  308. };
  309.  
  310. extern nsPluginManager* thePluginManager;
  311.  
  312. ////////////////////////////////////////////////////////////////////////////////
  313.  
  314. class nsPluginInstancePeer : public NPILiveConnectPluginInstancePeer {
  315. public:
  316.  
  317.     nsPluginInstancePeer(NPP npp);
  318.     virtual ~nsPluginInstancePeer(void);
  319.  
  320.     NS_DECL_AGGREGATED
  321.  
  322.     NPIPluginInstance* GetUserInstance(void) {
  323.         return userInst;
  324.     }
  325.  
  326.     void SetUserInstance(NPIPluginInstance* inst) {
  327.         userInst = inst;
  328.     }
  329.  
  330.     ////////////////////////////////////////////////////////////////////////////
  331.     // Methods specific to NPIPluginInstancePeer:
  332.  
  333.     NS_IMETHOD_(NPIPlugin*)
  334.     GetClass(void);
  335.  
  336.     // (Corresponds to NPP_New's MIMEType argument.)
  337.     NS_IMETHOD_(nsMIMEType)
  338.     GetMIMEType(void);
  339.  
  340.     // (Corresponds to NPP_New's mode argument.)
  341.     NS_IMETHOD_(NPPluginType)
  342.     GetMode(void);
  343.  
  344.     // (Corresponds to NPP_New's argc argument.)
  345.     NS_IMETHOD_(PRUint16)
  346.     GetArgCount(void);
  347.  
  348.     // (Corresponds to NPP_New's argn argument.)
  349.     NS_IMETHOD_(const char**)
  350.     GetArgNames(void);
  351.  
  352.     // (Corresponds to NPP_New's argv argument.)
  353.     NS_IMETHOD_(const char**)
  354.     GetArgValues(void);
  355.  
  356.     NS_IMETHOD_(NPIPluginManager*)
  357.     GetPluginManager(void);
  358.  
  359.     // (Corresponds to NPN_GetURL and NPN_GetURLNotify.)
  360.     NS_IMETHOD_(NPPluginError)
  361.     GetURL(const char* url, const char* target, void* notifyData, 
  362.            const char* altHost, const char* referer, PRBool forceJSEnabled);
  363.  
  364.     // (Corresponds to NPN_PostURL and NPN_PostURLNotify.)
  365.     NS_IMETHOD_(NPPluginError)
  366.     PostURL(const char* url, const char* target,
  367.             PRUint32 len, const char* buf, PRBool file, void* notifyData, 
  368.             const char* altHost, const char* referer, PRBool forceJSEnabled,
  369.             PRUint32 postHeadersLength, const char* postHeaders);
  370.  
  371.     // (Corresponds to NPN_NewStream.)
  372.     NS_IMETHOD_(NPPluginError)
  373.     NewStream(nsMIMEType type, const char* target,
  374.               NPIPluginManagerStream* *result);
  375.  
  376.     // (Corresponds to NPN_Status.)
  377.     NS_IMETHOD_(void)
  378.     ShowStatus(const char* message);
  379.  
  380.     // (Corresponds to NPN_UserAgent.)
  381.     NS_IMETHOD_(const char*)
  382.     UserAgent(void);
  383.  
  384.     // (Corresponds to NPN_GetValue.)
  385.     NS_IMETHOD_(NPPluginError)
  386.     GetValue(NPPluginManagerVariable variable, void *value);
  387.  
  388.     // (Corresponds to NPN_SetValue.)
  389.     NS_IMETHOD_(NPPluginError)
  390.     SetValue(NPPluginVariable variable, void *value);
  391.  
  392.     // (Corresponds to NPN_InvalidateRect.)
  393.     NS_IMETHOD_(void)
  394.     InvalidateRect(nsRect *invalidRect);
  395.  
  396.     // (Corresponds to NPN_InvalidateRegion.)
  397.     NS_IMETHOD_(void)
  398.     InvalidateRegion(nsRegion invalidRegion);
  399.  
  400.     // (Corresponds to NPN_ForceRedraw.)
  401.     NS_IMETHOD_(void)
  402.     ForceRedraw(void);
  403.  
  404.     NS_IMETHOD_(void)
  405.     RegisterWindow(void* window);
  406.     
  407.     NS_IMETHOD_(void)
  408.     UnregisterWindow(void* window);    
  409.  
  410.     ////////////////////////////////////////////////////////////////////////////
  411.     // Methods specific to NPILiveConnectPluginInstancePeer:
  412.  
  413.     // (Corresponds to NPN_GetJavaPeer.)
  414.     NS_IMETHOD_(jobject)
  415.     GetJavaPeer(void);
  416.  
  417. protected:
  418.     // NPP is the old plugin structure. If we were implementing this
  419.     // from scratch we wouldn't use it, but for now we're calling the old
  420.     // npglue.c routines wherever possible.
  421.     NPP npp;
  422.  
  423.     NPIPluginInstance* userInst;
  424.  
  425.     // aggregated sub-intefaces:
  426.     nsISupports* fJVMInstancePeer;
  427.  
  428. };
  429.  
  430. ////////////////////////////////////////////////////////////////////////////////
  431.  
  432. class nsPluginManagerStream : public NPIPluginManagerStream {
  433. public:
  434.  
  435.     nsPluginManagerStream(NPP npp, NPStream* pstr);
  436.     virtual ~nsPluginManagerStream(void);
  437.  
  438.     NS_DECL_ISUPPORTS
  439.  
  440.     ////////////////////////////////////////////////////////////////////////////
  441.     // from NPIStream:
  442.  
  443.     // (Corresponds to NPP_WriteReady.)
  444.     NS_IMETHOD_(PRInt32)
  445.     WriteReady(void);
  446.  
  447.     // (Corresponds to NPP_Write and NPN_Write.)
  448.     NS_IMETHOD_(PRInt32)
  449.     Write(PRInt32 len, void* buffer);
  450.  
  451.     ////////////////////////////////////////////////////////////////////////////
  452.     // from NPIPluginManagerStream:
  453.  
  454.     // (Corresponds to NPStream's url field.)
  455.     NS_IMETHOD_(const char*)
  456.     GetURL(void);
  457.  
  458.     // (Corresponds to NPStream's end field.)
  459.     NS_IMETHOD_(PRUint32)
  460.     GetEnd(void);
  461.  
  462.     // (Corresponds to NPStream's lastmodified field.)
  463.     NS_IMETHOD_(PRUint32)
  464.     GetLastModified(void);
  465.  
  466.     // (Corresponds to NPStream's notifyData field.)
  467.     NS_IMETHOD_(void*)
  468.     GetNotifyData(void);
  469.  
  470. protected:
  471.     NPP npp;
  472.     NPStream* pstream;
  473.  
  474. };
  475.  
  476. ////////////////////////////////////////////////////////////////////////////////
  477.  
  478. class nsPluginStreamPeer : public NPISeekablePluginStreamPeer {
  479. public:
  480.     
  481.     nsPluginStreamPeer(URL_Struct *urls, np_stream *stream);
  482.     virtual ~nsPluginStreamPeer(void);
  483.  
  484.     NS_DECL_ISUPPORTS
  485.     
  486.     NPIPluginStream* GetUserStream(void) {
  487.         return userStream;
  488.     }
  489.  
  490.     void SetUserStream(NPIPluginStream* str) {
  491.         userStream = str;
  492.     }
  493.  
  494.     void SetReason(NPPluginReason r) {
  495.         reason = r;
  496.     }
  497.  
  498.     ////////////////////////////////////////////////////////////////////////////
  499.     // from NPIPluginStreamPeer:
  500.  
  501.     // (Corresponds to NPP_DestroyStream's reason argument.)
  502.     NS_IMETHOD_(NPPluginReason)
  503.     GetReason(void);
  504.  
  505.     // (Corresponds to NPP_NewStream's MIMEType argument.)
  506.     NS_IMETHOD_(nsMIMEType)
  507.     GetMIMEType(void);
  508.  
  509.     NS_IMETHOD_(PRUint32)
  510.     GetContentLength(void);
  511. #if 0
  512.     NS_IMETHOD_(const char*)
  513.     GetContentEncoding(void);
  514.  
  515.     NS_IMETHOD_(const char*)
  516.     GetCharSet(void);
  517.  
  518.     NS_IMETHOD_(const char*)
  519.     GetBoundary(void);
  520.  
  521.     NS_IMETHOD_(const char*)
  522.     GetContentName(void);
  523.  
  524.     NS_IMETHOD_(time_t)
  525.     GetExpires(void);
  526.  
  527.     NS_IMETHOD_(time_t)
  528.     GetLastModified(void);
  529.  
  530.     NS_IMETHOD_(time_t)
  531.     GetServerDate(void);
  532.  
  533.     NS_IMETHOD_(NPServerStatus)
  534.     GetServerStatus(void);
  535. #endif
  536.     NS_IMETHOD_(PRUint32)
  537.     GetHeaderFieldCount(void);
  538.  
  539.     NS_IMETHOD_(const char*)
  540.     GetHeaderFieldKey(PRUint32 index);
  541.  
  542.     NS_IMETHOD_(const char*)
  543.     GetHeaderField(PRUint32 index);
  544.  
  545.     ////////////////////////////////////////////////////////////////////////////
  546.     // from NPISeekablePluginStreamPeer:
  547.  
  548.     // (Corresponds to NPN_RequestRead.)
  549.     NS_IMETHOD_(NPPluginError)
  550.     RequestRead(nsByteRange* rangeList);
  551.  
  552. protected:
  553.     NPIPluginStream* userStream;
  554.     URL_Struct *urls;
  555.     np_stream *stream;
  556.     NPPluginReason reason;
  557.  
  558. };
  559.  
  560. ////////////////////////////////////////////////////////////////////////////////
  561.  
  562. #if defined(__cplusplus)
  563. } /* extern "C" */
  564. #endif
  565.  
  566. #endif /* npglue_h__ */
  567.