ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/Mozilla-Plugin/ns4/SDK/Common/npwin.cpp
Revision: 1.1
Committed: Thu Feb 22 23:18:48 2001 UTC (25 years, 8 months ago) by root
Branch: MAIN
CVS Tags: HEAD
Log Message:
*** empty log message ***

File Contents

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