PageRenderTime 40ms CodeModel.GetById 11ms RepoModel.GetById 0ms app.codeStats 1ms

/flash/video/gnash-bzr/src/gnash-build/plugin/npapi/gshell.cpp

https://github.com/o1iver/Code-Backup
C++ | 527 lines | 408 code | 74 blank | 45 comment | 15 complexity | a124282dc1f2d60e811eee4b13eaa853 MD5 | raw file
  1. //
  2. // Copyright (C) 2010 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.
  13. //
  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
  17. //
  18. #include <iostream>
  19. #include <string>
  20. #include <cstdlib>
  21. #include <vector>
  22. #include <map>
  23. #include <cassert>
  24. #include "npapi.h"
  25. #include "npruntime.h"
  26. #include "npfunctions.h"
  27. #include "plugin.h"
  28. #include "pluginbase.h"
  29. #include <regex.h>
  30. #include "external.h"
  31. #include "dsodefs.h" // DSOEXPORT
  32. #ifdef _WIN32
  33. #undef DLL_EXPORT
  34. #define LIBLTDL_DLL_IMPORT 1
  35. #endif
  36. #include <sys/param.h>
  37. #include <ltdl.h>
  38. using namespace gnash;
  39. using namespace std;
  40. typedef NPError NP_InitializePtr (NPNetscapeFuncs* aNPNFuncs,
  41. NPPluginFuncs* aNPPFuncs);
  42. extern NPError NS_PluginGetValue(NPPVariable aVariable, void *aValue);
  43. // This is a global variable commonly used by plugins to access
  44. // the browser's function table. Since we aren't using a browser
  45. // we have to populate this ourselves.
  46. NPNetscapeFuncs *
  47. populateNPFuncs(NPNetscapeFuncs *aNPNFuncs)
  48. {
  49. aNPNFuncs->size = 45; // this is the count of entries
  50. aNPNFuncs->version = 1.9;
  51. aNPNFuncs->geturl = NPN_GetURL;
  52. aNPNFuncs->posturl = NPN_PostURL;
  53. aNPNFuncs->requestread = NPN_RequestRead;
  54. aNPNFuncs->newstream = NPN_NewStream;
  55. aNPNFuncs->write = NPN_Write;
  56. aNPNFuncs->destroystream = NPN_DestroyStream;
  57. aNPNFuncs->status = NPN_Status;
  58. aNPNFuncs->uagent = NPN_UserAgent;
  59. aNPNFuncs->memalloc = NPN_MemAlloc;
  60. aNPNFuncs->memfree = NPN_MemFree;
  61. aNPNFuncs->memflush = NPN_MemFlush;
  62. aNPNFuncs->reloadplugins = NPN_ReloadPlugins;
  63. aNPNFuncs->getJavaEnv = 0; // NPN_GetJavaEnv;
  64. aNPNFuncs->getJavaPeer = 0; //NPN_GetJavaPeer;
  65. aNPNFuncs->geturlnotify = NPN_GetURLNotify;
  66. aNPNFuncs->posturlnotify = NPN_PostURLNotify;
  67. aNPNFuncs->getvalue = NPN_GetValue;
  68. aNPNFuncs->setvalue = NPN_SetValue;
  69. aNPNFuncs->invalidaterect = NPN_InvalidateRect;
  70. aNPNFuncs->invalidateregion = NPN_InvalidateRegion;
  71. aNPNFuncs->forceredraw = 0; // NPN_ForceDraw;
  72. aNPNFuncs->getstringidentifier = NPN_GetStringIdentifier;
  73. aNPNFuncs->getstringidentifiers = NPN_GetStringIdentifiers;
  74. aNPNFuncs->getintidentifier = NPN_GetIntIdentifier;
  75. aNPNFuncs->identifierisstring = NPN_IdentifierIsString;
  76. aNPNFuncs->utf8fromidentifier = NPN_UTF8FromIdentifier;
  77. aNPNFuncs->intfromidentifier = NPN_IntFromIdentifier;
  78. aNPNFuncs->createobject = NPN_CreateObject;
  79. aNPNFuncs->retainobject = NPN_RetainObject;
  80. aNPNFuncs->releaseobject = NPN_ReleaseObject;
  81. aNPNFuncs->invoke = NPN_Invoke;
  82. aNPNFuncs->invokeDefault = NPN_InvokeDefault;
  83. aNPNFuncs->evaluate = NPN_Evaluate;
  84. aNPNFuncs->getproperty = NPN_GetProperty;
  85. aNPNFuncs->setproperty = NPN_SetProperty;
  86. aNPNFuncs->removeproperty = NPN_RemoveProperty;
  87. aNPNFuncs->hasproperty = NPN_HasProperty;
  88. aNPNFuncs->hasmethod = NPN_HasMethod;
  89. aNPNFuncs->releasevariantvalue = NPN_ReleaseVariantValue;
  90. aNPNFuncs->setexception = NPN_SetException;
  91. // aaNPNFuncs->pushpopupsenabledstate = NPN_PushPopupsEnabledState;
  92. // aaNPNFuncs->poppopupsenabledstate = NPN_PopPopupsEnabledState;
  93. aNPNFuncs->enumerate = NPN_Enumerate;
  94. aNPNFuncs->pluginthreadasynccall = NPN_PluginThreadAsyncCall;
  95. aNPNFuncs->construct = NPN_Construct;
  96. // aNPNFuncs->getvalueforurl = NPN_GetValueForURL;
  97. // aNPNFuncs->setvalueforurl = NPN_SetValueForURL;
  98. return aNPNFuncs;
  99. }
  100. int
  101. main(int argc, char *argv[])
  102. {
  103. // Initialize libtool's dynamic library loader
  104. int errors = lt_dlinit ();
  105. if (errors) {
  106. cerr << "ERROR: Couldn't initialize ltdl: " << lt_dlerror() << endl;
  107. }
  108. // load a plugin in the current directory
  109. string plugindir = ".";
  110. //
  111. char dir[MAXPATHLEN];
  112. getcwd(dir, MAXPATHLEN);
  113. plugindir += ":";
  114. plugindir += dir;
  115. plugindir += "/.libs/";
  116. // plugindir += "/plugin/npapo/.libs";
  117. lt_dlsetsearchpath(plugindir.c_str());
  118. string filespec = "libgnashplugin.so";
  119. lt_dlhandle handle;
  120. handle = lt_dlopenext (filespec.c_str());
  121. if (handle == NULL) {
  122. cerr << lt_dlerror() << endl;
  123. return false;
  124. }
  125. // Make this module unloadable
  126. lt_dlmakeresident(handle);
  127. // Get the init function
  128. lt_ptr run = NULL;
  129. string symbol = "NP_Initialize"; // NS_PluginInitialize instead ?
  130. run = lt_dlsym (handle, symbol.c_str());
  131. if (run == NULL) {
  132. cout << "Couldn't find symbol: " << symbol << endl;
  133. return NULL;
  134. } else {
  135. cout << "Found symbol " << symbol << " @ " << hex << run << endl;
  136. }
  137. // this gets populated by the browser
  138. NPNetscapeFuncs aNPNFuncs;
  139. populateNPFuncs(&aNPNFuncs);
  140. // this gets populated by the plugin
  141. //NPPluginFuncs *aNPPFuncs;
  142. nsPluginCreateData ds;
  143. // NPPFuncs.newp(NPMIMEType, 0, 0, 1, 0, "foo", 0);
  144. // nsPluginInstanceBase * plugin = NS_NewPluginInstance(&ds);
  145. NPPluginFuncs *aNPPFuncs = 0;
  146. // Execute the plugin's initialization function
  147. NP_InitializePtr *ptr = (NP_InitializePtr *)run;
  148. NPError error = ptr(&aNPNFuncs, aNPPFuncs);
  149. // cout << getPluginDescription() << endl;
  150. char *str = 0;
  151. NPP_GetValue(0, NPPVpluginDescriptionString, str);
  152. if (str) {
  153. cerr << str << endl;
  154. }
  155. bool bo = false;
  156. NPN_GetValue(0, NPNVSupportsXEmbedBool, &bo);
  157. cerr << bo << endl;
  158. }
  159. // We have to implement these two memory allocation functions as
  160. // they're used in the code we're testing.
  161. void *
  162. NPN_MemAlloc(uint32_t size)
  163. {
  164. void * rv = NULL;
  165. rv = malloc(size);
  166. return rv;
  167. }
  168. void
  169. NPN_MemFree(void* ptr)
  170. {
  171. assert(ptr);
  172. free(ptr);
  173. }
  174. uint32_t
  175. NPN_MemFlush(uint32_t size)
  176. {
  177. return size;
  178. }
  179. NPUTF8 *
  180. NPN_UTF8FromIdentifier(NPIdentifier identifier)
  181. {
  182. cerr << "UNIMPLEMENTED: " << __PRETTY_FUNCTION__ << endl;
  183. }
  184. int32_t
  185. NPN_IntFromIdentifier(NPIdentifier identifier)
  186. {
  187. cerr << "UNIMPLEMENTED: " << __PRETTY_FUNCTION__ << endl;
  188. }
  189. // These are just stubs to get the test case to link standalone.
  190. NPIdentifier
  191. NPN_GetStringIdentifier(const NPUTF8 *name)
  192. {
  193. cerr << "UNIMPLEMENTED: " << __PRETTY_FUNCTION__ << endl;
  194. }
  195. NPError
  196. NPP_GetValue(NPP instance, NPPVariable aVariable, void *aValue)
  197. {
  198. if (NPPFuncs.getvalue) {
  199. return NPPFuncs.getvalue(instance, aVariable, aValue);
  200. }
  201. return NPERR_GENERIC_ERROR;
  202. }
  203. NPError
  204. NPN_GetURLNotify(NPP instance, const char* url,
  205. const char* target, void* notifyData)
  206. {
  207. cerr << "UNIMPLEMENTED: " << __PRETTY_FUNCTION__ << endl;
  208. }
  209. NPError
  210. NPN_PostURLNotify(NPP instance, const char* url,
  211. const char* target, uint32_t len,
  212. const char* buf, NPBool file,
  213. void* notifyData)
  214. {
  215. cerr << "UNIMPLEMENTED: " << __PRETTY_FUNCTION__ << endl;
  216. }
  217. bool
  218. NPN_Invoke(NPP npp, NPObject *npobj, NPIdentifier methodName,
  219. const NPVariant *args, uint32_t argCount, NPVariant *result)
  220. {
  221. cerr << "UNIMPLEMENTED: " << __PRETTY_FUNCTION__ << endl;
  222. }
  223. bool
  224. NPN_InvokeDefault(NPP npp, NPObject *npobj, const NPVariant *args,
  225. uint32_t argCount, NPVariant *result)
  226. {
  227. cerr << "UNIMPLEMENTED: " << __PRETTY_FUNCTION__ << endl;
  228. }
  229. bool
  230. NPN_Evaluate(NPP npp, NPObject *npobj, NPString *script,
  231. NPVariant *result)
  232. {
  233. cerr << "UNIMPLEMENTED: " << __PRETTY_FUNCTION__ << endl;
  234. }
  235. bool
  236. NPN_GetProperty(NPP npp, NPObject *npobj, NPIdentifier propertyName,
  237. NPVariant *result)
  238. {
  239. cerr << "UNIMPLEMENTED: " << __PRETTY_FUNCTION__ << endl;
  240. }
  241. bool
  242. NPN_HasProperty(NPP npp, NPObject *npobj, NPIdentifier propertyName)
  243. {
  244. cerr << "UNIMPLEMENTED: " << __PRETTY_FUNCTION__ << endl;
  245. }
  246. bool
  247. NPN_HasMethod(NPP npp, NPObject *npobj, NPIdentifier methodName)
  248. {
  249. cerr << "UNIMPLEMENTED: " << __PRETTY_FUNCTION__ << endl;
  250. }
  251. NPError
  252. NPN_GetValue(NPP instance, NPNVariable aVariable, void *aValue)
  253. {
  254. if (NPPFuncs.getvalue) {
  255. return NPNFuncs.getvalue(instance, aVariable, aValue);
  256. }
  257. return NPERR_GENERIC_ERROR;
  258. }
  259. NPError
  260. NPN_SetValue(NPP instance, NPPVariable aVariable, void *aValue)
  261. {
  262. if (NPPFuncs.setvalue) {
  263. return NPNFuncs.setvalue(instance, aVariable, aValue);
  264. }
  265. return NPERR_GENERIC_ERROR;
  266. }
  267. void
  268. NPN_InvalidateRect(NPP instance, NPRect *invalidRect)
  269. {
  270. cerr << "UNIMPLEMENTED: " << __PRETTY_FUNCTION__ << endl;
  271. }
  272. void
  273. NPN_InvalidateRegion(NPP instance, NPRegion invalidRegion)
  274. {
  275. cerr << "UNIMPLEMENTED: " << __PRETTY_FUNCTION__ << endl;
  276. }
  277. void
  278. NPN_ReloadPlugins(NPBool reloadPages)
  279. {
  280. cerr << "UNIMPLEMENTED: " << __PRETTY_FUNCTION__ << endl;
  281. }
  282. NPError
  283. NPN_GetURL(NPP instance, const char* url, const char* target)
  284. {
  285. cerr << "UNIMPLEMENTED: " << __PRETTY_FUNCTION__ << endl;
  286. }
  287. NPError
  288. NP_LOADDS NPN_PostURL(NPP instance, const char* url,
  289. const char* target, uint32_t len,
  290. const char* buf, NPBool file)
  291. {
  292. cerr << "UNIMPLEMENTED: " << __PRETTY_FUNCTION__ << endl;
  293. }
  294. NPError
  295. NPN_RequestRead(NPStream* stream, NPByteRange* rangeList)
  296. {
  297. cerr << "UNIMPLEMENTED: " << __PRETTY_FUNCTION__ << endl;
  298. }
  299. NPError
  300. NPN_NewStream(NPP instance, NPMIMEType type, const char* target,
  301. NPStream** stream)
  302. {
  303. cerr << "UNIMPLEMENTED: " << __PRETTY_FUNCTION__ << endl;
  304. }
  305. void
  306. NPN_Status(NPP instance, const char* message)
  307. {
  308. cerr << "UNIMPLEMENTED: " << __PRETTY_FUNCTION__ << endl;
  309. }
  310. const char *
  311. NPN_UserAgent(NPP instance)
  312. {
  313. cerr << "UNIMPLEMENTED: " << __PRETTY_FUNCTION__ << endl;
  314. }
  315. int32_t
  316. NPN_Write(NPP instance, NPStream* stream, int32_t len, void* buffer)
  317. {
  318. cerr << "UNIMPLEMENTED: " << __PRETTY_FUNCTION__ << endl;
  319. }
  320. NPError
  321. NPN_DestroyStream(NPP instance, NPStream* stream, NPReason reason)
  322. {
  323. cerr << "UNIMPLEMENTED: " << __PRETTY_FUNCTION__ << endl;
  324. }
  325. void
  326. NS_PluginShutdown()
  327. {
  328. cerr << "UNIMPLEMENTED: " << __PRETTY_FUNCTION__ << endl;
  329. }
  330. char*
  331. NPP_GetMIMEDescription(void)
  332. {
  333. char *x = 0;
  334. return x;
  335. }
  336. void
  337. NS_DestroyPluginInstance(nsPluginInstanceBase *aPlugin)
  338. {
  339. cerr << "UNIMPLEMENTED: " << __PRETTY_FUNCTION__ << endl;
  340. }
  341. std::map<NPIdentifier, NPVariant *> _properties;
  342. std::map<NPIdentifier, NPInvokeFunctionPtr> _methods;
  343. // Implement minimal properties handling
  344. bool
  345. NPN_SetProperty(NPP npp, NPObject* obj, NPIdentifier name,
  346. const NPVariant *value)
  347. {
  348. _properties[name] = const_cast<NPVariant *>(value);
  349. }
  350. bool
  351. NPN_GetProperty(NPP npp, NPObject* obj, NPIdentifier name,
  352. const NPVariant *value)
  353. {
  354. return _properties[name];
  355. }
  356. bool
  357. NPN_RemoveProperty(NPP npp, NPObject *npobj, NPIdentifier propertyName)
  358. {
  359. cerr << "UNIMPLEMENTED: " << __PRETTY_FUNCTION__ << endl;
  360. }
  361. bool
  362. NPN_HasProperty(NPP npp, NPObject* obj, NPIdentifier name,
  363. const NPVariant *value)
  364. {
  365. std::map<NPIdentifier, NPVariant *>::iterator it;
  366. it = _properties.find(name);
  367. if (it != _properties.end()) {
  368. return true;
  369. }
  370. }
  371. void
  372. NPN_SetException(NPObject *npobj, const NPUTF8 *message)
  373. {
  374. cerr << "UNIMPLEMENTED: " << __PRETTY_FUNCTION__ << endl;
  375. }
  376. void
  377. NPN_PluginThreadAsyncCall(NPP plugin, void (*func)(void *), void *userData)
  378. {
  379. cerr << "UNIMPLEMENTED: " << __PRETTY_FUNCTION__ << endl;
  380. }
  381. bool
  382. NPN_Enumerate(NPP npp, NPObject *npobj, NPIdentifier **identifier,
  383. uint32_t *count)
  384. {
  385. cerr << "UNIMPLEMENTED: " << __PRETTY_FUNCTION__ << endl;
  386. }
  387. bool
  388. NPN_Construct(NPP npp, NPObject *npobj, const NPVariant *args,
  389. uint32_t argCount, NPVariant *result)
  390. {
  391. cerr << "UNIMPLEMENTED: " << __PRETTY_FUNCTION__ << endl;
  392. }
  393. void
  394. NPN_ReleaseVariantValue(NPVariant *variant)
  395. {
  396. switch(variant->type) {
  397. case NPVariantType_String:
  398. {
  399. NPN_MemFree(const_cast<NPUTF8*>(NPVARIANT_TO_STRING(*variant).UTF8Characters));
  400. break;
  401. }
  402. case NPVariantType_Object:
  403. {
  404. NPObject* obj = NPVARIANT_TO_OBJECT(*variant);
  405. if (obj) {
  406. NPN_ReleaseObject(obj);
  407. }
  408. break;
  409. }
  410. default:
  411. {}
  412. }
  413. NULL_TO_NPVARIANT(*variant);
  414. }
  415. NPObject *
  416. NPN_CreateObject(NPP npp, NPClass *aClass)
  417. {
  418. cerr << "UNIMPLEMENTED: " << __PRETTY_FUNCTION__ << endl;
  419. }
  420. void
  421. NPN_GetStringIdentifiers(const NPUTF8 **names, int32_t nameCount,
  422. NPIdentifier *identifiers)
  423. {
  424. cerr << "UNIMPLEMENTED: " << __PRETTY_FUNCTION__ << endl;
  425. }
  426. NPIdentifier
  427. NPN_GetIntIdentifier(int32_t intid)
  428. {
  429. cerr << "UNIMPLEMENTED: " << __PRETTY_FUNCTION__ << endl;
  430. }
  431. bool
  432. NPN_IdentifierIsString(NPIdentifier identifier)
  433. {
  434. cerr << "UNIMPLEMENTED: " << __PRETTY_FUNCTION__ << endl;
  435. }
  436. NPObject*
  437. NPN_RetainObject(NPObject *obj)
  438. {
  439. assert(obj); ++obj->referenceCount; return obj;
  440. }
  441. void
  442. NPN_ReleaseObject(NPObject *npobj)
  443. {
  444. assert(npobj);
  445. --npobj->referenceCount;
  446. if (npobj->referenceCount == 0) {
  447. NPN_MemFree(npobj);
  448. }
  449. }
  450. // Local Variables:
  451. // mode: C++
  452. // indent-tabs-mode: nil
  453. // End: