npn_gate.cpp 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322
  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 Netscape entry points (NPN_*)
  40. //
  41. #include "npapi.h"
  42. #include "npupp.h"
  43. #ifndef HIBYTE
  44. #define HIBYTE(x) ((((uint32)(x)) & 0xff00) >> 8)
  45. #endif
  46. #ifndef LOBYTE
  47. #define LOBYTE(W) ((W) & 0xFF)
  48. #endif
  49. extern NPNetscapeFuncs NPNFuncs;
  50. void NPN_Version(int* plugin_major, int* plugin_minor, int* netscape_major, int* netscape_minor)
  51. {
  52. *plugin_major = NP_VERSION_MAJOR;
  53. *plugin_minor = NP_VERSION_MINOR;
  54. *netscape_major = HIBYTE(NPNFuncs.version);
  55. *netscape_minor = LOBYTE(NPNFuncs.version);
  56. }
  57. NPError NPN_GetURLNotify(NPP instance, const char *url, const char *target, void* notifyData)
  58. {
  59. int navMinorVers = NPNFuncs.version & 0xFF;
  60. NPError rv = NPERR_NO_ERROR;
  61. if( navMinorVers >= NPVERS_HAS_NOTIFICATION )
  62. rv = NPNFuncs.geturlnotify(instance, url, target, notifyData);
  63. else
  64. rv = NPERR_INCOMPATIBLE_VERSION_ERROR;
  65. return rv;
  66. }
  67. NPError NPN_GetURL(NPP instance, const char *url, const char *target)
  68. {
  69. NPError rv = NPNFuncs.geturl(instance, url, target);
  70. return rv;
  71. }
  72. NPError NPN_PostURLNotify(NPP instance, const char* url, const char* window, uint32 len, const char* buf, NPBool file, void* notifyData)
  73. {
  74. int navMinorVers = NPNFuncs.version & 0xFF;
  75. NPError rv = NPERR_NO_ERROR;
  76. if( navMinorVers >= NPVERS_HAS_NOTIFICATION )
  77. rv = NPNFuncs.posturlnotify(instance, url, window, len, buf, file, notifyData);
  78. else
  79. rv = NPERR_INCOMPATIBLE_VERSION_ERROR;
  80. return rv;
  81. }
  82. NPError NPN_PostURL(NPP instance, const char* url, const char* window, uint32 len, const char* buf, NPBool file)
  83. {
  84. NPError rv = NPNFuncs.posturl(instance, url, window, len, buf, file);
  85. return rv;
  86. }
  87. NPError NPN_RequestRead(NPStream* stream, NPByteRange* rangeList)
  88. {
  89. NPError rv = NPNFuncs.requestread(stream, rangeList);
  90. return rv;
  91. }
  92. NPError NPN_NewStream(NPP instance, NPMIMEType type, const char* target, NPStream** stream)
  93. {
  94. int navMinorVersion = NPNFuncs.version & 0xFF;
  95. NPError rv = NPERR_NO_ERROR;
  96. if( navMinorVersion >= NPVERS_HAS_STREAMOUTPUT )
  97. rv = NPNFuncs.newstream(instance, type, target, stream);
  98. else
  99. rv = NPERR_INCOMPATIBLE_VERSION_ERROR;
  100. return rv;
  101. }
  102. int32 NPN_Write(NPP instance, NPStream *stream, int32 len, void *buffer)
  103. {
  104. int navMinorVersion = NPNFuncs.version & 0xFF;
  105. int32 rv = 0;
  106. if( navMinorVersion >= NPVERS_HAS_STREAMOUTPUT )
  107. rv = NPNFuncs.write(instance, stream, len, buffer);
  108. else
  109. rv = -1;
  110. return rv;
  111. }
  112. NPError NPN_DestroyStream(NPP instance, NPStream* stream, NPError reason)
  113. {
  114. int navMinorVersion = NPNFuncs.version & 0xFF;
  115. NPError rv = NPERR_NO_ERROR;
  116. if( navMinorVersion >= NPVERS_HAS_STREAMOUTPUT )
  117. rv = NPNFuncs.destroystream(instance, stream, reason);
  118. else
  119. rv = NPERR_INCOMPATIBLE_VERSION_ERROR;
  120. return rv;
  121. }
  122. void NPN_Status(NPP instance, const char *message)
  123. {
  124. NPNFuncs.status(instance, message);
  125. }
  126. const char* NPN_UserAgent(NPP instance)
  127. {
  128. const char * rv = NULL;
  129. rv = NPNFuncs.uagent(instance);
  130. return rv;
  131. }
  132. void* NPN_MemAlloc(uint32 size)
  133. {
  134. void * rv = NULL;
  135. rv = NPNFuncs.memalloc(size);
  136. return rv;
  137. }
  138. void NPN_MemFree(void* ptr)
  139. {
  140. NPNFuncs.memfree(ptr);
  141. }
  142. uint32 NPN_MemFlush(uint32 size)
  143. {
  144. uint32 rv = NPNFuncs.memflush(size);
  145. return rv;
  146. }
  147. void NPN_ReloadPlugins(NPBool reloadPages)
  148. {
  149. NPNFuncs.reloadplugins(reloadPages);
  150. }
  151. JRIEnv* NPN_GetJavaEnv(void)
  152. {
  153. JRIEnv * rv = NULL;
  154. rv = NPNFuncs.getJavaEnv();
  155. return rv;
  156. }
  157. jref NPN_GetJavaPeer(NPP instance)
  158. {
  159. jref rv;
  160. rv = NPNFuncs.getJavaPeer(instance);
  161. return rv;
  162. }
  163. NPError NPN_GetValue(NPP instance, NPNVariable variable, void *value)
  164. {
  165. NPError rv = NPNFuncs.getvalue(instance, variable, value);
  166. return rv;
  167. }
  168. NPError NPN_SetValue(NPP instance, NPPVariable variable, void *value)
  169. {
  170. NPError rv = NPNFuncs.setvalue(instance, variable, value);
  171. return rv;
  172. }
  173. void NPN_InvalidateRect(NPP instance, NPRect *invalidRect)
  174. {
  175. NPNFuncs.invalidaterect(instance, invalidRect);
  176. }
  177. void NPN_InvalidateRegion(NPP instance, NPRegion invalidRegion)
  178. {
  179. NPNFuncs.invalidateregion(instance, invalidRegion);
  180. }
  181. void NPN_ForceRedraw(NPP instance)
  182. {
  183. NPNFuncs.forceredraw(instance);
  184. }
  185. NPIdentifier NPN_GetStringIdentifier(const NPUTF8 *name)
  186. {
  187. return NPNFuncs.getstringidentifier(name);
  188. }
  189. void NPN_GetStringIdentifiers(const NPUTF8 **names, uint32_t nameCount,
  190. NPIdentifier *identifiers)
  191. {
  192. return NPNFuncs.getstringidentifiers(names, nameCount, identifiers);
  193. }
  194. NPIdentifier NPN_GetStringIdentifier(int32_t intid)
  195. {
  196. return NPNFuncs.getintidentifier(intid);
  197. }
  198. bool NPN_IdentifierIsString(NPIdentifier identifier)
  199. {
  200. return NPNFuncs.identifierisstring(identifier);
  201. }
  202. NPUTF8 *NPN_UTF8FromIdentifier(NPIdentifier identifier)
  203. {
  204. return NPNFuncs.utf8fromidentifier(identifier);
  205. }
  206. int32_t NPN_IntFromIdentifier(NPIdentifier identifier)
  207. {
  208. return NPNFuncs.intfromidentifier(identifier);
  209. }
  210. NPObject *NPN_CreateObject(NPP npp, NPClass *aClass)
  211. {
  212. return NPNFuncs.createobject(npp, aClass);
  213. }
  214. NPObject *NPN_RetainObject(NPObject *obj)
  215. {
  216. return NPNFuncs.retainobject(obj);
  217. }
  218. void NPN_ReleaseObject(NPObject *obj)
  219. {
  220. return NPNFuncs.releaseobject(obj);
  221. }
  222. bool NPN_Invoke(NPP npp, NPObject* obj, NPIdentifier methodName,
  223. const NPVariant *args, uint32_t argCount, NPVariant *result)
  224. {
  225. return NPNFuncs.invoke(npp, obj, methodName, args, argCount, result);
  226. }
  227. bool NPN_InvokeDefault(NPP npp, NPObject* obj, const NPVariant *args,
  228. uint32_t argCount, NPVariant *result)
  229. {
  230. return NPNFuncs.invokeDefault(npp, obj, args, argCount, result);
  231. }
  232. bool NPN_Evaluate(NPP npp, NPObject* obj, NPString *script,
  233. NPVariant *result)
  234. {
  235. return NPNFuncs.evaluate(npp, obj, script, result);
  236. }
  237. bool NPN_GetProperty(NPP npp, NPObject* obj, NPIdentifier propertyName,
  238. NPVariant *result)
  239. {
  240. return NPNFuncs.getproperty(npp, obj, propertyName, result);
  241. }
  242. bool NPN_SetProperty(NPP npp, NPObject* obj, NPIdentifier propertyName,
  243. const NPVariant *value)
  244. {
  245. return NPNFuncs.setproperty(npp, obj, propertyName, value);
  246. }
  247. bool NPN_RemoveProperty(NPP npp, NPObject* obj, NPIdentifier propertyName)
  248. {
  249. return NPNFuncs.removeproperty(npp, obj, propertyName);
  250. }
  251. bool NPN_HasProperty(NPP npp, NPObject* obj, NPIdentifier propertyName)
  252. {
  253. return NPNFuncs.hasproperty(npp, obj, propertyName);
  254. }
  255. bool NPN_HasMethod(NPP npp, NPObject* obj, NPIdentifier methodName)
  256. {
  257. return NPNFuncs.hasmethod(npp, obj, methodName);
  258. }
  259. void NPN_ReleaseVariantValue(NPVariant *variant)
  260. {
  261. NPNFuncs.releasevariantvalue(variant);
  262. }
  263. void NPN_SetException(NPObject* obj, const NPUTF8 *message)
  264. {
  265. NPNFuncs.setexception(obj, message);
  266. }