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
This commit is contained in:
@@ -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<class nsPluginNativeWindowOS2> 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<nsIEventQueueService> &aEventService);
|
||||
PluginWindowEvent * GetPluginWindowEvent(HWND aWnd, ULONG aMsg, MPARAM mp1, MPARAM mp2);
|
||||
|
||||
private:
|
||||
PFNWP mPluginWinProc;
|
||||
nsCOMPtr<nsIEventQueueService> mEventService;
|
||||
PluginWindowEvent mPluginWindowEvent;
|
||||
PluginWindowWeakRef mWeakRef;
|
||||
nsRefPtr<PluginWindowEvent> mCachedPluginWindowEvent;
|
||||
|
||||
public:
|
||||
nsPluginType mPluginType;
|
||||
@@ -156,17 +159,10 @@ static PRBool ProcessFlashMessageDelayed(nsPluginNativeWindowOS2 * aWin,
|
||||
return PR_FALSE; // no need to delay
|
||||
|
||||
// do stuff
|
||||
nsCOMPtr<nsIEventQueueService> eventService;
|
||||
if (NS_SUCCEEDED(aWin->GetEventService(eventService))) {
|
||||
nsCOMPtr<nsIEventQueue> 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<nsIRunnable> 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<nsIEventQueueService> eventService(do_GetService(kEventQueueServiceCID));
|
||||
if (eventService) {
|
||||
nsCOMPtr<nsIEventQueue> 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<nsIPluginInstance> 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<nsIEventQueueService> &aEventService)
|
||||
{
|
||||
if (!mEventService) {
|
||||
mEventService = do_GetService(kEventQueueServiceCID);
|
||||
if (!mEventService)
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
aEventService = mEventService;
|
||||
nsCOMPtr<nsIPluginInstance> 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;
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user