Bug 1497476 - Remove nsITransferable.kFlavorHasDataProvider. r=NeilDeakin
authorTom Schuster <evilpies@gmail.com>
Tue, 16 Oct 2018 20:35:10 +0000
changeset 490694 d1e4e5029ffb1e38b6328b8c9d422edfb4603107
parent 490693 2e5b99d12a6daf88e4fffa8f80efb7b874f18379
child 490695 2ac1bca7094c959bf382ee37779566056f8792a7
push id247
push userfmarier@mozilla.com
push dateSat, 27 Oct 2018 01:06:44 +0000
reviewersNeilDeakin
bugs1497476
milestone64.0a1
Bug 1497476 - Remove nsITransferable.kFlavorHasDataProvider. r=NeilDeakin Depends on D8074 Differential Revision: https://phabricator.services.mozilla.com/D8075
dom/events/DataTransfer.cpp
widget/nsITransferable.idl
widget/nsTransferable.cpp
--- a/dom/events/DataTransfer.cpp
+++ b/dom/events/DataTransfer.cpp
@@ -1152,20 +1152,19 @@ DataTransfer::ConvertFromVariant(nsIVari
       type == nsIDataType::VTYPE_INTERFACE_IS) {
     nsCOMPtr<nsISupports> data;
     if (NS_FAILED(aVariant->GetAsISupports(getter_AddRefs(data)))) {
       return false;
     }
 
     nsCOMPtr<nsIFlavorDataProvider> fdp = do_QueryInterface(data);
     if (fdp) {
-      // for flavour data providers, use kFlavorHasDataProvider (which has the
-      // value 0) as the length.
+      // For flavour data providers, use 0 as the length.
       fdp.forget(aSupports);
-      *aLength = nsITransferable::kFlavorHasDataProvider;
+      *aLength = 0;
     } else {
       data.forget(aSupports);
       *aLength = sizeof(nsISupports *);
     }
 
     return true;
   }
 
--- a/widget/nsITransferable.idl
+++ b/widget/nsITransferable.idl
@@ -90,18 +90,16 @@ interface nsIFlavorDataProvider : nsISup
     */
   void getFlavorData(in nsITransferable aTransferable, in string aFlavor, out nsISupports aData, out unsigned long aDataLen);
 };
 
 
 [scriptable, uuid(97e0c418-1c1e-4106-bad1-9fcb11dff2fe)]
 interface nsITransferable : nsISupports
 {
-  const long kFlavorHasDataProvider = 0;
-
   /**
    * Initializes a transferable object.  This should be called on all
    * transferable objects.  Failure to do so will result in fatal assertions in
    * debug builds.
    *
    * The load context is used to track whether the transferable is storing privacy-
    * sensitive information.  For example, we try to delete data that you copy
    * to the clipboard when you close a Private Browsing window.
--- a/widget/nsTransferable.cpp
+++ b/widget/nsTransferable.cpp
@@ -257,27 +257,28 @@ nsTransferable::GetTransferData(const ch
 
   // 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);
-      if (len == kFlavorHasDataProvider && dataBytes) {
-        // do we have a data provider?
-        nsCOMPtr<nsIFlavorDataProvider> dataProvider =
-          do_QueryInterface(dataBytes);
-        if (dataProvider) {
-          rv = dataProvider->GetFlavorData(
-            this, aFlavor, getter_AddRefs(dataBytes), &len);
-          if (NS_FAILED(rv))
-            break; // the provider failed. fall into the converter code below.
+
+      // 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)) {
+          // The provider failed, fall into the converter code below.
+          break;
         }
       }
+
       if (dataBytes && len > 0) { // XXXmats why is zero length not ok?
         *aDataLen = len;
         dataBytes.forget(aData);
         return NS_OK;
       }
       savedData = dataBytes; // return this if format converter fails
       break;
     }
@@ -290,27 +291,28 @@ nsTransferable::GetTransferData(const ch
     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;
         uint32_t len;
         data.GetData(getter_AddRefs(dataBytes), &len);
-        if (len == kFlavorHasDataProvider && dataBytes) {
-          // do we have a data provider?
-          nsCOMPtr<nsIFlavorDataProvider> dataProvider =
-            do_QueryInterface(dataBytes);
-          if (dataProvider) {
-            rv = dataProvider->GetFlavorData(
-              this, aFlavor, getter_AddRefs(dataBytes), &len);
-            if (NS_FAILED(rv))
-              break; // give up
+
+        // 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;
           }
         }
+
         mFormatConv->Convert(
           data.GetFlavor().get(), dataBytes, len, aFlavor, aData, aDataLen);
         found = true;
         break;
       }
     }
   }