74
74
#endif
75
75
#endif
76
76
77
+ #if !HAVE(UNIFORM_TYPE_IDENTIFERS_FRAMEWORK)
78
+ #import < MobileCoreServices/MobileCoreServices.h>
79
+ #endif
80
+
77
81
enum class WKFileUploadPanelImagePickerType : uint8_t {
78
82
Image = 1 << 0 ,
79
83
Video = 1 << 1 ,
@@ -98,14 +102,18 @@ static bool setContainsUTIThatConformsTo(NSSet<NSString *> *typeIdentifiers, UTT
98
102
}
99
103
#endif
100
104
101
- /* static bool setContainsUTIThatConformsTo(NSSet<NSString *> *typeIdentifiers, CFStringRef conformToUTI)
105
+ static bool setContainsUTIThatConformsTo (NSSet <NSString *> *typeIdentifiers, NSString * conformToUTI)
102
106
{
107
+ #if HAVE(UNIFORM_TYPE_IDENTIFIERS_FRAMEWORK)
108
+ return setContainsUTIThatConformsTo (typeIdentifiers, [UTType typeWithIdentifier: conformToUTI]);
109
+ #else
103
110
for (NSString *uti in typeIdentifiers) {
104
- if ([UTTypeConformance conforms:( __bridge CFStringRef)uti : conformToUTI] )
111
+ if (UTTypeConformsTo (( __bridge CFStringRef)uti, (__bridge CFStringRef) conformToUTI) )
105
112
return true ;
106
113
}
107
114
return false ;
108
- }*/
115
+ #endif
116
+ }
109
117
110
118
#if HAVE(PHOTOS_UI)
111
119
@@ -121,14 +129,18 @@ static bool setContainsUTIThatConformsTo(NSSet<NSString *> *typeIdentifiers, UTT
121
129
}
122
130
#endif
123
131
124
- /* static NSString * firstUTIThatConformsTo(NSArray<NSString *> *typeIdentifiers, CFStringRef conformToUTI)
132
+ static NSString * firstUTIThatConformsTo (NSArray <NSString *> *typeIdentifiers, NSString * conformToUTI)
125
133
{
134
+ #if HAVE(UNIFORM_TYPE_IDENTIFIERS_FRAMEWORK)
135
+ return firstUTIThatConformsTo (typeIdentifiers, [UTType typeWithIdentifier: conformToUTI]);
136
+ #else
126
137
for (NSString *uti in typeIdentifiers) {
127
- if ([UTTypeConformance conforms:( __bridge CFStringRef)uti : conformToUTI] )
138
+ if (UTTypeConformsTo (( __bridge CFStringRef)uti, (__bridge CFStringRef) conformToUTI) )
128
139
return uti;
129
140
}
130
141
return nil ;
131
- }*/
142
+ #endif
143
+ }
132
144
133
145
#endif
134
146
@@ -267,7 +279,20 @@ - (void)start
267
279
_progressController = adoptNS ([allocPUActivityProgressControllerInstance () init ]);
268
280
#endif
269
281
[_progressController setTitle: WEB_UI_STRING_KEY (" Preparing…" , " Preparing (file upload)" , " Title for file upload progress view" )];
270
- [_progressController showAnimated: YES allowDelay: YES ];
282
+ #pragma clang diagnostic push
283
+ #pragma clang diagnostic ignored "-Wundeclared-selector"
284
+ SEL selector = @selector (showAnimated:allowDelay: );
285
+ if ([_progressController respondsToSelector: selector]) {
286
+ BOOL myBoolValue = YES ;
287
+ NSMethodSignature * signature = [[_progressController.get () class ] instanceMethodSignatureForSelector: selector];
288
+ NSInvocation * invocation = [NSInvocation invocationWithMethodSignature: signature];
289
+ [invocation setTarget: _progressController.get ()];
290
+ [invocation setSelector: selector ];
291
+ [invocation setArgument: &myBoolValue atIndex: 2 ];
292
+ [invocation setArgument: &myBoolValue atIndex: 3 ];
293
+ [invocation invoke ];
294
+ }
295
+ #pragma clang diagnostic pop
271
296
272
297
[_progressController setCancellationHandler: makeBlockPtr ([weakSelf = WeakObjCPtr<WKFileUploadMediaTranscoder>(self )] {
273
298
auto strongSelf = weakSelf.get ();
@@ -313,7 +338,14 @@ - (void)_processItemAtIndex:(NSUInteger)index
313
338
return ;
314
339
}
315
340
316
- NSString *fileName = [item.fileURL.lastPathComponent.stringByDeletingPathExtension stringByAppendingPathExtension: UTTypeQuickTimeMovie.preferredFilenameExtension.uppercaseString];
341
+ NSString * QTExtension;
342
+ #if HAVE(UNIFORM_TYPE_IDENTIFIERS_FRAMEWORK)
343
+ QTExtension = UTTypeQuickTimeMovie.preferredFilenameExtension ;
344
+ #else
345
+ static CFStringRef kUTTagClassFilenameExtension ;
346
+ QTExtension = (NSString *)UTTypeCopyPreferredTagWithClass ((__bridge CFStringRef)@" com.apple.quicktime-movie" , kUTTagClassFilenameExtension );
347
+ #endif
348
+ NSString *fileName = [item.fileURL.lastPathComponent.stringByDeletingPathExtension stringByAppendingPathExtension: QTExtension.uppercaseString];
317
349
NSString *filePath = [temporaryDirectory stringByAppendingPathComponent: fileName];
318
350
NSURL *outputURL = [NSURL fileURLWithPath: filePath isDirectory: NO ];
319
351
@@ -357,13 +389,32 @@ - (void)_finishedProcessing
357
389
- (void )_dismissProgress
358
390
{
359
391
[_progressTimer invalidate ];
360
- [_progressController hideAnimated: NO allowDelay: NO ];
392
+ #pragma clang diagnostic push
393
+ #pragma clang diagnostic ignored "-Wundeclared-selector"
394
+ SEL selector = @selector (hideAnimated:allowDelay: );
395
+ if ([_progressController respondsToSelector: selector]) {
396
+ BOOL myBoolValue = NO ;
397
+ NSMethodSignature * signature = [[_progressController.get () class ] instanceMethodSignatureForSelector: selector];
398
+ NSInvocation * invocation = [NSInvocation invocationWithMethodSignature: signature];
399
+ [invocation setTarget: _progressController.get ()];
400
+ [invocation setSelector: selector ];
401
+ [invocation setArgument: &myBoolValue atIndex: 2 ];
402
+ [invocation setArgument: &myBoolValue atIndex: 3 ];
403
+ [invocation invoke ];
404
+ }
405
+ #pragma clang diagnostic pop
361
406
}
362
407
363
408
- (void )_updateProgress : (NSTimer *)timer
364
409
{
365
410
auto currentSessionProgress = [_exportSession progress ];
366
- [_progressController setFractionCompleted: (currentSessionProgress + _processedVideoCount) / _videoCount];
411
+ #pragma clang diagnostic push
412
+ #pragma clang diagnostic ignored "-Wundeclared-selector"
413
+ SEL selector = @selector (setFractionCompleted: );
414
+ if ([_progressController respondsToSelector: selector]) {
415
+ [_progressController performSelector: selector withObject: @((currentSessionProgress + _processedVideoCount) / _videoCount)];
416
+ }
417
+ #pragma clang diagnostic pop
367
418
}
368
419
369
420
- (NSString *)_temporaryDirectoryCreateIfNecessary
@@ -534,9 +585,9 @@ - (void)presentWithParameters:(API::OpenPanelParameters*)parameters resultListen
534
585
if (![_acceptedUTIs count ])
535
586
_allowedImagePickerTypes.add ({ WKFileUploadPanelImagePickerType::Image, WKFileUploadPanelImagePickerType::Video });
536
587
else {
537
- if (setContainsUTIThatConformsTo (_acceptedUTIs.get (), UTTypeImage ))
588
+ if (setContainsUTIThatConformsTo (_acceptedUTIs.get (), @" public.image " ))
538
589
_allowedImagePickerTypes.add ({ WKFileUploadPanelImagePickerType::Image });
539
- if (setContainsUTIThatConformsTo (_acceptedUTIs.get (), UTTypeMovie ))
590
+ if (setContainsUTIThatConformsTo (_acceptedUTIs.get (), @" public.movie " ))
540
591
_allowedImagePickerTypes.add ({ WKFileUploadPanelImagePickerType::Video });
541
592
}
542
593
@@ -623,17 +674,25 @@ - (void)_dismissDisplayAnimated:(BOOL)animated
623
674
return [NSSet set ];
624
675
625
676
if ([mimeType caseInsensitiveCompare: @" image/*" ] == NSOrderedSame)
626
- [mediaTypes addObject: UTTypeImage.identifier ];
677
+ [mediaTypes addObject: @" public.image " ];
627
678
else if ([mimeType caseInsensitiveCompare: @" video/*" ] == NSOrderedSame)
628
- [mediaTypes addObject: UTTypeMovie.identifier ];
679
+ [mediaTypes addObject: @" public.movie " ];
629
680
else if ([mimeType caseInsensitiveCompare: @" audio/*" ] == NSOrderedSame)
630
681
// UIImagePickerController doesn't allow audio-only recording, so show the video
631
682
// recorder for "audio/*".
632
- [mediaTypes addObject: UTTypeMovie.identifier ];
683
+ [mediaTypes addObject: @" public.movie " ];
633
684
else {
685
+ #if HAVE(UNIFORM_TYPE_IDENTIFIERS_FRAMEWORK)
634
686
auto uti = [UTType typeWithMIMEType: mimeType];
635
687
if (uti)
636
688
[mediaTypes addObject: uti.identifier];
689
+ #else
690
+ static CFStringRef kUTTagClassMIMEType ;
691
+ NSString *uti = (NSString *)UTTypeCreatePreferredIdentifierForTag (kUTTagClassMIMEType ,
692
+ (__bridge CFStringRef)mimeType, nullptr );
693
+ if (uti)
694
+ [mediaTypes addObject: uti];
695
+ #endif
637
696
}
638
697
}
639
698
return mediaTypes;
@@ -649,6 +708,7 @@ - (void)_dismissDisplayAnimated:(BOOL)animated
649
708
if ([acceptedMediaTypeUTIs containsObject: availableMediaTypeUTI])
650
709
[mediaTypes addObject: availableMediaTypeUTI];
651
710
else {
711
+ #if HAVE(UNIFORM_TYPE_IDENTIFIERS_FRAMEWORK)
652
712
UTType *availableMediaType = [UTType typeWithIdentifier: availableMediaTypeUTI];
653
713
for (NSString *acceptedMediaTypeUTI in acceptedMediaTypeUTIs) {
654
714
UTType *acceptedMediaType = [UTType typeWithIdentifier: acceptedMediaTypeUTI];
@@ -657,6 +717,15 @@ - (void)_dismissDisplayAnimated:(BOOL)animated
657
717
break ;
658
718
}
659
719
}
720
+ #else
721
+ for (NSString *acceptedMediaTypeUTI in acceptedMediaTypeUTIs) {
722
+ if (UTTypeConformsTo ((__bridge CFStringRef)acceptedMediaTypeUTI,
723
+ (__bridge CFStringRef)availableMediaTypeUTI)) {
724
+ [mediaTypes addObject: availableMediaTypeUTI];
725
+ break ;
726
+ }
727
+ }
728
+ #endif
660
729
}
661
730
}
662
731
@@ -814,7 +883,7 @@ - (void)repositionContextMenuIfNeeded
814
883
- (void )showFilePickerMenu
815
884
{
816
885
NSArray *mediaTypes = [_acceptedUTIs allObjects ];
817
- NSArray *documentTypes = mediaTypes.count ? mediaTypes : @[ UTTypeItem.identifier ];
886
+ NSArray *documentTypes = mediaTypes.count ? mediaTypes : @[ @" public.item " ];
818
887
819
888
_uploadFileManager = adoptNS ([[NSFileManager alloc ] init ]);
820
889
_uploadFileCoordinator = adoptNS ([[NSFileCoordinator alloc ] init ]);
@@ -1212,10 +1281,17 @@ - (void)_uploadItemForJPEGRepresentationOfImage:(UIImage *)image successBlock:(v
1212
1281
- (void )_uploadItemFromMediaInfo:(NSDictionary *)info successBlock:(void (^)(_WKFileUploadItem *))successBlock failureBlock:(void (^)(void ))failureBlock
1213
1282
{
1214
1283
NSString *mediaTypeUTI = [info objectForKey: UIImagePickerControllerMediaType];
1284
+ #if HAVE(UNIFORM_TYPE_IDENTIFIERS_FRAMEWORK)
1215
1285
UTType *mediaType = [UTType typeWithIdentifier: mediaTypeUTI];
1286
+ auto isMovie = [mediaType conformsToType: UTTypeMovie];
1287
+ auto isImage = [mediaType conformsToType: UTTypeImage];
1288
+ #else
1289
+ auto isMovie = UTTypeConformsTo ((__bridge CFStringRef)mediaTypeUTI, (__bridge CFStringRef)@" public.movie" );
1290
+ auto isImage = UTTypeConformsTo ((__bridge CFStringRef)mediaTypeUTI, (__bridge CFStringRef)@" public.image" );
1291
+ #endif
1216
1292
1217
1293
// For videos from the existing library or camera, the media URL will give us a file path.
1218
- if ([mediaType conformsToType: UTTypeMovie] ) {
1294
+ if (isMovie ) {
1219
1295
NSURL *mediaURL = [info objectForKey: UIImagePickerControllerMediaURL];
1220
1296
if (![mediaURL isFileURL ]) {
1221
1297
LOG_ERROR (" WKFileUploadPanel: Expected media URL to be a file path, it was not" );
@@ -1228,8 +1304,8 @@ - (void)_uploadItemFromMediaInfo:(NSDictionary *)info successBlock:(void (^)(_WK
1228
1304
return ;
1229
1305
}
1230
1306
1231
- if (![mediaType conformsToType: UTTypeImage] ) {
1232
- LOG_ERROR (" WKFileUploadPanel: Unexpected media type. Expected image or video, got: %@" , mediaType );
1307
+ if (!isImage ) {
1308
+ LOG_ERROR (" WKFileUploadPanel: Unexpected media type. Expected image or video, got: %@" , mediaTypeUTI );
1233
1309
ASSERT_NOT_REACHED ();
1234
1310
failureBlock ();
1235
1311
return ;
0 commit comments