<html>
    <head>
      <base href="https://bugs.webkit.org/" />
    </head>
    <body>
      <p>
        <div>
            <b><a class="bz_bug_link 
          bz_status_NEW "
   title="NEW - UIViewController with WKWebView presented modally causes the presented UIViewController to be dismissed."
   href="https://bugs.webkit.org/show_bug.cgi?id=165225#c29">Comment # 29</a>
              on <a class="bz_bug_link 
          bz_status_NEW "
   title="NEW - UIViewController with WKWebView presented modally causes the presented UIViewController to be dismissed."
   href="https://bugs.webkit.org/show_bug.cgi?id=165225">bug 165225</a>
              from <span class="vcard"><a class="email" href="mailto:bwright2&#64;apple.com" title="Brad Wright &lt;bwright2&#64;apple.com&gt;"> <span class="fn">Brad Wright</span></a>
</span></b>
        <pre>(In reply to <a href="show_bug.cgi?id=165225#c28">comment #28</a>)
<span class="quote">&gt; (In reply to <a href="show_bug.cgi?id=165225#c26">comment #26</a>)
&gt; &gt; (In reply to <a href="show_bug.cgi?id=165225#c25">comment #25</a>)
&gt; &gt; &gt; Comment on <span class="bz_obsolete"><a href="attachment.cgi?id=303130&amp;action=diff" name="attach_303130" title="Patch">attachment 303130</a> <a href="attachment.cgi?id=303130&amp;action=edit" title="Patch">[details]</a></span>
&gt; &gt; &gt; Patch
&gt; &gt; &gt; 
&gt; &gt; &gt; View in context:
&gt; &gt; &gt; <a href="https://bugs.webkit.org/attachment.cgi?id=303130&amp;action=review">https://bugs.webkit.org/attachment.cgi?id=303130&amp;action=review</a>
&gt; &gt; &gt; 
&gt; &gt; &gt; &gt; Source/WebKit2/UIProcess/ios/forms/WKFileUploadPanel.mm:391
&gt; &gt; &gt; &gt; +    // dismiss any viewController that is being presented. This is works all VC, popovers, etc.
&gt; &gt; 
&gt; &gt; This is works for all VC.  Missed the for, in the comment.
&gt; &gt; &gt; 
&gt; &gt; &gt; Normally we would want to use a capital D in this kind of sentence-style
&gt; &gt; &gt; comment.
&gt; &gt; &gt; 
&gt; &gt; &gt; VC is not normally an abbreviation we use for view controller in WebKit code.
&gt; &gt; &gt; 
&gt; &gt; &gt; &quot;This is works all&quot;, is not grammatically correct.
&gt; &gt; &gt; 
&gt; &gt; &gt; &gt; Source/WebKit2/UIProcess/ios/forms/WKFileUploadPanel.mm:394
&gt; &gt; &gt; &gt; +    UIViewController *presentedViewController = [UIViewController _viewControllerForFullScreenPresentationFromView:_view];
&gt; &gt; &gt; &gt; +    if (presentedViewController)
&gt; &gt; &gt; &gt; +        [presentedViewController dismissViewControllerAnimated:NO completion:nil];
&gt; &gt; &gt; 
&gt; &gt; &gt; Would be nice to define the variable inside the &quot;if&quot; since this is C++ code.
&gt; &gt; &gt; In fact, I personally would use auto instead of writing out UIViewController
&gt; &gt; &gt; * for the type of the variable.
&gt; &gt; &gt; 
&gt; &gt; &gt; &gt; Source/WebKit2/UIProcess/ios/forms/WKFileUploadPanel.mm:508
&gt; &gt; &gt; &gt; +    // Clear out any previous view controller reference, to prevent calling dismiss on a view controller that
&gt; &gt; &gt; &gt; +    // was no longer being presented. Don't save a reference to the UIDocumentMenuViewController as it is self dismissing.
&gt; &gt; &gt; &gt; +    _presentationViewController = nil;
&gt; &gt; &gt; 
&gt; &gt; &gt; I don’t understand this comment and therefore don’t understand the code.
&gt; &gt; 
&gt; &gt; So what happening is that the _presentationViewController is used to called
&gt; &gt; in:
&gt; &gt; 
&gt; &gt; - (void)_dismissDisplayAnimated:(BOOL)animated
&gt; &gt; {
&gt; &gt;     if (_presentationPopover) {
&gt; &gt;         [_presentationPopover dismissPopoverAnimated:animated];
&gt; &gt;         [_presentationPopover setDelegate:nil];
&gt; &gt;         _presentationPopover = nil;
&gt; &gt;     }
&gt; &gt; 
&gt; &gt;     if (_presentationViewController) {
&gt; &gt;         [_presentationViewController dismissViewControllerAnimated:animated
&gt; &gt; completion:^{
&gt; &gt;             _presentationViewController = nil;
&gt; &gt;         }];
&gt; &gt;     }
&gt; &gt; }
&gt; &gt; 
&gt; &gt; 
&gt; &gt; The UIDocumentMenuViewController dismisses itself, so when
&gt; &gt; _presentationViewController dismissViewControllerAnimated:animated is called
&gt; &gt; in this function, it dismisses the WKWebView when is presented modally. 
&gt; &gt; That's why it's set to nil in this function, so that the errant code path is
&gt; &gt; never executed.
&gt; &gt; &gt; 
&gt; &gt; &gt; On iPhone, the method called just before this will call
&gt; &gt; &gt; _presentFullscreenViewController. Then this line of code will clear out the
&gt; &gt; &gt; reference to that just-presented view controller. Given that, why does this
&gt; &gt; &gt; comment talk about clearing out a &quot;previous view controller reference&quot;?
&gt; 
&gt; 
&gt; Inside the call stack this is the reference that needs to be cleared out.
&gt; 
&gt; 1. We start here inside:
&gt; - (void)_showDocumentPickerMenu
&gt; 2.Then this is called:
&gt; - (void)_presentMenuOptionForCurrentInterfaceIdiom:(UIViewController
&gt; *)viewController
&gt; 3. Finally, inside here the property _presentationViewController is set.
&gt; - (void)_presentFullscreenViewController:(UIViewController *)viewController
&gt; animated:(BOOL)animated
&gt; {
&gt;     ...
&gt;     _presentationViewController = [UIViewController 
&gt; ...
&gt; }
&gt; 
&gt; 4. When we return up the stack, we need to set _presentationViewController back to nil.
&gt; 
&gt; - (void)_showDocumentPickerMenu
&gt; 
&gt; 
&gt; I put this comment and the nil reference as close together as possible to
&gt; minimize future errors.</span ></pre>
        </div>
      </p>
      <hr>
      <span>You are receiving this mail because:</span>
      
      <ul>
          <li>You are the assignee for the bug.</li>
      </ul>
    </body>
</html>