1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /* ***** BEGIN LICENSE BLOCK *****
3 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
5 * The contents of this file are subject to the Mozilla Public License Version
6 * 1.1 (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 * http://www.mozilla.org/MPL/
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
15 * The Original Code is mozilla.org code.
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.
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 MPL, 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 MPL, the GPL or the LGPL.
36 * ***** END LICENSE BLOCK ***** */
40 #include "epmanager.h"
44 extern NPNetscapeFuncs NPNFuncs
;
45 extern Logger
* logger
;
47 NPNetscapeFuncs fakeNPNFuncs
;
49 extern NPPEntryPointManager
* epManager
;
51 jref
NPP_GetJavaClass (void)
54 logger
->logCall(action_npp_get_java_class
);
57 logger
->logReturn(action_npp_get_java_class
);
61 NPError
NPP_New(NPMIMEType pluginType
,
70 return NPERR_GENERIC_ERROR
;
73 return NPERR_INVALID_INSTANCE_ERROR
;
76 logger
->logCall(action_npp_new
, (DWORD
)pluginType
, (DWORD
)instance
, (DWORD
)mode
, (DWORD
)argc
, (DWORD
)argn
, (DWORD
)argv
, (DWORD
)saved
);
78 /* now action begins */
80 if(NULL
== epManager
->findEntryPointsForPlugin(pluginType
))
82 // if it is first time in, we don't have it yet
83 // scan plugins dir for available plugins to see if we have anything
84 // for the given mimetype
85 XP_HLIB hLib
= LoadRealPlugin(pluginType
);
88 // what do we do if we don't?
89 return NPERR_GENERIC_ERROR
;
92 NP_GETENTRYPOINTS real_NP_GetEntryPoints
= (NP_GETENTRYPOINTS
)XP_GetSymbol(hLib
, "NP_GetEntryPoints");
93 if(!real_NP_GetEntryPoints
)
94 return NPERR_GENERIC_ERROR
;
96 NP_INITIALIZE real_NP_Initialize
= (NP_INITIALIZE
)XP_GetSymbol(hLib
, "NP_Initialize");
97 if(!real_NP_Initialize
)
98 return NPERR_GENERIC_ERROR
;
100 NP_SHUTDOWN real_NP_Shutdown
= (NP_SHUTDOWN
)XP_GetSymbol(hLib
, "NP_Shutdown");
101 if(!real_NP_Shutdown
)
102 return NPERR_GENERIC_ERROR
;
104 // fill callbacks structs
105 NPPluginFuncs realNPPFuncs
;
106 memset(&realNPPFuncs
, 0, sizeof(NPPluginFuncs
));
107 realNPPFuncs
.size
= sizeof(NPPluginFuncs
);
109 real_NP_GetEntryPoints(&realNPPFuncs
);
112 logger
->logSPY_NP_GetEntryPoints(&realNPPFuncs
);
114 // store the table with the entry point manager
115 epManager
->createEntryPointsForPlugin(pluginType
, &realNPPFuncs
, real_NP_Shutdown
, hLib
);
117 // inform the plugin about our entry point it should call
118 memset((void *)&fakeNPNFuncs
, 0, sizeof(fakeNPNFuncs
));
120 fakeNPNFuncs
.size
= sizeof(fakeNPNFuncs
);
121 fakeNPNFuncs
.version
= NPNFuncs
.version
;
122 fakeNPNFuncs
.geturlnotify
= NPN_GetURLNotify
;
123 fakeNPNFuncs
.geturl
= NPN_GetURL
;
124 fakeNPNFuncs
.posturlnotify
= NPN_PostURLNotify
;
125 fakeNPNFuncs
.posturl
= NPN_PostURL
;
126 fakeNPNFuncs
.requestread
= NPN_RequestRead
;
127 fakeNPNFuncs
.newstream
= NPN_NewStream
;
128 fakeNPNFuncs
.write
= NPN_Write
;
129 fakeNPNFuncs
.destroystream
= NPN_DestroyStream
;
130 fakeNPNFuncs
.status
= NPN_Status
;
131 fakeNPNFuncs
.uagent
= NPN_UserAgent
;
132 fakeNPNFuncs
.memalloc
= NPN_MemAlloc
;
133 fakeNPNFuncs
.memfree
= NPN_MemFree
;
134 fakeNPNFuncs
.memflush
= NPN_MemFlush
;
135 fakeNPNFuncs
.reloadplugins
= NPN_ReloadPlugins
;
136 fakeNPNFuncs
.getJavaEnv
= NPN_GetJavaEnv
;
137 fakeNPNFuncs
.getJavaPeer
= NPN_GetJavaPeer
;
138 fakeNPNFuncs
.getvalue
= NPN_GetValue
;
139 fakeNPNFuncs
.setvalue
= NPN_SetValue
;
140 fakeNPNFuncs
.invalidaterect
= NPN_InvalidateRect
;
141 fakeNPNFuncs
.invalidateregion
= NPN_InvalidateRegion
;
142 fakeNPNFuncs
.forceredraw
= NPN_ForceRedraw
;
143 fakeNPNFuncs
.getstringidentifier
= NPN_GetStringIdentifier
;
144 fakeNPNFuncs
.getstringidentifiers
= NPN_GetStringIdentifiers
;
145 fakeNPNFuncs
.getintidentifier
= NPN_GetIntIdentifier
;
146 fakeNPNFuncs
.identifierisstring
= NPN_IdentifierIsString
;
147 fakeNPNFuncs
.utf8fromidentifier
= NPN_UTF8FromIdentifier
;
148 fakeNPNFuncs
.intfromidentifier
= NPN_IntFromIdentifier
;
149 fakeNPNFuncs
.createobject
= NPN_CreateObject
;
150 fakeNPNFuncs
.retainobject
= NPN_RetainObject
;
151 fakeNPNFuncs
.releaseobject
= NPN_ReleaseObject
;
152 fakeNPNFuncs
.invoke
= NPN_Invoke
;
153 fakeNPNFuncs
.invokeDefault
= NPN_InvokeDefault
;
154 fakeNPNFuncs
.evaluate
= NPN_Evaluate
;
155 fakeNPNFuncs
.getproperty
= NPN_GetProperty
;
156 fakeNPNFuncs
.setproperty
= NPN_SetProperty
;
157 fakeNPNFuncs
.removeproperty
= NPN_RemoveProperty
;
158 fakeNPNFuncs
.hasproperty
= NPN_HasProperty
;
159 fakeNPNFuncs
.hasmethod
= NPN_HasMethod
;
160 fakeNPNFuncs
.releasevariantvalue
= NPN_ReleaseVariantValue
;
161 fakeNPNFuncs
.setexception
= NPN_SetException
;
162 fakeNPNFuncs
.pushpopupsenabledstate
= NPN_PushPopupsEnabledState
;
163 fakeNPNFuncs
.poppopupsenabledstate
= NPN_PopPopupsEnabledState
;
164 fakeNPNFuncs
.enumerate
= NPN_Enumerate
;
167 logger
->logSPY_NP_Initialize();
169 real_NP_Initialize(&fakeNPNFuncs
);
172 NPError rv
= epManager
->callNPP_New(pluginType
, instance
, mode
, argc
, argn
, argv
, saved
);
175 logger
->logReturn(action_npp_new
);
180 NPError
NPP_Destroy (NPP instance
, NPSavedData
** save
)
182 if(epManager
== NULL
)
183 return NPERR_GENERIC_ERROR
;
186 return NPERR_INVALID_INSTANCE_ERROR
;
191 logger
->logCall(action_npp_destroy
, (DWORD
)instance
, (DWORD
)save
);
193 NPError rv
= epManager
->callNPP_Destroy(instance
, save
, &last
);
196 logger
->logReturn(action_npp_destroy
, rv
);
198 if(last
&& logger
->bSPALID
)
201 epManager
->callNP_Shutdown(instance
);
205 epManager
->removeEntryPointsForPlugin(instance
, &hLib
);
207 UnloadRealPlugin(hLib
);
212 NPError
NPP_SetWindow (NPP instance
, NPWindow
* pNPWindow
)
214 if(epManager
== NULL
)
215 return NPERR_GENERIC_ERROR
;
218 return NPERR_INVALID_INSTANCE_ERROR
;
221 logger
->logCall(action_npp_set_window
, (DWORD
)instance
, (DWORD
)pNPWindow
);
223 NPError rv
= epManager
->callNPP_SetWindow(instance
, pNPWindow
);
226 logger
->logReturn(action_npp_set_window
, rv
);
231 NPError
NPP_NewStream(NPP instance
,
237 if(epManager
== NULL
)
238 return NPERR_GENERIC_ERROR
;
241 return NPERR_INVALID_INSTANCE_ERROR
;
244 logger
->logCall(action_npp_new_stream
, (DWORD
)instance
, (DWORD
)type
, (DWORD
)stream
, (DWORD
)seekable
, (DWORD
)stype
);
246 NPError rv
= epManager
->callNPP_NewStream(instance
, type
, stream
, seekable
, stype
);
249 logger
->logReturn(action_npp_new_stream
, rv
);
254 int32
NPP_WriteReady (NPP instance
, NPStream
*stream
)
256 if(epManager
== NULL
)
257 return NPERR_GENERIC_ERROR
;
260 return NPERR_INVALID_INSTANCE_ERROR
;
263 logger
->logCall(action_npp_write_ready
, (DWORD
)instance
, (DWORD
)stream
);
265 int32 rv
= epManager
->callNPP_WriteReady(instance
, stream
);
268 logger
->logReturn(action_npp_write_ready
, rv
);
273 int32
NPP_Write (NPP instance
, NPStream
*stream
, int32 offset
, int32 len
, void *buffer
)
275 if(epManager
== NULL
)
276 return NPERR_GENERIC_ERROR
;
279 return NPERR_INVALID_INSTANCE_ERROR
;
282 logger
->logCall(action_npp_write
, (DWORD
)instance
, (DWORD
)stream
, (DWORD
)offset
, (DWORD
)len
, (DWORD
)buffer
);
284 int32 rv
= epManager
->callNPP_Write(instance
, stream
, offset
, len
, buffer
);
287 logger
->logReturn(action_npp_write
, rv
);
292 NPError
NPP_DestroyStream (NPP instance
, NPStream
*stream
, NPError reason
)
294 if(epManager
== NULL
)
295 return NPERR_GENERIC_ERROR
;
298 return NPERR_INVALID_INSTANCE_ERROR
;
301 logger
->logCall(action_npp_destroy_stream
, (DWORD
)instance
, (DWORD
)stream
, (DWORD
)reason
);
303 NPError rv
= epManager
->callNPP_DestroyStream(instance
, stream
, reason
);
306 logger
->logReturn(action_npp_destroy_stream
, rv
);
311 void NPP_StreamAsFile (NPP instance
, NPStream
* stream
, const char* fname
)
313 if(epManager
== NULL
)
320 logger
->logCall(action_npp_stream_as_file
, (DWORD
)instance
, (DWORD
)stream
, (DWORD
)fname
);
322 epManager
->callNPP_StreamAsFile(instance
, stream
, fname
);
325 void NPP_Print (NPP instance
, NPPrint
* printInfo
)
327 if(epManager
== NULL
)
331 logger
->logCall(action_npp_print
, (DWORD
)instance
, (DWORD
)printInfo
);
333 epManager
->callNPP_Print(instance
, printInfo
);
336 void NPP_URLNotify(NPP instance
, const char* url
, NPReason reason
, void* notifyData
)
338 if(epManager
== NULL
)
345 logger
->logCall(action_npp_url_notify
, (DWORD
)instance
, (DWORD
)url
, (DWORD
)reason
, (DWORD
)notifyData
);
347 epManager
->callNPP_URLNotify(instance
, url
, reason
, notifyData
);
350 NPError
NPP_GetValue(NPP instance
, NPPVariable variable
, void *value
)
352 if(epManager
== NULL
)
353 return NPERR_GENERIC_ERROR
;
356 return NPERR_INVALID_INSTANCE_ERROR
;
359 logger
->logCall(action_npp_get_value
, (DWORD
)instance
, (DWORD
)variable
, (DWORD
)value
);
361 NPError rv
= epManager
->callNPP_GetValue(instance
, variable
, value
);
364 logger
->logReturn(action_npp_get_value
, rv
);
369 NPError
NPP_SetValue(NPP instance
, NPNVariable variable
, void *value
)
371 if(epManager
== NULL
)
372 return NPERR_GENERIC_ERROR
;
375 return NPERR_INVALID_INSTANCE_ERROR
;
378 logger
->logCall(action_npp_set_value
, (DWORD
)instance
, (DWORD
)variable
, (DWORD
)value
);
380 NPError rv
= epManager
->callNPP_SetValue(instance
, variable
, value
);
383 logger
->logReturn(action_npp_set_value
, rv
);
388 int16
NPP_HandleEvent(NPP instance
, void* event
)
390 if(epManager
== NULL
)
397 logger
->logCall(action_npp_handle_event
, (DWORD
)instance
, (DWORD
)event
);
399 int16 rv
= epManager
->callNPP_HandleEvent(instance
, event
);
402 logger
->logReturn(action_npp_handle_event
, rv
);