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

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

Issue 2601083003: [ios] Correctly determine last seen WKNavigation object. (Closed)
Patch Set: Addressed more comments Created 3 years, 11 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 | « ios/web/BUILD.gn ('k') | ios/web/web_state/ui/crw_wk_navigation_states.h » ('j') | 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 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
81 #import "ios/web/web_state/crw_pass_kit_downloader.h" 81 #import "ios/web/web_state/crw_pass_kit_downloader.h"
82 #import "ios/web/web_state/crw_web_view_proxy_impl.h" 82 #import "ios/web/web_state/crw_web_view_proxy_impl.h"
83 #import "ios/web/web_state/error_translation_util.h" 83 #import "ios/web/web_state/error_translation_util.h"
84 #import "ios/web/web_state/js/crw_js_plugin_placeholder_manager.h" 84 #import "ios/web/web_state/js/crw_js_plugin_placeholder_manager.h"
85 #import "ios/web/web_state/js/crw_js_post_request_loader.h" 85 #import "ios/web/web_state/js/crw_js_post_request_loader.h"
86 #import "ios/web/web_state/js/crw_js_window_id_manager.h" 86 #import "ios/web/web_state/js/crw_js_window_id_manager.h"
87 #import "ios/web/web_state/page_viewport_state.h" 87 #import "ios/web/web_state/page_viewport_state.h"
88 #import "ios/web/web_state/ui/crw_swipe_recognizer_provider.h" 88 #import "ios/web/web_state/ui/crw_swipe_recognizer_provider.h"
89 #import "ios/web/web_state/ui/crw_web_controller.h" 89 #import "ios/web/web_state/ui/crw_web_controller.h"
90 #import "ios/web/web_state/ui/crw_web_controller_container_view.h" 90 #import "ios/web/web_state/ui/crw_web_controller_container_view.h"
91 #import "ios/web/web_state/ui/crw_wk_navigation_states.h"
91 #import "ios/web/web_state/ui/crw_wk_script_message_router.h" 92 #import "ios/web/web_state/ui/crw_wk_script_message_router.h"
92 #import "ios/web/web_state/ui/wk_back_forward_list_item_holder.h" 93 #import "ios/web/web_state/ui/wk_back_forward_list_item_holder.h"
93 #import "ios/web/web_state/ui/wk_web_view_configuration_provider.h" 94 #import "ios/web/web_state/ui/wk_web_view_configuration_provider.h"
94 #import "ios/web/web_state/web_controller_observer_bridge.h" 95 #import "ios/web/web_state/web_controller_observer_bridge.h"
95 #include "ios/web/web_state/web_state_facade_delegate.h" 96 #include "ios/web/web_state/web_state_facade_delegate.h"
96 #import "ios/web/web_state/web_state_impl.h" 97 #import "ios/web/web_state/web_state_impl.h"
97 #import "ios/web/web_state/web_view_internal_creation_util.h" 98 #import "ios/web/web_state/web_view_internal_creation_util.h"
98 #import "ios/web/web_state/wk_web_view_security_util.h" 99 #import "ios/web/web_state/wk_web_view_security_util.h"
99 #import "ios/web/webui/crw_web_ui_manager.h" 100 #import "ios/web/webui/crw_web_ui_manager.h"
100 #import "ios/web/webui/mojo_facade.h" 101 #import "ios/web/webui/mojo_facade.h"
(...skipping 340 matching lines...) Expand 10 before | Expand all | Expand 10 after
441 // Referrer for the current page; does not include the fragment. 442 // Referrer for the current page; does not include the fragment.
442 base::scoped_nsobject<NSString> _currentReferrerString; 443 base::scoped_nsobject<NSString> _currentReferrerString;
443 444
444 // Pending information for an in-progress page navigation. The lifetime of 445 // Pending information for an in-progress page navigation. The lifetime of
445 // this object starts at |decidePolicyForNavigationAction| where the info is 446 // this object starts at |decidePolicyForNavigationAction| where the info is
446 // extracted from the request, and ends at either |didCommitNavigation| or 447 // extracted from the request, and ends at either |didCommitNavigation| or
447 // |didFailProvisionalNavigation|. 448 // |didFailProvisionalNavigation|.
448 base::scoped_nsobject<CRWWebControllerPendingNavigationInfo> 449 base::scoped_nsobject<CRWWebControllerPendingNavigationInfo>
449 _pendingNavigationInfo; 450 _pendingNavigationInfo;
450 451
451 // The WKNavigation for the most recent load request. 452 // Holds all WKNavigation objects and their states which are currently in
452 base::scoped_nsobject<WKNavigation> _latestWKNavigation; 453 // flight.
454 base::scoped_nsobject<CRWWKNavigationStates> _navigationStates;
453 455
454 // The WKNavigation captured when |stopLoading| was called. Used for reporting 456 // The WKNavigation captured when |stopLoading| was called. Used for reporting
455 // WebController.EmptyNavigationManagerCausedByStopLoading UMA metric which 457 // WebController.EmptyNavigationManagerCausedByStopLoading UMA metric which
456 // helps with diagnosing a navigation related crash (crbug.com/565457). 458 // helps with diagnosing a navigation related crash (crbug.com/565457).
457 base::WeakNSObject<WKNavigation> _stoppedWKNavigation; 459 base::WeakNSObject<WKNavigation> _stoppedWKNavigation;
458 460
459 // CRWWebUIManager object for loading WebUI pages. 461 // CRWWebUIManager object for loading WebUI pages.
460 base::scoped_nsobject<CRWWebUIManager> _webUIManager; 462 base::scoped_nsobject<CRWWebUIManager> _webUIManager;
461 463
462 // Updates SSLStatus for current navigation item. 464 // Updates SSLStatus for current navigation item.
(...skipping 579 matching lines...) Expand 10 before | Expand all | Expand 10 after
1042 [[CRWWebViewProxyImpl alloc] initWithWebController:self]); 1044 [[CRWWebViewProxyImpl alloc] initWithWebController:self]);
1043 [[_webViewProxy scrollViewProxy] addObserver:self]; 1045 [[_webViewProxy scrollViewProxy] addObserver:self];
1044 _gestureRecognizers.reset([[NSMutableArray alloc] init]); 1046 _gestureRecognizers.reset([[NSMutableArray alloc] init]);
1045 _webViewToolbars.reset([[NSMutableArray alloc] init]); 1047 _webViewToolbars.reset([[NSMutableArray alloc] init]);
1046 _pendingLoadCompleteActions.reset([[NSMutableArray alloc] init]); 1048 _pendingLoadCompleteActions.reset([[NSMutableArray alloc] init]);
1047 web::BrowserState* browserState = _webStateImpl->GetBrowserState(); 1049 web::BrowserState* browserState = _webStateImpl->GetBrowserState();
1048 _certVerificationController.reset([[CRWCertVerificationController alloc] 1050 _certVerificationController.reset([[CRWCertVerificationController alloc]
1049 initWithBrowserState:browserState]); 1051 initWithBrowserState:browserState]);
1050 _certVerificationErrors.reset( 1052 _certVerificationErrors.reset(
1051 new CertVerificationErrorsCacheType(kMaxCertErrorsCount)); 1053 new CertVerificationErrorsCacheType(kMaxCertErrorsCount));
1054 _navigationStates.reset([[CRWWKNavigationStates alloc] init]);
1052 [[NSNotificationCenter defaultCenter] 1055 [[NSNotificationCenter defaultCenter]
1053 addObserver:self 1056 addObserver:self
1054 selector:@selector(orientationDidChange) 1057 selector:@selector(orientationDidChange)
1055 name:UIApplicationDidChangeStatusBarOrientationNotification 1058 name:UIApplicationDidChangeStatusBarOrientationNotification
1056 object:nil]; 1059 object:nil];
1057 } 1060 }
1058 return self; 1061 return self;
1059 } 1062 }
1060 1063
1061 - (id<CRWNativeContentProvider>)nativeProvider { 1064 - (id<CRWNativeContentProvider>)nativeProvider {
(...skipping 2517 matching lines...) Expand 10 before | Expand all | Expand 10 after
3579 3582
3580 - (BOOL)shouldCancelLoadForCancelledError:(NSError*)error { 3583 - (BOOL)shouldCancelLoadForCancelledError:(NSError*)error {
3581 DCHECK_EQ(error.code, NSURLErrorCancelled); 3584 DCHECK_EQ(error.code, NSURLErrorCancelled);
3582 // Do not cancel the load if it is for an app specific URL, as such errors 3585 // Do not cancel the load if it is for an app specific URL, as such errors
3583 // are produced during the app specific URL load process. 3586 // are produced during the app specific URL load process.
3584 const GURL errorURL = 3587 const GURL errorURL =
3585 net::GURLWithNSURL(error.userInfo[NSURLErrorFailingURLErrorKey]); 3588 net::GURLWithNSURL(error.userInfo[NSURLErrorFailingURLErrorKey]);
3586 if (web::GetWebClient()->IsAppSpecificURL(errorURL)) 3589 if (web::GetWebClient()->IsAppSpecificURL(errorURL))
3587 return NO; 3590 return NO;
3588 3591
3589 if (self.sessionController.pendingEntryIndex != -1 &&
3590 ![self isLoadRequestPendingForURL:errorURL]) {
3591 // Do not cancel the load if there is a pending back forward navigation for
3592 // another URL (Back forward happened in the middle of WKWebView
3593 // navigation).
3594 return NO;
3595 }
3596
3597 // Don't cancel NSURLErrorCancelled errors originating from navigation 3592 // Don't cancel NSURLErrorCancelled errors originating from navigation
3598 // as the WKWebView will automatically retry these loads. 3593 // as the WKWebView will automatically retry these loads.
3599 WKWebViewErrorSource source = WKWebViewErrorSourceFromError(error); 3594 WKWebViewErrorSource source = WKWebViewErrorSourceFromError(error);
3600 return source != NAVIGATION; 3595 return source != NAVIGATION;
3601 } 3596 }
3602 3597
3603 #pragma mark - 3598 #pragma mark -
3604 #pragma mark WebUI 3599 #pragma mark WebUI
3605 3600
3606 - (void)createWebUIForURL:(const GURL&)URL { 3601 - (void)createWebUIForURL:(const GURL&)URL {
(...skipping 1217 matching lines...) Expand 10 before | Expand all | Expand 10 after
4824 // This happens during tests. 4819 // This happens during tests.
4825 if (!_webView) { 4820 if (!_webView) {
4826 return web::WEB_VIEW_DOCUMENT_TYPE_GENERIC; 4821 return web::WEB_VIEW_DOCUMENT_TYPE_GENERIC;
4827 } 4822 }
4828 4823
4829 std::string MIMEType = self.webState->GetContentsMimeType(); 4824 std::string MIMEType = self.webState->GetContentsMimeType();
4830 return [self documentTypeFromMIMEType:base::SysUTF8ToNSString(MIMEType)]; 4825 return [self documentTypeFromMIMEType:base::SysUTF8ToNSString(MIMEType)];
4831 } 4826 }
4832 4827
4833 - (void)loadRequest:(NSMutableURLRequest*)request { 4828 - (void)loadRequest:(NSMutableURLRequest*)request {
4834 _latestWKNavigation.reset([[_webView loadRequest:request] retain]); 4829 [_navigationStates setState:web::WKNavigationState::REQUESTED
4830 forNavigation:[_webView loadRequest:request]];
4835 } 4831 }
4836 4832
4837 - (void)loadPOSTRequest:(NSMutableURLRequest*)request { 4833 - (void)loadPOSTRequest:(NSMutableURLRequest*)request {
4838 if (!_POSTRequestLoader) { 4834 if (!_POSTRequestLoader) {
4839 _POSTRequestLoader.reset([[CRWJSPOSTRequestLoader alloc] init]); 4835 _POSTRequestLoader.reset([[CRWJSPOSTRequestLoader alloc] init]);
4840 } 4836 }
4841 4837
4842 CRWWKScriptMessageRouter* messageRouter = 4838 CRWWKScriptMessageRouter* messageRouter =
4843 [self webViewConfigurationProvider].GetScriptMessageRouter(); 4839 [self webViewConfigurationProvider].GetScriptMessageRouter();
4844 4840
(...skipping 12 matching lines...) Expand all
4857 // Remove the transient content view. 4853 // Remove the transient content view.
4858 [self clearTransientContentView]; 4854 [self clearTransientContentView];
4859 4855
4860 _loadPhase = web::LOAD_REQUESTED; 4856 _loadPhase = web::LOAD_REQUESTED;
4861 4857
4862 // Web View should not be created for App Specific URLs. 4858 // Web View should not be created for App Specific URLs.
4863 if (!web::GetWebClient()->IsAppSpecificURL(URL)) { 4859 if (!web::GetWebClient()->IsAppSpecificURL(URL)) {
4864 [self ensureWebViewCreated]; 4860 [self ensureWebViewCreated];
4865 DCHECK(_webView) << "_webView null while trying to load HTML"; 4861 DCHECK(_webView) << "_webView null while trying to load HTML";
4866 } 4862 }
4867 [_webView loadHTMLString:HTML baseURL:net::NSURLWithGURL(URL)]; 4863 WKNavigation* navigation =
4864 [_webView loadHTMLString:HTML baseURL:net::NSURLWithGURL(URL)];
4865 [_navigationStates setState:web::WKNavigationState::REQUESTED
4866 forNavigation:navigation];
4868 } 4867 }
4869 4868
4870 - (void)loadHTML:(NSString*)HTML forAppSpecificURL:(const GURL&)URL { 4869 - (void)loadHTML:(NSString*)HTML forAppSpecificURL:(const GURL&)URL {
4871 CHECK(web::GetWebClient()->IsAppSpecificURL(URL)); 4870 CHECK(web::GetWebClient()->IsAppSpecificURL(URL));
4872 [self loadHTML:HTML forURL:URL]; 4871 [self loadHTML:HTML forURL:URL];
4873 } 4872 }
4874 4873
4875 - (void)loadHTMLForCurrentURL:(NSString*)HTML { 4874 - (void)loadHTMLForCurrentURL:(NSString*)HTML {
4876 [self loadHTML:HTML forURL:self.currentURL]; 4875 [self loadHTML:HTML forURL:self.currentURL];
4877 } 4876 }
4878 4877
4879 - (void)stopLoading { 4878 - (void)stopLoading {
4880 _stoppedWKNavigation.reset(_latestWKNavigation); 4879 _stoppedWKNavigation.reset([_navigationStates lastAddedNavigation]);
4881 4880
4882 base::RecordAction(UserMetricsAction("Stop")); 4881 base::RecordAction(UserMetricsAction("Stop"));
4883 // Discard the pending and transient entried before notifying the tab model 4882 // Discard the pending and transient entried before notifying the tab model
4884 // observers of the change via |-abortLoad|. 4883 // observers of the change via |-abortLoad|.
4885 [[self sessionController] discardNonCommittedEntries]; 4884 [[self sessionController] discardNonCommittedEntries];
4886 [self abortLoad]; 4885 [self abortLoad];
4887 web::NavigationItem* item = [self currentNavItem]; 4886 web::NavigationItem* item = [self currentNavItem];
4888 GURL navigationURL = item ? item->GetVirtualURL() : GURL::EmptyGURL(); 4887 GURL navigationURL = item ? item->GetVirtualURL() : GURL::EmptyGURL();
4889 // If discarding the non-committed entries results in an app-specific URL, 4888 // If discarding the non-committed entries results in an app-specific URL,
4890 // reload it in its native view. 4889 // reload it in its native view.
(...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after
5133 } 5132 }
5134 5133
5135 handler(allowNavigation ? WKNavigationResponsePolicyAllow 5134 handler(allowNavigation ? WKNavigationResponsePolicyAllow
5136 : WKNavigationResponsePolicyCancel); 5135 : WKNavigationResponsePolicyCancel);
5137 } 5136 }
5138 5137
5139 // TODO(stuartmorgan): Move all the guesswork around these states out of the 5138 // TODO(stuartmorgan): Move all the guesswork around these states out of the
5140 // superclass, and wire these up to the remaining methods. 5139 // superclass, and wire these up to the remaining methods.
5141 - (void)webView:(WKWebView*)webView 5140 - (void)webView:(WKWebView*)webView
5142 didStartProvisionalNavigation:(WKNavigation*)navigation { 5141 didStartProvisionalNavigation:(WKNavigation*)navigation {
5142 [_navigationStates setState:web::WKNavigationState::STARTED
5143 forNavigation:navigation];
5144
5143 GURL webViewURL = net::GURLWithNSURL(webView.URL); 5145 GURL webViewURL = net::GURLWithNSURL(webView.URL);
5144 if (webViewURL.is_empty()) { 5146 if (webViewURL.is_empty()) {
5145 // May happen on iOS9, however in didCommitNavigation: callback the URL 5147 // May happen on iOS9, however in didCommitNavigation: callback the URL
5146 // will be "about:blank". 5148 // will be "about:blank".
5147 webViewURL = GURL(url::kAboutBlankURL); 5149 webViewURL = GURL(url::kAboutBlankURL);
5148 } 5150 }
5149 5151
5150 // Intercept renderer-initiated navigations. If this navigation has not yet 5152 // Intercept renderer-initiated navigations. If this navigation has not yet
5151 // been registered, do so. loadPhase check is necessary because 5153 // been registered, do so. loadPhase check is necessary because
5152 // lastRegisteredRequestURL may be the same as the webViewURL on a new tab 5154 // lastRegisteredRequestURL may be the same as the webViewURL on a new tab
(...skipping 16 matching lines...) Expand all
5169 [self loadWithParams:params]; 5171 [self loadWithParams:params];
5170 } 5172 }
5171 return; 5173 return;
5172 } else { 5174 } else {
5173 [self registerLoadRequest:webViewURL]; 5175 [self registerLoadRequest:webViewURL];
5174 } 5176 }
5175 } 5177 }
5176 // Ensure the URL is registered and loadPhase is as expected. 5178 // Ensure the URL is registered and loadPhase is as expected.
5177 DCHECK(_lastRegisteredRequestURL == webViewURL); 5179 DCHECK(_lastRegisteredRequestURL == webViewURL);
5178 DCHECK(self.loadPhase == web::LOAD_REQUESTED); 5180 DCHECK(self.loadPhase == web::LOAD_REQUESTED);
5179 _latestWKNavigation.reset([navigation retain]);
5180 } 5181 }
5181 5182
5182 - (void)webView:(WKWebView*)webView 5183 - (void)webView:(WKWebView*)webView
5183 didReceiveServerRedirectForProvisionalNavigation:(WKNavigation*)navigation { 5184 didReceiveServerRedirectForProvisionalNavigation:(WKNavigation*)navigation {
5185 [_navigationStates setState:web::WKNavigationState::REDIRECTED
5186 forNavigation:navigation];
5187
5184 [self registerLoadRequest:net::GURLWithNSURL(webView.URL) 5188 [self registerLoadRequest:net::GURLWithNSURL(webView.URL)
5185 referrer:[self currentReferrer] 5189 referrer:[self currentReferrer]
5186 transition:ui::PAGE_TRANSITION_SERVER_REDIRECT]; 5190 transition:ui::PAGE_TRANSITION_SERVER_REDIRECT];
5187 } 5191 }
5188 5192
5189 - (void)webView:(WKWebView*)webView 5193 - (void)webView:(WKWebView*)webView
5190 didFailProvisionalNavigation:(WKNavigation*)navigation 5194 didFailProvisionalNavigation:(WKNavigation*)navigation
5191 withError:(NSError*)error { 5195 withError:(NSError*)error {
5196 [_navigationStates setState:web::WKNavigationState::PROVISIONALY_FAILED
5197 forNavigation:navigation];
5198
5192 // Ignore provisional navigation failure if a new navigation has been started, 5199 // Ignore provisional navigation failure if a new navigation has been started,
5193 // for example, if a page is reloaded after the start of the provisional 5200 // for example, if a page is reloaded after the start of the provisional
5194 // load but before the load has been committed. 5201 // load but before the load has been committed.
5195 if (![_latestWKNavigation isEqual:navigation]) { 5202 if (![[_navigationStates lastAddedNavigation] isEqual:navigation]) {
5196 return; 5203 return;
5197 } 5204 }
5198 5205
5199 // TODO(crbug.com/570699): Remove this workaround once |stopLoading| does not 5206 // TODO(crbug.com/570699): Remove this workaround once |stopLoading| does not
5200 // discard pending navigation items. 5207 // discard pending navigation items.
5201 if ((!self.webStateImpl || 5208 if ((!self.webStateImpl ||
5202 !self.webStateImpl->GetNavigationManagerImpl().GetVisibleItem()) && 5209 !self.webStateImpl->GetNavigationManagerImpl().GetVisibleItem()) &&
5203 [error.domain isEqual:base::SysUTF8ToNSString(web::kWebKitErrorDomain)] && 5210 [error.domain isEqual:base::SysUTF8ToNSString(web::kWebKitErrorDomain)] &&
5204 error.code == web::kWebKitErrorFrameLoadInterruptedByPolicyChange) { 5211 error.code == web::kWebKitErrorFrameLoadInterruptedByPolicyChange) {
5205 // App is going to crash in this state (crbug.com/565457). Crash will occur 5212 // App is going to crash in this state (crbug.com/565457). Crash will occur
(...skipping 27 matching lines...) Expand all
5233 } 5240 }
5234 5241
5235 - (void)webView:(WKWebView*)webView 5242 - (void)webView:(WKWebView*)webView
5236 didCommitNavigation:(WKNavigation*)navigation { 5243 didCommitNavigation:(WKNavigation*)navigation {
5237 // This method will crash if |currentSessionEntry| is null. If this check is 5244 // This method will crash if |currentSessionEntry| is null. If this check is
5238 // hit it means that |didStartProvisionalNavigation| was called as expected 5245 // hit it means that |didStartProvisionalNavigation| was called as expected
5239 // but it did not call |registerLoadRequest|. TODO(crbug.com/676721): remove 5246 // but it did not call |registerLoadRequest|. TODO(crbug.com/676721): remove
5240 // this CHECK once there is at least one crash on this line (which means that 5247 // this CHECK once there is at least one crash on this line (which means that
5241 // |didStartProvisionalNavigation| did not call |registerLoadRequest| and it 5248 // |didStartProvisionalNavigation| did not call |registerLoadRequest| and it
5242 // should be fixed. 5249 // should be fixed.
5243 CHECK([self currentSessionEntry] || 5250 CHECK([self currentSessionEntry] || !navigation ||
5244 ![_latestWKNavigation isEqual:navigation]); 5251 [_navigationStates stateForNavigation:navigation] ==
5252 web::WKNavigationState::STARTED);
5253
5254 [_navigationStates setState:web::WKNavigationState::COMMITTED
5255 forNavigation:navigation];
5245 5256
5246 DCHECK_EQ(_webView, webView); 5257 DCHECK_EQ(_webView, webView);
5247 _certVerificationErrors->Clear(); 5258 _certVerificationErrors->Clear();
5248 5259
5249 // This is the point where the document's URL has actually changed, and 5260 // This is the point where the document's URL has actually changed, and
5250 // pending navigation information should be applied to state information. 5261 // pending navigation information should be applied to state information.
5251 [self setDocumentURL:net::GURLWithNSURL([_webView URL])]; 5262 [self setDocumentURL:net::GURLWithNSURL([_webView URL])];
5252 5263
5253 if (!_lastRegisteredRequestURL.is_valid() && 5264 if (!_lastRegisteredRequestURL.is_valid() &&
5254 _documentURL != _lastRegisteredRequestURL) { 5265 _documentURL != _lastRegisteredRequestURL) {
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
5295 if (_documentURL.SchemeIsCryptographic()) { 5306 if (_documentURL.SchemeIsCryptographic()) {
5296 scoped_refptr<net::X509Certificate> cert = 5307 scoped_refptr<net::X509Certificate> cert =
5297 web::CreateCertFromChain([_webView certificateChain]); 5308 web::CreateCertFromChain([_webView certificateChain]);
5298 UMA_HISTOGRAM_BOOLEAN("WebController.WKWebViewHasCertForSecureConnection", 5309 UMA_HISTOGRAM_BOOLEAN("WebController.WKWebViewHasCertForSecureConnection",
5299 static_cast<bool>(cert)); 5310 static_cast<bool>(cert));
5300 } 5311 }
5301 } 5312 }
5302 5313
5303 - (void)webView:(WKWebView*)webView 5314 - (void)webView:(WKWebView*)webView
5304 didFinishNavigation:(WKNavigation*)navigation { 5315 didFinishNavigation:(WKNavigation*)navigation {
5316 [_navigationStates setState:web::WKNavigationState::FINISHED
5317 forNavigation:navigation];
5318
5305 DCHECK(!_isHalted); 5319 DCHECK(!_isHalted);
5306 // Trigger JavaScript driven post-document-load-completion tasks. 5320 // Trigger JavaScript driven post-document-load-completion tasks.
5307 // TODO(crbug.com/546350): Investigate using 5321 // TODO(crbug.com/546350): Investigate using
5308 // WKUserScriptInjectionTimeAtDocumentEnd to inject this material at the 5322 // WKUserScriptInjectionTimeAtDocumentEnd to inject this material at the
5309 // appropriate time rather than invoking here. 5323 // appropriate time rather than invoking here.
5310 web::ExecuteJavaScript(webView, @"__gCrWeb.didFinishNavigation()", nil); 5324 web::ExecuteJavaScript(webView, @"__gCrWeb.didFinishNavigation()", nil);
5311 [self didFinishNavigation]; 5325 [self didFinishNavigation];
5312 } 5326 }
5313 5327
5314 - (void)webView:(WKWebView*)webView 5328 - (void)webView:(WKWebView*)webView
5315 didFailNavigation:(WKNavigation*)navigation 5329 didFailNavigation:(WKNavigation*)navigation
5316 withError:(NSError*)error { 5330 withError:(NSError*)error {
5331 [_navigationStates setState:web::WKNavigationState::FAILED
5332 forNavigation:navigation];
5333
5317 [self handleLoadError:WKWebViewErrorWithSource(error, NAVIGATION) 5334 [self handleLoadError:WKWebViewErrorWithSource(error, NAVIGATION)
5318 inMainFrame:YES]; 5335 inMainFrame:YES];
5319 _certVerificationErrors->Clear(); 5336 _certVerificationErrors->Clear();
5320 } 5337 }
5321 5338
5322 - (void)webView:(WKWebView*)webView 5339 - (void)webView:(WKWebView*)webView
5323 didReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge*)challenge 5340 didReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge*)challenge
5324 completionHandler: 5341 completionHandler:
5325 (void (^)(NSURLSessionAuthChallengeDisposition, 5342 (void (^)(NSURLSessionAuthChallengeDisposition,
5326 NSURLCredential*))completionHandler { 5343 NSURLCredential*))completionHandler {
(...skipping 347 matching lines...) Expand 10 before | Expand all | Expand 10 after
5674 // If the current navigation URL is the same as the URL of the visible 5691 // If the current navigation URL is the same as the URL of the visible
5675 // page, that means the user requested a reload. |goToBackForwardListItem| 5692 // page, that means the user requested a reload. |goToBackForwardListItem|
5676 // will be a no-op when it is passed the current back forward list item, 5693 // will be a no-op when it is passed the current back forward list item,
5677 // so |reload| must be explicitly called. 5694 // so |reload| must be explicitly called.
5678 web::NavigationItem* item = [self currentNavItem]; 5695 web::NavigationItem* item = [self currentNavItem];
5679 GURL navigationURL = item ? item->GetURL() : GURL::EmptyGURL(); 5696 GURL navigationURL = item ? item->GetURL() : GURL::EmptyGURL();
5680 [self registerLoadRequest:navigationURL 5697 [self registerLoadRequest:navigationURL
5681 referrer:[self currentSessionEntryReferrer] 5698 referrer:[self currentSessionEntryReferrer]
5682 transition:[self currentTransition]]; 5699 transition:[self currentTransition]];
5683 if (navigationURL == net::GURLWithNSURL([_webView URL])) { 5700 if (navigationURL == net::GURLWithNSURL([_webView URL])) {
5684 [_webView reload]; 5701 [_navigationStates setState:web::WKNavigationState::REQUESTED
5702 forNavigation:[_webView reload]];
5685 } else { 5703 } else {
5686 // |didCommitNavigation:| may not be called for fast navigation, so update 5704 // |didCommitNavigation:| may not be called for fast navigation, so update
5687 // the navigation type now as it is already known. 5705 // the navigation type now as it is already known.
5688 holder->set_navigation_type(WKNavigationTypeBackForward); 5706 holder->set_navigation_type(WKNavigationTypeBackForward);
5689 [_webView goToBackForwardListItem:holder->back_forward_list_item()]; 5707 WKNavigation* navigation =
5708 [_webView goToBackForwardListItem:holder->back_forward_list_item()];
5709 [_navigationStates setState:web::WKNavigationState::REQUESTED
5710 forNavigation:navigation];
5690 } 5711 }
5691 }; 5712 };
5692 5713
5693 // If the request is not a form submission or resubmission, or the user 5714 // If the request is not a form submission or resubmission, or the user
5694 // doesn't need to confirm the load, then continue right away. 5715 // doesn't need to confirm the load, then continue right away.
5695 5716
5696 if (!isFormPOSTResubmission || 5717 if (!isFormPOSTResubmission ||
5697 currentItem->ShouldSkipResubmitDataConfirmation()) { 5718 currentItem->ShouldSkipResubmitDataConfirmation()) {
5698 webViewNavigationBlock(); 5719 webViewNavigationBlock();
5699 return; 5720 return;
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
5784 } 5805 }
5785 5806
5786 return web::WEB_VIEW_DOCUMENT_TYPE_GENERIC; 5807 return web::WEB_VIEW_DOCUMENT_TYPE_GENERIC;
5787 } 5808 }
5788 5809
5789 - (NSString*)refererFromNavigationAction:(WKNavigationAction*)action { 5810 - (NSString*)refererFromNavigationAction:(WKNavigationAction*)action {
5790 return [action.request valueForHTTPHeaderField:@"Referer"]; 5811 return [action.request valueForHTTPHeaderField:@"Referer"];
5791 } 5812 }
5792 5813
5793 @end 5814 @end
OLDNEW
« no previous file with comments | « ios/web/BUILD.gn ('k') | ios/web/web_state/ui/crw_wk_navigation_states.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698