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