Bug 1503577 - Remove CreateDataFromPrimitive from macOS clipboard code. r=spohl
authorTom Schuster <evilpies@gmail.com>
Fri, 09 Nov 2018 13:24:28 +0000
changeset 445407 2df61d7610d6d819b666e118dd019bbeffb1410f
parent 445406 a668206f59fb119af6b6c02cc2e64aa250d8a088
child 445408 8b1dc4b08aabcfbee62035e5f32392791d74645d
push id35015
push userdluca@mozilla.com
push dateFri, 09 Nov 2018 17:45:20 +0000
treeherdermozilla-central@2f1158e5e0ce [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersspohl
bugs1503577
milestone65.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 1503577 - Remove CreateDataFromPrimitive from macOS clipboard code. r=spohl The previous |if (data)| check is not quite the same as !data.IsEmpty(), because the previous code just checked if the do_QueryInterface failed, but not if the resulting string is empty. Differential Revision: https://phabricator.services.mozilla.com/D10438
widget/cocoa/nsClipboard.mm
--- a/widget/cocoa/nsClipboard.mm
+++ b/widget/cocoa/nsClipboard.mm
@@ -512,48 +512,58 @@ nsClipboard::PasteboardDictFromTransfera
   for (uint32_t i = 0; i < flavors.Length(); i++) {
     nsCString& flavorStr = flavors[i];
 
     MOZ_LOG(sCocoaLog, LogLevel::Info, ("writing out clipboard data of type %s (%d)\n", flavorStr.get(), i));
 
     NSString *pboardType = nil;
 
     if (nsClipboard::IsStringType(flavorStr, &pboardType)) {
-      void* data = nullptr;
       uint32_t dataSize = 0;
       nsCOMPtr<nsISupports> genericDataWrapper;
       rv = aTransferable->GetTransferData(flavorStr.get(), getter_AddRefs(genericDataWrapper), &dataSize);
-      nsPrimitiveHelpers::CreateDataFromPrimitive(flavorStr, genericDataWrapper, &data, dataSize);
+      if (NS_FAILED(rv)) {
+        [pboardType release];
+        continue;
+      }
+
+      nsAutoString data;
+      if (nsCOMPtr<nsISupportsString> text = do_QueryInterface(genericDataWrapper)) {
+        text->GetData(data);
+      }
 
       NSString* nativeString;
-      if (data)
-        nativeString = [NSString stringWithCharacters:(const unichar*)data length:(dataSize / sizeof(char16_t))];
+      if (!data.IsEmpty())
+        nativeString = [NSString stringWithCharacters:(const unichar*)data.get() length:data.Length()];
       else
         nativeString = [NSString string];
-      
+
       // be nice to Carbon apps, normalize the receiver's contents using Form C.
       nativeString = [nativeString precomposedStringWithCanonicalMapping];
 
       [pasteboardOutputDict setObject:nativeString forKey:pboardType];
-      
-      free(data);
     }
     else if (flavorStr.EqualsLiteral(kCustomTypesMime)) {
-      void* data = nullptr;
       uint32_t dataSize = 0;
       nsCOMPtr<nsISupports> genericDataWrapper;
       rv = aTransferable->GetTransferData(flavorStr.get(), getter_AddRefs(genericDataWrapper), &dataSize);
-      nsPrimitiveHelpers::CreateDataFromPrimitive(flavorStr, genericDataWrapper, &data, dataSize);
+      if (NS_FAILED(rv)) {
+        continue;
+      }
 
-      if (data) {
-        NSData* nativeData = [NSData dataWithBytes:data length:dataSize];
+      nsAutoCString data;
+      if (nsCOMPtr<nsISupportsCString> text = do_QueryInterface(genericDataWrapper)) {
+        text->GetData(data);
+      }
+
+      if (!data.IsEmpty()) {
+        NSData* nativeData = [NSData dataWithBytes:data.get() length:data.Length()];
         NSString* customType =
           [UTIHelper stringFromPboardType:kMozCustomTypesPboardType];
         [pasteboardOutputDict setObject:nativeData forKey:customType];
-        free(data);
       }
     }
     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);