From 814812ce46112bcbfbeace9d01d3938d8b0b48c9 Mon Sep 17 00:00:00 2001 From: "mkaply%us.ibm.com" Date: Thu, 11 May 2006 17:22:54 +0000 Subject: [PATCH] #326273 r=mkaply, sr=mkaply (OS/2 only) OS/2 changes from threading checkin - build bustage git-svn-id: svn://10.0.0.236/trunk@196319 18797224-902f-48f8-a5cc-f745e15eee43 --- .../base/src/nsPluginNativeWindowOS2.cpp | 133 +++++++----------- .../protocol/http/src/nsHttpHandler.cpp | 5 + 2 files changed, 53 insertions(+), 85 deletions(-) diff --git a/mozilla/modules/plugin/base/src/nsPluginNativeWindowOS2.cpp b/mozilla/modules/plugin/base/src/nsPluginNativeWindowOS2.cpp index b696960e4b3..abe63ed579c 100644 --- a/mozilla/modules/plugin/base/src/nsPluginNativeWindowOS2.cpp +++ b/mozilla/modules/plugin/base/src/nsPluginNativeWindowOS2.cpp @@ -42,18 +42,19 @@ #include "nsDebug.h" -#include "plevent.h" -#include "nsIEventQueueService.h" - #include "nsIPluginInstancePeer.h" #include "nsPluginSafety.h" #include "nsPluginNativeWindow.h" +#include "nsThreadUtils.h" +#include "nsAutoPtr.h" +#include "nsTWeakRef.h" -static NS_DEFINE_CID(kEventQueueServiceCID, NS_EVENTQUEUESERVICE_CID); static NS_DEFINE_CID(kCPluginManagerCID, NS_PLUGINMANAGER_CID); // needed for NS_TRY_SAFE_CALL #define NS_PLUGIN_WINDOW_PROPERTY_ASSOCIATION "MozillaPluginWindowPropertyAssociation" +typedef nsTWeakRef PluginWindowWeakRef; + extern "C" { PVOID APIENTRY WinQueryProperty(HWND hwnd, PCSZ pszNameOrAtom); @@ -66,20 +67,21 @@ BOOL APIENTRY WinSetProperty(HWND hwnd, PCSZ pszNameOrAtom, /** * PLEvent handling code */ -class PluginWindowEvent : public PLEvent { +class PluginWindowEvent : public nsRunnable { public: PluginWindowEvent(); - void Init(HWND hWnd, ULONG msg, MPARAM mp1, MPARAM mp2); + void Init(const PluginWindowWeakRef &ref, HWND hWnd, ULONG msg, MPARAM mp1, MPARAM mp2); void Clear(); HWND GetWnd() { return mWnd; }; ULONG GetMsg() { return mMsg; }; MPARAM GetWParam() { return mWParam; }; MPARAM GetLParam() { return mLParam; }; - PRBool GetIsAlloced() { return mIsAlloced; }; - void SetIsAlloced(PRBool aIsAlloced) { mIsAlloced = aIsAlloced; }; - PRBool InUse() { return (mWnd!=NULL || mMsg!=0); }; + PRBool InUse() { return (mWnd!=NULL || mMsg!=0); }; + + NS_IMETHOD Run(); protected: + PluginWindowWeakRef mPluginWindowRef; HWND mWnd; ULONG mMsg; MPARAM mWParam; @@ -100,10 +102,12 @@ void PluginWindowEvent::Clear() mLParam = 0; } -void PluginWindowEvent::Init(HWND aWnd, ULONG aMsg, MPARAM mp1, MPARAM mp2) +void PluginWindowEvent::Init(const PluginWindowWeakRef &ref, HWND aWnd, + ULONG aMsg, MPARAM mp1, MPARAM mp2) { NS_ASSERTION(aWnd!=NULL && aMsg!=0, "invalid plugin event value"); NS_ASSERTION(mWnd==NULL && mMsg==0 && mWParam==0 && mLParam==0,"event already in use"); + mPluginWindowRef = ref; mWnd = aWnd; mMsg = aMsg; mWParam = mp1; @@ -135,13 +139,12 @@ private: public: // locals PFNWP GetWindowProc(); - nsresult GetEventService(nsCOMPtr &aEventService); PluginWindowEvent * GetPluginWindowEvent(HWND aWnd, ULONG aMsg, MPARAM mp1, MPARAM mp2); private: PFNWP mPluginWinProc; - nsCOMPtr mEventService; - PluginWindowEvent mPluginWindowEvent; + PluginWindowWeakRef mWeakRef; + nsRefPtr mCachedPluginWindowEvent; public: nsPluginType mPluginType; @@ -156,17 +159,10 @@ static PRBool ProcessFlashMessageDelayed(nsPluginNativeWindowOS2 * aWin, return PR_FALSE; // no need to delay // do stuff - nsCOMPtr eventService; - if (NS_SUCCEEDED(aWin->GetEventService(eventService))) { - nsCOMPtr eventQueue; - eventService->GetThreadEventQueue(PR_GetCurrentThread(), getter_AddRefs(eventQueue)); - if (eventQueue) { - PluginWindowEvent *pwe = aWin->GetPluginWindowEvent(hWnd, msg, mp1, mp2); - if (pwe) { - eventQueue->PostEvent(pwe); - return PR_TRUE; - } - } + nsCOMPtr pwe = aWin->GetPluginWindowEvent(hWnd, msg, mp1, mp2); + if (pwe) { + NS_DispatchToCurrentThread(pwe); + return PR_TRUE; } return PR_FALSE; } @@ -238,21 +234,14 @@ nsPluginNativeWindowOS2::nsPluginNativeWindowOS2() : nsPluginNativeWindow() height = 0; mPluginWinProc = NULL; - mPluginWindowEvent.SetIsAlloced(PR_FALSE); mPluginType = nsPluginType_Unknown; } nsPluginNativeWindowOS2::~nsPluginNativeWindowOS2() { - // clear any pending events to avoid dangling pointers - nsCOMPtr eventService(do_GetService(kEventQueueServiceCID)); - if (eventService) { - nsCOMPtr eventQueue; - eventService->GetThreadEventQueue(PR_GetCurrentThread(), getter_AddRefs(eventQueue)); - if (eventQueue) { - eventQueue->RevokeEvents(this); - } - } + // clear weak reference to self to prevent any pending events from + // dereferencing this. + mWeakRef.forget(); } PFNWP nsPluginNativeWindowOS2::GetWindowProc() @@ -260,63 +249,39 @@ PFNWP nsPluginNativeWindowOS2::GetWindowProc() return mPluginWinProc; } -PR_STATIC_CALLBACK(void*) -PluginWindowEvent_Handle(PLEvent* self) +NS_IMETHODIMP PluginWindowEvent::Run() { - if (!self) - return nsnull; + nsPluginNativeWindowOS2 *win = mPluginWindowRef.get(); + if (!win) + return NS_OK; - PluginWindowEvent *event = NS_STATIC_CAST(PluginWindowEvent*, self); - - HWND hWnd = event->GetWnd(); + HWND hWnd = GetWnd(); if (!hWnd) - return nsnull; + return NS_OK; - nsPluginNativeWindowOS2 * win = (nsPluginNativeWindowOS2 *)::WinQueryProperty(hWnd, NS_PLUGIN_WINDOW_PROPERTY_ASSOCIATION); - if (win) { - nsCOMPtr inst; - win->GetPluginInstance(inst); - NS_TRY_SAFE_CALL_VOID((win->GetWindowProc()) - (hWnd, - event->GetMsg(), - event->GetWParam(), - event->GetLParam()), - nsnull, inst); - } - - return nsnull; -} - -PR_STATIC_CALLBACK(void) -PluginWindowEvent_Destroy(PLEvent* self) -{ - if (!self) - return; - - PluginWindowEvent *event = NS_STATIC_CAST(PluginWindowEvent*, self); - if (event->GetIsAlloced()) { - delete event; - } - else - event->Clear(); -} - -nsresult nsPluginNativeWindowOS2::GetEventService(nsCOMPtr &aEventService) -{ - if (!mEventService) { - mEventService = do_GetService(kEventQueueServiceCID); - if (!mEventService) - return NS_ERROR_FAILURE; - } - aEventService = mEventService; + nsCOMPtr inst; + win->GetPluginInstance(inst); + NS_TRY_SAFE_CALL_VOID((win->GetWindowProc()) + (hWnd, + GetMsg(), + GetWParam(), + GetLParam()), + nsnull, inst); + Clear(); return NS_OK; } PluginWindowEvent* nsPluginNativeWindowOS2::GetPluginWindowEvent(HWND aWnd, ULONG aMsg, MPARAM aMp1, MPARAM aMp2) { + if (!mWeakRef) { + mWeakRef = this; + if (!mWeakRef) + return nsnull; + } + PluginWindowEvent *event; - if (mPluginWindowEvent.InUse()) { + if (!mCachedPluginWindowEvent || mCachedPluginWindowEvent->InUse()) { // We have the ability to alloc if needed in case in the future some plugin // should post multiple PostMessages. However, this could lead to many // alloc's per second which could become a performance issue. If/when this @@ -325,15 +290,13 @@ nsPluginNativeWindowOS2::GetPluginWindowEvent(HWND aWnd, ULONG aMsg, MPARAM aMp1 event = new PluginWindowEvent(); if (!event) return nsnull; - - event->SetIsAlloced(PR_TRUE); } else { - event = &mPluginWindowEvent; + event = mCachedPluginWindowEvent; } + NS_ADDREF(event); - event->Init(aWnd, aMsg, aMp1, aMp2); - PL_InitEvent(event, (void *)this, &PluginWindowEvent_Handle, PluginWindowEvent_Destroy); + event->Init(mWeakRef, aWnd, aMsg, aMp1, aMp2); return event; }; diff --git a/mozilla/netwerk/protocol/http/src/nsHttpHandler.cpp b/mozilla/netwerk/protocol/http/src/nsHttpHandler.cpp index b7a9ca193ed..e309117fbb4 100644 --- a/mozilla/netwerk/protocol/http/src/nsHttpHandler.cpp +++ b/mozilla/netwerk/protocol/http/src/nsHttpHandler.cpp @@ -83,6 +83,11 @@ #include #endif +#if defined(XP_OS2) +#define INCL_DOSMISC +#include +#endif + #ifdef DEBUG // defined by the socket transport service while active extern PRThread *gSocketThread;