Cast: Stop logging kVideoFrameSentToEncoder and rename a couple events.
[chromium-blink-merge.git] / third_party / npapi / npspy / common / npp_gate.cpp
blobaa1b95021f8da679d488c6f512237c690fcbda5e
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
13 * License.
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.
22 * Contributor(s):
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 ***** */
38 #include "xp.h"
40 #include "epmanager.h"
41 #include "plugload.h"
42 #include "logger.h"
44 extern NPNetscapeFuncs NPNFuncs;
45 extern Logger * logger;
47 NPNetscapeFuncs fakeNPNFuncs;
49 extern NPPEntryPointManager * epManager;
51 jref NPP_GetJavaClass (void)
53 if(logger)
54 logger->logCall(action_npp_get_java_class);
56 if(logger)
57 logger->logReturn(action_npp_get_java_class);
58 return NULL;
61 NPError NPP_New(NPMIMEType pluginType,
62 NPP instance,
63 uint16 mode,
64 int16 argc,
65 char* argn[],
66 char* argv[],
67 NPSavedData* saved)
69 if(epManager == NULL)
70 return NPERR_GENERIC_ERROR;
72 if(instance == NULL)
73 return NPERR_INVALID_INSTANCE_ERROR;
75 if(logger)
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);
86 if(!hLib)
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);
111 if(logger)
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;
166 if(logger)
167 logger->logSPY_NP_Initialize();
169 real_NP_Initialize(&fakeNPNFuncs);
172 NPError rv = epManager->callNPP_New(pluginType, instance, mode, argc, argn, argv, saved);
174 if(logger)
175 logger->logReturn(action_npp_new);
177 return rv;
180 NPError NPP_Destroy (NPP instance, NPSavedData** save)
182 if(epManager == NULL)
183 return NPERR_GENERIC_ERROR;
185 if(instance == NULL)
186 return NPERR_INVALID_INSTANCE_ERROR;
188 BOOL last = FALSE;
190 if(logger)
191 logger->logCall(action_npp_destroy, (DWORD)instance, (DWORD)save);
193 NPError rv = epManager->callNPP_Destroy(instance, save, &last);
195 if(logger)
196 logger->logReturn(action_npp_destroy, rv);
198 if(last && logger->bSPALID)
200 // this will log it
201 epManager->callNP_Shutdown(instance);
203 XP_HLIB hLib = NULL;
205 epManager->removeEntryPointsForPlugin(instance, &hLib);
207 UnloadRealPlugin(hLib);
209 return rv;
212 NPError NPP_SetWindow (NPP instance, NPWindow* pNPWindow)
214 if(epManager == NULL)
215 return NPERR_GENERIC_ERROR;
217 if(instance == NULL)
218 return NPERR_INVALID_INSTANCE_ERROR;
220 if(logger)
221 logger->logCall(action_npp_set_window, (DWORD)instance, (DWORD)pNPWindow);
223 NPError rv = epManager->callNPP_SetWindow(instance, pNPWindow);
225 if(logger)
226 logger->logReturn(action_npp_set_window, rv);
228 return rv;
231 NPError NPP_NewStream(NPP instance,
232 NPMIMEType type,
233 NPStream* stream,
234 NPBool seekable,
235 uint16* stype)
237 if(epManager == NULL)
238 return NPERR_GENERIC_ERROR;
240 if(instance == NULL)
241 return NPERR_INVALID_INSTANCE_ERROR;
243 if(logger)
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);
248 if(logger)
249 logger->logReturn(action_npp_new_stream, rv);
251 return rv;
254 int32 NPP_WriteReady (NPP instance, NPStream *stream)
256 if(epManager == NULL)
257 return NPERR_GENERIC_ERROR;
259 if(instance == NULL)
260 return NPERR_INVALID_INSTANCE_ERROR;
262 if(logger)
263 logger->logCall(action_npp_write_ready, (DWORD)instance, (DWORD)stream);
265 int32 rv = epManager->callNPP_WriteReady(instance, stream);
267 if(logger)
268 logger->logReturn(action_npp_write_ready, rv);
270 return rv;
273 int32 NPP_Write (NPP instance, NPStream *stream, int32 offset, int32 len, void *buffer)
275 if(epManager == NULL)
276 return NPERR_GENERIC_ERROR;
278 if(instance == NULL)
279 return NPERR_INVALID_INSTANCE_ERROR;
281 if(logger)
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);
286 if(logger)
287 logger->logReturn(action_npp_write, rv);
289 return rv;
292 NPError NPP_DestroyStream (NPP instance, NPStream *stream, NPError reason)
294 if(epManager == NULL)
295 return NPERR_GENERIC_ERROR;
297 if(instance == NULL)
298 return NPERR_INVALID_INSTANCE_ERROR;
300 if(logger)
301 logger->logCall(action_npp_destroy_stream, (DWORD)instance, (DWORD)stream, (DWORD)reason);
303 NPError rv = epManager->callNPP_DestroyStream(instance, stream, reason);
305 if(logger)
306 logger->logReturn(action_npp_destroy_stream, rv);
308 return rv;
311 void NPP_StreamAsFile (NPP instance, NPStream* stream, const char* fname)
313 if(epManager == NULL)
314 return;
316 if(instance == NULL)
317 return;
319 if(logger)
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)
328 return;
330 if(logger)
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)
339 return;
341 if(instance == NULL)
342 return;
344 if(logger)
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;
355 if(instance == NULL)
356 return NPERR_INVALID_INSTANCE_ERROR;
358 if(logger)
359 logger->logCall(action_npp_get_value, (DWORD)instance, (DWORD)variable, (DWORD)value);
361 NPError rv = epManager->callNPP_GetValue(instance, variable, value);
363 if(logger)
364 logger->logReturn(action_npp_get_value, rv);
366 return rv;
369 NPError NPP_SetValue(NPP instance, NPNVariable variable, void *value)
371 if(epManager == NULL)
372 return NPERR_GENERIC_ERROR;
374 if(instance == NULL)
375 return NPERR_INVALID_INSTANCE_ERROR;
377 if(logger)
378 logger->logCall(action_npp_set_value, (DWORD)instance, (DWORD)variable, (DWORD)value);
380 NPError rv = epManager->callNPP_SetValue(instance, variable, value);
382 if(logger)
383 logger->logReturn(action_npp_set_value, rv);
385 return rv;
388 int16 NPP_HandleEvent(NPP instance, void* event)
390 if(epManager == NULL)
391 return 0;
393 if(instance == NULL)
394 return 0;
396 if(logger)
397 logger->logCall(action_npp_handle_event, (DWORD)instance, (DWORD)event);
399 int16 rv = epManager->callNPP_HandleEvent(instance, event);
401 if(logger)
402 logger->logReturn(action_npp_handle_event, rv);
404 return rv;