| 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 #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 #import "ios/web/navigation/crw_session_entry.h" | 19 #import "ios/web/navigation/crw_session_entry.h" |
| 20 #include "ios/web/navigation/navigation_item_impl.h" | 20 #include "ios/web/navigation/navigation_item_impl.h" |
| 21 #include "ios/web/navigation/web_load_params.h" | 21 #include "ios/web/navigation/web_load_params.h" |
| 22 #import "ios/web/net/crw_cert_verification_controller.h" |
| 23 #include "ios/web/public/cert_store.h" |
| 24 #include "ios/web/public/navigation_item.h" |
| 25 #include "ios/web/public/ssl_status.h" |
| 22 #include "ios/web/public/web_client.h" | 26 #include "ios/web/public/web_client.h" |
| 23 #import "ios/web/public/web_state/js/crw_js_injection_manager.h" | 27 #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" | 28 #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" | 29 #import "ios/web/public/web_state/ui/crw_web_view_content_view.h" |
| 26 #import "ios/web/ui_web_view_util.h" | 30 #import "ios/web/ui_web_view_util.h" |
| 27 #include "ios/web/web_state/blocked_popup_info.h" | 31 #include "ios/web/web_state/blocked_popup_info.h" |
| 28 #import "ios/web/web_state/error_translation_util.h" | 32 #import "ios/web/web_state/error_translation_util.h" |
| 29 #include "ios/web/web_state/frame_info.h" | 33 #include "ios/web/web_state/frame_info.h" |
| 30 #import "ios/web/web_state/js/crw_js_window_id_manager.h" | 34 #import "ios/web/web_state/js/crw_js_window_id_manager.h" |
| 31 #import "ios/web/web_state/js/page_script_util.h" | 35 #import "ios/web/web_state/js/page_script_util.h" |
| 32 #import "ios/web/web_state/ui/crw_web_controller+protected.h" | 36 #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" | 37 #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" | 38 #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" | 39 #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" | 40 #import "ios/web/web_state/ui/wk_web_view_configuration_provider.h" |
| 37 #import "ios/web/web_state/web_state_impl.h" | 41 #import "ios/web/web_state/web_state_impl.h" |
| 38 #import "ios/web/web_state/web_view_internal_creation_util.h" | 42 #import "ios/web/web_state/web_view_internal_creation_util.h" |
| 43 #import "ios/web/web_state/wk_web_view_security_util.h" |
| 39 #import "ios/web/webui/crw_web_ui_manager.h" | 44 #import "ios/web/webui/crw_web_ui_manager.h" |
| 45 #include "net/cert/x509_certificate.h" |
| 40 #import "net/base/mac/url_conversions.h" | 46 #import "net/base/mac/url_conversions.h" |
| 47 #include "net/ssl/ssl_info.h" |
| 41 #include "url/url_constants.h" | 48 #include "url/url_constants.h" |
| 42 | 49 |
| 43 #if !defined(ENABLE_CHROME_NET_STACK_FOR_WKWEBVIEW) | |
| 44 #include "ios/web/public/cert_store.h" | |
| 45 #include "ios/web/public/navigation_item.h" | |
| 46 #include "ios/web/public/ssl_status.h" | |
| 47 #import "ios/web/web_state/wk_web_view_security_util.h" | |
| 48 #include "net/cert/x509_certificate.h" | |
| 49 #include "net/ssl/ssl_info.h" | |
| 50 #endif | |
| 51 | |
| 52 namespace { | 50 namespace { |
| 53 // Extracts Referer value from WKNavigationAction request header. | 51 // Extracts Referer value from WKNavigationAction request header. |
| 54 NSString* GetRefererFromNavigationAction(WKNavigationAction* action) { | 52 NSString* GetRefererFromNavigationAction(WKNavigationAction* action) { |
| 55 return [action.request valueForHTTPHeaderField:@"Referer"]; | 53 return [action.request valueForHTTPHeaderField:@"Referer"]; |
| 56 } | 54 } |
| 57 | 55 |
| 58 NSString* const kScriptMessageName = @"crwebinvoke"; | 56 NSString* const kScriptMessageName = @"crwebinvoke"; |
| 59 NSString* const kScriptImmediateName = @"crwebinvokeimmediate"; | 57 NSString* const kScriptImmediateName = @"crwebinvokeimmediate"; |
| 60 | 58 |
| 61 // Utility functions for storing the source of NSErrors received by WKWebViews: | 59 // Utility functions for storing the source of NSErrors received by WKWebViews: |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 129 | 127 |
| 130 // Whether the web page is currently performing window.history.pushState or | 128 // Whether the web page is currently performing window.history.pushState or |
| 131 // window.history.replaceState | 129 // window.history.replaceState |
| 132 // Set to YES on window.history.willChangeState message. To NO on | 130 // Set to YES on window.history.willChangeState message. To NO on |
| 133 // window.history.didPushState or window.history.didReplaceState. | 131 // window.history.didPushState or window.history.didReplaceState. |
| 134 BOOL _changingHistoryState; | 132 BOOL _changingHistoryState; |
| 135 | 133 |
| 136 // CRWWebUIManager object for loading WebUI pages. | 134 // CRWWebUIManager object for loading WebUI pages. |
| 137 base::scoped_nsobject<CRWWebUIManager> _webUIManager; | 135 base::scoped_nsobject<CRWWebUIManager> _webUIManager; |
| 138 | 136 |
| 137 // Controller used for certs verification to help with blocking requests with |
| 138 // bad SSL cert, presenting SSL interstitials and determining SSL status for |
| 139 // Navigation Items. |
| 140 base::scoped_nsobject<CRWCertVerificationController> |
| 141 _certVerificationController; |
| 142 |
| 139 // Whether the pending navigation has been directly cancelled in | 143 // Whether the pending navigation has been directly cancelled in |
| 140 // |decidePolicyForNavigationAction| or |decidePolicyForNavigationResponse|. | 144 // |decidePolicyForNavigationAction| or |decidePolicyForNavigationResponse|. |
| 141 // Cancelled navigations should be simply discarded without handling any | 145 // Cancelled navigations should be simply discarded without handling any |
| 142 // specific error. | 146 // specific error. |
| 143 BOOL _pendingNavigationCancelled; | 147 BOOL _pendingNavigationCancelled; |
| 144 } | 148 } |
| 145 | 149 |
| 146 // Response's MIME type of the last known navigation. | 150 // Response's MIME type of the last known navigation. |
| 147 @property(nonatomic, copy) NSString* documentMIMEType; | 151 @property(nonatomic, copy) NSString* documentMIMEType; |
| 148 | 152 |
| (...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 286 // Called when WKWebView URL has been changed. | 290 // Called when WKWebView URL has been changed. |
| 287 - (void)webViewURLDidChange; | 291 - (void)webViewURLDidChange; |
| 288 | 292 |
| 289 @end | 293 @end |
| 290 | 294 |
| 291 @implementation CRWWKWebViewWebController | 295 @implementation CRWWKWebViewWebController |
| 292 | 296 |
| 293 #pragma mark CRWWebController public methods | 297 #pragma mark CRWWebController public methods |
| 294 | 298 |
| 295 - (instancetype)initWithWebState:(scoped_ptr<web::WebStateImpl>)webState { | 299 - (instancetype)initWithWebState:(scoped_ptr<web::WebStateImpl>)webState { |
| 296 return [super initWithWebState:webState.Pass()]; | 300 DCHECK(webState); |
| 301 web::BrowserState* browserState = webState->GetBrowserState(); |
| 302 self = [super initWithWebState:webState.Pass()]; |
| 303 if (self) { |
| 304 _certVerificationController.reset([[CRWCertVerificationController alloc] |
| 305 initWithBrowserState:browserState]); |
| 306 } |
| 307 return self; |
| 297 } | 308 } |
| 298 | 309 |
| 299 - (BOOL)keyboardDisplayRequiresUserAction { | 310 - (BOOL)keyboardDisplayRequiresUserAction { |
| 300 // TODO(stuartmorgan): Find out whether YES or NO is correct; see comment | 311 // TODO(stuartmorgan): Find out whether YES or NO is correct; see comment |
| 301 // in protected header. | 312 // in protected header. |
| 302 NOTIMPLEMENTED(); | 313 NOTIMPLEMENTED(); |
| 303 return NO; | 314 return NO; |
| 304 } | 315 } |
| 305 | 316 |
| 306 - (void)setKeyboardDisplayRequiresUserAction:(BOOL)requiresUserAction { | 317 - (void)setKeyboardDisplayRequiresUserAction:(BOOL)requiresUserAction { |
| (...skipping 21 matching lines...) Expand all Loading... |
| 328 [super terminateNetworkActivity]; | 339 [super terminateNetworkActivity]; |
| 329 } | 340 } |
| 330 #endif // #if !defined(ENABLE_CHROME_NET_STACK_FOR_WKWEBVIEW) | 341 #endif // #if !defined(ENABLE_CHROME_NET_STACK_FOR_WKWEBVIEW) |
| 331 | 342 |
| 332 - (void)setPageDialogOpenPolicy:(web::PageDialogOpenPolicy)policy { | 343 - (void)setPageDialogOpenPolicy:(web::PageDialogOpenPolicy)policy { |
| 333 // TODO(eugenebut): implement dialogs/windows suppression using | 344 // TODO(eugenebut): implement dialogs/windows suppression using |
| 334 // WKNavigationDelegate methods where possible. | 345 // WKNavigationDelegate methods where possible. |
| 335 [super setPageDialogOpenPolicy:policy]; | 346 [super setPageDialogOpenPolicy:policy]; |
| 336 } | 347 } |
| 337 | 348 |
| 349 - (void)close { |
| 350 [_certVerificationController shutDown]; |
| 351 [super close]; |
| 352 } |
| 353 |
| 338 #pragma mark - | 354 #pragma mark - |
| 339 #pragma mark Testing-Only Methods | 355 #pragma mark Testing-Only Methods |
| 340 | 356 |
| 341 - (void)injectWebViewContentView:(CRWWebViewContentView*)webViewContentView { | 357 - (void)injectWebViewContentView:(CRWWebViewContentView*)webViewContentView { |
| 342 [super injectWebViewContentView:webViewContentView]; | 358 [super injectWebViewContentView:webViewContentView]; |
| 343 [self setWebView:static_cast<WKWebView*>(webViewContentView.webView)]; | 359 [self setWebView:static_cast<WKWebView*>(webViewContentView.webView)]; |
| 344 } | 360 } |
| 345 | 361 |
| 346 #pragma mark - Protected property implementations | 362 #pragma mark - Protected property implementations |
| 347 | 363 |
| (...skipping 989 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1337 withError:(NSError *)error { | 1353 withError:(NSError *)error { |
| 1338 [self handleLoadError:WKWebViewErrorWithSource(error, NAVIGATION) | 1354 [self handleLoadError:WKWebViewErrorWithSource(error, NAVIGATION) |
| 1339 inMainFrame:YES]; | 1355 inMainFrame:YES]; |
| 1340 } | 1356 } |
| 1341 | 1357 |
| 1342 - (void)webView:(WKWebView *)webView | 1358 - (void)webView:(WKWebView *)webView |
| 1343 didReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge | 1359 didReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge |
| 1344 completionHandler: | 1360 completionHandler: |
| 1345 (void (^)(NSURLSessionAuthChallengeDisposition disposition, | 1361 (void (^)(NSURLSessionAuthChallengeDisposition disposition, |
| 1346 NSURLCredential *credential))completionHandler { | 1362 NSURLCredential *credential))completionHandler { |
| 1347 NOTIMPLEMENTED(); | 1363 if (![challenge.protectionSpace.authenticationMethod |
| 1348 completionHandler(NSURLSessionAuthChallengeRejectProtectionSpace, nil); | 1364 isEqual:NSURLAuthenticationMethodServerTrust]) { |
| 1365 completionHandler(NSURLSessionAuthChallengePerformDefaultHandling, nil); |
| 1366 return; |
| 1367 } |
| 1368 |
| 1369 SecTrustRef trust = challenge.protectionSpace.serverTrust; |
| 1370 scoped_refptr<net::X509Certificate> cert = web::CreateCertFromTrust(trust); |
| 1371 [_certVerificationController |
| 1372 decidePolicyForCert:cert |
| 1373 host:challenge.protectionSpace.host |
| 1374 completionHandler:^(web::CertAcceptPolicy policy, |
| 1375 net::CertStatus status) { |
| 1376 completionHandler(NSURLSessionAuthChallengeRejectProtectionSpace, |
| 1377 nil); |
| 1378 }]; |
| 1349 } | 1379 } |
| 1350 | 1380 |
| 1351 - (void)webViewWebContentProcessDidTerminate:(WKWebView*)webView { | 1381 - (void)webViewWebContentProcessDidTerminate:(WKWebView*)webView { |
| 1352 [self webViewWebProcessDidCrash]; | 1382 [self webViewWebProcessDidCrash]; |
| 1353 } | 1383 } |
| 1354 | 1384 |
| 1355 #pragma mark WKUIDelegate Methods | 1385 #pragma mark WKUIDelegate Methods |
| 1356 | 1386 |
| 1357 - (WKWebView*)webView:(WKWebView*)webView | 1387 - (WKWebView*)webView:(WKWebView*)webView |
| 1358 createWebViewWithConfiguration:(WKWebViewConfiguration*)configuration | 1388 createWebViewWithConfiguration:(WKWebViewConfiguration*)configuration |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1437 placeholderText:defaultText | 1467 placeholderText:defaultText |
| 1438 requestURL: | 1468 requestURL: |
| 1439 net::GURLWithNSURL(frame.request.URL) | 1469 net::GURLWithNSURL(frame.request.URL) |
| 1440 completionHandler:completionHandler]; | 1470 completionHandler:completionHandler]; |
| 1441 } else if (completionHandler) { | 1471 } else if (completionHandler) { |
| 1442 completionHandler(nil); | 1472 completionHandler(nil); |
| 1443 } | 1473 } |
| 1444 } | 1474 } |
| 1445 | 1475 |
| 1446 @end | 1476 @end |
| OLD | NEW |