OLD | NEW |
---|---|
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 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 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
137 // bad SSL cert, presenting SSL interstitials and determining SSL status for | 157 // bad SSL cert, presenting SSL interstitials and determining SSL status for |
138 // Navigation Items. | 158 // Navigation Items. |
139 base::scoped_nsobject<CRWCertVerificationController> | 159 base::scoped_nsobject<CRWCertVerificationController> |
140 _certVerificationController; | 160 _certVerificationController; |
141 | 161 |
142 // Whether the pending navigation has been directly cancelled in | 162 // Whether the pending navigation has been directly cancelled in |
143 // |decidePolicyForNavigationAction| or |decidePolicyForNavigationResponse|. | 163 // |decidePolicyForNavigationAction| or |decidePolicyForNavigationResponse|. |
144 // Cancelled navigations should be simply discarded without handling any | 164 // Cancelled navigations should be simply discarded without handling any |
145 // specific error. | 165 // specific error. |
146 BOOL _pendingNavigationCancelled; | 166 BOOL _pendingNavigationCancelled; |
167 | |
168 // CertVerification errors which happened inside | |
169 // |webView:didReceiveAuthenticationChallenge:completionHandler:|. | |
170 // Key is leaf-cert/host pair. This storage is used to carry calculated | |
171 // cert status from |didReceiveAuthenticationChallenge:| to | |
172 // |didFailProvisionalNavigation:| delegate method. | |
173 scoped_ptr<CertVerificationErrorsCacheType> _certVerificationErrors; | |
147 } | 174 } |
148 | 175 |
149 // Response's MIME type of the last known navigation. | 176 // Response's MIME type of the last known navigation. |
150 @property(nonatomic, copy) NSString* documentMIMEType; | 177 @property(nonatomic, copy) NSString* documentMIMEType; |
151 | 178 |
152 // Dictionary where keys are the names of WKWebView properties and values are | 179 // Dictionary where keys are the names of WKWebView properties and values are |
153 // selector names which should be called when a corresponding property has | 180 // selector names which should be called when a corresponding property has |
154 // changed. e.g. @{ @"URL" : @"webViewURLDidChange" } means that | 181 // changed. e.g. @{ @"URL" : @"webViewURLDidChange" } means that |
155 // -[self webViewURLDidChange] must be called every time when WKWebView.URL is | 182 // -[self webViewURLDidChange] must be called every time when WKWebView.URL is |
156 // changed. | 183 // changed. |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
263 // cert_status and security_style to default. | 290 // cert_status and security_style to default. |
264 - (void)scheduleSSLStatusUpdateUsingCertChain:(NSArray*)chain | 291 - (void)scheduleSSLStatusUpdateUsingCertChain:(NSArray*)chain |
265 host:(NSString*)host; | 292 host:(NSString*)host; |
266 | 293 |
267 #if !defined(ENABLE_CHROME_NET_STACK_FOR_WKWEBVIEW) | 294 #if !defined(ENABLE_CHROME_NET_STACK_FOR_WKWEBVIEW) |
268 // Updates SSL status for the current navigation item based on the information | 295 // Updates SSL status for the current navigation item based on the information |
269 // provided by web view. | 296 // provided by web view. |
270 - (void)updateSSLStatusForCurrentNavigationItem; | 297 - (void)updateSSLStatusForCurrentNavigationItem; |
271 #endif | 298 #endif |
272 | 299 |
300 // Used in webView:didReceiveAuthenticationChallenge:completionHandler: to reply | |
301 // with NSURLSessionAuthChallengeDisposition and credentials. | |
302 - (void)processAuthChallenge:(NSURLAuthenticationChallenge*)challenge | |
303 forCertAcceptPolicy:(web::CertAcceptPolicy)policy | |
304 certStatus:(net::CertStatus)certStatus | |
305 completionHandler:(void (^)(NSURLSessionAuthChallengeDisposition, | |
306 NSURLCredential*))completionHandler; | |
307 | |
273 // Registers load request with empty referrer and link or client redirect | 308 // Registers load request with empty referrer and link or client redirect |
274 // transition based on user interaction state. | 309 // transition based on user interaction state. |
275 - (void)registerLoadRequest:(const GURL&)url; | 310 - (void)registerLoadRequest:(const GURL&)url; |
276 | 311 |
277 // Called when a non-document-changing URL change occurs. Updates the | 312 // Called when a non-document-changing URL change occurs. Updates the |
278 // _documentURL, and informs the superclass of the change. | 313 // _documentURL, and informs the superclass of the change. |
279 - (void)URLDidChangeWithoutDocumentChange:(const GURL&)URL; | 314 - (void)URLDidChangeWithoutDocumentChange:(const GURL&)URL; |
280 | 315 |
281 // Called when web controller receives a new message from the web page. | 316 // Called when web controller receives a new message from the web page. |
282 - (void)didReceiveScriptMessage:(WKScriptMessage*)message; | 317 - (void)didReceiveScriptMessage:(WKScriptMessage*)message; |
(...skipping 29 matching lines...) Expand all Loading... | |
312 | 347 |
313 #pragma mark CRWWebController public methods | 348 #pragma mark CRWWebController public methods |
314 | 349 |
315 - (instancetype)initWithWebState:(scoped_ptr<web::WebStateImpl>)webState { | 350 - (instancetype)initWithWebState:(scoped_ptr<web::WebStateImpl>)webState { |
316 DCHECK(webState); | 351 DCHECK(webState); |
317 web::BrowserState* browserState = webState->GetBrowserState(); | 352 web::BrowserState* browserState = webState->GetBrowserState(); |
318 self = [super initWithWebState:webState.Pass()]; | 353 self = [super initWithWebState:webState.Pass()]; |
319 if (self) { | 354 if (self) { |
320 _certVerificationController.reset([[CRWCertVerificationController alloc] | 355 _certVerificationController.reset([[CRWCertVerificationController alloc] |
321 initWithBrowserState:browserState]); | 356 initWithBrowserState:browserState]); |
357 _certVerificationErrors.reset( | |
358 new CertVerificationErrorsCacheType(kMaxCertErrorsCount)); | |
322 } | 359 } |
323 return self; | 360 return self; |
324 } | 361 } |
325 | 362 |
326 - (BOOL)keyboardDisplayRequiresUserAction { | 363 - (BOOL)keyboardDisplayRequiresUserAction { |
327 // TODO(stuartmorgan): Find out whether YES or NO is correct; see comment | 364 // TODO(stuartmorgan): Find out whether YES or NO is correct; see comment |
328 // in protected header. | 365 // in protected header. |
329 NOTIMPLEMENTED(); | 366 NOTIMPLEMENTED(); |
330 return NO; | 367 return NO; |
331 } | 368 } |
(...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
558 } | 595 } |
559 return [super URLForHistoryNavigationFromItem:fromItem toItem:toItem]; | 596 return [super URLForHistoryNavigationFromItem:fromItem toItem:toItem]; |
560 } | 597 } |
561 | 598 |
562 - (void)setPageChangeProbability:(web::PageChangeProbability)probability { | 599 - (void)setPageChangeProbability:(web::PageChangeProbability)probability { |
563 // Nothing to do; no polling timer. | 600 // Nothing to do; no polling timer. |
564 } | 601 } |
565 | 602 |
566 - (void)abortWebLoad { | 603 - (void)abortWebLoad { |
567 [_wkWebView stopLoading]; | 604 [_wkWebView stopLoading]; |
605 _certVerificationErrors->Clear(); | |
568 } | 606 } |
569 | 607 |
570 - (void)resetLoadState { | 608 - (void)resetLoadState { |
571 // Nothing to do. | 609 // Nothing to do. |
572 } | 610 } |
573 | 611 |
574 - (void)setSuppressDialogsWithHelperScript:(NSString*)script { | 612 - (void)setSuppressDialogsWithHelperScript:(NSString*)script { |
575 [self evaluateJavaScript:script stringResultHandler:nil]; | 613 [self evaluateJavaScript:script stringResultHandler:nil]; |
576 } | 614 } |
577 | 615 |
(...skipping 272 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
850 sourceURL:sourceURL | 888 sourceURL:sourceURL |
851 referrerPolicy:base::SysNSStringToUTF8(policy)]; | 889 referrerPolicy:base::SysNSStringToUTF8(policy)]; |
852 }]; | 890 }]; |
853 }); | 891 }); |
854 } | 892 } |
855 | 893 |
856 #if !defined(ENABLE_CHROME_NET_STACK_FOR_WKWEBVIEW) | 894 #if !defined(ENABLE_CHROME_NET_STACK_FOR_WKWEBVIEW) |
857 - (void)handleSSLCertError:(NSError*)error { | 895 - (void)handleSSLCertError:(NSError*)error { |
858 DCHECK(web::IsWKWebViewSSLCertError(error)); | 896 DCHECK(web::IsWKWebViewSSLCertError(error)); |
859 | 897 |
860 net::SSLInfo sslInfo; | 898 net::SSLInfo SSLInfo; |
861 web::GetSSLInfoFromWKWebViewSSLCertError(error, &sslInfo); | 899 web::GetSSLInfoFromWKWebViewSSLCertError(error, &SSLInfo); |
862 | 900 |
863 web::SSLStatus sslStatus; | 901 web::SSLStatus SSLStatus; |
864 sslStatus.security_style = web::SECURITY_STYLE_AUTHENTICATION_BROKEN; | 902 SSLStatus.security_style = web::SECURITY_STYLE_AUTHENTICATION_BROKEN; |
865 sslStatus.cert_status = sslInfo.cert_status; | 903 SSLStatus.cert_status = SSLInfo.cert_status; |
866 sslStatus.cert_id = web::CertStore::GetInstance()->StoreCert( | 904 SSLStatus.cert_id = web::CertStore::GetInstance()->StoreCert( |
867 sslInfo.cert.get(), self.certGroupID); | 905 SSLInfo.cert.get(), self.certGroupID); |
868 | 906 |
869 [self.delegate presentSSLError:sslInfo | 907 // Retrieve verification results from _certVerificationErrors cache to avoid |
870 forSSLStatus:sslStatus | 908 // unnecessary recalculations. Verification results are cached for leaf cert, |
Ryan Sleevi
2015/10/19 23:56:22
s/for leaf cert/for the leaf cert/
Eugene But (OOO till 7-30)
2015/10/21 04:01:02
Done.
| |
871 recoverable:NO | 909 // because cert chain in |didReceiveAuthenticationChallenge:| is OS |
Ryan Sleevi
2015/10/19 23:56:22
s/is OS/is the OS/
Ryan Sleevi
2015/10/19 23:56:22
s/because cert chain/because the cert chain/
Eugene But (OOO till 7-30)
2015/10/21 04:01:02
Done.
Eugene But (OOO till 7-30)
2015/10/21 04:01:03
Done.
| |
872 callback:nullptr]; | 910 // constructed chain, while |chain| is a chain from the server. |
Ryan Sleevi
2015/10/19 23:56:22
s/a chain/the chain/
Eugene But (OOO till 7-30)
2015/10/21 04:01:02
Done.
| |
911 NSArray* chain = error.userInfo[web::kNSErrorPeerCertificateChainKey]; | |
912 NSString* host = [error.userInfo[web::kNSErrorFailingURLKey] host]; | |
913 scoped_refptr<net::X509Certificate> leafCert; | |
914 BOOL recoverable = NO; | |
915 if (chain.count && host.length) { | |
916 // Complete cert chain may not be available inside this method, so leaf | |
917 // cert is used as a key to retrieve _certVerificationErrors as well as for | |
918 // storing cert decision. | |
Ryan Sleevi
2015/10/19 23:56:22
// The complete cert chain may not be available, s
Eugene But (OOO till 7-30)
2015/10/21 04:01:02
Done.
| |
919 leafCert = web::CreateCertFromChain(@[ chain.firstObject ]); | |
920 if (leafCert) { | |
921 // This cache will be purged anyway so there is no need to use |Get|. | |
Ryan Sleevi
2015/10/19 23:56:22
This is surprising/non-obvious, and doesn't seem t
Eugene But (OOO till 7-30)
2015/10/21 04:01:02
MRUCache allows cache to be bounded and evicts lea
Ryan Sleevi
2015/10/28 21:28:50
I suppose this wasn't clear, as I'm still uncertai
Eugene But (OOO till 7-30)
2015/10/29 00:39:14
_certVerificationErrors will be purged right after
| |
922 auto error = _certVerificationErrors->Peek( | |
923 {leafCert, base::SysNSStringToUTF8(host)}); | |
924 if (error != _certVerificationErrors->end()) { | |
925 SSLStatus.cert_status = error->second.status; | |
926 recoverable = error->second.is_recoverable; | |
927 } else { | |
928 // TODO(eugenebut): Report UMA with cache size (crbug.com/541736). | |
929 } | |
930 } | |
931 } | |
932 | |
933 // Present SSL interstitial. | |
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 }]; | |
873 } | 947 } |
874 #endif // #if !defined(ENABLE_CHROME_NET_STACK_FOR_WKWEBVIEW) | 948 #endif // #if !defined(ENABLE_CHROME_NET_STACK_FOR_WKWEBVIEW) |
875 | 949 |
876 - (void)addActivityIndicatorTask { | 950 - (void)addActivityIndicatorTask { |
877 [[CRWNetworkActivityIndicatorManager sharedInstance] | 951 [[CRWNetworkActivityIndicatorManager sharedInstance] |
878 startNetworkTaskForGroup:[self activityIndicatorGroupID]]; | 952 startNetworkTaskForGroup:[self activityIndicatorGroupID]]; |
879 } | 953 } |
880 | 954 |
881 - (void)clearActivityIndicatorTasks { | 955 - (void)clearActivityIndicatorTasks { |
882 [[CRWNetworkActivityIndicatorManager sharedInstance] | 956 [[CRWNetworkActivityIndicatorManager sharedInstance] |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1005 } | 1079 } |
1006 } | 1080 } |
1007 | 1081 |
1008 if (!previousSSLStatus.Equals(item->GetSSL())) { | 1082 if (!previousSSLStatus.Equals(item->GetSSL())) { |
1009 [self didUpdateSSLStatusForCurrentNavigationItem]; | 1083 [self didUpdateSSLStatusForCurrentNavigationItem]; |
1010 } | 1084 } |
1011 } | 1085 } |
1012 | 1086 |
1013 #endif // !defined(ENABLE_CHROME_NET_STACK_FOR_WKWEBVIEW) | 1087 #endif // !defined(ENABLE_CHROME_NET_STACK_FOR_WKWEBVIEW) |
1014 | 1088 |
1089 - (void)processAuthChallenge:(NSURLAuthenticationChallenge*)challenge | |
1090 forCertAcceptPolicy:(web::CertAcceptPolicy)policy | |
1091 certStatus:(net::CertStatus)certStatus | |
1092 completionHandler:(void (^)(NSURLSessionAuthChallengeDisposition, | |
1093 NSURLCredential*))completionHandler { | |
1094 SecTrustRef trust = challenge.protectionSpace.serverTrust; | |
1095 if (policy == web::CERT_ACCEPT_POLICY_RECOVERABLE_ERROR_ACCEPTED_BY_USER) { | |
1096 // Cert is invalid, but user agreed to proceed, override default behavior. | |
1097 completionHandler(NSURLSessionAuthChallengeUseCredential, | |
1098 [NSURLCredential credentialForTrust:trust]); | |
1099 return; | |
1100 } | |
1101 | |
1102 if (policy != web::CERT_ACCEPT_POLICY_ALLOW && | |
1103 SecTrustGetCertificateCount(trust)) { | |
1104 // Cert is invalid and user has not agreed to proceed. Cache cert | |
Ryan Sleevi
2015/10/19 23:56:22
// The cert is invalid and the user has not agreed
Eugene But (OOO till 7-30)
2015/10/21 04:01:03
Done.
| |
1105 // verification result with _certVerificationErrors storage, so it can be | |
1106 // later reused inside |didFailProvisionalNavigation:|. | |
1107 // Leaf cert (w/o any intermidiates) is used as a key, because chain inside | |
1108 // |didFailProvisionalNavigation:| differs (it will be server chain) and | |
1109 // using intermidiates may result in keys mismatch. | |
Ryan Sleevi
2015/10/19 23:56:22
// The leaf cert is used as the key, because the c
Eugene But (OOO till 7-30)
2015/10/21 04:01:02
Done.
| |
1110 scoped_refptr<net::X509Certificate> leafCert = | |
1111 net::X509Certificate::CreateFromHandle( | |
1112 SecTrustGetCertificateAtIndex(trust, 0), | |
1113 net::X509Certificate::OSCertHandles()); | |
1114 if (leafCert) { | |
1115 BOOL is_recoverable = | |
1116 policy == | |
1117 web::CERT_ACCEPT_POLICY_RECOVERABLE_ERROR_UNDECIDED_BY_USER; | |
1118 std::string host = | |
1119 base::SysNSStringToUTF8(challenge.protectionSpace.host); | |
1120 _certVerificationErrors->Put({leafCert, host}, | |
1121 {is_recoverable, certStatus}); | |
1122 } | |
1123 } | |
1124 completionHandler(NSURLSessionAuthChallengeRejectProtectionSpace, nil); | |
1125 } | |
1126 | |
1015 - (void)registerLoadRequest:(const GURL&)url { | 1127 - (void)registerLoadRequest:(const GURL&)url { |
1016 // If load request is registered via WKWebViewWebController, assume transition | 1128 // If load request is registered via WKWebViewWebController, assume transition |
1017 // is link or client redirect as other transitions will already be registered | 1129 // is link or client redirect as other transitions will already be registered |
1018 // by web controller or delegates. | 1130 // by web controller or delegates. |
1019 // TODO(stuartmorgan): Remove guesswork and replace with information from | 1131 // TODO(stuartmorgan): Remove guesswork and replace with information from |
1020 // decidePolicyForNavigationAction:. | 1132 // decidePolicyForNavigationAction:. |
1021 ui::PageTransition transition = self.userInteractionRegistered | 1133 ui::PageTransition transition = self.userInteractionRegistered |
1022 ? ui::PAGE_TRANSITION_LINK | 1134 ? ui::PAGE_TRANSITION_LINK |
1023 : ui::PAGE_TRANSITION_CLIENT_REDIRECT; | 1135 : ui::PAGE_TRANSITION_CLIENT_REDIRECT; |
1024 // The referrer is not known yet, and will be updated later. | 1136 // The referrer is not known yet, and will be updated later. |
(...skipping 395 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1420 #endif // defined(ENABLE_CHROME_NET_STACK_FOR_WKWEBVIEW) | 1532 #endif // defined(ENABLE_CHROME_NET_STACK_FOR_WKWEBVIEW) |
1421 | 1533 |
1422 #if !defined(ENABLE_CHROME_NET_STACK_FOR_WKWEBVIEW) | 1534 #if !defined(ENABLE_CHROME_NET_STACK_FOR_WKWEBVIEW) |
1423 if (web::IsWKWebViewSSLCertError(error)) | 1535 if (web::IsWKWebViewSSLCertError(error)) |
1424 [self handleSSLCertError:error]; | 1536 [self handleSSLCertError:error]; |
1425 else | 1537 else |
1426 #endif | 1538 #endif |
1427 [self handleLoadError:error inMainFrame:YES]; | 1539 [self handleLoadError:error inMainFrame:YES]; |
1428 | 1540 |
1429 [self discardPendingNavigationTypeForMainFrame]; | 1541 [self discardPendingNavigationTypeForMainFrame]; |
1542 _certVerificationErrors->Clear(); | |
1430 } | 1543 } |
1431 | 1544 |
1432 - (void)webView:(WKWebView *)webView | 1545 - (void)webView:(WKWebView *)webView |
1433 didCommitNavigation:(WKNavigation *)navigation { | 1546 didCommitNavigation:(WKNavigation *)navigation { |
1434 DCHECK_EQ(_wkWebView, webView); | 1547 DCHECK_EQ(_wkWebView, webView); |
1548 _certVerificationErrors->Clear(); | |
1435 // This point should closely approximate the document object change, so reset | 1549 // This point should closely approximate the document object change, so reset |
1436 // the list of injected scripts to those that are automatically injected. | 1550 // the list of injected scripts to those that are automatically injected. |
1437 _injectedScriptManagers.reset([[NSMutableSet alloc] init]); | 1551 _injectedScriptManagers.reset([[NSMutableSet alloc] init]); |
1438 [self injectWindowID]; | 1552 [self injectWindowID]; |
1439 | 1553 |
1440 // The page has changed; commit the pending referrer. | 1554 // The page has changed; commit the pending referrer. |
1441 [self commitPendingReferrerString]; | 1555 [self commitPendingReferrerString]; |
1442 | 1556 |
1443 // This is the point where the document's URL has actually changed. | 1557 // This is the point where the document's URL has actually changed. |
1444 _documentURL = net::GURLWithNSURL([_wkWebView URL]); | 1558 _documentURL = net::GURLWithNSURL([_wkWebView URL]); |
(...skipping 24 matching lines...) Expand all Loading... | |
1469 web::EvaluateJavaScript(webView, | 1583 web::EvaluateJavaScript(webView, |
1470 @"__gCrWeb.didFinishNavigation()", nil); | 1584 @"__gCrWeb.didFinishNavigation()", nil); |
1471 [self didFinishNavigation]; | 1585 [self didFinishNavigation]; |
1472 } | 1586 } |
1473 | 1587 |
1474 - (void)webView:(WKWebView *)webView | 1588 - (void)webView:(WKWebView *)webView |
1475 didFailNavigation:(WKNavigation *)navigation | 1589 didFailNavigation:(WKNavigation *)navigation |
1476 withError:(NSError *)error { | 1590 withError:(NSError *)error { |
1477 [self handleLoadError:WKWebViewErrorWithSource(error, NAVIGATION) | 1591 [self handleLoadError:WKWebViewErrorWithSource(error, NAVIGATION) |
1478 inMainFrame:YES]; | 1592 inMainFrame:YES]; |
1593 _certVerificationErrors->Clear(); | |
1479 } | 1594 } |
1480 | 1595 |
1481 - (void)webView:(WKWebView *)webView | 1596 - (void)webView:(WKWebView*)webView |
1482 didReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge | 1597 didReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge*)challenge |
1483 completionHandler: | 1598 completionHandler: |
1484 (void (^)(NSURLSessionAuthChallengeDisposition disposition, | 1599 (void (^)(NSURLSessionAuthChallengeDisposition, |
1485 NSURLCredential *credential))completionHandler { | 1600 NSURLCredential*))completionHandler { |
1486 if (![challenge.protectionSpace.authenticationMethod | 1601 if (![challenge.protectionSpace.authenticationMethod |
1487 isEqual:NSURLAuthenticationMethodServerTrust]) { | 1602 isEqual:NSURLAuthenticationMethodServerTrust]) { |
1488 completionHandler(NSURLSessionAuthChallengePerformDefaultHandling, nil); | 1603 completionHandler(NSURLSessionAuthChallengePerformDefaultHandling, nil); |
1489 return; | 1604 return; |
1490 } | 1605 } |
1491 | 1606 |
1492 SecTrustRef trust = challenge.protectionSpace.serverTrust; | 1607 SecTrustRef trust = challenge.protectionSpace.serverTrust; |
1493 scoped_refptr<net::X509Certificate> cert = web::CreateCertFromTrust(trust); | 1608 base::ScopedCFTypeRef<SecTrustRef> scopedTrust(trust, |
1494 // TODO(eugenebut): pass SecTrustRef instead of cert. | 1609 base::scoped_policy::RETAIN); |
1610 base::WeakNSObject<CRWWKWebViewWebController> weakSelf(self); | |
1495 [_certVerificationController | 1611 [_certVerificationController |
1496 decidePolicyForCert:cert | 1612 decideLoadPolicyForTrust:scopedTrust |
1497 host:challenge.protectionSpace.host | 1613 host:challenge.protectionSpace.host |
1498 completionHandler:^(web::CertAcceptPolicy policy, | 1614 completionHandler:^(web::CertAcceptPolicy policy, |
1499 net::CertStatus status) { | 1615 net::CertStatus status) { |
1500 completionHandler(NSURLSessionAuthChallengeRejectProtectionSpace, | 1616 base::scoped_nsobject<CRWWKWebViewWebController> strongSelf( |
1501 nil); | 1617 [weakSelf retain]); |
1502 }]; | 1618 [strongSelf processAuthChallenge:challenge |
1619 forCertAcceptPolicy:policy | |
1620 certStatus:status | |
1621 completionHandler:completionHandler]; | |
1622 }]; | |
1503 } | 1623 } |
1504 | 1624 |
1505 - (void)webViewWebContentProcessDidTerminate:(WKWebView*)webView { | 1625 - (void)webViewWebContentProcessDidTerminate:(WKWebView*)webView { |
1626 _certVerificationErrors->Clear(); | |
1506 [self webViewWebProcessDidCrash]; | 1627 [self webViewWebProcessDidCrash]; |
1507 } | 1628 } |
1508 | 1629 |
1509 #pragma mark WKUIDelegate Methods | 1630 #pragma mark WKUIDelegate Methods |
1510 | 1631 |
1511 - (WKWebView*)webView:(WKWebView*)webView | 1632 - (WKWebView*)webView:(WKWebView*)webView |
1512 createWebViewWithConfiguration:(WKWebViewConfiguration*)configuration | 1633 createWebViewWithConfiguration:(WKWebViewConfiguration*)configuration |
1513 forNavigationAction:(WKNavigationAction*)navigationAction | 1634 forNavigationAction:(WKNavigationAction*)navigationAction |
1514 windowFeatures:(WKWindowFeatures*)windowFeatures { | 1635 windowFeatures:(WKWindowFeatures*)windowFeatures { |
1515 GURL requestURL = net::GURLWithNSURL(navigationAction.request.URL); | 1636 GURL requestURL = net::GURLWithNSURL(navigationAction.request.URL); |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1591 placeholderText:defaultText | 1712 placeholderText:defaultText |
1592 requestURL: | 1713 requestURL: |
1593 net::GURLWithNSURL(frame.request.URL) | 1714 net::GURLWithNSURL(frame.request.URL) |
1594 completionHandler:completionHandler]; | 1715 completionHandler:completionHandler]; |
1595 } else if (completionHandler) { | 1716 } else if (completionHandler) { |
1596 completionHandler(nil); | 1717 completionHandler(nil); |
1597 } | 1718 } |
1598 } | 1719 } |
1599 | 1720 |
1600 @end | 1721 @end |
OLD | NEW |