update copyright date
[gnash.git] / plugin / npapi / gshell.cpp
blob390bed4a99aa3c909d29d0145b9eeab79a61872e
1 //
2 // Copyright (C) 2010, 2011 Free Software Foundation, Inc
3 //
4 // This program is free software; you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation; either version 3 of the License, or
7 // (at your option) any later version.
8 //
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
14 // You should hxave received a copy of the GNU General Public License
15 // along with this program; if not, write to the Free Software
16 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 #include <iostream>
20 #include <string>
21 #include <cstdlib>
22 #include <vector>
23 #include <map>
24 #include <cassert>
26 #include "npapi.h"
27 #include "npruntime.h"
28 #include "npfunctions.h"
29 #include "plugin.h"
30 #include "pluginbase.h"
31 #include <regex.h>
33 #include "external.h"
34 #include "dsodefs.h" // DSOEXPORT
36 #ifdef _WIN32
37 #undef DLL_EXPORT
38 #define LIBLTDL_DLL_IMPORT 1
39 #endif
41 #include <sys/param.h>
42 #include <ltdl.h>
44 using namespace gnash;
45 using namespace std;
47 typedef NPError NP_InitializePtr (NPNetscapeFuncs* aNPNFuncs,
48 NPPluginFuncs* aNPPFuncs);
50 extern NPError NS_PluginGetValue(NPPVariable aVariable, void *aValue);
52 // This is a global variable commonly used by plugins to access
53 // the browser's function table. Since we aren't using a browser
54 // we have to populate this ourselves.
55 NPNetscapeFuncs *
56 populateNPFuncs(NPNetscapeFuncs *aNPNFuncs)
58 aNPNFuncs->size = 45; // this is the count of entries
59 aNPNFuncs->version = 1.9;
61 aNPNFuncs->geturl = NPN_GetURL;
62 aNPNFuncs->posturl = NPN_PostURL;
63 aNPNFuncs->requestread = NPN_RequestRead;
64 aNPNFuncs->newstream = NPN_NewStream;
65 aNPNFuncs->write = NPN_Write;
66 aNPNFuncs->destroystream = NPN_DestroyStream;
67 aNPNFuncs->status = NPN_Status;
68 aNPNFuncs->uagent = NPN_UserAgent;
69 aNPNFuncs->memalloc = NPN_MemAlloc;
70 aNPNFuncs->memfree = NPN_MemFree;
71 aNPNFuncs->memflush = NPN_MemFlush;
72 aNPNFuncs->reloadplugins = NPN_ReloadPlugins;
73 aNPNFuncs->getJavaEnv = 0; // NPN_GetJavaEnv;
74 aNPNFuncs->getJavaPeer = 0; //NPN_GetJavaPeer;
75 aNPNFuncs->geturlnotify = NPN_GetURLNotify;
76 aNPNFuncs->posturlnotify = NPN_PostURLNotify;
77 aNPNFuncs->getvalue = NPN_GetValue;
78 aNPNFuncs->setvalue = NPN_SetValue;
79 aNPNFuncs->invalidaterect = NPN_InvalidateRect;
80 aNPNFuncs->invalidateregion = NPN_InvalidateRegion;
81 aNPNFuncs->forceredraw = 0; // NPN_ForceDraw;
82 aNPNFuncs->getstringidentifier = NPN_GetStringIdentifier;
83 aNPNFuncs->getstringidentifiers = NPN_GetStringIdentifiers;
84 aNPNFuncs->getintidentifier = NPN_GetIntIdentifier;
85 aNPNFuncs->identifierisstring = NPN_IdentifierIsString;
86 aNPNFuncs->utf8fromidentifier = NPN_UTF8FromIdentifier;
87 aNPNFuncs->intfromidentifier = NPN_IntFromIdentifier;
88 aNPNFuncs->createobject = NPN_CreateObject;
89 aNPNFuncs->retainobject = NPN_RetainObject;
90 aNPNFuncs->releaseobject = NPN_ReleaseObject;
91 aNPNFuncs->invoke = NPN_Invoke;
92 aNPNFuncs->invokeDefault = NPN_InvokeDefault;
93 aNPNFuncs->evaluate = NPN_Evaluate;
94 aNPNFuncs->getproperty = NPN_GetProperty;
95 aNPNFuncs->setproperty = NPN_SetProperty;
96 aNPNFuncs->removeproperty = NPN_RemoveProperty;
97 aNPNFuncs->hasproperty = NPN_HasProperty;
98 aNPNFuncs->hasmethod = NPN_HasMethod;
99 aNPNFuncs->releasevariantvalue = NPN_ReleaseVariantValue;
100 aNPNFuncs->setexception = NPN_SetException;
101 // aaNPNFuncs->pushpopupsenabledstate = NPN_PushPopupsEnabledState;
102 // aaNPNFuncs->poppopupsenabledstate = NPN_PopPopupsEnabledState;
103 aNPNFuncs->enumerate = NPN_Enumerate;
104 aNPNFuncs->pluginthreadasynccall = NPN_PluginThreadAsyncCall;
105 aNPNFuncs->construct = NPN_Construct;
106 // aNPNFuncs->getvalueforurl = NPN_GetValueForURL;
107 // aNPNFuncs->setvalueforurl = NPN_SetValueForURL;
109 return aNPNFuncs;
113 main(int argc, char *argv[])
115 // Initialize libtool's dynamic library loader
116 int errors = lt_dlinit ();
117 if (errors) {
118 cerr << "ERROR: Couldn't initialize ltdl: " << lt_dlerror() << endl;
121 // load a plugin in the current directory
122 string plugindir = ".";
125 char dir[MAXPATHLEN];
126 getcwd(dir, MAXPATHLEN);
127 plugindir += ":";
128 plugindir += dir;
129 plugindir += "/.libs/";
130 // plugindir += "/plugin/npapo/.libs";
132 lt_dlsetsearchpath(plugindir.c_str());
134 string filespec = "libgnashplugin.so";
135 lt_dlhandle handle;
136 handle = lt_dlopenext (filespec.c_str());
138 if (handle == NULL) {
139 cerr << lt_dlerror() << endl;
140 return false;
142 // Make this module unloadable
143 lt_dlmakeresident(handle);
145 // Get the init function
146 lt_ptr run = NULL;
147 string symbol = "NP_Initialize"; // NS_PluginInitialize instead ?
148 run = lt_dlsym (handle, symbol.c_str());
150 if (run == NULL) {
151 cout << "Couldn't find symbol: " << symbol << endl;
152 return NULL;
153 } else {
154 cout << "Found symbol " << symbol << " @ " << hex << run << endl;
157 // this gets populated by the browser
158 NPNetscapeFuncs aNPNFuncs;
159 populateNPFuncs(&aNPNFuncs);
161 // this gets populated by the plugin
162 //NPPluginFuncs *aNPPFuncs;
163 nsPluginCreateData ds;
165 // NPPFuncs.newp(NPMIMEType, 0, 0, 1, 0, "foo", 0);
166 // nsPluginInstanceBase * plugin = NS_NewPluginInstance(&ds);
168 NPPluginFuncs *aNPPFuncs = 0;
169 // Execute the plugin's initialization function
170 NP_InitializePtr *ptr = (NP_InitializePtr *)run;
171 NPError error = ptr(&aNPNFuncs, aNPPFuncs);
172 // cout << getPluginDescription() << endl;
174 char *str = 0;
175 NPP_GetValue(0, NPPVpluginDescriptionString, str);
176 if (str) {
177 cerr << str << endl;
180 bool bo = false;
181 NPN_GetValue(0, NPNVSupportsXEmbedBool, &bo);
182 cerr << bo << endl;
185 // We have to implement these two memory allocation functions as
186 // they're used in the code we're testing.
187 void *
188 NPN_MemAlloc(uint32_t size)
190 void * rv = NULL;
191 rv = malloc(size);
192 return rv;
195 void
196 NPN_MemFree(void* ptr)
198 assert(ptr);
199 free(ptr);
202 uint32_t
203 NPN_MemFlush(uint32_t size)
205 return size;
208 NPUTF8 *
209 NPN_UTF8FromIdentifier(NPIdentifier identifier)
211 cerr << "UNIMPLEMENTED: " << __PRETTY_FUNCTION__ << endl;
214 int32_t
215 NPN_IntFromIdentifier(NPIdentifier identifier)
217 cerr << "UNIMPLEMENTED: " << __PRETTY_FUNCTION__ << endl;
220 // These are just stubs to get the test case to link standalone.
221 NPIdentifier
222 NPN_GetStringIdentifier(const NPUTF8 *name)
224 cerr << "UNIMPLEMENTED: " << __PRETTY_FUNCTION__ << endl;
227 NPError
228 NPP_GetValue(NPP instance, NPPVariable aVariable, void *aValue)
230 if (NPPFuncs.getvalue) {
231 return NPPFuncs.getvalue(instance, aVariable, aValue);
233 return NPERR_GENERIC_ERROR;
236 NPError
237 NPN_GetURLNotify(NPP instance, const char* url,
238 const char* target, void* notifyData)
240 cerr << "UNIMPLEMENTED: " << __PRETTY_FUNCTION__ << endl;
243 NPError
244 NPN_PostURLNotify(NPP instance, const char* url,
245 const char* target, uint32_t len,
246 const char* buf, NPBool file,
247 void* notifyData)
249 cerr << "UNIMPLEMENTED: " << __PRETTY_FUNCTION__ << endl;
252 bool
253 NPN_Invoke(NPP npp, NPObject *npobj, NPIdentifier methodName,
254 const NPVariant *args, uint32_t argCount, NPVariant *result)
256 cerr << "UNIMPLEMENTED: " << __PRETTY_FUNCTION__ << endl;
259 bool
260 NPN_InvokeDefault(NPP npp, NPObject *npobj, const NPVariant *args,
261 uint32_t argCount, NPVariant *result)
263 cerr << "UNIMPLEMENTED: " << __PRETTY_FUNCTION__ << endl;
266 bool
267 NPN_Evaluate(NPP npp, NPObject *npobj, NPString *script,
268 NPVariant *result)
270 cerr << "UNIMPLEMENTED: " << __PRETTY_FUNCTION__ << endl;
273 bool
274 NPN_GetProperty(NPP npp, NPObject *npobj, NPIdentifier propertyName,
275 NPVariant *result)
277 cerr << "UNIMPLEMENTED: " << __PRETTY_FUNCTION__ << endl;
280 bool
281 NPN_HasProperty(NPP npp, NPObject *npobj, NPIdentifier propertyName)
283 cerr << "UNIMPLEMENTED: " << __PRETTY_FUNCTION__ << endl;
286 bool
287 NPN_HasMethod(NPP npp, NPObject *npobj, NPIdentifier methodName)
289 cerr << "UNIMPLEMENTED: " << __PRETTY_FUNCTION__ << endl;
292 NPError
293 NPN_GetValue(NPP instance, NPNVariable aVariable, void *aValue)
295 if (NPPFuncs.getvalue) {
296 return NPNFuncs.getvalue(instance, aVariable, aValue);
298 return NPERR_GENERIC_ERROR;
301 NPError
302 NPN_SetValue(NPP instance, NPPVariable aVariable, void *aValue)
304 if (NPPFuncs.setvalue) {
305 return NPNFuncs.setvalue(instance, aVariable, aValue);
307 return NPERR_GENERIC_ERROR;
310 void
311 NPN_InvalidateRect(NPP instance, NPRect *invalidRect)
313 cerr << "UNIMPLEMENTED: " << __PRETTY_FUNCTION__ << endl;
316 void
317 NPN_InvalidateRegion(NPP instance, NPRegion invalidRegion)
319 cerr << "UNIMPLEMENTED: " << __PRETTY_FUNCTION__ << endl;
322 void
323 NPN_ReloadPlugins(NPBool reloadPages)
325 cerr << "UNIMPLEMENTED: " << __PRETTY_FUNCTION__ << endl;
328 NPError
329 NPN_GetURL(NPP instance, const char* url, const char* target)
331 cerr << "UNIMPLEMENTED: " << __PRETTY_FUNCTION__ << endl;
334 NPError
335 NP_LOADDS NPN_PostURL(NPP instance, const char* url,
336 const char* target, uint32_t len,
337 const char* buf, NPBool file)
339 cerr << "UNIMPLEMENTED: " << __PRETTY_FUNCTION__ << endl;
342 NPError
343 NPN_RequestRead(NPStream* stream, NPByteRange* rangeList)
345 cerr << "UNIMPLEMENTED: " << __PRETTY_FUNCTION__ << endl;
348 NPError
349 NPN_NewStream(NPP instance, NPMIMEType type, const char* target,
350 NPStream** stream)
352 cerr << "UNIMPLEMENTED: " << __PRETTY_FUNCTION__ << endl;
355 void
356 NPN_Status(NPP instance, const char* message)
358 cerr << "UNIMPLEMENTED: " << __PRETTY_FUNCTION__ << endl;
361 const char *
362 NPN_UserAgent(NPP instance)
364 cerr << "UNIMPLEMENTED: " << __PRETTY_FUNCTION__ << endl;
367 int32_t
368 NPN_Write(NPP instance, NPStream* stream, int32_t len, void* buffer)
370 cerr << "UNIMPLEMENTED: " << __PRETTY_FUNCTION__ << endl;
373 NPError
374 NPN_DestroyStream(NPP instance, NPStream* stream, NPReason reason)
376 cerr << "UNIMPLEMENTED: " << __PRETTY_FUNCTION__ << endl;
379 void
380 NS_PluginShutdown()
382 cerr << "UNIMPLEMENTED: " << __PRETTY_FUNCTION__ << endl;
385 char*
386 NPP_GetMIMEDescription(void)
388 char *x = 0;
389 return x;
392 void
393 NS_DestroyPluginInstance(nsPluginInstanceBase *aPlugin)
395 cerr << "UNIMPLEMENTED: " << __PRETTY_FUNCTION__ << endl;
398 std::map<NPIdentifier, NPVariant *> _properties;
399 std::map<NPIdentifier, NPInvokeFunctionPtr> _methods;
401 // Implement minimal properties handling
402 bool
403 NPN_SetProperty(NPP npp, NPObject* obj, NPIdentifier name,
404 const NPVariant *value)
406 _properties[name] = const_cast<NPVariant *>(value);
409 bool
410 NPN_GetProperty(NPP npp, NPObject* obj, NPIdentifier name,
411 const NPVariant *value)
413 return _properties[name];
416 bool
417 NPN_RemoveProperty(NPP npp, NPObject *npobj, NPIdentifier propertyName)
419 cerr << "UNIMPLEMENTED: " << __PRETTY_FUNCTION__ << endl;
422 bool
423 NPN_HasProperty(NPP npp, NPObject* obj, NPIdentifier name,
424 const NPVariant *value)
426 std::map<NPIdentifier, NPVariant *>::iterator it;
427 it = _properties.find(name);
428 if (it != _properties.end()) {
429 return true;
434 void
435 NPN_SetException(NPObject *npobj, const NPUTF8 *message)
437 cerr << "UNIMPLEMENTED: " << __PRETTY_FUNCTION__ << endl;
440 void
441 NPN_PluginThreadAsyncCall(NPP plugin, void (*func)(void *), void *userData)
443 cerr << "UNIMPLEMENTED: " << __PRETTY_FUNCTION__ << endl;
446 bool
447 NPN_Enumerate(NPP npp, NPObject *npobj, NPIdentifier **identifier,
448 uint32_t *count)
450 cerr << "UNIMPLEMENTED: " << __PRETTY_FUNCTION__ << endl;
453 bool
454 NPN_Construct(NPP npp, NPObject *npobj, const NPVariant *args,
455 uint32_t argCount, NPVariant *result)
457 cerr << "UNIMPLEMENTED: " << __PRETTY_FUNCTION__ << endl;
460 void
461 NPN_ReleaseVariantValue(NPVariant *variant)
463 switch(variant->type) {
464 case NPVariantType_String:
466 NPN_MemFree(const_cast<NPUTF8*>(NPVARIANT_TO_STRING(*variant).UTF8Characters));
467 break;
469 case NPVariantType_Object:
471 NPObject* obj = NPVARIANT_TO_OBJECT(*variant);
472 if (obj) {
473 NPN_ReleaseObject(obj);
475 break;
477 default:
481 NULL_TO_NPVARIANT(*variant);
484 NPObject *
485 NPN_CreateObject(NPP npp, NPClass *aClass)
487 cerr << "UNIMPLEMENTED: " << __PRETTY_FUNCTION__ << endl;
490 void
491 NPN_GetStringIdentifiers(const NPUTF8 **names, int32_t nameCount,
492 NPIdentifier *identifiers)
494 cerr << "UNIMPLEMENTED: " << __PRETTY_FUNCTION__ << endl;
497 NPIdentifier
498 NPN_GetIntIdentifier(int32_t intid)
500 cerr << "UNIMPLEMENTED: " << __PRETTY_FUNCTION__ << endl;
503 bool
504 NPN_IdentifierIsString(NPIdentifier identifier)
506 cerr << "UNIMPLEMENTED: " << __PRETTY_FUNCTION__ << endl;
509 NPObject*
510 NPN_RetainObject(NPObject *obj)
512 assert(obj); ++obj->referenceCount; return obj;
515 void
516 NPN_ReleaseObject(NPObject *npobj)
518 assert(npobj);
519 --npobj->referenceCount;
520 if (npobj->referenceCount == 0) {
521 NPN_MemFree(npobj);
524 // Local Variables:
525 // mode: C++
526 // indent-tabs-mode: nil
527 // End: