Cast: Stop logging kVideoFrameSentToEncoder and rename a couple events.
[chromium-blink-merge.git] / third_party / npapi / npspy / common / epmanager.cpp
blob6201f23e87588c5f3fd5d946bdd9eecac5817a6b
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 "logger.h"
43 extern Logger * logger;
45 InstanceList::InstanceList(NPP _instance) :
46 next(NULL),
47 instance(_instance)
51 InstanceList::~InstanceList()
55 PluginEntryPointList::PluginEntryPointList() :
56 next(NULL),
57 instances(NULL)
59 mimetype[0] = '\0';
60 memset((void *)&realNPPFuncs, 0, sizeof(realNPPFuncs));
61 realShutdown = NULL;
62 hLib = NULL;
65 PluginEntryPointList::~PluginEntryPointList()
69 NPPEntryPointManager::NPPEntryPointManager() :
70 mEntryPoints(NULL)
74 NPPEntryPointManager::~NPPEntryPointManager()
76 for(PluginEntryPointList * eps = mEntryPoints; eps != NULL;)
78 for(InstanceList * instances = eps->instances; instances != NULL;)
80 InstanceList * next = instances->next;
81 delete instances;
82 instances = next;
85 PluginEntryPointList * next = eps->next;
86 delete eps;
87 eps = next;
91 void NPPEntryPointManager::createEntryPointsForPlugin(char * mimetype, NPPluginFuncs * funcs, NP_SHUTDOWN shutdownproc, XP_HLIB hLib)
93 PluginEntryPointList * eps = new PluginEntryPointList();
95 if(eps == NULL)
96 return;
98 strcpy(eps->mimetype, mimetype);
100 if(funcs)
102 eps->realNPPFuncs.size = funcs->size;
103 eps->realNPPFuncs.version = funcs->version;
104 eps->realNPPFuncs.newp = funcs->newp;
105 eps->realNPPFuncs.destroy = funcs->destroy;
106 eps->realNPPFuncs.setwindow = funcs->setwindow;
107 eps->realNPPFuncs.newstream = funcs->newstream;
108 eps->realNPPFuncs.destroystream = funcs->destroystream;
109 eps->realNPPFuncs.asfile = funcs->asfile;
110 eps->realNPPFuncs.writeready = funcs->writeready;
111 eps->realNPPFuncs.write = funcs->write;
112 eps->realNPPFuncs.print = funcs->print;
113 eps->realNPPFuncs.event = funcs->event;
114 eps->realNPPFuncs.urlnotify = funcs->urlnotify;
115 eps->realNPPFuncs.javaClass = funcs->javaClass;
116 eps->realNPPFuncs.getvalue = funcs->getvalue;
120 eps->realShutdown = shutdownproc;
121 eps->hLib = hLib;
123 eps->next = mEntryPoints;
124 mEntryPoints = eps;
127 void NPPEntryPointManager::removeEntryPointsForPlugin(NPP instance, XP_HLIB * lib)
129 NPPluginFuncs * eptoremove = findEntryPointsForInstance(instance);
131 PluginEntryPointList * prev = NULL;
133 for(PluginEntryPointList * eps = mEntryPoints; eps != NULL; eps = eps->next)
135 if(&eps->realNPPFuncs == eptoremove)
137 if(prev)
138 prev->next = eps->next;
139 else
140 mEntryPoints = eps->next;
142 *lib = eps->hLib;
143 delete eps;
144 return;
147 prev = eps;
151 NPPluginFuncs * NPPEntryPointManager::findEntryPointsForPlugin(char * mimetype)
153 for(PluginEntryPointList * eps = mEntryPoints; eps != NULL; eps = eps->next)
155 if(0 == _stricmp(eps->mimetype, mimetype))
156 return &eps->realNPPFuncs;
159 return NULL;
162 NPPluginFuncs * NPPEntryPointManager::findEntryPointsForInstance(NPP instance)
164 for(PluginEntryPointList * eps = mEntryPoints; eps != NULL; eps = eps->next)
166 for(InstanceList * instances = eps->instances; instances != NULL; instances = instances->next)
168 if(instances->instance == instance)
169 return &eps->realNPPFuncs;
173 return NULL;
176 void NPPEntryPointManager::callNP_ShutdownAll()
178 for(PluginEntryPointList * eps = mEntryPoints; eps != NULL; eps = eps->next)
180 if(eps->realShutdown)
182 logger->logSPY_NP_Shutdown(eps->mimetype);
183 eps->realShutdown();
184 eps->realShutdown = NULL; // don't want to call it more than once
189 void NPPEntryPointManager::callNP_Shutdown(NPP instance)
191 for(PluginEntryPointList * eps = mEntryPoints; eps != NULL; eps = eps->next)
193 for(InstanceList * instances = eps->instances; instances != NULL; instances = instances->next)
195 if(instances->instance == instance)
197 if(eps->realShutdown)
199 logger->logSPY_NP_Shutdown(eps->mimetype);
200 eps->realShutdown();
201 eps->realShutdown = NULL; // don't want to call it more than once
208 NPError NPPEntryPointManager::callNPP_New(NPMIMEType pluginType, NPP instance, uint16 mode, int16 argc, char* argn[], char* argv[], NPSavedData* saved)
210 NPPluginFuncs * nppfuncs = NULL;
212 for(PluginEntryPointList * eps = mEntryPoints; eps != NULL; eps = eps->next)
214 if(0 == _stricmp(eps->mimetype, pluginType))
216 nppfuncs = &eps->realNPPFuncs;
218 // now we should associate this plugin instance with plugin entry points
219 // so that later we could find entry points by instance rather than by mimetype
220 InstanceList * inst = new InstanceList(instance);
221 inst->next = eps->instances;
222 eps->instances = inst;
224 break;
228 if(!nppfuncs || !nppfuncs->newp)
229 return NPERR_GENERIC_ERROR;
231 NPError rv = CallNPP_NewProc(nppfuncs->newp, pluginType, instance, mode, argc, argn, argv, saved);
233 return rv;
236 NPError NPPEntryPointManager::callNPP_Destroy(NPP instance, NPSavedData** save, BOOL * last)
238 NPPluginFuncs * nppfuncs = NULL;
240 BOOL done = FALSE;
242 for(PluginEntryPointList * eps = mEntryPoints; eps != NULL; eps = eps->next)
244 InstanceList * prev = NULL;
245 for(InstanceList * instances = eps->instances; instances != NULL; instances = instances->next)
247 if(instances->instance == instance)
249 nppfuncs = &eps->realNPPFuncs;
250 done = TRUE;
252 // check if this is the last one
253 if(eps->instances->next == NULL)
254 *last = TRUE;
255 else
257 // deassociate instance if this is not the last one
258 // last instance will be needed to find corresponding shutdown proc
259 if(prev)
260 prev->next = instances->next;
261 else
262 eps->instances = instances->next;
264 delete instances;
267 break;
269 prev = instances;
271 if(done)
272 break;
275 if(!nppfuncs || !nppfuncs->destroy)
276 return NPERR_GENERIC_ERROR;
278 return CallNPP_DestroyProc(nppfuncs->destroy, instance, save);
281 NPError NPPEntryPointManager::callNPP_SetWindow(NPP instance, NPWindow* window)
283 NPPluginFuncs * nppfuncs = findEntryPointsForInstance(instance);
284 if(!nppfuncs || !nppfuncs->setwindow)
285 return NPERR_GENERIC_ERROR;
287 return CallNPP_SetWindowProc(nppfuncs->setwindow, instance, window);
290 NPError NPPEntryPointManager::callNPP_NewStream(NPP instance, NPMIMEType type, NPStream* stream, NPBool seekable, uint16* stype)
292 NPPluginFuncs * nppfuncs = findEntryPointsForInstance(instance);
293 if(!nppfuncs || !nppfuncs->newstream)
294 return NPERR_GENERIC_ERROR;
296 return CallNPP_NewStreamProc(nppfuncs->newstream, instance, type, stream, seekable, stype);
299 NPError NPPEntryPointManager::callNPP_DestroyStream(NPP instance, NPStream* stream, NPReason reason)
301 NPPluginFuncs * nppfuncs = findEntryPointsForInstance(instance);
302 if(!nppfuncs || !nppfuncs->destroystream)
303 return NPERR_GENERIC_ERROR;
305 return CallNPP_DestroyStreamProc(nppfuncs->destroystream, instance, stream, reason);
308 int32 NPPEntryPointManager::callNPP_WriteReady(NPP instance, NPStream* stream)
310 NPPluginFuncs * nppfuncs = findEntryPointsForInstance(instance);
311 if(!nppfuncs || !nppfuncs->writeready)
312 return NPERR_GENERIC_ERROR;
314 return CallNPP_WriteReadyProc(nppfuncs->writeready, instance, stream);
317 int32 NPPEntryPointManager::callNPP_Write(NPP instance, NPStream* stream, int32 offset, int32 len, void* buffer)
319 NPPluginFuncs * nppfuncs = findEntryPointsForInstance(instance);
320 if(!nppfuncs || !nppfuncs->write)
321 return NPERR_GENERIC_ERROR;
323 return CallNPP_WriteProc(nppfuncs->write, instance, stream, offset, len, buffer);
326 void NPPEntryPointManager::callNPP_StreamAsFile(NPP instance, NPStream* stream, const char* fname)
328 NPPluginFuncs * nppfuncs = findEntryPointsForInstance(instance);
329 if(!nppfuncs || !nppfuncs->asfile)
330 return;
332 CallNPP_StreamAsFileProc(nppfuncs->asfile, instance, stream, fname);
335 void NPPEntryPointManager::callNPP_Print(NPP instance, NPPrint* platformPrint)
337 NPPluginFuncs * nppfuncs = findEntryPointsForInstance(instance);
338 if(!nppfuncs || !nppfuncs->print)
339 return;
341 CallNPP_PrintProc(nppfuncs->print, instance, platformPrint);
344 void NPPEntryPointManager::callNPP_URLNotify(NPP instance, const char* url, NPReason reason, void* notifyData)
346 NPPluginFuncs * nppfuncs = findEntryPointsForInstance(instance);
347 if(!nppfuncs || !nppfuncs->urlnotify)
348 return;
350 CallNPP_URLNotifyProc(nppfuncs->urlnotify, instance, url, reason, notifyData);
353 NPError NPPEntryPointManager::callNPP_GetValue(NPP instance, NPPVariable variable, void *value)
355 NPPluginFuncs * nppfuncs = findEntryPointsForInstance(instance);
356 if(!nppfuncs || !nppfuncs->getvalue)
357 return NPERR_GENERIC_ERROR;
359 return CallNPP_GetValueProc(nppfuncs->getvalue, instance, variable, value);
362 NPError NPPEntryPointManager::callNPP_SetValue(NPP instance, NPNVariable variable, void *value)
364 NPPluginFuncs * nppfuncs = findEntryPointsForInstance(instance);
365 if(!nppfuncs || !nppfuncs->setvalue)
366 return NPERR_GENERIC_ERROR;
368 return CallNPP_SetValueProc(nppfuncs->setvalue, instance, variable, value);
371 int16 NPPEntryPointManager::callNPP_HandleEvent(NPP instance, void* event)
373 NPPluginFuncs * nppfuncs = findEntryPointsForInstance(instance);
374 if(!nppfuncs || !nppfuncs->event)
375 return NPERR_GENERIC_ERROR;
377 return CallNPP_HandleEventProc(nppfuncs->event, instance, event);