From eccc1a5ed8f43e27fe8b9442b7f17990b9cb1f62 Mon Sep 17 00:00:00 2001 From: "peterlubczynski%netscape.com" Date: Tue, 11 Mar 2003 00:54:18 +0000 Subject: [PATCH] Fixing bug 131007, unpaired events cause us to remain in capture and look hung, r=jkeiser sr=bryner --- layout/generic/nsObjectFrame.cpp | 8 ++++++ layout/html/base/src/nsObjectFrame.cpp | 8 ++++++ .../plugin/base/public/nsPluginNativeWindow.h | 11 ++++++++ .../base/src/nsPluginNativeWindowWin.cpp | 27 +++++++++++++++++++ modules/plugin/base/src/nsPluginViewer.cpp | 7 +++++ 5 files changed, 61 insertions(+) diff --git a/layout/generic/nsObjectFrame.cpp b/layout/generic/nsObjectFrame.cpp index 1a161417aa07..1bd50f63b282 100644 --- a/layout/generic/nsObjectFrame.cpp +++ b/layout/generic/nsObjectFrame.cpp @@ -704,6 +704,11 @@ nsObjectFrame::Destroy(nsIPresContext* aPresContext) nsCOMPtr pluginHost = do_GetService(kCPluginManagerCID); if(pluginHost) pluginHost->StopPluginInstance(inst); + + // the frame is going away along with its widget + // so tell the window to forget its widget too + if (window) + window->SetPluginWidget(nsnull); } } return nsObjectFrameSuper::Destroy(aPresContext); @@ -4113,6 +4118,9 @@ NS_IMETHODIMP nsPluginInstanceOwner::CreateWidget(void) // start the idle timer. StartTimer(); + + // tell the plugin window about the widget + mPluginWindow->SetPluginWidget(mWidget); } } } diff --git a/layout/html/base/src/nsObjectFrame.cpp b/layout/html/base/src/nsObjectFrame.cpp index 1a161417aa07..1bd50f63b282 100644 --- a/layout/html/base/src/nsObjectFrame.cpp +++ b/layout/html/base/src/nsObjectFrame.cpp @@ -704,6 +704,11 @@ nsObjectFrame::Destroy(nsIPresContext* aPresContext) nsCOMPtr pluginHost = do_GetService(kCPluginManagerCID); if(pluginHost) pluginHost->StopPluginInstance(inst); + + // the frame is going away along with its widget + // so tell the window to forget its widget too + if (window) + window->SetPluginWidget(nsnull); } } return nsObjectFrameSuper::Destroy(aPresContext); @@ -4113,6 +4118,9 @@ NS_IMETHODIMP nsPluginInstanceOwner::CreateWidget(void) // start the idle timer. StartTimer(); + + // tell the plugin window about the widget + mPluginWindow->SetPluginWidget(mWidget); } } } diff --git a/modules/plugin/base/public/nsPluginNativeWindow.h b/modules/plugin/base/public/nsPluginNativeWindow.h index 21fad509bd09..dc23179d82c6 100644 --- a/modules/plugin/base/public/nsPluginNativeWindow.h +++ b/modules/plugin/base/public/nsPluginNativeWindow.h @@ -45,6 +45,7 @@ #include "nsCOMPtr.h" #include "nsIPluginInstance.h" #include "nsplugindefs.h" +#include "nsIWidget.h" /** * base class for native plugin window implementations @@ -76,6 +77,15 @@ public: return NS_OK; } + nsresult GetPluginWidget(nsIWidget **aWidget) { + NS_IF_ADDREF(*aWidget = mWidget); + return NS_OK; + } + nsresult SetPluginWidget(nsIWidget *aWidget) { + mWidget = aWidget; + return NS_OK; + } + public: virtual nsresult CallSetWindow(nsCOMPtr &aPluginInstance) { // null aPluginInstance means that we want to call SetWindow(null) @@ -90,6 +100,7 @@ public: protected: nsCOMPtr mPluginInstance; + nsCOMPtr mWidget; }; nsresult PLUG_NewPluginNativeWindow(nsPluginNativeWindow ** aPluginNativeWindow); diff --git a/modules/plugin/base/src/nsPluginNativeWindowWin.cpp b/modules/plugin/base/src/nsPluginNativeWindowWin.cpp index 80db469c16ca..f671b883d3d1 100644 --- a/modules/plugin/base/src/nsPluginNativeWindowWin.cpp +++ b/modules/plugin/base/src/nsPluginNativeWindowWin.cpp @@ -192,6 +192,33 @@ static LRESULT CALLBACK PluginWndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM } } + // Activate/deactivate mouse capture on the plugin widget + // here, before we pass the Windows event to the plugin + // because its possible our widget won't get paired events + // (see bug 131007) and we'll look frozen. Note that this + // is also done in ChildWindow::DispatchMouseEvent. + switch (msg) { + case WM_LBUTTONDOWN: + case WM_MBUTTONDOWN: + case WM_RBUTTONDOWN: { + nsCOMPtr widget; + win->GetPluginWidget(getter_AddRefs(widget)); + if (widget) + widget->CaptureMouse(PR_TRUE); + break; + } + case WM_MBUTTONUP: + case WM_LBUTTONUP: + case WM_RBUTTONUP: { + nsCOMPtr widget; + win->GetPluginWidget(getter_AddRefs(widget)); + if (widget) + widget->CaptureMouse(PR_FALSE); + break; + } + } + + // Macromedia Flash plugin may flood the message queue with some special messages // (WM_USER+1) causing 100% CPU consumption and GUI freeze, see mozilla bug 132759; // we can prevent this from happening by delaying the processing such messages; diff --git a/modules/plugin/base/src/nsPluginViewer.cpp b/modules/plugin/base/src/nsPluginViewer.cpp index ce145769fdec..1100bd25713f 100644 --- a/modules/plugin/base/src/nsPluginViewer.cpp +++ b/modules/plugin/base/src/nsPluginViewer.cpp @@ -392,6 +392,10 @@ PluginViewerImpl::CreatePlugin(nsIRequest* request, nsIPluginHost* aHost, const channel->GetContentType(ct); if (NS_FAILED(rv)) return rv; rv = aHost->InstantiateFullPagePlugin(ct.get(), str, aResult, mOwner); + + if (NS_SUCCEEDED(rv)) { + NS_STATIC_CAST(nsPluginNativeWindow*, win)->SetPluginWidget(mWindow); + } } return rv; @@ -492,6 +496,9 @@ PluginViewerImpl::Destroy(void) window ? window->CallSetWindow(nullinst) : inst->SetWindow(nsnull); inst->Stop(); } + + if (window) + window->SetPluginWidget(nsnull); } } return NS_OK;