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

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: Self review Created 5 years, 2 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
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/js/page_script_util.h" 38 #import "ios/web/web_state/js/page_script_util.h"
37 #import "ios/web/web_state/ui/crw_web_controller+protected.h" 39 #import "ios/web/web_state/ui/crw_web_controller+protected.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 BOOL is_recoverable;
60 net::CertStatus status;
61 };
62
63 // Type of Cache object for storing cert verification errors.
64 typedef base::MRUCache<web::CertHostPair, CertVerificationError>
65 CertVerificationErrorsCacheType;
66
67 // Maximum number of errors to store in cert verification errors cache.
68 // Cache holds errors only for pending navigation, so the actual number of
69 // stored errors is not expected to be high.
70 const CertVerificationErrorsCacheType::size_type kMaxCertErrorsCount = 100;
71
52 // Extracts Referer value from WKNavigationAction request header. 72 // Extracts Referer value from WKNavigationAction request header.
53 NSString* GetRefererFromNavigationAction(WKNavigationAction* action) { 73 NSString* GetRefererFromNavigationAction(WKNavigationAction* action) {
54 return [action.request valueForHTTPHeaderField:@"Referer"]; 74 return [action.request valueForHTTPHeaderField:@"Referer"];
55 } 75 }
56 76
57 NSString* const kScriptMessageName = @"crwebinvoke"; 77 NSString* const kScriptMessageName = @"crwebinvoke";
58 NSString* const kScriptImmediateName = @"crwebinvokeimmediate"; 78 NSString* const kScriptImmediateName = @"crwebinvokeimmediate";
59 79
60 // Utility functions for storing the source of NSErrors received by WKWebViews: 80 // Utility functions for storing the source of NSErrors received by WKWebViews:
61 // - Errors received by |-webView:didFailProvisionalNavigation:withError:| are 81 // - Errors received by |-webView:didFailProvisionalNavigation:withError:| are
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
147 // bad SSL cert, presenting SSL interstitials and determining SSL status for 167 // bad SSL cert, presenting SSL interstitials and determining SSL status for
148 // Navigation Items. 168 // Navigation Items.
149 base::scoped_nsobject<CRWCertVerificationController> 169 base::scoped_nsobject<CRWCertVerificationController>
150 _certVerificationController; 170 _certVerificationController;
151 171
152 // Whether the pending navigation has been directly cancelled in 172 // Whether the pending navigation has been directly cancelled in
153 // |decidePolicyForNavigationAction| or |decidePolicyForNavigationResponse|. 173 // |decidePolicyForNavigationAction| or |decidePolicyForNavigationResponse|.
154 // Cancelled navigations should be simply discarded without handling any 174 // Cancelled navigations should be simply discarded without handling any
155 // specific error. 175 // specific error.
156 BOOL _pendingNavigationCancelled; 176 BOOL _pendingNavigationCancelled;
177
178 // CertVerification errors which happened inside
179 // |webView:didReceiveAuthenticationChallenge:completionHandler:|.
180 // Key is leaf-cert/host pair. This storage is used to carry calculated
181 // cert status from |didReceiveAuthenticationChallenge:| to
182 // |didFailProvisionalNavigation:| delegate method.
183 scoped_ptr<CertVerificationErrorsCacheType> _certVerificationErrors;
157 } 184 }
158 185
159 // Response's MIME type of the last known navigation. 186 // Response's MIME type of the last known navigation.
160 @property(nonatomic, copy) NSString* documentMIMEType; 187 @property(nonatomic, copy) NSString* documentMIMEType;
161 188
162 // Dictionary where keys are the names of WKWebView properties and values are 189 // Dictionary where keys are the names of WKWebView properties and values are
163 // selector names which should be called when a corresponding property has 190 // selector names which should be called when a corresponding property has
164 // changed. e.g. @{ @"URL" : @"webViewURLDidChange" } means that 191 // changed. e.g. @{ @"URL" : @"webViewURLDidChange" } means that
165 // -[self webViewURLDidChange] must be called every time when WKWebView.URL is 192 // -[self webViewURLDidChange] must be called every time when WKWebView.URL is
166 // changed. 193 // changed.
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
274 301
275 #if !defined(ENABLE_CHROME_NET_STACK_FOR_WKWEBVIEW) 302 #if !defined(ENABLE_CHROME_NET_STACK_FOR_WKWEBVIEW)
276 // Updates SSL status for the current navigation item based on the information 303 // Updates SSL status for the current navigation item based on the information
277 // provided by web view. 304 // provided by web view.
278 - (void)updateSSLStatusForCurrentNavigationItem; 305 - (void)updateSSLStatusForCurrentNavigationItem;
279 #endif 306 #endif
280 307
281 // Reports "WebController.WKWebViewHasCertForSecureConnection" UMA. 308 // Reports "WebController.WKWebViewHasCertForSecureConnection" UMA.
282 - (void)reportHasCertForSecureConnectionUMAWithValue:(bool)value; 309 - (void)reportHasCertForSecureConnectionUMAWithValue:(bool)value;
283 310
311 // Used in webView:didReceiveAuthenticationChallenge:completionHandler: to reply
312 // with NSURLSessionAuthChallengeDisposition and credentials.
313 - (void)processAuthChallenge:(NSURLAuthenticationChallenge*)challenge
314 forCertAcceptPolicy:(web::CertAcceptPolicy)policy
315 certStatus:(net::CertStatus)certStatus
316 completionHandler:(void (^)(NSURLSessionAuthChallengeDisposition,
317 NSURLCredential*))completionHandler;
318
284 // Registers load request with empty referrer and link or client redirect 319 // Registers load request with empty referrer and link or client redirect
285 // transition based on user interaction state. 320 // transition based on user interaction state.
286 - (void)registerLoadRequest:(const GURL&)url; 321 - (void)registerLoadRequest:(const GURL&)url;
287 322
288 // Called when a non-document-changing URL change occurs. Updates the 323 // Called when a non-document-changing URL change occurs. Updates the
289 // _documentURL, and informs the superclass of the change. 324 // _documentURL, and informs the superclass of the change.
290 - (void)URLDidChangeWithoutDocumentChange:(const GURL&)URL; 325 - (void)URLDidChangeWithoutDocumentChange:(const GURL&)URL;
291 326
292 // Returns new autoreleased instance of WKUserContentController which has 327 // Returns new autoreleased instance of WKUserContentController which has
293 // early page script. 328 // early page script.
(...skipping 30 matching lines...) Expand all
324 359
325 #pragma mark CRWWebController public methods 360 #pragma mark CRWWebController public methods
326 361
327 - (instancetype)initWithWebState:(scoped_ptr<web::WebStateImpl>)webState { 362 - (instancetype)initWithWebState:(scoped_ptr<web::WebStateImpl>)webState {
328 DCHECK(webState); 363 DCHECK(webState);
329 web::BrowserState* browserState = webState->GetBrowserState(); 364 web::BrowserState* browserState = webState->GetBrowserState();
330 self = [super initWithWebState:webState.Pass()]; 365 self = [super initWithWebState:webState.Pass()];
331 if (self) { 366 if (self) {
332 _certVerificationController.reset([[CRWCertVerificationController alloc] 367 _certVerificationController.reset([[CRWCertVerificationController alloc]
333 initWithBrowserState:browserState]); 368 initWithBrowserState:browserState]);
369 _certVerificationErrors.reset(
370 new CertVerificationErrorsCacheType(kMaxCertErrorsCount));
334 } 371 }
335 return self; 372 return self;
336 } 373 }
337 374
338 - (BOOL)keyboardDisplayRequiresUserAction { 375 - (BOOL)keyboardDisplayRequiresUserAction {
339 // TODO(stuartmorgan): Find out whether YES or NO is correct; see comment 376 // TODO(stuartmorgan): Find out whether YES or NO is correct; see comment
340 // in protected header. 377 // in protected header.
341 NOTIMPLEMENTED(); 378 NOTIMPLEMENTED();
342 return NO; 379 return NO;
343 } 380 }
(...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after
570 } 607 }
571 return [super URLForHistoryNavigationFromItem:fromItem toItem:toItem]; 608 return [super URLForHistoryNavigationFromItem:fromItem toItem:toItem];
572 } 609 }
573 610
574 - (void)setPageChangeProbability:(web::PageChangeProbability)probability { 611 - (void)setPageChangeProbability:(web::PageChangeProbability)probability {
575 // Nothing to do; no polling timer. 612 // Nothing to do; no polling timer.
576 } 613 }
577 614
578 - (void)abortWebLoad { 615 - (void)abortWebLoad {
579 [_wkWebView stopLoading]; 616 [_wkWebView stopLoading];
617 _certVerificationErrors->Clear();
580 } 618 }
581 619
582 - (void)resetLoadState { 620 - (void)resetLoadState {
583 // Nothing to do. 621 // Nothing to do.
584 } 622 }
585 623
586 - (void)setSuppressDialogsWithHelperScript:(NSString*)script { 624 - (void)setSuppressDialogsWithHelperScript:(NSString*)script {
587 [self evaluateJavaScript:script stringResultHandler:nil]; 625 [self evaluateJavaScript:script stringResultHandler:nil];
588 } 626 }
589 627
(...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after
856 sourceURL:sourceURL 894 sourceURL:sourceURL
857 referrerPolicy:base::SysNSStringToUTF8(policy)]; 895 referrerPolicy:base::SysNSStringToUTF8(policy)];
858 }]; 896 }];
859 }); 897 });
860 } 898 }
861 899
862 #if !defined(ENABLE_CHROME_NET_STACK_FOR_WKWEBVIEW) 900 #if !defined(ENABLE_CHROME_NET_STACK_FOR_WKWEBVIEW)
863 - (void)handleSSLCertError:(NSError*)error { 901 - (void)handleSSLCertError:(NSError*)error {
864 DCHECK(web::IsWKWebViewSSLCertError(error)); 902 DCHECK(web::IsWKWebViewSSLCertError(error));
865 903
866 net::SSLInfo sslInfo; 904 net::SSLInfo SSLInfo;
867 web::GetSSLInfoFromWKWebViewSSLCertError(error, &sslInfo); 905 web::GetSSLInfoFromWKWebViewSSLCertError(error, &SSLInfo);
868 906
869 web::SSLStatus sslStatus; 907 web::SSLStatus SSLStatus;
870 sslStatus.security_style = web::SECURITY_STYLE_AUTHENTICATION_BROKEN; 908 SSLStatus.security_style = web::SECURITY_STYLE_AUTHENTICATION_BROKEN;
871 sslStatus.cert_status = sslInfo.cert_status; 909 SSLStatus.cert_status = SSLInfo.cert_status;
872 sslStatus.cert_id = web::CertStore::GetInstance()->StoreCert( 910 SSLStatus.cert_id = web::CertStore::GetInstance()->StoreCert(
873 sslInfo.cert.get(), self.certGroupID); 911 SSLInfo.cert.get(), self.certGroupID);
874 912
875 [self.delegate presentSSLError:sslInfo 913 NSArray* chain = error.userInfo[web::kNSErrorPeerCertificateChainKey];
876 forSSLStatus:sslStatus 914 NSString* host = [error.userInfo[web::kNSErrorFailingURLKey] host];
877 recoverable:NO 915 // Verification results are cached for leaf cert, because cert chain in
878 callback:nullptr]; 916 // |didReceiveAuthenticationChallenge:| maybe different from |chain|.
917 scoped_refptr<net::X509Certificate> leafCert;
918 BOOL recoverable = NO;
919 if (chain.count && host.length) {
920 // Complete cert chain may not be available inside this method, so leaf
921 // cert is used as a key to retrieve _certVerificationErrors as well as for
922 // storing cert decision.
923 leafCert = web::CreateCertFromChain(@[ chain.firstObject ]);
924 if (leafCert) {
925 // This cache will be purged anyway so there is no need to use |Get|.
926 auto error = _certVerificationErrors->Peek(
927 {leafCert, base::SysNSStringToUTF8(host)});
928 if (error != _certVerificationErrors->end()) {
929 SSLStatus.cert_status = error->second.status;
930 recoverable = error->second.is_recoverable;
931 }
932 }
933 }
934 [self.delegate presentSSLError:SSLInfo
935 forSSLStatus:SSLStatus
936 recoverable:recoverable
937 callback:^(BOOL proceed) {
938 if (proceed) {
939 // The interstitial will be removed during reload.
940 [_certVerificationController
941 allowCert:leafCert
942 forHost:host
943 status:SSLStatus.cert_status];
944 [self loadCurrentURL];
945 }
946 }];
879 } 947 }
880 #endif // #if !defined(ENABLE_CHROME_NET_STACK_FOR_WKWEBVIEW) 948 #endif // #if !defined(ENABLE_CHROME_NET_STACK_FOR_WKWEBVIEW)
881 949
882 - (void)addActivityIndicatorTask { 950 - (void)addActivityIndicatorTask {
883 [[CRWNetworkActivityIndicatorManager sharedInstance] 951 [[CRWNetworkActivityIndicatorManager sharedInstance]
884 startNetworkTaskForGroup:[self activityIndicatorGroupID]]; 952 startNetworkTaskForGroup:[self activityIndicatorGroupID]];
885 } 953 }
886 954
887 - (void)clearActivityIndicatorTasks { 955 - (void)clearActivityIndicatorTasks {
888 [[CRWNetworkActivityIndicatorManager sharedInstance] 956 [[CRWNetworkActivityIndicatorManager sharedInstance]
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
1016 } 1084 }
1017 } 1085 }
1018 1086
1019 #endif // !defined(ENABLE_CHROME_NET_STACK_FOR_WKWEBVIEW) 1087 #endif // !defined(ENABLE_CHROME_NET_STACK_FOR_WKWEBVIEW)
1020 1088
1021 - (void)reportHasCertForSecureConnectionUMAWithValue:(bool)value { 1089 - (void)reportHasCertForSecureConnectionUMAWithValue:(bool)value {
1022 UMA_HISTOGRAM_BOOLEAN("WebController.WKWebViewHasCertForSecureConnection", 1090 UMA_HISTOGRAM_BOOLEAN("WebController.WKWebViewHasCertForSecureConnection",
1023 value); 1091 value);
1024 } 1092 }
1025 1093
1094 - (void)processAuthChallenge:(NSURLAuthenticationChallenge*)challenge
1095 forCertAcceptPolicy:(web::CertAcceptPolicy)policy
1096 certStatus:(net::CertStatus)certStatus
1097 completionHandler:(void (^)(NSURLSessionAuthChallengeDisposition,
1098 NSURLCredential*))completionHandler {
1099 SecTrustRef trust = challenge.protectionSpace.serverTrust;
1100 if (policy == web::CERT_ACCEPT_POLICY_RECOVERABLE_ERROR_ACCEPTED_BY_USER) {
1101 // Cert is invalid, but user agreed to proceed.
1102 completionHandler(NSURLSessionAuthChallengeUseCredential,
1103 [NSURLCredential credentialForTrust:trust]);
1104 return;
1105 }
1106
1107 if (policy != web::CERT_ACCEPT_POLICY_ALLOW &&
1108 SecTrustGetCertificateCount(trust)) {
1109 // Cert is invalid and user has not agreed to proceed. Cache cert
1110 // verification result with _certVerificationErrors storage, so it can be
1111 // later reused inside |didFailProvisionalNavigation:|.
1112 // Leaf cert (w/o any intermidiates) is used as a key, because chain inside
1113 // |didFailProvisionalNavigation:| differs (it will be server chain) and
1114 // using intermidiates may result in keys mismatch.
1115 scoped_refptr<net::X509Certificate> leafCert =
1116 net::X509Certificate::CreateFromHandle(
1117 SecTrustGetCertificateAtIndex(trust, 0),
1118 net::X509Certificate::OSCertHandles());
1119 if (leafCert) {
1120 BOOL is_recoverable =
1121 policy ==
1122 web::CERT_ACCEPT_POLICY_RECOVERABLE_ERROR_NOT_ACCEPTED_BY_USER;
1123 std::string host =
1124 base::SysNSStringToUTF8(challenge.protectionSpace.host);
1125 _certVerificationErrors->Put({leafCert, host},
1126 {is_recoverable, certStatus});
1127 }
1128 }
1129 completionHandler(NSURLSessionAuthChallengeRejectProtectionSpace, nil);
1130 }
1131
1026 - (void)registerLoadRequest:(const GURL&)url { 1132 - (void)registerLoadRequest:(const GURL&)url {
1027 // If load request is registered via WKWebViewWebController, assume transition 1133 // If load request is registered via WKWebViewWebController, assume transition
1028 // is link or client redirect as other transitions will already be registered 1134 // is link or client redirect as other transitions will already be registered
1029 // by web controller or delegates. 1135 // by web controller or delegates.
1030 // TODO(stuartmorgan): Remove guesswork and replace with information from 1136 // TODO(stuartmorgan): Remove guesswork and replace with information from
1031 // decidePolicyForNavigationAction:. 1137 // decidePolicyForNavigationAction:.
1032 ui::PageTransition transition = self.userInteractionRegistered 1138 ui::PageTransition transition = self.userInteractionRegistered
1033 ? ui::PAGE_TRANSITION_LINK 1139 ? ui::PAGE_TRANSITION_LINK
1034 : ui::PAGE_TRANSITION_CLIENT_REDIRECT; 1140 : ui::PAGE_TRANSITION_CLIENT_REDIRECT;
1035 // The referrer is not known yet, and will be updated later. 1141 // The referrer is not known yet, and will be updated later.
(...skipping 406 matching lines...) Expand 10 before | Expand all | Expand 10 after
1442 #endif // defined(ENABLE_CHROME_NET_STACK_FOR_WKWEBVIEW) 1548 #endif // defined(ENABLE_CHROME_NET_STACK_FOR_WKWEBVIEW)
1443 1549
1444 #if !defined(ENABLE_CHROME_NET_STACK_FOR_WKWEBVIEW) 1550 #if !defined(ENABLE_CHROME_NET_STACK_FOR_WKWEBVIEW)
1445 if (web::IsWKWebViewSSLCertError(error)) 1551 if (web::IsWKWebViewSSLCertError(error))
1446 [self handleSSLCertError:error]; 1552 [self handleSSLCertError:error];
1447 else 1553 else
1448 #endif 1554 #endif
1449 [self handleLoadError:error inMainFrame:YES]; 1555 [self handleLoadError:error inMainFrame:YES];
1450 1556
1451 [self discardPendingNavigationTypeForMainFrame]; 1557 [self discardPendingNavigationTypeForMainFrame];
1558 _certVerificationErrors->Clear();
1452 } 1559 }
1453 1560
1454 - (void)webView:(WKWebView *)webView 1561 - (void)webView:(WKWebView *)webView
1455 didCommitNavigation:(WKNavigation *)navigation { 1562 didCommitNavigation:(WKNavigation *)navigation {
1456 DCHECK_EQ(_wkWebView, webView); 1563 DCHECK_EQ(_wkWebView, webView);
1564 _certVerificationErrors->Clear();
1457 // This point should closely approximate the document object change, so reset 1565 // This point should closely approximate the document object change, so reset
1458 // the list of injected scripts to those that are automatically injected. 1566 // the list of injected scripts to those that are automatically injected.
1459 _injectedScriptManagers.reset([[NSMutableSet alloc] init]); 1567 _injectedScriptManagers.reset([[NSMutableSet alloc] init]);
1460 [self injectWindowID]; 1568 [self injectWindowID];
1461 1569
1462 // The page has changed; commit the pending referrer. 1570 // The page has changed; commit the pending referrer.
1463 [self commitPendingReferrerString]; 1571 [self commitPendingReferrerString];
1464 1572
1465 // This is the point where the document's URL has actually changed. 1573 // This is the point where the document's URL has actually changed.
1466 _documentURL = net::GURLWithNSURL([_wkWebView URL]); 1574 _documentURL = net::GURLWithNSURL([_wkWebView URL]);
(...skipping 16 matching lines...) Expand all
1483 web::EvaluateJavaScript(webView, 1591 web::EvaluateJavaScript(webView,
1484 @"__gCrWeb.didFinishNavigation()", nil); 1592 @"__gCrWeb.didFinishNavigation()", nil);
1485 [self didFinishNavigation]; 1593 [self didFinishNavigation];
1486 } 1594 }
1487 1595
1488 - (void)webView:(WKWebView *)webView 1596 - (void)webView:(WKWebView *)webView
1489 didFailNavigation:(WKNavigation *)navigation 1597 didFailNavigation:(WKNavigation *)navigation
1490 withError:(NSError *)error { 1598 withError:(NSError *)error {
1491 [self handleLoadError:WKWebViewErrorWithSource(error, NAVIGATION) 1599 [self handleLoadError:WKWebViewErrorWithSource(error, NAVIGATION)
1492 inMainFrame:YES]; 1600 inMainFrame:YES];
1601 _certVerificationErrors->Clear();
1493 } 1602 }
1494 1603
1495 - (void)webView:(WKWebView *)webView 1604 - (void)webView:(WKWebView*)webView
1496 didReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge 1605 didReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge*)challenge
1497 completionHandler: 1606 completionHandler:
1498 (void (^)(NSURLSessionAuthChallengeDisposition disposition, 1607 (void (^)(NSURLSessionAuthChallengeDisposition,
1499 NSURLCredential *credential))completionHandler { 1608 NSURLCredential*))completionHandler {
1500 if (![challenge.protectionSpace.authenticationMethod 1609 if (![challenge.protectionSpace.authenticationMethod
1501 isEqual:NSURLAuthenticationMethodServerTrust]) { 1610 isEqual:NSURLAuthenticationMethodServerTrust]) {
1502 completionHandler(NSURLSessionAuthChallengePerformDefaultHandling, nil); 1611 completionHandler(NSURLSessionAuthChallengePerformDefaultHandling, nil);
1503 return; 1612 return;
1504 } 1613 }
1505 1614
1506 SecTrustRef trust = challenge.protectionSpace.serverTrust; 1615 SecTrustRef trust = challenge.protectionSpace.serverTrust;
1507 scoped_refptr<net::X509Certificate> cert = web::CreateCertFromTrust(trust); 1616 base::ScopedCFTypeRef<SecTrustRef> scopedTrust(trust,
1508 // TODO(eugenebut): pass SecTrustRef instead of cert. 1617 base::scoped_policy::RETAIN);
1618 base::WeakNSObject<CRWWKWebViewWebController> weakSelf(self);
1509 [_certVerificationController 1619 [_certVerificationController
1510 decidePolicyForCert:cert 1620 decideLoadPolicyForTrust:scopedTrust
1511 host:challenge.protectionSpace.host 1621 host:challenge.protectionSpace.host
1512 completionHandler:^(web::CertAcceptPolicy policy, 1622 completionHandler:^(web::CertAcceptPolicy policy,
1513 net::CertStatus status) { 1623 net::CertStatus status) {
1514 completionHandler(NSURLSessionAuthChallengeRejectProtectionSpace, 1624 base::scoped_nsobject<CRWWKWebViewWebController> strongSelf(
1515 nil); 1625 [weakSelf retain]);
1516 }]; 1626 [strongSelf processAuthChallenge:challenge
1627 forCertAcceptPolicy:policy
1628 certStatus:status
1629 completionHandler:completionHandler];
1630 }];
1517 } 1631 }
1518 1632
1519 - (void)webViewWebContentProcessDidTerminate:(WKWebView*)webView { 1633 - (void)webViewWebContentProcessDidTerminate:(WKWebView*)webView {
1634 _certVerificationErrors->Clear();
1520 [self webViewWebProcessDidCrash]; 1635 [self webViewWebProcessDidCrash];
1521 } 1636 }
1522 1637
1523 #pragma mark WKUIDelegate Methods 1638 #pragma mark WKUIDelegate Methods
1524 1639
1525 - (WKWebView*)webView:(WKWebView*)webView 1640 - (WKWebView*)webView:(WKWebView*)webView
1526 createWebViewWithConfiguration:(WKWebViewConfiguration*)configuration 1641 createWebViewWithConfiguration:(WKWebViewConfiguration*)configuration
1527 forNavigationAction:(WKNavigationAction*)navigationAction 1642 forNavigationAction:(WKNavigationAction*)navigationAction
1528 windowFeatures:(WKWindowFeatures*)windowFeatures { 1643 windowFeatures:(WKWindowFeatures*)windowFeatures {
1529 GURL requestURL = net::GURLWithNSURL(navigationAction.request.URL); 1644 GURL requestURL = net::GURLWithNSURL(navigationAction.request.URL);
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
1605 placeholderText:defaultText 1720 placeholderText:defaultText
1606 requestURL: 1721 requestURL:
1607 net::GURLWithNSURL(frame.request.URL) 1722 net::GURLWithNSURL(frame.request.URL)
1608 completionHandler:completionHandler]; 1723 completionHandler:completionHandler];
1609 } else if (completionHandler) { 1724 } else if (completionHandler) {
1610 completionHandler(nil); 1725 completionHandler(nil);
1611 } 1726 }
1612 } 1727 }
1613 1728
1614 @end 1729 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698