UIViewController with WKWebView presented modally causes the presented UIViewControll...
authorcommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 8 Mar 2017 09:15:10 +0000 (09:15 +0000)
committercommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 8 Mar 2017 09:15:10 +0000 (09:15 +0000)
https://bugs.webkit.org/show_bug.cgi?id=165225

Patch by Brad Wright <bwright2@apple.com> on 2017-03-08
Reviewed by Wenson Hsieh.

The problem happens on an iPhone with a WKWebView inside a view controller presented modally. If the user selects an HTML file input
tag button, a UIDocumentMenuViewController will appear. Anything the user does next causes the entire modal view controller to get dismissed.

To fix this problem, I prevent the UIDocumentMenuViewController from being dismissed by not saving a pointer to it. The UIDocumentMenuViewController
always goes away by itself on any user interaction. Trying to dismiss the UIDocumentMenuViewController when it is already dismissed causes the modal view controller
to be dismissed.

* UIProcess/ios/forms/WKFileUploadPanel.mm:
(-[WKFileUploadPanel _cancel]):
(-[WKFileUploadPanel dismiss]):
(-[WKFileUploadPanel _showDocumentPickerMenu]):
(-[WKFileUploadPanel _presentMenuOptionForCurrentInterfaceIdiom:]):
(-[WKFileUploadPanel _presentForCurrentInterfaceIdiom:]): Deleted.

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

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

index c44d919..3726449 100644 (file)
@@ -1,3 +1,24 @@
+2017-03-08  Brad Wright  <bwright2@apple.com>
+
+        UIViewController with WKWebView presented modally causes the presented UIViewController to be dismissed.
+        https://bugs.webkit.org/show_bug.cgi?id=165225
+        
+        Reviewed by Wenson Hsieh.
+
+        The problem happens on an iPhone with a WKWebView inside a view controller presented modally. If the user selects an HTML file input 
+        tag button, a UIDocumentMenuViewController will appear. Anything the user does next causes the entire modal view controller to get dismissed.
+
+        To fix this problem, I prevent the UIDocumentMenuViewController from being dismissed by not saving a pointer to it. The UIDocumentMenuViewController 
+        always goes away by itself on any user interaction. Trying to dismiss the UIDocumentMenuViewController when it is already dismissed causes the modal view controller
+        to be dismissed.
+
+        * UIProcess/ios/forms/WKFileUploadPanel.mm:
+        (-[WKFileUploadPanel _cancel]):
+        (-[WKFileUploadPanel dismiss]):
+        (-[WKFileUploadPanel _showDocumentPickerMenu]):
+        (-[WKFileUploadPanel _presentMenuOptionForCurrentInterfaceIdiom:]):
+        (-[WKFileUploadPanel _presentForCurrentInterfaceIdiom:]): Deleted.
+
 2017-03-08  Alexey Proskuryakov  <ap@apple.com>
 
         WebKit should not export dyld install name hints on watchOS and tvOS
index 253b8bc..a9af3c9 100644 (file)
@@ -327,7 +327,9 @@ static UIImage* iconForFile(NSURL *file)
 
 - (void)_cancel
 {
-    _listener->cancel();
+    if (_listener)
+        _listener->cancel();
+    
     [self _dispatchDidDismiss];
 }
 
@@ -386,7 +388,15 @@ static UIImage* iconForFile(NSURL *file)
 
 - (void)dismiss
 {
-    [self _dismissDisplayAnimated:NO];
+    // Dismiss any view controller that is being presented. This works for all types of view controllers, popovers, etc.
+    // If there is any kind of view controller presented on this view, it will be removed. 
+    
+    [[UIViewController _viewControllerForFullScreenPresentationFromView:_view] dismissViewControllerAnimated:NO completion:nil];
+    
+    [_presentationPopover setDelegate:nil];
+    _presentationPopover = nil;
+    _presentationViewController = nil;
+    
     [self _cancel];
 }
 
@@ -496,7 +506,9 @@ static NSArray *UTIsForMIMETypes(NSArray *mimeTypes)
         }
     }
 
-    [self _presentForCurrentInterfaceIdiom:_documentMenuController.get()];
+    [self _presentMenuOptionForCurrentInterfaceIdiom:_documentMenuController.get()];
+    // Clear out the view controller we just presented. Don't save a reference to the UIDocumentMenuViewController as it is self dismissing.
+    _presentationViewController = nil;
 }
 
 #pragma mark - Image Picker
@@ -550,7 +562,7 @@ static NSArray *UTIsForMIMETypes(NSArray *mimeTypes)
 
 #pragma mark - Presenting View Controllers
 
-- (void)_presentForCurrentInterfaceIdiom:(UIViewController *)viewController
+- (void)_presentMenuOptionForCurrentInterfaceIdiom:(UIViewController *)viewController
 {
     if (UICurrentUserInterfaceIdiomIsPad())
         [self _presentPopoverWithContentViewController:viewController animated:YES];