X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=mozilla%2Fvlcplugin.cpp;h=71af56480913a4cbfdeda879c8222f5f927d53fc;hb=9c7f833f2441b85d2d959b423f7de30ee59743ff;hp=b86828448872d810774d6523254475fb61cef405;hpb=a593fa18ef93069b6152cc571561c5ccc053e67b;p=vlc diff --git a/mozilla/vlcplugin.cpp b/mozilla/vlcplugin.cpp index b868284488..71af564809 100644 --- a/mozilla/vlcplugin.cpp +++ b/mozilla/vlcplugin.cpp @@ -5,6 +5,7 @@ * $Id$ * * Authors: Samuel Hocevar + * Damien Fouilleul * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -34,16 +35,20 @@ #include "control/npovlc.h" #include "control/npolibvlc.h" +#include + /***************************************************************************** * VlcPlugin constructor and destructor *****************************************************************************/ VlcPlugin::VlcPlugin( NPP instance, uint16 mode ) : i_npmode(mode), b_stream(0), - b_autoplay(0), + b_autoplay(1), psz_target(NULL), libvlc_instance(NULL), - scriptClass(NULL), + libvlc_log(NULL), + p_scriptClass(NULL), + p_scriptObject(NULL), p_browser(instance), psz_baseURL(NULL) #if XP_WIN @@ -57,7 +62,7 @@ VlcPlugin::VlcPlugin( NPP instance, uint16 mode ) : memset(&npwindow, 0, sizeof(NPWindow)); } -static int boolValue(const char *value) { +static bool boolValue(const char *value) { return ( !strcmp(value, "1") || !strcasecmp(value, "true") || !strcasecmp(value, "yes") ); @@ -66,14 +71,8 @@ static int boolValue(const char *value) { NPError VlcPlugin::init(int argc, char* const argn[], char* const argv[]) { /* prepare VLC command line */ - char *ppsz_argv[32] = - { - "vlc", - "-vv", - "--no-stats", - "--intf", "dummy", - }; - int ppsz_argc = 5; + char *ppsz_argv[32] = { "vlc" }; + int ppsz_argc = 1; /* locate VLC module path */ #ifdef XP_MACOSX @@ -92,20 +91,43 @@ NPError VlcPlugin::init(int argc, char* const argn[], char* const argv[]) { if( i_type == REG_SZ ) { - strcat( p_data, "\\vlc" ); - ppsz_argv[0] = p_data; + strcat( p_data, "\\plugins" ); + ppsz_argv[ppsz_argc++] = "--plugin-path"; + ppsz_argv[ppsz_argc++] = p_data; } } RegCloseKey( h_key ); } ppsz_argv[ppsz_argc++] = "--no-one-instance"; -#if 1 - ppsz_argv[0] = "F:\\Cygwin\\home\\Damien\\dev\\videolan\\vlc-trunk\\vlc"; + if( IsDebuggerPresent() ) + { + /* + ** VLC default threading mechanism is designed to be as compatible + ** with POSIX as possible. However when debugged on win32, threads + ** lose signals and eventually VLC get stuck during initialization. + ** threading support can be configured to be more debugging friendly + ** but it will be less compatible with POSIX. + ** This is done by initializing with the following options: + */ + ppsz_argv[ppsz_argc++] = "--fast-mutex"; + ppsz_argv[ppsz_argc++] = "--win9x-cv-method=1"; + } + + +#if 0 + ppsz_argv[0] = "C:\\Cygwin\\home\\damienf\\vlc-trunk\\vlc"; #endif #endif /* XP_MACOSX */ - const char *version = NULL; + /* common settings */ + ppsz_argv[ppsz_argc++] = "-vv"; + ppsz_argv[ppsz_argc++] = "--no-stats"; + ppsz_argv[ppsz_argc++] = "--no-media-library"; + ppsz_argv[ppsz_argc++] = "--intf"; + ppsz_argv[ppsz_argc++] = "dummy"; + + const char *progid = NULL; /* parse plugin arguments */ for( int i = 0; i < argc ; i++ ) @@ -154,10 +176,11 @@ NPError VlcPlugin::init(int argc, char* const argn[], char* const argv[]) ppsz_argv[ppsz_argc++] = "--no-loop"; } } - else if( !strcmp( argn[i], "version") ) - { - version = argv[i]; - } + else if( !strcmp( argn[i], "version") + || !strcmp( argn[i], "progid") ) + { + progid = argv[i]; + } } libvlc_instance = libvlc_new(ppsz_argc, ppsz_argv, NULL); @@ -206,19 +229,20 @@ NPError VlcPlugin::init(int argc, char* const argn[], char* const argv[]) if( psz_target ) { // get absolute URL from src - psz_target = getAbsoluteURL(psz_target); + char *psz_absurl = getAbsoluteURL(psz_target); + psz_target = psz_absurl ? psz_absurl : strdup(psz_target); } /* assign plugin script root class */ - if( (NULL != version) && (!strcmp(version, "VideoLAN.VLCPlugin.2")) ) + if( (NULL != progid) && (!strcmp(progid, "VideoLAN.VLCPlugin.2")) ) { - /* new APIs */ - scriptClass = new RuntimeNPClass(); + /* new APIs */ + p_scriptClass = RuntimeNPClass::getClass(); } else { - /* legacy APIs */ - scriptClass = new RuntimeNPClass(); + /* legacy APIs */ + p_scriptClass = RuntimeNPClass::getClass(); } return NPERR_NO_ERROR; @@ -261,8 +285,12 @@ VlcPlugin::~VlcPlugin() { delete psz_baseURL; delete psz_target; + if( p_scriptObject ) + NPN_ReleaseObject(p_scriptObject); + if( libvlc_log ) + libvlc_log_close(libvlc_log, NULL); if( libvlc_instance ) - libvlc_destroy(libvlc_instance); + libvlc_destroy(libvlc_instance, NULL ); } /***************************************************************************** @@ -280,20 +308,22 @@ char *VlcPlugin::getAbsoluteURL(const char *url) // validate protocol header const char *start = url; while( start != end ) { - char c = *start | 0x20; + char c = tolower(*start); if( (c < 'a') || (c > 'z') ) // not valid protocol header, assume relative URL - break; + goto relativeurl; ++start; } /* we have a protocol header, therefore URL is absolute */ return strdup(url); } +relativeurl: + if( psz_baseURL ) { size_t baseLen = strlen(psz_baseURL); - char *href = new char[baseLen+strlen(url)]; + char *href = new char[baseLen+strlen(url)+1]; if( href ) { /* prepend base URL */ @@ -313,21 +343,35 @@ char *VlcPlugin::getAbsoluteURL(const char *url) /* skip over protocol part */ char *pathstart = strchr(href, ':'); char *pathend; - if( '/' == *(++pathstart) ) + if( pathstart ) { if( '/' == *(++pathstart) ) { - ++pathstart; + if( '/' == *(++pathstart) ) + { + ++pathstart; + } + } + /* skip over host part */ + pathstart = strchr(pathstart, '/'); + pathend = href+baseLen; + if( ! pathstart ) + { + // no path, add a / past end of url (over '\0') + pathstart = pathend; + *pathstart = '/'; } } - /* skip over host part */ - pathstart = strchr(pathstart, '/'); - pathend = href+baseLen; - if( ! pathstart ) + else { - // no path, add a / past end of url (over '\0') - pathstart = pathend; - *pathstart = '/'; + /* baseURL is just a UNIX path */ + if( '/' != *href ) + { + /* baseURL is not an absolute path */ + return NULL; + } + pathstart = href; + pathend = href+baseLen; } /* relative URL made of an absolute path ? */ @@ -339,7 +383,8 @@ char *VlcPlugin::getAbsoluteURL(const char *url) } /* find last path component and replace it */ - while( '/' != *pathend) --pathend; + while( '/' != *pathend) + --pathend; /* ** if relative url path starts with one or more '../', @@ -352,17 +397,43 @@ char *VlcPlugin::getAbsoluteURL(const char *url) if( '.' != *p ) break; ++p; - if( '.' != *p ) + if( '\0' == *p ) + { + /* relative url is just '.' */ + url = p; break; - ++p; - if( '/' != *p ) + } + if( '/' == *p ) + { + /* relative url starts with './' */ + url = ++p; + continue; + } + if( '.' != *p ) break; ++p; + if( '\0' == *p ) + { + /* relative url is '..' */ + } + else + { + if( '/' != *p ) + break; + /* relative url starts with '../' */ + ++p; + } url = p; - while( '/' != *pathend ) --pathend; + do + { + --pathend; + } + while( '/' != *pathend ); } + /* skip over '/' separator */ + ++pathend; /* concatenate remaining base URL and relative URL */ - strcpy(pathend+1, url); + strcpy(pathend, url); } return href; } @@ -370,6 +441,15 @@ char *VlcPlugin::getAbsoluteURL(const char *url) return NULL; } +NPObject* VlcPlugin::getScriptObject() +{ + if( NULL == p_scriptObject ) + { + p_scriptObject = NPN_CreateObject(p_browser, p_scriptClass); + } + return NPN_RetainObject(p_scriptObject); +} + #if XP_UNIX int VlcPlugin::setSize(unsigned width, unsigned height) {