⚠ Archived content — this site is no longer maintained.   Current WebKit documentation is at docs.webkit.org.

Changeset 181476 in webkit


Ignore:
Timestamp:
Mar 13, 2015, 1:08:56 AM (11 years ago)
Author:
jhoneycutt@apple.com
Message:

Use UIDocumentMenuViewController to allow selection of files from
iCloud Drive in WKFileUploadPanel

Part of <https://bugs.webkit.org/show_bug.cgi?id=142596> WebKit on
iOS should support file upload from iCloud Drive
<rdar://problem/12178991>

Reviewed by Andy Estes.

  • Platform/spi/ios/UIKitSPI.h:

Include UIDocumentMenuViewController_Private.h if it exists. If not,
declare this new SPI.

  • UIProcess/ios/forms/WKFileUploadPanel.mm:

(fallbackIconForFile):
Create a UIDocumentInteractionController for the file, and return a
thumbnail image from its smallest icon.

(iconForImageFile):
If we can get a UIImage from the file, create a thumbnail from it.
Otherwise, call fallbackIconForFile().

(iconForVideoFile):
Code moved from -[_WKVideoFileUploadItem displayImage].

(iconForFile):
Get the file's extension, and get the extension's preferred UTI. If the
UTI is an image type, call iconForImageFile(). If it's a video type,
call iconForVideoFile(). Otherwise, return the fallback icon.

(-[_WKFileUploadItem initWithFileURL:]):
Added an initializer that takes a file URL.

(-[_WKFileUploadItem fileURL]):
(-[_WKImageFileUploadItem initWithFileURL:originalImage:]):
(-[_WKVideoFileUploadItem displayImage]):
(WKFileUploadPanel):
Inherit from UIDocumentPickerDelegate and UIDocumentMenuDelegate. Add
an ivar for the document menu controller.

(-[WKFileUploadPanel dealloc]):
(-[WKFileUploadPanel presentWithParameters:resultListener:]):
If instances of UIDocumentMenuViewController respond to
-_setIgnoreApplicationEntitlementForImport:, meaning we can disable the
assertion that the current app has the iCloud Documents entitlement,
then show the document picker menu. Otherwise, show the current source
selection UI. The runtime check will be removed when a newer UIKit is
available.

(UTIsForMIMETypes):
Return the UTIs for the <input> element's "accept" attribute's MIME
type list.

(-[WKFileUploadPanel _mediaTypesForPickerSourceType:]):
Call UTIsForMIMETypes(). Fall back to available source types for this
picker type.

(-[WKFileUploadPanel _documentPickerMenuMediaTypes]):
Call UTIsForMIMETypes(). Fall back to the all-encompassing
"public.item" UTI.

(-[WKFileUploadPanel _photoLibraryButtonLabel]):
(-[WKFileUploadPanel _cameraButtonLabel]):
Factored out of -_showMediaSourceSelectionSheet. Return the
appropriate label for the camera button, based on whether it can take a
photo or video, or return nil if the camera is not available.

(-[WKFileUploadPanel _showMediaSourceSelectionSheet]):
Changed to use -_cameraButtonLabel and
-_presentForCurrentInterfaceIdiom:.

(-[WKFileUploadPanel _showDocumentPickerMenu]):
Create a UIDocumentMenuViewController, and populate it with options to
open the photo library or take a picture or video. If iCloud Drive or
other document sources are available, they will be added automatically.

(-[WKFileUploadPanel _presentForCurrentInterfaceIdiom:]):
(-[WKFileUploadPanel documentMenu:didPickDocumentPicker:]):
(-[WKFileUploadPanel documentMenuWasCancelled:]):
(-[WKFileUploadPanel documentPicker:didPickDocumentAtURL:]):
(-[WKFileUploadPanel documentPickerWasCancelled:]):
(-[WKFileUploadPanel _uploadItemFromMediaInfo:successBlock:failureBlock:]):

(-[_WKImageFileUploadItem initWithFilePath:originalImage:]): Deleted.
(-[_WKImageFileUploadItem fileURL]): Deleted.
(-[_WKVideoFileUploadItem initWithFilePath:mediaURL:]): Deleted.
(-[_WKVideoFileUploadItem fileURL]): Deleted.

Location:
trunk/Source/WebKit2
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebKit2/ChangeLog

    r181448 r181476  
     12015-03-12  Jon Honeycutt  <jhoneycutt@apple.com>
     2
     3        Use UIDocumentMenuViewController to allow selection of files from
     4        iCloud Drive in WKFileUploadPanel
     5
     6        Part of <https://bugs.webkit.org/show_bug.cgi?id=142596> WebKit on
     7        iOS should support file upload from iCloud Drive
     8        <rdar://problem/12178991>
     9
     10        Reviewed by Andy Estes.
     11
     12        * Platform/spi/ios/UIKitSPI.h:
     13        Include UIDocumentMenuViewController_Private.h if it exists. If not,
     14        declare this new SPI.
     15
     16        * UIProcess/ios/forms/WKFileUploadPanel.mm:
     17        (fallbackIconForFile):
     18        Create a UIDocumentInteractionController for the file, and return a
     19        thumbnail image from its smallest icon.
     20
     21        (iconForImageFile):
     22        If we can get a UIImage from the file, create a thumbnail from it.
     23        Otherwise, call fallbackIconForFile().
     24
     25        (iconForVideoFile):
     26        Code moved from -[_WKVideoFileUploadItem displayImage].
     27
     28        (iconForFile):
     29        Get the file's extension, and get the extension's preferred UTI. If the
     30        UTI is an image type, call iconForImageFile(). If it's a video type,
     31        call iconForVideoFile(). Otherwise, return the fallback icon.
     32
     33        (-[_WKFileUploadItem initWithFileURL:]):
     34        Added an initializer that takes a file URL.
     35
     36        (-[_WKFileUploadItem fileURL]):
     37        (-[_WKImageFileUploadItem initWithFileURL:originalImage:]):
     38        (-[_WKVideoFileUploadItem displayImage]):
     39        (WKFileUploadPanel):
     40        Inherit from UIDocumentPickerDelegate and UIDocumentMenuDelegate. Add
     41        an ivar for the document menu controller.
     42
     43        (-[WKFileUploadPanel dealloc]):
     44        (-[WKFileUploadPanel presentWithParameters:resultListener:]):
     45        If instances of UIDocumentMenuViewController respond to
     46        -_setIgnoreApplicationEntitlementForImport:, meaning we can disable the
     47        assertion that the current app has the iCloud Documents entitlement,
     48        then show the document picker menu. Otherwise, show the current source
     49        selection UI. The runtime check will be removed when a newer UIKit is
     50        available.
     51
     52        (UTIsForMIMETypes):
     53        Return the UTIs for the <input> element's "accept" attribute's MIME
     54        type list.
     55
     56        (-[WKFileUploadPanel _mediaTypesForPickerSourceType:]):
     57        Call UTIsForMIMETypes(). Fall back to available source types for this
     58        picker type.
     59
     60        (-[WKFileUploadPanel _documentPickerMenuMediaTypes]):
     61        Call UTIsForMIMETypes(). Fall back to the all-encompassing
     62        "public.item" UTI.
     63
     64        (-[WKFileUploadPanel _photoLibraryButtonLabel]):
     65        (-[WKFileUploadPanel _cameraButtonLabel]):
     66        Factored out of -_showMediaSourceSelectionSheet. Return the
     67        appropriate label for the camera button, based on whether it can take a
     68        photo or video, or return nil if the camera is not available.
     69
     70        (-[WKFileUploadPanel _showMediaSourceSelectionSheet]):
     71        Changed to use -_cameraButtonLabel and
     72        -_presentForCurrentInterfaceIdiom:.
     73
     74        (-[WKFileUploadPanel _showDocumentPickerMenu]):
     75        Create a UIDocumentMenuViewController, and populate it with options to
     76        open the photo library or take a picture or video. If iCloud Drive or
     77        other document sources are available, they will be added automatically.
     78
     79        (-[WKFileUploadPanel _presentForCurrentInterfaceIdiom:]):
     80        (-[WKFileUploadPanel documentMenu:didPickDocumentPicker:]):
     81        (-[WKFileUploadPanel documentMenuWasCancelled:]):
     82        (-[WKFileUploadPanel documentPicker:didPickDocumentAtURL:]):
     83        (-[WKFileUploadPanel documentPickerWasCancelled:]):
     84        (-[WKFileUploadPanel _uploadItemFromMediaInfo:successBlock:failureBlock:]):
     85
     86        (-[_WKImageFileUploadItem initWithFilePath:originalImage:]): Deleted.
     87        (-[_WKImageFileUploadItem fileURL]): Deleted.
     88        (-[_WKVideoFileUploadItem initWithFilePath:mediaURL:]): Deleted.
     89        (-[_WKVideoFileUploadItem fileURL]): Deleted.
     90
    1912015-03-11  Enrica Casucci  <enrica@apple.com>
    292
  • trunk/Source/WebKit2/Platform/spi/ios/UIKitSPI.h

    r180965 r181476  
    7070#import <UIKit/_UINavigationParallaxTransition.h>
    7171
     72// FIXME: Unconditionally include this file when a new SDK is available. <rdar://problem/20150072>
     73#if defined(__has_include) && __has_include(<UIKit/UIDocumentMenuViewController_Private.h>)
     74#import <UIKit/UIDocumentMenuViewController_Private.h>
     75#else
     76@interface UIDocumentMenuViewController (Details)
     77@property (nonatomic, assign, setter = _setIgnoreApplicationEntitlementForImport:, getter = _ignoreApplicationEntitlementForImport) BOOL _ignoreApplicationEntitlementForImport;
     78@end
     79#endif
     80
    7281#else
    7382
     
    659668@end
    660669
     670@interface UIDocumentMenuViewController (Details)
     671@property (nonatomic, assign, setter = _setIgnoreApplicationEntitlementForImport:, getter = _ignoreApplicationEntitlementForImport) BOOL _ignoreApplicationEntitlementForImport;
     672@end
     673
    661674#endif // USE(APPLE_INTERNAL_SDK)
    662675
  • trunk/Source/WebKit2/UIProcess/ios/forms/WKFileUploadPanel.mm

    r178080 r181476  
    5858#define kCMTimeZero getkCMTimeZero()
    5959
    60 
    61 #pragma mark - _WKFileUploadItem
     60#pragma mark - Icon generation
    6261
    6362static CGRect squareCropRectForSize(CGSize size)
     
    106105}
    107106
     107static UIImage* fallbackIconForFile(NSURL *file)
     108{
     109    ASSERT_ARG(file, [file isFileURL]);
     110
     111    UIDocumentInteractionController *interactionController = [UIDocumentInteractionController interactionControllerWithURL:file];
     112    return thumbnailSizedImageForImage(interactionController.icons[0]);
     113}
     114
     115static UIImage* iconForImageFile(NSURL *file)
     116{
     117    ASSERT_ARG(file, [file isFileURL]);
     118
     119    if (UIImage *image = [UIImage imageWithContentsOfFile:file.path])
     120        return thumbnailSizedImageForImage(image);
     121
     122    LOG_ERROR("WKFileUploadPanel: Error creating thumbnail image for image: %@", file);
     123    return fallbackIconForFile(file);
     124}
     125
     126static UIImage* iconForVideoFile(NSURL *file)
     127{
     128    ASSERT_ARG(file, [file isFileURL]);
     129
     130    RetainPtr<AVURLAsset> asset = adoptNS([allocAVURLAssetInstance() initWithURL:file options:nil]);
     131    RetainPtr<AVAssetImageGenerator> generator = adoptNS([allocAVAssetImageGeneratorInstance() initWithAsset:asset.get()]);
     132    [generator setAppliesPreferredTrackTransform:YES];
     133
     134    NSError *error = nil;
     135    RetainPtr<CGImageRef> imageRef = adoptCF([generator copyCGImageAtTime:kCMTimeZero actualTime:nil error:&error]);
     136    if (!imageRef) {
     137        LOG_ERROR("WKFileUploadPanel: Error creating image for video '%@': %@", file, error);
     138        return fallbackIconForFile(file);
     139    }
     140
     141    RetainPtr<UIImage> image = adoptNS([[UIImage alloc] initWithCGImage:imageRef.get()]);
     142    return thumbnailSizedImageForImage(image.get());
     143}
     144
     145static UIImage* iconForFile(NSURL *file)
     146{
     147    ASSERT_ARG(file, [file isFileURL]);
     148
     149    NSString *fileExtension = file.pathExtension;
     150    if (!fileExtension.length)
     151        return nil;
     152
     153    RetainPtr<CFStringRef> fileUTI = adoptCF(UTTypeCreatePreferredIdentifierForTag(kUTTagClassFilenameExtension, (CFStringRef)fileExtension, 0));
     154
     155    if (UTTypeConformsTo(fileUTI.get(), kUTTypeImage))
     156        return iconForImageFile(file);
     157
     158    if (UTTypeConformsTo(fileUTI.get(), kUTTypeMovie))
     159        return iconForVideoFile(file);
     160
     161    return fallbackIconForFile(file);
     162}
     163
     164
     165#pragma mark - _WKFileUploadItem
    108166
    109167@interface _WKFileUploadItem : NSObject
     168- (instancetype)initWithFileURL:(NSURL *)fileURL;
    110169@property (nonatomic, readonly, getter=isVideo) BOOL video;
    111170@property (nonatomic, readonly) NSURL *fileURL;
     
    113172@end
    114173
    115 @implementation _WKFileUploadItem
     174@implementation _WKFileUploadItem {
     175    RetainPtr<NSURL> _fileURL;
     176}
     177
     178- (instancetype)initWithFileURL:(NSURL *)fileURL
     179{
     180    if (!(self = [super init]))
     181        return nil;
     182
     183    ASSERT([fileURL isFileURL]);
     184    ASSERT([[NSFileManager defaultManager] fileExistsAtPath:fileURL.path]);
     185    _fileURL = fileURL;
     186    return self;
     187}
    116188
    117189- (BOOL)isVideo
     
    123195- (NSURL *)fileURL
    124196{
     197    return _fileURL.get();
     198}
     199
     200- (UIImage *)displayImage
     201{
    125202    ASSERT_NOT_REACHED();
    126203    return nil;
    127204}
    128205
    129 - (UIImage *)displayImage
    130 {
    131     ASSERT_NOT_REACHED();
    132     return nil;
    133 }
    134 
    135206@end
    136207
    137208
    138209@interface _WKImageFileUploadItem : _WKFileUploadItem
    139 - (instancetype)initWithFilePath:(NSString *)filePath originalImage:(UIImage *)originalImage;
     210- (instancetype)initWithFileURL:(NSURL *)fileURL originalImage:(UIImage *)originalImage;
    140211@end
    141212
    142213@implementation _WKImageFileUploadItem {
    143     RetainPtr<NSString> _filePath;
    144214    RetainPtr<UIImage> _originalImage;
    145215}
    146216
    147 - (instancetype)initWithFilePath:(NSString *)filePath originalImage:(UIImage *)originalImage
    148 {
    149     if (!(self = [super init]))
     217- (instancetype)initWithFileURL:(NSURL *)fileURL originalImage:(UIImage *)originalImage
     218{
     219    if (!(self = [super initWithFileURL:fileURL]))
    150220        return nil;
    151     _filePath = filePath;
     221
    152222    _originalImage = originalImage;
    153223    return self;
     
    159229}
    160230
    161 - (NSURL *)fileURL
    162 {
    163     return [NSURL fileURLWithPath:_filePath.get()];
    164 }
    165 
    166231- (UIImage *)displayImage
    167232{
     
    173238
    174239@interface _WKVideoFileUploadItem : _WKFileUploadItem
    175 - (instancetype)initWithFilePath:(NSString *)filePath mediaURL:(NSURL *)mediaURL;
    176240@end
    177241
    178 @implementation _WKVideoFileUploadItem {
    179     RetainPtr<NSString> _filePath;
    180     RetainPtr<NSURL> _mediaURL;
    181 }
    182 
    183 - (instancetype)initWithFilePath:(NSString *)filePath mediaURL:(NSURL *)mediaURL
    184 {
    185     if (!(self = [super init]))
    186         return nil;
    187     _filePath = filePath;
    188     _mediaURL = mediaURL;
    189     return self;
    190 }
     242@implementation _WKVideoFileUploadItem
    191243
    192244- (BOOL)isVideo
     
    195247}
    196248
    197 - (NSURL *)fileURL
    198 {
    199     return [NSURL fileURLWithPath:_filePath.get()];
    200 }
    201 
    202249- (UIImage *)displayImage
    203250{
    204     RetainPtr<AVURLAsset> asset = adoptNS([allocAVURLAssetInstance() initWithURL:_mediaURL.get() options:nil]);
    205     RetainPtr<AVAssetImageGenerator> generator = adoptNS([allocAVAssetImageGeneratorInstance() initWithAsset:asset.get()]);
    206     [generator setAppliesPreferredTrackTransform:YES];
    207 
    208     NSError *error = nil;
    209     RetainPtr<CGImageRef> imageRef = adoptCF([generator copyCGImageAtTime:kCMTimeZero actualTime:nil error:&error]);
    210     if (error) {
    211         LOG_ERROR("_WKVideoFileUploadItem: Error creating image for video: %@", _mediaURL.get());
    212         return nil;
    213     }
    214 
    215     RetainPtr<UIImage> image = adoptNS([[UIImage alloc] initWithCGImage:imageRef.get()]);
    216     return thumbnailSizedImageForImage(image.get());
     251    return iconForVideoFile(self.fileURL);
    217252}
    218253
     
    222257#pragma mark - WKFileUploadPanel
    223258
    224 @interface WKFileUploadPanel () <UIPopoverControllerDelegate, UINavigationControllerDelegate, UIImagePickerControllerDelegate>
     259@interface WKFileUploadPanel () <UIPopoverControllerDelegate, UINavigationControllerDelegate, UIImagePickerControllerDelegate, UIDocumentPickerDelegate, UIDocumentMenuDelegate>
    225260@end
    226261
     
    233268    BOOL _usingCamera;
    234269    RetainPtr<UIImagePickerController> _imagePicker;
    235     RetainPtr<UIAlertController> _actionSheetController;
    236270    RetainPtr<UIViewController> _presentationViewController; // iPhone always. iPad for Fullscreen Camera.
    237271    RetainPtr<UIPopoverController> _presentationPopover; // iPad for action sheet and Photo Library.
     272    RetainPtr<UIDocumentMenuViewController> _documentMenuController;
     273    RetainPtr<UIAlertController> _actionSheetController;
    238274}
    239275
     
    250286    [_imagePicker setDelegate:nil];
    251287    [_presentationPopover setDelegate:nil];
     288    [_documentMenuController setDelegate:nil];
     289
    252290    [super dealloc];
    253291}
     
    306344    _mimeTypes = adoptNS([mimeTypes copy]);
    307345
     346    // FIXME: Remove this check and the fallback code when a new SDK is available. <rdar://problem/20150072>
     347    if ([UIDocumentMenuViewController instancesRespondToSelector:@selector(_setIgnoreApplicationEntitlementForImport:)]) {
     348        [self _showDocumentPickerMenu];
     349        return;
     350    }
     351
     352    // Fall back to showing the old-style source selection sheet.
    308353    // If there is no camera or this is type=multiple, just show the image picker for the photo library.
    309354    // Otherwise, show an action sheet for the user to choose between camera or library.
     
    335380}
    336381
    337 #pragma mark - Action Sheet
     382#pragma mark - Media Types
    338383
    339384static bool stringHasPrefixCaseInsensitive(NSString *str, NSString *prefix)
     
    343388}
    344389
    345 - (NSArray *)_mediaTypesForPickerSourceType:(UIImagePickerControllerSourceType)sourceType
     390static NSArray *UTIsForMIMETypes(NSArray *mimeTypes)
    346391{
    347392    // The HTML5 spec mentions the literal "image/*" and "video/*" strings.
     
    350395    // So, "image/jpeg" would make the picker display all images types.
    351396    NSMutableSet *mediaTypes = [NSMutableSet set];
    352     for (NSString *mimeType in _mimeTypes.get()) {
     397    for (NSString *mimeType in mimeTypes) {
     398        // FIXME: We should support more MIME type -> UTI mappings. <http://webkit.org/b/142614>
    353399        if (stringHasPrefixCaseInsensitive(mimeType, @"image/"))
    354400            [mediaTypes addObject:(NSString *)kUTTypeImage];
     
    357403    }
    358404
    359     if ([mediaTypes count])
    360         return [mediaTypes allObjects];
     405    return mediaTypes.allObjects;
     406}
     407
     408- (NSArray *)_mediaTypesForPickerSourceType:(UIImagePickerControllerSourceType)sourceType
     409{
     410    NSArray *mediaTypes = UTIsForMIMETypes(_mimeTypes.get());
     411    if (mediaTypes.count)
     412        return mediaTypes;
    361413
    362414    // Fallback to every supported media type if there is no filter.
     
    364416}
    365417
    366 - (void)_showMediaSourceSelectionSheet
    367 {
    368     NSString *existingString = WEB_UI_STRING_KEY("Photo Library", "Photo Library (file upload action sheet)", "File Upload alert sheet button string for choosing an existing media item from the Photo Library");
    369     NSString *cancelString = WEB_UI_STRING_KEY("Cancel", "Cancel (file upload action sheet)", "File Upload alert sheet button string to cancel");
     418- (NSArray *)_documentPickerMenuMediaTypes
     419{
     420    NSArray *mediaTypes = UTIsForMIMETypes(_mimeTypes.get());
     421    if (mediaTypes.count)
     422        return mediaTypes;
     423
     424    // Fallback to every supported media type if there is no filter.
     425    return @[@"public.item"];
     426}
     427
     428#pragma mark - Source selection menu
     429
     430- (NSString *)_photoLibraryButtonLabel
     431{
     432    return WEB_UI_STRING_KEY("Photo Library", "Photo Library (file upload action sheet)", "File Upload alert sheet button string for choosing an existing media item from the Photo Library");
     433}
     434
     435- (NSString *)_cameraButtonLabel
     436{
     437    if (![UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera])
     438        return nil;
    370439
    371440    // Choose the appropriate string for the camera button.
    372     NSString *cameraString;
    373441    NSArray *filteredMediaTypes = [self _mediaTypesForPickerSourceType:UIImagePickerControllerSourceTypeCamera];
    374442    BOOL containsImageMediaType = [filteredMediaTypes containsObject:(NSString *)kUTTypeImage];
     
    376444    ASSERT(containsImageMediaType || containsVideoMediaType);
    377445    if (containsImageMediaType && containsVideoMediaType)
    378         cameraString = WEB_UI_STRING_KEY("Take Photo or Video", "Take Photo or Video (file upload action sheet)", "File Upload alert sheet camera button string for taking photos or videos");
    379     else if (containsVideoMediaType)
    380         cameraString = WEB_UI_STRING_KEY("Take Video", "Take Video (file upload action sheet)", "File Upload alert sheet camera button string for taking only videos");
    381     else
    382         cameraString = WEB_UI_STRING_KEY("Take Photo", "Take Photo (file upload action sheet)", "File Upload alert sheet camera button string for taking only photos");
     446        return WEB_UI_STRING_KEY("Take Photo or Video", "Take Photo or Video (file upload action sheet)", "File Upload alert sheet camera button string for taking photos or videos");
     447
     448    if (containsVideoMediaType)
     449        return WEB_UI_STRING_KEY("Take Video", "Take Video (file upload action sheet)", "File Upload alert sheet camera button string for taking only videos");
     450
     451    return WEB_UI_STRING_KEY("Take Photo", "Take Photo (file upload action sheet)", "File Upload alert sheet camera button string for taking only photos");
     452}
     453
     454- (void)_showMediaSourceSelectionSheet
     455{
     456    NSString *existingString = [self _photoLibraryButtonLabel];
     457    NSString *cameraString = [self _cameraButtonLabel];
     458    NSString *cancelString = WEB_UI_STRING_KEY("Cancel", "Cancel (file upload action sheet)", "File Upload alert sheet button string to cancel");
    383459
    384460    _actionSheetController = [UIAlertController alertControllerWithTitle:nil message:nil preferredStyle:UIAlertControllerStyleActionSheet];
     
    403479    [_actionSheetController addAction:photoLibraryAction];
    404480
    405     if (UICurrentUserInterfaceIdiomIsPad())
    406         [self _presentPopoverWithContentViewController:_actionSheetController.get() animated:YES];
    407     else
    408         [self _presentFullscreenViewController:_actionSheetController.get() animated:YES];
     481    [self _presentForCurrentInterfaceIdiom:_actionSheetController.get()];
     482}
     483
     484- (void)_showDocumentPickerMenu
     485{
     486    // FIXME: Support multiple file selection when implemented. <rdar://17177981>
     487    // FIXME: We call -_setIgnoreApplicationEntitlementForImport: before initialization, because the assertion we're trying
     488    // to suppress is in the initializer. <rdar://problem/20137692> tracks doing this with a private initializer.
     489    _documentMenuController = adoptNS([UIDocumentMenuViewController alloc]);
     490    [_documentMenuController _setIgnoreApplicationEntitlementForImport:YES];
     491    [_documentMenuController initWithDocumentTypes:[self _documentPickerMenuMediaTypes] inMode:UIDocumentPickerModeImport];
     492    [_documentMenuController setDelegate:self];
     493
     494    // FIXME: Need icons for Camera and Photo Library options.
     495    [_documentMenuController addOptionWithTitle:[self _photoLibraryButtonLabel] image:nil order:UIDocumentMenuOrderFirst handler:^{
     496        [self _showPhotoPickerWithSourceType:UIImagePickerControllerSourceTypePhotoLibrary];
     497    }];
     498
     499    if (NSString *cameraString = [self _cameraButtonLabel]) {
     500        [_documentMenuController addOptionWithTitle:cameraString image:nil order:UIDocumentMenuOrderFirst handler:^{
     501            _usingCamera = YES;
     502            [self _showPhotoPickerWithSourceType:UIImagePickerControllerSourceTypeCamera];
     503        }];
     504    }
     505
     506    [self _presentForCurrentInterfaceIdiom:_documentMenuController.get()];
    409507}
    410508
     
    432530#pragma mark - Presenting View Controllers
    433531
     532- (void)_presentForCurrentInterfaceIdiom:(UIViewController *)viewController
     533{
     534    if (UICurrentUserInterfaceIdiomIsPad())
     535        [self _presentPopoverWithContentViewController:viewController animated:YES];
     536    else
     537        [self _presentFullscreenViewController:viewController animated:YES];
     538}
     539
    434540- (void)_presentPopoverWithContentViewController:(UIViewController *)contentViewController animated:(BOOL)animated
    435541{
     
    453559- (void)popoverControllerDidDismissPopover:(UIPopoverController *)popoverController
    454560{
     561    [self _cancel];
     562}
     563
     564#pragma mark - UIDocumentMenuDelegate implementation
     565
     566- (void)documentMenu:(UIDocumentMenuViewController *)documentMenu didPickDocumentPicker:(UIDocumentPickerViewController *)documentPicker
     567{
     568    documentPicker.delegate = self;
     569    documentPicker.modalPresentationStyle = UIModalPresentationFullScreen;
     570
     571    [self _presentForCurrentInterfaceIdiom:documentPicker];
     572}
     573
     574- (void)documentMenuWasCancelled:(UIDocumentMenuViewController *)documentMenu
     575{
     576    [self _dismissDisplayAnimated:YES];
     577    [self _cancel];
     578}
     579
     580#pragma mark - UIDocumentPickerControllerDelegate implementation
     581
     582- (void)documentPicker:(UIDocumentPickerViewController *)documentPicker didPickDocumentAtURL:(NSURL *)url
     583{
     584    [self _dismissDisplayAnimated:YES];
     585    [self _chooseFiles:@[url] displayString:url.lastPathComponent iconImage:iconForFile(url)];
     586}
     587
     588- (void)documentPickerWasCancelled:(UIDocumentPickerViewController *)documentPicker
     589{
     590    [self _dismissDisplayAnimated:YES];
    455591    [self _cancel];
    456592}
     
    575711        }
    576712
    577         NSString *filePath = [mediaURL path];
    578         successBlock(adoptNS([[_WKVideoFileUploadItem alloc] initWithFilePath:filePath mediaURL:mediaURL]).get());
     713        successBlock(adoptNS([[_WKVideoFileUploadItem alloc] initWithFileURL:mediaURL]).get());
    579714        return;
    580715    }
     
    628763            }
    629764
    630             successBlock(adoptNS([[_WKImageFileUploadItem alloc] initWithFilePath:filePath originalImage:originalImage]).get());
     765            successBlock(adoptNS([[_WKImageFileUploadItem alloc] initWithFileURL:[NSURL fileURLWithPath:filePath] originalImage:originalImage]).get());
    631766        });
    632767        return;
Note: See TracChangeset for help on using the changeset viewer.