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

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: Self review 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 &&
Eugene But (OOO till 7-30) 2016/12/29 02:18:50 This is not needed with better tracking of last WK
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 addNavigation:[_webView loadRequest:request]
4830 forState:web::WK_NAVIGATION_STATE_REQUESTED];
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 addNavigation:navigation
4866 forState:web::WK_NAVIGATION_STATE_REQUESTED];
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 addNavigation:navigation
5143 forState:web::WK_NAVIGATION_STATE_STARTED];
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 addNavigation:navigation
5186 forState:web::WK_NAVIGATION_STATE_REDIRECTED];
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
5197 addNavigation:navigation
5198 forState:web::WK_NAVIGATION_STATE_PROVISIONALY_FAILED];
5199
5192 // Ignore provisional navigation failure if a new navigation has been started, 5200 // 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 5201 // for example, if a page is reloaded after the start of the provisional
5194 // load but before the load has been committed. 5202 // load but before the load has been committed.
5195 if (![_latestWKNavigation isEqual:navigation]) { 5203 if (![[_navigationStates lastAddedNavigation] isEqual:navigation]) {
5196 return; 5204 return;
5197 } 5205 }
5198 5206
5199 // TODO(crbug.com/570699): Remove this workaround once |stopLoading| does not 5207 // TODO(crbug.com/570699): Remove this workaround once |stopLoading| does not
5200 // discard pending navigation items. 5208 // discard pending navigation items.
5201 if ((!self.webStateImpl || 5209 if ((!self.webStateImpl ||
5202 !self.webStateImpl->GetNavigationManagerImpl().GetVisibleItem()) && 5210 !self.webStateImpl->GetNavigationManagerImpl().GetVisibleItem()) &&
5203 [error.domain isEqual:base::SysUTF8ToNSString(web::kWebKitErrorDomain)] && 5211 [error.domain isEqual:base::SysUTF8ToNSString(web::kWebKitErrorDomain)] &&
5204 error.code == web::kWebKitErrorFrameLoadInterruptedByPolicyChange) { 5212 error.code == web::kWebKitErrorFrameLoadInterruptedByPolicyChange) {
5205 // App is going to crash in this state (crbug.com/565457). Crash will occur 5213 // App is going to crash in this state (crbug.com/565457). Crash will occur
(...skipping 21 matching lines...) Expand all
5227 } 5235 }
5228 5236
5229 // This must be reset at the end, since code above may need information about 5237 // This must be reset at the end, since code above may need information about
5230 // the pending load. 5238 // the pending load.
5231 _pendingNavigationInfo.reset(); 5239 _pendingNavigationInfo.reset();
5232 _certVerificationErrors->Clear(); 5240 _certVerificationErrors->Clear();
5233 } 5241 }
5234 5242
5235 - (void)webView:(WKWebView*)webView 5243 - (void)webView:(WKWebView*)webView
5236 didCommitNavigation:(WKNavigation*)navigation { 5244 didCommitNavigation:(WKNavigation*)navigation {
5245 [_navigationStates addNavigation:navigation
5246 forState:web::WK_NAVIGATION_STATE_COMMITTED];
5247
5237 // This method will crash if |currentSessionEntry| is null. If this check is 5248 // This method will crash if |currentSessionEntry| is null. If this check is
5238 // hit it means that |didStartProvisionalNavigation| was called as expected 5249 // hit it means that |didStartProvisionalNavigation| was called as expected
5239 // but it did not call |registerLoadRequest|. TODO(crbug.com/676721): remove 5250 // 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 5251 // this CHECK once there is at least one crash on this line (which means that
5241 // |didStartProvisionalNavigation| did not call |registerLoadRequest| and it 5252 // |didStartProvisionalNavigation| did not call |registerLoadRequest| and it
5242 // should be fixed. 5253 // should be fixed.
5243 CHECK([self currentSessionEntry] || 5254 CHECK([self currentSessionEntry] ||
5244 ![_latestWKNavigation isEqual:navigation]); 5255 [_navigationStates stateForNavigation:navigation] ==
5256 web::WK_NAVIGATION_STATE_STARTED);
5245 5257
5246 DCHECK_EQ(_webView, webView); 5258 DCHECK_EQ(_webView, webView);
5247 _certVerificationErrors->Clear(); 5259 _certVerificationErrors->Clear();
5248 5260
5249 // This is the point where the document's URL has actually changed, and 5261 // This is the point where the document's URL has actually changed, and
5250 // pending navigation information should be applied to state information. 5262 // pending navigation information should be applied to state information.
5251 [self setDocumentURL:net::GURLWithNSURL([_webView URL])]; 5263 [self setDocumentURL:net::GURLWithNSURL([_webView URL])];
5252 5264
5253 if (!_lastRegisteredRequestURL.is_valid() && 5265 if (!_lastRegisteredRequestURL.is_valid() &&
5254 _documentURL != _lastRegisteredRequestURL) { 5266 _documentURL != _lastRegisteredRequestURL) {
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
5295 if (_documentURL.SchemeIsCryptographic()) { 5307 if (_documentURL.SchemeIsCryptographic()) {
5296 scoped_refptr<net::X509Certificate> cert = 5308 scoped_refptr<net::X509Certificate> cert =
5297 web::CreateCertFromChain([_webView certificateChain]); 5309 web::CreateCertFromChain([_webView certificateChain]);
5298 UMA_HISTOGRAM_BOOLEAN("WebController.WKWebViewHasCertForSecureConnection", 5310 UMA_HISTOGRAM_BOOLEAN("WebController.WKWebViewHasCertForSecureConnection",
5299 static_cast<bool>(cert)); 5311 static_cast<bool>(cert));
5300 } 5312 }
5301 } 5313 }
5302 5314
5303 - (void)webView:(WKWebView*)webView 5315 - (void)webView:(WKWebView*)webView
5304 didFinishNavigation:(WKNavigation*)navigation { 5316 didFinishNavigation:(WKNavigation*)navigation {
5317 [_navigationStates addNavigation:navigation
5318 forState:web::WK_NAVIGATION_STATE_FINISHED];
5319
5305 DCHECK(!_isHalted); 5320 DCHECK(!_isHalted);
5306 // Trigger JavaScript driven post-document-load-completion tasks. 5321 // Trigger JavaScript driven post-document-load-completion tasks.
5307 // TODO(crbug.com/546350): Investigate using 5322 // TODO(crbug.com/546350): Investigate using
5308 // WKUserScriptInjectionTimeAtDocumentEnd to inject this material at the 5323 // WKUserScriptInjectionTimeAtDocumentEnd to inject this material at the
5309 // appropriate time rather than invoking here. 5324 // appropriate time rather than invoking here.
5310 web::ExecuteJavaScript(webView, @"__gCrWeb.didFinishNavigation()", nil); 5325 web::ExecuteJavaScript(webView, @"__gCrWeb.didFinishNavigation()", nil);
5311 [self didFinishNavigation]; 5326 [self didFinishNavigation];
5312 } 5327 }
5313 5328
5314 - (void)webView:(WKWebView*)webView 5329 - (void)webView:(WKWebView*)webView
5315 didFailNavigation:(WKNavigation*)navigation 5330 didFailNavigation:(WKNavigation*)navigation
5316 withError:(NSError*)error { 5331 withError:(NSError*)error {
5332 [_navigationStates addNavigation:navigation
5333 forState:web::WK_NAVIGATION_STATE_FAILED];
5334
5317 [self handleLoadError:WKWebViewErrorWithSource(error, NAVIGATION) 5335 [self handleLoadError:WKWebViewErrorWithSource(error, NAVIGATION)
5318 inMainFrame:YES]; 5336 inMainFrame:YES];
5319 _certVerificationErrors->Clear(); 5337 _certVerificationErrors->Clear();
5320 } 5338 }
5321 5339
5322 - (void)webView:(WKWebView*)webView 5340 - (void)webView:(WKWebView*)webView
5323 didReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge*)challenge 5341 didReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge*)challenge
5324 completionHandler: 5342 completionHandler:
5325 (void (^)(NSURLSessionAuthChallengeDisposition, 5343 (void (^)(NSURLSessionAuthChallengeDisposition,
5326 NSURLCredential*))completionHandler { 5344 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 5692 // If the current navigation URL is the same as the URL of the visible
5675 // page, that means the user requested a reload. |goToBackForwardListItem| 5693 // 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, 5694 // will be a no-op when it is passed the current back forward list item,
5677 // so |reload| must be explicitly called. 5695 // so |reload| must be explicitly called.
5678 web::NavigationItem* item = [self currentNavItem]; 5696 web::NavigationItem* item = [self currentNavItem];
5679 GURL navigationURL = item ? item->GetURL() : GURL::EmptyGURL(); 5697 GURL navigationURL = item ? item->GetURL() : GURL::EmptyGURL();
5680 [self registerLoadRequest:navigationURL 5698 [self registerLoadRequest:navigationURL
5681 referrer:[self currentSessionEntryReferrer] 5699 referrer:[self currentSessionEntryReferrer]
5682 transition:[self currentTransition]]; 5700 transition:[self currentTransition]];
5683 if (navigationURL == net::GURLWithNSURL([_webView URL])) { 5701 if (navigationURL == net::GURLWithNSURL([_webView URL])) {
5684 [_webView reload]; 5702 [_navigationStates addNavigation:[_webView reload]
5703 forState:web::WK_NAVIGATION_STATE_REQUESTED];
5685 } else { 5704 } else {
5686 // |didCommitNavigation:| may not be called for fast navigation, so update 5705 // |didCommitNavigation:| may not be called for fast navigation, so update
5687 // the navigation type now as it is already known. 5706 // the navigation type now as it is already known.
5688 holder->set_navigation_type(WKNavigationTypeBackForward); 5707 holder->set_navigation_type(WKNavigationTypeBackForward);
5689 [_webView goToBackForwardListItem:holder->back_forward_list_item()]; 5708 WKNavigation* navigation =
5709 [_webView goToBackForwardListItem:holder->back_forward_list_item()];
5710 [_navigationStates addNavigation:navigation
5711 forState:web::WK_NAVIGATION_STATE_REQUESTED];
5690 } 5712 }
5691 }; 5713 };
5692 5714
5693 // If the request is not a form submission or resubmission, or the user 5715 // 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. 5716 // doesn't need to confirm the load, then continue right away.
5695 5717
5696 if (!isFormPOSTResubmission || 5718 if (!isFormPOSTResubmission ||
5697 currentItem->ShouldSkipResubmitDataConfirmation()) { 5719 currentItem->ShouldSkipResubmitDataConfirmation()) {
5698 webViewNavigationBlock(); 5720 webViewNavigationBlock();
5699 return; 5721 return;
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
5784 } 5806 }
5785 5807
5786 return web::WEB_VIEW_DOCUMENT_TYPE_GENERIC; 5808 return web::WEB_VIEW_DOCUMENT_TYPE_GENERIC;
5787 } 5809 }
5788 5810
5789 - (NSString*)refererFromNavigationAction:(WKNavigationAction*)action { 5811 - (NSString*)refererFromNavigationAction:(WKNavigationAction*)action {
5790 return [action.request valueForHTTPHeaderField:@"Referer"]; 5812 return [action.request valueForHTTPHeaderField:@"Referer"];
5791 } 5813 }
5792 5814
5793 @end 5815 @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