Bug 1629533: Fix an issue that prevented some icons from drawing in the macOS share menu. r=mstange a=pascalc
authorStephen A Pohl <spohl.mozilla.bugs@gmail.com>
Fri, 01 May 2020 22:30:46 +0000
changeset 594938 9fcdff1da854a46f48646f2f87d38eea74714847
parent 594937 939b5bba13d8724008c2eb286132a637a68d4774
child 594939 54ca458874c29dc4d7bec908d511929a6c9dfe53
push id2335
push userffxbld-merge
push dateMon, 25 May 2020 13:47:24 +0000
treeherdermozilla-release@69ca1d06f46a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmstange, pascalc
bugs1629533
milestone77.0
Bug 1629533: Fix an issue that prevented some icons from drawing in the macOS share menu. r=mstange a=pascalc Differential Revision: https://phabricator.services.mozilla.com/D71871
widget/cocoa/nsMacSharingService.mm
--- a/widget/cocoa/nsMacSharingService.mm
+++ b/widget/cocoa/nsMacSharingService.mm
@@ -73,22 +73,22 @@ NSString* const openSharingSubpaneProtoc
 - (void)dealloc {
   [mShareActivity release];
   [super dealloc];
 }
 
 @end
 
 static NSString* NSImageToBase64(const NSImage* aImage) {
-  NSRect rect = NSMakeRect(0, 0, aImage.size.width, aImage.size.height);
-  NSImageRep* bestRep = [aImage bestRepresentationForRect:rect context:nil hints:nil];
-  NSData* tiffData = [NSBitmapImageRep TIFFRepresentationOfImageRepsInArray:@[ bestRep ]];
-  NSBitmapImageRep* bitmapRep = [NSBitmapImageRep imageRepWithData:tiffData];
+  CGImageRef cgRef = [aImage CGImageForProposedRect:nil context:nil hints:nil];
+  NSBitmapImageRep* bitmapRep = [[NSBitmapImageRep alloc] initWithCGImage:cgRef];
+  [bitmapRep setSize:[aImage size]];
   NSData* imageData = [bitmapRep representationUsingType:NSPNGFileType properties:@{}];
   NSString* base64Encoded = [imageData base64EncodedStringWithOptions:0];
+  [bitmapRep release];
   return [NSString stringWithFormat:@"data:image/png;base64,%@", base64Encoded];
 }
 
 static void SetStrAttribute(JSContext* aCx, JS::Rooted<JSObject*>& aObj, const char* aKey,
                             NSString* aVal) {
   nsAutoString strVal;
   mozilla::CopyCocoaStringToXPCOMString(aVal, strVal);
   JS::Rooted<JSString*> title(aCx, JS_NewUCStringCopyZ(aCx, strVal.get()));