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

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Tom Schuster 2018-11-09 13:24:28 +00:00
parent 7e85243d3f
commit 7b787afdfe

View File

@ -517,15 +517,22 @@ nsClipboard::PasteboardDictFromTransferable(nsITransferable* aTransferable)
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];
@ -533,22 +540,25 @@ nsClipboard::PasteboardDictFromTransferable(nsITransferable* aTransferable)
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) ||