[vlc-commits] npapi win32: added window proc replacing for browser drawable window.

Sergey Radionov git at videolan.org
Sat Dec 31 03:50:19 CET 2011


npapi-vlc | branch: master | Sergey Radionov <RSATom at gmail.com> | Fri Dec 30 19:13:30 2011 +0700| [70dc01b10f68b06afd994a421a445571f8b354d3] | committer: Jean-Baptiste Kempf

npapi win32: added window proc replacing for browser drawable window.

some browsers (mainly opera) have not good realization of NPApi,
and we will need track some events via native window messages,
rather than via NPP_SetWindow.

> http://git.videolan.org/gitweb.cgi/npapi-vlc.git/?a=commit;h=70dc01b10f68b06afd994a421a445571f8b354d3
---

 npapi/vlcplugin_win.cpp |   35 ++++++++++++++++++++++++++++++++---
 npapi/vlcplugin_win.h   |    2 ++
 npapi/vlcshell.cpp      |    6 ++++--
 3 files changed, 38 insertions(+), 5 deletions(-)

diff --git a/npapi/vlcplugin_win.cpp b/npapi/vlcplugin_win.cpp
index 91f92c6..05b0a9c 100644
--- a/npapi/vlcplugin_win.cpp
+++ b/npapi/vlcplugin_win.cpp
@@ -50,8 +50,22 @@ BOOL WINAPI DllMain(HANDLE hModule, DWORD fdwReason, LPVOID lpReserved )
 };
 
 
+LRESULT CALLBACK VlcPluginWin::NPWndProcR(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
+{
+    LONG_PTR ud = GetWindowLongPtr(hWnd, GWLP_USERDATA);
+    if( ud ) {
+        VlcPluginWin *p_plugin = reinterpret_cast<VlcPluginWin *>(ud);
+
+        /* delegate to default handler */
+        return CallWindowProc( p_plugin->_NPWndProc, hWnd,
+                               uMsg, wParam, lParam);
+    }
+    else
+        return DefWindowProc(hWnd, uMsg, wParam, lParam);
+}
+
 VlcPluginWin::VlcPluginWin(NPP instance, NPuint16_t mode) :
-    VlcPluginBase(instance, mode),
+    VlcPluginBase(instance, mode), _NPWndProc(0),
     _WindowsManager(DllGetModule())
 {
 }
@@ -105,8 +119,14 @@ bool VlcPluginWin::create_windows()
         return false;
 
     /* attach our plugin object */
-    SetWindowLongPtr(drawable, GWLP_USERDATA,
-                     (LONG_PTR)this);
+    SetWindowLongPtr(drawable, GWLP_USERDATA, (LONG_PTR)this);
+
+    /* Some browsers (mainly opera) do not implement NPAPI correctly,
+     * so we will need track some events via native window messages,
+     * rather than via NPP_SetWindow. */
+    _NPWndProc = (WNDPROC) SetWindowLongPtr( drawable,
+                                             GWLP_WNDPROC,
+                                             (LONG_PTR)NPWndProcR );
 
     /* change window style to our liking */
     LONG style = GetWindowLong(drawable, GWL_STYLE);
@@ -133,6 +153,15 @@ bool VlcPluginWin::resize_windows()
 bool VlcPluginWin::destroy_windows()
 {
     _WindowsManager.DestroyWindows();
+
+    HWND hWnd = (HWND)npwindow.window;
+    if( hWnd && _NPWndProc){
+        /* reset WNDPROC */
+        SetWindowLongPtr( hWnd, GWLP_WNDPROC, (LONG_PTR)_NPWndProc );
+    }
+    _NPWndProc = 0;
+    npwindow.window = 0;
+
     SetWindowLongPtr(hWnd, GWLP_USERDATA, 0);
     return true;
 }
diff --git a/npapi/vlcplugin_win.h b/npapi/vlcplugin_win.h
index bbc66c9..6c998ad 100644
--- a/npapi/vlcplugin_win.h
+++ b/npapi/vlcplugin_win.h
@@ -63,8 +63,10 @@ protected:
     virtual void on_media_player_release();
 
 private:
+    static LRESULT CALLBACK NPWndProcR(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
     void set_player_window(){};
 
+    WNDPROC _NPWndProc;
     VLCWindowsManager _WindowsManager;
 };
 
diff --git a/npapi/vlcshell.cpp b/npapi/vlcshell.cpp
index 79fa987..f21aef7 100644
--- a/npapi/vlcshell.cpp
+++ b/npapi/vlcshell.cpp
@@ -138,7 +138,7 @@ int16_t NPP_HandleEvent( NPP instance, void * event )
         return false;
     }
 
-#ifndef __x86_64__  
+#ifndef __x86_64__
     EventRecord *myEvent = (EventRecord*)event;
 
     switch( myEvent->what )
@@ -362,12 +362,14 @@ NPError NPP_SetWindow( NPP instance, NPWindow* window )
             }
         }
     } else {
+        /* NOTE: on Windows, Opera does not call NPP_SetWindow
+         * on window destruction. */
         if (curr_window.window) {
             /* we've been destroyed */
             p_plugin->destroy_windows();
         }
     }
-    
+
     /* now display toolbar if asked through parameters */
     if( p_plugin->b_toolbar )
     {



More information about the vlc-commits mailing list