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/metrics/histogram_macros.h" | |
14 #include "base/strings/sys_string_conversions.h" | 15 #include "base/strings/sys_string_conversions.h" |
15 #include "base/values.h" | 16 #include "base/values.h" |
16 #import "ios/net/http_response_headers_util.h" | 17 #import "ios/net/http_response_headers_util.h" |
17 #import "ios/web/crw_network_activity_indicator_manager.h" | 18 #import "ios/web/crw_network_activity_indicator_manager.h" |
18 #import "ios/web/navigation/crw_session_controller.h" | 19 #import "ios/web/navigation/crw_session_controller.h" |
19 #import "ios/web/navigation/crw_session_entry.h" | 20 #import "ios/web/navigation/crw_session_entry.h" |
20 #include "ios/web/navigation/navigation_item_impl.h" | 21 #include "ios/web/navigation/navigation_item_impl.h" |
21 #include "ios/web/navigation/web_load_params.h" | 22 #include "ios/web/navigation/web_load_params.h" |
22 #import "ios/web/net/crw_cert_verification_controller.h" | 23 #import "ios/web/net/crw_cert_verification_controller.h" |
23 #include "ios/web/public/cert_store.h" | 24 #include "ios/web/public/cert_store.h" |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
75 userInfo:userInfo]; | 76 userInfo:userInfo]; |
76 } | 77 } |
77 WKWebViewErrorSource WKWebViewErrorSourceFromError(NSError* error) { | 78 WKWebViewErrorSource WKWebViewErrorSourceFromError(NSError* error) { |
78 DCHECK(error); | 79 DCHECK(error); |
79 return static_cast<WKWebViewErrorSource>( | 80 return static_cast<WKWebViewErrorSource>( |
80 [error.userInfo[kWKWebViewErrorSourceKey] integerValue]); | 81 [error.userInfo[kWKWebViewErrorSourceKey] integerValue]); |
81 } | 82 } |
82 | 83 |
83 } // namespace | 84 } // namespace |
84 | 85 |
86 #if !defined(__IPHONE_9_0) | |
stuartmorgan
2015/10/06 22:02:36
You're missing:
|| __IPHONE_OS_VERSION_MAX_ALLOWE
Eugene But (OOO till 7-30)
2015/10/07 15:27:13
Done.
| |
87 // Predeclare iOS9 API so calls are compiled on iOS8 bots. | |
88 // TODO(eugenebut): cleanup this (crbug.com/523365). | |
89 @interface WKWebView (CRWIOS9API) | |
90 @property(nonatomic, readonly, copy) NSArray* certificateChain; | |
91 @end | |
92 #endif | |
93 | |
85 @interface CRWWKWebViewWebController () <WKNavigationDelegate, | 94 @interface CRWWKWebViewWebController () <WKNavigationDelegate, |
86 WKScriptMessageHandler, | 95 WKScriptMessageHandler, |
87 WKUIDelegate> { | 96 WKUIDelegate> { |
88 // The WKWebView managed by this instance. | 97 // The WKWebView managed by this instance. |
89 base::scoped_nsobject<WKWebView> _wkWebView; | 98 base::scoped_nsobject<WKWebView> _wkWebView; |
90 | 99 |
91 // The Watch Dog that detects and reports WKWebView crashes. | 100 // The Watch Dog that detects and reports WKWebView crashes. |
92 base::scoped_nsobject<CRWWKWebViewCrashDetector> _crashDetector; | 101 base::scoped_nsobject<CRWWKWebViewCrashDetector> _crashDetector; |
93 | 102 |
94 // The actual URL of the document object (i.e., the last committed URL). | 103 // The actual URL of the document object (i.e., the last committed URL). |
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
243 // Called when a load ends in an SSL error and certificate chain. | 252 // Called when a load ends in an SSL error and certificate chain. |
244 - (void)handleSSLCertError:(NSError*)error; | 253 - (void)handleSSLCertError:(NSError*)error; |
245 #endif | 254 #endif |
246 | 255 |
247 // Adds an activity indicator tasks for this web controller. | 256 // Adds an activity indicator tasks for this web controller. |
248 - (void)addActivityIndicatorTask; | 257 - (void)addActivityIndicatorTask; |
249 | 258 |
250 // Clears all activity indicator tasks for this web controller. | 259 // Clears all activity indicator tasks for this web controller. |
251 - (void)clearActivityIndicatorTasks; | 260 - (void)clearActivityIndicatorTasks; |
252 | 261 |
262 // Obtains SSL status from given |certChain| and updates navigation items with | |
263 // given |certID| and |host|. | |
264 - (void)updateSSLStatusForNavigationItemsWithCertID:(int)certID | |
265 host:(NSString*)host | |
266 usingCertChain:(NSArray*)certChain; | |
267 | |
253 #if !defined(ENABLE_CHROME_NET_STACK_FOR_WKWEBVIEW) | 268 #if !defined(ENABLE_CHROME_NET_STACK_FOR_WKWEBVIEW) |
254 // Updates SSL status for the current navigation item based on the information | 269 // Updates SSL status for the current navigation item based on the information |
255 // provided by web view. | 270 // provided by web view. |
256 - (void)updateSSLStatusForCurrentNavigationItem; | 271 - (void)updateSSLStatusForCurrentNavigationItem; |
257 #endif | 272 #endif |
258 | 273 |
274 // Reports "WebController.WKWebViewHasCertForSecureConnection" UMA. | |
275 - (void)reportHasCertForSecureConnectionUMAWithValue:(bool)value; | |
276 | |
259 // Registers load request with empty referrer and link or client redirect | 277 // Registers load request with empty referrer and link or client redirect |
260 // transition based on user interaction state. | 278 // transition based on user interaction state. |
261 - (void)registerLoadRequest:(const GURL&)url; | 279 - (void)registerLoadRequest:(const GURL&)url; |
262 | 280 |
263 // Called when a non-document-changing URL change occurs. Updates the | 281 // Called when a non-document-changing URL change occurs. Updates the |
264 // _documentURL, and informs the superclass of the change. | 282 // _documentURL, and informs the superclass of the change. |
265 - (void)URLDidChangeWithoutDocumentChange:(const GURL&)URL; | 283 - (void)URLDidChangeWithoutDocumentChange:(const GURL&)URL; |
266 | 284 |
267 // Returns new autoreleased instance of WKUserContentController which has | 285 // Returns new autoreleased instance of WKUserContentController which has |
268 // early page script. | 286 // early page script. |
(...skipping 588 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
857 - (void)addActivityIndicatorTask { | 875 - (void)addActivityIndicatorTask { |
858 [[CRWNetworkActivityIndicatorManager sharedInstance] | 876 [[CRWNetworkActivityIndicatorManager sharedInstance] |
859 startNetworkTaskForGroup:[self activityIndicatorGroupID]]; | 877 startNetworkTaskForGroup:[self activityIndicatorGroupID]]; |
860 } | 878 } |
861 | 879 |
862 - (void)clearActivityIndicatorTasks { | 880 - (void)clearActivityIndicatorTasks { |
863 [[CRWNetworkActivityIndicatorManager sharedInstance] | 881 [[CRWNetworkActivityIndicatorManager sharedInstance] |
864 clearNetworkTasksForGroup:[self activityIndicatorGroupID]]; | 882 clearNetworkTasksForGroup:[self activityIndicatorGroupID]]; |
865 } | 883 } |
866 | 884 |
885 - (void)updateSSLStatusForNavigationItemsWithCertID:(int)certID | |
886 host:(NSString*)host | |
887 usingCertChain:(NSArray*)certChain { | |
888 base::WeakNSObject<CRWWKWebViewWebController> weakSelf(self); | |
889 void (^SSLStatusResponse)(web::SecurityStyle, net::CertStatus) = ^( | |
890 web::SecurityStyle style, net::CertStatus certStatus) { | |
891 base::scoped_nsobject<CRWWKWebViewWebController> strongSelf( | |
892 [weakSelf retain]); | |
893 if (!strongSelf || [strongSelf isBeingDestroyed]) { | |
894 return; | |
895 } | |
896 | |
897 web::NavigationManager* navigationManager = | |
898 [strongSelf webStateImpl]->GetNavigationManager(); | |
899 int currentItemIndex = navigationManager->GetCurrentEntryIndex(); | |
stuartmorgan
2015/10/06 22:02:36
Are we guaranteed that the lookup can't be for a p
Eugene But (OOO till 7-30)
2015/10/07 15:27:13
There is no need to do a lookup for a pending item
| |
900 | |
901 bool updatedCurrentItem = false; | |
902 std::string GURLHost = base::SysNSStringToUTF8(host); | |
903 for (int i = 0; i < navigationManager->GetEntryCount(); i++) { | |
904 web::NavigationItem* item = navigationManager->GetItemAtIndex(i); | |
905 web::SSLStatus& SSLStatus = item->GetSSL(); | |
906 if (SSLStatus.cert_id == certID && item->GetURL().host() == GURLHost) { | |
907 web::SSLStatus previousSSLStatus = item->GetSSL(); | |
908 SSLStatus.cert_status = certStatus; | |
909 SSLStatus.security_style = style; | |
910 if (currentItemIndex == i && !previousSSLStatus.Equals(SSLStatus)) { | |
911 updatedCurrentItem = true; | |
912 } | |
913 } | |
914 } | |
915 | |
916 if (updatedCurrentItem) { | |
917 [strongSelf didUpdateSSLStatusForCurrentNavigationItem]; | |
918 } | |
919 }; | |
920 | |
921 [_certVerificationController | |
922 querySSLStatusForTrust:web::CreateServerTrustFromChain(certChain, host) | |
923 host:host | |
924 completionHandler:SSLStatusResponse]; | |
925 } | |
926 | |
867 #if !defined(ENABLE_CHROME_NET_STACK_FOR_WKWEBVIEW) | 927 #if !defined(ENABLE_CHROME_NET_STACK_FOR_WKWEBVIEW) |
928 | |
868 - (void)updateSSLStatusForCurrentNavigationItem { | 929 - (void)updateSSLStatusForCurrentNavigationItem { |
869 if ([self isBeingDestroyed]) | 930 if ([self isBeingDestroyed]) |
870 return; | 931 return; |
871 | 932 |
872 DCHECK(self.webStateImpl); | |
873 web::NavigationItem* item = | 933 web::NavigationItem* item = |
874 self.webStateImpl->GetNavigationManagerImpl().GetLastCommittedItem(); | 934 self.webStateImpl->GetNavigationManagerImpl().GetLastCommittedItem(); |
875 if (!item) | 935 if (!item) |
876 return; | 936 return; |
877 | 937 |
878 web::SSLStatus previousSSLStatus = item->GetSSL(); | 938 web::SSLStatus previousSSLStatus = item->GetSSL(); |
879 web::SSLStatus& SSLStatus = item->GetSSL(); | 939 web::SSLStatus& SSLStatus = item->GetSSL(); |
880 if (item->GetURL().SchemeIsCryptographic()) { | |
881 // TODO(eugenebut): Do not set security style to authenticated once | |
882 // proceeding with bad ssl cert is implemented. | |
883 SSLStatus.security_style = web::SECURITY_STYLE_AUTHENTICATED; | |
884 SSLStatus.content_status = [_wkWebView hasOnlySecureContent] | |
885 ? web::SSLStatus::NORMAL_CONTENT | |
886 : web::SSLStatus::DISPLAYED_INSECURE_CONTENT; | |
887 | 940 |
888 if (base::ios::IsRunningOnIOS9OrLater()) { | 941 // Starting from iOS9 WKWebView blocks active mixed content, so if |
889 scoped_refptr<net::X509Certificate> cert(web::CreateCertFromChain( | 942 // |hasOnlySecureContent| returns NO it means passive content. |
890 [_wkWebView performSelector:@selector(certificateChain)])); | 943 // On iOS8 there is no way to determine if web view has active mixed content. |
891 if (cert) { | 944 SSLStatus.content_status = [_wkWebView hasOnlySecureContent] |
892 SSLStatus.cert_id = web::CertStore::GetInstance()->StoreCert( | 945 ? web::SSLStatus::NORMAL_CONTENT |
893 cert.get(), self.certGroupID); | 946 : web::SSLStatus::DISPLAYED_INSECURE_CONTENT; |
894 } else { | 947 |
895 SSLStatus.security_style = web::SECURITY_STYLE_UNAUTHENTICATED; | 948 // Retrieve top level frame certificate. |
stuartmorgan
2015/10/06 22:02:36
Since the innermost code in the block is updating
Eugene But (OOO till 7-30)
2015/10/07 15:27:13
Updated comment. I can't really factor much of the
| |
896 SSLStatus.cert_id = 0; | 949 scoped_refptr<net::X509Certificate> cert; |
950 if (base::ios::IsRunningOnIOS9OrLater() && | |
951 item->GetURL().SchemeIsCryptographic()) { | |
952 NSArray* chain = [_wkWebView certificateChain]; | |
953 cert = web::CreateCertFromChain(chain); | |
954 if (cert) { | |
955 [self reportHasCertForSecureConnectionUMAWithValue:true]; | |
956 int oldCertID = SSLStatus.cert_id; | |
957 SSLStatus.cert_id = web::CertStore::GetInstance()->StoreCert( | |
958 cert.get(), self.certGroupID); | |
959 NSString* host = [_wkWebView URL].host; | |
stuartmorgan
2015/10/06 22:02:36
Are you sure you want the raw web view URL, rather
Eugene But (OOO till 7-30)
2015/10/07 15:27:13
I wanted to avoid std::string -> NSString conversi
| |
960 if (oldCertID != SSLStatus.cert_id || | |
961 item->GetURL().host() != base::SysNSStringToUTF8(host)) { | |
962 [self updateSSLStatusForNavigationItemsWithCertID:SSLStatus.cert_id | |
963 host:host | |
964 usingCertChain:chain]; | |
897 } | 965 } |
898 } | 966 } |
899 } else { | 967 } |
900 SSLStatus.security_style = web::SECURITY_STYLE_UNAUTHENTICATED; | 968 |
969 if (!cert) { | |
901 SSLStatus.cert_id = 0; | 970 SSLStatus.cert_id = 0; |
971 if (!item->GetURL().SchemeIsCryptographic()) { | |
972 // HTTP or other non-secure connection. | |
973 SSLStatus.security_style = web::SECURITY_STYLE_UNAUTHENTICATED; | |
974 } else if (base::ios::IsRunningOnIOS9OrLater()) { | |
975 // HTTPS, iOS9 and no certificate (this use-case has not been observed). | |
976 [self reportHasCertForSecureConnectionUMAWithValue:false]; | |
977 SSLStatus.security_style = web::SECURITY_STYLE_UNKNOWN; | |
978 } else { | |
979 // HTTPS, iOS8. | |
980 // iOS8 cannot load unauthenticated HTTPS content. | |
981 SSLStatus.security_style = web::SECURITY_STYLE_AUTHENTICATED; | |
982 } | |
902 } | 983 } |
903 | 984 |
904 if (!previousSSLStatus.Equals(SSLStatus)) { | 985 if (!previousSSLStatus.Equals(SSLStatus)) { |
905 [self didUpdateSSLStatusForCurrentNavigationItem]; | 986 [self didUpdateSSLStatusForCurrentNavigationItem]; |
906 } | 987 } |
907 } | 988 } |
989 | |
990 - (void)reportHasCertForSecureConnectionUMAWithValue:(bool)value { | |
991 UMA_HISTOGRAM_BOOLEAN("WebController.WKWebViewHasCertForSecureConnection", | |
992 value); | |
993 } | |
994 | |
908 #endif // !defined(ENABLE_CHROME_NET_STACK_FOR_WKWEBVIEW) | 995 #endif // !defined(ENABLE_CHROME_NET_STACK_FOR_WKWEBVIEW) |
909 | 996 |
910 - (void)registerLoadRequest:(const GURL&)url { | 997 - (void)registerLoadRequest:(const GURL&)url { |
911 // If load request is registered via WKWebViewWebController, assume transition | 998 // If load request is registered via WKWebViewWebController, assume transition |
912 // is link or client redirect as other transitions will already be registered | 999 // is link or client redirect as other transitions will already be registered |
913 // by web controller or delegates. | 1000 // by web controller or delegates. |
914 // TODO(stuartmorgan): Remove guesswork and replace with information from | 1001 // TODO(stuartmorgan): Remove guesswork and replace with information from |
915 // decidePolicyForNavigationAction:. | 1002 // decidePolicyForNavigationAction:. |
916 ui::PageTransition transition = self.userInteractionRegistered | 1003 ui::PageTransition transition = self.userInteractionRegistered |
917 ? ui::PAGE_TRANSITION_LINK | 1004 ? ui::PAGE_TRANSITION_LINK |
(...skipping 570 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1488 placeholderText:defaultText | 1575 placeholderText:defaultText |
1489 requestURL: | 1576 requestURL: |
1490 net::GURLWithNSURL(frame.request.URL) | 1577 net::GURLWithNSURL(frame.request.URL) |
1491 completionHandler:completionHandler]; | 1578 completionHandler:completionHandler]; |
1492 } else if (completionHandler) { | 1579 } else if (completionHandler) { |
1493 completionHandler(nil); | 1580 completionHandler(nil); |
1494 } | 1581 } |
1495 } | 1582 } |
1496 | 1583 |
1497 @end | 1584 @end |
OLD | NEW |