1
0

npp_gate.cpp 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262
  1. /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
  2. /* ***** BEGIN LICENSE BLOCK *****
  3. * Version: NPL 1.1/GPL 2.0/LGPL 2.1
  4. *
  5. * The contents of this file are subject to the Netscape Public License
  6. * Version 1.1 (the "License"); you may not use this file except in
  7. * compliance with the License. You may obtain a copy of the License at
  8. * http://www.mozilla.org/NPL/
  9. *
  10. * Software distributed under the License is distributed on an "AS IS" basis,
  11. * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
  12. * for the specific language governing rights and limitations under the
  13. * License.
  14. *
  15. * The Original Code is mozilla.org code.
  16. *
  17. * The Initial Developer of the Original Code is
  18. * Netscape Communications Corporation.
  19. * Portions created by the Initial Developer are Copyright (C) 1998
  20. * the Initial Developer. All Rights Reserved.
  21. *
  22. * Contributor(s):
  23. *
  24. * Alternatively, the contents of this file may be used under the terms of
  25. * either the GNU General Public License Version 2 or later (the "GPL"), or
  26. * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
  27. * in which case the provisions of the GPL or the LGPL are applicable instead
  28. * of those above. If you wish to allow use of your version of this file only
  29. * under the terms of either the GPL or the LGPL, and not to allow others to
  30. * use your version of this file under the terms of the NPL, indicate your
  31. * decision by deleting the provisions above and replace them with the notice
  32. * and other provisions required by the GPL or the LGPL. If you do not delete
  33. * the provisions above, a recipient may use your version of this file under
  34. * the terms of any one of the NPL, the GPL or the LGPL.
  35. *
  36. * ***** END LICENSE BLOCK ***** */
  37. ////////////////////////////////////////////////////////////
  38. //
  39. // Implementation of plugin entry points (NPP_*)
  40. // most are just empty stubs for this particular plugin
  41. //
  42. #include "plugin.h"
  43. char*
  44. NPP_GetMIMEDescription(void)
  45. {
  46. return "application/x-winampx-1.0.0.1::Winamp Application Detector";
  47. }
  48. NPError NPP_Initialize(void)
  49. {
  50. return NPERR_NO_ERROR;
  51. }
  52. void NPP_Shutdown(void)
  53. {
  54. }
  55. // here the plugin creates an instance of our CPlugin object which
  56. // will be associated with this newly created plugin instance and
  57. // will do all the neccessary job
  58. NPError NPP_New(NPMIMEType pluginType,
  59. NPP instance,
  60. uint16 mode,
  61. int16 argc,
  62. char* argn[],
  63. char* argv[],
  64. NPSavedData* saved)
  65. {
  66. if(instance == NULL)
  67. return NPERR_INVALID_INSTANCE_ERROR;
  68. NPError rv = NPERR_NO_ERROR;
  69. CPlugin * pPlugin = new CPlugin(instance);
  70. if(pPlugin == NULL)
  71. return NPERR_OUT_OF_MEMORY_ERROR;
  72. instance->pdata = (void *)pPlugin;
  73. return rv;
  74. }
  75. // here is the place to clean up and destroy the CPlugin object
  76. NPError NPP_Destroy (NPP instance, NPSavedData** save)
  77. {
  78. if(instance == NULL)
  79. return NPERR_INVALID_INSTANCE_ERROR;
  80. NPError rv = NPERR_NO_ERROR;
  81. CPlugin * pPlugin = (CPlugin *)instance->pdata;
  82. if(pPlugin != NULL) {
  83. pPlugin->shut();
  84. delete pPlugin;
  85. }
  86. return rv;
  87. }
  88. // during this call we know when the plugin window is ready or
  89. // is about to be destroyed so we can do some gui specific
  90. // initialization and shutdown
  91. NPError NPP_SetWindow (NPP instance, NPWindow* pNPWindow)
  92. {
  93. if(instance == NULL)
  94. return NPERR_INVALID_INSTANCE_ERROR;
  95. NPError rv = NPERR_NO_ERROR;
  96. if(pNPWindow == NULL)
  97. return NPERR_GENERIC_ERROR;
  98. CPlugin * pPlugin = (CPlugin *)instance->pdata;
  99. if(pPlugin == NULL)
  100. return NPERR_GENERIC_ERROR;
  101. // window just created
  102. if(!pPlugin->isInitialized() && (pNPWindow->window != NULL)) {
  103. if(!pPlugin->init(pNPWindow)) {
  104. delete pPlugin;
  105. pPlugin = NULL;
  106. return NPERR_MODULE_LOAD_FAILED_ERROR;
  107. }
  108. }
  109. // window goes away
  110. if((pNPWindow->window == NULL) && pPlugin->isInitialized())
  111. return NPERR_NO_ERROR;
  112. // window resized
  113. if(pPlugin->isInitialized() && (pNPWindow->window != NULL))
  114. return NPERR_NO_ERROR;
  115. // this should not happen, nothing to do
  116. if((pNPWindow->window == NULL) && !pPlugin->isInitialized())
  117. return NPERR_NO_ERROR;
  118. return rv;
  119. }
  120. // ==============================
  121. // ! Scriptability related code !
  122. // ==============================
  123. //
  124. // here the plugin is asked by Mozilla to tell if it is scriptable
  125. // we should return a valid interface id and a pointer to
  126. // nsScriptablePeer interface which we should have implemented
  127. // and which should be defined in the corressponding *.xpt file
  128. // in the bin/components folder
  129. NPError NPP_GetValue(NPP instance, NPPVariable variable, void *value)
  130. {
  131. if(instance == NULL)
  132. return NPERR_INVALID_INSTANCE_ERROR;
  133. NPError rv = NPERR_NO_ERROR;
  134. if(instance == NULL)
  135. return NPERR_GENERIC_ERROR;
  136. CPlugin * plugin = (CPlugin *)instance->pdata;
  137. if(plugin == NULL)
  138. return NPERR_GENERIC_ERROR;
  139. switch (variable) {
  140. case NPPVpluginNameString:
  141. *((char **)value) = "Winamp Application Detector";
  142. break;
  143. case NPPVpluginDescriptionString:
  144. *((char **)value) = "Winamp Application Detector";
  145. break;
  146. case NPPVpluginScriptableNPObject:
  147. *(NPObject **)value = plugin->GetScriptableObject();
  148. break;
  149. default:
  150. rv = NPERR_GENERIC_ERROR;
  151. }
  152. return rv;
  153. }
  154. NPError NPP_NewStream(NPP instance,
  155. NPMIMEType type,
  156. NPStream* stream,
  157. NPBool seekable,
  158. uint16* stype)
  159. {
  160. if(instance == NULL)
  161. return NPERR_INVALID_INSTANCE_ERROR;
  162. NPError rv = NPERR_NO_ERROR;
  163. return rv;
  164. }
  165. int32 NPP_WriteReady (NPP instance, NPStream *stream)
  166. {
  167. if(instance == NULL)
  168. return NPERR_INVALID_INSTANCE_ERROR;
  169. int32 rv = 0x0fffffff;
  170. return rv;
  171. }
  172. int32 NPP_Write (NPP instance, NPStream *stream, int32 offset, int32 len, void *buffer)
  173. {
  174. if(instance == NULL)
  175. return NPERR_INVALID_INSTANCE_ERROR;
  176. int32 rv = len;
  177. return rv;
  178. }
  179. NPError NPP_DestroyStream (NPP instance, NPStream *stream, NPError reason)
  180. {
  181. if(instance == NULL)
  182. return NPERR_INVALID_INSTANCE_ERROR;
  183. NPError rv = NPERR_NO_ERROR;
  184. return rv;
  185. }
  186. void NPP_StreamAsFile (NPP instance, NPStream* stream, const char* fname)
  187. {
  188. if(instance == NULL)
  189. return;
  190. }
  191. void NPP_Print (NPP instance, NPPrint* printInfo)
  192. {
  193. if(instance == NULL)
  194. return;
  195. }
  196. void NPP_URLNotify(NPP instance, const char* url, NPReason reason, void* notifyData)
  197. {
  198. if(instance == NULL)
  199. return;
  200. }
  201. NPError NPP_SetValue(NPP instance, NPNVariable variable, void *value)
  202. {
  203. if(instance == NULL)
  204. return NPERR_INVALID_INSTANCE_ERROR;
  205. NPError rv = NPERR_NO_ERROR;
  206. return rv;
  207. }
  208. int16 NPP_HandleEvent(NPP instance, void* event)
  209. {
  210. if(instance == NULL)
  211. return 0;
  212. int16 rv = 0;
  213. CPlugin * pPlugin = (CPlugin *)instance->pdata;
  214. if (pPlugin)
  215. rv = pPlugin->handleEvent(event);
  216. return rv;
  217. }