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
Родитель 7e85243d3f
Коммит 7b787afdfe
1 изменённых файлов: 22 добавлений и 12 удалений

Просмотреть файл

@ -517,38 +517,48 @@ 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];
// 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) ||