Bug 1629533: Fix an issue that prevented some icons from drawing in the macOS share menu. r=mstange
authorStephen A Pohl <spohl.mozilla.bugs@gmail.com>
Fri, 01 May 2020 22:30:46 +0000
changeset 527863 a13d22a758e1c458d98dfe6b5bc670019b87a939
parent 527862 cedec222408d3ea6af5f1cbaa9fa041d503a250c
child 527864 85fd9ac6ca7905cf6cc0ed0dd824a28d28fe504a
push id114832
push userspohl@mozilla.com
push dateMon, 04 May 2020 13:44:59 +0000
treeherderautoland@a13d22a758e1 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmstange
bugs1629533
milestone77.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 1629533: Fix an issue that prevented some icons from drawing in the macOS share menu. r=mstange 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()));