npshell.c 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388
  1. /* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
  2. *
  3. * ***** BEGIN LICENSE BLOCK *****
  4. * Version: MPL 1.1/GPL 2.0/LGPL 2.1
  5. *
  6. * The contents of this file are subject to the Mozilla Public License Version
  7. * 1.1 (the "License"); you may not use this file except in compliance with
  8. * the License. You may obtain a copy of the License at
  9. * http://www.mozilla.org/MPL/
  10. *
  11. * Software distributed under the License is distributed on an "AS IS" basis,
  12. * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
  13. * for the specific language governing rights and limitations under the
  14. * License.
  15. *
  16. * The Original Code is mozilla.org code.
  17. *
  18. * The Initial Developer of the Original Code is
  19. * Netscape Communications Corporation.
  20. * Portions created by the Initial Developer are Copyright (C) 1998
  21. * the Initial Developer. All Rights Reserved.
  22. *
  23. * Contributor(s):
  24. * Stephen Mak <smak@sun.com>
  25. *
  26. * Alternatively, the contents of this file may be used under the terms of
  27. * either the GNU General Public License Version 2 or later (the "GPL"), or
  28. * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
  29. * in which case the provisions of the GPL or the LGPL are applicable instead
  30. * of those above. If you wish to allow use of your version of this file only
  31. * under the terms of either the GPL or the LGPL, and not to allow others to
  32. * use your version of this file under the terms of the MPL, indicate your
  33. * decision by deleting the provisions above and replace them with the notice
  34. * and other provisions required by the GPL or the LGPL. If you do not delete
  35. * the provisions above, a recipient may use your version of this file under
  36. * the terms of any one of the MPL, the GPL or the LGPL.
  37. *
  38. * ***** END LICENSE BLOCK ***** */
  39. /*
  40. * npshell.c
  41. *
  42. * Netscape Client Plugin API
  43. * - Function that need to be implemented by plugin developers
  44. *
  45. * This file defines a "shell" plugin that plugin developers can use
  46. * as the basis for a real plugin. This shell just provides empty
  47. * implementations of all functions that the plugin can implement
  48. * that will be called by Netscape (the NPP_xxx methods defined in
  49. * npapi.h).
  50. *
  51. * dp Suresh <dp@netscape.com>
  52. * updated 5/1998 <pollmann@netscape.com>
  53. * updated 9/2000 <smak@sun.com>
  54. *
  55. */
  56. /*
  57. The contents of this file are subject to the Mozilla Public License
  58. Version 1.1 (the "License"); you may not use this file except in compliance
  59. with the License. You may obtain a copy of the License at http://www.mozilla.org/MPL/
  60. Software distributed under the License is distributed on an "AS IS" basis,
  61. WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
  62. the specific language governing rights and limitations under the License.
  63. The Original Code is stub code that defines the binary interface to a Mozilla
  64. plugin.
  65. The Initial Developer of the Original Code is Mozilla.
  66. Portions created by Adobe Systems Incorporated are Copyright (C) 2007. All Rights Reserved.
  67. Contributor(s): Adobe Systems Incorporated.
  68. */
  69. #include <stdio.h>
  70. #include <string.h>
  71. #include "npapi.h"
  72. #include "strings.h"
  73. #include "diamondx.h"
  74. /***********************************************************************
  75. *
  76. * Implementations of plugin API functions
  77. *
  78. ***********************************************************************/
  79. char*
  80. NPP_GetMIMEDescription(void)
  81. {
  82. printf("NPP_GetMIMEDescription()\n");
  83. return(MIME_TYPES_HANDLED);
  84. }
  85. NPError
  86. NPP_GetValue(NPP instance, NPPVariable variable, void *value)
  87. {
  88. NPError err = NPERR_NO_ERROR;
  89. printf("NPP_GetValue(%d)\n", variable);
  90. switch (variable) {
  91. case NPPVpluginNameString:
  92. *((char **)value) = PLUGIN_NAME;
  93. break;
  94. case NPPVpluginDescriptionString:
  95. *((char **)value) = PLUGIN_DESCRIPTION;
  96. break;
  97. case NPPVpluginNeedsXEmbed:
  98. *((PRBool *)value) = PR_TRUE;
  99. break;
  100. default:
  101. err = NPERR_GENERIC_ERROR;
  102. }
  103. return err;
  104. }
  105. NPError
  106. NPP_Initialize(void)
  107. {
  108. printf("NPP_Initialize()\n");
  109. gtk_init(0, 0);
  110. return NPERR_NO_ERROR;
  111. }
  112. #ifdef OJI
  113. jref
  114. NPP_GetJavaClass()
  115. {
  116. return NULL;
  117. }
  118. #endif
  119. void
  120. NPP_Shutdown(void)
  121. {
  122. printf("NPP_Shutdown()\n");
  123. }
  124. NPError
  125. NPP_New(NPMIMEType pluginType,
  126. NPP instance,
  127. uint16 mode,
  128. int16 argc,
  129. char* argn[],
  130. char* argv[],
  131. NPSavedData* saved)
  132. {
  133. PluginInstance* This;
  134. int i;
  135. char *key, *value;
  136. int xembedSupported = 0;
  137. printf("NPP_New()\n");
  138. /* if the browser does not support XEmbed, let it down easy at this point */
  139. NPN_GetValue(instance, NPNVSupportsXEmbedBool, &xembedSupported);
  140. if (!xembedSupported)
  141. {
  142. printf("DiamondX: XEmbed not supported\n");
  143. return NPERR_GENERIC_ERROR;
  144. }
  145. if (instance == NULL)
  146. return NPERR_INVALID_INSTANCE_ERROR;
  147. instance->pdata = NPN_MemAlloc(sizeof(PluginInstance));
  148. This = (PluginInstance*) instance->pdata;
  149. if (This == NULL)
  150. {
  151. return NPERR_OUT_OF_MEMORY_ERROR;
  152. }
  153. memset(This, 0, sizeof(PluginInstance));
  154. /* mode is NP_EMBED, NP_FULL, or NP_BACKGROUND (see npapi.h) */
  155. This->mode = mode;
  156. This->instance = instance;
  157. This->dialog_up = 0;
  158. This->windowless = FALSE;
  159. for (i = 0; i < argc; i++)
  160. {
  161. key = argn[i];
  162. value = argv[i];
  163. if (!strcmp(argn[i], "wmode") && !strcmp(argv[i], "transparent"))
  164. {
  165. /* no window */
  166. NPN_SetValue(instance, NPPVpluginWindowBool, (void*)FALSE);
  167. /* transparent */
  168. NPN_SetValue(instance, NPPVpluginTransparentBool, (void*)TRUE);
  169. This->windowless = TRUE;
  170. This->ximage = NULL;
  171. }
  172. }
  173. return NPERR_NO_ERROR;
  174. }
  175. NPError
  176. NPP_Destroy(NPP instance, NPSavedData** save)
  177. {
  178. PluginInstance* This;
  179. printf("NPP_Destroy()\n");
  180. if (instance == NULL)
  181. return NPERR_INVALID_INSTANCE_ERROR;
  182. This = (PluginInstance*) instance->pdata;
  183. if (This != NULL)
  184. {
  185. if (This->ximage)
  186. {
  187. if (This->ximage->data)
  188. NPN_MemFree(This->ximage->data);
  189. NPN_MemFree(This->ximage);
  190. }
  191. if (This->four_quads)
  192. NPN_MemFree(This->four_quads);
  193. NPN_MemFree(instance->pdata);
  194. instance->pdata = NULL;
  195. }
  196. return NPERR_NO_ERROR;
  197. }
  198. NPError
  199. NPP_SetWindow(NPP instance, NPWindow* window)
  200. {
  201. printf("NPP_SetWindow()\n");
  202. return DiamondXSetWindow(instance, window);
  203. }
  204. int32
  205. NPP_WriteReady(NPP instance, NPStream *stream)
  206. {
  207. printf("NPP_WriteReady()\n");
  208. if (instance == NULL)
  209. return NPERR_INVALID_INSTANCE_ERROR;
  210. /* We don't want any data, kill the stream */
  211. NPN_DestroyStream(instance, stream, NPRES_DONE);
  212. /* Number of bytes ready to accept in NPP_Write() */
  213. return -1L; /* don't accept any bytes in NPP_Write() */
  214. }
  215. int32
  216. NPP_Write(NPP instance, NPStream *stream, int32 offset, int32 len, void *buffer)
  217. {
  218. printf("NPP_Write()\n");
  219. if (instance == NULL)
  220. return NPERR_INVALID_INSTANCE_ERROR;
  221. /* We don't want any data, kill the stream */
  222. NPN_DestroyStream(instance, stream, NPRES_DONE);
  223. return -1L; /* don't accept any bytes in NPP_Write() */
  224. }
  225. NPError
  226. NPP_DestroyStream(NPP instance, NPStream *stream, NPError reason)
  227. {
  228. printf("NPP_DestroyStream()\n");
  229. if (instance == NULL)
  230. return NPERR_INVALID_INSTANCE_ERROR;
  231. /***** Insert NPP_DestroyStream code here *****\
  232. PluginInstance* This;
  233. This = (PluginInstance*) instance->pdata;
  234. \**********************************************/
  235. return NPERR_NO_ERROR;
  236. }
  237. void
  238. NPP_StreamAsFile(NPP instance, NPStream *stream, const char* fname)
  239. {
  240. printf("NPP_StreamAsFile()\n");
  241. /***** Insert NPP_StreamAsFile code here *****\
  242. PluginInstance* This;
  243. if (instance != NULL)
  244. This = (PluginInstance*) instance->pdata;
  245. \*********************************************/
  246. }
  247. void
  248. NPP_URLNotify(NPP instance, const char* url,
  249. NPReason reason, void* notifyData)
  250. {
  251. printf("NPP_URLNotify()\n");
  252. /***** Insert NPP_URLNotify code here *****\
  253. PluginInstance* This;
  254. if (instance != NULL)
  255. This = (PluginInstance*) instance->pdata;
  256. \*********************************************/
  257. }
  258. void
  259. NPP_Print(NPP instance, NPPrint* printInfo)
  260. {
  261. printf("NPP_Print()\n");
  262. if(printInfo == NULL)
  263. return;
  264. if (instance != NULL) {
  265. /***** Insert NPP_Print code here *****\
  266. PluginInstance* This = (PluginInstance*) instance->pdata;
  267. \**************************************/
  268. if (printInfo->mode == NP_FULL) {
  269. /*
  270. * PLUGIN DEVELOPERS:
  271. * If your plugin would like to take over
  272. * printing completely when it is in full-screen mode,
  273. * set printInfo->pluginPrinted to TRUE and print your
  274. * plugin as you see fit. If your plugin wants Netscape
  275. * to handle printing in this case, set
  276. * printInfo->pluginPrinted to FALSE (the default) and
  277. * do nothing. If you do want to handle printing
  278. * yourself, printOne is true if the print button
  279. * (as opposed to the print menu) was clicked.
  280. * On the Macintosh, platformPrint is a THPrint; on
  281. * Windows, platformPrint is a structure
  282. * (defined in npapi.h) containing the printer name, port,
  283. * etc.
  284. */
  285. /***** Insert NPP_Print code here *****\
  286. void* platformPrint =
  287. printInfo->print.fullPrint.platformPrint;
  288. NPBool printOne =
  289. printInfo->print.fullPrint.printOne;
  290. \**************************************/
  291. /* Do the default*/
  292. printInfo->print.fullPrint.pluginPrinted = FALSE;
  293. }
  294. else { /* If not fullscreen, we must be embedded */
  295. /*
  296. * PLUGIN DEVELOPERS:
  297. * If your plugin is embedded, or is full-screen
  298. * but you returned false in pluginPrinted above, NPP_Print
  299. * will be called with mode == NP_EMBED. The NPWindow
  300. * in the printInfo gives the location and dimensions of
  301. * the embedded plugin on the printed page. On the
  302. * Macintosh, platformPrint is the printer port; on
  303. * Windows, platformPrint is the handle to the printing
  304. * device context.
  305. */
  306. /***** Insert NPP_Print code here *****\
  307. NPWindow* printWindow =
  308. &(printInfo->print.embedPrint.window);
  309. void* platformPrint =
  310. printInfo->print.embedPrint.platformPrint;
  311. \**************************************/
  312. }
  313. }
  314. }
  315. int16 NPP_HandleEvent(NPP instance, void* event)
  316. {
  317. printf("NPP_HandleEvent()\n");
  318. return DiamondXHandleEvent(instance, event);
  319. }