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/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 #include "base/mac/bind_objc_block.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" |
15 #import "base/memory/scoped_ptr.h" | |
14 #include "base/strings/sys_string_conversions.h" | 16 #include "base/strings/sys_string_conversions.h" |
15 #include "base/values.h" | 17 #include "base/values.h" |
16 #import "ios/net/http_response_headers_util.h" | 18 #import "ios/net/http_response_headers_util.h" |
17 #import "ios/web/crw_network_activity_indicator_manager.h" | 19 #import "ios/web/crw_network_activity_indicator_manager.h" |
18 #import "ios/web/navigation/crw_session_controller.h" | 20 #import "ios/web/navigation/crw_session_controller.h" |
19 #import "ios/web/navigation/crw_session_entry.h" | 21 #import "ios/web/navigation/crw_session_entry.h" |
20 #include "ios/web/navigation/navigation_item_impl.h" | 22 #include "ios/web/navigation/navigation_item_impl.h" |
21 #include "ios/web/navigation/web_load_params.h" | 23 #include "ios/web/navigation/web_load_params.h" |
24 #include "ios/web/net/cert_verifier_block_adapter.h" | |
25 #include "ios/web/public/browser_state.h" | |
22 #include "ios/web/public/web_client.h" | 26 #include "ios/web/public/web_client.h" |
27 #include "ios/web/public/web_thread.h" | |
23 #import "ios/web/public/web_state/js/crw_js_injection_manager.h" | 28 #import "ios/web/public/web_state/js/crw_js_injection_manager.h" |
24 #import "ios/web/public/web_state/ui/crw_native_content_provider.h" | 29 #import "ios/web/public/web_state/ui/crw_native_content_provider.h" |
25 #import "ios/web/public/web_state/ui/crw_web_view_content_view.h" | 30 #import "ios/web/public/web_state/ui/crw_web_view_content_view.h" |
26 #import "ios/web/ui_web_view_util.h" | 31 #import "ios/web/ui_web_view_util.h" |
27 #include "ios/web/web_state/blocked_popup_info.h" | 32 #include "ios/web/web_state/blocked_popup_info.h" |
28 #import "ios/web/web_state/error_translation_util.h" | 33 #import "ios/web/web_state/error_translation_util.h" |
29 #include "ios/web/web_state/frame_info.h" | 34 #include "ios/web/web_state/frame_info.h" |
30 #import "ios/web/web_state/js/crw_js_window_id_manager.h" | 35 #import "ios/web/web_state/js/crw_js_window_id_manager.h" |
31 #import "ios/web/web_state/js/page_script_util.h" | 36 #import "ios/web/web_state/js/page_script_util.h" |
32 #import "ios/web/web_state/ui/crw_web_controller+protected.h" | 37 #import "ios/web/web_state/ui/crw_web_controller+protected.h" |
33 #import "ios/web/web_state/ui/crw_wk_web_view_crash_detector.h" | 38 #import "ios/web/web_state/ui/crw_wk_web_view_crash_detector.h" |
34 #import "ios/web/web_state/ui/web_view_js_utils.h" | 39 #import "ios/web/web_state/ui/web_view_js_utils.h" |
35 #import "ios/web/web_state/ui/wk_back_forward_list_item_holder.h" | 40 #import "ios/web/web_state/ui/wk_back_forward_list_item_holder.h" |
36 #import "ios/web/web_state/ui/wk_web_view_configuration_provider.h" | 41 #import "ios/web/web_state/ui/wk_web_view_configuration_provider.h" |
37 #import "ios/web/web_state/web_state_impl.h" | 42 #import "ios/web/web_state/web_state_impl.h" |
38 #import "ios/web/web_state/web_view_internal_creation_util.h" | 43 #import "ios/web/web_state/web_view_internal_creation_util.h" |
39 #import "ios/web/webui/crw_web_ui_manager.h" | 44 #import "ios/web/webui/crw_web_ui_manager.h" |
40 #import "net/base/mac/url_conversions.h" | 45 #import "net/base/mac/url_conversions.h" |
46 #include "net/cert/cert_verify_result.h" | |
47 #include "net/ssl/ssl_config_service.h" | |
48 #include "net/url_request/url_request_context.h" | |
41 #include "url/url_constants.h" | 49 #include "url/url_constants.h" |
42 | 50 |
43 #if !defined(ENABLE_CHROME_NET_STACK_FOR_WKWEBVIEW) | 51 #if !defined(ENABLE_CHROME_NET_STACK_FOR_WKWEBVIEW) |
44 #include "ios/web/public/cert_store.h" | 52 #include "ios/web/public/cert_store.h" |
45 #include "ios/web/public/navigation_item.h" | 53 #include "ios/web/public/navigation_item.h" |
46 #include "ios/web/public/ssl_status.h" | 54 #include "ios/web/public/ssl_status.h" |
47 #import "ios/web/web_state/wk_web_view_security_util.h" | 55 #import "ios/web/web_state/wk_web_view_security_util.h" |
48 #include "net/cert/x509_certificate.h" | 56 #include "net/cert/x509_certificate.h" |
49 #include "net/ssl/ssl_info.h" | 57 #include "net/ssl/ssl_info.h" |
50 #endif | 58 #endif |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
128 scoped_ptr<WKNavigationType> _pendingNavigationTypeForMainFrame; | 136 scoped_ptr<WKNavigationType> _pendingNavigationTypeForMainFrame; |
129 | 137 |
130 // Whether the web page is currently performing window.history.pushState or | 138 // Whether the web page is currently performing window.history.pushState or |
131 // window.history.replaceState | 139 // window.history.replaceState |
132 // Set to YES on window.history.willChangeState message. To NO on | 140 // Set to YES on window.history.willChangeState message. To NO on |
133 // window.history.didPushState or window.history.didReplaceState. | 141 // window.history.didPushState or window.history.didReplaceState. |
134 BOOL _changingHistoryState; | 142 BOOL _changingHistoryState; |
135 | 143 |
136 // CRWWebUIManager object for loading WebUI pages. | 144 // CRWWebUIManager object for loading WebUI pages. |
137 base::scoped_nsobject<CRWWebUIManager> _webUIManager; | 145 base::scoped_nsobject<CRWWebUIManager> _webUIManager; |
146 | |
147 // Cert verification object which wraps |net::CertVerifier|. Must be created, | |
148 // used and destroyed on IO Thread. | |
149 scoped_ptr<web::CertVerifierBlockAdapter> _certVerifier; | |
150 | |
151 // URLRequestContextGetter for obtaining net layer objects. | |
152 net::URLRequestContextGetter* _contextGetter; | |
138 } | 153 } |
139 | 154 |
140 // Response's MIME type of the last known navigation. | 155 // Response's MIME type of the last known navigation. |
141 @property(nonatomic, copy) NSString* documentMIMEType; | 156 @property(nonatomic, copy) NSString* documentMIMEType; |
142 | 157 |
143 // Dictionary where keys are the names of WKWebView properties and values are | 158 // Dictionary where keys are the names of WKWebView properties and values are |
144 // selector names which should be called when a corresponding property has | 159 // selector names which should be called when a corresponding property has |
145 // changed. e.g. @{ @"URL" : @"webViewURLDidChange" } means that | 160 // changed. e.g. @{ @"URL" : @"webViewURLDidChange" } means that |
146 // -[self webViewURLDidChange] must be called every time when WKWebView.URL is | 161 // -[self webViewURLDidChange] must be called every time when WKWebView.URL is |
147 // changed. | 162 // changed. |
148 @property(nonatomic, readonly) NSDictionary* wkWebViewObservers; | 163 @property(nonatomic, readonly) NSDictionary* wkWebViewObservers; |
149 | 164 |
150 // Returns the string to use as the request group ID in the user agent. Returns | 165 // Returns the string to use as the request group ID in the user agent. Returns |
151 // nil unless the network stack is enabled. | 166 // nil unless the network stack is enabled. |
152 @property(nonatomic, readonly) NSString* requestGroupIDForUserAgent; | 167 @property(nonatomic, readonly) NSString* requestGroupIDForUserAgent; |
153 | 168 |
154 // Activity indicator group ID for this web controller. | 169 // Activity indicator group ID for this web controller. |
155 @property(nonatomic, readonly) NSString* activityIndicatorGroupID; | 170 @property(nonatomic, readonly) NSString* activityIndicatorGroupID; |
156 | 171 |
157 #if !defined(ENABLE_CHROME_NET_STACK_FOR_WKWEBVIEW) | 172 #if !defined(ENABLE_CHROME_NET_STACK_FOR_WKWEBVIEW) |
158 // Identifier used for storing and retrieving certificates. | 173 // Identifier used for storing and retrieving certificates. |
159 @property(nonatomic, readonly) int certGroupID; | 174 @property(nonatomic, readonly) int certGroupID; |
160 #endif // #if !defined(ENABLE_CHROME_NET_STACK_FOR_WKWEBVIEW) | 175 #endif // #if !defined(ENABLE_CHROME_NET_STACK_FOR_WKWEBVIEW) |
161 | 176 |
177 // Cert verification flags. Must be used on IO Thread. | |
178 @property(nonatomic, readonly) int certVerifyFlags; | |
179 | |
180 // Creates _certVerifier object on IO thread. | |
181 - (void)createCertVerifier; | |
182 | |
162 // Returns the WKWebViewConfigurationProvider associated with the web | 183 // Returns the WKWebViewConfigurationProvider associated with the web |
163 // controller's BrowserState. | 184 // controller's BrowserState. |
164 - (web::WKWebViewConfigurationProvider&)webViewConfigurationProvider; | 185 - (web::WKWebViewConfigurationProvider&)webViewConfigurationProvider; |
165 | 186 |
166 // Creates a web view with given |config|. No-op if web view is already created. | 187 // Creates a web view with given |config|. No-op if web view is already created. |
167 - (void)ensureWebViewCreatedWithConfiguration:(WKWebViewConfiguration*)config; | 188 - (void)ensureWebViewCreatedWithConfiguration:(WKWebViewConfiguration*)config; |
168 | 189 |
169 // Returns a new autoreleased web view created with given configuration. | 190 // Returns a new autoreleased web view created with given configuration. |
170 - (WKWebView*)createWebViewWithConfiguration:(WKWebViewConfiguration*)config; | 191 - (WKWebView*)createWebViewWithConfiguration:(WKWebViewConfiguration*)config; |
171 | 192 |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
247 // _documentURL, and informs the superclass of the change. | 268 // _documentURL, and informs the superclass of the change. |
248 - (void)URLDidChangeWithoutDocumentChange:(const GURL&)URL; | 269 - (void)URLDidChangeWithoutDocumentChange:(const GURL&)URL; |
249 | 270 |
250 // Returns new autoreleased instance of WKUserContentController which has | 271 // Returns new autoreleased instance of WKUserContentController which has |
251 // early page script. | 272 // early page script. |
252 - (WKUserContentController*)createUserContentController; | 273 - (WKUserContentController*)createUserContentController; |
253 | 274 |
254 // Attempts to handle a script message. Returns YES on success, NO otherwise. | 275 // Attempts to handle a script message. Returns YES on success, NO otherwise. |
255 - (BOOL)respondToWKScriptMessage:(WKScriptMessage*)scriptMessage; | 276 - (BOOL)respondToWKScriptMessage:(WKScriptMessage*)scriptMessage; |
256 | 277 |
278 // Verifies the given |cert| for the given |host| and calls |completionHandler| | |
279 // on completion. |completionHandler| cannot be null and will be called | |
280 // asynchronously on IO thread. | |
281 - (void)verifyCert:(const scoped_refptr<net::X509Certificate>&)cert | |
282 forHost:(NSString*)host | |
283 completionHandler:(void (^)(net::CertVerifyResult, int))completionHandler; | |
284 | |
257 // Used to decide whether a load that generates errors with the | 285 // Used to decide whether a load that generates errors with the |
258 // NSURLErrorCancelled code should be cancelled. | 286 // NSURLErrorCancelled code should be cancelled. |
259 - (BOOL)shouldAbortLoadForCancelledError:(NSError*)error; | 287 - (BOOL)shouldAbortLoadForCancelledError:(NSError*)error; |
260 | 288 |
261 #if !defined(ENABLE_CHROME_NET_STACK_FOR_WKWEBVIEW) | 289 #if !defined(ENABLE_CHROME_NET_STACK_FOR_WKWEBVIEW) |
262 // Called when WKWebView estimatedProgress has been changed. | 290 // Called when WKWebView estimatedProgress has been changed. |
263 - (void)webViewEstimatedProgressDidChange; | 291 - (void)webViewEstimatedProgressDidChange; |
264 | 292 |
265 // Called when WKWebView certificateChain or hasOnlySecureContent property has | 293 // Called when WKWebView certificateChain or hasOnlySecureContent property has |
266 // changed. | 294 // changed. |
267 - (void)webViewSecurityFeaturesDidChange; | 295 - (void)webViewSecurityFeaturesDidChange; |
268 #endif // !defined(ENABLE_CHROME_NET_STACK_FOR_WKWEBVIEW) | 296 #endif // !defined(ENABLE_CHROME_NET_STACK_FOR_WKWEBVIEW) |
269 | 297 |
270 // Called when WKWebView loading state has been changed. | 298 // Called when WKWebView loading state has been changed. |
271 - (void)webViewLoadingStateDidChange; | 299 - (void)webViewLoadingStateDidChange; |
272 | 300 |
273 // Called when WKWebView title has been changed. | 301 // Called when WKWebView title has been changed. |
274 - (void)webViewTitleDidChange; | 302 - (void)webViewTitleDidChange; |
275 | 303 |
276 // Called when WKWebView URL has been changed. | 304 // Called when WKWebView URL has been changed. |
277 - (void)webViewURLDidChange; | 305 - (void)webViewURLDidChange; |
278 | 306 |
279 @end | 307 @end |
280 | 308 |
281 @implementation CRWWKWebViewWebController | 309 @implementation CRWWKWebViewWebController |
282 | 310 |
283 #pragma mark CRWWebController public methods | 311 #pragma mark CRWWebController public methods |
284 | 312 |
285 - (instancetype)initWithWebState:(scoped_ptr<web::WebStateImpl>)webState { | 313 - (instancetype)initWithWebState:(scoped_ptr<web::WebStateImpl>)webState { |
286 return [super initWithWebState:webState.Pass()]; | 314 DCHECK(webState); |
315 web::BrowserState* browserState = webState->GetBrowserState(); | |
316 self = [super initWithWebState:webState.Pass()]; | |
317 if (self) { | |
318 _contextGetter = browserState->GetRequestContext(); | |
319 [self createCertVerifier]; | |
320 } | |
321 return self; | |
287 } | 322 } |
288 | 323 |
289 - (BOOL)keyboardDisplayRequiresUserAction { | 324 - (BOOL)keyboardDisplayRequiresUserAction { |
290 // TODO(stuartmorgan): Find out whether YES or NO is correct; see comment | 325 // TODO(stuartmorgan): Find out whether YES or NO is correct; see comment |
291 // in protected header. | 326 // in protected header. |
292 NOTIMPLEMENTED(); | 327 NOTIMPLEMENTED(); |
293 return NO; | 328 return NO; |
294 } | 329 } |
295 | 330 |
296 - (void)setKeyboardDisplayRequiresUserAction:(BOOL)requiresUserAction { | 331 - (void)setKeyboardDisplayRequiresUserAction:(BOOL)requiresUserAction { |
(...skipping 21 matching lines...) Expand all Loading... | |
318 [super terminateNetworkActivity]; | 353 [super terminateNetworkActivity]; |
319 } | 354 } |
320 #endif // #if !defined(ENABLE_CHROME_NET_STACK_FOR_WKWEBVIEW) | 355 #endif // #if !defined(ENABLE_CHROME_NET_STACK_FOR_WKWEBVIEW) |
321 | 356 |
322 - (void)setPageDialogOpenPolicy:(web::PageDialogOpenPolicy)policy { | 357 - (void)setPageDialogOpenPolicy:(web::PageDialogOpenPolicy)policy { |
323 // TODO(eugenebut): implement dialogs/windows suppression using | 358 // TODO(eugenebut): implement dialogs/windows suppression using |
324 // WKNavigationDelegate methods where possible. | 359 // WKNavigationDelegate methods where possible. |
325 [super setPageDialogOpenPolicy:policy]; | 360 [super setPageDialogOpenPolicy:policy]; |
326 } | 361 } |
327 | 362 |
363 - (void)close { | |
364 // _certVerifier must be accessed only on IO thread. | |
365 web::WebThread::PostTask(web::WebThread::IO, FROM_HERE, base::BindBlock(^{ | |
366 _certVerifier.reset(); | |
367 // This block will be destroyed on IO thread, so make sure that self is | |
368 // deallocated on the main thread. | |
369 [self retain]; | |
370 dispatch_async(dispatch_get_main_queue(), ^{ | |
371 [self release]; | |
372 }); | |
davidben
2015/08/24 21:23:02
I don't think this works. The block itself retains
stuartmorgan
2015/08/24 21:29:43
Ugh, right. Someday I hope to actually learn to re
davidben
2015/08/24 21:33:42
And that's why we //net folks are so allergic to r
stuartmorgan
2015/08/24 22:44:02
A common pattern for us is explicit teardowns that
| |
373 })); | |
374 [super close]; | |
375 } | |
376 | |
328 #pragma mark - | 377 #pragma mark - |
329 #pragma mark Testing-Only Methods | 378 #pragma mark Testing-Only Methods |
330 | 379 |
331 - (void)injectWebViewContentView:(CRWWebViewContentView*)webViewContentView { | 380 - (void)injectWebViewContentView:(CRWWebViewContentView*)webViewContentView { |
332 [super injectWebViewContentView:webViewContentView]; | 381 [super injectWebViewContentView:webViewContentView]; |
333 [self setWebView:static_cast<WKWebView*>(webViewContentView.webView)]; | 382 [self setWebView:static_cast<WKWebView*>(webViewContentView.webView)]; |
334 } | 383 } |
335 | 384 |
336 #pragma mark - Protected property implementations | 385 #pragma mark - Protected property implementations |
337 | 386 |
(...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
585 } | 634 } |
586 | 635 |
587 #if !defined(ENABLE_CHROME_NET_STACK_FOR_WKWEBVIEW) | 636 #if !defined(ENABLE_CHROME_NET_STACK_FOR_WKWEBVIEW) |
588 - (int)certGroupID { | 637 - (int)certGroupID { |
589 DCHECK(self.webStateImpl); | 638 DCHECK(self.webStateImpl); |
590 // Request tracker IDs are used as certificate groups. | 639 // Request tracker IDs are used as certificate groups. |
591 return self.webStateImpl->GetRequestTracker()->identifier(); | 640 return self.webStateImpl->GetRequestTracker()->identifier(); |
592 } | 641 } |
593 #endif | 642 #endif |
594 | 643 |
644 - (int)certVerifyFlags { | |
645 DCHECK(web::WebThread::CurrentlyOn(web::WebThread::IO)); | |
646 DCHECK(_contextGetter); | |
647 // Context Getter's life time is expected to be at least the same or longer | |
648 // than |BrowserState| lifetime in which case it is safe to assume that | |
649 // _contextGetter is alive at least until -close is called. | |
stuartmorgan
2015/08/24 20:34:24
DCHECK(_certVerifier) so that the requirement that
Eugene But (OOO till 7-30)
2015/08/24 21:18:07
Sure.
| |
650 net::URLRequestContext* context = _contextGetter->GetURLRequestContext(); | |
651 DCHECK(context); | |
652 net::SSLConfigService* SSLConfigService = context->ssl_config_service(); | |
653 DCHECK(SSLConfigService); | |
654 net::SSLConfig config; | |
655 SSLConfigService->GetSSLConfig(&config); | |
656 return config.GetCertVerifyFlags(); | |
657 } | |
658 | |
659 - (void)createCertVerifier { | |
660 web::WebThread::PostTask(web::WebThread::IO, FROM_HERE, base::BindBlock(^{ | |
661 net::URLRequestContext* context = _contextGetter->GetURLRequestContext(); | |
662 _certVerifier.reset(new web::CertVerifierBlockAdapter( | |
663 context->cert_verifier(), context->net_log())); | |
664 })); | |
665 } | |
666 | |
595 - (web::WKWebViewConfigurationProvider&)webViewConfigurationProvider { | 667 - (web::WKWebViewConfigurationProvider&)webViewConfigurationProvider { |
596 DCHECK(self.webStateImpl); | 668 DCHECK(self.webStateImpl); |
597 web::BrowserState* browserState = self.webStateImpl->GetBrowserState(); | 669 web::BrowserState* browserState = self.webStateImpl->GetBrowserState(); |
598 return web::WKWebViewConfigurationProvider::FromBrowserState(browserState); | 670 return web::WKWebViewConfigurationProvider::FromBrowserState(browserState); |
599 } | 671 } |
600 | 672 |
601 - (void)ensureWebViewCreatedWithConfiguration:(WKWebViewConfiguration*)config { | 673 - (void)ensureWebViewCreatedWithConfiguration:(WKWebViewConfiguration*)config { |
602 if (!_wkWebView) { | 674 if (!_wkWebView) { |
603 // Use a separate userContentController for each web view. | 675 // Use a separate userContentController for each web view. |
604 // WKUserContentController does not allow adding multiple script message | 676 // WKUserContentController does not allow adding multiple script message |
(...skipping 351 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
956 (*handlers)["window.history.willChangeState"] = | 1028 (*handlers)["window.history.willChangeState"] = |
957 @selector(handleWindowHistoryWillChangeStateMessage:context:); | 1029 @selector(handleWindowHistoryWillChangeStateMessage:context:); |
958 }); | 1030 }); |
959 DCHECK(handlers); | 1031 DCHECK(handlers); |
960 auto iter = handlers->find(command); | 1032 auto iter = handlers->find(command); |
961 return iter != handlers->end() | 1033 return iter != handlers->end() |
962 ? iter->second | 1034 ? iter->second |
963 : [super selectorToHandleJavaScriptCommand:command]; | 1035 : [super selectorToHandleJavaScriptCommand:command]; |
964 } | 1036 } |
965 | 1037 |
1038 - (void)verifyCert:(const scoped_refptr<net::X509Certificate>&)cert | |
1039 forHost:(NSString*)host | |
1040 completionHandler:(void (^)(net::CertVerifyResult, int))completionHandler { | |
1041 DCHECK(completionHandler); | |
1042 __block scoped_refptr<net::X509Certificate> blockCert = cert; | |
1043 web::WebThread::PostTask( | |
1044 web::WebThread::IO, FROM_HERE, base::BindBlock(^{ | |
1045 // WeakNSObject does not work across different threads, hence this block | |
1046 // retains self. | |
1047 if (!_certVerifier) { | |
1048 completionHandler(net::CertVerifyResult(), net::ERR_FAILED); | |
1049 return; | |
1050 } | |
1051 | |
1052 web::CertVerifierBlockAdapter::Params params( | |
1053 blockCert.Pass(), base::SysNSStringToUTF8(host)); | |
1054 params.flags = self.certVerifyFlags; | |
1055 params.crl_set = net::SSLConfigService::GetCRLSet(); | |
1056 // OCSP response is not provided by iOS API. | |
1057 _certVerifier->Verify(params, completionHandler); | |
1058 })); | |
1059 } | |
1060 | |
966 - (BOOL)shouldAbortLoadForCancelledError:(NSError*)error { | 1061 - (BOOL)shouldAbortLoadForCancelledError:(NSError*)error { |
967 DCHECK_EQ(error.code, NSURLErrorCancelled); | 1062 DCHECK_EQ(error.code, NSURLErrorCancelled); |
968 // Do not abort the load if it is for an app specific URL, as such errors | 1063 // Do not abort the load if it is for an app specific URL, as such errors |
969 // are produced during the app specific URL load process. | 1064 // are produced during the app specific URL load process. |
970 const GURL errorURL = | 1065 const GURL errorURL = |
971 net::GURLWithNSURL(error.userInfo[NSURLErrorFailingURLErrorKey]); | 1066 net::GURLWithNSURL(error.userInfo[NSURLErrorFailingURLErrorKey]); |
972 if (web::GetWebClient()->IsAppSpecificURL(errorURL)) | 1067 if (web::GetWebClient()->IsAppSpecificURL(errorURL)) |
973 return NO; | 1068 return NO; |
974 // Don't abort NSURLErrorCancelled errors originating from navigation | 1069 // Don't abort NSURLErrorCancelled errors originating from navigation |
975 // as the WKWebView will automatically retry these loads. | 1070 // as the WKWebView will automatically retry these loads. |
(...skipping 325 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1301 withError:(NSError *)error { | 1396 withError:(NSError *)error { |
1302 [self handleLoadError:WKWebViewErrorWithSource(error, NAVIGATION) | 1397 [self handleLoadError:WKWebViewErrorWithSource(error, NAVIGATION) |
1303 inMainFrame:YES]; | 1398 inMainFrame:YES]; |
1304 } | 1399 } |
1305 | 1400 |
1306 - (void)webView:(WKWebView *)webView | 1401 - (void)webView:(WKWebView *)webView |
1307 didReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge | 1402 didReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge |
1308 completionHandler: | 1403 completionHandler: |
1309 (void (^)(NSURLSessionAuthChallengeDisposition disposition, | 1404 (void (^)(NSURLSessionAuthChallengeDisposition disposition, |
1310 NSURLCredential *credential))completionHandler { | 1405 NSURLCredential *credential))completionHandler { |
1311 NOTIMPLEMENTED(); | 1406 if (![challenge.protectionSpace.authenticationMethod |
1312 completionHandler(NSURLSessionAuthChallengeRejectProtectionSpace, nil); | 1407 isEqual:NSURLAuthenticationMethodServerTrust]) { |
1408 completionHandler(NSURLSessionAuthChallengePerformDefaultHandling, nil); | |
1409 return; | |
1410 } | |
1411 | |
1412 SecTrustRef trust = challenge.protectionSpace.serverTrust; | |
1413 scoped_refptr<net::X509Certificate> cert = web::CreateCertFromTrust(trust); | |
1414 [self verifyCert:cert | |
1415 forHost:challenge.protectionSpace.host | |
1416 completionHandler:^(net::CertVerifyResult, int error) { | |
1417 dispatch_async(dispatch_get_main_queue(), ^{ | |
1418 if (error == net::OK) { | |
1419 // Cert is valid. | |
1420 } else { | |
1421 // Cert is invalid or its state is unknown. | |
1422 } | |
1423 NOTIMPLEMENTED(); | |
1424 completionHandler(NSURLSessionAuthChallengeRejectProtectionSpace, | |
1425 nil); | |
1426 }); | |
1427 }]; | |
1313 } | 1428 } |
1314 | 1429 |
1315 - (void)webViewWebContentProcessDidTerminate:(WKWebView*)webView { | 1430 - (void)webViewWebContentProcessDidTerminate:(WKWebView*)webView { |
1316 [self webViewWebProcessDidCrash]; | 1431 [self webViewWebProcessDidCrash]; |
1317 } | 1432 } |
1318 | 1433 |
1319 #pragma mark WKUIDelegate Methods | 1434 #pragma mark WKUIDelegate Methods |
1320 | 1435 |
1321 - (WKWebView*)webView:(WKWebView*)webView | 1436 - (WKWebView*)webView:(WKWebView*)webView |
1322 createWebViewWithConfiguration:(WKWebViewConfiguration*)configuration | 1437 createWebViewWithConfiguration:(WKWebViewConfiguration*)configuration |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1401 placeholderText:defaultText | 1516 placeholderText:defaultText |
1402 requestURL: | 1517 requestURL: |
1403 net::GURLWithNSURL(frame.request.URL) | 1518 net::GURLWithNSURL(frame.request.URL) |
1404 completionHandler:completionHandler]; | 1519 completionHandler:completionHandler]; |
1405 } else if (completionHandler) { | 1520 } else if (completionHandler) { |
1406 completionHandler(nil); | 1521 completionHandler(nil); |
1407 } | 1522 } |
1408 } | 1523 } |
1409 | 1524 |
1410 @end | 1525 @end |
OLD | NEW |