2 // Copyright (C) 2010, 2011 Free Software Foundation, Inc
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.
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
27 #include "npruntime.h"
28 #include "npfunctions.h"
30 #include "pluginbase.h"
34 #include "dsodefs.h" // DSOEXPORT
38 #define LIBLTDL_DLL_IMPORT 1
41 #include <sys/param.h>
44 using namespace gnash
;
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.
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;
113 main(int argc
, char *argv
[])
115 // Initialize libtool's dynamic library loader
116 int errors
= lt_dlinit ();
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
);
129 plugindir
+= "/.libs/";
130 // plugindir += "/plugin/npapo/.libs";
132 lt_dlsetsearchpath(plugindir
.c_str());
134 string filespec
= "libgnashplugin.so";
136 handle
= lt_dlopenext (filespec
.c_str());
138 if (handle
== NULL
) {
139 cerr
<< lt_dlerror() << endl
;
142 // Make this module unloadable
143 lt_dlmakeresident(handle
);
145 // Get the init function
147 string symbol
= "NP_Initialize"; // NS_PluginInitialize instead ?
148 run
= lt_dlsym (handle
, symbol
.c_str());
151 cout
<< "Couldn't find symbol: " << symbol
<< endl
;
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;
175 NPP_GetValue(0, NPPVpluginDescriptionString
, str
);
181 NPN_GetValue(0, NPNVSupportsXEmbedBool
, &bo
);
185 // We have to implement these two memory allocation functions as
186 // they're used in the code we're testing.
188 NPN_MemAlloc(uint32_t size
)
196 NPN_MemFree(void* ptr
)
203 NPN_MemFlush(uint32_t size
)
209 NPN_UTF8FromIdentifier(NPIdentifier identifier
)
211 cerr
<< "UNIMPLEMENTED: " << __PRETTY_FUNCTION__
<< endl
;
215 NPN_IntFromIdentifier(NPIdentifier identifier
)
217 cerr
<< "UNIMPLEMENTED: " << __PRETTY_FUNCTION__
<< endl
;
220 // These are just stubs to get the test case to link standalone.
222 NPN_GetStringIdentifier(const NPUTF8
*name
)
224 cerr
<< "UNIMPLEMENTED: " << __PRETTY_FUNCTION__
<< endl
;
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
;
237 NPN_GetURLNotify(NPP instance
, const char* url
,
238 const char* target
, void* notifyData
)
240 cerr
<< "UNIMPLEMENTED: " << __PRETTY_FUNCTION__
<< endl
;
244 NPN_PostURLNotify(NPP instance
, const char* url
,
245 const char* target
, uint32_t len
,
246 const char* buf
, NPBool file
,
249 cerr
<< "UNIMPLEMENTED: " << __PRETTY_FUNCTION__
<< endl
;
253 NPN_Invoke(NPP npp
, NPObject
*npobj
, NPIdentifier methodName
,
254 const NPVariant
*args
, uint32_t argCount
, NPVariant
*result
)
256 cerr
<< "UNIMPLEMENTED: " << __PRETTY_FUNCTION__
<< endl
;
260 NPN_InvokeDefault(NPP npp
, NPObject
*npobj
, const NPVariant
*args
,
261 uint32_t argCount
, NPVariant
*result
)
263 cerr
<< "UNIMPLEMENTED: " << __PRETTY_FUNCTION__
<< endl
;
267 NPN_Evaluate(NPP npp
, NPObject
*npobj
, NPString
*script
,
270 cerr
<< "UNIMPLEMENTED: " << __PRETTY_FUNCTION__
<< endl
;
274 NPN_GetProperty(NPP npp
, NPObject
*npobj
, NPIdentifier propertyName
,
277 cerr
<< "UNIMPLEMENTED: " << __PRETTY_FUNCTION__
<< endl
;
281 NPN_HasProperty(NPP npp
, NPObject
*npobj
, NPIdentifier propertyName
)
283 cerr
<< "UNIMPLEMENTED: " << __PRETTY_FUNCTION__
<< endl
;
287 NPN_HasMethod(NPP npp
, NPObject
*npobj
, NPIdentifier methodName
)
289 cerr
<< "UNIMPLEMENTED: " << __PRETTY_FUNCTION__
<< endl
;
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
;
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
;
311 NPN_InvalidateRect(NPP instance
, NPRect
*invalidRect
)
313 cerr
<< "UNIMPLEMENTED: " << __PRETTY_FUNCTION__
<< endl
;
317 NPN_InvalidateRegion(NPP instance
, NPRegion invalidRegion
)
319 cerr
<< "UNIMPLEMENTED: " << __PRETTY_FUNCTION__
<< endl
;
323 NPN_ReloadPlugins(NPBool reloadPages
)
325 cerr
<< "UNIMPLEMENTED: " << __PRETTY_FUNCTION__
<< endl
;
329 NPN_GetURL(NPP instance
, const char* url
, const char* target
)
331 cerr
<< "UNIMPLEMENTED: " << __PRETTY_FUNCTION__
<< endl
;
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
;
343 NPN_RequestRead(NPStream
* stream
, NPByteRange
* rangeList
)
345 cerr
<< "UNIMPLEMENTED: " << __PRETTY_FUNCTION__
<< endl
;
349 NPN_NewStream(NPP instance
, NPMIMEType type
, const char* target
,
352 cerr
<< "UNIMPLEMENTED: " << __PRETTY_FUNCTION__
<< endl
;
356 NPN_Status(NPP instance
, const char* message
)
358 cerr
<< "UNIMPLEMENTED: " << __PRETTY_FUNCTION__
<< endl
;
362 NPN_UserAgent(NPP instance
)
364 cerr
<< "UNIMPLEMENTED: " << __PRETTY_FUNCTION__
<< endl
;
368 NPN_Write(NPP instance
, NPStream
* stream
, int32_t len
, void* buffer
)
370 cerr
<< "UNIMPLEMENTED: " << __PRETTY_FUNCTION__
<< endl
;
374 NPN_DestroyStream(NPP instance
, NPStream
* stream
, NPReason reason
)
376 cerr
<< "UNIMPLEMENTED: " << __PRETTY_FUNCTION__
<< endl
;
382 cerr
<< "UNIMPLEMENTED: " << __PRETTY_FUNCTION__
<< endl
;
386 NPP_GetMIMEDescription(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
403 NPN_SetProperty(NPP npp
, NPObject
* obj
, NPIdentifier name
,
404 const NPVariant
*value
)
406 _properties
[name
] = const_cast<NPVariant
*>(value
);
410 NPN_GetProperty(NPP npp
, NPObject
* obj
, NPIdentifier name
,
411 const NPVariant
*value
)
413 return _properties
[name
];
417 NPN_RemoveProperty(NPP npp
, NPObject
*npobj
, NPIdentifier propertyName
)
419 cerr
<< "UNIMPLEMENTED: " << __PRETTY_FUNCTION__
<< endl
;
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()) {
435 NPN_SetException(NPObject
*npobj
, const NPUTF8
*message
)
437 cerr
<< "UNIMPLEMENTED: " << __PRETTY_FUNCTION__
<< endl
;
441 NPN_PluginThreadAsyncCall(NPP plugin
, void (*func
)(void *), void *userData
)
443 cerr
<< "UNIMPLEMENTED: " << __PRETTY_FUNCTION__
<< endl
;
447 NPN_Enumerate(NPP npp
, NPObject
*npobj
, NPIdentifier
**identifier
,
450 cerr
<< "UNIMPLEMENTED: " << __PRETTY_FUNCTION__
<< endl
;
454 NPN_Construct(NPP npp
, NPObject
*npobj
, const NPVariant
*args
,
455 uint32_t argCount
, NPVariant
*result
)
457 cerr
<< "UNIMPLEMENTED: " << __PRETTY_FUNCTION__
<< endl
;
461 NPN_ReleaseVariantValue(NPVariant
*variant
)
463 switch(variant
->type
) {
464 case NPVariantType_String
:
466 NPN_MemFree(const_cast<NPUTF8
*>(NPVARIANT_TO_STRING(*variant
).UTF8Characters
));
469 case NPVariantType_Object
:
471 NPObject
* obj
= NPVARIANT_TO_OBJECT(*variant
);
473 NPN_ReleaseObject(obj
);
481 NULL_TO_NPVARIANT(*variant
);
485 NPN_CreateObject(NPP npp
, NPClass
*aClass
)
487 cerr
<< "UNIMPLEMENTED: " << __PRETTY_FUNCTION__
<< endl
;
491 NPN_GetStringIdentifiers(const NPUTF8
**names
, int32_t nameCount
,
492 NPIdentifier
*identifiers
)
494 cerr
<< "UNIMPLEMENTED: " << __PRETTY_FUNCTION__
<< endl
;
498 NPN_GetIntIdentifier(int32_t intid
)
500 cerr
<< "UNIMPLEMENTED: " << __PRETTY_FUNCTION__
<< endl
;
504 NPN_IdentifierIsString(NPIdentifier identifier
)
506 cerr
<< "UNIMPLEMENTED: " << __PRETTY_FUNCTION__
<< endl
;
510 NPN_RetainObject(NPObject
*obj
)
512 assert(obj
); ++obj
->referenceCount
; return obj
;
516 NPN_ReleaseObject(NPObject
*npobj
)
519 --npobj
->referenceCount
;
520 if (npobj
->referenceCount
== 0) {
526 // indent-tabs-mode: nil