1 /*****************************************************************************
2 * vlcplugin.cpp: a VLC plugin for Mozilla
3 *****************************************************************************
4 * Copyright (C) 2002-2010 the VideoLAN team
7 * Authors: Samuel Hocevar <sam@zoy.org>
8 * Damien Fouilleul <damienf.fouilleul@laposte.net>
9 * Jean-Paul Saman <jpsaman@videolan.org>
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
24 *****************************************************************************/
26 /*****************************************************************************
28 *****************************************************************************/
31 #ifdef HAVE_MOZILLA_CONFIG_H
32 # include <mozilla-config.h>
35 #include "vlcplugin.h"
36 #include "control/npolibvlc.h"
45 #warning "locking not implemented for this platform"
50 /*****************************************************************************
52 *****************************************************************************/
53 static void plugin_lock_init(plugin_lock_t *lock)
58 pthread_mutex_init(&lock->mutex, NULL);
60 InitializeCriticalSection(&lock->cs);
62 #warning "locking not implemented in this platform"
66 static void plugin_lock_destroy(plugin_lock_t *lock)
71 pthread_mutex_destroy(&lock->mutex);
73 DeleteCriticalSection(&lock->cs);
75 #warning "locking not implemented in this platform"
79 static void plugin_lock(plugin_lock_t *lock)
84 pthread_mutex_lock(&lock->mutex);
86 EnterCriticalSection(&lock->cs);
88 #warning "locking not implemented in this platform"
92 static void plugin_unlock(plugin_lock_t *lock)
97 pthread_mutex_unlock(&lock->mutex);
99 LeaveCriticalSection(&lock->cs);
101 #warning "locking not implemented in this platform"
105 /*****************************************************************************
106 * VlcPlugin constructor and destructor
107 *****************************************************************************/
108 VlcPlugin::VlcPlugin( NPP instance, uint16 mode ) :
116 libvlc_instance(NULL),
117 libvlc_media_list(NULL),
118 libvlc_media_player(NULL),
126 ,i_width((unsigned)-1)
127 ,i_height((unsigned)-1)
136 ,p_btnFullscreen(NULL)
141 memset(&npwindow, 0, sizeof(NPWindow));
143 memset(&npvideo, 0, sizeof(Window));
144 memset(&npcontrol, 0, sizeof(Window));
148 static bool boolValue(const char *value) {
149 return ( !strcmp(value, "1") ||
150 !strcasecmp(value, "true") ||
151 !strcasecmp(value, "yes") );
154 bool EventObj::init()
156 plugin_lock_init(&lock);
160 EventObj::~EventObj()
162 plugin_lock_destroy(&lock);
165 void EventObj::deliver(NPP browser)
172 for( ev_l::iterator i=_elist.begin();i!=_elist.end();++i )
174 libvlc_event_type_t event = *i;
175 STRINGZ_TO_NPVARIANT(libvlc_event_type_name(event), params[0]);
177 // Invalid events aren't supposed to be queued up.
178 // if( !have_event(event) ) continue;
180 for( lr_l::iterator j=_llist.begin();j!=_llist.end();++j )
184 NPN_InvokeDefault(browser, j->listener(), params, 1, &result);
185 NPN_ReleaseVariantValue(&result);
191 plugin_unlock(&lock);
194 void VlcPlugin::eventAsync(void *param)
196 VlcPlugin *plugin = (VlcPlugin*)param;
197 plugin->events.deliver(plugin->getBrowser());
200 void EventObj::callback(const libvlc_event_t* event)
204 if( have_event(event->type) )
205 _elist.push_back(event->type);
207 plugin_unlock(&lock);
210 void VlcPlugin::event_callback(const libvlc_event_t* event, void *param)
212 VlcPlugin *plugin = (VlcPlugin*)param;
214 plugin->events.callback(event);
215 NPN_PluginThreadAsyncCall(plugin->getBrowser(), eventAsync, plugin);
217 #warning NPN_PluginThreadAsyncCall not implemented yet.
218 printf("No NPN_PluginThreadAsyncCall(), doing nothing.");
222 inline EventObj::event_t EventObj::find_event(const char *s) const
225 for(i=0;i<maxbit();++i)
226 if(!strcmp(s,libvlc_event_type_name(i)))
231 bool EventObj::insert(const NPString &s, NPObject *l, bool b)
233 event_t e = find_event(s.utf8characters);
237 if( !have_event(e) && !ask_for_event(e) )
241 for(i=_llist.begin();i!=_llist.end();++i)
242 if(i->listener()==l && i->bubble()==b)
245 if( i == _llist.end() ) {
246 _llist.push_back(Listener(e,l,b));
256 bool EventObj::remove(const NPString &s, NPObject *l, bool b)
258 event_t e = find_event(s.utf8characters);
259 if( e>=maxbit() || !get(e) )
263 for(lr_l::iterator i=_llist.begin();i!=_llist.end();)
265 if(i->listener()!=l || i->bubble()!=b)
285 void EventObj::hook_manager(libvlc_event_manager_t *em,
286 libvlc_callback_t cb, void *udata)
288 _em = em; _cb = cb; _ud = udata;
291 for(size_t i=0;i<maxbit();++i)
293 libvlc_event_attach(_em, i, _cb, _ud);
296 void EventObj::unhook_manager()
300 for(size_t i=0;i<maxbit();++i)
302 libvlc_event_detach(_em, i, _cb, _ud);
306 bool EventObj::ask_for_event(event_t e)
308 return _em?0==libvlc_event_attach(_em, e, _cb, _ud):false;
312 void EventObj::unask_for_event(event_t e)
314 if(_em) libvlc_event_detach(_em, e, _cb, _ud);
318 NPError VlcPlugin::init(int argc, char* const argn[], char* const argv[])
320 /* prepare VLC command line */
321 const char *ppsz_argv[32];
325 ppsz_argv[ppsz_argc++] = "--no-plugins-cache";
328 /* locate VLC module path */
330 ppsz_argv[ppsz_argc++] = "--plugin-path=/Library/Internet\\ Plug-Ins/VLC\\ Plugin.plugin/Contents/MacOS/modules";
331 ppsz_argv[ppsz_argc++] = "--vout=minimal_macosx";
332 #elif defined(XP_WIN)
334 DWORD i_type, i_data = MAX_PATH + 1;
335 char p_data[MAX_PATH + 1];
336 if( RegOpenKeyEx( HKEY_LOCAL_MACHINE, "Software\\VideoLAN\\VLC",
337 0, KEY_READ, &h_key ) == ERROR_SUCCESS )
339 if( RegQueryValueEx( h_key, "InstallDir", 0, &i_type,
340 (LPBYTE)p_data, &i_data ) == ERROR_SUCCESS )
342 if( i_type == REG_SZ )
344 strcat( p_data, "\\plugins" );
345 ppsz_argv[ppsz_argc++] = "--plugin-path";
346 ppsz_argv[ppsz_argc++] = p_data;
349 RegCloseKey( h_key );
351 ppsz_argv[ppsz_argc++] = "--no-one-instance";
353 #endif /* XP_MACOSX */
355 /* common settings */
356 ppsz_argv[ppsz_argc++] = "-vv";
357 ppsz_argv[ppsz_argc++] = "--no-stats";
358 ppsz_argv[ppsz_argc++] = "--no-media-library";
359 ppsz_argv[ppsz_argc++] = "--intf=dummy";
360 ppsz_argv[ppsz_argc++] = "--no-video-title-show";
362 const char *progid = NULL;
364 /* parse plugin arguments */
365 for( int i = 0; (i < argc) && (ppsz_argc < 32); i++ )
367 /* fprintf(stderr, "argn=%s, argv=%s\n", argn[i], argv[i]); */
369 if( !strcmp( argn[i], "target" )
370 || !strcmp( argn[i], "mrl")
371 || !strcmp( argn[i], "filename")
372 || !strcmp( argn[i], "src") )
374 psz_target = argv[i];
376 else if( !strcmp( argn[i], "text" ) )
379 psz_text = strdup( argv[i] );
381 else if( !strcmp( argn[i], "autoplay")
382 || !strcmp( argn[i], "autostart") )
384 b_autoplay = boolValue(argv[i]);
386 else if( !strcmp( argn[i], "fullscreen" ) )
388 if( boolValue(argv[i]) )
390 ppsz_argv[ppsz_argc++] = "--fullscreen";
394 ppsz_argv[ppsz_argc++] = "--no-fullscreen";
397 else if( !strcmp( argn[i], "mute" ) )
399 if( boolValue(argv[i]) )
401 ppsz_argv[ppsz_argc++] = "--volume=0";
404 else if( !strcmp( argn[i], "loop")
405 || !strcmp( argn[i], "autoloop") )
407 if( boolValue(argv[i]) )
409 ppsz_argv[ppsz_argc++] = "--loop";
413 ppsz_argv[ppsz_argc++] = "--no-loop";
416 else if( !strcmp( argn[i], "version")
417 || !strcmp( argn[i], "progid") )
421 else if( !strcmp( argn[i], "toolbar" ) )
423 /* FIXME: Remove this when toolbar functionality has been implemented on
424 * MacOS X and Win32 for Firefox/Mozilla/Safari. */
426 b_toolbar = boolValue(argv[i]);
431 libvlc_instance = libvlc_new(ppsz_argc, ppsz_argv);
432 if( !libvlc_instance )
433 return NPERR_GENERIC_ERROR;
434 libvlc_media_list = libvlc_media_list_new(libvlc_instance);
437 ** fetch plugin base URL, which is the URL of the page containing the plugin
438 ** this URL is used for making absolute URL from relative URL that may be
439 ** passed as an MRL argument
441 NPObject *plugin = NULL;
443 if( NPERR_NO_ERROR == NPN_GetValue(p_browser, NPNVWindowNPObject, &plugin) )
446 ** is there a better way to get that info ?
448 static const char docLocHref[] = "document.location.href";
452 script.utf8characters = docLocHref;
453 script.utf8length = sizeof(docLocHref)-1;
455 if( NPN_Evaluate(p_browser, plugin, &script, &result) )
457 if( NPVARIANT_IS_STRING(result) )
459 NPString &location = NPVARIANT_TO_STRING(result);
461 psz_baseURL = (char *) malloc(location.utf8length+1);
464 strncpy(psz_baseURL, location.utf8characters, location.utf8length);
465 psz_baseURL[location.utf8length] = '\0';
468 NPN_ReleaseVariantValue(&result);
470 NPN_ReleaseObject(plugin);
475 // get absolute URL from src
476 char *psz_absurl = getAbsoluteURL(psz_target);
477 psz_target = psz_absurl ? psz_absurl : strdup(psz_target);
480 /* assign plugin script root class */
482 p_scriptClass = RuntimeNPClass<LibvlcRootNPObject>::getClass();
485 return NPERR_GENERIC_ERROR;
487 return NPERR_NO_ERROR;
490 VlcPlugin::~VlcPlugin()
496 if( libvlc_media_player )
498 events.unhook_manager();
499 libvlc_media_player_release( libvlc_media_player );
501 if( libvlc_media_list )
502 libvlc_media_list_release( libvlc_media_list );
503 if( libvlc_instance )
504 libvlc_release(libvlc_instance);
507 /*****************************************************************************
508 * VlcPlugin playlist replacement methods
509 *****************************************************************************/
510 void VlcPlugin::set_player_window()
513 libvlc_media_player_set_xwindow(libvlc_media_player,
514 (uint32_t)getVideoWindow());
517 // XXX FIXME insert appropriate call here
520 libvlc_media_player_set_hwnd(libvlc_media_player,
525 int VlcPlugin::playlist_add( const char *mrl )
528 libvlc_media_t *p_m = libvlc_media_new_location(libvlc_instance,mrl);
531 assert( libvlc_media_list );
532 libvlc_media_list_lock(libvlc_media_list);
533 if( !libvlc_media_list_add_media(libvlc_media_list,p_m) )
534 item = libvlc_media_list_count(libvlc_media_list)-1;
535 libvlc_media_list_unlock(libvlc_media_list);
537 libvlc_media_release(p_m);
542 int VlcPlugin::playlist_add_extended_untrusted( const char *mrl, const char *name,
543 int optc, const char **optv )
548 assert( libvlc_media_list );
550 p_m = libvlc_media_new_location(libvlc_instance, mrl);
554 for( int i = 0; i < optc; ++i )
555 libvlc_media_add_option_flag(p_m, optv[i], libvlc_media_option_unique);
557 libvlc_media_list_lock(libvlc_media_list);
558 if( !libvlc_media_list_add_media(libvlc_media_list,p_m) )
559 item = libvlc_media_list_count(libvlc_media_list)-1;
560 libvlc_media_list_unlock(libvlc_media_list);
561 libvlc_media_release(p_m);
566 bool VlcPlugin::playlist_select( int idx )
568 libvlc_media_t *p_m = NULL;
570 assert( libvlc_media_list );
572 libvlc_media_list_lock(libvlc_media_list);
574 int count = libvlc_media_list_count(libvlc_media_list);
575 if( idx<0||idx>=count )
578 playlist_index = idx;
580 p_m = libvlc_media_list_item_at_index(libvlc_media_list,playlist_index);
581 libvlc_media_list_unlock(libvlc_media_list);
586 if( libvlc_media_player )
588 if( playlist_isplaying() )
590 events.unhook_manager();
591 libvlc_media_player_release( libvlc_media_player );
592 libvlc_media_player = NULL;
595 libvlc_media_player = libvlc_media_player_new_from_media(p_m);
596 if( libvlc_media_player )
600 libvlc_media_player_event_manager(libvlc_media_player),
601 event_callback, this);
604 libvlc_media_release( p_m );
608 libvlc_media_list_unlock(libvlc_media_list);
612 int VlcPlugin::playlist_delete_item( int idx )
614 if( !libvlc_media_list )
616 libvlc_media_list_lock(libvlc_media_list);
617 int ret = libvlc_media_list_remove_index(libvlc_media_list,idx);
618 libvlc_media_list_unlock(libvlc_media_list);
622 void VlcPlugin::playlist_clear()
624 if( libvlc_media_list )
625 libvlc_media_list_release(libvlc_media_list);
626 libvlc_media_list = libvlc_media_list_new(getVLC());
629 int VlcPlugin::playlist_count()
632 if( !libvlc_media_list )
634 libvlc_media_list_lock(libvlc_media_list);
635 items_count = libvlc_media_list_count(libvlc_media_list);
636 libvlc_media_list_unlock(libvlc_media_list);
640 void VlcPlugin::toggle_fullscreen()
642 if( playlist_isplaying() )
643 libvlc_toggle_fullscreen(libvlc_media_player);
646 void VlcPlugin::set_fullscreen( int yes )
648 if( playlist_isplaying() )
649 libvlc_set_fullscreen(libvlc_media_player,yes);
652 int VlcPlugin::get_fullscreen()
655 if( playlist_isplaying() )
656 r = libvlc_get_fullscreen(libvlc_media_player);
660 bool VlcPlugin::player_has_vout()
663 if( playlist_isplaying() )
664 r = libvlc_media_player_has_vout(libvlc_media_player);
668 /*****************************************************************************
670 *****************************************************************************/
672 char *VlcPlugin::getAbsoluteURL(const char *url)
676 // check whether URL is already absolute
677 const char *end=strchr(url, ':');
678 if( (NULL != end) && (end != url) )
680 // validate protocol header
681 const char *start = url;
686 while( start != end )
693 || ('/' == c)) ) /* VLC uses / to allow user to specify a demuxer */
694 // not valid protocol header, assume relative URL
698 /* we have a protocol header, therefore URL is absolute */
701 // not a valid protocol header, assume relative URL
708 size_t baseLen = strlen(psz_baseURL);
709 char *href = (char *) malloc(baseLen+strlen(url)+1);
712 /* prepend base URL */
713 memcpy(href, psz_baseURL, baseLen+1);
716 ** relative url could be empty,
717 ** in which case return base URL
723 ** locate pathname part of base URL
726 /* skip over protocol part */
727 char *pathstart = strchr(href, ':');
728 char *pathend = href+baseLen;
731 if( '/' == *(++pathstart) )
733 if( '/' == *(++pathstart) )
738 /* skip over host part */
739 pathstart = strchr(pathstart, '/');
742 // no path, add a / past end of url (over '\0')
749 /* baseURL is just a UNIX path */
752 /* baseURL is not an absolute path */
759 /* relative URL made of an absolute path ? */
762 /* replace path completely */
763 strcpy(pathstart, url);
767 /* find last path component and replace it */
768 while( '/' != *pathend)
772 ** if relative url path starts with one or more '../',
773 ** factor them out of href so that we return a
776 while( pathend != pathstart )
784 /* relative url is just '.' */
790 /* relative url starts with './' */
799 /* relative url is '..' */
805 /* relative url starts with '../' */
813 while( '/' != *pathend );
815 /* skip over '/' separator */
817 /* concatenate remaining base URL and relative URL */
818 strcpy(pathend, url);
827 int VlcPlugin::setSize(unsigned width, unsigned height)
829 int diff = (width != i_width) || (height != i_height);
838 #define BTN_SPACE ((unsigned int)4)
839 void VlcPlugin::showToolbar()
841 const NPWindow& window = getWindow();
842 Window control = getControlWindow();
843 Window video = getVideoWindow();
844 Display *p_display = ((NPSetWindowCallbackStruct *)window.ws_info)->display;
845 unsigned int i_height = 0, i_width = BTN_SPACE;
849 XpmReadFileToImage( p_display, DATA_PATH "/mozilla/play.xpm",
850 &p_btnPlay, NULL, NULL);
853 i_height = __MAX( i_height, p_btnPlay->height );
856 XpmReadFileToImage( p_display, DATA_PATH "/mozilla/pause.xpm",
857 &p_btnPause, NULL, NULL);
860 i_height = __MAX( i_height, p_btnPause->height );
862 i_width += __MAX( p_btnPause->width, p_btnPlay->width );
865 XpmReadFileToImage( p_display, DATA_PATH "/mozilla/stop.xpm",
866 &p_btnStop, NULL, NULL );
869 i_height = __MAX( i_height, p_btnStop->height );
870 i_width += BTN_SPACE + p_btnStop->width;
873 XpmReadFileToImage( p_display, DATA_PATH "/mozilla/time_line.xpm",
874 &p_timeline, NULL, NULL);
877 i_height = __MAX( i_height, p_timeline->height );
878 i_width += BTN_SPACE + p_timeline->width;
881 XpmReadFileToImage( p_display, DATA_PATH "/mozilla/time_icon.xpm",
882 &p_btnTime, NULL, NULL);
885 i_height = __MAX( i_height, p_btnTime->height );
886 i_width += BTN_SPACE + p_btnTime->width;
888 if( !p_btnFullscreen )
889 XpmReadFileToImage( p_display, DATA_PATH "/mozilla/fullscreen.xpm",
890 &p_btnFullscreen, NULL, NULL);
891 if( p_btnFullscreen )
893 i_height = __MAX( i_height, p_btnFullscreen->height );
894 i_width += BTN_SPACE + p_btnFullscreen->width;
897 XpmReadFileToImage( p_display, DATA_PATH "/mozilla/volume_max.xpm",
898 &p_btnMute, NULL, NULL);
901 i_height = __MAX( i_height, p_btnMute->height );
904 XpmReadFileToImage( p_display, DATA_PATH "/mozilla/volume_mute.xpm",
905 &p_btnUnmute, NULL, NULL);
908 i_height = __MAX( i_height, p_btnUnmute->height );
910 i_width += BTN_SPACE + __MAX( p_btnUnmute->width, p_btnMute->width );
912 setToolbarSize( i_width, i_height );
914 if( !p_btnPlay || !p_btnPause || !p_btnStop || !p_timeline ||
915 !p_btnTime || !p_btnFullscreen || !p_btnMute || !p_btnUnmute )
916 fprintf(stderr, "Error: some button images not found in %s\n", DATA_PATH );
918 /* reset panels position and size */
919 /* XXX use i_width */
920 XResizeWindow( p_display, video, window.width, window.height - i_height);
921 XMoveWindow( p_display, control, 0, window.height - i_height );
922 XResizeWindow( p_display, control, window.width, i_height -1);
924 b_toolbar = 1; /* says toolbar is now shown */
928 void VlcPlugin::hideToolbar()
930 const NPWindow& window = getWindow();
931 Display *p_display = ((NPSetWindowCallbackStruct *)window.ws_info)->display;
932 Window control = getControlWindow();
933 Window video = getVideoWindow();
935 i_tb_width = i_tb_height = 0;
937 if( p_btnPlay ) XDestroyImage( p_btnPlay );
938 if( p_btnPause ) XDestroyImage( p_btnPause );
939 if( p_btnStop ) XDestroyImage( p_btnStop );
940 if( p_timeline ) XDestroyImage( p_timeline );
941 if( p_btnTime ) XDestroyImage( p_btnTime );
942 if( p_btnFullscreen ) XDestroyImage( p_btnFullscreen );
943 if( p_btnMute ) XDestroyImage( p_btnMute );
944 if( p_btnUnmute ) XDestroyImage( p_btnUnmute );
951 p_btnFullscreen = NULL;
955 /* reset panels position and size */
956 /* XXX use i_width */
957 XResizeWindow( p_display, video, window.width, window.height );
958 XMoveWindow( p_display, control, 0, window.height-1 );
959 XResizeWindow( p_display, control, window.width, 1 );
961 b_toolbar = 0; /* says toolbar is now hidden */
965 void VlcPlugin::redrawToolbar()
969 unsigned int dst_x, dst_y;
972 unsigned int i_tb_width, i_tb_height;
974 /* This method does nothing if toolbar is hidden. */
975 if( !b_toolbar || !libvlc_media_player )
978 const NPWindow& window = getWindow();
979 Window control = getControlWindow();
980 Display *p_display = ((NPSetWindowCallbackStruct *)window.ws_info)->display;
982 getToolbarSize( &i_tb_width, &i_tb_height );
985 b_mute = libvlc_audio_get_mute( libvlc_media_player );
987 gcv.foreground = BlackPixel( p_display, 0 );
988 gc = XCreateGC( p_display, control, GCForeground, &gcv );
990 XFillRectangle( p_display, control, gc,
991 0, 0, window.width, i_tb_height );
992 gcv.foreground = WhitePixel( p_display, 0 );
993 XChangeGC( p_display, gc, GCForeground, &gcv );
997 dst_y = i_tb_height >> 1; /* baseline = vertical middle */
999 if( p_btnPause && (is_playing == 1) )
1001 XPutImage( p_display, control, gc, p_btnPause, 0, 0, dst_x,
1002 dst_y - (p_btnPause->height >> 1),
1003 p_btnPause->width, p_btnPause->height );
1004 dst_x += BTN_SPACE + p_btnPause->width;
1006 else if( p_btnPlay )
1008 XPutImage( p_display, control, gc, p_btnPlay, 0, 0, dst_x,
1009 dst_y - (p_btnPlay->height >> 1),
1010 p_btnPlay->width, p_btnPlay->height );
1011 dst_x += BTN_SPACE + p_btnPlay->width;
1015 XPutImage( p_display, control, gc, p_btnStop, 0, 0, dst_x,
1016 dst_y - (p_btnStop->height >> 1),
1017 p_btnStop->width, p_btnStop->height );
1019 dst_x += BTN_SPACE + ( p_btnStop ? p_btnStop->width : 0 );
1021 if( p_btnFullscreen )
1022 XPutImage( p_display, control, gc, p_btnFullscreen, 0, 0, dst_x,
1023 dst_y - (p_btnFullscreen->height >> 1),
1024 p_btnFullscreen->width, p_btnFullscreen->height );
1026 dst_x += BTN_SPACE + ( p_btnFullscreen ? p_btnFullscreen->width : 0 );
1028 if( p_btnUnmute && b_mute )
1030 XPutImage( p_display, control, gc, p_btnUnmute, 0, 0, dst_x,
1031 dst_y - (p_btnUnmute->height >> 1),
1032 p_btnUnmute->width, p_btnUnmute->height );
1034 dst_x += BTN_SPACE + ( p_btnUnmute ? p_btnUnmute->width : 0 );
1036 else if( p_btnMute )
1038 XPutImage( p_display, control, gc, p_btnMute, 0, 0, dst_x,
1039 dst_y - (p_btnMute->height >> 1),
1040 p_btnMute->width, p_btnMute->height );
1042 dst_x += BTN_SPACE + ( p_btnMute ? p_btnMute->width : 0 );
1046 XPutImage( p_display, control, gc, p_timeline, 0, 0, dst_x,
1047 dst_y - (p_timeline->height >> 1),
1048 (window.width-(dst_x+BTN_SPACE)), p_timeline->height );
1050 /* get movie position in % */
1051 if( playlist_isplaying() )
1053 i_last_position = (int)((window.width-(dst_x+BTN_SPACE))*
1054 libvlc_media_player_get_position(libvlc_media_player));
1058 XPutImage( p_display, control, gc, p_btnTime,
1059 0, 0, (dst_x+i_last_position),
1060 dst_y - (p_btnTime->height >> 1),
1061 p_btnTime->width, p_btnTime->height );
1063 XFreeGC( p_display, gc );
1066 vlc_toolbar_clicked_t VlcPlugin::getToolbarButtonClicked( int i_xpos, int i_ypos )
1068 unsigned int i_dest = BTN_SPACE;
1070 bool b_mute = false;
1073 fprintf( stderr, "ToolbarButtonClicked:: "
1074 "trying to match (%d,%d) (%d,%d)\n",
1075 i_xpos, i_ypos, i_tb_height, i_tb_width );
1077 if( i_ypos >= i_tb_width )
1078 return clicked_Unknown;
1080 /* Note: the order of testing is dependend on the original
1081 * drawing positions of the icon buttons. Buttons are tested
1086 is_playing = playlist_isplaying();
1089 if( libvlc_media_player )
1090 b_mute = libvlc_audio_get_mute( libvlc_media_player );
1092 /* is Pause of Play button clicked */
1093 if( (is_playing != 1) &&
1094 (i_xpos >= (BTN_SPACE>>1)) &&
1095 (i_xpos <= i_dest + p_btnPlay->width + (BTN_SPACE>>1)) )
1096 return clicked_Play;
1097 else if( (i_xpos >= (BTN_SPACE>>1)) &&
1098 (i_xpos <= i_dest + p_btnPause->width) )
1099 return clicked_Pause;
1101 /* is Stop button clicked */
1102 if( is_playing != 1 )
1103 i_dest += (p_btnPlay->width + (BTN_SPACE>>1));
1105 i_dest += (p_btnPause->width + (BTN_SPACE>>1));
1107 if( (i_xpos >= i_dest) &&
1108 (i_xpos <= i_dest + p_btnStop->width + (BTN_SPACE>>1)) )
1109 return clicked_Stop;
1111 /* is Fullscreen button clicked */
1112 i_dest += (p_btnStop->width + (BTN_SPACE>>1));
1113 if( (i_xpos >= i_dest) &&
1114 (i_xpos <= i_dest + p_btnFullscreen->width + (BTN_SPACE>>1)) )
1115 return clicked_Fullscreen;
1117 /* is Mute or Unmute button clicked */
1118 i_dest += (p_btnFullscreen->width + (BTN_SPACE>>1));
1119 if( !b_mute && (i_xpos >= i_dest) &&
1120 (i_xpos <= i_dest + p_btnMute->width + (BTN_SPACE>>1)) )
1121 return clicked_Mute;
1122 else if( (i_xpos >= i_dest) &&
1123 (i_xpos <= i_dest + p_btnUnmute->width + (BTN_SPACE>>1)) )
1124 return clicked_Unmute;
1126 /* is timeline clicked */
1128 i_dest += (p_btnMute->width + (BTN_SPACE>>1));
1130 i_dest += (p_btnUnmute->width + (BTN_SPACE>>1));
1131 if( (i_xpos >= i_dest) &&
1132 (i_xpos <= i_dest + p_timeline->width + (BTN_SPACE>>1)) )
1133 return clicked_timeline;
1135 /* is time button clicked */
1136 i_dest += (p_timeline->width + (BTN_SPACE>>1));
1137 if( (i_xpos >= i_dest) &&
1138 (i_xpos <= i_dest + p_btnTime->width + (BTN_SPACE>>1)) )
1139 return clicked_Time;
1141 return clicked_Unknown;
1146 // Verifies the version of the NPAPI.
1147 // The eventListeners use a NPAPI function available
1149 bool VlcPlugin::canUseEventListener()
1151 int plugin_major, plugin_minor;
1152 int browser_major, browser_minor;
1154 NPN_Version(&plugin_major, &plugin_minor,
1155 &browser_major, &browser_minor);
1157 if (browser_minor >= 19 || browser_major > 0)