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"
46 #warning "locking not implemented for this platform"
53 /*****************************************************************************
55 *****************************************************************************/
56 static void plugin_lock_init(plugin_lock_t *lock)
61 pthread_mutex_init(&lock->mutex, NULL);
63 InitializeCriticalSection(&lock->cs);
65 #warning "locking not implemented in this platform"
69 static void plugin_lock_destroy(plugin_lock_t *lock)
74 pthread_mutex_destroy(&lock->mutex);
76 DeleteCriticalSection(&lock->cs);
78 #warning "locking not implemented in this platform"
82 static void plugin_lock(plugin_lock_t *lock)
87 pthread_mutex_lock(&lock->mutex);
89 EnterCriticalSection(&lock->cs);
91 #warning "locking not implemented in this platform"
95 static void plugin_unlock(plugin_lock_t *lock)
100 pthread_mutex_unlock(&lock->mutex);
101 #elif defined(XP_WIN)
102 LeaveCriticalSection(&lock->cs);
104 #warning "locking not implemented in this platform"
108 /*****************************************************************************
109 * VlcPlugin constructor and destructor
110 *****************************************************************************/
111 #if (((NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR) < 20)
112 VlcPlugin::VlcPlugin( NPP instance, uint16 mode ) :
114 VlcPlugin::VlcPlugin( NPP instance, uint16_t mode ) :
123 libvlc_instance(NULL),
124 libvlc_media_list(NULL),
125 libvlc_media_player(NULL),
133 ,i_width((unsigned)-1)
134 ,i_height((unsigned)-1)
143 ,p_btnFullscreen(NULL)
148 memset(&npwindow, 0, sizeof(NPWindow));
150 memset(&npvideo, 0, sizeof(Window));
151 memset(&npcontrol, 0, sizeof(Window));
155 static bool boolValue(const char *value) {
156 return ( !strcmp(value, "1") ||
157 !strcasecmp(value, "true") ||
158 !strcasecmp(value, "yes") );
161 bool EventObj::init()
163 plugin_lock_init(&lock);
167 EventObj::~EventObj()
169 plugin_lock_destroy(&lock);
172 void EventObj::deliver(NPP browser)
179 for( ev_l::iterator i=_elist.begin();i!=_elist.end();++i )
181 libvlc_event_type_t event = *i;
182 STRINGZ_TO_NPVARIANT(libvlc_event_type_name(event), params[0]);
184 // Invalid events aren't supposed to be queued up.
185 // if( !have_event(event) ) continue;
187 for( lr_l::iterator j=_llist.begin();j!=_llist.end();++j )
191 NPN_InvokeDefault(browser, j->listener(), params, 1, &result);
192 NPN_ReleaseVariantValue(&result);
198 plugin_unlock(&lock);
201 void VlcPlugin::eventAsync(void *param)
203 VlcPlugin *plugin = (VlcPlugin*)param;
204 plugin->events.deliver(plugin->getBrowser());
207 void EventObj::callback(const libvlc_event_t* event)
211 if( have_event(event->type) )
212 _elist.push_back(event->type);
214 plugin_unlock(&lock);
217 void VlcPlugin::event_callback(const libvlc_event_t* event, void *param)
219 VlcPlugin *plugin = (VlcPlugin*)param;
221 plugin->events.callback(event);
222 NPN_PluginThreadAsyncCall(plugin->getBrowser(), eventAsync, plugin);
224 #warning NPN_PluginThreadAsyncCall not implemented yet.
225 printf("No NPN_PluginThreadAsyncCall(), doing nothing.");
229 inline EventObj::event_t EventObj::find_event(const char *s) const
232 for(i=0;i<maxbit();++i)
233 if(!strcmp(s,libvlc_event_type_name(i)))
238 bool EventObj::insert(const NPString &s, NPObject *l, bool b)
240 event_t e = find_event(s.UTF8Characters);
244 if( !have_event(e) && !ask_for_event(e) )
248 for(i=_llist.begin();i!=_llist.end();++i)
249 if(i->listener()==l && i->bubble()==b)
252 if( i == _llist.end() ) {
253 _llist.push_back(Listener(e,l,b));
263 bool EventObj::remove(const NPString &s, NPObject *l, bool b)
265 event_t e = find_event(s.UTF8Characters);
266 if( e>=maxbit() || !get(e) )
270 for(lr_l::iterator i=_llist.begin();i!=_llist.end();)
272 if(i->listener()!=l || i->bubble()!=b)
292 void EventObj::hook_manager(libvlc_event_manager_t *em,
293 libvlc_callback_t cb, void *udata)
295 _em = em; _cb = cb; _ud = udata;
298 for(size_t i=0;i<maxbit();++i)
300 libvlc_event_attach(_em, i, _cb, _ud);
303 void EventObj::unhook_manager()
307 for(size_t i=0;i<maxbit();++i)
309 libvlc_event_detach(_em, i, _cb, _ud);
313 bool EventObj::ask_for_event(event_t e)
315 return _em?0==libvlc_event_attach(_em, e, _cb, _ud):false;
319 void EventObj::unask_for_event(event_t e)
321 if(_em) libvlc_event_detach(_em, e, _cb, _ud);
325 NPError VlcPlugin::init(int argc, char* const argn[], char* const argv[])
327 /* prepare VLC command line */
328 const char *ppsz_argv[32];
332 ppsz_argv[ppsz_argc++] = "--no-plugins-cache";
335 /* locate VLC module path */
337 ppsz_argv[ppsz_argc++] = "--plugin-path=/Library/Internet\\ Plug-Ins/VLC\\ Plugin.plugin/Contents/MacOS/modules";
338 ppsz_argv[ppsz_argc++] = "--vout=minimal_macosx";
339 #elif defined(XP_WIN)
341 DWORD i_type, i_data = MAX_PATH + 1;
342 char p_data[MAX_PATH + 1];
343 if( RegOpenKeyEx( HKEY_LOCAL_MACHINE, "Software\\VideoLAN\\VLC",
344 0, KEY_READ, &h_key ) == ERROR_SUCCESS )
346 if( RegQueryValueEx( h_key, "InstallDir", 0, &i_type,
347 (LPBYTE)p_data, &i_data ) == ERROR_SUCCESS )
349 if( i_type == REG_SZ )
351 strcat( p_data, "\\plugins" );
352 ppsz_argv[ppsz_argc++] = "--plugin-path";
353 ppsz_argv[ppsz_argc++] = p_data;
356 RegCloseKey( h_key );
358 ppsz_argv[ppsz_argc++] = "--no-one-instance";
360 #endif /* XP_MACOSX */
362 /* common settings */
363 ppsz_argv[ppsz_argc++] = "-vv";
364 ppsz_argv[ppsz_argc++] = "--no-stats";
365 ppsz_argv[ppsz_argc++] = "--no-media-library";
366 ppsz_argv[ppsz_argc++] = "--intf=dummy";
367 ppsz_argv[ppsz_argc++] = "--no-video-title-show";
369 const char *progid = NULL;
371 /* parse plugin arguments */
372 for( int i = 0; (i < argc) && (ppsz_argc < 32); i++ )
374 /* fprintf(stderr, "argn=%s, argv=%s\n", argn[i], argv[i]); */
376 if( !strcmp( argn[i], "target" )
377 || !strcmp( argn[i], "mrl")
378 || !strcmp( argn[i], "filename")
379 || !strcmp( argn[i], "src") )
381 psz_target = argv[i];
383 else if( !strcmp( argn[i], "text" ) )
386 psz_text = strdup( argv[i] );
388 else if( !strcmp( argn[i], "autoplay")
389 || !strcmp( argn[i], "autostart") )
391 b_autoplay = boolValue(argv[i]);
393 else if( !strcmp( argn[i], "fullscreen" ) )
395 if( boolValue(argv[i]) )
397 ppsz_argv[ppsz_argc++] = "--fullscreen";
401 ppsz_argv[ppsz_argc++] = "--no-fullscreen";
404 else if( !strcmp( argn[i], "mute" ) )
406 if( boolValue(argv[i]) )
408 ppsz_argv[ppsz_argc++] = "--volume=0";
411 else if( !strcmp( argn[i], "loop")
412 || !strcmp( argn[i], "autoloop") )
414 if( boolValue(argv[i]) )
416 ppsz_argv[ppsz_argc++] = "--loop";
420 ppsz_argv[ppsz_argc++] = "--no-loop";
423 else if( !strcmp( argn[i], "version")
424 || !strcmp( argn[i], "progid") )
428 else if( !strcmp( argn[i], "toolbar" ) )
430 /* FIXME: Remove this when toolbar functionality has been implemented on
431 * MacOS X and Win32 for Firefox/Mozilla/Safari. */
433 b_toolbar = boolValue(argv[i]);
438 libvlc_instance = libvlc_new(ppsz_argc, ppsz_argv);
439 if( !libvlc_instance )
440 return NPERR_GENERIC_ERROR;
441 libvlc_media_list = libvlc_media_list_new(libvlc_instance);
444 ** fetch plugin base URL, which is the URL of the page containing the plugin
445 ** this URL is used for making absolute URL from relative URL that may be
446 ** passed as an MRL argument
448 NPObject *plugin = NULL;
450 if( NPERR_NO_ERROR == NPN_GetValue(p_browser, NPNVWindowNPObject, &plugin) )
453 ** is there a better way to get that info ?
455 static const char docLocHref[] = "document.location.href";
459 script.UTF8Characters = docLocHref;
460 script.UTF8Length = sizeof(docLocHref)-1;
462 if( NPN_Evaluate(p_browser, plugin, &script, &result) )
464 if( NPVARIANT_IS_STRING(result) )
466 NPString &location = NPVARIANT_TO_STRING(result);
468 psz_baseURL = (char *) malloc(location.UTF8Length+1);
471 strncpy(psz_baseURL, location.UTF8Characters, location.UTF8Length);
472 psz_baseURL[location.UTF8Length] = '\0';
475 NPN_ReleaseVariantValue(&result);
477 NPN_ReleaseObject(plugin);
482 // get absolute URL from src
483 char *psz_absurl = getAbsoluteURL(psz_target);
484 psz_target = psz_absurl ? psz_absurl : strdup(psz_target);
487 /* assign plugin script root class */
489 p_scriptClass = RuntimeNPClass<LibvlcRootNPObject>::getClass();
492 return NPERR_GENERIC_ERROR;
494 return NPERR_NO_ERROR;
497 VlcPlugin::~VlcPlugin()
503 if( libvlc_media_player )
505 if( playlist_isplaying() )
507 events.unhook_manager();
508 libvlc_media_player_release( libvlc_media_player );
510 if( libvlc_media_list )
511 libvlc_media_list_release( libvlc_media_list );
512 if( libvlc_instance )
513 libvlc_release(libvlc_instance);
516 /*****************************************************************************
517 * VlcPlugin playlist replacement methods
518 *****************************************************************************/
519 void VlcPlugin::set_player_window()
522 libvlc_media_player_set_xwindow(libvlc_media_player,
523 (uint32_t)getVideoWindow());
526 // XXX FIXME insert appropriate call here
529 libvlc_media_player_set_hwnd(libvlc_media_player,
534 int VlcPlugin::playlist_add( const char *mrl )
537 libvlc_media_t *p_m = libvlc_media_new_location(libvlc_instance,mrl);
540 assert( libvlc_media_list );
541 libvlc_media_list_lock(libvlc_media_list);
542 if( !libvlc_media_list_add_media(libvlc_media_list,p_m) )
543 item = libvlc_media_list_count(libvlc_media_list)-1;
544 libvlc_media_list_unlock(libvlc_media_list);
546 libvlc_media_release(p_m);
551 int VlcPlugin::playlist_add_extended_untrusted( const char *mrl, const char *name,
552 int optc, const char **optv )
557 assert( libvlc_media_list );
559 p_m = libvlc_media_new_location(libvlc_instance, mrl);
563 for( int i = 0; i < optc; ++i )
564 libvlc_media_add_option_flag(p_m, optv[i], libvlc_media_option_unique);
566 libvlc_media_list_lock(libvlc_media_list);
567 if( !libvlc_media_list_add_media(libvlc_media_list,p_m) )
568 item = libvlc_media_list_count(libvlc_media_list)-1;
569 libvlc_media_list_unlock(libvlc_media_list);
570 libvlc_media_release(p_m);
575 bool VlcPlugin::playlist_select( int idx )
577 libvlc_media_t *p_m = NULL;
579 assert( libvlc_media_list );
581 libvlc_media_list_lock(libvlc_media_list);
583 int count = libvlc_media_list_count(libvlc_media_list);
584 if( idx<0||idx>=count )
587 playlist_index = idx;
589 p_m = libvlc_media_list_item_at_index(libvlc_media_list,playlist_index);
590 libvlc_media_list_unlock(libvlc_media_list);
595 if( libvlc_media_player )
597 if( playlist_isplaying() )
599 events.unhook_manager();
600 libvlc_media_player_release( libvlc_media_player );
601 libvlc_media_player = NULL;
604 libvlc_media_player = libvlc_media_player_new_from_media(p_m);
605 if( libvlc_media_player )
609 libvlc_media_player_event_manager(libvlc_media_player),
610 event_callback, this);
613 libvlc_media_release( p_m );
617 libvlc_media_list_unlock(libvlc_media_list);
621 int VlcPlugin::playlist_delete_item( int idx )
623 if( !libvlc_media_list )
625 libvlc_media_list_lock(libvlc_media_list);
626 int ret = libvlc_media_list_remove_index(libvlc_media_list,idx);
627 libvlc_media_list_unlock(libvlc_media_list);
631 void VlcPlugin::playlist_clear()
633 if( libvlc_media_list )
634 libvlc_media_list_release(libvlc_media_list);
635 libvlc_media_list = libvlc_media_list_new(getVLC());
638 int VlcPlugin::playlist_count()
641 if( !libvlc_media_list )
643 libvlc_media_list_lock(libvlc_media_list);
644 items_count = libvlc_media_list_count(libvlc_media_list);
645 libvlc_media_list_unlock(libvlc_media_list);
649 void VlcPlugin::toggle_fullscreen()
651 if( playlist_isplaying() )
652 libvlc_toggle_fullscreen(libvlc_media_player);
655 void VlcPlugin::set_fullscreen( int yes )
657 if( playlist_isplaying() )
658 libvlc_set_fullscreen(libvlc_media_player,yes);
661 int VlcPlugin::get_fullscreen()
664 if( playlist_isplaying() )
665 r = libvlc_get_fullscreen(libvlc_media_player);
669 bool VlcPlugin::player_has_vout()
672 if( playlist_isplaying() )
673 r = libvlc_media_player_has_vout(libvlc_media_player);
677 /*****************************************************************************
679 *****************************************************************************/
681 char *VlcPlugin::getAbsoluteURL(const char *url)
685 // check whether URL is already absolute
686 const char *end=strchr(url, ':');
687 if( (NULL != end) && (end != url) )
689 // validate protocol header
690 const char *start = url;
695 while( start != end )
702 || ('/' == c)) ) /* VLC uses / to allow user to specify a demuxer */
703 // not valid protocol header, assume relative URL
707 /* we have a protocol header, therefore URL is absolute */
710 // not a valid protocol header, assume relative URL
717 size_t baseLen = strlen(psz_baseURL);
718 char *href = (char *) malloc(baseLen+strlen(url)+1);
721 /* prepend base URL */
722 memcpy(href, psz_baseURL, baseLen+1);
725 ** relative url could be empty,
726 ** in which case return base URL
732 ** locate pathname part of base URL
735 /* skip over protocol part */
736 char *pathstart = strchr(href, ':');
737 char *pathend = href+baseLen;
740 if( '/' == *(++pathstart) )
742 if( '/' == *(++pathstart) )
747 /* skip over host part */
748 pathstart = strchr(pathstart, '/');
751 // no path, add a / past end of url (over '\0')
758 /* baseURL is just a UNIX path */
761 /* baseURL is not an absolute path */
768 /* relative URL made of an absolute path ? */
771 /* replace path completely */
772 strcpy(pathstart, url);
776 /* find last path component and replace it */
777 while( '/' != *pathend)
781 ** if relative url path starts with one or more '../',
782 ** factor them out of href so that we return a
785 while( pathend != pathstart )
793 /* relative url is just '.' */
799 /* relative url starts with './' */
808 /* relative url is '..' */
814 /* relative url starts with '../' */
822 while( '/' != *pathend );
824 /* skip over '/' separator */
826 /* concatenate remaining base URL and relative URL */
827 strcpy(pathend, url);
836 int VlcPlugin::setSize(unsigned width, unsigned height)
838 int diff = (width != i_width) || (height != i_height);
847 #define BTN_SPACE ((unsigned int)4)
848 void VlcPlugin::showToolbar()
850 const NPWindow& window = getWindow();
851 Window control = getControlWindow();
852 Window video = getVideoWindow();
853 Display *p_display = ((NPSetWindowCallbackStruct *)window.ws_info)->display;
854 unsigned int i_height = 0, i_width = BTN_SPACE;
858 XpmReadFileToImage( p_display, DATA_PATH "/mozilla/play.xpm",
859 &p_btnPlay, NULL, NULL);
862 i_height = __MAX( i_height, p_btnPlay->height );
865 XpmReadFileToImage( p_display, DATA_PATH "/mozilla/pause.xpm",
866 &p_btnPause, NULL, NULL);
869 i_height = __MAX( i_height, p_btnPause->height );
871 i_width += __MAX( p_btnPause->width, p_btnPlay->width );
874 XpmReadFileToImage( p_display, DATA_PATH "/mozilla/stop.xpm",
875 &p_btnStop, NULL, NULL );
878 i_height = __MAX( i_height, p_btnStop->height );
879 i_width += BTN_SPACE + p_btnStop->width;
882 XpmReadFileToImage( p_display, DATA_PATH "/mozilla/time_line.xpm",
883 &p_timeline, NULL, NULL);
886 i_height = __MAX( i_height, p_timeline->height );
887 i_width += BTN_SPACE + p_timeline->width;
890 XpmReadFileToImage( p_display, DATA_PATH "/mozilla/time_icon.xpm",
891 &p_btnTime, NULL, NULL);
894 i_height = __MAX( i_height, p_btnTime->height );
895 i_width += BTN_SPACE + p_btnTime->width;
897 if( !p_btnFullscreen )
898 XpmReadFileToImage( p_display, DATA_PATH "/mozilla/fullscreen.xpm",
899 &p_btnFullscreen, NULL, NULL);
900 if( p_btnFullscreen )
902 i_height = __MAX( i_height, p_btnFullscreen->height );
903 i_width += BTN_SPACE + p_btnFullscreen->width;
906 XpmReadFileToImage( p_display, DATA_PATH "/mozilla/volume_max.xpm",
907 &p_btnMute, NULL, NULL);
910 i_height = __MAX( i_height, p_btnMute->height );
913 XpmReadFileToImage( p_display, DATA_PATH "/mozilla/volume_mute.xpm",
914 &p_btnUnmute, NULL, NULL);
917 i_height = __MAX( i_height, p_btnUnmute->height );
919 i_width += BTN_SPACE + __MAX( p_btnUnmute->width, p_btnMute->width );
921 setToolbarSize( i_width, i_height );
923 if( !p_btnPlay || !p_btnPause || !p_btnStop || !p_timeline ||
924 !p_btnTime || !p_btnFullscreen || !p_btnMute || !p_btnUnmute )
925 fprintf(stderr, "Error: some button images not found in %s\n", DATA_PATH );
927 /* reset panels position and size */
928 /* XXX use i_width */
929 XResizeWindow( p_display, video, window.width, window.height - i_height);
930 XMoveWindow( p_display, control, 0, window.height - i_height );
931 XResizeWindow( p_display, control, window.width, i_height -1);
933 b_toolbar = 1; /* says toolbar is now shown */
937 void VlcPlugin::hideToolbar()
939 const NPWindow& window = getWindow();
940 Display *p_display = ((NPSetWindowCallbackStruct *)window.ws_info)->display;
941 Window control = getControlWindow();
942 Window video = getVideoWindow();
944 i_tb_width = i_tb_height = 0;
946 if( p_btnPlay ) XDestroyImage( p_btnPlay );
947 if( p_btnPause ) XDestroyImage( p_btnPause );
948 if( p_btnStop ) XDestroyImage( p_btnStop );
949 if( p_timeline ) XDestroyImage( p_timeline );
950 if( p_btnTime ) XDestroyImage( p_btnTime );
951 if( p_btnFullscreen ) XDestroyImage( p_btnFullscreen );
952 if( p_btnMute ) XDestroyImage( p_btnMute );
953 if( p_btnUnmute ) XDestroyImage( p_btnUnmute );
960 p_btnFullscreen = NULL;
964 /* reset panels position and size */
965 /* XXX use i_width */
966 XResizeWindow( p_display, video, window.width, window.height );
967 XMoveWindow( p_display, control, 0, window.height-1 );
968 XResizeWindow( p_display, control, window.width, 1 );
970 b_toolbar = 0; /* says toolbar is now hidden */
974 void VlcPlugin::redrawToolbar()
978 unsigned int dst_x, dst_y;
981 unsigned int i_tb_width, i_tb_height;
983 /* This method does nothing if toolbar is hidden. */
984 if( !b_toolbar || !libvlc_media_player )
987 const NPWindow& window = getWindow();
988 Window control = getControlWindow();
989 Display *p_display = ((NPSetWindowCallbackStruct *)window.ws_info)->display;
991 getToolbarSize( &i_tb_width, &i_tb_height );
994 b_mute = libvlc_audio_get_mute( libvlc_media_player );
996 gcv.foreground = BlackPixel( p_display, 0 );
997 gc = XCreateGC( p_display, control, GCForeground, &gcv );
999 XFillRectangle( p_display, control, gc,
1000 0, 0, window.width, i_tb_height );
1001 gcv.foreground = WhitePixel( p_display, 0 );
1002 XChangeGC( p_display, gc, GCForeground, &gcv );
1004 /* position icons */
1006 dst_y = i_tb_height >> 1; /* baseline = vertical middle */
1008 if( p_btnPause && (is_playing == 1) )
1010 XPutImage( p_display, control, gc, p_btnPause, 0, 0, dst_x,
1011 dst_y - (p_btnPause->height >> 1),
1012 p_btnPause->width, p_btnPause->height );
1013 dst_x += BTN_SPACE + p_btnPause->width;
1015 else if( p_btnPlay )
1017 XPutImage( p_display, control, gc, p_btnPlay, 0, 0, dst_x,
1018 dst_y - (p_btnPlay->height >> 1),
1019 p_btnPlay->width, p_btnPlay->height );
1020 dst_x += BTN_SPACE + p_btnPlay->width;
1024 XPutImage( p_display, control, gc, p_btnStop, 0, 0, dst_x,
1025 dst_y - (p_btnStop->height >> 1),
1026 p_btnStop->width, p_btnStop->height );
1028 dst_x += BTN_SPACE + ( p_btnStop ? p_btnStop->width : 0 );
1030 if( p_btnFullscreen )
1031 XPutImage( p_display, control, gc, p_btnFullscreen, 0, 0, dst_x,
1032 dst_y - (p_btnFullscreen->height >> 1),
1033 p_btnFullscreen->width, p_btnFullscreen->height );
1035 dst_x += BTN_SPACE + ( p_btnFullscreen ? p_btnFullscreen->width : 0 );
1037 if( p_btnUnmute && b_mute )
1039 XPutImage( p_display, control, gc, p_btnUnmute, 0, 0, dst_x,
1040 dst_y - (p_btnUnmute->height >> 1),
1041 p_btnUnmute->width, p_btnUnmute->height );
1043 dst_x += BTN_SPACE + ( p_btnUnmute ? p_btnUnmute->width : 0 );
1045 else if( p_btnMute )
1047 XPutImage( p_display, control, gc, p_btnMute, 0, 0, dst_x,
1048 dst_y - (p_btnMute->height >> 1),
1049 p_btnMute->width, p_btnMute->height );
1051 dst_x += BTN_SPACE + ( p_btnMute ? p_btnMute->width : 0 );
1055 XPutImage( p_display, control, gc, p_timeline, 0, 0, dst_x,
1056 dst_y - (p_timeline->height >> 1),
1057 (window.width-(dst_x+BTN_SPACE)), p_timeline->height );
1059 /* get movie position in % */
1060 if( playlist_isplaying() )
1062 i_last_position = (int)((window.width-(dst_x+BTN_SPACE))*
1063 libvlc_media_player_get_position(libvlc_media_player));
1067 XPutImage( p_display, control, gc, p_btnTime,
1068 0, 0, (dst_x+i_last_position),
1069 dst_y - (p_btnTime->height >> 1),
1070 p_btnTime->width, p_btnTime->height );
1072 XFreeGC( p_display, gc );
1075 vlc_toolbar_clicked_t VlcPlugin::getToolbarButtonClicked( int i_xpos, int i_ypos )
1077 unsigned int i_dest = BTN_SPACE;
1079 bool b_mute = false;
1082 fprintf( stderr, "ToolbarButtonClicked:: "
1083 "trying to match (%d,%d) (%d,%d)\n",
1084 i_xpos, i_ypos, i_tb_height, i_tb_width );
1086 if( i_ypos >= i_tb_width )
1087 return clicked_Unknown;
1089 /* Note: the order of testing is dependend on the original
1090 * drawing positions of the icon buttons. Buttons are tested
1095 is_playing = playlist_isplaying();
1098 if( libvlc_media_player )
1099 b_mute = libvlc_audio_get_mute( libvlc_media_player );
1101 /* is Pause of Play button clicked */
1102 if( (is_playing != 1) &&
1103 (i_xpos >= (BTN_SPACE>>1)) &&
1104 (i_xpos <= i_dest + p_btnPlay->width + (BTN_SPACE>>1)) )
1105 return clicked_Play;
1106 else if( (i_xpos >= (BTN_SPACE>>1)) &&
1107 (i_xpos <= i_dest + p_btnPause->width) )
1108 return clicked_Pause;
1110 /* is Stop button clicked */
1111 if( is_playing != 1 )
1112 i_dest += (p_btnPlay->width + (BTN_SPACE>>1));
1114 i_dest += (p_btnPause->width + (BTN_SPACE>>1));
1116 if( (i_xpos >= i_dest) &&
1117 (i_xpos <= i_dest + p_btnStop->width + (BTN_SPACE>>1)) )
1118 return clicked_Stop;
1120 /* is Fullscreen button clicked */
1121 i_dest += (p_btnStop->width + (BTN_SPACE>>1));
1122 if( (i_xpos >= i_dest) &&
1123 (i_xpos <= i_dest + p_btnFullscreen->width + (BTN_SPACE>>1)) )
1124 return clicked_Fullscreen;
1126 /* is Mute or Unmute button clicked */
1127 i_dest += (p_btnFullscreen->width + (BTN_SPACE>>1));
1128 if( !b_mute && (i_xpos >= i_dest) &&
1129 (i_xpos <= i_dest + p_btnMute->width + (BTN_SPACE>>1)) )
1130 return clicked_Mute;
1131 else if( (i_xpos >= i_dest) &&
1132 (i_xpos <= i_dest + p_btnUnmute->width + (BTN_SPACE>>1)) )
1133 return clicked_Unmute;
1135 /* is timeline clicked */
1137 i_dest += (p_btnMute->width + (BTN_SPACE>>1));
1139 i_dest += (p_btnUnmute->width + (BTN_SPACE>>1));
1140 if( (i_xpos >= i_dest) &&
1141 (i_xpos <= i_dest + p_timeline->width + (BTN_SPACE>>1)) )
1142 return clicked_timeline;
1144 /* is time button clicked */
1145 i_dest += (p_timeline->width + (BTN_SPACE>>1));
1146 if( (i_xpos >= i_dest) &&
1147 (i_xpos <= i_dest + p_btnTime->width + (BTN_SPACE>>1)) )
1148 return clicked_Time;
1150 return clicked_Unknown;
1155 // Verifies the version of the NPAPI.
1156 // The eventListeners use a NPAPI function available
1158 bool VlcPlugin::canUseEventListener()
1160 int plugin_major, plugin_minor;
1161 int browser_major, browser_minor;
1163 NPN_Version(&plugin_major, &plugin_minor,
1164 &browser_major, &browser_minor);
1166 if (browser_minor >= 19 || browser_major > 0)