Merge branch 'charlesmchen/paste'

pull/1/head
Matthew Chen 9 years ago
commit 32ac0fb7c9

@ -1,4 +1,6 @@
// Copyright © 2016 Open Whisper Systems. All rights reserved. //
// Copyright (c) 2017 Open Whisper Systems. All rights reserved.
//
extern NSString *const OWSMimeTypeApplicationOctetStream; extern NSString *const OWSMimeTypeApplicationOctetStream;
extern NSString *const OWSMimeTypeImagePng; extern NSString *const OWSMimeTypeImagePng;
@ -44,4 +46,9 @@ extern NSString *const OWSMimeTypeImagePng;
+ (BOOL)getIsSupportedTypeFromImage:(UIImage *)image; + (BOOL)getIsSupportedTypeFromImage:(UIImage *)image;
#endif #endif
+ (NSSet<NSString *> *)supportedVideoUTITypes;
+ (NSSet<NSString *> *)supportedAudioUTITypes;
+ (NSSet<NSString *> *)supportedImageUTITypes;
+ (NSSet<NSString *> *)supportedAnimatedImageUTITypes;
@end @end

@ -1,6 +1,13 @@
//
// Copyright (c) 2017 Open Whisper Systems. All rights reserved.
//
#import "MIMETypeUtil.h" #import "MIMETypeUtil.h"
#if TARGET_OS_IPHONE #if TARGET_OS_IPHONE
#import "UIImage+contentTypes.h" #import "UIImage+contentTypes.h"
#import <MobileCoreServices/MobileCoreServices.h>
#else
#import <CoreServices/CoreServices.h>
#endif #endif
NSString *const OWSMimeTypeApplicationOctetStream = @"application/octet-stream"; NSString *const OWSMimeTypeApplicationOctetStream = @"application/octet-stream";
@ -9,17 +16,25 @@ NSString *const OWSMimeTypeImagePng = @"image/png";
@implementation MIMETypeUtil @implementation MIMETypeUtil
+ (NSDictionary *)supportedVideoMIMETypesToExtensionTypes { + (NSDictionary *)supportedVideoMIMETypesToExtensionTypes {
return @{ static NSDictionary *result = nil;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
result = @{
@"video/3gpp" : @"3gp", @"video/3gpp" : @"3gp",
@"video/3gpp2" : @"3g2", @"video/3gpp2" : @"3g2",
@"video/mp4" : @"mp4", @"video/mp4" : @"mp4",
@"video/quicktime" : @"mov", @"video/quicktime" : @"mov",
@"video/x-m4v" : @"m4v" @"video/x-m4v" : @"m4v"
}; };
});
return result;
} }
+ (NSDictionary *)supportedAudioMIMETypesToExtensionTypes { + (NSDictionary *)supportedAudioMIMETypesToExtensionTypes {
return @{ static NSDictionary *result = nil;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
result = @{
@"audio/aac" : @"m4a", @"audio/aac" : @"m4a",
@"audio/x-m4p" : @"m4p", @"audio/x-m4p" : @"m4p",
@"audio/x-m4b" : @"m4b", @"audio/x-m4b" : @"m4b",
@ -39,10 +54,15 @@ NSString *const OWSMimeTypeImagePng = @"image/png";
@"audio/3gpp2" : @"3g2", @"audio/3gpp2" : @"3g2",
@"audio/3gpp" : @"3gp" @"audio/3gpp" : @"3gp"
}; };
});
return result;
} }
+ (NSDictionary *)supportedImageMIMETypesToExtensionTypes { + (NSDictionary *)supportedImageMIMETypesToExtensionTypes {
return @{ static NSDictionary *result = nil;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
result = @{
@"image/jpeg" : @"jpeg", @"image/jpeg" : @"jpeg",
@"image/pjpeg" : @"jpeg", @"image/pjpeg" : @"jpeg",
OWSMimeTypeImagePng : @"png", OWSMimeTypeImagePng : @"png",
@ -51,23 +71,38 @@ NSString *const OWSMimeTypeImagePng = @"image/png";
@"image/bmp" : @"bmp", @"image/bmp" : @"bmp",
@"image/x-windows-bmp" : @"bmp" @"image/x-windows-bmp" : @"bmp"
}; };
});
return result;
} }
+ (NSDictionary *)supportedAnimatedMIMETypesToExtensionTypes { + (NSDictionary *)supportedAnimatedMIMETypesToExtensionTypes {
return @{ static NSDictionary *result = nil;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
result = @{
@"image/gif" : @"gif", @"image/gif" : @"gif",
}; };
});
return result;
} }
+ (NSDictionary *)supportedBinaryDataMIMETypesToExtensionTypes + (NSDictionary *)supportedBinaryDataMIMETypesToExtensionTypes
{ {
return @{ static NSDictionary *result = nil;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
result = @{
OWSMimeTypeApplicationOctetStream : @"dat", OWSMimeTypeApplicationOctetStream : @"dat",
}; };
});
return result;
} }
+ (NSDictionary *)supportedVideoExtensionTypesToMIMETypes { + (NSDictionary *)supportedVideoExtensionTypesToMIMETypes {
return @{ static NSDictionary *result = nil;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
result = @{
@"3gp" : @"video/3gpp", @"3gp" : @"video/3gpp",
@"3gpp" : @"video/3gpp", @"3gpp" : @"video/3gpp",
@"3gp2" : @"video/3gpp2", @"3gp2" : @"video/3gpp2",
@ -77,9 +112,15 @@ NSString *const OWSMimeTypeImagePng = @"image/png";
@"mqv" : @"video/quicktime", @"mqv" : @"video/quicktime",
@"m4v" : @"video/x-m4v" @"m4v" : @"video/x-m4v"
}; };
});
return result;
} }
+ (NSDictionary *)supportedAudioExtensionTypesToMIMETypes { + (NSDictionary *)supportedAudioExtensionTypesToMIMETypes {
return @{ static NSDictionary *result = nil;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
result = @{
@"3gp" : @"audio/3gpp", @"3gp" : @"audio/3gpp",
@"3gpp" : @"@audio/3gpp", @"3gpp" : @"@audio/3gpp",
@"3g2" : @"audio/3gpp2", @"3g2" : @"audio/3gpp2",
@ -100,10 +141,15 @@ NSString *const OWSMimeTypeImagePng = @"image/png";
@"m4b" : @"audio/x-m4b", @"m4b" : @"audio/x-m4b",
@"m4p" : @"audio/x-m4p" @"m4p" : @"audio/x-m4p"
}; };
});
return result;
} }
+ (NSDictionary *)supportedImageExtensionTypesToMIMETypes { + (NSDictionary *)supportedImageExtensionTypesToMIMETypes {
return @{ static NSDictionary *result = nil;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
result = @{
@"png" : OWSMimeTypeImagePng, @"png" : OWSMimeTypeImagePng,
@"x-png" : OWSMimeTypeImagePng, @"x-png" : OWSMimeTypeImagePng,
@"jfif" : @"image/jpeg", @"jfif" : @"image/jpeg",
@ -116,12 +162,19 @@ NSString *const OWSMimeTypeImagePng = @"image/png";
@"tif" : @"image/tiff", @"tif" : @"image/tiff",
@"tiff" : @"image/tiff" @"tiff" : @"image/tiff"
}; };
});
return result;
} }
+ (NSDictionary *)supportedAnimatedExtensionTypesToMIMETypes { + (NSDictionary *)supportedAnimatedExtensionTypesToMIMETypes {
return @{ static NSDictionary *result = nil;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
result = @{
@"gif" : @"image/gif", @"gif" : @"image/gif",
}; };
});
return result;
} }
+ (BOOL)isSupportedVideoMIMEType:(NSString *)contentType { + (BOOL)isSupportedVideoMIMEType:(NSString *)contentType {
@ -303,4 +356,64 @@ NSString *const OWSMimeTypeImagePng = @"image/png";
#endif #endif
+ (NSString *)utiTypeForMIMEType:(NSString *)mimeType
{
CFStringRef utiType
= UTTypeCreatePreferredIdentifierForTag(kUTTagClassMIMEType, (__bridge CFStringRef)mimeType, NULL);
return (__bridge_transfer NSString *)utiType;
}
+ (NSSet<NSString *> *)utiTypesForMIMETypes:(NSArray *)mimeTypes
{
NSMutableSet<NSString *> *result = [NSMutableSet new];
for (NSString *mimeType in mimeTypes) {
[result addObject:[self utiTypeForMIMEType:mimeType]];
}
return result;
}
+ (NSSet<NSString *> *)supportedVideoUTITypes
{
OWSAssert([NSThread isMainThread]);
static NSSet<NSString *> *result = nil;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
result = [self utiTypesForMIMETypes:[self supportedVideoMIMETypesToExtensionTypes].allKeys];
});
return result;
}
+ (NSSet<NSString *> *)supportedAudioUTITypes
{
OWSAssert([NSThread isMainThread]);
static NSSet<NSString *> *result = nil;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
result = [self utiTypesForMIMETypes:[self supportedAudioMIMETypesToExtensionTypes].allKeys];
});
return result;
}
+ (NSSet<NSString *> *)supportedImageUTITypes
{
OWSAssert([NSThread isMainThread]);
static NSSet<NSString *> *result = nil;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
result = [self utiTypesForMIMETypes:[self supportedImageMIMETypesToExtensionTypes].allKeys];
});
return result;
}
+ (NSSet<NSString *> *)supportedAnimatedImageUTITypes
{
OWSAssert([NSThread isMainThread]);
static NSSet<NSString *> *result = nil;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
result = [self utiTypesForMIMETypes:[self supportedAnimatedMIMETypesToExtensionTypes].allKeys];
});
return result;
}
@end @end

Loading…
Cancel
Save