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

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

Issue 1357773002: WKWebView: Implemented recoverable SSL interstitials. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@lock_coloring
Patch Set: Addressed unit tests review comments Created 5 years, 1 month 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
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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_wk_web_view_web_controller.h" 5 #import "ios/web/web_state/ui/crw_wk_web_view_web_controller.h"
6 6
7 #import <WebKit/WebKit.h> 7 #import <WebKit/WebKit.h>
8 8
9 #include "base/containers/mru_cache.h"
9 #include "base/ios/ios_util.h" 10 #include "base/ios/ios_util.h"
10 #include "base/ios/weak_nsobject.h" 11 #include "base/ios/weak_nsobject.h"
11 #include "base/json/json_reader.h" 12 #include "base/json/json_reader.h"
12 #import "base/mac/scoped_nsobject.h" 13 #import "base/mac/scoped_nsobject.h"
13 #include "base/macros.h" 14 #include "base/macros.h"
14 #include "base/metrics/histogram_macros.h" 15 #include "base/metrics/histogram_macros.h"
15 #include "base/strings/sys_string_conversions.h" 16 #include "base/strings/sys_string_conversions.h"
16 #include "base/values.h" 17 #include "base/values.h"
17 #import "ios/net/http_response_headers_util.h" 18 #import "ios/net/http_response_headers_util.h"
18 #import "ios/web/crw_network_activity_indicator_manager.h" 19 #import "ios/web/crw_network_activity_indicator_manager.h"
19 #import "ios/web/navigation/crw_session_controller.h" 20 #import "ios/web/navigation/crw_session_controller.h"
20 #import "ios/web/navigation/crw_session_entry.h" 21 #import "ios/web/navigation/crw_session_entry.h"
21 #include "ios/web/navigation/navigation_item_impl.h" 22 #include "ios/web/navigation/navigation_item_impl.h"
22 #include "ios/web/navigation/web_load_params.h" 23 #include "ios/web/navigation/web_load_params.h"
24 #include "ios/web/net/cert_host_pair.h"
23 #import "ios/web/net/crw_cert_verification_controller.h" 25 #import "ios/web/net/crw_cert_verification_controller.h"
24 #include "ios/web/public/cert_store.h" 26 #include "ios/web/public/cert_store.h"
25 #include "ios/web/public/navigation_item.h" 27 #include "ios/web/public/navigation_item.h"
26 #include "ios/web/public/ssl_status.h" 28 #include "ios/web/public/ssl_status.h"
27 #include "ios/web/public/web_client.h" 29 #include "ios/web/public/web_client.h"
28 #import "ios/web/public/web_state/js/crw_js_injection_manager.h" 30 #import "ios/web/public/web_state/js/crw_js_injection_manager.h"
29 #import "ios/web/public/web_state/ui/crw_native_content_provider.h" 31 #import "ios/web/public/web_state/ui/crw_native_content_provider.h"
30 #import "ios/web/public/web_state/ui/crw_web_view_content_view.h" 32 #import "ios/web/public/web_state/ui/crw_web_view_content_view.h"
31 #import "ios/web/ui_web_view_util.h" 33 #import "ios/web/ui_web_view_util.h"
32 #include "ios/web/web_state/blocked_popup_info.h" 34 #include "ios/web/web_state/blocked_popup_info.h"
33 #import "ios/web/web_state/error_translation_util.h" 35 #import "ios/web/web_state/error_translation_util.h"
34 #include "ios/web/web_state/frame_info.h" 36 #include "ios/web/web_state/frame_info.h"
35 #import "ios/web/web_state/js/crw_js_window_id_manager.h" 37 #import "ios/web/web_state/js/crw_js_window_id_manager.h"
36 #import "ios/web/web_state/ui/crw_web_controller+protected.h" 38 #import "ios/web/web_state/ui/crw_web_controller+protected.h"
37 #import "ios/web/web_state/ui/crw_wk_script_message_router.h" 39 #import "ios/web/web_state/ui/crw_wk_script_message_router.h"
38 #import "ios/web/web_state/ui/crw_wk_web_view_crash_detector.h" 40 #import "ios/web/web_state/ui/crw_wk_web_view_crash_detector.h"
39 #import "ios/web/web_state/ui/web_view_js_utils.h" 41 #import "ios/web/web_state/ui/web_view_js_utils.h"
40 #import "ios/web/web_state/ui/wk_back_forward_list_item_holder.h" 42 #import "ios/web/web_state/ui/wk_back_forward_list_item_holder.h"
41 #import "ios/web/web_state/ui/wk_web_view_configuration_provider.h" 43 #import "ios/web/web_state/ui/wk_web_view_configuration_provider.h"
42 #import "ios/web/web_state/web_state_impl.h" 44 #import "ios/web/web_state/web_state_impl.h"
43 #import "ios/web/web_state/web_view_internal_creation_util.h" 45 #import "ios/web/web_state/web_view_internal_creation_util.h"
44 #import "ios/web/web_state/wk_web_view_security_util.h" 46 #import "ios/web/web_state/wk_web_view_security_util.h"
45 #import "ios/web/webui/crw_web_ui_manager.h" 47 #import "ios/web/webui/crw_web_ui_manager.h"
48 #import "net/base/mac/url_conversions.h"
46 #include "net/cert/x509_certificate.h" 49 #include "net/cert/x509_certificate.h"
47 #import "net/base/mac/url_conversions.h"
48 #include "net/ssl/ssl_info.h" 50 #include "net/ssl/ssl_info.h"
49 #include "url/url_constants.h" 51 #include "url/url_constants.h"
50 52
51 namespace { 53 namespace {
54
55 // Represents cert verification error, which happened inside
56 // |webView:didReceiveAuthenticationChallenge:completionHandler:| and should
57 // be checked inside |webView:didFailProvisionalNavigation:withError:|.
58 struct CertVerificationError {
59 CertVerificationError(BOOL is_recoverable, net::CertStatus status)
60 : is_recoverable(is_recoverable), status(status) {}
61
62 BOOL is_recoverable;
63 net::CertStatus status;
64 };
65
66 // Type of Cache object for storing cert verification errors.
67 typedef base::MRUCache<web::CertHostPair, CertVerificationError>
68 CertVerificationErrorsCacheType;
69
70 // Maximum number of errors to store in cert verification errors cache.
71 // Cache holds errors only for pending navigations, so the actual number of
72 // stored errors is not expected to be high.
73 const CertVerificationErrorsCacheType::size_type kMaxCertErrorsCount = 100;
74
52 // Extracts Referer value from WKNavigationAction request header. 75 // Extracts Referer value from WKNavigationAction request header.
53 NSString* GetRefererFromNavigationAction(WKNavigationAction* action) { 76 NSString* GetRefererFromNavigationAction(WKNavigationAction* action) {
54 return [action.request valueForHTTPHeaderField:@"Referer"]; 77 return [action.request valueForHTTPHeaderField:@"Referer"];
55 } 78 }
56 79
57 NSString* const kScriptMessageName = @"crwebinvoke"; 80 NSString* const kScriptMessageName = @"crwebinvoke";
58 NSString* const kScriptImmediateName = @"crwebinvokeimmediate"; 81 NSString* const kScriptImmediateName = @"crwebinvokeimmediate";
59 82
60 // Utility functions for storing the source of NSErrors received by WKWebViews: 83 // Utility functions for storing the source of NSErrors received by WKWebViews:
61 // - Errors received by |-webView:didFailProvisionalNavigation:withError:| are 84 // - Errors received by |-webView:didFailProvisionalNavigation:withError:| are
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
137 // bad SSL cert, presenting SSL interstitials and determining SSL status for 160 // bad SSL cert, presenting SSL interstitials and determining SSL status for
138 // Navigation Items. 161 // Navigation Items.
139 base::scoped_nsobject<CRWCertVerificationController> 162 base::scoped_nsobject<CRWCertVerificationController>
140 _certVerificationController; 163 _certVerificationController;
141 164
142 // Whether the pending navigation has been directly cancelled in 165 // Whether the pending navigation has been directly cancelled in
143 // |decidePolicyForNavigationAction| or |decidePolicyForNavigationResponse|. 166 // |decidePolicyForNavigationAction| or |decidePolicyForNavigationResponse|.
144 // Cancelled navigations should be simply discarded without handling any 167 // Cancelled navigations should be simply discarded without handling any
145 // specific error. 168 // specific error.
146 BOOL _pendingNavigationCancelled; 169 BOOL _pendingNavigationCancelled;
170
171 // CertVerification errors which happened inside
172 // |webView:didReceiveAuthenticationChallenge:completionHandler:|.
173 // Key is leaf-cert/host pair. This storage is used to carry calculated
174 // cert status from |didReceiveAuthenticationChallenge:| to
175 // |didFailProvisionalNavigation:| delegate method.
176 scoped_ptr<CertVerificationErrorsCacheType> _certVerificationErrors;
147 } 177 }
148 178
149 // Response's MIME type of the last known navigation. 179 // Response's MIME type of the last known navigation.
150 @property(nonatomic, copy) NSString* documentMIMEType; 180 @property(nonatomic, copy) NSString* documentMIMEType;
151 181
152 // Dictionary where keys are the names of WKWebView properties and values are 182 // Dictionary where keys are the names of WKWebView properties and values are
153 // selector names which should be called when a corresponding property has 183 // selector names which should be called when a corresponding property has
154 // changed. e.g. @{ @"URL" : @"webViewURLDidChange" } means that 184 // changed. e.g. @{ @"URL" : @"webViewURLDidChange" } means that
155 // -[self webViewURLDidChange] must be called every time when WKWebView.URL is 185 // -[self webViewURLDidChange] must be called every time when WKWebView.URL is
156 // changed. 186 // changed.
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
264 // updates current navigation item. Before scheduling update changes SSLStatus' 294 // updates current navigation item. Before scheduling update changes SSLStatus'
265 // cert_status and security_style to default. 295 // cert_status and security_style to default.
266 - (void)scheduleSSLStatusUpdateUsingCertChain:(NSArray*)chain 296 - (void)scheduleSSLStatusUpdateUsingCertChain:(NSArray*)chain
267 host:(NSString*)host; 297 host:(NSString*)host;
268 298
269 // Updates SSL status for the current navigation item based on the information 299 // Updates SSL status for the current navigation item based on the information
270 // provided by web view. 300 // provided by web view.
271 - (void)updateSSLStatusForCurrentNavigationItem; 301 - (void)updateSSLStatusForCurrentNavigationItem;
272 #endif 302 #endif
273 303
304 // Used in webView:didReceiveAuthenticationChallenge:completionHandler: to reply
305 // with NSURLSessionAuthChallengeDisposition and credentials.
306 - (void)processAuthChallenge:(NSURLAuthenticationChallenge*)challenge
307 forCertAcceptPolicy:(web::CertAcceptPolicy)policy
308 certStatus:(net::CertStatus)certStatus
309 completionHandler:(void (^)(NSURLSessionAuthChallengeDisposition,
310 NSURLCredential*))completionHandler;
311
274 // Registers load request with empty referrer and link or client redirect 312 // Registers load request with empty referrer and link or client redirect
275 // transition based on user interaction state. 313 // transition based on user interaction state.
276 - (void)registerLoadRequest:(const GURL&)url; 314 - (void)registerLoadRequest:(const GURL&)url;
277 315
278 // Called when a non-document-changing URL change occurs. Updates the 316 // Called when a non-document-changing URL change occurs. Updates the
279 // _documentURL, and informs the superclass of the change. 317 // _documentURL, and informs the superclass of the change.
280 - (void)URLDidChangeWithoutDocumentChange:(const GURL&)URL; 318 - (void)URLDidChangeWithoutDocumentChange:(const GURL&)URL;
281 319
282 // Called when web controller receives a new message from the web page. 320 // Called when web controller receives a new message from the web page.
283 - (void)didReceiveScriptMessage:(WKScriptMessage*)message; 321 - (void)didReceiveScriptMessage:(WKScriptMessage*)message;
(...skipping 29 matching lines...) Expand all
313 351
314 #pragma mark CRWWebController public methods 352 #pragma mark CRWWebController public methods
315 353
316 - (instancetype)initWithWebState:(scoped_ptr<web::WebStateImpl>)webState { 354 - (instancetype)initWithWebState:(scoped_ptr<web::WebStateImpl>)webState {
317 DCHECK(webState); 355 DCHECK(webState);
318 web::BrowserState* browserState = webState->GetBrowserState(); 356 web::BrowserState* browserState = webState->GetBrowserState();
319 self = [super initWithWebState:webState.Pass()]; 357 self = [super initWithWebState:webState.Pass()];
320 if (self) { 358 if (self) {
321 _certVerificationController.reset([[CRWCertVerificationController alloc] 359 _certVerificationController.reset([[CRWCertVerificationController alloc]
322 initWithBrowserState:browserState]); 360 initWithBrowserState:browserState]);
361 _certVerificationErrors.reset(
362 new CertVerificationErrorsCacheType(kMaxCertErrorsCount));
323 } 363 }
324 return self; 364 return self;
325 } 365 }
326 366
327 - (BOOL)keyboardDisplayRequiresUserAction { 367 - (BOOL)keyboardDisplayRequiresUserAction {
328 // TODO(stuartmorgan): Find out whether YES or NO is correct; see comment 368 // TODO(stuartmorgan): Find out whether YES or NO is correct; see comment
329 // in protected header. 369 // in protected header.
330 NOTIMPLEMENTED(); 370 NOTIMPLEMENTED();
331 return NO; 371 return NO;
332 } 372 }
(...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after
559 } 599 }
560 return [super URLForHistoryNavigationFromItem:fromItem toItem:toItem]; 600 return [super URLForHistoryNavigationFromItem:fromItem toItem:toItem];
561 } 601 }
562 602
563 - (void)setPageChangeProbability:(web::PageChangeProbability)probability { 603 - (void)setPageChangeProbability:(web::PageChangeProbability)probability {
564 // Nothing to do; no polling timer. 604 // Nothing to do; no polling timer.
565 } 605 }
566 606
567 - (void)abortWebLoad { 607 - (void)abortWebLoad {
568 [_wkWebView stopLoading]; 608 [_wkWebView stopLoading];
609 _certVerificationErrors->Clear();
569 } 610 }
570 611
571 - (void)resetLoadState { 612 - (void)resetLoadState {
572 // Nothing to do. 613 // Nothing to do.
573 } 614 }
574 615
575 - (void)setSuppressDialogsWithHelperScript:(NSString*)script { 616 - (void)setSuppressDialogsWithHelperScript:(NSString*)script {
576 [self evaluateJavaScript:script stringResultHandler:nil]; 617 [self evaluateJavaScript:script stringResultHandler:nil];
577 } 618 }
578 619
(...skipping 278 matching lines...) Expand 10 before | Expand all | Expand 10 after
857 sourceURL:sourceURL 898 sourceURL:sourceURL
858 referrerPolicy:base::SysNSStringToUTF8(policy)]; 899 referrerPolicy:base::SysNSStringToUTF8(policy)];
859 }]; 900 }];
860 }); 901 });
861 } 902 }
862 903
863 #if !defined(ENABLE_CHROME_NET_STACK_FOR_WKWEBVIEW) 904 #if !defined(ENABLE_CHROME_NET_STACK_FOR_WKWEBVIEW)
864 - (void)handleSSLCertError:(NSError*)error { 905 - (void)handleSSLCertError:(NSError*)error {
865 DCHECK(web::IsWKWebViewSSLCertError(error)); 906 DCHECK(web::IsWKWebViewSSLCertError(error));
866 907
867 net::SSLInfo sslInfo; 908 net::SSLInfo info;
868 web::GetSSLInfoFromWKWebViewSSLCertError(error, &sslInfo); 909 web::GetSSLInfoFromWKWebViewSSLCertError(error, &info);
869 910
870 web::SSLStatus sslStatus; 911 web::SSLStatus status;
871 sslStatus.security_style = web::SECURITY_STYLE_AUTHENTICATION_BROKEN; 912 status.security_style = web::SECURITY_STYLE_AUTHENTICATION_BROKEN;
872 sslStatus.cert_status = sslInfo.cert_status; 913 status.cert_status = info.cert_status;
873 sslStatus.cert_id = web::CertStore::GetInstance()->StoreCert( 914 status.cert_id = web::CertStore::GetInstance()->StoreCert(
874 sslInfo.cert.get(), self.certGroupID); 915 info.cert.get(), self.certGroupID);
875 916
876 [self.delegate presentSSLError:sslInfo 917 // Retrieve verification results from _certVerificationErrors cache to avoid
877 forSSLStatus:sslStatus 918 // unnecessary recalculations. Verification results are cached for the leaf
878 recoverable:NO 919 // cert, because the cert chain in |didReceiveAuthenticationChallenge:| is
879 callback:nullptr]; 920 // the OS constructed chain, while |chain| is the chain from the server.
921 NSArray* chain = error.userInfo[web::kNSErrorPeerCertificateChainKey];
922 NSString* host = [error.userInfo[web::kNSErrorFailingURLKey] host];
923 scoped_refptr<net::X509Certificate> leafCert;
924 BOOL recoverable = NO;
925 if (chain.count && host.length) {
926 // The complete cert chain may not be available, so the leaf cert is used
927 // as a key to retrieve _certVerificationErrors, as well as for storing the
928 // cert decision.
929 leafCert = web::CreateCertFromChain(@[ chain.firstObject ]);
930 if (leafCert) {
931 auto error = _certVerificationErrors->Get(
932 {leafCert, base::SysNSStringToUTF8(host)});
933 if (error != _certVerificationErrors->end()) {
934 status.cert_status = error->second.status;
935 recoverable = error->second.is_recoverable;
936 } else {
937 // TODO(eugenebut): Report UMA with cache size (crbug.com/541736).
938 }
939 }
940 }
941
942 // Present SSL interstitial.
943 [self.delegate presentSSLError:info
944 forSSLStatus:status
945 recoverable:recoverable
946 callback:^(BOOL proceed) {
947 if (proceed) {
948 // The interstitial will be removed during reload.
949 [_certVerificationController
950 allowCert:leafCert
951 forHost:host
952 status:status.cert_status];
953 [self loadCurrentURL];
954 }
955 }];
880 } 956 }
881 #endif // #if !defined(ENABLE_CHROME_NET_STACK_FOR_WKWEBVIEW) 957 #endif // #if !defined(ENABLE_CHROME_NET_STACK_FOR_WKWEBVIEW)
882 958
883 - (void)addActivityIndicatorTask { 959 - (void)addActivityIndicatorTask {
884 [[CRWNetworkActivityIndicatorManager sharedInstance] 960 [[CRWNetworkActivityIndicatorManager sharedInstance]
885 startNetworkTaskForGroup:[self activityIndicatorGroupID]]; 961 startNetworkTaskForGroup:[self activityIndicatorGroupID]];
886 } 962 }
887 963
888 - (void)clearActivityIndicatorTasks { 964 - (void)clearActivityIndicatorTasks {
889 [[CRWNetworkActivityIndicatorManager sharedInstance] 965 [[CRWNetworkActivityIndicatorManager sharedInstance]
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
1012 } 1088 }
1013 } 1089 }
1014 1090
1015 if (!previousSSLStatus.Equals(item->GetSSL())) { 1091 if (!previousSSLStatus.Equals(item->GetSSL())) {
1016 [self didUpdateSSLStatusForCurrentNavigationItem]; 1092 [self didUpdateSSLStatusForCurrentNavigationItem];
1017 } 1093 }
1018 } 1094 }
1019 1095
1020 #endif // !defined(ENABLE_CHROME_NET_STACK_FOR_WKWEBVIEW) 1096 #endif // !defined(ENABLE_CHROME_NET_STACK_FOR_WKWEBVIEW)
1021 1097
1098 - (void)processAuthChallenge:(NSURLAuthenticationChallenge*)challenge
1099 forCertAcceptPolicy:(web::CertAcceptPolicy)policy
1100 certStatus:(net::CertStatus)certStatus
1101 completionHandler:(void (^)(NSURLSessionAuthChallengeDisposition,
1102 NSURLCredential*))completionHandler {
1103 SecTrustRef trust = challenge.protectionSpace.serverTrust;
1104 if (policy == web::CERT_ACCEPT_POLICY_RECOVERABLE_ERROR_ACCEPTED_BY_USER) {
1105 // Cert is invalid, but user agreed to proceed, override default behavior.
1106 completionHandler(NSURLSessionAuthChallengeUseCredential,
1107 [NSURLCredential credentialForTrust:trust]);
1108 return;
1109 }
1110
1111 if (policy != web::CERT_ACCEPT_POLICY_ALLOW &&
1112 SecTrustGetCertificateCount(trust)) {
1113 // The cert is invalid and the user has not agreed to proceed. Cache the
1114 // cert verification result in |_certVerificationErrors|, so that it can
1115 // later be reused inside |didFailProvisionalNavigation:|.
1116 // The leaf cert is used as the key, because the chain provided by
1117 // |didFailProvisionalNavigation:| will differ (it is the server-supplied
1118 // chain), thus if intermediates were considered, the keys would mismatch.
1119 scoped_refptr<net::X509Certificate> leafCert =
1120 net::X509Certificate::CreateFromHandle(
1121 SecTrustGetCertificateAtIndex(trust, 0),
1122 net::X509Certificate::OSCertHandles());
1123 if (leafCert) {
1124 BOOL is_recoverable =
1125 policy == web::CERT_ACCEPT_POLICY_RECOVERABLE_ERROR_UNDECIDED_BY_USER;
1126 std::string host =
1127 base::SysNSStringToUTF8(challenge.protectionSpace.host);
1128 _certVerificationErrors->Put(
1129 web::CertHostPair(leafCert, host),
1130 CertVerificationError(is_recoverable, certStatus));
1131 }
1132 }
1133 completionHandler(NSURLSessionAuthChallengeRejectProtectionSpace, nil);
1134 }
1135
1022 - (void)registerLoadRequest:(const GURL&)url { 1136 - (void)registerLoadRequest:(const GURL&)url {
1023 // If load request is registered via WKWebViewWebController, assume transition 1137 // If load request is registered via WKWebViewWebController, assume transition
1024 // is link or client redirect as other transitions will already be registered 1138 // is link or client redirect as other transitions will already be registered
1025 // by web controller or delegates. 1139 // by web controller or delegates.
1026 // TODO(stuartmorgan): Remove guesswork and replace with information from 1140 // TODO(stuartmorgan): Remove guesswork and replace with information from
1027 // decidePolicyForNavigationAction:. 1141 // decidePolicyForNavigationAction:.
1028 ui::PageTransition transition = self.userInteractionRegistered 1142 ui::PageTransition transition = self.userInteractionRegistered
1029 ? ui::PAGE_TRANSITION_LINK 1143 ? ui::PAGE_TRANSITION_LINK
1030 : ui::PAGE_TRANSITION_CLIENT_REDIRECT; 1144 : ui::PAGE_TRANSITION_CLIENT_REDIRECT;
1031 // The referrer is not known yet, and will be updated later. 1145 // The referrer is not known yet, and will be updated later.
(...skipping 392 matching lines...) Expand 10 before | Expand all | Expand 10 after
1424 #endif // defined(ENABLE_CHROME_NET_STACK_FOR_WKWEBVIEW) 1538 #endif // defined(ENABLE_CHROME_NET_STACK_FOR_WKWEBVIEW)
1425 1539
1426 #if !defined(ENABLE_CHROME_NET_STACK_FOR_WKWEBVIEW) 1540 #if !defined(ENABLE_CHROME_NET_STACK_FOR_WKWEBVIEW)
1427 if (web::IsWKWebViewSSLCertError(error)) 1541 if (web::IsWKWebViewSSLCertError(error))
1428 [self handleSSLCertError:error]; 1542 [self handleSSLCertError:error];
1429 else 1543 else
1430 #endif 1544 #endif
1431 [self handleLoadError:error inMainFrame:YES]; 1545 [self handleLoadError:error inMainFrame:YES];
1432 1546
1433 [self discardPendingNavigationTypeForMainFrame]; 1547 [self discardPendingNavigationTypeForMainFrame];
1548 _certVerificationErrors->Clear();
1434 } 1549 }
1435 1550
1436 - (void)webView:(WKWebView *)webView 1551 - (void)webView:(WKWebView *)webView
1437 didCommitNavigation:(WKNavigation *)navigation { 1552 didCommitNavigation:(WKNavigation *)navigation {
1438 DCHECK_EQ(_wkWebView, webView); 1553 DCHECK_EQ(_wkWebView, webView);
1554 _certVerificationErrors->Clear();
1439 // This point should closely approximate the document object change, so reset 1555 // This point should closely approximate the document object change, so reset
1440 // the list of injected scripts to those that are automatically injected. 1556 // the list of injected scripts to those that are automatically injected.
1441 _injectedScriptManagers.reset([[NSMutableSet alloc] init]); 1557 _injectedScriptManagers.reset([[NSMutableSet alloc] init]);
1442 [self injectWindowID]; 1558 [self injectWindowID];
1443 1559
1444 // The page has changed; commit the pending referrer. 1560 // The page has changed; commit the pending referrer.
1445 [self commitPendingReferrerString]; 1561 [self commitPendingReferrerString];
1446 1562
1447 // This is the point where the document's URL has actually changed. 1563 // This is the point where the document's URL has actually changed.
1448 _documentURL = net::GURLWithNSURL([_wkWebView URL]); 1564 _documentURL = net::GURLWithNSURL([_wkWebView URL]);
(...skipping 25 matching lines...) Expand all
1474 web::EvaluateJavaScript(webView, 1590 web::EvaluateJavaScript(webView,
1475 @"__gCrWeb.didFinishNavigation()", nil); 1591 @"__gCrWeb.didFinishNavigation()", nil);
1476 [self didFinishNavigation]; 1592 [self didFinishNavigation];
1477 } 1593 }
1478 1594
1479 - (void)webView:(WKWebView *)webView 1595 - (void)webView:(WKWebView *)webView
1480 didFailNavigation:(WKNavigation *)navigation 1596 didFailNavigation:(WKNavigation *)navigation
1481 withError:(NSError *)error { 1597 withError:(NSError *)error {
1482 [self handleLoadError:WKWebViewErrorWithSource(error, NAVIGATION) 1598 [self handleLoadError:WKWebViewErrorWithSource(error, NAVIGATION)
1483 inMainFrame:YES]; 1599 inMainFrame:YES];
1600 _certVerificationErrors->Clear();
1484 } 1601 }
1485 1602
1486 - (void)webView:(WKWebView *)webView 1603 - (void)webView:(WKWebView*)webView
1487 didReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge 1604 didReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge*)challenge
1488 completionHandler: 1605 completionHandler:
1489 (void (^)(NSURLSessionAuthChallengeDisposition disposition, 1606 (void (^)(NSURLSessionAuthChallengeDisposition,
1490 NSURLCredential *credential))completionHandler { 1607 NSURLCredential*))completionHandler {
1491 if (![challenge.protectionSpace.authenticationMethod 1608 if (![challenge.protectionSpace.authenticationMethod
1492 isEqual:NSURLAuthenticationMethodServerTrust]) { 1609 isEqual:NSURLAuthenticationMethodServerTrust]) {
1493 completionHandler(NSURLSessionAuthChallengePerformDefaultHandling, nil); 1610 completionHandler(NSURLSessionAuthChallengePerformDefaultHandling, nil);
1494 return; 1611 return;
1495 } 1612 }
1496 1613
1497 SecTrustRef trust = challenge.protectionSpace.serverTrust; 1614 SecTrustRef trust = challenge.protectionSpace.serverTrust;
1498 scoped_refptr<net::X509Certificate> cert = web::CreateCertFromTrust(trust); 1615 base::ScopedCFTypeRef<SecTrustRef> scopedTrust(trust,
1499 // TODO(eugenebut): pass SecTrustRef instead of cert. 1616 base::scoped_policy::RETAIN);
1617 base::WeakNSObject<CRWWKWebViewWebController> weakSelf(self);
1500 [_certVerificationController 1618 [_certVerificationController
1501 decidePolicyForCert:cert 1619 decideLoadPolicyForTrust:scopedTrust
1502 host:challenge.protectionSpace.host 1620 host:challenge.protectionSpace.host
1503 completionHandler:^(web::CertAcceptPolicy policy, 1621 completionHandler:^(web::CertAcceptPolicy policy,
1504 net::CertStatus status) { 1622 net::CertStatus status) {
1505 completionHandler(NSURLSessionAuthChallengeRejectProtectionSpace, 1623 base::scoped_nsobject<CRWWKWebViewWebController> strongSelf(
1506 nil); 1624 [weakSelf retain]);
1507 }]; 1625 [strongSelf processAuthChallenge:challenge
1626 forCertAcceptPolicy:policy
1627 certStatus:status
1628 completionHandler:completionHandler];
1629 }];
1508 } 1630 }
1509 1631
1510 - (void)webViewWebContentProcessDidTerminate:(WKWebView*)webView { 1632 - (void)webViewWebContentProcessDidTerminate:(WKWebView*)webView {
1633 _certVerificationErrors->Clear();
1511 [self webViewWebProcessDidCrash]; 1634 [self webViewWebProcessDidCrash];
1512 } 1635 }
1513 1636
1514 #pragma mark WKUIDelegate Methods 1637 #pragma mark WKUIDelegate Methods
1515 1638
1516 - (WKWebView*)webView:(WKWebView*)webView 1639 - (WKWebView*)webView:(WKWebView*)webView
1517 createWebViewWithConfiguration:(WKWebViewConfiguration*)configuration 1640 createWebViewWithConfiguration:(WKWebViewConfiguration*)configuration
1518 forNavigationAction:(WKNavigationAction*)navigationAction 1641 forNavigationAction:(WKNavigationAction*)navigationAction
1519 windowFeatures:(WKWindowFeatures*)windowFeatures { 1642 windowFeatures:(WKWindowFeatures*)windowFeatures {
1520 GURL requestURL = net::GURLWithNSURL(navigationAction.request.URL); 1643 GURL requestURL = net::GURLWithNSURL(navigationAction.request.URL);
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
1596 placeholderText:defaultText 1719 placeholderText:defaultText
1597 requestURL: 1720 requestURL:
1598 net::GURLWithNSURL(frame.request.URL) 1721 net::GURLWithNSURL(frame.request.URL)
1599 completionHandler:completionHandler]; 1722 completionHandler:completionHandler];
1600 } else if (completionHandler) { 1723 } else if (completionHandler) {
1601 completionHandler(nil); 1724 completionHandler(nil);
1602 } 1725 }
1603 } 1726 }
1604 1727
1605 @end 1728 @end
OLDNEW
« no previous file with comments | « ios/web/web_state/ui/crw_web_controller_unittest.mm ('k') | ios/web/web_state/wk_web_view_security_util.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698