Bug 1500954 - Remove special zero length handling in nsITransferable.GetTransferData. r=mats
authorTom Schuster <evilpies@gmail.com>
Wed, 24 Oct 2018 21:32:04 +0000
changeset 491221 79b5f27ba745e51feaeeb4c8cee773620f3e4387
parent 491220 f2ce0b583163feb057514003da2d60cc2fee8e28
child 491222 7b87be447ed82263ea5e1e8cb6f5412dd427dc71
push id247
push userfmarier@mozilla.com
push dateSat, 27 Oct 2018 01:06:44 +0000
reviewersmats
bugs1500954
milestone65.0a1
Bug 1500954 - Remove special zero length handling in nsITransferable.GetTransferData. r=mats Differential Revision: https://phabricator.services.mozilla.com/D9423
widget/nsTransferable.cpp
--- a/widget/nsTransferable.cpp
+++ b/widget/nsTransferable.cpp
@@ -244,20 +244,20 @@ nsTransferable::GetTransferDataFlavors(n
 //
 NS_IMETHODIMP
 nsTransferable::GetTransferData(const char* aFlavor,
                                 nsISupports** aData,
                                 uint32_t* aDataLen)
 {
   MOZ_ASSERT(mInitialized);
 
-  NS_ENSURE_ARG_POINTER(aFlavor && aData && aDataLen);
+  *aData = nullptr;
+  *aDataLen = 0;
 
   nsresult rv = NS_OK;
-  nsCOMPtr<nsISupports> savedData;
 
   // first look and see if the data is present in one of the intrinsic flavors
   for (size_t i = 0; i < mDataArray.Length(); ++i) {
     DataStruct& data = mDataArray.ElementAt(i);
     if (data.GetFlavor().Equals(aFlavor)) {
       nsCOMPtr<nsISupports> dataBytes;
       uint32_t len;
       data.GetData(getter_AddRefs(dataBytes), &len);
@@ -268,28 +268,27 @@ nsTransferable::GetTransferData(const ch
         rv = dataProvider->GetFlavorData(this, aFlavor,
                                          getter_AddRefs(dataBytes), &len);
         if (NS_FAILED(rv)) {
           // The provider failed, fall into the converter code below.
           break;
         }
       }
 
-      if (dataBytes && len > 0) { // XXXmats why is zero length not ok?
+      if (dataBytes) {
         *aDataLen = len;
         dataBytes.forget(aData);
         return NS_OK;
       }
-      savedData = dataBytes; // return this if format converter fails
+
+      // Not found.
       break;
     }
   }
 
-  bool found = false;
-
   // if not, try using a format converter to get the requested flavor
   if (mFormatConv) {
     for (size_t i = 0; i < mDataArray.Length(); ++i) {
       DataStruct& data = mDataArray.ElementAt(i);
       bool canConvert = false;
       mFormatConv->CanConvert(data.GetFlavor().get(), aFlavor, &canConvert);
       if (canConvert) {
         nsCOMPtr<nsISupports> dataBytes;
@@ -298,35 +297,27 @@ nsTransferable::GetTransferData(const ch
 
         // Do we have a (lazy) data provider?
         if (nsCOMPtr<nsIFlavorDataProvider> dataProvider =
               do_QueryInterface(dataBytes)) {
           rv = dataProvider->GetFlavorData(this, aFlavor,
                                            getter_AddRefs(dataBytes), &len);
           if (NS_FAILED(rv)) {
             // Give up.
-            break;
+            return rv;
           }
         }
 
-        mFormatConv->Convert(
-          data.GetFlavor().get(), dataBytes, len, aFlavor, aData, aDataLen);
-        found = true;
-        break;
+        return mFormatConv->Convert(data.GetFlavor().get(), dataBytes, len,
+                                    aFlavor, aData, aDataLen);
       }
     }
   }
 
-  // for backward compatibility
-  if (!found) {
-    savedData.forget(aData);
-    *aDataLen = 0;
-  }
-
-  return found ? NS_OK : NS_ERROR_FAILURE;
+  return NS_ERROR_FAILURE;
 }
 
 //
 // GetAnyTransferData
 //
 // Returns the data of the first flavor found. Caller is responsible for
 // deleting the flavor string.
 //