Chromium Code Reviews| Index: ios/web/web_state/ui/crw_web_controller.mm |
| diff --git a/ios/web/web_state/ui/crw_web_controller.mm b/ios/web/web_state/ui/crw_web_controller.mm |
| index ddd16776867f016d38fd77a40dbd8e8c84627cd6..2a9ad0118b9ac63fbc0ada2f148f8f3fc45c082d 100644 |
| --- a/ios/web/web_state/ui/crw_web_controller.mm |
| +++ b/ios/web/web_state/ui/crw_web_controller.mm |
| @@ -517,6 +517,9 @@ - (void)ensureWebViewCreatedWithConfiguration:(WKWebViewConfiguration*)config; |
| - (WKWebView*)webViewWithConfiguration:(WKWebViewConfiguration*)config; |
| // Sets the value of the webView property, and performs its basic setup. |
| - (void)setWebView:(WKWebView*)webView; |
| +// Wraps the web view in a CRWWebViewContentView and adds it to the container |
| +// view. |
| +- (void)displayWebView; |
| // Removes webView, optionally tracking the URL of the evicted |
| // page for later cache-based reconstruction. |
| - (void)removeWebViewAllowingCachedReconstruction:(BOOL)allowCache; |
| @@ -4020,13 +4023,18 @@ - (void)ensureWebViewCreatedWithConfiguration:(WKWebViewConfiguration*)config { |
| _URLOnStartLoading = _defaultURL; |
| - // Add the web toolbars. |
| - [_containerView addToolbars:_webViewToolbars]; |
| + // WKWebViews with invalid or empty frames have exhibited rendering bugs, so |
| + // resize the view to match the container view upon creation. |
| + [_webView setFrame:[_containerView bounds]]; |
| - base::scoped_nsobject<CRWWebViewContentView> webViewContentView( |
| - [[CRWWebViewContentView alloc] initWithWebView:_webView |
| - scrollView:self.webScrollView]); |
| - [_containerView displayWebViewContentView:webViewContentView]; |
| + // If the visible NavigationItem should be loaded in this web view, display |
| + // it immediately. Otherwise, it will be displayed when the pending load is |
| + // committed. |
| + web::NavigationItem* visibleItem = |
| + self.navigationManagerImpl->GetVisibleItem(); |
| + DCHECK(visibleItem); |
| + if (![self shouldLoadURLInNativeView:visibleItem->GetURL()]) |
| + [self displayWebView]; |
| } |
| } |
| @@ -4079,6 +4087,19 @@ - (void)setWebView:(WKWebView*)webView { |
| [self setDocumentURL:_defaultURL]; |
| } |
| +- (void)displayWebView { |
| + if (!self.webView || [_containerView webViewContentView]) |
|
Eugene But (OOO till 7-30)
2017/04/15 00:48:51
When web view can be nil?
kkhorimoto
2017/04/17 23:42:09
It really shouldn't be. I've changed to use a DCH
|
| + return; |
| + |
| + // Add the web toolbars. |
| + [_containerView addToolbars:_webViewToolbars]; |
| + |
| + base::scoped_nsobject<CRWWebViewContentView> webViewContentView( |
| + [[CRWWebViewContentView alloc] initWithWebView:_webView |
| + scrollView:self.webScrollView]); |
| + [_containerView displayWebViewContentView:webViewContentView]; |
| +} |
| + |
| - (void)removeWebViewAllowingCachedReconstruction:(BOOL)allowCache { |
| if (!_webView) |
| return; |
| @@ -4491,6 +4512,9 @@ - (void)webView:(WKWebView*)webView |
| - (void)webView:(WKWebView*)webView |
| didCommitNavigation:(WKNavigation*)navigation { |
| + [self displayWebView]; |
| + |
| + // Record the navigation state. |
| [_navigationStates setState:web::WKNavigationState::COMMITTED |
| forNavigation:navigation]; |
| @@ -4898,7 +4922,7 @@ - (BOOL)isLoadRequestPendingForURL:(const GURL&)targetURL { |
| } |
| - (void)loadRequestForCurrentNavigationItem { |
| - DCHECK(_webView && !self.nativeController); |
| + DCHECK(_webView); |
| DCHECK(self.currentNavItem); |
| // If a load is kicked off on a WKWebView with a frame whose size is {0, 0} or |
| // that has a negative dimension for a size, rendering issues occur that |