[iOSMac] Use UIDocumentPickerViewController for picking files
authoraestes@apple.com <aestes@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 17 Apr 2019 04:45:49 +0000 (04:45 +0000)
committeraestes@apple.com <aestes@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 17 Apr 2019 04:45:49 +0000 (04:45 +0000)
https://bugs.webkit.org/show_bug.cgi?id=196999
<rdar://problem/49961414>

Reviewed by Tim Horton.

* UIProcess/ios/forms/WKFileUploadPanel.mm:
(-[WKFileUploadPanel _showDocumentPickerMenu]):
Changed to present a UIDocumentPickerViewController on iOSMac.

(-[WKFileUploadPanel documentPicker:didPickDocumentsAtURLs:]):
(-[WKFileUploadPanel documentPicker:didPickDocumentAtURL:]):
Replaced a deprecated delegate method implementation.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@244371 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WebKit/ChangeLog
Source/WebKit/UIProcess/ios/forms/WKFileUploadPanel.mm

index 5d9e047..750c74e 100644 (file)
@@ -1,3 +1,19 @@
+2019-04-16  Andy Estes  <aestes@apple.com>
+
+        [iOSMac] Use UIDocumentPickerViewController for picking files
+        https://bugs.webkit.org/show_bug.cgi?id=196999
+        <rdar://problem/49961414>
+
+        Reviewed by Tim Horton.
+
+        * UIProcess/ios/forms/WKFileUploadPanel.mm:
+        (-[WKFileUploadPanel _showDocumentPickerMenu]):
+        Changed to present a UIDocumentPickerViewController on iOSMac.
+
+        (-[WKFileUploadPanel documentPicker:didPickDocumentsAtURLs:]):
+        (-[WKFileUploadPanel documentPicker:didPickDocumentAtURL:]):
+        Replaced a deprecated delegate method implementation.
+
 2019-04-16  Wenson Hsieh  <wenson_hsieh@apple.com>
 
         [iOS] [WebKit2] Add support for honoring -[UIMenuItem dontDismiss]
index f5780d8..2468651 100644 (file)
@@ -404,10 +404,17 @@ static NSSet<NSString *> *UTIsForMIMETypes(NSArray *mimeTypes)
     BOOL containsImageMediaType = !mediaTypes.count || arrayContainsUTIThatConformsTo(mediaTypes, kUTTypeImage);
     BOOL containsVideoMediaType = !mediaTypes.count || arrayContainsUTIThatConformsTo(mediaTypes, kUTTypeMovie);
 
+#if PLATFORM(IOSMAC)
+    // FIXME 49961589: Support picking media with UIImagePickerController
+    BOOL shouldPresentDocumentMenuViewController = NO;
+#else
+    BOOL shouldPresentDocumentMenuViewController = containsImageMediaType || containsVideoMediaType;
+#endif
+
     NSArray *documentTypes = mediaTypes.count ? mediaTypes : @[(__bridge NSString *)kUTTypeItem];
-    if (containsImageMediaType || containsVideoMediaType) {
+    if (shouldPresentDocumentMenuViewController) {
         // FIXME: UIDocumentMenuViewController is deprecated, we should use UIDocumentPickerViewController instead.
-        // FIXME: Support multiple file selection when implemented. <rdar://17177981>
+        // FIXME 49963514: Support multiple file selection
         _documentMenuController = adoptNS([[UIDocumentMenuViewController alloc] _initIgnoringApplicationEntitlementForImportOfTypes:documentTypes]);
         [_documentMenuController setDelegate:self];
 
@@ -426,7 +433,7 @@ static NSSet<NSString *> *UTIsForMIMETypes(NSArray *mimeTypes)
         [self _presentMenuOptionForCurrentInterfaceIdiom:_documentMenuController.get()];
     } else {
         // Image and Video types are not accepted so bypass the menu and open the file picker directly.
-        // FIXME: Support multiple file selection when implemented. <rdar://17177981>
+        // FIXME 49963514: Support multiple file selection
         _documentPickerController = adoptNS([[UIDocumentPickerViewController alloc] initWithDocumentTypes:documentTypes inMode:UIDocumentPickerModeImport]);
         [_documentPickerController setDelegate:self];
         [self _presentFullscreenViewController:_documentPickerController.get() animated:YES];
@@ -544,12 +551,13 @@ IGNORE_WARNINGS_END
 
 #pragma mark - UIDocumentPickerControllerDelegate implementation
 
-IGNORE_WARNINGS_BEGIN("deprecated-implementations")
-- (void)documentPicker:(UIDocumentPickerViewController *)documentPicker didPickDocumentAtURL:(NSURL *)url
-IGNORE_WARNINGS_END
+- (void)documentPicker:(UIDocumentPickerViewController *)controller didPickDocumentsAtURLs:(NSArray <NSURL *> *)urls
 {
+    // FIXME 49963514: Support multiple file selection
+    ASSERT(urls.count == 1);
+    NSURL *url = urls[0];
     [self _dismissDisplayAnimated:YES];
-    [self _chooseFiles:@[url] displayString:url.lastPathComponent iconImage:iconForFile(url)];
+    [self _chooseFiles:urls displayString:url.lastPathComponent iconImage:iconForFile(url)];
 }
 
 - (void)documentPickerWasCancelled:(UIDocumentPickerViewController *)documentPicker