Commit af760c91 authored by Hiroshi Ichikawa's avatar Hiroshi Ichikawa Committed by Commit Bot

Add more information to |error| of -didFailFavigationWithSSLError:.

Add error.localizedDescription and error.userInfo[CWVCertStatusKey].

Bug: 898037
Change-Id: I3e552330378992574d7c08f96f343aba6a7b4d29
Reviewed-on: https://chromium-review.googlesource.com/c/1325578Reviewed-by: default avatarCarlos IL <carlosil@chromium.org>
Reviewed-by: default avatarEugene But <eugenebut@chromium.org>
Commit-Queue: Hiroshi Ichikawa <ichikawa@chromium.org>
Cr-Commit-Position: refs/heads/master@{#607127}
parent 90d90170
...@@ -130,6 +130,7 @@ ios_web_view_sources = [ ...@@ -130,6 +130,7 @@ ios_web_view_sources = [
"internal/cwv_user_content_controller.mm", "internal/cwv_user_content_controller.mm",
"internal/cwv_user_content_controller_internal.h", "internal/cwv_user_content_controller_internal.h",
"internal/cwv_user_script.mm", "internal/cwv_user_script.mm",
"internal/cwv_navigation_delegate.mm",
"internal/cwv_web_view.mm", "internal/cwv_web_view.mm",
"internal/cwv_web_view_configuration.mm", "internal/cwv_web_view_configuration.mm",
"internal/cwv_web_view_configuration_internal.h", "internal/cwv_web_view_configuration_internal.h",
...@@ -291,6 +292,7 @@ ios_web_view_deps = [ ...@@ -291,6 +292,7 @@ ios_web_view_deps = [
"//components/version_info:version_string", "//components/version_info:version_string",
"//components/web_resource", "//components/web_resource",
"//components/webdata_services", "//components/webdata_services",
"//components/ssl_errors",
"//google_apis", "//google_apis",
"//ios/components/io_thread", "//ios/components/io_thread",
"//ios/net", "//ios/net",
......
...@@ -20,6 +20,7 @@ include_rules = [ ...@@ -20,6 +20,7 @@ include_rules = [
"+components/proxy_config", "+components/proxy_config",
"+components/signin/core", "+components/signin/core",
"+components/signin/ios", "+components/signin/ios",
"+components/ssl_errors",
"+components/strings/grit", "+components/strings/grit",
"+components/sync", "+components/sync",
"+components/sync_sessions", "+components/sync_sessions",
......
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "ios/web_view/public/cwv_navigation_delegate.h"
#if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support."
#endif
NSErrorUserInfoKey CWVCertStatusKey = @"CWVCertStatus";
...@@ -26,6 +26,7 @@ CWVSecurityStyle CWVSecurityStyleFromWebSecurityStyle( ...@@ -26,6 +26,7 @@ CWVSecurityStyle CWVSecurityStyleFromWebSecurityStyle(
return CWVSecurityStyleAuthenticated; return CWVSecurityStyleAuthenticated;
} }
} }
} // namespace
CWVCertStatus CWVCertStatusFromNetCertStatus(net::CertStatus cert_status) { CWVCertStatus CWVCertStatusFromNetCertStatus(net::CertStatus cert_status) {
CWVCertStatus cwv_status = 0; CWVCertStatus cwv_status = 0;
...@@ -76,7 +77,6 @@ CWVCertStatus CWVCertStatusFromNetCertStatus(net::CertStatus cert_status) { ...@@ -76,7 +77,6 @@ CWVCertStatus CWVCertStatusFromNetCertStatus(net::CertStatus cert_status) {
} }
return cwv_status; return cwv_status;
} }
} // namespace
@implementation CWVSSLStatus { @implementation CWVSSLStatus {
web::SSLStatus _internalStatus; web::SSLStatus _internalStatus;
......
...@@ -10,6 +10,9 @@ ...@@ -10,6 +10,9 @@
NS_ASSUME_NONNULL_BEGIN NS_ASSUME_NONNULL_BEGIN
// Converts net::CertStatus to CWVCertStatus.
CWVCertStatus CWVCertStatusFromNetCertStatus(net::CertStatus cert_status);
@interface CWVSSLStatus () @interface CWVSSLStatus ()
// Creates CWVSSLStatus which wraps |internalStatus|. // Creates CWVSSLStatus which wraps |internalStatus|.
......
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
#include "base/mac/bundle_locations.h" #include "base/mac/bundle_locations.h"
#include "base/strings/sys_string_conversions.h" #include "base/strings/sys_string_conversions.h"
#include "base/task/post_task.h" #include "base/task/post_task.h"
#include "components/ssl_errors/error_info.h"
#include "components/strings/grit/components_strings.h" #include "components/strings/grit/components_strings.h"
#include "ios/web/public/ssl_status.h" #include "ios/web/public/ssl_status.h"
#include "ios/web/public/user_agent.h" #include "ios/web/public/user_agent.h"
...@@ -111,10 +112,20 @@ void WebViewWebClient::AllowCertificateError( ...@@ -111,10 +112,20 @@ void WebViewWebClient::AllowCertificateError(
SEL selector = @selector SEL selector = @selector
(webView:didFailNavigationWithSSLError:overridable:decisionHandler:); (webView:didFailNavigationWithSSLError:overridable:decisionHandler:);
if ([web_view.navigationDelegate respondsToSelector:selector]) { if ([web_view.navigationDelegate respondsToSelector:selector]) {
// TODO(crbug.com/898037): Pass a more informative error here. CWVCertStatus cert_status = CWVCertStatusFromNetCertStatus(
NSError* error = [NSError errorWithDomain:NSURLErrorDomain net::MapNetErrorToCertStatus(cert_error));
code:NSURLErrorSecureConnectionFailed ssl_errors::ErrorInfo error_info = ssl_errors::ErrorInfo::CreateError(
userInfo:nil]; ssl_errors::ErrorInfo::NetErrorToErrorType(cert_error),
ssl_info.cert.get(), request_url);
NSString* error_description =
base::SysUTF16ToNSString(error_info.short_description());
NSError* error =
[NSError errorWithDomain:NSURLErrorDomain
code:NSURLErrorSecureConnectionFailed
userInfo:@{
NSLocalizedDescriptionKey : error_description,
CWVCertStatusKey : @(cert_status),
}];
void (^decisionHandler)(CWVSSLErrorDecision) = void (^decisionHandler)(CWVSSLErrorDecision) =
^(CWVSSLErrorDecision decision) { ^(CWVSSLErrorDecision decision) {
......
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
#import <Foundation/Foundation.h> #import <Foundation/Foundation.h>
#import "cwv_export.h"
#import "cwv_navigation_type.h" #import "cwv_navigation_type.h"
@protocol CRIWVTranslateDelegate; @protocol CRIWVTranslateDelegate;
...@@ -23,6 +24,10 @@ typedef NS_ENUM(NSInteger, CWVSSLErrorDecision) { ...@@ -23,6 +24,10 @@ typedef NS_ENUM(NSInteger, CWVSSLErrorDecision) {
CWVSSLErrorDecisionOverrideErrorAndReload, CWVSSLErrorDecisionOverrideErrorAndReload,
}; };
// A key of NSError.userInfo. The corresponding value is CWVCertStatus which
// indicates the type of the SSL error.
FOUNDATION_EXPORT CWV_EXPORT NSErrorUserInfoKey CWVCertStatusKey;
// Navigation delegate protocol for CWVWebViews. Allows embedders to hook // Navigation delegate protocol for CWVWebViews. Allows embedders to hook
// page loading and receive events for navigation. // page loading and receive events for navigation.
@protocol CWVNavigationDelegate<NSObject> @protocol CWVNavigationDelegate<NSObject>
...@@ -63,6 +68,10 @@ typedef NS_ENUM(NSInteger, CWVSSLErrorDecision) { ...@@ -63,6 +68,10 @@ typedef NS_ENUM(NSInteger, CWVSSLErrorDecision) {
// method can leave the failure as is by calling |decisionHandler| with // method can leave the failure as is by calling |decisionHandler| with
// CWVSSLErrorDecisionDoNothing. // CWVSSLErrorDecisionDoNothing.
// //
// error.localizedDescription contains localized description of the SSL error.
// error.userInfo[CWVCertStatusKey] contains CWVCertStatus which indicates the
// type of the SSL error.
//
// Note: When |decisionHandler| is called with // Note: When |decisionHandler| is called with
// CWVSSLErrorDecisionOverrideErrorAndReload, it must not be called // CWVSSLErrorDecisionOverrideErrorAndReload, it must not be called
// synchronously in the method. It breaks status management and causes an // synchronously in the method. It breaks status management and causes an
......
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