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

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

Issue 1230033005: WKWebView: Added cert verification API to web controller. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 5 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/ios/ios_util.h" 9 #include "base/ios/ios_util.h"
10 #include "base/ios/weak_nsobject.h" 10 #include "base/ios/weak_nsobject.h"
11 #include "base/json/json_reader.h" 11 #include "base/json/json_reader.h"
12 #import "base/mac/scoped_nsobject.h" 12 #import "base/mac/scoped_nsobject.h"
13 #include "base/macros.h" 13 #include "base/macros.h"
14 #include "base/strings/sys_string_conversions.h" 14 #include "base/strings/sys_string_conversions.h"
15 #include "base/values.h" 15 #include "base/values.h"
16 #import "ios/net/http_response_headers_util.h" 16 #import "ios/net/http_response_headers_util.h"
17 #import "ios/web/crw_network_activity_indicator_manager.h" 17 #import "ios/web/crw_network_activity_indicator_manager.h"
18 #import "ios/web/navigation/crw_session_controller.h" 18 #import "ios/web/navigation/crw_session_controller.h"
19 #include "ios/web/navigation/web_load_params.h" 19 #include "ios/web/navigation/web_load_params.h"
20 #include "ios/web/net/cert_verifier_block_adapter.h"
20 #include "ios/web/public/web_client.h" 21 #include "ios/web/public/web_client.h"
21 #import "ios/web/public/web_state/js/crw_js_injection_manager.h" 22 #import "ios/web/public/web_state/js/crw_js_injection_manager.h"
22 #import "ios/web/public/web_state/ui/crw_native_content_provider.h" 23 #import "ios/web/public/web_state/ui/crw_native_content_provider.h"
23 #import "ios/web/public/web_state/ui/crw_web_view_content_view.h" 24 #import "ios/web/public/web_state/ui/crw_web_view_content_view.h"
24 #import "ios/web/ui_web_view_util.h" 25 #import "ios/web/ui_web_view_util.h"
25 #include "ios/web/web_state/blocked_popup_info.h" 26 #include "ios/web/web_state/blocked_popup_info.h"
26 #import "ios/web/web_state/error_translation_util.h" 27 #import "ios/web/web_state/error_translation_util.h"
27 #include "ios/web/web_state/frame_info.h" 28 #include "ios/web/web_state/frame_info.h"
28 #import "ios/web/web_state/js/crw_js_window_id_manager.h" 29 #import "ios/web/web_state/js/crw_js_window_id_manager.h"
29 #import "ios/web/web_state/js/page_script_util.h" 30 #import "ios/web/web_state/js/page_script_util.h"
30 #import "ios/web/web_state/ui/crw_web_controller+protected.h" 31 #import "ios/web/web_state/ui/crw_web_controller+protected.h"
31 #import "ios/web/web_state/ui/crw_wk_web_view_crash_detector.h" 32 #import "ios/web/web_state/ui/crw_wk_web_view_crash_detector.h"
32 #import "ios/web/web_state/ui/web_view_js_utils.h" 33 #import "ios/web/web_state/ui/web_view_js_utils.h"
33 #import "ios/web/web_state/ui/wk_web_view_configuration_provider.h" 34 #import "ios/web/web_state/ui/wk_web_view_configuration_provider.h"
34 #import "ios/web/web_state/web_state_impl.h" 35 #import "ios/web/web_state/web_state_impl.h"
35 #import "ios/web/web_state/web_view_internal_creation_util.h" 36 #import "ios/web/web_state/web_view_internal_creation_util.h"
36 #import "ios/web/webui/crw_web_ui_manager.h" 37 #import "ios/web/webui/crw_web_ui_manager.h"
37 #import "net/base/mac/url_conversions.h" 38 #import "net/base/mac/url_conversions.h"
39 #include "net/cert/cert_verify_result.h"
40 #include "net/ssl/ssl_config_service.h"
38 41
39 #if !defined(ENABLE_CHROME_NET_STACK_FOR_WKWEBVIEW) 42 #if !defined(ENABLE_CHROME_NET_STACK_FOR_WKWEBVIEW)
40 #include "ios/web/public/cert_store.h" 43 #include "ios/web/public/cert_store.h"
41 #include "ios/web/public/navigation_item.h" 44 #include "ios/web/public/navigation_item.h"
42 #include "ios/web/public/ssl_status.h" 45 #include "ios/web/public/ssl_status.h"
43 #import "ios/web/web_state/wk_web_view_security_util.h" 46 #import "ios/web/web_state/wk_web_view_security_util.h"
44 #include "net/ssl/ssl_info.h" 47 #include "net/ssl/ssl_info.h"
45 #endif 48 #endif
46 49
47 namespace { 50 namespace {
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
117 base::scoped_nsobject<NSString> _documentMIMEType; 120 base::scoped_nsobject<NSString> _documentMIMEType;
118 121
119 // Whether the web page is currently performing window.history.pushState or 122 // Whether the web page is currently performing window.history.pushState or
120 // window.history.replaceState 123 // window.history.replaceState
121 // Set to YES on window.history.willChangeState message. To NO on 124 // Set to YES on window.history.willChangeState message. To NO on
122 // window.history.didPushState or window.history.didReplaceState. 125 // window.history.didPushState or window.history.didReplaceState.
123 BOOL _changingHistoryState; 126 BOOL _changingHistoryState;
124 127
125 // CRWWebUIManager object for loading WebUI pages. 128 // CRWWebUIManager object for loading WebUI pages.
126 base::scoped_nsobject<CRWWebUIManager> _webUIManager; 129 base::scoped_nsobject<CRWWebUIManager> _webUIManager;
130
131 // Cert verification object which wraps net::CertVerifier.
132 net::CertVerifierBlockAdapter _certVerifier;
127 } 133 }
128 134
129 // Response's MIME type of the last known navigation. 135 // Response's MIME type of the last known navigation.
130 @property(nonatomic, copy) NSString* documentMIMEType; 136 @property(nonatomic, copy) NSString* documentMIMEType;
131 137
132 // Dictionary where keys are the names of WKWebView properties and values are 138 // Dictionary where keys are the names of WKWebView properties and values are
133 // selector names which should be called when a corresponding property has 139 // selector names which should be called when a corresponding property has
134 // changed. e.g. @{ @"URL" : @"webViewURLDidChange" } means that 140 // changed. e.g. @{ @"URL" : @"webViewURLDidChange" } means that
135 // -[self webViewURLDidChange] must be called every time when WKWebView.URL is 141 // -[self webViewURLDidChange] must be called every time when WKWebView.URL is
136 // changed. 142 // changed.
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
219 // _documentURL, and informs the superclass of the change. 225 // _documentURL, and informs the superclass of the change.
220 - (void)URLDidChangeWithoutDocumentChange:(const GURL&)URL; 226 - (void)URLDidChangeWithoutDocumentChange:(const GURL&)URL;
221 227
222 // Returns new autoreleased instance of WKUserContentController which has 228 // Returns new autoreleased instance of WKUserContentController which has
223 // early page script. 229 // early page script.
224 - (WKUserContentController*)createUserContentController; 230 - (WKUserContentController*)createUserContentController;
225 231
226 // Attempts to handle a script message. Returns YES on success, NO otherwise. 232 // Attempts to handle a script message. Returns YES on success, NO otherwise.
227 - (BOOL)respondToWKScriptMessage:(WKScriptMessage*)scriptMessage; 233 - (BOOL)respondToWKScriptMessage:(WKScriptMessage*)scriptMessage;
228 234
235 // Verifies the given |cert| for the given |host| and calls |block| on
236 // completion. |block| can not be null and may be called either synchronously or
237 // asynchronously.
238 - (void)verifyCert:(scoped_refptr<net::X509Certificate>)cert
239 forHost:(NSString*)host
240 completionHandler:(void (^)(scoped_ptr<net::CertVerifyResult>, int))block;
241
229 #if !defined(ENABLE_CHROME_NET_STACK_FOR_WKWEBVIEW) 242 #if !defined(ENABLE_CHROME_NET_STACK_FOR_WKWEBVIEW)
230 // Called when WKWebView estimatedProgress has been changed. 243 // Called when WKWebView estimatedProgress has been changed.
231 - (void)webViewEstimatedProgressDidChange; 244 - (void)webViewEstimatedProgressDidChange;
232 245
233 // Called when WKWebView hasOnlySecureContent property has changed. 246 // Called when WKWebView hasOnlySecureContent property has changed.
234 - (void)webViewContentSecurityDidChange; 247 - (void)webViewContentSecurityDidChange;
235 #endif // !defined(ENABLE_CHROME_NET_STACK_FOR_WKWEBVIEW) 248 #endif // !defined(ENABLE_CHROME_NET_STACK_FOR_WKWEBVIEW)
236 249
237 // Called when WKWebView loading state has been changed. 250 // Called when WKWebView loading state has been changed.
238 - (void)webViewLoadingStateDidChange; 251 - (void)webViewLoadingStateDidChange;
(...skipping 562 matching lines...) Expand 10 before | Expand all | Expand 10 after
801 (*handlers)["window.history.willChangeState"] = 814 (*handlers)["window.history.willChangeState"] =
802 @selector(handleWindowHistoryWillChangeStateMessage:context:); 815 @selector(handleWindowHistoryWillChangeStateMessage:context:);
803 }); 816 });
804 DCHECK(handlers); 817 DCHECK(handlers);
805 auto iter = handlers->find(command); 818 auto iter = handlers->find(command);
806 return iter != handlers->end() 819 return iter != handlers->end()
807 ? iter->second 820 ? iter->second
808 : [super selectorToHandleJavaScriptCommand:command]; 821 : [super selectorToHandleJavaScriptCommand:command];
809 } 822 }
810 823
824 - (void)verifyCert:(scoped_refptr<net::X509Certificate>)cert
825 forHost:(NSString*)host
826 completionHandler:(void (^)(scoped_ptr<net::CertVerifyResult>, int))block {
827 DCHECK(block);
828 std::string hostname = base::SysNSStringToUTF8(host);
829 net::CertVerifierBlockAdapter::Params params(cert, hostname);
830 params.ocsp_response == ""; // Not provided by iOS API.
831 params.flags = net::CertVerifier::VERIFY_CERT_IO_ENABLED;
832 params.crl_set = net::SSLConfigService::GetCRLSet().Pass();
833 _certVerifier.Verify(params, block);
834 }
835
811 #pragma mark - 836 #pragma mark -
812 #pragma mark JavaScript message handlers 837 #pragma mark JavaScript message handlers
813 838
814 - (BOOL)handleWindowHistoryWillChangeStateMessage: 839 - (BOOL)handleWindowHistoryWillChangeStateMessage:
815 (base::DictionaryValue*)message 840 (base::DictionaryValue*)message
816 context:(NSDictionary*)context { 841 context:(NSDictionary*)context {
817 _changingHistoryState = YES; 842 _changingHistoryState = YES;
818 return 843 return
819 [super handleWindowHistoryWillChangeStateMessage:message context:context]; 844 [super handleWindowHistoryWillChangeStateMessage:message context:context];
820 } 845 }
(...skipping 286 matching lines...) Expand 10 before | Expand all | Expand 10 after
1107 withError:(NSError *)error { 1132 withError:(NSError *)error {
1108 [self handleLoadError:WKWebViewErrorWithSource(error, NAVIGATION) 1133 [self handleLoadError:WKWebViewErrorWithSource(error, NAVIGATION)
1109 inMainFrame:YES]; 1134 inMainFrame:YES];
1110 } 1135 }
1111 1136
1112 - (void)webView:(WKWebView *)webView 1137 - (void)webView:(WKWebView *)webView
1113 didReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge 1138 didReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge
1114 completionHandler: 1139 completionHandler:
1115 (void (^)(NSURLSessionAuthChallengeDisposition disposition, 1140 (void (^)(NSURLSessionAuthChallengeDisposition disposition,
1116 NSURLCredential *credential))completionHandler { 1141 NSURLCredential *credential))completionHandler {
1117 NOTIMPLEMENTED(); 1142 SecTrustRef trust = challenge.protectionSpace.serverTrust;
1118 completionHandler(NSURLSessionAuthChallengeRejectProtectionSpace, nil); 1143 scoped_refptr<net::X509Certificate> cert = web::CreateCertFromTrust(trust);
1144 [self verifyCert:cert
Eugene But (OOO till 7-30) 2015/07/10 19:42:02 At the moment CertVerifier DCHECKs on null cert or
Eugene But (OOO till 7-30) 2015/07/13 16:49:51 Please ignore this comment. cl/1231783003 has land
1145 forHost:challenge.protectionSpace.host
1146 completionHandler:^(scoped_ptr<net::CertVerifyResult> result,
1147 int status) {
1148 DCHECK(result || status);
1149 if (result && !net::IsCertStatusError(result->cert_status)) {
1150 // Cert is valid.
1151 } else {
1152 // Cert is invalid.
1153 }
1154 NOTIMPLEMENTED();
1155 completionHandler(NSURLSessionAuthChallengeRejectProtectionSpace, nil);
1156 }];
1119 } 1157 }
1120 1158
1121 - (void)webViewWebContentProcessDidTerminate:(WKWebView*)webView { 1159 - (void)webViewWebContentProcessDidTerminate:(WKWebView*)webView {
1122 [self webViewWebProcessDidCrash]; 1160 [self webViewWebProcessDidCrash];
1123 } 1161 }
1124 1162
1125 #pragma mark WKUIDelegate Methods 1163 #pragma mark WKUIDelegate Methods
1126 1164
1127 - (WKWebView*)webView:(WKWebView*)webView 1165 - (WKWebView*)webView:(WKWebView*)webView
1128 createWebViewWithConfiguration:(WKWebViewConfiguration*)configuration 1166 createWebViewWithConfiguration:(WKWebViewConfiguration*)configuration
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
1207 placeholderText:defaultText 1245 placeholderText:defaultText
1208 requestURL: 1246 requestURL:
1209 net::GURLWithNSURL(frame.request.URL) 1247 net::GURLWithNSURL(frame.request.URL)
1210 completionHandler:completionHandler]; 1248 completionHandler:completionHandler];
1211 } else if (completionHandler) { 1249 } else if (completionHandler) {
1212 completionHandler(nil); 1250 completionHandler(nil);
1213 } 1251 }
1214 } 1252 }
1215 1253
1216 @end 1254 @end
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698