Commit 7dc5533c authored by Eugene But's avatar Eugene But Committed by Commit Bot

Remove WKWebViewErrorSource enum.

Only 2 values of this enum were used and those values can now be
represented as a BOOL. Also that BOOL will be passed as a method
argument instead of attaching to NSError.

Bug: None
Change-Id: Ifd9985e74997e12cb87fa4d73cae0466b3a3c218
Reviewed-on: https://chromium-review.googlesource.com/c/1300755
Commit-Queue: Eugene But <eugenebut@chromium.org>
Reviewed-by: default avatarKurt Horimoto <kkhorimoto@chromium.org>
Cr-Commit-Position: refs/heads/master@{#603183}
parent 943ff34f
...@@ -174,16 +174,6 @@ enum class BackForwardNavigationType { ...@@ -174,16 +174,6 @@ enum class BackForwardNavigationType {
BACK_FORWARD_NAVIGATION_TYPE_COUNT BACK_FORWARD_NAVIGATION_TYPE_COUNT
}; };
// Constants for storing the source of NSErrors received by WKWebViews:
// - Errors received by |-webView:didFailProvisionalNavigation:withError:| are
// recorded using WKWebViewErrorSource::PROVISIONAL_LOAD. These should be
// cancelled.
// - Errors received by |-webView:didFailNavigation:withError:| are recorded
// using WKWebViewsource::NAVIGATION. These errors should not be cancelled,
// as the WKWebView will automatically retry the load.
NSString* const kWKWebViewErrorSourceKey = @"ErrorSource";
typedef enum { NONE = 0, PROVISIONAL_LOAD, NAVIGATION } WKWebViewErrorSource;
// Represents cert verification error, which happened inside // Represents cert verification error, which happened inside
// |webView:didReceiveAuthenticationChallenge:completionHandler:| and should // |webView:didReceiveAuthenticationChallenge:completionHandler:| and should
// be checked inside |webView:didFailProvisionalNavigation:withError:|. // be checked inside |webView:didFailProvisionalNavigation:withError:|.
...@@ -204,21 +194,6 @@ typedef base::MRUCache<web::CertHostPair, CertVerificationError> ...@@ -204,21 +194,6 @@ typedef base::MRUCache<web::CertHostPair, CertVerificationError>
// stored errors is not expected to be high. // stored errors is not expected to be high.
const CertVerificationErrorsCacheType::size_type kMaxCertErrorsCount = 100; const CertVerificationErrorsCacheType::size_type kMaxCertErrorsCount = 100;
// Utility function for getting the source of NSErrors received by WKWebViews.
WKWebViewErrorSource WKWebViewErrorSourceFromError(NSError* error) {
DCHECK(error);
return static_cast<WKWebViewErrorSource>(
[error.userInfo[kWKWebViewErrorSourceKey] integerValue]);
}
// Utility function for converting the WKWebViewErrorSource to the NSError
// received by WKWebViews.
NSError* WKWebViewErrorWithSource(NSError* error, WKWebViewErrorSource source) {
DCHECK(error);
NSMutableDictionary* userInfo = [error.userInfo mutableCopy];
[userInfo setObject:@(source) forKey:kWKWebViewErrorSourceKey];
return
[NSError errorWithDomain:error.domain code:error.code userInfo:userInfo];
}
} // namespace } // namespace
#pragma mark - #pragma mark -
...@@ -911,15 +886,19 @@ typedef void (^ViewportStateCompletion)(const web::PageViewportState*); ...@@ -911,15 +886,19 @@ typedef void (^ViewportStateCompletion)(const web::PageViewportState*);
transition: transition:
(ui::PageTransition)pageTransition; (ui::PageTransition)pageTransition;
// Called when a load ends in an error. // Called when a load ends in an error.
- (void)handleLoadError:(NSError*)error forNavigation:(WKNavigation*)navigation; - (void)handleLoadError:(NSError*)error
forNavigation:(WKNavigation*)navigation
provisionalLoad:(BOOL)provisionalLoad;
// Handles cancelled load in WKWebView (error with NSURLErrorCancelled code). // Handles cancelled load in WKWebView (error with NSURLErrorCancelled code).
- (void)handleCancelledError:(NSError*)error - (void)handleCancelledError:(NSError*)error
forNavigation:(WKNavigation*)navigation; forNavigation:(WKNavigation*)navigation
provisionalLoad:(BOOL)provisionalLoad;
// Used to decide whether a load that generates errors with the // Used to decide whether a load that generates errors with the
// NSURLErrorCancelled code should be cancelled. // NSURLErrorCancelled code should be cancelled.
- (BOOL)shouldCancelLoadForCancelledError:(NSError*)error; - (BOOL)shouldCancelLoadForCancelledError:(NSError*)error
provisionalLoad:(BOOL)provisionalLoad;
// Returns YES if response should be rendered in WKWebView. // Returns YES if response should be rendered in WKWebView.
- (BOOL)shouldRenderResponse:(WKNavigationResponse*)WKResponse; - (BOOL)shouldRenderResponse:(WKNavigationResponse*)WKResponse;
...@@ -3066,9 +3045,12 @@ registerLoadRequestForURL:(const GURL&)requestURL ...@@ -3066,9 +3045,12 @@ registerLoadRequestForURL:(const GURL&)requestURL
} }
- (void)handleLoadError:(NSError*)error - (void)handleLoadError:(NSError*)error
forNavigation:(WKNavigation*)navigation { forNavigation:(WKNavigation*)navigation
provisionalLoad:(BOOL)provisionalLoad {
if (error.code == NSURLErrorCancelled) { if (error.code == NSURLErrorCancelled) {
[self handleCancelledError:error forNavigation:navigation]; [self handleCancelledError:error
forNavigation:navigation
provisionalLoad:provisionalLoad];
// NSURLErrorCancelled errors that aren't handled by aborting the load will // NSURLErrorCancelled errors that aren't handled by aborting the load will
// automatically be retried by the web view, so early return in this case. // automatically be retried by the web view, so early return in this case.
return; return;
...@@ -3129,12 +3111,11 @@ registerLoadRequestForURL:(const GURL&)requestURL ...@@ -3129,12 +3111,11 @@ registerLoadRequestForURL:(const GURL&)requestURL
if (item) { if (item) {
GURL errorURL = GURL errorURL =
net::GURLWithNSURL(error.userInfo[NSURLErrorFailingURLErrorKey]); net::GURLWithNSURL(error.userInfo[NSURLErrorFailingURLErrorKey]);
WKWebViewErrorSource source = WKWebViewErrorSourceFromError(error);
web::ErrorRetryCommand command = web::ErrorRetryCommand::kDoNothing; web::ErrorRetryCommand command = web::ErrorRetryCommand::kDoNothing;
if (source == PROVISIONAL_LOAD) { if (provisionalLoad) {
command = item->error_retry_state_machine().DidFailProvisionalNavigation( command = item->error_retry_state_machine().DidFailProvisionalNavigation(
net::GURLWithNSURL(_webView.URL), errorURL); net::GURLWithNSURL(_webView.URL), errorURL);
} else if (source == NAVIGATION) { } else {
command = item->error_retry_state_machine().DidFailNavigation( command = item->error_retry_state_machine().DidFailNavigation(
net::GURLWithNSURL(_webView.URL), errorURL); net::GURLWithNSURL(_webView.URL), errorURL);
} }
...@@ -3147,16 +3128,17 @@ registerLoadRequestForURL:(const GURL&)requestURL ...@@ -3147,16 +3128,17 @@ registerLoadRequestForURL:(const GURL&)requestURL
self.navigationManagerImpl->CommitPendingItem(); self.navigationManagerImpl->CommitPendingItem();
} }
if ([_navigationStates stateForNavigation:navigation] == if (provisionalLoad) {
web::WKNavigationState::PROVISIONALY_FAILED) {
_webStateImpl->OnNavigationFinished(navigationContext); _webStateImpl->OnNavigationFinished(navigationContext);
} }
[self loadCompleteWithSuccess:NO forNavigation:navigation]; [self loadCompleteWithSuccess:NO forNavigation:navigation];
} }
- (void)handleCancelledError:(NSError*)error - (void)handleCancelledError:(NSError*)error
forNavigation:(WKNavigation*)navigation { forNavigation:(WKNavigation*)navigation
if ([self shouldCancelLoadForCancelledError:error]) { provisionalLoad:(BOOL)provisionalLoad {
if ([self shouldCancelLoadForCancelledError:error
provisionalLoad:provisionalLoad]) {
[self loadCancelled]; [self loadCancelled];
self.navigationManagerImpl->DiscardNonCommittedItems(); self.navigationManagerImpl->DiscardNonCommittedItems();
// If discarding the non-committed entries results in native content URL, // If discarding the non-committed entries results in native content URL,
...@@ -3174,14 +3156,14 @@ registerLoadRequestForURL:(const GURL&)requestURL ...@@ -3174,14 +3156,14 @@ registerLoadRequestForURL:(const GURL&)requestURL
web::NavigationContextImpl* navigationContext = web::NavigationContextImpl* navigationContext =
[_navigationStates contextForNavigation:navigation]; [_navigationStates contextForNavigation:navigation];
if ([_navigationStates stateForNavigation:navigation] == if (provisionalLoad) {
web::WKNavigationState::PROVISIONALY_FAILED) {
_webStateImpl->OnNavigationFinished(navigationContext); _webStateImpl->OnNavigationFinished(navigationContext);
} }
} }
} }
- (BOOL)shouldCancelLoadForCancelledError:(NSError*)error { - (BOOL)shouldCancelLoadForCancelledError:(NSError*)error
provisionalLoad:(BOOL)provisionalLoad {
DCHECK(error.code == NSURLErrorCancelled || DCHECK(error.code == NSURLErrorCancelled ||
error.code == web::kWebKitErrorFrameLoadInterruptedByPolicyChange); error.code == web::kWebKitErrorFrameLoadInterruptedByPolicyChange);
// Do not cancel the load if it is for an app specific URL, as such errors // Do not cancel the load if it is for an app specific URL, as such errors
...@@ -3191,10 +3173,7 @@ registerLoadRequestForURL:(const GURL&)requestURL ...@@ -3191,10 +3173,7 @@ registerLoadRequestForURL:(const GURL&)requestURL
if (web::GetWebClient()->IsAppSpecificURL(errorURL)) if (web::GetWebClient()->IsAppSpecificURL(errorURL))
return NO; return NO;
// Don't cancel NSURLErrorCancelled errors originating from navigation return provisionalLoad;
// as the WKWebView will automatically retry these loads.
WKWebViewErrorSource source = WKWebViewErrorSourceFromError(error);
return source != NAVIGATION;
} }
- (void)didReceiveWebViewNavigationDelegateCallback { - (void)didReceiveWebViewNavigationDelegateCallback {
...@@ -3836,7 +3815,7 @@ registerLoadRequestForURL:(const GURL&)requestURL ...@@ -3836,7 +3815,7 @@ registerLoadRequestForURL:(const GURL&)requestURL
// |info.cert| can be null if certChain in NSError is empty or can not be // |info.cert| can be null if certChain in NSError is empty or can not be
// parsed, in this case do not ask delegate if error should be allowed, it // parsed, in this case do not ask delegate if error should be allowed, it
// should not be. // should not be.
[self handleLoadError:error forNavigation:navigation]; [self handleLoadError:error forNavigation:navigation provisionalLoad:YES];
return; return;
} }
...@@ -4137,7 +4116,9 @@ registerLoadRequestForURL:(const GURL&)requestURL ...@@ -4137,7 +4116,9 @@ registerLoadRequestForURL:(const GURL&)requestURL
messageRouter:messageRouter messageRouter:messageRouter
completionHandler:^(NSError* loadError) { completionHandler:^(NSError* loadError) {
if (loadError) if (loadError)
[self handleLoadError:loadError forNavigation:nil]; [self handleLoadError:loadError
forNavigation:nil
provisionalLoad:YES];
else else
self.webStateImpl->SetContentsMimeType("text/html"); self.webStateImpl->SetContentsMimeType("text/html");
}]; }];
...@@ -4741,18 +4722,19 @@ registerLoadRequestForURL:(const GURL&)requestURL ...@@ -4741,18 +4722,19 @@ registerLoadRequestForURL:(const GURL&)requestURL
// Handle load cancellation for directly cancelled navigations without // Handle load cancellation for directly cancelled navigations without
// handling their potential errors. Otherwise, handle the error. // handling their potential errors. Otherwise, handle the error.
if ([_pendingNavigationInfo cancelled]) { if ([_pendingNavigationInfo cancelled]) {
[self handleCancelledError:error forNavigation:navigation]; [self handleCancelledError:error
forNavigation:navigation
provisionalLoad:YES];
} else if (error.code == NSURLErrorUnsupportedURL && } else if (error.code == NSURLErrorUnsupportedURL &&
_webStateImpl->HasWebUI()) { _webStateImpl->HasWebUI()) {
// This is a navigation to WebUI page. // This is a navigation to WebUI page.
DCHECK(web::GetWebClient()->IsAppSpecificURL( DCHECK(web::GetWebClient()->IsAppSpecificURL(
net::GURLWithNSURL(error.userInfo[NSURLErrorFailingURLErrorKey]))); net::GURLWithNSURL(error.userInfo[NSURLErrorFailingURLErrorKey])));
} else { } else {
error = WKWebViewErrorWithSource(error, PROVISIONAL_LOAD);
if (web::IsWKWebViewSSLCertError(error)) { if (web::IsWKWebViewSSLCertError(error)) {
[self handleSSLCertError:error forNavigation:navigation]; [self handleSSLCertError:error forNavigation:navigation];
} else { } else {
[self handleLoadError:error forNavigation:navigation]; [self handleLoadError:error forNavigation:navigation provisionalLoad:YES];
} }
} }
...@@ -5084,8 +5066,7 @@ registerLoadRequestForURL:(const GURL&)requestURL ...@@ -5084,8 +5066,7 @@ registerLoadRequestForURL:(const GURL&)requestURL
[_navigationStates setState:web::WKNavigationState::FAILED [_navigationStates setState:web::WKNavigationState::FAILED
forNavigation:navigation]; forNavigation:navigation];
[self handleLoadError:WKWebViewErrorWithSource(error, NAVIGATION) [self handleLoadError:error forNavigation:navigation provisionalLoad:NO];
forNavigation:navigation];
[self removeAllWebFrames]; [self removeAllWebFrames];
_certVerificationErrors->Clear(); _certVerificationErrors->Clear();
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment