| OLD | NEW |
| 1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 2012 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_web_controller.h" | 5 #import "ios/web/web_state/ui/crw_web_controller.h" |
| 6 | 6 |
| 7 #import <WebKit/WebKit.h> | 7 #import <WebKit/WebKit.h> |
| 8 | 8 |
| 9 #import <objc/runtime.h> | 9 #import <objc/runtime.h> |
| 10 #include <stddef.h> | 10 #include <stddef.h> |
| (...skipping 729 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 740 // Called when a JavaScript dialog, HTTP authentication dialog or window.open | 740 // Called when a JavaScript dialog, HTTP authentication dialog or window.open |
| 741 // call has been suppressed. | 741 // call has been suppressed. |
| 742 - (void)didSuppressDialog; | 742 - (void)didSuppressDialog; |
| 743 // Returns YES if the navigation action is associated with a main frame request. | 743 // Returns YES if the navigation action is associated with a main frame request. |
| 744 - (BOOL)isMainFrameNavigationAction:(WKNavigationAction*)action; | 744 - (BOOL)isMainFrameNavigationAction:(WKNavigationAction*)action; |
| 745 // Returns whether external URL navigation action should be opened. | 745 // Returns whether external URL navigation action should be opened. |
| 746 - (BOOL)shouldOpenExternalURLForNavigationAction:(WKNavigationAction*)action; | 746 - (BOOL)shouldOpenExternalURLForNavigationAction:(WKNavigationAction*)action; |
| 747 // Updates SSL status for the current navigation item based on the information | 747 // Updates SSL status for the current navigation item based on the information |
| 748 // provided by web view. | 748 // provided by web view. |
| 749 - (void)updateSSLStatusForCurrentNavigationItem; | 749 - (void)updateSSLStatusForCurrentNavigationItem; |
| 750 // Called when SSL status has been updated for the current navigation item. | |
| 751 - (void)didUpdateSSLStatusForCurrentNavigationItem; | |
| 752 // Called when a load ends in an SSL error and certificate chain. | 750 // Called when a load ends in an SSL error and certificate chain. |
| 753 - (void)handleSSLCertError:(NSError*)error; | 751 - (void)handleSSLCertError:(NSError*)error; |
| 754 | 752 |
| 755 // Used in webView:didReceiveAuthenticationChallenge:completionHandler: to | 753 // Used in webView:didReceiveAuthenticationChallenge:completionHandler: to |
| 756 // reply with NSURLSessionAuthChallengeDisposition and credentials. | 754 // reply with NSURLSessionAuthChallengeDisposition and credentials. |
| 757 - (void)processAuthChallenge:(NSURLAuthenticationChallenge*)challenge | 755 - (void)processAuthChallenge:(NSURLAuthenticationChallenge*)challenge |
| 758 forCertAcceptPolicy:(web::CertAcceptPolicy)policy | 756 forCertAcceptPolicy:(web::CertAcceptPolicy)policy |
| 759 certStatus:(net::CertStatus)certStatus | 757 certStatus:(net::CertStatus)certStatus |
| 760 completionHandler:(void (^)(NSURLSessionAuthChallengeDisposition, | 758 completionHandler:(void (^)(NSURLSessionAuthChallengeDisposition, |
| 761 NSURLCredential*))completionHandler; | 759 NSURLCredential*))completionHandler; |
| (...skipping 3276 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4038 } else { | 4036 } else { |
| 4039 trust = web::CreateServerTrustFromChain([_webView certificateChain], host); | 4037 trust = web::CreateServerTrustFromChain([_webView certificateChain], host); |
| 4040 } | 4038 } |
| 4041 | 4039 |
| 4042 [_SSLStatusUpdater updateSSLStatusForNavigationItem:currentNavItem | 4040 [_SSLStatusUpdater updateSSLStatusForNavigationItem:currentNavItem |
| 4043 withCertHost:host | 4041 withCertHost:host |
| 4044 trust:std::move(trust) | 4042 trust:std::move(trust) |
| 4045 hasOnlySecureContent:hasOnlySecureContent]; | 4043 hasOnlySecureContent:hasOnlySecureContent]; |
| 4046 } | 4044 } |
| 4047 | 4045 |
| 4048 - (void)didUpdateSSLStatusForCurrentNavigationItem { | |
| 4049 if ([_delegate respondsToSelector: | |
| 4050 @selector( | |
| 4051 webControllerDidUpdateSSLStatusForCurrentNavigationItem:)]) { | |
| 4052 [_delegate webControllerDidUpdateSSLStatusForCurrentNavigationItem:self]; | |
| 4053 } | |
| 4054 } | |
| 4055 | |
| 4056 - (void)didShowPasswordInputOnHTTP { | 4046 - (void)didShowPasswordInputOnHTTP { |
| 4057 DCHECK(!web::IsOriginSecure(self.webState->GetLastCommittedURL())); | 4047 DCHECK(!web::IsOriginSecure(self.webState->GetLastCommittedURL())); |
| 4058 web::NavigationItem* item = | 4048 web::NavigationItem* item = |
| 4059 self.webState->GetNavigationManager()->GetLastCommittedItem(); | 4049 _webStateImpl->GetNavigationManager()->GetLastCommittedItem(); |
| 4060 item->GetSSL().content_status |= | 4050 item->GetSSL().content_status |= |
| 4061 web::SSLStatus::DISPLAYED_PASSWORD_FIELD_ON_HTTP; | 4051 web::SSLStatus::DISPLAYED_PASSWORD_FIELD_ON_HTTP; |
| 4062 [self didUpdateSSLStatusForCurrentNavigationItem]; | 4052 _webStateImpl->OnVisibleSecurityStateChange(); |
| 4063 } | 4053 } |
| 4064 | 4054 |
| 4065 - (void)didShowCreditCardInputOnHTTP { | 4055 - (void)didShowCreditCardInputOnHTTP { |
| 4066 DCHECK(!web::IsOriginSecure(self.webState->GetLastCommittedURL())); | 4056 DCHECK(!web::IsOriginSecure(self.webState->GetLastCommittedURL())); |
| 4067 web::NavigationItem* item = | 4057 web::NavigationItem* item = |
| 4068 self.webState->GetNavigationManager()->GetLastCommittedItem(); | 4058 _webStateImpl->GetNavigationManager()->GetLastCommittedItem(); |
| 4069 item->GetSSL().content_status |= | 4059 item->GetSSL().content_status |= |
| 4070 web::SSLStatus::DISPLAYED_CREDIT_CARD_FIELD_ON_HTTP; | 4060 web::SSLStatus::DISPLAYED_CREDIT_CARD_FIELD_ON_HTTP; |
| 4071 [self didUpdateSSLStatusForCurrentNavigationItem]; | 4061 _webStateImpl->OnVisibleSecurityStateChange(); |
| 4072 } | 4062 } |
| 4073 | 4063 |
| 4074 - (void)handleSSLCertError:(NSError*)error { | 4064 - (void)handleSSLCertError:(NSError*)error { |
| 4075 CHECK(web::IsWKWebViewSSLCertError(error)); | 4065 CHECK(web::IsWKWebViewSSLCertError(error)); |
| 4076 | 4066 |
| 4077 net::SSLInfo info; | 4067 net::SSLInfo info; |
| 4078 web::GetSSLInfoFromWKWebViewSSLCertError(error, &info); | 4068 web::GetSSLInfoFromWKWebViewSSLCertError(error, &info); |
| 4079 | 4069 |
| 4080 if (!info.cert) { | 4070 if (!info.cert) { |
| 4081 // |info.cert| can be null if certChain in NSError is empty or can not be | 4071 // |info.cert| can be null if certChain in NSError is empty or can not be |
| (...skipping 25 matching lines...) Expand all Loading... |
| 4107 recoverable = error->second.is_recoverable; | 4097 recoverable = error->second.is_recoverable; |
| 4108 info.cert_status = error->second.status; | 4098 info.cert_status = error->second.status; |
| 4109 } | 4099 } |
| 4110 UMA_HISTOGRAM_BOOLEAN("WebController.CertVerificationErrorsCacheHit", | 4100 UMA_HISTOGRAM_BOOLEAN("WebController.CertVerificationErrorsCacheHit", |
| 4111 cacheHit); | 4101 cacheHit); |
| 4112 } | 4102 } |
| 4113 } | 4103 } |
| 4114 | 4104 |
| 4115 // Ask web client if this cert error should be allowed. | 4105 // Ask web client if this cert error should be allowed. |
| 4116 web::GetWebClient()->AllowCertificateError( | 4106 web::GetWebClient()->AllowCertificateError( |
| 4117 self.webState, net::MapCertStatusToNetError(info.cert_status), info, | 4107 _webStateImpl, net::MapCertStatusToNetError(info.cert_status), info, |
| 4118 net::GURLWithNSURL(requestURL), recoverable, | 4108 net::GURLWithNSURL(requestURL), recoverable, |
| 4119 base::BindBlock(^(bool proceed) { | 4109 base::BindBlock(^(bool proceed) { |
| 4120 if (proceed) { | 4110 if (proceed) { |
| 4121 DCHECK(recoverable); | 4111 DCHECK(recoverable); |
| 4122 [_certVerificationController allowCert:leafCert | 4112 [_certVerificationController allowCert:leafCert |
| 4123 forHost:host | 4113 forHost:host |
| 4124 status:info.cert_status]; | 4114 status:info.cert_status]; |
| 4125 [self.sessionController.sessionCertificatePolicyManager | 4115 [self.sessionController.sessionCertificatePolicyManager |
| 4126 registerAllowedCertificate:leafCert | 4116 registerAllowedCertificate:leafCert |
| 4127 forHost:base::SysNSStringToUTF8(host) | 4117 forHost:base::SysNSStringToUTF8(host) |
| 4128 status:info.cert_status]; | 4118 status:info.cert_status]; |
| 4129 [self loadCurrentURL]; | 4119 [self loadCurrentURL]; |
| 4130 } | 4120 } |
| 4131 })); | 4121 })); |
| 4132 | 4122 |
| 4133 [self didUpdateSSLStatusForCurrentNavigationItem]; | 4123 _webStateImpl->OnVisibleSecurityStateChange(); |
| 4134 [self loadCancelled]; | 4124 [self loadCancelled]; |
| 4135 } | 4125 } |
| 4136 | 4126 |
| 4137 - (void)ensureWebViewCreated { | 4127 - (void)ensureWebViewCreated { |
| 4138 WKWebViewConfiguration* config = | 4128 WKWebViewConfiguration* config = |
| 4139 [self webViewConfigurationProvider].GetWebViewConfiguration(); | 4129 [self webViewConfigurationProvider].GetWebViewConfiguration(); |
| 4140 [self ensureWebViewCreatedWithConfiguration:config]; | 4130 [self ensureWebViewCreatedWithConfiguration:config]; |
| 4141 } | 4131 } |
| 4142 | 4132 |
| 4143 - (void)ensureWebViewCreatedWithConfiguration:(WKWebViewConfiguration*)config { | 4133 - (void)ensureWebViewCreatedWithConfiguration:(WKWebViewConfiguration*)config { |
| (...skipping 646 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4790 host:(NSString*)host | 4780 host:(NSString*)host |
| 4791 completionHandler:(StatusQueryHandler)completionHandler { | 4781 completionHandler:(StatusQueryHandler)completionHandler { |
| 4792 [_certVerificationController querySSLStatusForTrust:std::move(trust) | 4782 [_certVerificationController querySSLStatusForTrust:std::move(trust) |
| 4793 host:host | 4783 host:host |
| 4794 completionHandler:completionHandler]; | 4784 completionHandler:completionHandler]; |
| 4795 } | 4785 } |
| 4796 | 4786 |
| 4797 - (void)SSLStatusUpdater:(CRWSSLStatusUpdater*)SSLStatusUpdater | 4787 - (void)SSLStatusUpdater:(CRWSSLStatusUpdater*)SSLStatusUpdater |
| 4798 didChangeSSLStatusForNavigationItem:(web::NavigationItem*)navigationItem { | 4788 didChangeSSLStatusForNavigationItem:(web::NavigationItem*)navigationItem { |
| 4799 web::NavigationItem* lastCommittedNavigationItem = | 4789 web::NavigationItem* lastCommittedNavigationItem = |
| 4800 self.webState->GetNavigationManager()->GetLastCommittedItem(); | 4790 _webStateImpl->GetNavigationManager()->GetLastCommittedItem(); |
| 4801 if (navigationItem == lastCommittedNavigationItem) { | 4791 if (navigationItem == lastCommittedNavigationItem) { |
| 4802 [self didUpdateSSLStatusForCurrentNavigationItem]; | 4792 _webStateImpl->OnVisibleSecurityStateChange(); |
| 4803 } | 4793 } |
| 4804 } | 4794 } |
| 4805 | 4795 |
| 4806 #pragma mark - | 4796 #pragma mark - |
| 4807 #pragma mark CRWWebContextMenuControllerDelegate methods | 4797 #pragma mark CRWWebContextMenuControllerDelegate methods |
| 4808 | 4798 |
| 4809 - (BOOL)webView:(WKWebView*)webView | 4799 - (BOOL)webView:(WKWebView*)webView |
| 4810 handleContextMenu:(const web::ContextMenuParams&)params { | 4800 handleContextMenu:(const web::ContextMenuParams&)params { |
| 4811 DCHECK(webView == _webView); | 4801 DCHECK(webView == _webView); |
| 4812 if (_isBeingDestroyed) { | 4802 if (_isBeingDestroyed) { |
| (...skipping 406 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5219 - (void)simulateLoadRequestWithURL:(const GURL&)URL { | 5209 - (void)simulateLoadRequestWithURL:(const GURL&)URL { |
| 5220 _lastRegisteredRequestURL = URL; | 5210 _lastRegisteredRequestURL = URL; |
| 5221 _loadPhase = web::LOAD_REQUESTED; | 5211 _loadPhase = web::LOAD_REQUESTED; |
| 5222 } | 5212 } |
| 5223 | 5213 |
| 5224 - (NSString*)referrerFromNavigationAction:(WKNavigationAction*)action { | 5214 - (NSString*)referrerFromNavigationAction:(WKNavigationAction*)action { |
| 5225 return [action.request valueForHTTPHeaderField:kReferrerHeaderName]; | 5215 return [action.request valueForHTTPHeaderField:kReferrerHeaderName]; |
| 5226 } | 5216 } |
| 5227 | 5217 |
| 5228 @end | 5218 @end |
| OLD | NEW |