added a FIXME
[moon.git] / plugin / plugin-entry.cpp
blobb39249ae39fa1d717d68b684a54a03c0e1b69397
1 /*
2 * plugin-entry.cpp: MoonLight browser plugin.
4 * Contact:
5 * Moonlight List (moonlight-list@lists.ximian.com)
7 * Copyright 2007 Novell, Inc. (http://www.novell.com)
9 * See the LICENSE file included with the distribution for details.
13 #include <config.h>
14 #include <stdio.h>
15 #include <string.h>
17 #include "moonlight.h"
18 #include "deployment.h"
20 // Global function table
21 static NPNetscapeFuncs MozillaFuncs;
23 /*** Wrapper functions ********************************************************/
25 void
26 NPN_Version (int *plugin_major, int *plugin_minor, int *netscape_major, int *netscape_minor)
28 *plugin_major = NP_VERSION_MAJOR;
29 *plugin_minor = NP_VERSION_MINOR;
30 *netscape_major = MozillaFuncs.version >> 8;
31 *netscape_minor = MozillaFuncs.version & 0xFF;
34 NPError
35 NPN_GetValue (NPP instance, NPNVariable variable, void *r_value)
37 // This will end up calling Deployment::SetCurrent before mono has initialized, which crashes.
38 // in any case NPN_GetValue should not end up running js code nor in other plugins.
39 // DeploymentStack deployment_push_pop;
40 return MozillaFuncs.getvalue (instance, variable, r_value);
43 NPError
44 NPN_SetValue (NPP instance, NPPVariable variable, void *value)
46 DeploymentStack deployment_push_pop;
47 return MozillaFuncs.setvalue (instance, variable, value);
50 NPError
51 NPN_GetURL (NPP instance, const char *url, const char *window)
53 DeploymentStack deployment_push_pop;
54 return MozillaFuncs.geturl (instance, url, window);
57 NPError
58 NPN_GetURLNotify (NPP instance, const char *url,
59 const char *window, void *notifyData)
61 DeploymentStack deployment_push_pop;
62 return MozillaFuncs.geturlnotify (instance,
63 url, window, notifyData);
66 NPError
67 NPN_PostURL (NPP instance, const char *url, const char *window,
68 uint32_t len, const char *buf, NPBool file)
70 DeploymentStack deployment_push_pop;
71 return MozillaFuncs.posturl (instance, url, window, len, buf, file);
74 NPError
75 NPN_PostURLNotify (NPP instance, const char *url, const char *window,
76 uint32_t len, const char *buf, NPBool file, void *notifyData)
78 DeploymentStack deployment_push_pop;
79 return MozillaFuncs.posturlnotify (instance, url,
80 window, len, buf, file, notifyData);
83 NPError
84 NPN_RequestRead (NPStream *stream, NPByteRange *rangeList)
86 DeploymentStack deployment_push_pop;
87 return MozillaFuncs.requestread (stream, rangeList);
90 NPError
91 NPN_NewStream (NPP instance, NPMIMEType type, const char *window, NPStream **stream_ptr)
93 DeploymentStack deployment_push_pop;
94 return MozillaFuncs.newstream (instance,
95 type, window, stream_ptr);
98 int32_t
99 NPN_Write (NPP instance, NPStream *stream, int32_t len, void *buffer)
101 DeploymentStack deployment_push_pop;
102 return MozillaFuncs.write (instance, stream, len, buffer);
105 NPError
106 NPN_DestroyStream (NPP instance, NPStream *stream, NPError reason)
108 DeploymentStack deployment_push_pop;
109 return MozillaFuncs.destroystream (instance, stream, reason);
112 void NPN_Status (NPP instance, const char *message)
114 DeploymentStack deployment_push_pop;
115 if (strstr (NPN_UserAgent (instance), "Firefox"))
116 MozillaFuncs.status (instance, message);
119 const char *
120 NPN_UserAgent (NPP instance)
122 DeploymentStack deployment_push_pop;
123 return MozillaFuncs.uagent (instance);
126 void *
127 NPN_MemAlloc (uint32_t size)
129 DeploymentStack deployment_push_pop;
130 return MozillaFuncs.memalloc (size);
133 void
134 NPN_MemFree (void *ptr)
136 DeploymentStack deployment_push_pop;
137 MozillaFuncs.memfree (ptr);
140 uint32_t
141 NPN_MemFlush (uint32_t size)
143 DeploymentStack deployment_push_pop;
144 return MozillaFuncs.memflush (size);
147 void
148 NPN_ReloadPlugins (NPBool reloadPages)
150 DeploymentStack deployment_push_pop;
151 MozillaFuncs.reloadplugins (reloadPages);
154 void
155 NPN_InvalidateRect (NPP instance, NPRect *invalidRect)
157 DeploymentStack deployment_push_pop;
158 MozillaFuncs.invalidaterect (instance, invalidRect);
161 void
162 NPN_InvalidateRegion (NPP instance, NPRegion invalidRegion)
164 DeploymentStack deployment_push_pop;
165 MozillaFuncs.invalidateregion (instance, invalidRegion);
168 void
169 NPN_ForceRedraw (NPP instance)
171 DeploymentStack deployment_push_pop;
172 MozillaFuncs.forceredraw (instance);
175 /*** Runtime support **********************************************************/
177 NPIdentifier
178 NPN_GetStringIdentifier (const NPUTF8 *name)
180 DeploymentStack deployment_push_pop;
181 return MozillaFuncs.getstringidentifier (name);
184 void
185 NPN_GetStringIdentifiers (const NPUTF8 **names, int32_t nameCount, NPIdentifier *identifiers)
187 DeploymentStack deployment_push_pop;
188 MozillaFuncs.getstringidentifiers (names, nameCount, identifiers);
191 NPIdentifier
192 NPN_GetIntIdentifier (int32_t intid)
194 DeploymentStack deployment_push_pop;
195 return MozillaFuncs.getintidentifier (intid);
198 bool
199 NPN_IdentifierIsString (NPIdentifier identifier)
201 DeploymentStack deployment_push_pop;
202 return MozillaFuncs.identifierisstring (identifier);
205 NPUTF8 *
206 NPN_UTF8FromIdentifier (NPIdentifier identifier)
208 DeploymentStack deployment_push_pop;
209 return MozillaFuncs.utf8fromidentifier (identifier);
212 int32_t
213 NPN_IntFromIdentifier (NPIdentifier identifier)
215 DeploymentStack deployment_push_pop;
216 return MozillaFuncs.intfromidentifier (identifier);
219 NPObject *
220 NPN_CreateObject (NPP npp, NPClass *aClass)
222 DeploymentStack deployment_push_pop;
223 return MozillaFuncs.createobject (npp, aClass);
226 NPObject *
227 NPN_RetainObject (NPObject *obj)
229 DeploymentStack deployment_push_pop;
230 return MozillaFuncs.retainobject (obj);
233 void
234 NPN_ReleaseObject (NPObject *obj)
236 DeploymentStack deployment_push_pop;
237 return MozillaFuncs.releaseobject (obj);
240 bool
241 NPN_Invoke (NPP npp, NPObject *obj, NPIdentifier methodName,
242 const NPVariant *args, uint32_t argCount, NPVariant *result)
244 DeploymentStack deployment_push_pop;
245 return MozillaFuncs.invoke (npp, obj, methodName, args, argCount, result);
248 bool
249 NPN_InvokeDefault (NPP npp, NPObject *obj, const NPVariant *args,
250 uint32_t argCount, NPVariant *result)
252 DeploymentStack deployment_push_pop;
253 return MozillaFuncs.invokeDefault (npp, obj, args, argCount, result);
256 bool
257 NPN_Evaluate (NPP npp, NPObject *obj, NPString *script, NPVariant *result)
259 DeploymentStack deployment_push_pop;
260 return MozillaFuncs.evaluate (npp, obj, script, result);
263 bool
264 NPN_GetProperty (NPP npp, NPObject *obj, NPIdentifier propertyName, NPVariant *result)
266 DeploymentStack deployment_push_pop;
267 return MozillaFuncs.getproperty (npp, obj, propertyName, result);
270 bool
271 NPN_SetProperty (NPP npp, NPObject *obj, NPIdentifier propertyName, const NPVariant *value)
273 DeploymentStack deployment_push_pop;
274 return MozillaFuncs.setproperty (npp, obj, propertyName, value);
277 bool
278 NPN_RemoveProperty (NPP npp, NPObject *obj, NPIdentifier propertyName)
280 DeploymentStack deployment_push_pop;
281 return MozillaFuncs.removeproperty (npp, obj, propertyName);
284 bool
285 NPN_HasProperty (NPP npp, NPObject *obj, NPIdentifier propertyName)
287 DeploymentStack deployment_push_pop;
288 return MozillaFuncs.hasproperty (npp, obj, propertyName);
291 bool
292 NPN_Enumerate (NPP npp, NPObject *obj, NPIdentifier **values,
293 uint32_t *count)
295 DeploymentStack deployment_push_pop;
296 return MozillaFuncs.enumerate (npp, obj, values, count);
299 bool
300 NPN_HasMethod (NPP npp, NPObject *obj, NPIdentifier methodName)
302 DeploymentStack deployment_push_pop;
303 return MozillaFuncs.hasmethod (npp, obj, methodName);
306 void
307 NPN_ReleaseVariantValue (NPVariant *variant)
309 DeploymentStack deployment_push_pop;
310 MozillaFuncs.releasevariantvalue (variant);
313 void NPN_SetException (NPObject *obj, const NPUTF8 *message)
315 DeploymentStack deployment_push_pop;
316 MozillaFuncs.setexception (obj, message);
319 /*** Popup support ************************************************************/
321 void
322 NPN_PushPopupsEnabledState (NPP instance, NPBool enabled)
324 DeploymentStack deployment_push_pop;
325 MozillaFuncs.pushpopupsenabledstate (instance, enabled);
328 void
329 NPN_PopPopupsEnabledState (NPP instance)
331 DeploymentStack deployment_push_pop;
332 MozillaFuncs.poppopupsenabledstate (instance);
335 /*** These functions are located automagically by mozilla *********************/
337 char *
338 LOADER_RENAMED_SYM(NP_GetMIMEDescription) (void)
340 return NPP_GetMIMEDescription ();
343 NPError
344 LOADER_RENAMED_SYM(NP_GetValue) (void *future, NPPVariable variable, void *value)
346 return NPP_GetValue ((NPP) future, variable, value);
349 NPError OSCALL
350 LOADER_RENAMED_SYM(NP_Initialize) (NPNetscapeFuncs *mozilla_funcs, NPPluginFuncs *plugin_funcs)
352 if (mozilla_funcs == NULL || plugin_funcs == NULL)
353 return NPERR_INVALID_FUNCTABLE_ERROR;
355 // remove these checks, since we compile against trunk firefox
356 // np*.h now, sizeof (struct) will be > if we run against
357 // firefox 2.
359 // everything is ok, though. we just need to check against
360 // the NPVERS_HAS_* defines when filling in the function
361 // table.
362 #if 0
363 if (mozilla_funcs->size < sizeof (NPNetscapeFuncs))
364 return NPERR_INVALID_FUNCTABLE_ERROR;
367 if (plugin_funcs->size < sizeof (NPPluginFuncs))
368 return NPERR_INVALID_FUNCTABLE_ERROR;
369 #endif
371 if ((mozilla_funcs->version >> 8) > NP_VERSION_MAJOR)
372 return NPERR_INCOMPATIBLE_VERSION_ERROR;
374 NPError err = NPERR_NO_ERROR;
375 guint32 supportsXEmbed = FALSE; // NPBool + padding
376 NPNToolkitType toolkit = (NPNToolkitType) 0;
378 // XEmbed ?
379 err = mozilla_funcs->getvalue (NULL,
380 NPNVSupportsXEmbedBool,
381 (void *) &supportsXEmbed);
383 if (err != NPERR_NO_ERROR || supportsXEmbed != TRUE)
384 g_warning ("It appears your browser may not support XEmbed");
386 // GTK+ ?
387 err = mozilla_funcs->getvalue (NULL,
388 NPNVToolkit,
389 (void *) &toolkit);
391 if (err != NPERR_NO_ERROR || toolkit != NPNVGtk2)
392 g_warning ("It appears your browser may not support Gtk2");
394 MozillaFuncs.size = mozilla_funcs->size;
395 MozillaFuncs.version = mozilla_funcs->version;
396 MozillaFuncs.geturlnotify = mozilla_funcs->geturlnotify;
397 MozillaFuncs.geturl = mozilla_funcs->geturl;
398 MozillaFuncs.posturlnotify = mozilla_funcs->posturlnotify;
399 MozillaFuncs.posturl = mozilla_funcs->posturl;
400 MozillaFuncs.requestread = mozilla_funcs->requestread;
401 MozillaFuncs.newstream = mozilla_funcs->newstream;
402 MozillaFuncs.write = mozilla_funcs->write;
403 MozillaFuncs.destroystream = mozilla_funcs->destroystream;
404 MozillaFuncs.status = mozilla_funcs->status;
405 MozillaFuncs.uagent = mozilla_funcs->uagent;
406 MozillaFuncs.memalloc = mozilla_funcs->memalloc;
407 MozillaFuncs.memfree = mozilla_funcs->memfree;
408 MozillaFuncs.memflush = mozilla_funcs->memflush;
409 MozillaFuncs.reloadplugins = mozilla_funcs->reloadplugins;
410 MozillaFuncs.getJavaEnv = mozilla_funcs->getJavaEnv;
411 MozillaFuncs.getJavaPeer = mozilla_funcs->getJavaPeer;
412 MozillaFuncs.getvalue = mozilla_funcs->getvalue;
413 MozillaFuncs.setvalue = mozilla_funcs->setvalue;
414 MozillaFuncs.invalidaterect = mozilla_funcs->invalidaterect;
415 MozillaFuncs.invalidateregion = mozilla_funcs->invalidateregion;
416 MozillaFuncs.forceredraw = mozilla_funcs->forceredraw;
418 if (mozilla_funcs->version >= NPVERS_HAS_NPRUNTIME_SCRIPTING) {
419 MozillaFuncs.getstringidentifier = mozilla_funcs->getstringidentifier;
420 MozillaFuncs.getstringidentifiers = mozilla_funcs->getstringidentifiers;
421 MozillaFuncs.getintidentifier = mozilla_funcs->getintidentifier;
422 MozillaFuncs.identifierisstring = mozilla_funcs->identifierisstring;
423 MozillaFuncs.utf8fromidentifier = mozilla_funcs->utf8fromidentifier;
424 MozillaFuncs.intfromidentifier = mozilla_funcs->intfromidentifier;
425 MozillaFuncs.createobject = mozilla_funcs->createobject;
426 MozillaFuncs.retainobject = mozilla_funcs->retainobject;
427 MozillaFuncs.releaseobject = mozilla_funcs->releaseobject;
428 MozillaFuncs.invoke = mozilla_funcs->invoke;
429 MozillaFuncs.invokeDefault = mozilla_funcs->invokeDefault;
430 MozillaFuncs.evaluate = mozilla_funcs->evaluate;
431 MozillaFuncs.getproperty = mozilla_funcs->getproperty;
432 MozillaFuncs.setproperty = mozilla_funcs->setproperty;
433 MozillaFuncs.removeproperty = mozilla_funcs->removeproperty;
434 MozillaFuncs.hasproperty = mozilla_funcs->hasproperty;
435 MozillaFuncs.hasmethod = mozilla_funcs->hasmethod;
436 MozillaFuncs.releasevariantvalue = mozilla_funcs->releasevariantvalue;
437 MozillaFuncs.setexception = mozilla_funcs->setexception;
440 if (mozilla_funcs->version >= NPVERS_HAS_NPOBJECT_ENUM) {
441 MozillaFuncs.enumerate = mozilla_funcs->enumerate;
444 if (mozilla_funcs->version >= NPVERS_HAS_POPUPS_ENABLED_STATE) {
445 MozillaFuncs.pushpopupsenabledstate = mozilla_funcs->pushpopupsenabledstate;
446 MozillaFuncs.poppopupsenabledstate = mozilla_funcs->poppopupsenabledstate;
449 if (plugin_funcs->size < sizeof (NPPluginFuncs))
450 return NPERR_INVALID_FUNCTABLE_ERROR;
452 plugin_funcs->version = ((NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR);
453 plugin_funcs->size = sizeof (NPPluginFuncs);
454 plugin_funcs->newp = NPP_New;
455 plugin_funcs->destroy = NPP_Destroy;
456 plugin_funcs->setwindow = NPP_SetWindow;
457 plugin_funcs->newstream = NPP_NewStream;
458 plugin_funcs->destroystream = NPP_DestroyStream;
459 plugin_funcs->asfile = NPP_StreamAsFile;
460 plugin_funcs->writeready = NPP_WriteReady;
461 plugin_funcs->write = NPP_Write;
462 plugin_funcs->print = NPP_Print;
463 plugin_funcs->urlnotify = NPP_URLNotify;
464 plugin_funcs->event = NPP_HandleEvent;
465 #ifdef OJI
466 plugin_funcs->javaClass = NULL;
467 #endif
468 if (mozilla_funcs->version >= NPVERS_HAS_NPRUNTIME_SCRIPTING) {
469 plugin_funcs->getvalue = NPP_GetValue;
470 plugin_funcs->setvalue = NPP_SetValue;
473 return NPP_Initialize ();
476 NPError OSCALL
477 LOADER_RENAMED_SYM(NP_Shutdown) (void)
479 NPP_Shutdown ();
480 return NPERR_NO_ERROR;