Skip to content

Commit

Permalink
Compile iOS 13
Browse files Browse the repository at this point in the history
  • Loading branch information
Matthew Benedict authored and Matthew Benedict committed Apr 23, 2023
1 parent 3b2d162 commit b298686
Show file tree
Hide file tree
Showing 8 changed files with 146 additions and 28 deletions.
11 changes: 9 additions & 2 deletions Source/CyberCore/platform/ios/PasteboardIOS.mm
Original file line number Diff line number Diff line change
Expand Up @@ -304,8 +304,15 @@ static void readURLAlongsideAttachmentIfNecessary(PasteboardWebContentReader& re

static bool shouldTreatAsAttachmentByDefault(const String& typeIdentifier)
{
auto type = [UTType typeWithIdentifier:typeIdentifier];
return [type conformsToType:UTTypeVCard] || [type conformsToType:UTTypePDF];
if (@available(iOS 14.0, *)) {
auto type = [UTType typeWithIdentifier:typeIdentifier];
return [type conformsToType:UTTypeVCard] || [type conformsToType:UTTypePDF];
} else {
ALLOW_DEPRECATED_DECLARATIONS_BEGIN
CFStringRef type = (__bridge CFStringRef)typeIdentifier.utf8().data();
return UTTypeConformsTo(type, kUTTypeVCard) || UTTypeConformsTo(type, kUTTypePDF);
ALLOW_DEPRECATED_DECLARATIONS_END
}
}

static bool prefersAttachmentRepresentation(const PasteboardItemInfo& info)
Expand Down
2 changes: 1 addition & 1 deletion Source/CyberKit/Shared/API/Cocoa/_WKHitTestResult.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

#import <CyberKit/WKFoundation.h>

#if TARGET_OS_OSX || TARGET_OS_IOS
#if TARGET_OS_OSX || (TARGET_OS_IOS && __IPHONE_OS_VERSION_MIN_REQUIRED >= 130400)

#import <Foundation/Foundation.h>

Expand Down
14 changes: 14 additions & 0 deletions Source/CyberKit/UIProcess/Extensions/Cocoa/WebExtensionCocoa.mm
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,10 @@
SOFT_LINK(CoreSVG, CGSVGDocumentRelease, void, (CGSVGDocumentRef document), (document))
#endif

#if !HAVE(UNIFORM_TYPE_IDENTIFIERS_FRAMEWORK)
#import <MobileCoreServices/MobileCoreServices.h>
#endif

namespace CyberKit {

static NSString * const manifestVersionManifestKey = @"manifest_version";
Expand Down Expand Up @@ -747,10 +751,20 @@ static _WKWebExtensionError toAPI(WebExtension::Error error)

NSURL *imageURL = resourceFileURLForPath(imagePath);

#if HAVE(UNIFORM_TYPE_IDENTIFIERS_FRAMEWORK)
UTType *imageType;
[imageURL getResourceValue:&imageType forKey:NSURLContentTypeKey error:nil];

if ([imageType.identifier isEqualToString:UTTypeSVG.identifier]) {
#else
ALLOW_DEPRECATED_DECLARATIONS_BEGIN
static CFStringRef kUTTagClassFilenameExtension;
static CFStringRef kUTTypeSVG;
CFStringRef fileExtension = (__bridge CFStringRef)((NSURL *)imageURL).pathExtension;
CFStringRef UTI = UTTypeCreatePreferredIdentifierForTag(kUTTagClassFilenameExtension, fileExtension, nullptr);
if (UTTypeConformsTo(UTI, kUTTypeSVG)) {
ALLOW_DEPRECATED_DECLARATIONS_END
#endif
#if PLATFORM(MAC)
#if USE(NSIMAGE_FOR_SVG_SUPPORT)
return [[NSImage alloc] initWithData:imageData];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@
#import <UniformTypeIdentifiers/UTType.h>
#import <wtf/BlockPtr.h>

#if !HAVE(UNIFORM_TYPE_IDENTIFIERS_FRAMEWORK)
#import <MobileCoreServices/MobileCoreServices.h>
#endif

namespace CyberKit {

class WebPageProxy;
Expand Down Expand Up @@ -91,7 +95,19 @@
return;
}

NSString *mimeType = [UTType typeWithFilenameExtension:((NSURL *)requestURL).pathExtension].preferredMIMEType;
NSString *mimeType;
#if HAVE(UNIFORM_TYPE_IDENTIFIERS_FRAMEWORK)
mimeType = [UTType typeWithFilenameExtension:((NSURL *)requestURL).pathExtension].preferredMIMEType;
#else
ALLOW_DEPRECATED_DECLARATIONS_BEGIN
static CFStringRef kUTTagClassFilenameExtension;
static CFStringRef kUTTagClassMIMEType;
CFStringRef fileExtension = (__bridge CFStringRef)((NSURL *)requestURL).pathExtension;
CFStringRef UTI = UTTypeCreatePreferredIdentifierForTag(kUTTagClassFilenameExtension, fileExtension, nullptr);
mimeType = (__bridge_transfer NSString *)UTTypeCopyPreferredTagWithClass(UTI, kUTTagClassMIMEType);
CFRelease(UTI);
ALLOW_DEPRECATED_DECLARATIONS_END
#endif
if (!mimeType)
mimeType = @"application/octet-stream";

Expand Down
8 changes: 6 additions & 2 deletions Source/CyberKit/UIProcess/ios/WKContentViewInteraction.mm
Original file line number Diff line number Diff line change
Expand Up @@ -5357,7 +5357,9 @@ - (void)updateFocusedElementValueAsColor:(UIColor *)value

_page->setFocusedElementValue(_focusedElementInformation.elementContext, valueAsString);
_focusedElementInformation.value = valueAsString;
#if ENABLE(INPUT_TYPE_COLOR)
_focusedElementInformation.colorValue = color;
#endif
}

- (void)updateFocusedElementSelectedIndex:(uint32_t)index allowsMultipleSelection:(bool)allowsMultipleSelection
Expand Down Expand Up @@ -10902,7 +10904,7 @@ - (NSInteger)numberOfPreviewItemsInPreviewController:(QLPreviewController *)cont
{
ASSERT(controller == _visualSearchPreviewController);
ASSERT(!index);
auto item = adoptNS([PAL::allocQLItemInstance() initWithDataProvider:self contentType:UTTypeTIFF.identifier previewTitle:_visualSearchPreviewTitle.get()]);
auto item = adoptNS([PAL::allocQLItemInstance() initWithDataProvider:self contentType:@"public.tiff" previewTitle:_visualSearchPreviewTitle.get()]);
if ([item respondsToSelector:@selector(setPreviewOptions:)]) {
auto previewOptions = adoptNS([[NSMutableDictionary alloc] initWithCapacity:2]);
if (_visualSearchPreviewImageURL)
Expand All @@ -10920,7 +10922,7 @@ - (NSInteger)numberOfPreviewItemsInPreviewController:(QLPreviewController *)cont
- (NSData *)provideDataForItem:(QLItem *)item
{
ASSERT(_visualSearchPreviewImage);
return CyberKit::transcode([_visualSearchPreviewImage CGImage], (__bridge CFStringRef)UTTypeTIFF.identifier).autorelease();
return CyberKit::transcode([_visualSearchPreviewImage CGImage], (__bridge CFStringRef)@"public.tiff").autorelease();
}

#pragma mark - WKActionSheetAssistantDelegate
Expand Down Expand Up @@ -11686,8 +11688,10 @@ - (BOOL)selectFormAccessoryHasCheckedItemAtRow:(long)rowIndex

- (void)setSelectedColorForColorPicker:(UIColor *)color
{
#if ENABLE(INPUT_TYPE_COLOR)
if ([_inputPeripheral isKindOfClass:[WKFormColorControl class]])
[(WKFormColorControl *)_inputPeripheral selectColor:color];
#endif
}

- (NSString *)textContentTypeForTesting
Expand Down
114 changes: 95 additions & 19 deletions Source/CyberKit/UIProcess/ios/forms/WKFileUploadPanel.mm
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,10 @@
#endif
#endif

#if !HAVE(UNIFORM_TYPE_IDENTIFERS_FRAMEWORK)
#import <MobileCoreServices/MobileCoreServices.h>
#endif

enum class WKFileUploadPanelImagePickerType : uint8_t {
Image = 1 << 0,
Video = 1 << 1,
Expand All @@ -98,14 +102,18 @@ static bool setContainsUTIThatConformsTo(NSSet<NSString *> *typeIdentifiers, UTT
}
#endif

/*static bool setContainsUTIThatConformsTo(NSSet<NSString *> *typeIdentifiers, CFStringRef conformToUTI)
static bool setContainsUTIThatConformsTo(NSSet<NSString *> *typeIdentifiers, NSString* conformToUTI)
{
#if HAVE(UNIFORM_TYPE_IDENTIFIERS_FRAMEWORK)
return setContainsUTIThatConformsTo(typeIdentifiers, [UTType typeWithIdentifier:conformToUTI]);
#else
for (NSString *uti in typeIdentifiers) {
if ([UTTypeConformance conforms:(__bridge CFStringRef)uti :conformToUTI])
if (UTTypeConformsTo((__bridge CFStringRef)uti, (__bridge CFStringRef)conformToUTI))
return true;
}
return false;
}*/
#endif
}

#if HAVE(PHOTOS_UI)

Expand All @@ -121,14 +129,18 @@ static bool setContainsUTIThatConformsTo(NSSet<NSString *> *typeIdentifiers, UTT
}
#endif

/*static NSString * firstUTIThatConformsTo(NSArray<NSString *> *typeIdentifiers, CFStringRef conformToUTI)
static NSString * firstUTIThatConformsTo(NSArray<NSString *> *typeIdentifiers, NSString* conformToUTI)
{
#if HAVE(UNIFORM_TYPE_IDENTIFIERS_FRAMEWORK)
return firstUTIThatConformsTo(typeIdentifiers, [UTType typeWithIdentifier:conformToUTI]);
#else
for (NSString *uti in typeIdentifiers) {
if ([UTTypeConformance conforms:(__bridge CFStringRef)uti :conformToUTI])
if (UTTypeConformsTo((__bridge CFStringRef)uti, (__bridge CFStringRef)conformToUTI))
return uti;
}
return nil;
}*/
#endif
}

#endif

Expand Down Expand Up @@ -267,7 +279,20 @@ - (void)start
_progressController = adoptNS([allocPUActivityProgressControllerInstance() init]);
#endif
[_progressController setTitle:WEB_UI_STRING_KEY("Preparing…", "Preparing (file upload)", "Title for file upload progress view")];
[_progressController showAnimated:YES allowDelay:YES];
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wundeclared-selector"
SEL selector = @selector(showAnimated:allowDelay:);
if ([_progressController respondsToSelector:selector]) {
BOOL myBoolValue = YES;
NSMethodSignature* signature = [[_progressController.get() class] instanceMethodSignatureForSelector:selector];
NSInvocation* invocation = [NSInvocation invocationWithMethodSignature: signature];
[invocation setTarget: _progressController.get()];
[invocation setSelector: selector ];
[invocation setArgument: &myBoolValue atIndex: 2];
[invocation setArgument: &myBoolValue atIndex: 3];
[invocation invoke];
}
#pragma clang diagnostic pop

[_progressController setCancellationHandler:makeBlockPtr([weakSelf = WeakObjCPtr<WKFileUploadMediaTranscoder>(self)] {
auto strongSelf = weakSelf.get();
Expand Down Expand Up @@ -313,7 +338,14 @@ - (void)_processItemAtIndex:(NSUInteger)index
return;
}

NSString *fileName = [item.fileURL.lastPathComponent.stringByDeletingPathExtension stringByAppendingPathExtension:UTTypeQuickTimeMovie.preferredFilenameExtension.uppercaseString];
NSString* QTExtension;
#if HAVE(UNIFORM_TYPE_IDENTIFIERS_FRAMEWORK)
QTExtension = UTTypeQuickTimeMovie.preferredFilenameExtension;
#else
static CFStringRef kUTTagClassFilenameExtension;
QTExtension = (NSString *)UTTypeCopyPreferredTagWithClass((__bridge CFStringRef)@"com.apple.quicktime-movie", kUTTagClassFilenameExtension);
#endif
NSString *fileName = [item.fileURL.lastPathComponent.stringByDeletingPathExtension stringByAppendingPathExtension:QTExtension.uppercaseString];
NSString *filePath = [temporaryDirectory stringByAppendingPathComponent:fileName];
NSURL *outputURL = [NSURL fileURLWithPath:filePath isDirectory:NO];

Expand Down Expand Up @@ -357,13 +389,32 @@ - (void)_finishedProcessing
- (void)_dismissProgress
{
[_progressTimer invalidate];
[_progressController hideAnimated:NO allowDelay:NO];
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wundeclared-selector"
SEL selector = @selector(hideAnimated:allowDelay:);
if ([_progressController respondsToSelector:selector]) {
BOOL myBoolValue = NO;
NSMethodSignature* signature = [[_progressController.get() class] instanceMethodSignatureForSelector:selector];
NSInvocation* invocation = [NSInvocation invocationWithMethodSignature: signature];
[invocation setTarget: _progressController.get()];
[invocation setSelector: selector ];
[invocation setArgument: &myBoolValue atIndex: 2];
[invocation setArgument: &myBoolValue atIndex: 3];
[invocation invoke];
}
#pragma clang diagnostic pop
}

- (void)_updateProgress:(NSTimer *)timer
{
auto currentSessionProgress = [_exportSession progress];
[_progressController setFractionCompleted:(currentSessionProgress + _processedVideoCount) / _videoCount];
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wundeclared-selector"
SEL selector = @selector(setFractionCompleted:);
if ([_progressController respondsToSelector:selector]) {
[_progressController performSelector:selector withObject:@((currentSessionProgress + _processedVideoCount) / _videoCount)];
}
#pragma clang diagnostic pop
}

- (NSString *)_temporaryDirectoryCreateIfNecessary
Expand Down Expand Up @@ -534,9 +585,9 @@ - (void)presentWithParameters:(API::OpenPanelParameters*)parameters resultListen
if (![_acceptedUTIs count])
_allowedImagePickerTypes.add({ WKFileUploadPanelImagePickerType::Image, WKFileUploadPanelImagePickerType::Video });
else {
if (setContainsUTIThatConformsTo(_acceptedUTIs.get(), UTTypeImage))
if (setContainsUTIThatConformsTo(_acceptedUTIs.get(), @"public.image"))
_allowedImagePickerTypes.add({ WKFileUploadPanelImagePickerType::Image });
if (setContainsUTIThatConformsTo(_acceptedUTIs.get(), UTTypeMovie))
if (setContainsUTIThatConformsTo(_acceptedUTIs.get(), @"public.movie"))
_allowedImagePickerTypes.add({ WKFileUploadPanelImagePickerType::Video });
}

Expand Down Expand Up @@ -623,17 +674,25 @@ - (void)_dismissDisplayAnimated:(BOOL)animated
return [NSSet set];

if ([mimeType caseInsensitiveCompare:@"image/*"] == NSOrderedSame)
[mediaTypes addObject:UTTypeImage.identifier];
[mediaTypes addObject:@"public.image"];
else if ([mimeType caseInsensitiveCompare:@"video/*"] == NSOrderedSame)
[mediaTypes addObject:UTTypeMovie.identifier];
[mediaTypes addObject:@"public.movie"];
else if ([mimeType caseInsensitiveCompare:@"audio/*"] == NSOrderedSame)
// UIImagePickerController doesn't allow audio-only recording, so show the video
// recorder for "audio/*".
[mediaTypes addObject:UTTypeMovie.identifier];
[mediaTypes addObject:@"public.movie"];
else {
#if HAVE(UNIFORM_TYPE_IDENTIFIERS_FRAMEWORK)
auto uti = [UTType typeWithMIMEType:mimeType];
if (uti)
[mediaTypes addObject:uti.identifier];
#else
static CFStringRef kUTTagClassMIMEType;
NSString *uti = (NSString *)UTTypeCreatePreferredIdentifierForTag(kUTTagClassMIMEType,
(__bridge CFStringRef)mimeType, nullptr);
if (uti)
[mediaTypes addObject:uti];
#endif
}
}
return mediaTypes;
Expand All @@ -649,6 +708,7 @@ - (void)_dismissDisplayAnimated:(BOOL)animated
if ([acceptedMediaTypeUTIs containsObject:availableMediaTypeUTI])
[mediaTypes addObject:availableMediaTypeUTI];
else {
#if HAVE(UNIFORM_TYPE_IDENTIFIERS_FRAMEWORK)
UTType *availableMediaType = [UTType typeWithIdentifier:availableMediaTypeUTI];
for (NSString *acceptedMediaTypeUTI in acceptedMediaTypeUTIs) {
UTType *acceptedMediaType = [UTType typeWithIdentifier:acceptedMediaTypeUTI];
Expand All @@ -657,6 +717,15 @@ - (void)_dismissDisplayAnimated:(BOOL)animated
break;
}
}
#else
for (NSString *acceptedMediaTypeUTI in acceptedMediaTypeUTIs) {
if (UTTypeConformsTo((__bridge CFStringRef)acceptedMediaTypeUTI,
(__bridge CFStringRef)availableMediaTypeUTI)) {
[mediaTypes addObject:availableMediaTypeUTI];
break;
}
}
#endif
}
}

Expand Down Expand Up @@ -814,7 +883,7 @@ - (void)repositionContextMenuIfNeeded
- (void)showFilePickerMenu
{
NSArray *mediaTypes = [_acceptedUTIs allObjects];
NSArray *documentTypes = mediaTypes.count ? mediaTypes : @[ UTTypeItem.identifier ];
NSArray *documentTypes = mediaTypes.count ? mediaTypes : @[ @"public.item" ];

_uploadFileManager = adoptNS([[NSFileManager alloc] init]);
_uploadFileCoordinator = adoptNS([[NSFileCoordinator alloc] init]);
Expand Down Expand Up @@ -1212,10 +1281,17 @@ - (void)_uploadItemForJPEGRepresentationOfImage:(UIImage *)image successBlock:(v
- (void)_uploadItemFromMediaInfo:(NSDictionary *)info successBlock:(void (^)(_WKFileUploadItem *))successBlock failureBlock:(void (^)(void))failureBlock
{
NSString *mediaTypeUTI = [info objectForKey:UIImagePickerControllerMediaType];
#if HAVE(UNIFORM_TYPE_IDENTIFIERS_FRAMEWORK)
UTType *mediaType = [UTType typeWithIdentifier:mediaTypeUTI];
auto isMovie = [mediaType conformsToType:UTTypeMovie];
auto isImage = [mediaType conformsToType:UTTypeImage];
#else
auto isMovie = UTTypeConformsTo((__bridge CFStringRef)mediaTypeUTI, (__bridge CFStringRef)@"public.movie");
auto isImage = UTTypeConformsTo((__bridge CFStringRef)mediaTypeUTI, (__bridge CFStringRef)@"public.image");
#endif

// For videos from the existing library or camera, the media URL will give us a file path.
if ([mediaType conformsToType:UTTypeMovie]) {
if (isMovie) {
NSURL *mediaURL = [info objectForKey:UIImagePickerControllerMediaURL];
if (![mediaURL isFileURL]) {
LOG_ERROR("WKFileUploadPanel: Expected media URL to be a file path, it was not");
Expand All @@ -1228,8 +1304,8 @@ - (void)_uploadItemFromMediaInfo:(NSDictionary *)info successBlock:(void (^)(_WK
return;
}

if (![mediaType conformsToType:UTTypeImage]) {
LOG_ERROR("WKFileUploadPanel: Unexpected media type. Expected image or video, got: %@", mediaType);
if (!isImage) {
LOG_ERROR("WKFileUploadPanel: Unexpected media type. Expected image or video, got: %@", mediaTypeUTI);
ASSERT_NOT_REACHED();
failureBlock();
return;
Expand Down
2 changes: 1 addition & 1 deletion Source/WTF/wtf/PlatformEnable.h
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@
#define ENABLE_GEOLOCATION 0
#endif

#if !defined(ENABLE_INPUT_TYPE_COLOR)
#if !defined(ENABLE_INPUT_TYPE_COLOR) && (!PLATFORM(IOS) || __IPHONE_OS_VERSION_MIN_REQUIRED >= 140000)
#define ENABLE_INPUT_TYPE_COLOR 1
#endif

Expand Down
5 changes: 3 additions & 2 deletions Source/WTF/wtf/PlatformHave.h
Original file line number Diff line number Diff line change
Expand Up @@ -1080,7 +1080,7 @@
#define HAVE_AVSAMPLEBUFFERVIDEOOUTPUT 1
#endif

#if PLATFORM(IOS)
#if PLATFORM(IOS) && (!PLATFORM(IOS) || __IPHONE_OS_VERSION_MIN_REQUIRED >= 140000)
#define HAVE_PHOTOS_UI 1
// FIXME (102246762): Remove this have (and make it true everywhere) when possible.
#if __has_include(<PhotosUICore/PXActivityProgressController.h>)
Expand Down Expand Up @@ -1143,7 +1143,8 @@
#define HAVE_UNIFIED_SPEECHSYNTHESIS_FIX_FOR_81465164 1
#endif

#if PLATFORM(COCOA)
#if PLATFORM(COCOA) \
&& (!PLATFORM(IOS) || __IPHONE_OS_VERSION_MIN_REQUIRED >= 140000)
#define HAVE_UNIFORM_TYPE_IDENTIFIERS_FRAMEWORK 1
#endif

Expand Down

0 comments on commit b298686

Please sign in to comment.