From 338408d9e4555e0d3caf97b17b485ab04f3482a0 Mon Sep 17 00:00:00 2001 From: Mats Palmgren Date: Sat, 14 Aug 2010 01:58:19 +0200 Subject: [PATCH] Bug 585961. r=roc a=blocking2.0:final --- widget/src/windows/nsNativeDragTarget.cpp | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/widget/src/windows/nsNativeDragTarget.cpp b/widget/src/windows/nsNativeDragTarget.cpp index 25b6c03a5b0..53c504c43f9 100644 --- a/widget/src/windows/nsNativeDragTarget.cpp +++ b/widget/src/windows/nsNativeDragTarget.cpp @@ -399,16 +399,23 @@ nsNativeDragTarget::Drop(LPDATAOBJECT pData, // This cast is ok because in the constructor we created a // the actual implementation we wanted, so we know this is // a nsDragService (but it should still be a private interface) - nsDragService * winDragService = - static_cast(mDragService); + nsDragService* winDragService = static_cast(mDragService); winDragService->SetIDataObject(pData); - // Note: Calling ProcessDrag can destroy us; don't touch members after that. + // NOTE: ProcessDrag spins the event loop which may destroy arbitrary objects. + // We use strong refs to prevent it from destroying these: + nsRefPtr kungFuDeathGrip = this; nsCOMPtr serv = mDragService; // Now process the native drag state and then dispatch the event ProcessDrag(pData, NS_DRAGDROP_DROP, grfKeyState, aPT, pdwEffect); + nsCOMPtr currentDragSession; + serv->GetCurrentSession(getter_AddRefs(currentDragSession)); + if (!currentDragSession) { + return S_OK; // DragCancel() was called. + } + // Let the win drag service know whether this session experienced // a drop event within the application. Drop will not oocur if the // drop landed outside the app. (used in tab tear off, bug 455884)