| 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 526 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 537 - (void)removePlaceholderOverlay; | 537 - (void)removePlaceholderOverlay; |
| 538 | 538 |
| 539 // Creates a web view if it's not yet created. | 539 // Creates a web view if it's not yet created. |
| 540 - (void)ensureWebViewCreated; | 540 - (void)ensureWebViewCreated; |
| 541 // Creates a web view with given |config|. No-op if web view is already created. | 541 // Creates a web view with given |config|. No-op if web view is already created. |
| 542 - (void)ensureWebViewCreatedWithConfiguration:(WKWebViewConfiguration*)config; | 542 - (void)ensureWebViewCreatedWithConfiguration:(WKWebViewConfiguration*)config; |
| 543 // Returns a new autoreleased web view created with given configuration. | 543 // Returns a new autoreleased web view created with given configuration. |
| 544 - (WKWebView*)webViewWithConfiguration:(WKWebViewConfiguration*)config; | 544 - (WKWebView*)webViewWithConfiguration:(WKWebViewConfiguration*)config; |
| 545 // Sets the value of the webView property, and performs its basic setup. | 545 // Sets the value of the webView property, and performs its basic setup. |
| 546 - (void)setWebView:(WKWebView*)webView; | 546 - (void)setWebView:(WKWebView*)webView; |
| 547 // Wraps the web view in a CRWWebViewContentView and adds it to the container |
| 548 // view. |
| 549 - (void)displayWebView; |
| 547 // Removes webView, optionally tracking the URL of the evicted | 550 // Removes webView, optionally tracking the URL of the evicted |
| 548 // page for later cache-based reconstruction. | 551 // page for later cache-based reconstruction. |
| 549 - (void)removeWebViewAllowingCachedReconstruction:(BOOL)allowCache; | 552 - (void)removeWebViewAllowingCachedReconstruction:(BOOL)allowCache; |
| 550 // Called when web view process has been terminated. | 553 // Called when web view process has been terminated. |
| 551 - (void)webViewWebProcessDidCrash; | 554 - (void)webViewWebProcessDidCrash; |
| 552 // Returns the WKWebViewConfigurationProvider associated with the web | 555 // Returns the WKWebViewConfigurationProvider associated with the web |
| 553 // controller's BrowserState. | 556 // controller's BrowserState. |
| 554 - (web::WKWebViewConfigurationProvider&)webViewConfigurationProvider; | 557 - (web::WKWebViewConfigurationProvider&)webViewConfigurationProvider; |
| 555 // Extracts "Referer" [sic] value from WKNavigationAction request header. | 558 // Extracts "Referer" [sic] value from WKNavigationAction request header. |
| 556 - (NSString*)referrerFromNavigationAction:(WKNavigationAction*)action; | 559 - (NSString*)referrerFromNavigationAction:(WKNavigationAction*)action; |
| (...skipping 3488 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4045 injectionEvaluator:self | 4048 injectionEvaluator:self |
| 4046 delegate:self]); | 4049 delegate:self]); |
| 4047 | 4050 |
| 4048 // Add all additional gesture recognizers to the web view. | 4051 // Add all additional gesture recognizers to the web view. |
| 4049 for (UIGestureRecognizer* recognizer in _gestureRecognizers.get()) { | 4052 for (UIGestureRecognizer* recognizer in _gestureRecognizers.get()) { |
| 4050 [_webView addGestureRecognizer:recognizer]; | 4053 [_webView addGestureRecognizer:recognizer]; |
| 4051 } | 4054 } |
| 4052 | 4055 |
| 4053 _URLOnStartLoading = _defaultURL; | 4056 _URLOnStartLoading = _defaultURL; |
| 4054 | 4057 |
| 4055 // Add the web toolbars. | 4058 // WKWebViews with invalid or empty frames have exhibited rendering bugs, so |
| 4056 [_containerView addToolbars:_webViewToolbars]; | 4059 // resize the view to match the container view upon creation. |
| 4060 [_webView setFrame:[_containerView bounds]]; |
| 4057 | 4061 |
| 4058 base::scoped_nsobject<CRWWebViewContentView> webViewContentView( | 4062 // If the visible NavigationItem should be loaded in this web view, display |
| 4059 [[CRWWebViewContentView alloc] initWithWebView:_webView | 4063 // it immediately. Otherwise, it will be displayed when the pending load is |
| 4060 scrollView:self.webScrollView]); | 4064 // committed. |
| 4061 [_containerView displayWebViewContentView:webViewContentView]; | 4065 web::NavigationItem* visibleItem = |
| 4066 self.navigationManagerImpl->GetVisibleItem(); |
| 4067 const GURL& visibleURL = |
| 4068 visibleItem ? visibleItem->GetURL() : GURL::EmptyGURL(); |
| 4069 if (![self shouldLoadURLInNativeView:visibleURL]) |
| 4070 [self displayWebView]; |
| 4062 } | 4071 } |
| 4063 } | 4072 } |
| 4064 | 4073 |
| 4065 - (WKWebView*)webViewWithConfiguration:(WKWebViewConfiguration*)config { | 4074 - (WKWebView*)webViewWithConfiguration:(WKWebViewConfiguration*)config { |
| 4066 // Do not attach the context menu controller immediately as the JavaScript | 4075 // Do not attach the context menu controller immediately as the JavaScript |
| 4067 // delegate must be specified. | 4076 // delegate must be specified. |
| 4068 return web::BuildWKWebView(CGRectZero, config, | 4077 return web::BuildWKWebView(CGRectZero, config, |
| 4069 self.webStateImpl->GetBrowserState(), | 4078 self.webStateImpl->GetBrowserState(), |
| 4070 self.userAgentType); | 4079 self.userAgentType); |
| 4071 } | 4080 } |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4104 } | 4113 } |
| 4105 [_webView setNavigationDelegate:self]; | 4114 [_webView setNavigationDelegate:self]; |
| 4106 [_webView setUIDelegate:self]; | 4115 [_webView setUIDelegate:self]; |
| 4107 for (NSString* keyPath in self.WKWebViewObservers) { | 4116 for (NSString* keyPath in self.WKWebViewObservers) { |
| 4108 [_webView addObserver:self forKeyPath:keyPath options:0 context:nullptr]; | 4117 [_webView addObserver:self forKeyPath:keyPath options:0 context:nullptr]; |
| 4109 } | 4118 } |
| 4110 _injectedScriptManagers.reset([[NSMutableSet alloc] init]); | 4119 _injectedScriptManagers.reset([[NSMutableSet alloc] init]); |
| 4111 [self setDocumentURL:_defaultURL]; | 4120 [self setDocumentURL:_defaultURL]; |
| 4112 } | 4121 } |
| 4113 | 4122 |
| 4123 - (void)displayWebView { |
| 4124 if (!self.webView || [_containerView webViewContentView]) |
| 4125 return; |
| 4126 |
| 4127 // Add the web toolbars. |
| 4128 [_containerView addToolbars:_webViewToolbars]; |
| 4129 |
| 4130 base::scoped_nsobject<CRWWebViewContentView> webViewContentView( |
| 4131 [[CRWWebViewContentView alloc] initWithWebView:_webView |
| 4132 scrollView:self.webScrollView]); |
| 4133 [_containerView displayWebViewContentView:webViewContentView]; |
| 4134 } |
| 4135 |
| 4114 - (void)removeWebViewAllowingCachedReconstruction:(BOOL)allowCache { | 4136 - (void)removeWebViewAllowingCachedReconstruction:(BOOL)allowCache { |
| 4115 if (!_webView) | 4137 if (!_webView) |
| 4116 return; | 4138 return; |
| 4117 | 4139 |
| 4118 _webStateImpl->CancelDialogs(); | 4140 _webStateImpl->CancelDialogs(); |
| 4119 | 4141 |
| 4120 web::NavigationItem* item = self.currentNavItem; | 4142 web::NavigationItem* item = self.currentNavItem; |
| 4121 if (allowCache && item) { | 4143 if (allowCache && item) { |
| 4122 _expectedReconstructionURL = item->GetVirtualURL(); | 4144 _expectedReconstructionURL = item->GetVirtualURL(); |
| 4123 } else { | 4145 } else { |
| (...skipping 392 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4516 } | 4538 } |
| 4517 | 4539 |
| 4518 // This must be reset at the end, since code above may need information about | 4540 // This must be reset at the end, since code above may need information about |
| 4519 // the pending load. | 4541 // the pending load. |
| 4520 _pendingNavigationInfo.reset(); | 4542 _pendingNavigationInfo.reset(); |
| 4521 _certVerificationErrors->Clear(); | 4543 _certVerificationErrors->Clear(); |
| 4522 } | 4544 } |
| 4523 | 4545 |
| 4524 - (void)webView:(WKWebView*)webView | 4546 - (void)webView:(WKWebView*)webView |
| 4525 didCommitNavigation:(WKNavigation*)navigation { | 4547 didCommitNavigation:(WKNavigation*)navigation { |
| 4548 [self displayWebView]; |
| 4549 |
| 4550 // Record the navigation state. |
| 4526 [_navigationStates setState:web::WKNavigationState::COMMITTED | 4551 [_navigationStates setState:web::WKNavigationState::COMMITTED |
| 4527 forNavigation:navigation]; | 4552 forNavigation:navigation]; |
| 4528 | 4553 |
| 4529 DCHECK_EQ(_webView, webView); | 4554 DCHECK_EQ(_webView, webView); |
| 4530 _certVerificationErrors->Clear(); | 4555 _certVerificationErrors->Clear(); |
| 4531 | 4556 |
| 4532 // This is the point where the document's URL has actually changed, and | 4557 // This is the point where the document's URL has actually changed, and |
| 4533 // pending navigation information should be applied to state information. | 4558 // pending navigation information should be applied to state information. |
| 4534 [self setDocumentURL:net::GURLWithNSURL([_webView URL])]; | 4559 [self setDocumentURL:net::GURLWithNSURL([_webView URL])]; |
| 4535 | 4560 |
| (...skipping 387 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4923 - (BOOL)isLoadRequestPendingForURL:(const GURL&)targetURL { | 4948 - (BOOL)isLoadRequestPendingForURL:(const GURL&)targetURL { |
| 4924 if (self.loadPhase != web::LOAD_REQUESTED) | 4949 if (self.loadPhase != web::LOAD_REQUESTED) |
| 4925 return NO; | 4950 return NO; |
| 4926 | 4951 |
| 4927 web::NavigationItem* pendingItem = | 4952 web::NavigationItem* pendingItem = |
| 4928 self.webState->GetNavigationManager()->GetPendingItem(); | 4953 self.webState->GetNavigationManager()->GetPendingItem(); |
| 4929 return pendingItem && pendingItem->GetURL() == targetURL; | 4954 return pendingItem && pendingItem->GetURL() == targetURL; |
| 4930 } | 4955 } |
| 4931 | 4956 |
| 4932 - (void)loadRequestForCurrentNavigationItem { | 4957 - (void)loadRequestForCurrentNavigationItem { |
| 4933 DCHECK(_webView && !self.nativeController); | 4958 DCHECK(_webView); |
| 4934 DCHECK(self.currentNavItem); | 4959 DCHECK(self.currentNavItem); |
| 4935 // If a load is kicked off on a WKWebView with a frame whose size is {0, 0} or | 4960 // If a load is kicked off on a WKWebView with a frame whose size is {0, 0} or |
| 4936 // that has a negative dimension for a size, rendering issues occur that | 4961 // that has a negative dimension for a size, rendering issues occur that |
| 4937 // manifest in erroneous scrolling and tap handling (crbug.com/574996, | 4962 // manifest in erroneous scrolling and tap handling (crbug.com/574996, |
| 4938 // crbug.com/577793). | 4963 // crbug.com/577793). |
| 4939 DCHECK_GT(CGRectGetWidth([_webView frame]), 0.0); | 4964 DCHECK_GT(CGRectGetWidth([_webView frame]), 0.0); |
| 4940 DCHECK_GT(CGRectGetHeight([_webView frame]), 0.0); | 4965 DCHECK_GT(CGRectGetHeight([_webView frame]), 0.0); |
| 4941 | 4966 |
| 4942 web::WKBackForwardListItemHolder* holder = | 4967 web::WKBackForwardListItemHolder* holder = |
| 4943 [self currentBackForwardListItemHolder]; | 4968 [self currentBackForwardListItemHolder]; |
| (...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5124 - (void)simulateLoadRequestWithURL:(const GURL&)URL { | 5149 - (void)simulateLoadRequestWithURL:(const GURL&)URL { |
| 5125 _lastRegisteredRequestURL = URL; | 5150 _lastRegisteredRequestURL = URL; |
| 5126 _loadPhase = web::LOAD_REQUESTED; | 5151 _loadPhase = web::LOAD_REQUESTED; |
| 5127 } | 5152 } |
| 5128 | 5153 |
| 5129 - (NSString*)referrerFromNavigationAction:(WKNavigationAction*)action { | 5154 - (NSString*)referrerFromNavigationAction:(WKNavigationAction*)action { |
| 5130 return [action.request valueForHTTPHeaderField:kReferrerHeaderName]; | 5155 return [action.request valueForHTTPHeaderField:kReferrerHeaderName]; |
| 5131 } | 5156 } |
| 5132 | 5157 |
| 5133 @end | 5158 @end |
| OLD | NEW |