Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #import "ios/web/web_state/ui/crw_web_controller.h" | 5 #import "ios/web/web_state/ui/crw_web_controller.h" |
| 6 | 6 |
| 7 #import <WebKit/WebKit.h> | 7 #import <WebKit/WebKit.h> |
| 8 | 8 |
| 9 #import <objc/runtime.h> | 9 #import <objc/runtime.h> |
| 10 #include <stddef.h> | 10 #include <stddef.h> |
| (...skipping 499 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 510 - (void)removePlaceholderOverlay; | 510 - (void)removePlaceholderOverlay; |
| 511 | 511 |
| 512 // Creates a web view if it's not yet created. | 512 // Creates a web view if it's not yet created. |
| 513 - (void)ensureWebViewCreated; | 513 - (void)ensureWebViewCreated; |
| 514 // Creates a web view with given |config|. No-op if web view is already created. | 514 // Creates a web view with given |config|. No-op if web view is already created. |
| 515 - (void)ensureWebViewCreatedWithConfiguration:(WKWebViewConfiguration*)config; | 515 - (void)ensureWebViewCreatedWithConfiguration:(WKWebViewConfiguration*)config; |
| 516 // Returns a new autoreleased web view created with given configuration. | 516 // Returns a new autoreleased web view created with given configuration. |
| 517 - (WKWebView*)webViewWithConfiguration:(WKWebViewConfiguration*)config; | 517 - (WKWebView*)webViewWithConfiguration:(WKWebViewConfiguration*)config; |
| 518 // Sets the value of the webView property, and performs its basic setup. | 518 // Sets the value of the webView property, and performs its basic setup. |
| 519 - (void)setWebView:(WKWebView*)webView; | 519 - (void)setWebView:(WKWebView*)webView; |
| 520 // Wraps the web view in a CRWWebViewContentView and adds it to the container | |
| 521 // view. | |
| 522 - (void)displayWebView; | |
| 520 // Removes webView, optionally tracking the URL of the evicted | 523 // Removes webView, optionally tracking the URL of the evicted |
| 521 // page for later cache-based reconstruction. | 524 // page for later cache-based reconstruction. |
| 522 - (void)removeWebViewAllowingCachedReconstruction:(BOOL)allowCache; | 525 - (void)removeWebViewAllowingCachedReconstruction:(BOOL)allowCache; |
| 523 // Called when web view process has been terminated. | 526 // Called when web view process has been terminated. |
| 524 - (void)webViewWebProcessDidCrash; | 527 - (void)webViewWebProcessDidCrash; |
| 525 // Returns the WKWebViewConfigurationProvider associated with the web | 528 // Returns the WKWebViewConfigurationProvider associated with the web |
| 526 // controller's BrowserState. | 529 // controller's BrowserState. |
| 527 - (web::WKWebViewConfigurationProvider&)webViewConfigurationProvider; | 530 - (web::WKWebViewConfigurationProvider&)webViewConfigurationProvider; |
| 528 // Extracts "Referer" [sic] value from WKNavigationAction request header. | 531 // Extracts "Referer" [sic] value from WKNavigationAction request header. |
| 529 - (NSString*)referrerFromNavigationAction:(WKNavigationAction*)action; | 532 - (NSString*)referrerFromNavigationAction:(WKNavigationAction*)action; |
| (...skipping 3483 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 4013 injectionEvaluator:self | 4016 injectionEvaluator:self |
| 4014 delegate:self]); | 4017 delegate:self]); |
| 4015 | 4018 |
| 4016 // Add all additional gesture recognizers to the web view. | 4019 // Add all additional gesture recognizers to the web view. |
| 4017 for (UIGestureRecognizer* recognizer in _gestureRecognizers.get()) { | 4020 for (UIGestureRecognizer* recognizer in _gestureRecognizers.get()) { |
| 4018 [_webView addGestureRecognizer:recognizer]; | 4021 [_webView addGestureRecognizer:recognizer]; |
| 4019 } | 4022 } |
| 4020 | 4023 |
| 4021 _URLOnStartLoading = _defaultURL; | 4024 _URLOnStartLoading = _defaultURL; |
| 4022 | 4025 |
| 4023 // Add the web toolbars. | 4026 // WKWebViews with invalid or empty frames have exhibited rendering bugs, so |
| 4024 [_containerView addToolbars:_webViewToolbars]; | 4027 // resize the view to match the container view upon creation. |
| 4028 [_webView setFrame:[_containerView bounds]]; | |
| 4025 | 4029 |
| 4026 base::scoped_nsobject<CRWWebViewContentView> webViewContentView( | 4030 // If the visible NavigationItem should be loaded in this web view, display |
| 4027 [[CRWWebViewContentView alloc] initWithWebView:_webView | 4031 // it immediately. Otherwise, it will be displayed when the pending load is |
| 4028 scrollView:self.webScrollView]); | 4032 // committed. |
| 4029 [_containerView displayWebViewContentView:webViewContentView]; | 4033 web::NavigationItem* visibleItem = |
| 4034 self.navigationManagerImpl->GetVisibleItem(); | |
| 4035 DCHECK(visibleItem); | |
| 4036 if (![self shouldLoadURLInNativeView:visibleItem->GetURL()]) | |
| 4037 [self displayWebView]; | |
| 4030 } | 4038 } |
| 4031 } | 4039 } |
| 4032 | 4040 |
| 4033 - (WKWebView*)webViewWithConfiguration:(WKWebViewConfiguration*)config { | 4041 - (WKWebView*)webViewWithConfiguration:(WKWebViewConfiguration*)config { |
| 4034 // Do not attach the context menu controller immediately as the JavaScript | 4042 // Do not attach the context menu controller immediately as the JavaScript |
| 4035 // delegate must be specified. | 4043 // delegate must be specified. |
| 4036 return web::BuildWKWebView(CGRectZero, config, | 4044 return web::BuildWKWebView(CGRectZero, config, |
| 4037 self.webStateImpl->GetBrowserState(), | 4045 self.webStateImpl->GetBrowserState(), |
| 4038 self.usesDesktopUserAgent); | 4046 self.usesDesktopUserAgent); |
| 4039 } | 4047 } |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 4072 } | 4080 } |
| 4073 [_webView setNavigationDelegate:self]; | 4081 [_webView setNavigationDelegate:self]; |
| 4074 [_webView setUIDelegate:self]; | 4082 [_webView setUIDelegate:self]; |
| 4075 for (NSString* keyPath in self.WKWebViewObservers) { | 4083 for (NSString* keyPath in self.WKWebViewObservers) { |
| 4076 [_webView addObserver:self forKeyPath:keyPath options:0 context:nullptr]; | 4084 [_webView addObserver:self forKeyPath:keyPath options:0 context:nullptr]; |
| 4077 } | 4085 } |
| 4078 _injectedScriptManagers.reset([[NSMutableSet alloc] init]); | 4086 _injectedScriptManagers.reset([[NSMutableSet alloc] init]); |
| 4079 [self setDocumentURL:_defaultURL]; | 4087 [self setDocumentURL:_defaultURL]; |
| 4080 } | 4088 } |
| 4081 | 4089 |
| 4090 - (void)displayWebView { | |
| 4091 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
| |
| 4092 return; | |
| 4093 | |
| 4094 // Add the web toolbars. | |
| 4095 [_containerView addToolbars:_webViewToolbars]; | |
| 4096 | |
| 4097 base::scoped_nsobject<CRWWebViewContentView> webViewContentView( | |
| 4098 [[CRWWebViewContentView alloc] initWithWebView:_webView | |
| 4099 scrollView:self.webScrollView]); | |
| 4100 [_containerView displayWebViewContentView:webViewContentView]; | |
| 4101 } | |
| 4102 | |
| 4082 - (void)removeWebViewAllowingCachedReconstruction:(BOOL)allowCache { | 4103 - (void)removeWebViewAllowingCachedReconstruction:(BOOL)allowCache { |
| 4083 if (!_webView) | 4104 if (!_webView) |
| 4084 return; | 4105 return; |
| 4085 | 4106 |
| 4086 _webStateImpl->CancelDialogs(); | 4107 _webStateImpl->CancelDialogs(); |
| 4087 | 4108 |
| 4088 web::NavigationItem* item = self.currentNavItem; | 4109 web::NavigationItem* item = self.currentNavItem; |
| 4089 if (allowCache && item) { | 4110 if (allowCache && item) { |
| 4090 _expectedReconstructionURL = item->GetVirtualURL(); | 4111 _expectedReconstructionURL = item->GetVirtualURL(); |
| 4091 } else { | 4112 } else { |
| (...skipping 392 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 4484 } | 4505 } |
| 4485 | 4506 |
| 4486 // This must be reset at the end, since code above may need information about | 4507 // This must be reset at the end, since code above may need information about |
| 4487 // the pending load. | 4508 // the pending load. |
| 4488 _pendingNavigationInfo.reset(); | 4509 _pendingNavigationInfo.reset(); |
| 4489 _certVerificationErrors->Clear(); | 4510 _certVerificationErrors->Clear(); |
| 4490 } | 4511 } |
| 4491 | 4512 |
| 4492 - (void)webView:(WKWebView*)webView | 4513 - (void)webView:(WKWebView*)webView |
| 4493 didCommitNavigation:(WKNavigation*)navigation { | 4514 didCommitNavigation:(WKNavigation*)navigation { |
| 4515 [self displayWebView]; | |
| 4516 | |
| 4517 // Record the navigation state. | |
| 4494 [_navigationStates setState:web::WKNavigationState::COMMITTED | 4518 [_navigationStates setState:web::WKNavigationState::COMMITTED |
| 4495 forNavigation:navigation]; | 4519 forNavigation:navigation]; |
| 4496 | 4520 |
| 4497 DCHECK_EQ(_webView, webView); | 4521 DCHECK_EQ(_webView, webView); |
| 4498 _certVerificationErrors->Clear(); | 4522 _certVerificationErrors->Clear(); |
| 4499 | 4523 |
| 4500 // This is the point where the document's URL has actually changed, and | 4524 // This is the point where the document's URL has actually changed, and |
| 4501 // pending navigation information should be applied to state information. | 4525 // pending navigation information should be applied to state information. |
| 4502 [self setDocumentURL:net::GURLWithNSURL([_webView URL])]; | 4526 [self setDocumentURL:net::GURLWithNSURL([_webView URL])]; |
| 4503 | 4527 |
| (...skipping 387 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 4891 - (BOOL)isLoadRequestPendingForURL:(const GURL&)targetURL { | 4915 - (BOOL)isLoadRequestPendingForURL:(const GURL&)targetURL { |
| 4892 if (self.loadPhase != web::LOAD_REQUESTED) | 4916 if (self.loadPhase != web::LOAD_REQUESTED) |
| 4893 return NO; | 4917 return NO; |
| 4894 | 4918 |
| 4895 web::NavigationItem* pendingItem = | 4919 web::NavigationItem* pendingItem = |
| 4896 self.webState->GetNavigationManager()->GetPendingItem(); | 4920 self.webState->GetNavigationManager()->GetPendingItem(); |
| 4897 return pendingItem && pendingItem->GetURL() == targetURL; | 4921 return pendingItem && pendingItem->GetURL() == targetURL; |
| 4898 } | 4922 } |
| 4899 | 4923 |
| 4900 - (void)loadRequestForCurrentNavigationItem { | 4924 - (void)loadRequestForCurrentNavigationItem { |
| 4901 DCHECK(_webView && !self.nativeController); | 4925 DCHECK(_webView); |
| 4902 DCHECK(self.currentNavItem); | 4926 DCHECK(self.currentNavItem); |
| 4903 // If a load is kicked off on a WKWebView with a frame whose size is {0, 0} or | 4927 // If a load is kicked off on a WKWebView with a frame whose size is {0, 0} or |
| 4904 // that has a negative dimension for a size, rendering issues occur that | 4928 // that has a negative dimension for a size, rendering issues occur that |
| 4905 // manifest in erroneous scrolling and tap handling (crbug.com/574996, | 4929 // manifest in erroneous scrolling and tap handling (crbug.com/574996, |
| 4906 // crbug.com/577793). | 4930 // crbug.com/577793). |
| 4907 DCHECK_GT(CGRectGetWidth([_webView frame]), 0.0); | 4931 DCHECK_GT(CGRectGetWidth([_webView frame]), 0.0); |
| 4908 DCHECK_GT(CGRectGetHeight([_webView frame]), 0.0); | 4932 DCHECK_GT(CGRectGetHeight([_webView frame]), 0.0); |
| 4909 | 4933 |
| 4910 web::WKBackForwardListItemHolder* holder = | 4934 web::WKBackForwardListItemHolder* holder = |
| 4911 [self currentBackForwardListItemHolder]; | 4935 [self currentBackForwardListItemHolder]; |
| (...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 5066 - (void)simulateLoadRequestWithURL:(const GURL&)URL { | 5090 - (void)simulateLoadRequestWithURL:(const GURL&)URL { |
| 5067 _lastRegisteredRequestURL = URL; | 5091 _lastRegisteredRequestURL = URL; |
| 5068 _loadPhase = web::LOAD_REQUESTED; | 5092 _loadPhase = web::LOAD_REQUESTED; |
| 5069 } | 5093 } |
| 5070 | 5094 |
| 5071 - (NSString*)referrerFromNavigationAction:(WKNavigationAction*)action { | 5095 - (NSString*)referrerFromNavigationAction:(WKNavigationAction*)action { |
| 5072 return [action.request valueForHTTPHeaderField:kReferrerHeaderName]; | 5096 return [action.request valueForHTTPHeaderField:kReferrerHeaderName]; |
| 5073 } | 5097 } |
| 5074 | 5098 |
| 5075 @end | 5099 @end |
| OLD | NEW |