b=497498 prevent GetTargetDragData (and IsTargetContextList) from being called without a target GtkWidget r=roc
authorKarl Tomlinson <karlt+@karlt.net>
Tue, 17 Apr 2012 13:00:26 +1200
changeset 91821 b73de501ea5ee5a7f9838cb33d20c8976aca8683
parent 91820 4e72b79e7cee1f1942c430bd9b4f976fd124ec22
child 91822 96e8cc4b2b20ba9f2021b5499a7c0f53e77db0b8
push id1
push userroot
push dateMon, 20 Oct 2014 17:29:22 +0000
reviewersroc
bugs497498
milestone14.0a1
b=497498 prevent GetTargetDragData (and IsTargetContextList) from being called without a target GtkWidget r=roc
widget/gtk2/nsDragService.cpp
--- a/widget/gtk2/nsDragService.cpp
+++ b/widget/gtk2/nsDragService.cpp
@@ -542,16 +542,25 @@ GetTextUriListItem(const char *data,
                             data, datalen, convertedText, convertedTextLen);
     }
 }
 
 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);
     else {
         GdkAtom gdkFlavor = gdk_atom_intern(gTextUriListType, FALSE);
         GetTargetDragData(gdkFlavor);
         if (mTargetDragData) {
             const char *data = reinterpret_cast<char*>(mTargetDragData);
@@ -569,22 +578,28 @@ nsDragService::GetData(nsITransferable *
                        PRUint32 aItemIndex)
 {
     PR_LOG(sDragLm, PR_LOG_DEBUG, ("nsDragService::GetData %d", aItemIndex));
 
     // make sure that we have a transferable
     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<nsISupportsArray> flavorList;
-    rv = aTransferable->FlavorsTransferableCanImport(
+    nsresult rv = aTransferable->FlavorsTransferableCanImport(
                         getter_AddRefs(flavorList));
     if (NS_FAILED(rv))
         return rv;
 
     // count the number of flavors
     PRUint32 cnt;
     flavorList->Count(&cnt);
     unsigned int i;
@@ -873,20 +888,20 @@ nsDragService::IsDataFlavorSupported(con
                                    aDataFlavor));
     if (!_retval)
         return NS_ERROR_INVALID_ARG;
 
     // set this to no by default
     *_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;
     }
 
     // check to see if the target context is a list.
     bool isList = IsTargetContextList();
     // if it is, just look in the internal data since we are the source
     // for it.
     if (isList) {
@@ -1069,19 +1084,16 @@ nsDragService::TargetSetTimeCallback(nsI
 }
 
 
 bool
 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
     // gMimeListType drop will work or not.
     if (gtk_drag_get_source_widget(mTargetDragContext) == NULL)
         return retval;
 
     GList *tmp;