-
-
-/*
-** implementation of libvlc event object
-*/
-
-const NPUTF8 * const LibvlcEventNPObject::propertyNames[] =
-{
-};
-
-enum LibvlcEventNPObjectPropertyIds
-{
-};
-COUNTNAMES(LibvlcEventNPObject,propertyCount,propertyNames);
-
-const NPUTF8 * const LibvlcEventNPObject::methodNames[] =
-{
- "addListener",
- "removeListeners",
-};
-COUNTNAMES(LibvlcEventNPObject,methodCount,methodNames);
-
-enum LibvlcEventNPObjectMethodIds
-{
- ID_event_addListener,
- ID_event_removeListeners,
-};
-
-bool LibvlcEventNPObject::parseArgs(const NPVariant *args, uint32_t argCount,
- eventtypes_bitmap_t &eventToGet)
-{
- if (argCount > 2)
- eventToGet.clear();
-
- for (int argIndex = 2; argIndex < argCount; argIndex++)
- {
- if (NPVARIANT_IS_STRING(args[argIndex]))
- {
- if (!eventToGet.add_event(NPVARIANT_TO_STRING(args[argIndex]).utf8characters))
- return false;
- }
- else if (NPVARIANT_IS_OBJECT(args[argIndex]))
- {
- if (!parseEventArray(NPVARIANT_TO_OBJECT(args[argIndex]), eventToGet, _instance))
- return false;
- }
- else
- return false;
- }
- return true;
-}
-
-RuntimeNPObject::InvokeResult
-LibvlcEventNPObject::invoke(int index, const NPVariant *args,
- uint32_t argCount, NPVariant &result)
-{
- /* is plugin still running */
- if( isPluginRunning() )
- {
- libvlc_exception_t ex;
- libvlc_exception_init(&ex);
-
- switch( index )
- {
- case ID_event_addListener:
- if (argCount >= 2)
- {
- // Checks if the first argument is a NPObject
- if (!NPVARIANT_IS_OBJECT(args[0]))
- return INVOKERESULT_NO_SUCH_METHOD;
-
- // Checks if the browser has the NPAPI version 0.19 at least.
- if (!VlcPlugin::canUseEventListener())
- {
- NPN_SetException(this, strdup(ERROR_API_VERSION));
- return INVOKERESULT_GENERIC_ERROR;
- }
-
- VlcPlugin* p_plugin = getPrivate<VlcPlugin>();
-
- // Gets the binary field corresponding to the events the
- // listener must listen to if specified.
- // Else, listen to all events.
- eventtypes_bitmap_t eventToGet;
- eventToGet.set_all_events();
-
- if (!parseArgs(args, argCount, eventToGet))
- {
- NPN_SetException(this, strdup(ERROR_EVENT_NOT_FOUND));
- return INVOKERESULT_GENERIC_ERROR;
- }
-
- NPObject *listener = NPVARIANT_TO_OBJECT(args[0]);
- NPN_RetainObject(listener);
-
- EventListener *eventListener = new EventListener();
- eventListener->listener = listener;
- eventListener->id = copyNPVariant(args[1]);
- eventListener->eventMap = eventToGet;
-
- p_plugin->eventToCatch.add_event(eventToGet);
-
- p_plugin->eventListeners.push_back(eventListener);
-
- return INVOKERESULT_NO_ERROR;
- }
- return INVOKERESULT_NO_SUCH_METHOD;
- case ID_event_removeListeners:
- if (argCount == 0)
- {
- VlcPlugin* p_plugin = getPrivate<VlcPlugin>();
- p_plugin->eventListeners.clear();
- p_plugin->eventToCatch.clear();
- return INVOKERESULT_NO_ERROR;
- }
- return INVOKERESULT_NO_SUCH_METHOD;
- default:
- ;
- }
- }
- return INVOKERESULT_GENERIC_ERROR;
-}