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 #include "vlcplugin.h"
32 #include "control/npolibvlc.h"
42 #warning "locking not implemented for this platform"
49 /*****************************************************************************
51 *****************************************************************************/
52 static void plugin_lock_init(plugin_lock_t *lock)
57 pthread_mutex_init(&lock->mutex, NULL);
59 InitializeCriticalSection(&lock->cs);
61 #warning "locking not implemented in this platform"
65 static void plugin_lock_destroy(plugin_lock_t *lock)
70 pthread_mutex_destroy(&lock->mutex);
72 DeleteCriticalSection(&lock->cs);
74 #warning "locking not implemented in this platform"
78 static void plugin_lock(plugin_lock_t *lock)
83 pthread_mutex_lock(&lock->mutex);
85 EnterCriticalSection(&lock->cs);
87 #warning "locking not implemented in this platform"
91 static void plugin_unlock(plugin_lock_t *lock)
96 pthread_mutex_unlock(&lock->mutex);
98 LeaveCriticalSection(&lock->cs);
100 #warning "locking not implemented in this platform"
104 /*****************************************************************************
105 * VlcPlugin constructor and destructor
106 *****************************************************************************/
107 #if (((NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR) < 20)
108 VlcPlugin::VlcPlugin( NPP instance, uint16 mode ) :
110 VlcPlugin::VlcPlugin( NPP instance, uint16_t mode ) :
119 libvlc_instance(NULL),
120 libvlc_media_list(NULL),
121 libvlc_media_player(NULL),
129 ,i_width((unsigned)-1)
130 ,i_height((unsigned)-1)
139 ,p_btnFullscreen(NULL)
144 memset(&npwindow, 0, sizeof(NPWindow));
146 memset(&npvideo, 0, sizeof(Window));
147 memset(&npcontrol, 0, sizeof(Window));
151 static bool boolValue(const char *value) {
152 return ( !strcmp(value, "1") ||
153 !strcasecmp(value, "true") ||
154 !strcasecmp(value, "yes") );
157 bool EventObj::init()
159 plugin_lock_init(&lock);
163 EventObj::~EventObj()
165 plugin_lock_destroy(&lock);
168 void EventObj::deliver(NPP browser)
175 for( ev_l::iterator i=_elist.begin();i!=_elist.end();++i )
177 libvlc_event_type_t event = *i;
178 STRINGZ_TO_NPVARIANT(libvlc_event_type_name(event), params[0]);
180 // Invalid events aren't supposed to be queued up.
181 // if( !have_event(event) ) continue;
183 for( lr_l::iterator j=_llist.begin();j!=_llist.end();++j )
187 NPN_InvokeDefault(browser, j->listener(), params, 1, &result);
188 NPN_ReleaseVariantValue(&result);
194 plugin_unlock(&lock);
197 void VlcPlugin::eventAsync(void *param)
199 VlcPlugin *plugin = (VlcPlugin*)param;
200 plugin->events.deliver(plugin->getBrowser());
203 void EventObj::callback(const libvlc_event_t* event)
207 if( have_event(event->type) )
208 _elist.push_back(event->type);
210 plugin_unlock(&lock);
213 void VlcPlugin::event_callback(const libvlc_event_t* event, void *param)
215 VlcPlugin *plugin = (VlcPlugin*)param;
217 plugin->events.callback(event);
218 NPN_PluginThreadAsyncCall(plugin->getBrowser(), eventAsync, plugin);
220 #warning NPN_PluginThreadAsyncCall not implemented yet.
221 printf("No NPN_PluginThreadAsyncCall(), doing nothing.");
225 inline EventObj::event_t EventObj::find_event(const char *s) const
228 for(i=0;i<maxbit();++i)
229 if(!strcmp(s,libvlc_event_type_name(i)))
234 bool EventObj::insert(const NPString &s, NPObject *l, bool b)
236 event_t e = find_event(s.UTF8Characters);
240 if( !have_event(e) && !ask_for_event(e) )
244 for(i=_llist.begin();i!=_llist.end();++i)
245 if(i->listener()==l && i->bubble()==b)
248 if( i == _llist.end() ) {
249 _llist.push_back(Listener(e,l,b));
259 bool EventObj::remove(const NPString &s, NPObject *l, bool b)
261 event_t e = find_event(s.UTF8Characters);
262 if( e>=maxbit() || !get(e) )
266 for(lr_l::iterator i=_llist.begin();i!=_llist.end();)
268 if(i->listener()!=l || i->bubble()!=b)
288 void EventObj::hook_manager(libvlc_event_manager_t *em,
289 libvlc_callback_t cb, void *udata)
291 _em = em; _cb = cb; _ud = udata;
294 for(size_t i=0;i<maxbit();++i)
296 libvlc_event_attach(_em, i, _cb, _ud);
299 void EventObj::unhook_manager()
303 for(size_t i=0;i<maxbit();++i)
305 libvlc_event_detach(_em, i, _cb, _ud);
309 bool EventObj::ask_for_event(event_t e)
311 return _em?0==libvlc_event_attach(_em, e, _cb, _ud):false;
315 void EventObj::unask_for_event(event_t e)
317 if(_em) libvlc_event_detach(_em, e, _cb, _ud);
321 NPError VlcPlugin::init(int argc, char* const argn[], char* const argv[])
323 /* prepare VLC command line */
324 const char *ppsz_argv[32];
328 ppsz_argv[ppsz_argc++] = "--no-plugins-cache";
331 /* locate VLC module path */
333 ppsz_argv[ppsz_argc++] = "--plugin-path=/Library/Internet\\ Plug-Ins/VLC\\ Plugin.plugin/Contents/MacOS/modules";
334 ppsz_argv[ppsz_argc++] = "--vout=minimal_macosx";
335 #elif defined(XP_WIN)
337 DWORD i_type, i_data = MAX_PATH + 1;
338 char p_data[MAX_PATH + 1];
339 if( RegOpenKeyEx( HKEY_LOCAL_MACHINE, "Software\\VideoLAN\\VLC",
340 0, KEY_READ, &h_key ) == ERROR_SUCCESS )
342 if( RegQueryValueEx( h_key, "InstallDir", 0, &i_type,
343 (LPBYTE)p_data, &i_data ) == ERROR_SUCCESS )
345 if( i_type == REG_SZ )
347 strcat( p_data, "\\plugins" );
348 ppsz_argv[ppsz_argc++] = "--plugin-path";
349 ppsz_argv[ppsz_argc++] = p_data;
352 RegCloseKey( h_key );
354 ppsz_argv[ppsz_argc++] = "--no-one-instance";
356 #endif /* XP_MACOSX */
358 /* common settings */
359 ppsz_argv[ppsz_argc++] = "-vv";
360 ppsz_argv[ppsz_argc++] = "--no-stats";
361 ppsz_argv[ppsz_argc++] = "--no-media-library";
362 ppsz_argv[ppsz_argc++] = "--intf=dummy";
363 ppsz_argv[ppsz_argc++] = "--no-video-title-show";
365 const char *progid = NULL;
367 /* parse plugin arguments */
368 for( int i = 0; (i < argc) && (ppsz_argc < 32); i++ )
370 /* fprintf(stderr, "argn=%s, argv=%s\n", argn[i], argv[i]); */
372 if( !strcmp( argn[i], "target" )
373 || !strcmp( argn[i], "mrl")
374 || !strcmp( argn[i], "filename")
375 || !strcmp( argn[i], "src") )
377 psz_target = argv[i];
379 else if( !strcmp( argn[i], "text" ) )
382 psz_text = strdup( argv[i] );
384 else if( !strcmp( argn[i], "autoplay")
385 || !strcmp( argn[i], "autostart") )
387 b_autoplay = boolValue(argv[i]);
389 else if( !strcmp( argn[i], "fullscreen" ) )
391 if( boolValue(argv[i]) )
393 ppsz_argv[ppsz_argc++] = "--fullscreen";
397 ppsz_argv[ppsz_argc++] = "--no-fullscreen";
400 else if( !strcmp( argn[i], "mute" ) )
402 if( boolValue(argv[i]) )
404 ppsz_argv[ppsz_argc++] = "--volume=0";
407 else if( !strcmp( argn[i], "loop")
408 || !strcmp( argn[i], "autoloop") )
410 if( boolValue(argv[i]) )
412 ppsz_argv[ppsz_argc++] = "--loop";
416 ppsz_argv[ppsz_argc++] = "--no-loop";
419 else if( !strcmp( argn[i], "version")
420 || !strcmp( argn[i], "progid") )
424 else if( !strcmp( argn[i], "toolbar" ) )
426 /* FIXME: Remove this when toolbar functionality has been implemented on
427 * MacOS X and Win32 for Firefox/Mozilla/Safari. */
429 b_toolbar = boolValue(argv[i]);
434 libvlc_instance = libvlc_new(ppsz_argc, ppsz_argv);
435 if( !libvlc_instance )
436 return NPERR_GENERIC_ERROR;
437 libvlc_media_list = libvlc_media_list_new(libvlc_instance);
440 ** fetch plugin base URL, which is the URL of the page containing the plugin
441 ** this URL is used for making absolute URL from relative URL that may be
442 ** passed as an MRL argument
444 NPObject *plugin = NULL;
446 if( NPERR_NO_ERROR == NPN_GetValue(p_browser, NPNVWindowNPObject, &plugin) )
449 ** is there a better way to get that info ?
451 static const char docLocHref[] = "document.location.href";
455 script.UTF8Characters = docLocHref;
456 script.UTF8Length = sizeof(docLocHref)-1;
458 if( NPN_Evaluate(p_browser, plugin, &script, &result) )
460 if( NPVARIANT_IS_STRING(result) )
462 NPString &location = NPVARIANT_TO_STRING(result);
464 psz_baseURL = (char *) malloc(location.UTF8Length+1);
467 strncpy(psz_baseURL, location.UTF8Characters, location.UTF8Length);
468 psz_baseURL[location.UTF8Length] = '\0';
471 NPN_ReleaseVariantValue(&result);
473 NPN_ReleaseObject(plugin);
478 // get absolute URL from src
479 char *psz_absurl = getAbsoluteURL(psz_target);
480 psz_target = psz_absurl ? psz_absurl : strdup(psz_target);
483 /* assign plugin script root class */
485 p_scriptClass = RuntimeNPClass<LibvlcRootNPObject>::getClass();
488 return NPERR_GENERIC_ERROR;
490 return NPERR_NO_ERROR;
493 VlcPlugin::~VlcPlugin()
499 if( libvlc_media_player )
501 if( playlist_isplaying() )
503 events.unhook_manager();
504 libvlc_media_player_release( libvlc_media_player );
506 if( libvlc_media_list )
507 libvlc_media_list_release( libvlc_media_list );
508 if( libvlc_instance )
509 libvlc_release(libvlc_instance);
512 /*****************************************************************************
513 * VlcPlugin playlist replacement methods
514 *****************************************************************************/
515 void VlcPlugin::set_player_window()
518 libvlc_media_player_set_xwindow(libvlc_media_player,
519 (uint32_t)getVideoWindow());
522 // XXX FIXME insert appropriate call here
525 libvlc_media_player_set_hwnd(libvlc_media_player,
530 int VlcPlugin::playlist_add( const char *mrl )
533 libvlc_media_t *p_m = libvlc_media_new_location(libvlc_instance,mrl);
536 assert( libvlc_media_list );
537 libvlc_media_list_lock(libvlc_media_list);
538 if( !libvlc_media_list_add_media(libvlc_media_list,p_m) )
539 item = libvlc_media_list_count(libvlc_media_list)-1;
540 libvlc_media_list_unlock(libvlc_media_list);
542 libvlc_media_release(p_m);
547 int VlcPlugin::playlist_add_extended_untrusted( const char *mrl, const char *name,
548 int optc, const char **optv )
553 assert( libvlc_media_list );
555 p_m = libvlc_media_new_location(libvlc_instance, mrl);
559 for( int i = 0; i < optc; ++i )
560 libvlc_media_add_option_flag(p_m, optv[i], libvlc_media_option_unique);
562 libvlc_media_list_lock(libvlc_media_list);
563 if( !libvlc_media_list_add_media(libvlc_media_list,p_m) )
564 item = libvlc_media_list_count(libvlc_media_list)-1;
565 libvlc_media_list_unlock(libvlc_media_list);
566 libvlc_media_release(p_m);
571 bool VlcPlugin::playlist_select( int idx )
573 libvlc_media_t *p_m = NULL;
575 assert( libvlc_media_list );
577 libvlc_media_list_lock(libvlc_media_list);
579 int count = libvlc_media_list_count(libvlc_media_list);
580 if( idx<0||idx>=count )
583 playlist_index = idx;
585 p_m = libvlc_media_list_item_at_index(libvlc_media_list,playlist_index);
586 libvlc_media_list_unlock(libvlc_media_list);
591 if( libvlc_media_player )
593 if( playlist_isplaying() )
595 events.unhook_manager();
596 libvlc_media_player_release( libvlc_media_player );
597 libvlc_media_player = NULL;
600 libvlc_media_player = libvlc_media_player_new_from_media(p_m);
601 if( libvlc_media_player )
605 libvlc_media_player_event_manager(libvlc_media_player),
606 event_callback, this);
609 libvlc_media_release( p_m );
613 libvlc_media_list_unlock(libvlc_media_list);
617 int VlcPlugin::playlist_delete_item( int idx )
619 if( !libvlc_media_list )
621 libvlc_media_list_lock(libvlc_media_list);
622 int ret = libvlc_media_list_remove_index(libvlc_media_list,idx);
623 libvlc_media_list_unlock(libvlc_media_list);
627 void VlcPlugin::playlist_clear()
629 if( libvlc_media_list )
630 libvlc_media_list_release(libvlc_media_list);
631 libvlc_media_list = libvlc_media_list_new(getVLC());
634 int VlcPlugin::playlist_count()
637 if( !libvlc_media_list )
639 libvlc_media_list_lock(libvlc_media_list);
640 items_count = libvlc_media_list_count(libvlc_media_list);
641 libvlc_media_list_unlock(libvlc_media_list);
645 void VlcPlugin::toggle_fullscreen()
647 if( playlist_isplaying() )
648 libvlc_toggle_fullscreen(libvlc_media_player);
651 void VlcPlugin::set_fullscreen( int yes )
653 if( playlist_isplaying() )
654 libvlc_set_fullscreen(libvlc_media_player,yes);
657 int VlcPlugin::get_fullscreen()
660 if( playlist_isplaying() )
661 r = libvlc_get_fullscreen(libvlc_media_player);
665 bool VlcPlugin::player_has_vout()
668 if( playlist_isplaying() )
669 r = libvlc_media_player_has_vout(libvlc_media_player);
673 /*****************************************************************************
675 *****************************************************************************/
677 char *VlcPlugin::getAbsoluteURL(const char *url)
681 // check whether URL is already absolute
682 const char *end=strchr(url, ':');
683 if( (NULL != end) && (end != url) )
685 // validate protocol header
686 const char *start = url;
691 while( start != end )
698 || ('/' == c)) ) /* VLC uses / to allow user to specify a demuxer */
699 // not valid protocol header, assume relative URL
703 /* we have a protocol header, therefore URL is absolute */
706 // not a valid protocol header, assume relative URL
713 size_t baseLen = strlen(psz_baseURL);
714 char *href = (char *) malloc(baseLen+strlen(url)+1);
717 /* prepend base URL */
718 memcpy(href, psz_baseURL, baseLen+1);
721 ** relative url could be empty,
722 ** in which case return base URL
728 ** locate pathname part of base URL
731 /* skip over protocol part */
732 char *pathstart = strchr(href, ':');
733 char *pathend = href+baseLen;
736 if( '/' == *(++pathstart) )
738 if( '/' == *(++pathstart) )
743 /* skip over host part */
744 pathstart = strchr(pathstart, '/');
747 // no path, add a / past end of url (over '\0')
754 /* baseURL is just a UNIX path */
757 /* baseURL is not an absolute path */
764 /* relative URL made of an absolute path ? */
767 /* replace path completely */
768 strcpy(pathstart, url);
772 /* find last path component and replace it */
773 while( '/' != *pathend)
777 ** if relative url path starts with one or more '../',
778 ** factor them out of href so that we return a
781 while( pathend != pathstart )
789 /* relative url is just '.' */
795 /* relative url starts with './' */
804 /* relative url is '..' */
810 /* relative url starts with '../' */
818 while( '/' != *pathend );
820 /* skip over '/' separator */
822 /* concatenate remaining base URL and relative URL */
823 strcpy(pathend, url);
832 int VlcPlugin::setSize(unsigned width, unsigned height)
834 int diff = (width != i_width) || (height != i_height);
843 #define BTN_SPACE ((unsigned int)4)
844 void VlcPlugin::showToolbar()
846 const NPWindow& window = getWindow();
847 Window control = getControlWindow();
848 Window video = getVideoWindow();
849 Display *p_display = ((NPSetWindowCallbackStruct *)window.ws_info)->display;
850 unsigned int i_height = 0, i_width = BTN_SPACE;
854 XpmReadFileToImage( p_display, DATA_PATH "/mozilla/play.xpm",
855 &p_btnPlay, NULL, NULL);
858 i_height = __MAX( i_height, p_btnPlay->height );
861 XpmReadFileToImage( p_display, DATA_PATH "/mozilla/pause.xpm",
862 &p_btnPause, NULL, NULL);
865 i_height = __MAX( i_height, p_btnPause->height );
867 i_width += __MAX( p_btnPause->width, p_btnPlay->width );
870 XpmReadFileToImage( p_display, DATA_PATH "/mozilla/stop.xpm",
871 &p_btnStop, NULL, NULL );
874 i_height = __MAX( i_height, p_btnStop->height );
875 i_width += BTN_SPACE + p_btnStop->width;
878 XpmReadFileToImage( p_display, DATA_PATH "/mozilla/time_line.xpm",
879 &p_timeline, NULL, NULL);
882 i_height = __MAX( i_height, p_timeline->height );
883 i_width += BTN_SPACE + p_timeline->width;
886 XpmReadFileToImage( p_display, DATA_PATH "/mozilla/time_icon.xpm",
887 &p_btnTime, NULL, NULL);
890 i_height = __MAX( i_height, p_btnTime->height );
891 i_width += BTN_SPACE + p_btnTime->width;
893 if( !p_btnFullscreen )
894 XpmReadFileToImage( p_display, DATA_PATH "/mozilla/fullscreen.xpm",
895 &p_btnFullscreen, NULL, NULL);
896 if( p_btnFullscreen )
898 i_height = __MAX( i_height, p_btnFullscreen->height );
899 i_width += BTN_SPACE + p_btnFullscreen->width;
902 XpmReadFileToImage( p_display, DATA_PATH "/mozilla/volume_max.xpm",
903 &p_btnMute, NULL, NULL);
906 i_height = __MAX( i_height, p_btnMute->height );
909 XpmReadFileToImage( p_display, DATA_PATH "/mozilla/volume_mute.xpm",
910 &p_btnUnmute, NULL, NULL);
913 i_height = __MAX( i_height, p_btnUnmute->height );
915 i_width += BTN_SPACE + __MAX( p_btnUnmute->width, p_btnMute->width );
917 setToolbarSize( i_width, i_height );
919 if( !p_btnPlay || !p_btnPause || !p_btnStop || !p_timeline ||
920 !p_btnTime || !p_btnFullscreen || !p_btnMute || !p_btnUnmute )
921 fprintf(stderr, "Error: some button images not found in %s\n", DATA_PATH );
923 /* reset panels position and size */
924 /* XXX use i_width */
925 XResizeWindow( p_display, video, window.width, window.height - i_height);
926 XMoveWindow( p_display, control, 0, window.height - i_height );
927 XResizeWindow( p_display, control, window.width, i_height -1);
929 b_toolbar = 1; /* says toolbar is now shown */
933 void VlcPlugin::hideToolbar()
935 const NPWindow& window = getWindow();
936 Display *p_display = ((NPSetWindowCallbackStruct *)window.ws_info)->display;
937 Window control = getControlWindow();
938 Window video = getVideoWindow();
940 i_tb_width = i_tb_height = 0;
942 if( p_btnPlay ) XDestroyImage( p_btnPlay );
943 if( p_btnPause ) XDestroyImage( p_btnPause );
944 if( p_btnStop ) XDestroyImage( p_btnStop );
945 if( p_timeline ) XDestroyImage( p_timeline );
946 if( p_btnTime ) XDestroyImage( p_btnTime );
947 if( p_btnFullscreen ) XDestroyImage( p_btnFullscreen );
948 if( p_btnMute ) XDestroyImage( p_btnMute );
949 if( p_btnUnmute ) XDestroyImage( p_btnUnmute );
956 p_btnFullscreen = NULL;
960 /* reset panels position and size */
961 /* XXX use i_width */
962 XResizeWindow( p_display, video, window.width, window.height );
963 XMoveWindow( p_display, control, 0, window.height-1 );
964 XResizeWindow( p_display, control, window.width, 1 );
966 b_toolbar = 0; /* says toolbar is now hidden */
970 void VlcPlugin::redrawToolbar()
974 unsigned int dst_x, dst_y;
977 unsigned int i_tb_width, i_tb_height;
979 /* This method does nothing if toolbar is hidden. */
980 if( !b_toolbar || !libvlc_media_player )
983 const NPWindow& window = getWindow();
984 Window control = getControlWindow();
985 Display *p_display = ((NPSetWindowCallbackStruct *)window.ws_info)->display;
987 getToolbarSize( &i_tb_width, &i_tb_height );
990 b_mute = libvlc_audio_get_mute( libvlc_media_player );
992 gcv.foreground = BlackPixel( p_display, 0 );
993 gc = XCreateGC( p_display, control, GCForeground, &gcv );
995 XFillRectangle( p_display, control, gc,
996 0, 0, window.width, i_tb_height );
997 gcv.foreground = WhitePixel( p_display, 0 );
998 XChangeGC( p_display, gc, GCForeground, &gcv );
1000 /* position icons */
1002 dst_y = i_tb_height >> 1; /* baseline = vertical middle */
1004 if( p_btnPause && (is_playing == 1) )
1006 XPutImage( p_display, control, gc, p_btnPause, 0, 0, dst_x,
1007 dst_y - (p_btnPause->height >> 1),
1008 p_btnPause->width, p_btnPause->height );
1009 dst_x += BTN_SPACE + p_btnPause->width;
1011 else if( p_btnPlay )
1013 XPutImage( p_display, control, gc, p_btnPlay, 0, 0, dst_x,
1014 dst_y - (p_btnPlay->height >> 1),
1015 p_btnPlay->width, p_btnPlay->height );
1016 dst_x += BTN_SPACE + p_btnPlay->width;
1020 XPutImage( p_display, control, gc, p_btnStop, 0, 0, dst_x,
1021 dst_y - (p_btnStop->height >> 1),
1022 p_btnStop->width, p_btnStop->height );
1024 dst_x += BTN_SPACE + ( p_btnStop ? p_btnStop->width : 0 );
1026 if( p_btnFullscreen )
1027 XPutImage( p_display, control, gc, p_btnFullscreen, 0, 0, dst_x,
1028 dst_y - (p_btnFullscreen->height >> 1),
1029 p_btnFullscreen->width, p_btnFullscreen->height );
1031 dst_x += BTN_SPACE + ( p_btnFullscreen ? p_btnFullscreen->width : 0 );
1033 if( p_btnUnmute && b_mute )
1035 XPutImage( p_display, control, gc, p_btnUnmute, 0, 0, dst_x,
1036 dst_y - (p_btnUnmute->height >> 1),
1037 p_btnUnmute->width, p_btnUnmute->height );
1039 dst_x += BTN_SPACE + ( p_btnUnmute ? p_btnUnmute->width : 0 );
1041 else if( p_btnMute )
1043 XPutImage( p_display, control, gc, p_btnMute, 0, 0, dst_x,
1044 dst_y - (p_btnMute->height >> 1),
1045 p_btnMute->width, p_btnMute->height );
1047 dst_x += BTN_SPACE + ( p_btnMute ? p_btnMute->width : 0 );
1051 XPutImage( p_display, control, gc, p_timeline, 0, 0, dst_x,
1052 dst_y - (p_timeline->height >> 1),
1053 (window.width-(dst_x+BTN_SPACE)), p_timeline->height );
1055 /* get movie position in % */
1056 if( playlist_isplaying() )
1058 i_last_position = (int)((window.width-(dst_x+BTN_SPACE))*
1059 libvlc_media_player_get_position(libvlc_media_player));
1063 XPutImage( p_display, control, gc, p_btnTime,
1064 0, 0, (dst_x+i_last_position),
1065 dst_y - (p_btnTime->height >> 1),
1066 p_btnTime->width, p_btnTime->height );
1068 XFreeGC( p_display, gc );
1071 vlc_toolbar_clicked_t VlcPlugin::getToolbarButtonClicked( int i_xpos, int i_ypos )
1073 unsigned int i_dest = BTN_SPACE;
1075 bool b_mute = false;
1078 fprintf( stderr, "ToolbarButtonClicked:: "
1079 "trying to match (%d,%d) (%d,%d)\n",
1080 i_xpos, i_ypos, i_tb_height, i_tb_width );
1082 if( i_ypos >= i_tb_width )
1083 return clicked_Unknown;
1085 /* Note: the order of testing is dependend on the original
1086 * drawing positions of the icon buttons. Buttons are tested
1091 is_playing = playlist_isplaying();
1094 if( libvlc_media_player )
1095 b_mute = libvlc_audio_get_mute( libvlc_media_player );
1097 /* is Pause of Play button clicked */
1098 if( (is_playing != 1) &&
1099 (i_xpos >= (BTN_SPACE>>1)) &&
1100 (i_xpos <= i_dest + p_btnPlay->width + (BTN_SPACE>>1)) )
1101 return clicked_Play;
1102 else if( (i_xpos >= (BTN_SPACE>>1)) &&
1103 (i_xpos <= i_dest + p_btnPause->width) )
1104 return clicked_Pause;
1106 /* is Stop button clicked */
1107 if( is_playing != 1 )
1108 i_dest += (p_btnPlay->width + (BTN_SPACE>>1));
1110 i_dest += (p_btnPause->width + (BTN_SPACE>>1));
1112 if( (i_xpos >= i_dest) &&
1113 (i_xpos <= i_dest + p_btnStop->width + (BTN_SPACE>>1)) )
1114 return clicked_Stop;
1116 /* is Fullscreen button clicked */
1117 i_dest += (p_btnStop->width + (BTN_SPACE>>1));
1118 if( (i_xpos >= i_dest) &&
1119 (i_xpos <= i_dest + p_btnFullscreen->width + (BTN_SPACE>>1)) )
1120 return clicked_Fullscreen;
1122 /* is Mute or Unmute button clicked */
1123 i_dest += (p_btnFullscreen->width + (BTN_SPACE>>1));
1124 if( !b_mute && (i_xpos >= i_dest) &&
1125 (i_xpos <= i_dest + p_btnMute->width + (BTN_SPACE>>1)) )
1126 return clicked_Mute;
1127 else if( (i_xpos >= i_dest) &&
1128 (i_xpos <= i_dest + p_btnUnmute->width + (BTN_SPACE>>1)) )
1129 return clicked_Unmute;
1131 /* is timeline clicked */
1133 i_dest += (p_btnMute->width + (BTN_SPACE>>1));
1135 i_dest += (p_btnUnmute->width + (BTN_SPACE>>1));
1136 if( (i_xpos >= i_dest) &&
1137 (i_xpos <= i_dest + p_timeline->width + (BTN_SPACE>>1)) )
1138 return clicked_timeline;
1140 /* is time button clicked */
1141 i_dest += (p_timeline->width + (BTN_SPACE>>1));
1142 if( (i_xpos >= i_dest) &&
1143 (i_xpos <= i_dest + p_btnTime->width + (BTN_SPACE>>1)) )
1144 return clicked_Time;
1146 return clicked_Unknown;
1151 // Verifies the version of the NPAPI.
1152 // The eventListeners use a NPAPI function available
1154 bool VlcPlugin::canUseEventListener()
1156 int plugin_major, plugin_minor;
1157 int browser_major, browser_minor;
1159 NPN_Version(&plugin_major, &plugin_minor,
1160 &browser_major, &browser_minor);
1162 if (browser_minor >= 19 || browser_major > 0)