From 6317aac66caea8f5119ca13af8d87b9edf5bf1d0 Mon Sep 17 00:00:00 2001 From: Karl Tomlinson Date: Tue, 17 Apr 2012 13:00:26 +1200 Subject: [PATCH] b=497498 prevent GetTargetDragData (and IsTargetContextList) from being called without a target GtkWidget r=roc --HG-- extra : rebase_source : 4c6d856abbe49913b74da4d9640d47a9870c2210 --- widget/gtk2/nsDragService.cpp | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/widget/gtk2/nsDragService.cpp b/widget/gtk2/nsDragService.cpp index 1840281f038..b166b824571 100644 --- a/widget/gtk2/nsDragService.cpp +++ b/widget/gtk2/nsDragService.cpp @@ -547,6 +547,15 @@ NS_IMETHODIMP nsDragService::GetNumDropItems(PRUint32 * aNumItems) { PR_LOG(sDragLm, PR_LOG_DEBUG, ("nsDragService::GetNumDropItems")); + + if (!mTargetWidget) { + PR_LOG(sDragLm, PR_LOG_DEBUG, + ("*** warning: GetNumDropItems \ + called without a valid target widget!\n")); + *aNumItems = 0; + return NS_OK; + } + bool isList = IsTargetContextList(); if (isList) mSourceDataItems->Count(aNumItems); @@ -574,12 +583,18 @@ nsDragService::GetData(nsITransferable * aTransferable, if (!aTransferable) return NS_ERROR_INVALID_ARG; + if (!mTargetWidget) { + PR_LOG(sDragLm, PR_LOG_DEBUG, + ("*** warning: GetData \ + called without a valid target widget!\n")); + return NS_ERROR_FAILURE; + } + // get flavor list that includes all acceptable flavors (including // ones obtained through conversion). Flavors are nsISupportsStrings // so that they can be seen from JS. - nsresult rv = NS_ERROR_FAILURE; nsCOMPtr flavorList; - rv = aTransferable->FlavorsTransferableCanImport( + nsresult rv = aTransferable->FlavorsTransferableCanImport( getter_AddRefs(flavorList)); if (NS_FAILED(rv)) return rv; @@ -878,10 +893,10 @@ nsDragService::IsDataFlavorSupported(const char *aDataFlavor, *_retval = false; // check to make sure that we have a drag object set, here - if (!mTargetDragContext) { + if (!mTargetWidget) { PR_LOG(sDragLm, PR_LOG_DEBUG, ("*** warning: IsDataFlavorSupported \ - called without a valid drag context!\n")); + called without a valid target widget!\n")); return NS_OK; } @@ -1074,9 +1089,6 @@ nsDragService::IsTargetContextList(void) { bool retval = false; - if (!mTargetDragContext) - return retval; - // gMimeListType drags only work for drags within a single process. // The gtk_drag_get_source_widget() function will return NULL if the // source of the drag is another app, so we use it to check if a