Bug 1310193 - Remove wrapping of nsISupports as nsISupportsInterfacePointer in transferables. r=smaug
authorNeil Deakin <enndeakin@gmail.com>
Sun, 07 Oct 2018 16:33:07 +0200
changeset 498408 15fe5851f113defcc86285e94ed79687031a5d56
parent 498407 556ba29c2e6c5af0ba72aaf67f8c81f96e2a6672
child 498409 107add19c310179d442ce6649d2848364ab5fb86
push id1864
push userffxbld-merge
push dateMon, 03 Dec 2018 15:51:40 +0000
treeherdermozilla-release@f040763d99ad [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssmaug
bugs1310193
milestone64.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1310193 - Remove wrapping of nsISupports as nsISupportsInterfacePointer in transferables. r=smaug
devtools/client/webconsole/test/mochitest/browser_jsterm_screenshot_command_clipboard.js
devtools/shared/screenshot/save.js
dom/base/nsContentUtils.cpp
dom/base/nsCopySupport.cpp
dom/events/DataTransfer.cpp
toolkit/components/extensions/parent/ext-clipboard.js
widget/cocoa/nsClipboard.mm
widget/gtk/nsClipboard.cpp
widget/gtk/nsDragService.cpp
widget/windows/nsDataObj.cpp
--- a/devtools/client/webconsole/test/mochitest/browser_jsterm_screenshot_command_clipboard.js
+++ b/devtools/client/webconsole/test/mochitest/browser_jsterm_screenshot_command_clipboard.js
@@ -171,21 +171,18 @@ async function getImageSizeFromClipboard
   ok(data.value, "screenshot exists");
   ok(dataLength.value > 0, "screenshot has length");
 
   let image = data.value;
   let dataURI = `data:${flavor};base64,`;
 
   // Due to the differences in how images could be stored in the clipboard the
   // checks below are needed. The clipboard could already provide the image as
-  // byte streams, but also as pointer, or as image container. If it's not
-  // possible obtain a byte stream, the function returns `null`.
-  if (image instanceof Ci.nsISupportsInterfacePointer) {
-    image = image.data;
-  }
+  // byte streams or as image container. If it's not possible obtain a
+  // byte stream, the function throws.
 
   if (image instanceof Ci.imgIContainer) {
     image = Cc["@mozilla.org/image/tools;1"]
               .getService(Ci.imgITools)
               .encodeImage(image, flavor);
   }
 
   if (image instanceof Ci.nsIInputStream) {
--- a/devtools/shared/screenshot/save.js
+++ b/devtools/shared/screenshot/save.js
@@ -178,25 +178,23 @@ async function save(args, image) {
 function saveToClipboard(base64URI) {
   try {
     const imageTools = Cc["@mozilla.org/image/tools;1"]
                        .getService(Ci.imgITools);
 
     const base64Data = base64URI.replace("data:image/png;base64,", "");
 
     const image = atob(base64Data);
-    const imgPtr = Cc["@mozilla.org/supports-interface-pointer;1"]
-                   .createInstance(Ci.nsISupportsInterfacePointer);
-    imgPtr.data = imageTools.decodeImageFromBuffer(image, image.length, "image/png");
+    const img = imageTools.decodeImageFromBuffer(image, image.length, "image/png");
 
     const transferable = Cc["@mozilla.org/widget/transferable;1"]
                      .createInstance(Ci.nsITransferable);
     transferable.init(null);
     transferable.addDataFlavor("image/png");
-    transferable.setTransferData("image/png", imgPtr, -1);
+    transferable.setTransferData("image/png", img, -1);
 
     Services.clipboard.setData(transferable, null, Services.clipboard.kGlobalClipboard);
     return L10N.getStr("screenshotCopied");
   } catch (ex) {
     console.error(ex);
     return L10N.getStr("screenshotErrorCopying");
   }
 }
--- a/dom/base/nsContentUtils.cpp
+++ b/dom/base/nsContentUtils.cpp
@@ -7748,24 +7748,17 @@ nsContentUtils::IPCTransferableToTransfe
       NS_ENSURE_SUCCESS(rv, rv);
     } else if (item.data().type() == IPCDataTransferData::TShmem) {
       if (nsContentUtils::IsFlavorImage(item.flavor())) {
         nsCOMPtr<imgIContainer> imageContainer;
         rv = nsContentUtils::DataTransferItemToImage(item,
                                                      getter_AddRefs(imageContainer));
         NS_ENSURE_SUCCESS(rv, rv);
 
-        nsCOMPtr<nsISupportsInterfacePointer> imgPtr =
-          do_CreateInstance(NS_SUPPORTS_INTERFACE_POINTER_CONTRACTID);
-        NS_ENSURE_TRUE(imgPtr, NS_ERROR_FAILURE);
-
-        rv = imgPtr->SetData(imageContainer);
-        NS_ENSURE_SUCCESS(rv, rv);
-
-        aTransferable->SetTransferData(item.flavor().get(), imgPtr, sizeof(nsISupports*));
+        aTransferable->SetTransferData(item.flavor().get(), imageContainer, sizeof(nsISupports*));
       } else {
         nsCOMPtr<nsISupportsCString> dataWrapper =
           do_CreateInstance(NS_SUPPORTS_CSTRING_CONTRACTID, &rv);
         NS_ENSURE_SUCCESS(rv, rv);
 
         // The buffer contains the terminating null.
         Shmem itemData = item.data().get_Shmem();
         const nsDependentCSubstring text(itemData.get<char>(),
@@ -8010,22 +8003,16 @@ nsContentUtils::TransferableToIPCTransfe
 
           Shmem dataAsShmem = ConvertToShmem(aChild, aParent, dataAsString);
           if (!dataAsShmem.IsReadable() || !dataAsShmem.Size<char>()) {
             continue;
           }
 
           item->data() = dataAsShmem;
         } else {
-          nsCOMPtr<nsISupportsInterfacePointer> sip =
-            do_QueryInterface(data);
-          if (sip) {
-            sip->GetData(getter_AddRefs(data));
-          }
-
           // Images to be pasted on the clipboard are nsIInputStreams
           nsCOMPtr<nsIInputStream> stream(do_QueryInterface(data));
           if (stream) {
             IPCDataTransferItem* item = aIPCDataTransfer->items().AppendElement();
             item->flavor() = flavorStr;
 
             nsCString imageData;
             NS_ConsumeStream(stream, UINT32_MAX, imageData);
--- a/dom/base/nsCopySupport.cpp
+++ b/dom/base/nsCopySupport.cpp
@@ -416,25 +416,18 @@ nsCopySupport::ImageCopy(nsIImageLoading
                                           getter_AddRefs(imgRequest));
     NS_ENSURE_TRUE(image, NS_ERROR_FAILURE);
 
 #ifdef XP_WIN
     rv = AppendImagePromise(trans, imgRequest, aImageElement);
     NS_ENSURE_SUCCESS(rv, rv);
 #endif
 
-    nsCOMPtr<nsISupportsInterfacePointer>
-      imgPtr(do_CreateInstance(NS_SUPPORTS_INTERFACE_POINTER_CONTRACTID, &rv));
-    NS_ENSURE_SUCCESS(rv, rv);
-
-    rv = imgPtr->SetData(image);
-    NS_ENSURE_SUCCESS(rv, rv);
-
     // copy the image data onto the transferable
-    rv = trans->SetTransferData(kNativeImageMime, imgPtr,
+    rv = trans->SetTransferData(kNativeImageMime, image,
                                 sizeof(nsISupports*));
     NS_ENSURE_SUCCESS(rv, rv);
   }
 
   // get clipboard
   nsCOMPtr<nsIClipboard> clipboard(do_GetService(kCClipboardCID, &rv));
   NS_ENSURE_SUCCESS(rv, rv);
 
--- a/dom/events/DataTransfer.cpp
+++ b/dom/events/DataTransfer.cpp
@@ -1156,29 +1156,19 @@ DataTransfer::ConvertFromVariant(nsIVari
     }
 
     nsCOMPtr<nsIFlavorDataProvider> fdp = do_QueryInterface(data);
     if (fdp) {
       // for flavour data providers, use kFlavorHasDataProvider (which has the
       // value 0) as the length.
       fdp.forget(aSupports);
       *aLength = nsITransferable::kFlavorHasDataProvider;
-    }
-    else {
-      // wrap the item in an nsISupportsInterfacePointer
-      nsCOMPtr<nsISupportsInterfacePointer> ptrSupports =
-        do_CreateInstance(NS_SUPPORTS_INTERFACE_POINTER_CONTRACTID);
-      if (!ptrSupports) {
-        return false;
-      }
-
-      ptrSupports->SetData(data);
-      ptrSupports.forget(aSupports);
-
-      *aLength = sizeof(nsISupportsInterfacePointer *);
+    } else {
+      data.forget(aSupports);
+      *aLength = sizeof(nsISupports *);
     }
 
     return true;
   }
 
   nsAutoString str;
   nsresult rv = aVariant->GetAsAString(str);
   if (NS_FAILED(rv)) {
--- a/toolkit/components/extensions/parent/ext-clipboard.js
+++ b/toolkit/components/extensions/parent/ext-clipboard.js
@@ -1,79 +1,74 @@
 /* -*- Mode: indent-tabs-mode: nil; js-indent-level: 2 -*- */
 /* vim: set sts=2 sw=2 et tw=80: */
 "use strict";
 
 XPCOMUtils.defineLazyServiceGetter(this, "imgTools",
                                    "@mozilla.org/image/tools;1", "imgITools");
 
-const SupportsInterfacePointer = Components.Constructor(
-  "@mozilla.org/supports-interface-pointer;1", "nsISupportsInterfacePointer");
 const Transferable = Components.Constructor(
   "@mozilla.org/widget/transferable;1", "nsITransferable");
 
 this.clipboard = class extends ExtensionAPI {
   getAPI(context) {
     return {
       clipboard: {
         async setImageData(imageData, imageType) {
           if (AppConstants.platform == "android") {
             return Promise.reject({message: "Writing images to the clipboard is not supported on Android"});
           }
           let mimeType = `image/${imageType}`;
-          let container;
+          let img;
           try {
-            container = imgTools.decodeImageFromArrayBuffer(imageData, mimeType);
+            img = imgTools.decodeImageFromArrayBuffer(imageData, mimeType);
           } catch (e) {
             return Promise.reject({message: `Data is not a valid ${imageType} image`});
           }
 
           // Other applications can only access the copied image once the data
           // is exported via the platform-specific clipboard APIs:
           // nsClipboard::SelectionGetEvent (widget/gtk/nsClipboard.cpp)
           // nsClipboard::PasteDictFromTransferable (widget/cocoa/nsClipboard.mm)
           // nsDataObj::GetDib (widget/windows/nsDataObj.cpp)
           //
           // The common protocol for exporting a nsITransferable as an image is:
           // - Use nsITransferable::GetTransferData to fetch the stored data.
-          // - QI a nsISupportsInterfacePointer and get the underlying pointer.
           // - QI imgIContainer on the pointer.
           // - Convert the image to the native clipboard format.
           //
           // Below we create a nsITransferable in the above format.
-          let imgPtr = new SupportsInterfacePointer();
-          imgPtr.data = container;
           let transferable = new Transferable();
           transferable.init(null);
           transferable.addDataFlavor(mimeType);
 
           // Internal consumers expect the image data to be stored as a
           // nsIInputStream. On Linux and Windows, pasted data is directly
           // retrieved from the system's native clipboard, and made available
           // as a nsIInputStream.
           //
           // On macOS, nsClipboard::GetNativeClipboardData (nsClipboard.mm) uses
           // a cached copy of nsITransferable if available, e.g. when the copy
           // was initiated by the same browser instance. Consequently, the
-          // transferable still holds a nsISupportsInterfacePointer pointer
+          // transferable still holds a imgIContainer pointer
           // instead of a nsIInputStream, and logic that assumes the data to be
           // a nsIInputStream instance fails.
           // For example HTMLEditor::InsertObject (HTMLEditorDataTransfer.cpp)
           // and DataTransferItem::FillInExternalData (DataTransferItem.cpp).
           //
           // As a work-around, we force nsClipboard::GetNativeClipboardData to
           // ignore the cached image data, by passing zero as the length
           // parameter to transferable.setTransferData. When the length is zero,
           // nsITransferable::GetTransferData will return NS_ERROR_FAILURE and
           // conveniently nsClipboard::GetNativeClipboardData will then fall
           // back to retrieving the data directly from the system's clipboard.
           //
           // Note that the length itself is not really used if the data is not
           // a string type, so the actual value does not matter.
-          transferable.setTransferData(mimeType, imgPtr, 0);
+          transferable.setTransferData(mimeType, img, 0);
 
           Services.clipboard.setData(
             transferable, null, Services.clipboard.kGlobalClipboard);
         },
       },
     };
   }
 };
--- a/widget/cocoa/nsClipboard.mm
+++ b/widget/cocoa/nsClipboard.mm
@@ -582,24 +582,18 @@ nsClipboard::PasteboardDictFromTransfera
       }
     }
     else if (flavorStr.EqualsLiteral(kPNGImageMime) || flavorStr.EqualsLiteral(kJPEGImageMime) ||
              flavorStr.EqualsLiteral(kJPGImageMime) || flavorStr.EqualsLiteral(kGIFImageMime) ||
              flavorStr.EqualsLiteral(kNativeImageMime)) {
       uint32_t dataSize = 0;
       nsCOMPtr<nsISupports> transferSupports;
       aTransferable->GetTransferData(flavorStr.get(), getter_AddRefs(transferSupports), &dataSize);
-      nsCOMPtr<nsISupportsInterfacePointer> ptrPrimitive(do_QueryInterface(transferSupports));
-      if (!ptrPrimitive)
-        continue;
 
-      nsCOMPtr<nsISupports> primitiveData;
-      ptrPrimitive->GetData(getter_AddRefs(primitiveData));
-
-      nsCOMPtr<imgIContainer> image(do_QueryInterface(primitiveData));
+      nsCOMPtr<imgIContainer> image(do_QueryInterface(transferSupports));
       if (!image) {
         NS_WARNING("Image isn't an imgIContainer in transferable");
         continue;
       }
 
       RefPtr<SourceSurface> surface =
         image->GetFrame(imgIContainer::FRAME_CURRENT,
                         imgIContainer::FLAG_SYNC_DECODE);
@@ -643,25 +637,16 @@ nsClipboard::PasteboardDictFromTransfera
       nsCOMPtr<nsISupports> genericFile;
       rv = aTransferable->GetTransferData(flavorStr.get(), getter_AddRefs(genericFile), &len);
       if (NS_FAILED(rv)) {
         continue;
       }
 
       nsCOMPtr<nsIFile> file(do_QueryInterface(genericFile));
       if (!file) {
-        nsCOMPtr<nsISupportsInterfacePointer> ptr(do_QueryInterface(genericFile));
-
-        if (ptr) {
-          ptr->GetData(getter_AddRefs(genericFile));
-          file = do_QueryInterface(genericFile);
-        }
-      }
-
-      if (!file) {
         continue;
       }
 
       nsAutoString fileURI;
       rv = file->GetPath(fileURI);
       if (NS_FAILED(rv)) {
         continue;
       }
--- a/widget/gtk/nsClipboard.cpp
+++ b/widget/gtk/nsClipboard.cpp
@@ -531,29 +531,28 @@ nsClipboard::SelectionGetEvent(GtkClipbo
     }
 
     // Check to see if the selection data is an image type
     if (gtk_targets_include_image(&selectionTarget, 1, TRUE)) {
         // Look through our transfer data for the image
         static const char* const imageMimeTypes[] = {
             kNativeImageMime, kPNGImageMime, kJPEGImageMime, kJPGImageMime, kGIFImageMime };
         nsCOMPtr<nsISupports> imageItem;
-        nsCOMPtr<nsISupportsInterfacePointer> ptrPrimitive;
-        for (uint32_t i = 0; !ptrPrimitive && i < ArrayLength(imageMimeTypes); i++) {
+        nsCOMPtr<imgIContainer> image;
+        for (uint32_t i = 0; i < ArrayLength(imageMimeTypes); i++) {
             rv = trans->GetTransferData(imageMimeTypes[i], getter_AddRefs(imageItem), &len);
-            ptrPrimitive = do_QueryInterface(imageItem);
+            image = do_QueryInterface(imageItem);
+            if (image) {
+                break;
+            }
         }
-        if (!ptrPrimitive)
+
+        if (!image) { // Not getting an image for an image mime type!?
             return;
-
-        nsCOMPtr<nsISupports> primitiveData;
-        ptrPrimitive->GetData(getter_AddRefs(primitiveData));
-        nsCOMPtr<imgIContainer> image(do_QueryInterface(primitiveData));
-        if (!image) // Not getting an image for an image mime type!?
-            return;
+        }
 
         GdkPixbuf* pixbuf = nsImageToPixbuf::ImageToPixbuf(image);
         if (!pixbuf)
             return;
 
         gtk_selection_data_set_pixbuf(aSelectionData, pixbuf);
         g_object_unref(pixbuf);
         return;
--- a/widget/gtk/nsDragService.cpp
+++ b/widget/gtk/nsDragService.cpp
@@ -1586,30 +1586,17 @@ CreateUriList(nsIArray *items, gchar **t
             } else {
                 // There is no uri available.  If there is a file available,
                 // create a uri from the file.
                 nsCOMPtr<nsISupports> data;
                 rv = item->GetTransferData(kFileMime,
                                            getter_AddRefs(data),
                                            &tmpDataLen);
                 if (NS_SUCCEEDED(rv)) {
-                    nsCOMPtr<nsIFile> file = do_QueryInterface(data);
-                    if (!file) {
-                        // Sometimes the file is wrapped in a
-                        // nsISupportsInterfacePointer. See bug 1310193 for
-                        // removing this distinction.
-                        nsCOMPtr<nsISupportsInterfacePointer> ptr =
-                          do_QueryInterface(data);
-                        if (ptr) {
-                            ptr->GetData(getter_AddRefs(data));
-                            file = do_QueryInterface(data);
-                        }
-                    }
-
-                    if (file) {
+                    if (nsCOMPtr<nsIFile> file = do_QueryInterface(data)) {
                         nsCOMPtr<nsIURI> fileURI;
                         NS_NewFileURI(getter_AddRefs(fileURI), file);
                         if (fileURI) {
                             nsAutoCString uristring;
                             fileURI->GetSpec(uristring);
                             g_string_append(uriList, uristring.get());
                             g_string_append(uriList, "\r\n");
                         }
--- a/widget/windows/nsDataObj.cpp
+++ b/widget/windows/nsDataObj.cpp
@@ -896,28 +896,16 @@ nsDataObj::GetDib(const nsACString& inFl
                   FORMATETC &aFormat,
                   STGMEDIUM & aSTG)
 {
   ULONG result = E_FAIL;
   uint32_t len = 0;
   nsCOMPtr<nsISupports> genericDataWrapper;
   mTransferable->GetTransferData(PromiseFlatCString(inFlavor).get(), getter_AddRefs(genericDataWrapper), &len);
   nsCOMPtr<imgIContainer> image ( do_QueryInterface(genericDataWrapper) );
-  if ( !image ) {
-    // Check if the image was put in an nsISupportsInterfacePointer wrapper.
-    // This might not be necessary any more, but could be useful for backwards
-    // compatibility.
-    nsCOMPtr<nsISupportsInterfacePointer> ptr(do_QueryInterface(genericDataWrapper));
-    if ( ptr ) {
-      nsCOMPtr<nsISupports> supports;
-      ptr->GetData(getter_AddRefs(supports));
-      image = do_QueryInterface(supports);
-    }
-  }
-  
   if ( image ) {
     // use the |nsImageToClipboard| helper class to build up a bitmap. We now own
     // the bits, and pass them back to the OS in |aSTG|.
     nsImageToClipboard converter(image, aFormat.cfFormat == CF_DIBV5);
     HANDLE bits = nullptr;
     nsresult rv = converter.GetPicture ( &bits );
     if ( NS_SUCCEEDED(rv) && bits ) {
       aSTG.hGlobal = bits;
@@ -1461,27 +1449,16 @@ HRESULT nsDataObj::DropFile(FORMATETC& a
 {
   nsresult rv;
   uint32_t len = 0;
   nsCOMPtr<nsISupports> genericDataWrapper;
 
   mTransferable->GetTransferData(kFileMime, getter_AddRefs(genericDataWrapper),
                                  &len);
   nsCOMPtr<nsIFile> file ( do_QueryInterface(genericDataWrapper) );
-
-  if (!file)
-  {
-    nsCOMPtr<nsISupportsInterfacePointer> ptr(do_QueryInterface(genericDataWrapper));
-    if (ptr) {
-      nsCOMPtr<nsISupports> supports;
-      ptr->GetData(getter_AddRefs(supports));
-      file = do_QueryInterface(supports);
-    }
-  }
-
   if (!file)
     return E_FAIL;
 
   aSTG.tymed = TYMED_HGLOBAL;
   aSTG.pUnkForRelease = nullptr;
 
   nsAutoString path;
   rv = file->GetPath(path);
@@ -1526,29 +1503,16 @@ HRESULT nsDataObj::DropImage(FORMATETC& 
 {
   nsresult rv;
   if (!mCachedTempFile) {
     uint32_t len = 0;
     nsCOMPtr<nsISupports> genericDataWrapper;
 
     mTransferable->GetTransferData(kNativeImageMime, getter_AddRefs(genericDataWrapper), &len);
     nsCOMPtr<imgIContainer> image(do_QueryInterface(genericDataWrapper));
-
-    if (!image) {
-      // Check if the image was put in an nsISupportsInterfacePointer wrapper.
-      // This might not be necessary any more, but could be useful for backwards
-      // compatibility.
-      nsCOMPtr<nsISupportsInterfacePointer> ptr(do_QueryInterface(genericDataWrapper));
-      if (ptr) {
-        nsCOMPtr<nsISupports> supports;
-        ptr->GetData(getter_AddRefs(supports));
-        image = do_QueryInterface(supports);
-      }
-    }
-
     if (!image) 
       return E_FAIL;
 
     // Use the clipboard helper class to build up a memory bitmap.
     nsImageToClipboard converter(image);
     HANDLE bits = nullptr;
     rv = converter.GetPicture(&bits); // Clipboard routines return a global handle we own.