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

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

Issue 2872823002: Display the web view after commit for non-user-initiated loads. (Closed)
Patch Set: Created 3 years, 7 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 499 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 3490 matching lines...) Expand 10 before | Expand all | Expand 10 after
4020 injectionEvaluator:self 4023 injectionEvaluator:self
4021 delegate:self]); 4024 delegate:self]);
4022 4025
4023 // Add all additional gesture recognizers to the web view. 4026 // Add all additional gesture recognizers to the web view.
4024 for (UIGestureRecognizer* recognizer in _gestureRecognizers.get()) { 4027 for (UIGestureRecognizer* recognizer in _gestureRecognizers.get()) {
4025 [_webView addGestureRecognizer:recognizer]; 4028 [_webView addGestureRecognizer:recognizer];
4026 } 4029 }
4027 4030
4028 _URLOnStartLoading = _defaultURL; 4031 _URLOnStartLoading = _defaultURL;
4029 4032
4030 // Add the web toolbars. 4033 // WKWebViews with invalid or empty frames have exhibited rendering bugs, so
4031 [_containerView addToolbars:_webViewToolbars]; 4034 // resize the view to match the container view upon creation.
4035 [_webView setFrame:[_containerView bounds]];
4032 4036
4033 base::scoped_nsobject<CRWWebViewContentView> webViewContentView( 4037 // If the visible NavigationItem should be loaded in this web view, display
4034 [[CRWWebViewContentView alloc] initWithWebView:_webView 4038 // it immediately. Otherwise, it will be displayed when the pending load is
4035 scrollView:self.webScrollView]); 4039 // committed.
4036 [_containerView displayWebViewContentView:webViewContentView]; 4040 web::NavigationItem* visibleItem =
4041 self.navigationManagerImpl->GetVisibleItem();
4042 const GURL& visibleURL =
4043 visibleItem ? visibleItem->GetURL() : GURL::EmptyGURL();
4044 if (![self shouldLoadURLInNativeView:visibleURL])
4045 [self displayWebView];
4037 } 4046 }
4038 } 4047 }
4039 4048
4040 - (WKWebView*)webViewWithConfiguration:(WKWebViewConfiguration*)config { 4049 - (WKWebView*)webViewWithConfiguration:(WKWebViewConfiguration*)config {
4041 // Do not attach the context menu controller immediately as the JavaScript 4050 // Do not attach the context menu controller immediately as the JavaScript
4042 // delegate must be specified. 4051 // delegate must be specified.
4043 return web::BuildWKWebView(CGRectZero, config, 4052 return web::BuildWKWebView(CGRectZero, config,
4044 self.webStateImpl->GetBrowserState(), 4053 self.webStateImpl->GetBrowserState(),
4045 self.usesDesktopUserAgent); 4054 self.usesDesktopUserAgent);
4046 } 4055 }
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
4079 } 4088 }
4080 [_webView setNavigationDelegate:self]; 4089 [_webView setNavigationDelegate:self];
4081 [_webView setUIDelegate:self]; 4090 [_webView setUIDelegate:self];
4082 for (NSString* keyPath in self.WKWebViewObservers) { 4091 for (NSString* keyPath in self.WKWebViewObservers) {
4083 [_webView addObserver:self forKeyPath:keyPath options:0 context:nullptr]; 4092 [_webView addObserver:self forKeyPath:keyPath options:0 context:nullptr];
4084 } 4093 }
4085 _injectedScriptManagers.reset([[NSMutableSet alloc] init]); 4094 _injectedScriptManagers.reset([[NSMutableSet alloc] init]);
4086 [self setDocumentURL:_defaultURL]; 4095 [self setDocumentURL:_defaultURL];
4087 } 4096 }
4088 4097
4098 - (void)displayWebView {
4099 if (!self.webView || [_containerView webViewContentView])
4100 return;
4101
4102 // Add the web toolbars.
4103 [_containerView addToolbars:_webViewToolbars];
4104
4105 base::scoped_nsobject<CRWWebViewContentView> webViewContentView(
4106 [[CRWWebViewContentView alloc] initWithWebView:_webView
4107 scrollView:self.webScrollView]);
4108 [_containerView displayWebViewContentView:webViewContentView];
4109 }
4110
4089 - (void)removeWebViewAllowingCachedReconstruction:(BOOL)allowCache { 4111 - (void)removeWebViewAllowingCachedReconstruction:(BOOL)allowCache {
4090 if (!_webView) 4112 if (!_webView)
4091 return; 4113 return;
4092 4114
4093 _webStateImpl->CancelDialogs(); 4115 _webStateImpl->CancelDialogs();
4094 4116
4095 web::NavigationItem* item = self.currentNavItem; 4117 web::NavigationItem* item = self.currentNavItem;
4096 if (allowCache && item) { 4118 if (allowCache && item) {
4097 _expectedReconstructionURL = item->GetVirtualURL(); 4119 _expectedReconstructionURL = item->GetVirtualURL();
4098 } else { 4120 } else {
(...skipping 401 matching lines...) Expand 10 before | Expand all | Expand 10 after
4500 } 4522 }
4501 4523
4502 // This must be reset at the end, since code above may need information about 4524 // This must be reset at the end, since code above may need information about
4503 // the pending load. 4525 // the pending load.
4504 _pendingNavigationInfo.reset(); 4526 _pendingNavigationInfo.reset();
4505 _certVerificationErrors->Clear(); 4527 _certVerificationErrors->Clear();
4506 } 4528 }
4507 4529
4508 - (void)webView:(WKWebView*)webView 4530 - (void)webView:(WKWebView*)webView
4509 didCommitNavigation:(WKNavigation*)navigation { 4531 didCommitNavigation:(WKNavigation*)navigation {
4532 [self displayWebView];
4533
4534 // Record the navigation state.
4510 [_navigationStates setState:web::WKNavigationState::COMMITTED 4535 [_navigationStates setState:web::WKNavigationState::COMMITTED
4511 forNavigation:navigation]; 4536 forNavigation:navigation];
4512 4537
4513 DCHECK_EQ(_webView, webView); 4538 DCHECK_EQ(_webView, webView);
4514 _certVerificationErrors->Clear(); 4539 _certVerificationErrors->Clear();
4515 4540
4516 // This is the point where the document's URL has actually changed, and 4541 // This is the point where the document's URL has actually changed, and
4517 // pending navigation information should be applied to state information. 4542 // pending navigation information should be applied to state information.
4518 [self setDocumentURL:net::GURLWithNSURL([_webView URL])]; 4543 [self setDocumentURL:net::GURLWithNSURL([_webView URL])];
4519 4544
(...skipping 411 matching lines...) Expand 10 before | Expand all | Expand 10 after
4931 - (BOOL)isLoadRequestPendingForURL:(const GURL&)targetURL { 4956 - (BOOL)isLoadRequestPendingForURL:(const GURL&)targetURL {
4932 if (self.loadPhase != web::LOAD_REQUESTED) 4957 if (self.loadPhase != web::LOAD_REQUESTED)
4933 return NO; 4958 return NO;
4934 4959
4935 web::NavigationItem* pendingItem = 4960 web::NavigationItem* pendingItem =
4936 self.webState->GetNavigationManager()->GetPendingItem(); 4961 self.webState->GetNavigationManager()->GetPendingItem();
4937 return pendingItem && pendingItem->GetURL() == targetURL; 4962 return pendingItem && pendingItem->GetURL() == targetURL;
4938 } 4963 }
4939 4964
4940 - (void)loadRequestForCurrentNavigationItem { 4965 - (void)loadRequestForCurrentNavigationItem {
4941 DCHECK(_webView && !self.nativeController); 4966 DCHECK(_webView);
4942 DCHECK(self.currentNavItem); 4967 DCHECK(self.currentNavItem);
4943 // If a load is kicked off on a WKWebView with a frame whose size is {0, 0} or 4968 // If a load is kicked off on a WKWebView with a frame whose size is {0, 0} or
4944 // that has a negative dimension for a size, rendering issues occur that 4969 // that has a negative dimension for a size, rendering issues occur that
4945 // manifest in erroneous scrolling and tap handling (crbug.com/574996, 4970 // manifest in erroneous scrolling and tap handling (crbug.com/574996,
4946 // crbug.com/577793). 4971 // crbug.com/577793).
4947 DCHECK_GT(CGRectGetWidth([_webView frame]), 0.0); 4972 DCHECK_GT(CGRectGetWidth([_webView frame]), 0.0);
4948 DCHECK_GT(CGRectGetHeight([_webView frame]), 0.0); 4973 DCHECK_GT(CGRectGetHeight([_webView frame]), 0.0);
4949 4974
4950 web::WKBackForwardListItemHolder* holder = 4975 web::WKBackForwardListItemHolder* holder =
4951 [self currentBackForwardListItemHolder]; 4976 [self currentBackForwardListItemHolder];
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after
5106 - (void)simulateLoadRequestWithURL:(const GURL&)URL { 5131 - (void)simulateLoadRequestWithURL:(const GURL&)URL {
5107 _lastRegisteredRequestURL = URL; 5132 _lastRegisteredRequestURL = URL;
5108 _loadPhase = web::LOAD_REQUESTED; 5133 _loadPhase = web::LOAD_REQUESTED;
5109 } 5134 }
5110 5135
5111 - (NSString*)referrerFromNavigationAction:(WKNavigationAction*)action { 5136 - (NSString*)referrerFromNavigationAction:(WKNavigationAction*)action {
5112 return [action.request valueForHTTPHeaderField:kReferrerHeaderName]; 5137 return [action.request valueForHTTPHeaderField:kReferrerHeaderName];
5113 } 5138 }
5114 5139
5115 @end 5140 @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