Title: [219750] trunk/Source/WebKit
Revision
219750
Author
[email protected]
Date
2017-07-21 15:44:32 -0700 (Fri, 21 Jul 2017)

Log Message

[iOS] Adopt UIImagePickerControllerImageURL for photo uploads
https://bugs.webkit.org/show_bug.cgi?id=174723
<rdar://problem/33223962>

Reviewed by Joseph Pecoraro.

In iOS 11, use the URL provided by UIImagePickerControllerImageURL, if available, as the
file URL for photo uploads. Since we use the UIImagePickerController imageExportPreset of
UIImagePickerControllerImageURLExportPresetCompatible, UIKit will take care of converting
HEIF images to JPEG for us. For other types (GIF, JPEG, and PNG), it will preserve the
original format.

Since UIImagePickerController now provides GIF and PNG representations, we no longer need to
use PHImageManager to access the original assets. This patch removes the
PHAsset/PHImageManager code added in r185241.

* Platform/spi/ios/PhotosSPI.h: Removed.
* UIProcess/ios/forms/WKFileUploadPanel.mm:
(-[WKFileUploadPanel _uploadItemFromMediaInfo:successBlock:failureBlock:]):
(-[WKFileUploadPanel _uploadItemForImage:withAssetURL:successBlock:failureBlock:]): Deleted.
* WebKit.xcodeproj/project.pbxproj:

Modified Paths

Removed Paths

Diff

Modified: trunk/Source/WebKit/ChangeLog (219749 => 219750)


--- trunk/Source/WebKit/ChangeLog	2017-07-21 22:41:26 UTC (rev 219749)
+++ trunk/Source/WebKit/ChangeLog	2017-07-21 22:44:32 UTC (rev 219750)
@@ -1,3 +1,27 @@
+2017-07-21  Andy Estes  <[email protected]>
+
+        [iOS] Adopt UIImagePickerControllerImageURL for photo uploads
+        https://bugs.webkit.org/show_bug.cgi?id=174723
+        <rdar://problem/33223962>
+
+        Reviewed by Joseph Pecoraro.
+
+        In iOS 11, use the URL provided by UIImagePickerControllerImageURL, if available, as the
+        file URL for photo uploads. Since we use the UIImagePickerController imageExportPreset of
+        UIImagePickerControllerImageURLExportPresetCompatible, UIKit will take care of converting
+        HEIF images to JPEG for us. For other types (GIF, JPEG, and PNG), it will preserve the
+        original format.
+
+        Since UIImagePickerController now provides GIF and PNG representations, we no longer need to
+        use PHImageManager to access the original assets. This patch removes the
+        PHAsset/PHImageManager code added in r185241.
+
+        * Platform/spi/ios/PhotosSPI.h: Removed.
+        * UIProcess/ios/forms/WKFileUploadPanel.mm:
+        (-[WKFileUploadPanel _uploadItemFromMediaInfo:successBlock:failureBlock:]):
+        (-[WKFileUploadPanel _uploadItemForImage:withAssetURL:successBlock:failureBlock:]): Deleted.
+        * WebKit.xcodeproj/project.pbxproj:
+
 2017-07-21  Konstantin Tokarev  <[email protected]>
 
         [cmake][Mac] Unreviewed, fix linking WebKitSystemInterface

Deleted: trunk/Source/WebKit/Platform/spi/ios/PhotosSPI.h (219749 => 219750)


--- trunk/Source/WebKit/Platform/spi/ios/PhotosSPI.h	2017-07-21 22:41:26 UTC (rev 219749)
+++ trunk/Source/WebKit/Platform/spi/ios/PhotosSPI.h	2017-07-21 22:44:32 UTC (rev 219750)
@@ -1,47 +0,0 @@
-/*
- * Copyright (C) 2016 Apple Inc. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
- * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE INC. OR
- * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
- * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
- * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
- * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
- * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#if PLATFORM(IOS)
-
-#import <Photos/Photos.h>
-
-#if USE(APPLE_INTERNAL_SDK)
-
-#import <Photos/Photos_Private.h>
-
-#else
-
-@interface PHAssetOriginalMetadataProperties
-@property (nonatomic, strong, readonly) NSString *originalFilename;
-@end
-
-@interface PHAsset ()
-- (PHAssetOriginalMetadataProperties *)originalMetadataProperties;
-- (void)fetchPropertySetsIfNeeded;
-@end
-
-#endif
-
-#endif

Modified: trunk/Source/WebKit/UIProcess/ios/forms/WKFileUploadPanel.mm (219749 => 219750)


--- trunk/Source/WebKit/UIProcess/ios/forms/WKFileUploadPanel.mm	2017-07-21 22:41:26 UTC (rev 219749)
+++ trunk/Source/WebKit/UIProcess/ios/forms/WKFileUploadPanel.mm	2017-07-21 22:44:32 UTC (rev 219750)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2014, 2016 Apple Inc. All rights reserved.
+ * Copyright (C) 2014-2017 Apple Inc. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
@@ -32,7 +32,6 @@
 #import "APIData.h"
 #import "APIOpenPanelParameters.h"
 #import "APIString.h"
-#import "PhotosSPI.h"
 #import "UIKitSPI.h"
 #import "WKContentViewInteraction.h"
 #import "WKData.h"
@@ -41,23 +40,13 @@
 #import "WebIconUtilities.h"
 #import "WebOpenPanelResultListenerProxy.h"
 #import "WebPageProxy.h"
-#import <AVFoundation/AVFoundation.h>
-#import <CoreMedia/CoreMedia.h>
 #import <MobileCoreServices/MobileCoreServices.h>
 #import <WebCore/LocalizedStrings.h>
 #import <WebKit/WebNSFileManagerExtras.h>
 #import <wtf/RetainPtr.h>
-#import <wtf/SoftLinking.h>
 
 using namespace WebKit;
 
-SOFT_LINK_FRAMEWORK(Photos);
-SOFT_LINK_CLASS(Photos, PHAsset);
-SOFT_LINK_CLASS(Photos, PHImageManager);
-SOFT_LINK_CLASS(Photos, PHImageRequestOptions);
-SOFT_LINK_CONSTANT(Photos, PHImageRequestOptionsResizeModeNone, NSString *);
-SOFT_LINK_CONSTANT(Photos, PHImageRequestOptionsVersionCurrent, NSString *);
-
 #pragma clang diagnostic push
 #pragma clang diagnostic ignored "-Wdeprecated-declarations"
 
@@ -664,43 +653,6 @@
     });
 }
 
-- (void)_uploadItemForImage:(UIImage *)image withAssetURL:(NSURL *)assetURL successBlock:(void (^)(_WKFileUploadItem *))successBlock failureBlock:(void (^)(void))failureBlock
-{
-    ASSERT_ARG(image, image);
-    ASSERT_ARG(assetURL, assetURL);
-
-    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
-        PHFetchResult *result = [getPHAssetClass() fetchAssetsWithALAssetURLs:@[assetURL] options:nil];
-        if (!result.count) {
-            LOG_ERROR("WKFileUploadPanel: Failed to fetch asset with URL %@", assetURL);
-            [self _uploadItemForJPEGRepresentationOfImage:image successBlock:successBlock failureBlock:failureBlock];
-            return;
-        }
-
-        PHAsset *firstAsset = result[0];
-        [firstAsset fetchPropertySetsIfNeeded];
-        NSString *originalFilename = [[firstAsset originalMetadataProperties] originalFilename];
-        ASSERT(originalFilename);
-
-        RetainPtr<PHImageRequestOptions> options = adoptNS([allocPHImageRequestOptionsInstance() init]);
-        [options setVersion:PHImageRequestOptionsVersionCurrent];
-        [options setSynchronous:YES];
-        [options setResizeMode:PHImageRequestOptionsResizeModeNone];
-
-        PHImageManager *manager = (PHImageManager *)[getPHImageManagerClass() defaultManager];
-        [manager requestImageDataForAsset:firstAsset options:options.get() resultHandler:^(NSData *imageData, NSString *dataUTI, UIImageOrientation, NSDictionary *info)
-        {
-            if (!imageData) {
-                LOG_ERROR("WKFileUploadPanel: Failed to request image data for asset with URL %@", assetURL);
-                [self _uploadItemForJPEGRepresentationOfImage:image successBlock:successBlock failureBlock:failureBlock];
-                return;
-            }
-
-            [self _uploadItemForImageData:imageData imageName:originalFilename successBlock:successBlock failureBlock:failureBlock];
-        }];
-    });
-}
-
 - (void)_uploadItemFromMediaInfo:(NSDictionary *)info successBlock:(void (^)(_WKFileUploadItem *))successBlock failureBlock:(void (^)(void))failureBlock
 {
     NSString *mediaType = [info objectForKey:UIImagePickerControllerMediaType];
@@ -726,6 +678,20 @@
         return;
     }
 
+#if __IPHONE_OS_VERSION_MIN_REQUIRED >= 110000
+    if (NSURL *imageURL = info[UIImagePickerControllerImageURL]) {
+        if (!imageURL.isFileURL) {
+            LOG_ERROR("WKFileUploadPanel: Expected image URL to be a file path, it was not");
+            ASSERT_NOT_REACHED();
+            failureBlock();
+            return;
+        }
+
+        successBlock(adoptNS([[_WKImageFileUploadItem alloc] initWithFileURL:imageURL]).get());
+        return;
+    }
+#endif
+
     UIImage *originalImage = [info objectForKey:UIImagePickerControllerOriginalImage];
     if (!originalImage) {
         LOG_ERROR("WKFileUploadPanel: Expected image data but there was none");
@@ -734,14 +700,7 @@
         return;
     }
 
-    // If we have an asset URL, try to upload the native image.
-    NSURL *referenceURL = [info objectForKey:UIImagePickerControllerReferenceURL];
-    if (referenceURL) {
-        [self _uploadItemForImage:originalImage withAssetURL:referenceURL successBlock:successBlock failureBlock:failureBlock];
-        return;
-    }
-
-    // Photos taken with the camera will not have an asset URL. Fall back to a JPEG representation.
+    // Photos taken with the camera will not have an image URL. Fall back to a JPEG representation.
     [self _uploadItemForJPEGRepresentationOfImage:originalImage successBlock:successBlock failureBlock:failureBlock];
 }
 

Modified: trunk/Source/WebKit/WebKit.xcodeproj/project.pbxproj (219749 => 219750)


--- trunk/Source/WebKit/WebKit.xcodeproj/project.pbxproj	2017-07-21 22:41:26 UTC (rev 219749)
+++ trunk/Source/WebKit/WebKit.xcodeproj/project.pbxproj	2017-07-21 22:44:32 UTC (rev 219750)
@@ -3393,7 +3393,6 @@
 		539EB5461DC2EE40009D48CF /* NetworkDataTaskBlob.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = NetworkDataTaskBlob.cpp; path = NetworkProcess/NetworkDataTaskBlob.cpp; sourceTree = "<group>"; };
 		539EB5471DC2EE40009D48CF /* NetworkDataTaskBlob.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = NetworkDataTaskBlob.h; path = NetworkProcess/NetworkDataTaskBlob.h; sourceTree = "<group>"; };
 		53DEA3651DDE422E00E82648 /* json.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = json.hpp; path = NetworkProcess/capture/json.hpp; sourceTree = "<group>"; };
-		579D18B71CCFE34B00B1974C /* PhotosSPI.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = PhotosSPI.h; sourceTree = "<group>"; };
 		5C052F241C6D3AB60076E919 /* AuthenticationManagerCocoa.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; name = AuthenticationManagerCocoa.mm; path = Authentication/cocoa/AuthenticationManagerCocoa.mm; sourceTree = "<group>"; };
 		5C0B17741E7C879C00E9123C /* NetworkSocketStreamMessageReceiver.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = NetworkSocketStreamMessageReceiver.cpp; sourceTree = "<group>"; };
 		5C0B17751E7C879C00E9123C /* NetworkSocketStreamMessages.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = NetworkSocketStreamMessages.h; sourceTree = "<group>"; };
@@ -7984,7 +7983,6 @@
 				07A8F3861E64A8F900B668E8 /* CelestialSPI.h */,
 				CE1A0BCD1A48E6C60054EF74 /* CorePDFSPI.h */,
 				CE1A0BCF1A48E6C60054EF74 /* ManagedConfigurationSPI.h */,
-				579D18B71CCFE34B00B1974C /* PhotosSPI.h */,
 				CE1A0BD01A48E6C60054EF74 /* TCCSPI.h */,
 				CE1A0BD11A48E6C60054EF74 /* TextInputSPI.h */,
 				CEE4AE2A1A5DCF430002F49B /* UIKitSPI.h */,
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to