From ca0e40385d054e39eacfdb55140c8ed85a208ad7 Mon Sep 17 00:00:00 2001 From: "bzbarsky%mit.edu" Date: Fri, 15 Apr 2005 03:17:13 +0000 Subject: [PATCH] Fix revokeEvents to reliably revoke them. Bug 284389, r=darin, sr=dbaron, a=asa git-svn-id: svn://10.0.0.236/trunk@172263 18797224-902f-48f8-a5cc-f745e15eee43 --- mozilla/view/src/nsViewManager.cpp | 8 -------- mozilla/xpcom/threads/nsEventQueue.cpp | 22 ++++++++++++++------- mozilla/xpcom/threads/nsEventQueue.h | 1 + mozilla/xpcom/threads/nsIEventQueue.idl | 4 ++++ mozilla/xpcom/threads/nsPIEventQueueChain.h | 13 ++++++++++-- 5 files changed, 31 insertions(+), 17 deletions(-) diff --git a/mozilla/view/src/nsViewManager.cpp b/mozilla/view/src/nsViewManager.cpp index 3d728c51441..14cf227ab54 100644 --- a/mozilla/view/src/nsViewManager.cpp +++ b/mozilla/view/src/nsViewManager.cpp @@ -358,14 +358,6 @@ static void* PR_CALLBACK HandlePLEvent(PLEvent* aEvent) NS_ASSERTION(nsnull != aEvent,"Event is null"); nsViewManagerEvent *event = NS_STATIC_CAST(nsViewManagerEvent*, aEvent); - // Search for valid view manager before trying to access it. This - // is working around a bug in RevokeEvents. - const nsVoidArray *vmArray = nsViewManager::GetViewManagerArray(); - if (!vmArray || vmArray->IndexOf(event->ViewManager()) == -1) { - NS_ERROR("RevokeEvents is buggy. Fix it!"); - return nsnull; - } - event->HandleEvent(); return nsnull; } diff --git a/mozilla/xpcom/threads/nsEventQueue.cpp b/mozilla/xpcom/threads/nsEventQueue.cpp index 7653193a29f..6d375e7eef8 100644 --- a/mozilla/xpcom/threads/nsEventQueue.cpp +++ b/mozilla/xpcom/threads/nsEventQueue.cpp @@ -346,13 +346,12 @@ nsEventQueueImpl::ExitMonitor() NS_IMETHODIMP nsEventQueueImpl::RevokeEvents(void* owner) { - PL_RevokeEvents(mEventQueue, owner); - if (mElderQueue) { - nsCOMPtr elder(do_QueryInterface(mElderQueue)); - if (elder) - elder->RevokeEvents(owner); - } - return NS_OK; + nsCOMPtr youngest; + GetYoungest(getter_AddRefs(youngest)); + NS_ASSERTION(youngest, "How could we possibly not have a youngest queue?"); + nsCOMPtr youngestAsChain(do_QueryInterface(youngest)); + NS_ASSERTION(youngestAsChain, "RevokeEvents won't work; expect crashes"); + return youngestAsChain->RevokeEventsInternal(owner); } @@ -657,3 +656,12 @@ nsEventQueueImpl::GetElder(nsIEventQueue **aQueue) return mElderQueue->QueryInterface(NS_GET_IID(nsIEventQueue), (void**)&aQueue); } +NS_IMETHODIMP +nsEventQueueImpl::RevokeEventsInternal(void* aOwner) +{ + PL_RevokeEvents(mEventQueue, aOwner); + if (mElderQueue) { + mElderQueue->RevokeEventsInternal(aOwner); + } + return NS_OK; +} diff --git a/mozilla/xpcom/threads/nsEventQueue.h b/mozilla/xpcom/threads/nsEventQueue.h index 7660e331a8b..446b30fa321 100644 --- a/mozilla/xpcom/threads/nsEventQueue.h +++ b/mozilla/xpcom/threads/nsEventQueue.h @@ -64,6 +64,7 @@ public: NS_IMETHOD GetYounger(nsIEventQueue **aQueue); NS_IMETHOD SetElder(nsPIEventQueueChain *aQueue); NS_IMETHOD GetElder(nsIEventQueue **aQueue); + NS_IMETHOD RevokeEventsInternal(void* aOwner); private: ~nsEventQueueImpl(); diff --git a/mozilla/xpcom/threads/nsIEventQueue.idl b/mozilla/xpcom/threads/nsIEventQueue.idl index 416c80a1b2e..0e1a10e3047 100644 --- a/mozilla/xpcom/threads/nsIEventQueue.idl +++ b/mozilla/xpcom/threads/nsIEventQueue.idl @@ -95,6 +95,10 @@ interface nsIEventQueue : nsIEventTarget void enterMonitor(); void exitMonitor(); + /** + * Revoke events in this event queue and all other event queues + * for this thread that have |owner| as the event owner. + */ [noscript] void revokeEvents(in voidPtr owner); [noscript] PLEventQueuePtr getPLEventQueue(); diff --git a/mozilla/xpcom/threads/nsPIEventQueueChain.h b/mozilla/xpcom/threads/nsPIEventQueueChain.h index 8d3c093393c..f03b90ebea7 100644 --- a/mozilla/xpcom/threads/nsPIEventQueueChain.h +++ b/mozilla/xpcom/threads/nsPIEventQueueChain.h @@ -74,8 +74,10 @@ public: /** * Fetch (and addref) the youngest member of the chain which is - * still accepting events, or at least still contains events in need - * of processing. + * still accepting events. Note that there may be still younger + * queues which still contain events in need of processing but + * have already stopped accepting new events. + * * @param *aQueue the youngest such queue. aQueue must not be null. * *aQueue will be returned null, if no such queue is found. * @return error indication -- can be NS_OK even if *aQueue is 0 @@ -87,6 +89,13 @@ public: NS_IMETHOD SetElder(nsPIEventQueueChain *aQueue) = 0; NS_IMETHOD GetElder(nsIEventQueue **aQueue) = 0; + + /** + * Revoke events for aOwner in this queue and all elder queues. This + * differs in behavior from nsIEventQueue::RevokeEvents in that that + * method revokes events in younger queues too. + */ + NS_IMETHOD RevokeEventsInternal(void* aOwner) = 0; }; #endif /* nsPIEventQueueChain_h___ */