Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(71)

Side by Side Diff: ios/web/web_state/ui/crw_web_controller.mm

Issue 2820013003: Display the web view after commit for non-user-initiated loads. (Closed)
Patch Set: DCHECK Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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
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 DCHECK(visibleItem);
4068 if (![self shouldLoadURLInNativeView:visibleItem->GetURL()])
4069 [self displayWebView];
4062 } 4070 }
4063 } 4071 }
4064 4072
4065 - (WKWebView*)webViewWithConfiguration:(WKWebViewConfiguration*)config { 4073 - (WKWebView*)webViewWithConfiguration:(WKWebViewConfiguration*)config {
4066 // Do not attach the context menu controller immediately as the JavaScript 4074 // Do not attach the context menu controller immediately as the JavaScript
4067 // delegate must be specified. 4075 // delegate must be specified.
4068 return web::BuildWKWebView(CGRectZero, config, 4076 return web::BuildWKWebView(CGRectZero, config,
4069 self.webStateImpl->GetBrowserState(), 4077 self.webStateImpl->GetBrowserState(),
4070 self.userAgentType); 4078 self.userAgentType);
4071 } 4079 }
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
4104 } 4112 }
4105 [_webView setNavigationDelegate:self]; 4113 [_webView setNavigationDelegate:self];
4106 [_webView setUIDelegate:self]; 4114 [_webView setUIDelegate:self];
4107 for (NSString* keyPath in self.WKWebViewObservers) { 4115 for (NSString* keyPath in self.WKWebViewObservers) {
4108 [_webView addObserver:self forKeyPath:keyPath options:0 context:nullptr]; 4116 [_webView addObserver:self forKeyPath:keyPath options:0 context:nullptr];
4109 } 4117 }
4110 _injectedScriptManagers.reset([[NSMutableSet alloc] init]); 4118 _injectedScriptManagers.reset([[NSMutableSet alloc] init]);
4111 [self setDocumentURL:_defaultURL]; 4119 [self setDocumentURL:_defaultURL];
4112 } 4120 }
4113 4121
4122 - (void)displayWebView {
4123 if ([_containerView webViewContentView])
4124 return;
4125
4126 // Add the web toolbars.
4127 [_containerView addToolbars:_webViewToolbars];
4128
4129 // Wrap the WKWebView in a content view and display it in the container.
4130 DCHECK(self.webView);
Eugene But (OOO till 7-30) 2017/04/18 00:20:13 nit: s/self.webView/_webView for consistency with
kkhorimoto 2017/04/18 00:54:13 Done.
4131 base::scoped_nsobject<CRWWebViewContentView> webViewContentView(
4132 [[CRWWebViewContentView alloc] initWithWebView:_webView
4133 scrollView:self.webScrollView]);
4134 [_containerView displayWebViewContentView:webViewContentView];
4135 }
4136
4114 - (void)removeWebViewAllowingCachedReconstruction:(BOOL)allowCache { 4137 - (void)removeWebViewAllowingCachedReconstruction:(BOOL)allowCache {
4115 if (!_webView) 4138 if (!_webView)
4116 return; 4139 return;
4117 4140
4118 _webStateImpl->CancelDialogs(); 4141 _webStateImpl->CancelDialogs();
4119 4142
4120 web::NavigationItem* item = self.currentNavItem; 4143 web::NavigationItem* item = self.currentNavItem;
4121 if (allowCache && item) { 4144 if (allowCache && item) {
4122 _expectedReconstructionURL = item->GetVirtualURL(); 4145 _expectedReconstructionURL = item->GetVirtualURL();
4123 } else { 4146 } else {
(...skipping 392 matching lines...) Expand 10 before | Expand all | Expand 10 after
4516 } 4539 }
4517 4540
4518 // This must be reset at the end, since code above may need information about 4541 // This must be reset at the end, since code above may need information about
4519 // the pending load. 4542 // the pending load.
4520 _pendingNavigationInfo.reset(); 4543 _pendingNavigationInfo.reset();
4521 _certVerificationErrors->Clear(); 4544 _certVerificationErrors->Clear();
4522 } 4545 }
4523 4546
4524 - (void)webView:(WKWebView*)webView 4547 - (void)webView:(WKWebView*)webView
4525 didCommitNavigation:(WKNavigation*)navigation { 4548 didCommitNavigation:(WKNavigation*)navigation {
4549 [self displayWebView];
4550
4551 // Record the navigation state.
4526 [_navigationStates setState:web::WKNavigationState::COMMITTED 4552 [_navigationStates setState:web::WKNavigationState::COMMITTED
4527 forNavigation:navigation]; 4553 forNavigation:navigation];
4528 4554
4529 DCHECK_EQ(_webView, webView); 4555 DCHECK_EQ(_webView, webView);
4530 _certVerificationErrors->Clear(); 4556 _certVerificationErrors->Clear();
4531 4557
4532 // This is the point where the document's URL has actually changed, and 4558 // This is the point where the document's URL has actually changed, and
4533 // pending navigation information should be applied to state information. 4559 // pending navigation information should be applied to state information.
4534 [self setDocumentURL:net::GURLWithNSURL([_webView URL])]; 4560 [self setDocumentURL:net::GURLWithNSURL([_webView URL])];
4535 4561
(...skipping 387 matching lines...) Expand 10 before | Expand all | Expand 10 after
4923 - (BOOL)isLoadRequestPendingForURL:(const GURL&)targetURL { 4949 - (BOOL)isLoadRequestPendingForURL:(const GURL&)targetURL {
4924 if (self.loadPhase != web::LOAD_REQUESTED) 4950 if (self.loadPhase != web::LOAD_REQUESTED)
4925 return NO; 4951 return NO;
4926 4952
4927 web::NavigationItem* pendingItem = 4953 web::NavigationItem* pendingItem =
4928 self.webState->GetNavigationManager()->GetPendingItem(); 4954 self.webState->GetNavigationManager()->GetPendingItem();
4929 return pendingItem && pendingItem->GetURL() == targetURL; 4955 return pendingItem && pendingItem->GetURL() == targetURL;
4930 } 4956 }
4931 4957
4932 - (void)loadRequestForCurrentNavigationItem { 4958 - (void)loadRequestForCurrentNavigationItem {
4933 DCHECK(_webView && !self.nativeController); 4959 DCHECK(_webView);
4934 DCHECK(self.currentNavItem); 4960 DCHECK(self.currentNavItem);
4935 // If a load is kicked off on a WKWebView with a frame whose size is {0, 0} or 4961 // 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 4962 // that has a negative dimension for a size, rendering issues occur that
4937 // manifest in erroneous scrolling and tap handling (crbug.com/574996, 4963 // manifest in erroneous scrolling and tap handling (crbug.com/574996,
4938 // crbug.com/577793). 4964 // crbug.com/577793).
4939 DCHECK_GT(CGRectGetWidth([_webView frame]), 0.0); 4965 DCHECK_GT(CGRectGetWidth([_webView frame]), 0.0);
4940 DCHECK_GT(CGRectGetHeight([_webView frame]), 0.0); 4966 DCHECK_GT(CGRectGetHeight([_webView frame]), 0.0);
4941 4967
4942 web::WKBackForwardListItemHolder* holder = 4968 web::WKBackForwardListItemHolder* holder =
4943 [self currentBackForwardListItemHolder]; 4969 [self currentBackForwardListItemHolder];
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after
5124 - (void)simulateLoadRequestWithURL:(const GURL&)URL { 5150 - (void)simulateLoadRequestWithURL:(const GURL&)URL {
5125 _lastRegisteredRequestURL = URL; 5151 _lastRegisteredRequestURL = URL;
5126 _loadPhase = web::LOAD_REQUESTED; 5152 _loadPhase = web::LOAD_REQUESTED;
5127 } 5153 }
5128 5154
5129 - (NSString*)referrerFromNavigationAction:(WKNavigationAction*)action { 5155 - (NSString*)referrerFromNavigationAction:(WKNavigationAction*)action {
5130 return [action.request valueForHTTPHeaderField:kReferrerHeaderName]; 5156 return [action.request valueForHTTPHeaderField:kReferrerHeaderName];
5131 } 5157 }
5132 5158
5133 @end 5159 @end
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698