]> git.sesse.net Git - vlc/blobdiff - projects/mozilla/vlcshell.cpp
Remove references to mozilla-config.h, remove linkage with libnspr and other xpcom...
[vlc] / projects / mozilla / vlcshell.cpp
index be2ea7bbcb03bf59a594e9fbc0e5730be1c1050a..575c2b1b91710d5707b6443cface096c34a0e8ff 100644 (file)
@@ -1,7 +1,7 @@
 /*****************************************************************************
  * vlcshell.cpp: a VLC plugin for Mozilla
  *****************************************************************************
- * Copyright (C) 2002-2008 the VideoLAN team
+ * Copyright (C) 2002-2009 the VideoLAN team
  * $Id$
  *
  * Authors: Samuel Hocevar <sam@zoy.org>
 #include <string.h>
 #include <stdlib.h>
 
-/* Mozilla stuff */
-#ifdef HAVE_MOZILLA_CONFIG_H
-#   include <mozilla-config.h>
-#endif
-
 /* This is from mozilla java, do we really need it? */
 #if 0
 #include <jri.h>
 #endif
 
 #include "vlcplugin.h"
+#include "vlcshell.h"
 
 /* Enable/disable debugging printf's for X11 resizing */
 #undef X11_RESIZE_DEBUG
 
-#define WINDOW_TEXT "Video is loading..."
-
 /*****************************************************************************
  * Unix-only declarations
 ******************************************************************************/
-#ifdef XP_UNIX
+#if defined(XP_UNIX)
 
 static void Redraw( Widget w, XtPointer closure, XEvent *event );
 static void ControlHandler( Widget w, XtPointer closure, XEvent *event );
@@ -79,19 +73,20 @@ static LRESULT CALLBACK Manage( HWND p_hwnd, UINT i_msg, WPARAM wpar, LPARAM lpa
  *****************************************************************************/
 char * NPP_GetMIMEDescription( void )
 {
-    return PLUGIN_MIMETYPES;
+    static char mimetype[] = PLUGIN_MIMETYPES;
+    return mimetype;
 }
 
 NPError NPP_GetValue( NPP instance, NPPVariable variable, void *value )
 {
-
+    static char psz_name[] = PLUGIN_NAME;
     static char psz_desc[1000];
 
     /* plugin class variables */
     switch( variable )
     {
         case NPPVpluginNameString:
-            *((char **)value) = PLUGIN_NAME;
+            *((char **)value) = psz_name;
             return NPERR_NO_ERROR;
 
         case NPPVpluginDescriptionString:
@@ -154,17 +149,15 @@ NPError NPP_SetValue( NPP instance, NPNVariable variable, void *value )
  * Mac-only API calls
  *****************************************************************************/
 #ifdef XP_MACOSX
-int16 NPP_HandleEvent( NPP instance, void * event )
+int16_t NPP_HandleEvent( NPP instance, void * event )
 {
     static UInt32 lastMouseUp = 0;
-
     if( instance == NULL )
     {
         return false;
     }
 
-    VlcPlugin *p_plugin = (VlcPlugin*)instance->pdata;
-
+    VlcPlugin* p_plugin = reinterpret_cast<VlcPlugin*>(instance->pdata);
     if( p_plugin == NULL )
     {
         return false;
@@ -181,21 +174,7 @@ int16 NPP_HandleEvent( NPP instance, void * event )
             if( (myEvent->when - lastMouseUp) < GetDblTime() )
             {
                 /* double click */
-                libvlc_instance_t *p_vlc = p_plugin->getVLC();
-
-                if( p_vlc )
-                {
-                    if( libvlc_playlist_isplaying(p_vlc, NULL) )
-                    {
-                        libvlc_media_player_t *p_md =
-                            libvlc_playlist_get_media_player(p_vlc, NULL);
-                        if( p_md )
-                        {
-                            libvlc_toggle_fullscreen(p_md, NULL);
-                            libvlc_media_player_release(p_md);
-                        }
-                    }
-                }
+                p_plugin->toggle_fullscreen();
             }
             return true;
         }
@@ -211,32 +190,24 @@ int16 NPP_HandleEvent( NPP instance, void * event )
             const NPWindow& npwindow = p_plugin->getWindow();
             if( npwindow.window )
             {
-                int hasVout = FALSE;
-                libvlc_instance_t *p_vlc = p_plugin->getVLC();
+                bool hasVout = false;
 
-                if( p_vlc )
+                if( p_plugin->playlist_isplaying() )
                 {
-                    if( libvlc_playlist_isplaying(p_vlc, NULL) )
+                    hasVout = p_plugin->player_has_vout();
+#if 0
+                    if( hasVout )
                     {
-                        libvlc_media_player_t *p_md =
-                            libvlc_playlist_get_media_player(p_vlc, NULL);
-                        if( p_md )
-                        {
-                            hasVout = libvlc_media_player_has_vout(p_md,
-                                                                     NULL);
-                            if( hasVout )
-                            {
-                                libvlc_rectangle_t area;
-                                area.left = 0;
-                                area.top = 0;
-                                area.right = npwindow.width;
-                                area.bottom = npwindow.height;
-                                libvlc_video_redraw_rectangle(p_md, &area,
-                                                              NULL);
-                            }
-                            libvlc_media_player_release(p_md);
-                        }
+                        libvlc_rectangle_t area;
+                        area.left = 0;
+                        area.top = 0;
+                        area.right = npwindow.width;
+                        area.bottom = npwindow.height;
+                        libvlc_video_redraw_rectangle(p_plugin->getMD(), &area, NULL);
                     }
+#else
+#warning disabled code
+#endif
                 }
 
                 if( ! hasVout )
@@ -260,7 +231,8 @@ int16 NPP_HandleEvent( NPP instance, void * event )
 
                     ForeColor(whiteColor);
                     MoveTo( (npwindow.width-80)/ 2  , npwindow.height / 2 );
-                    DrawText( WINDOW_TEXT , 0 , strlen(WINDOW_TEXT) );
+                    if( p_plugin->psz_text )
+                        DrawText( p_plugin->psz_text, 0, strlen(p_plugin->psz_text) );
                 }
             }
             return true;
@@ -295,17 +267,24 @@ NPError NPP_Initialize( void )
     return NPERR_NO_ERROR;
 }
 
+#ifdef OJI
 jref NPP_GetJavaClass( void )
 {
     return NULL;
 }
+#endif
 
 void NPP_Shutdown( void )
 {
     ;
 }
 
-NPError NPP_New( NPMIMEType pluginType, NPP instance, uint16 mode, int16 argc,
+NPError NPP_New( NPMIMEType pluginType, NPP instance,
+#if (((NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR) < 20)
+                 uint16 mode, int16 argc,
+#else
+                 uint16_t mode, int16_t argc,
+#endif
                  char* argn[], char* argv[], NPSavedData* saved )
 {
     NPError status;
@@ -348,7 +327,7 @@ NPError NPP_Destroy( NPP instance, NPSavedData** save )
 
     instance->pdata = NULL;
 
-#if XP_WIN
+#if defined(XP_WIN)
     HWND win = (HWND)p_plugin->getWindow().window;
     WNDPROC winproc = p_plugin->getWindowProc();
     if( winproc )
@@ -358,6 +337,9 @@ NPError NPP_Destroy( NPP instance, NPSavedData** save )
     }
 #endif
 
+    if( p_plugin->playlist_isplaying() )
+        p_plugin->playlist_stop();
+
     delete p_plugin;
 
     return NPERR_NO_ERROR;
@@ -365,7 +347,7 @@ NPError NPP_Destroy( NPP instance, NPSavedData** save )
 
 NPError NPP_SetWindow( NPP instance, NPWindow* window )
 {
-#ifdef XP_UNIX && !defined(__APPLE__)
+#if defined(XP_UNIX)
     Window control;
     unsigned int i_control_height = 0, i_control_width = 0;
 #endif
@@ -382,9 +364,11 @@ NPError NPP_SetWindow( NPP instance, NPWindow* window )
         /* we should probably show a splash screen here */
         return NPERR_NO_ERROR;
     }
-#ifdef XP_UNIX && !defined(__APPLE__)
+
+#if defined(XP_UNIX)
     control = p_plugin->getControlWindow();
 #endif
+
     libvlc_instance_t *p_vlc = p_plugin->getVLC();
 
     /*
@@ -403,11 +387,6 @@ NPError NPP_SetWindow( NPP instance, NPWindow* window )
     {
         /* check if plugin has a new parent window */
         CGrafPtr drawable = (((NP_Port*) (window->window))->port);
-        if( !curwin.window || drawable != (((NP_Port*) (curwin.window))->port) )
-        {
-            /* set/change parent window */
-            libvlc_video_set_parent(p_vlc, (libvlc_drawable_t)drawable, NULL);
-        }
 
         /* as MacOS X video output is windowless, set viewport */
         libvlc_rectangle_t view, clip;
@@ -421,20 +400,23 @@ NPError NPP_SetWindow( NPP instance, NPWindow* window )
         view.left    = ((NP_Port*) (window->window))->portx;
         view.bottom  = window->height+view.top;
         view.right   = window->width+view.left;
+
         /* clipRect coordinates are also relative to GrafPort */
         clip.top     = window->clipRect.top;
         clip.left    = window->clipRect.left;
         clip.bottom  = window->clipRect.bottom;
         clip.right   = window->clipRect.right;
-
-        libvlc_video_set_viewport(p_vlc, &view, &clip, NULL);
-
+#ifdef NOT_WORKING
+        libvlc_video_set_viewport(p_vlc, p_plugin->getMD(), &view, &clip);
+#else
+#warning disabled code
+#endif
         /* remember new window */
         p_plugin->setWindow(*window);
     }
-    else if( curwin.window ) {
+    else if( curwin.window )
+    {
         /* change/set parent */
-        libvlc_video_set_parent(p_vlc, 0, NULL);
         curwin.window = NULL;
     }
 #endif /* XP_MACOSX */
@@ -467,9 +449,6 @@ NPError NPP_SetWindow( NPP instance, NPWindow* window )
             style |= WS_CLIPCHILDREN|WS_CLIPSIBLINGS;
             SetWindowLong((HWND)drawable, GWL_STYLE, style);
 
-            /* change/set parent */
-            libvlc_video_set_parent(p_vlc, (libvlc_drawable_t)drawable, NULL);
-
             /* remember new window */
             p_plugin->setWindow(*window);
 
@@ -478,19 +457,18 @@ NPError NPP_SetWindow( NPP instance, NPWindow* window )
             UpdateWindow( (HWND)drawable );
         }
     }
-    else if ( curwin.window )
+    else if( curwin.window )
     {
         /* reset WNDPROC */
         HWND oldwin = (HWND)curwin.window;
         SetWindowLong( oldwin, GWL_WNDPROC, (LONG)(p_plugin->getWindowProc()) );
         p_plugin->setWindowProc(NULL);
-        /* change/set parent */
-        libvlc_video_set_parent(p_vlc, 0, NULL);
+
         curwin.window = NULL;
     }
 #endif /* XP_WIN */
 
-#ifdef XP_UNIX
+#if defined(XP_UNIX)
     /* default to hidden toolbar, shown at the end of this method if asked *
      * developers note : getToolbarSize need to wait the end of this method
      */
@@ -535,25 +513,14 @@ NPError NPP_SetWindow( NPP instance, NPWindow* window )
             XtAddEventHandler( w, ButtonReleaseMask, FALSE,
                                (XtEventHandler)ControlHandler, p_plugin );
 
-            /* callback */
-/*
-            libvlc_media_player_t *p_md;
-
-            libvlc_exception_t ex;
-            libvlc_exception_init(& ex );
-            p_md = libvlc_playlist_get_media_player( p_plugin->getVLC(), &ex );
-            libvlc_exception_init( &ex );
-            libvlc_event_attach( libvlc_media_player_event_manager( p_md, &ex ),
-                                 libvlc_MediaPlayerPositionChanged, Redraw, NULL, &ex );
-*/
-
-            /* set/change parent window */
-            libvlc_video_set_parent( p_vlc, (libvlc_drawable_t) video, NULL );
-
             /* remember window */
             p_plugin->setWindow( *window );
             p_plugin->setVideoWindow( video );
-            if( controls ) { p_plugin->setControlWindow( controls ); }
+
+            if( controls )
+            {
+                p_plugin->setControlWindow( controls );
+            }
 
             Redraw( w, (XtPointer)p_plugin, NULL );
 
@@ -564,10 +531,8 @@ NPError NPP_SetWindow( NPP instance, NPWindow* window )
             }
         }
     }
-    else if ( curwin.window )
+    else if( curwin.window )
     {
-        /* change/set parent */
-        libvlc_video_set_parent(p_vlc, 0, NULL);
         curwin.window = NULL;
     }
 #endif /* XP_UNIX */
@@ -576,12 +541,11 @@ NPError NPP_SetWindow( NPP instance, NPWindow* window )
     {
         if( p_plugin->psz_target )
         {
-            if( libvlc_playlist_add( p_vlc, p_plugin->psz_target,
-                                     NULL, NULL ) != -1 )
+            if( p_plugin->playlist_add( p_plugin->psz_target ) != -1 )
             {
                 if( p_plugin->b_autoplay )
                 {
-                    libvlc_playlist_play(p_vlc, 0, 0, NULL, NULL);
+                    p_plugin->playlist_play();
                 }
             }
             p_plugin->b_stream = true;
@@ -591,7 +555,11 @@ NPError NPP_SetWindow( NPP instance, NPWindow* window )
 }
 
 NPError NPP_NewStream( NPP instance, NPMIMEType type, NPStream *stream,
+#if (((NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR) < 20)
                        NPBool seekable, uint16 *stype )
+#else
+                       NPBool seekable, uint16_t *stype )
+#endif
 {
     if( NULL == instance  )
     {
@@ -620,21 +588,28 @@ NPError NPP_NewStream( NPP instance, NPMIMEType type, NPStream *stream,
     return NPERR_GENERIC_ERROR;
 }
 
+#if (((NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR) < 20)
 int32 NPP_WriteReady( NPP instance, NPStream *stream )
+#else
+int32_t NPP_WriteReady( NPP instance, NPStream *stream )
+#endif
 {
     /* TODO */
     return 8*1024;
 }
 
-
+#if (((NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR) < 20)
 int32 NPP_Write( NPP instance, NPStream *stream, int32 offset,
                  int32 len, void *buffer )
+#else
+int32_t NPP_Write( NPP instance, NPStream *stream, int32_t offset,
+                 int32_t len, void *buffer )
+#endif
 {
     /* TODO */
     return len;
 }
 
-
 NPError NPP_DestroyStream( NPP instance, NPStream *stream, NPError reason )
 {
     if( instance == NULL )
@@ -644,7 +619,6 @@ NPError NPP_DestroyStream( NPP instance, NPStream *stream, NPError reason )
     return NPERR_NO_ERROR;
 }
 
-
 void NPP_StreamAsFile( NPP instance, NPStream *stream, const char* fname )
 {
     if( instance == NULL )
@@ -658,17 +632,15 @@ void NPP_StreamAsFile( NPP instance, NPStream *stream, const char* fname )
         return;
     }
 
-    if( libvlc_playlist_add( p_plugin->getVLC(), fname, stream->url, NULL )
-        != -1 )
+    if( p_plugin->playlist_add( stream->url ) != -1 )
     {
         if( p_plugin->b_autoplay )
         {
-            libvlc_playlist_play( p_plugin->getVLC(), 0, 0, NULL, NULL);
+            p_plugin->playlist_play();
         }
     }
 }
 
-
 void NPP_URLNotify( NPP instance, const char* url,
                     NPReason reason, void* notifyData )
 {
@@ -679,7 +651,6 @@ void NPP_URLNotify( NPP instance, const char* url,
     \*********************************************/
 }
 
-
 void NPP_Print( NPP instance, NPPrint* printInfo )
 {
     if( printInfo == NULL )
@@ -750,7 +721,7 @@ void NPP_Print( NPP instance, NPPrint* printInfo )
 /******************************************************************************
  * Windows-only methods
  *****************************************************************************/
-#if XP_WIN
+#if defined(XP_WIN)
 static LRESULT CALLBACK Manage( HWND p_hwnd, UINT i_msg, WPARAM wpar, LPARAM lpar )
 {
     VlcPlugin* p_plugin = reinterpret_cast<VlcPlugin*>(GetWindowLongPtr(p_hwnd, GWLP_USERDATA));
@@ -773,8 +744,9 @@ static LRESULT CALLBACK Manage( HWND p_hwnd, UINT i_msg, WPARAM wpar, LPARAM lpa
             FillRect( hdc, &rect, (HBRUSH)GetStockObject(BLACK_BRUSH) );
             SetTextColor(hdc, RGB(255, 255, 255));
             SetBkColor(hdc, RGB(0, 0, 0));
-            DrawText( hdc, WINDOW_TEXT, strlen(WINDOW_TEXT), &rect,
-                      DT_CENTER|DT_VCENTER|DT_SINGLELINE);
+            if( p_plugin->psz_text )
+                DrawText( hdc, p_plugin->psz_text, strlen(p_plugin->psz_text), &rect,
+                          DT_CENTER|DT_VCENTER|DT_SINGLELINE);
 
             EndPaint( p_hwnd, &paintstruct );
             return 0L;
@@ -790,7 +762,7 @@ static LRESULT CALLBACK Manage( HWND p_hwnd, UINT i_msg, WPARAM wpar, LPARAM lpa
 /******************************************************************************
  * UNIX-only methods
  *****************************************************************************/
-#ifdef XP_UNIX
+#if defined(XP_UNIX)
 static void Redraw( Widget w, XtPointer closure, XEvent *event )
 {
     VlcPlugin* p_plugin = reinterpret_cast<VlcPlugin*>(closure);
@@ -817,9 +789,10 @@ static void Redraw( Widget w, XtPointer closure, XEvent *event )
     gcv.foreground = WhitePixel( p_display, 0 );
     XChangeGC( p_display, gc, GCForeground, &gcv );
 
-    XDrawString( p_display, video, gc,
-                 window.width / 2 - 40, (window.height - i_control_height) / 2,
-                 WINDOW_TEXT, strlen(WINDOW_TEXT) );
+    if( p_plugin->psz_text )
+        XDrawString( p_display, video, gc,
+                     window.width / 2 - 40, (window.height - i_control_height) / 2,
+                     p_plugin->psz_text, strlen(p_plugin->psz_text) );
     XFreeGC( p_display, gc );
 
     p_plugin->redrawToolbar();
@@ -838,20 +811,10 @@ static void ControlHandler( Widget w, XtPointer closure, XEvent *event )
     if( p_plugin && p_plugin->b_toolbar )
     {
         int i_playing;
-        libvlc_exception_t ex;
 
-        libvlc_exception_init( &ex );
-        libvlc_media_player_t *p_md =
-                libvlc_playlist_get_media_player(p_plugin->getVLC(), &ex);
-        if( libvlc_exception_raised(&ex) )
-            fprintf( stderr, "%s\n", libvlc_exception_get_message(&ex));
-        libvlc_exception_clear( &ex );
+        libvlc_media_player_t *p_md = p_plugin->getMD();
 
-        libvlc_exception_init( &ex );
-        i_playing = libvlc_playlist_isplaying( p_plugin->getVLC(), &ex );
-        if( libvlc_exception_raised(&ex) )
-            fprintf( stderr, "%s\n", libvlc_exception_get_message(&ex));
-        libvlc_exception_clear( &ex );
+        i_playing = p_plugin->playlist_isplaying();
 
         vlc_toolbar_clicked_t clicked;
         clicked = p_plugin->getToolbarButtonClicked( i_xPos, i_yPos );
@@ -860,49 +823,30 @@ static void ControlHandler( Widget w, XtPointer closure, XEvent *event )
             case clicked_Play:
             case clicked_Pause:
             {
-                libvlc_exception_init( &ex );
                 if( i_playing == 1 )
-                    libvlc_playlist_pause( p_plugin->getVLC(), &ex );
+                    p_plugin->playlist_pause();
                 else
-                    libvlc_playlist_play( p_plugin->getVLC(), -1, 0, NULL, &ex );
-
-                if( libvlc_exception_raised(&ex) )
-                    fprintf( stderr, "%s\n", libvlc_exception_get_message(&ex));
-                libvlc_exception_clear( &ex );
+                    p_plugin->playlist_play();
             }
             break;
 
             case clicked_Stop:
             {
-                libvlc_exception_init( &ex );
-                libvlc_playlist_stop( p_plugin->getVLC(), &ex );
-                if( libvlc_exception_raised(&ex) )
-                    fprintf( stderr, "%s\n", libvlc_exception_get_message(&ex));
-                libvlc_exception_clear( &ex );
+                p_plugin->playlist_stop();
             }
             break;
 
             case clicked_Fullscreen:
             {
-                if( (i_playing == 1) && p_md )
-                {
-                    libvlc_exception_init( &ex );
-                    libvlc_set_fullscreen( p_md, 1, &ex );
-                    if( libvlc_exception_raised(&ex) )
-                        fprintf( stderr, "%s\n", libvlc_exception_get_message(&ex));
-                    libvlc_exception_clear( &ex );
-                }
+                p_plugin->set_fullscreen( 1 );
             }
             break;
 
             case clicked_Mute:
             case clicked_Unmute:
             {
-                libvlc_exception_init( &ex );
-                libvlc_audio_toggle_mute( p_plugin->getVLC(), &ex );
-                if( libvlc_exception_raised(&ex) )
-                    fprintf( stderr, "%s\n", libvlc_exception_get_message(&ex));
-                libvlc_exception_clear( &ex );
+                if( p_md )
+                    libvlc_audio_toggle_mute( p_md );
             }
             break;
 
@@ -912,18 +856,12 @@ static void ControlHandler( Widget w, XtPointer closure, XEvent *event )
                 if( p_md )
                 {
                     int64_t f_length;
-                    libvlc_exception_init( &ex );
-                    f_length = libvlc_media_player_get_length( p_md, &ex ) / 100;
-                    libvlc_exception_clear( &ex );
+                    f_length = libvlc_media_player_get_length( p_md ) / 100;
 
                     f_length = (float)f_length *
                             ( ((float)i_xPos-4.0 ) / ( ((float)i_width-8.0)/100) );
 
-                    libvlc_exception_init( &ex );
-                    libvlc_media_player_set_time( p_md, f_length, &ex );
-                    if( libvlc_exception_raised(&ex) )
-                        fprintf( stderr, "%s\n", libvlc_exception_get_message(&ex));
-                    libvlc_exception_clear( &ex );
+                    libvlc_media_player_set_time( p_md, f_length );
                 }
             }
             break;
@@ -937,7 +875,6 @@ static void ControlHandler( Widget w, XtPointer closure, XEvent *event )
             default: /* button_Unknown */
             break;
         }
-        if( p_md ) libvlc_media_player_release( p_md );
     }
     Redraw( w, closure, event );
 }