Bug 1293593: Fix crash due to an Objective-C exception when calling getRed:green:blue:alpha on an NSColor instance with an incompatible NSColorSpace. r=mstange

This commit is contained in:
Stephen A Pohl 2016-08-19 23:17:58 -04:00
parent 3daf0f3f96
commit 8f756a0ba5

View File

@ -136,7 +136,14 @@ nsColorPicker::GetNSColorFromHexString(const nsAString& aColor)
nsColorPicker::GetHexStringFromNSColor(NSColor* aColor, nsAString& aResult) nsColorPicker::GetHexStringFromNSColor(NSColor* aColor, nsAString& aResult)
{ {
CGFloat redFloat, greenFloat, blueFloat; CGFloat redFloat, greenFloat, blueFloat;
[aColor getRed: &redFloat green: &greenFloat blue: &blueFloat alpha: nil];
NSColor* color = aColor;
@try {
[color getRed:&redFloat green:&greenFloat blue:&blueFloat alpha: nil];
} @catch (NSException* e) {
color = [color colorUsingColorSpace:[NSColorSpace genericRGBColorSpace]];
[color getRed:&redFloat green:&greenFloat blue:&blueFloat alpha: nil];
}
nsCocoaUtils::GetStringForNSString([NSString stringWithFormat:@"#%02x%02x%02x", nsCocoaUtils::GetStringForNSString([NSString stringWithFormat:@"#%02x%02x%02x",
(int)(redFloat * 255), (int)(redFloat * 255),
@ -162,10 +169,6 @@ nsColorPicker::Open(nsIColorPickerShownCallback* aCallback)
void void
nsColorPicker::Update(NSColor* aColor) nsColorPicker::Update(NSColor* aColor)
{ {
NSColor *color = aColor;
if ([[aColor colorSpaceName] isEqualToString:NSNamedColorSpace]) {
color = [aColor colorUsingColorSpace:[NSColorSpace genericRGBColorSpace]];
}
GetHexStringFromNSColor(aColor, mColor); GetHexStringFromNSColor(aColor, mColor);
mCallback->Update(mColor); mCallback->Update(mColor);
} }