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" | |
22 #include "ios/web/public/web_client.h" | 23 #include "ios/web/public/web_client.h" |
23 #import "ios/web/public/web_state/js/crw_js_injection_manager.h" | 24 #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" | 25 #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" | 26 #import "ios/web/public/web_state/ui/crw_web_view_content_view.h" |
26 #import "ios/web/ui_web_view_util.h" | 27 #import "ios/web/ui_web_view_util.h" |
27 #include "ios/web/web_state/blocked_popup_info.h" | 28 #include "ios/web/web_state/blocked_popup_info.h" |
28 #import "ios/web/web_state/error_translation_util.h" | 29 #import "ios/web/web_state/error_translation_util.h" |
29 #include "ios/web/web_state/frame_info.h" | 30 #include "ios/web/web_state/frame_info.h" |
30 #import "ios/web/web_state/js/crw_js_window_id_manager.h" | 31 #import "ios/web/web_state/js/crw_js_window_id_manager.h" |
31 #import "ios/web/web_state/js/page_script_util.h" | 32 #import "ios/web/web_state/js/page_script_util.h" |
32 #import "ios/web/web_state/ui/crw_web_controller+protected.h" | 33 #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" | 34 #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" | 35 #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" | 36 #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" | 37 #import "ios/web/web_state/ui/wk_web_view_configuration_provider.h" |
37 #import "ios/web/web_state/web_state_impl.h" | 38 #import "ios/web/web_state/web_state_impl.h" |
38 #import "ios/web/web_state/web_view_internal_creation_util.h" | 39 #import "ios/web/web_state/web_view_internal_creation_util.h" |
40 #import "ios/web/web_state/wk_web_view_security_util.h" | |
39 #import "ios/web/webui/crw_web_ui_manager.h" | 41 #import "ios/web/webui/crw_web_ui_manager.h" |
42 #include "net/cert/x509_certificate.h" | |
40 #import "net/base/mac/url_conversions.h" | 43 #import "net/base/mac/url_conversions.h" |
41 #include "url/url_constants.h" | 44 #include "url/url_constants.h" |
42 | 45 |
43 #if !defined(ENABLE_CHROME_NET_STACK_FOR_WKWEBVIEW) | 46 #if !defined(ENABLE_CHROME_NET_STACK_FOR_WKWEBVIEW) |
stuartmorgan
2015/09/04 18:22:32
How about we just go ahead and eliminate this whol
Eugene But (OOO till 7-30)
2015/09/04 18:39:54
Done.
| |
44 #include "ios/web/public/cert_store.h" | 47 #include "ios/web/public/cert_store.h" |
45 #include "ios/web/public/navigation_item.h" | 48 #include "ios/web/public/navigation_item.h" |
46 #include "ios/web/public/ssl_status.h" | 49 #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 #include "net/ssl/ssl_info.h" |
50 #endif | 51 #endif |
51 | 52 |
52 namespace { | 53 namespace { |
53 // Extracts Referer value from WKNavigationAction request header. | 54 // Extracts Referer value from WKNavigationAction request header. |
54 NSString* GetRefererFromNavigationAction(WKNavigationAction* action) { | 55 NSString* GetRefererFromNavigationAction(WKNavigationAction* action) { |
55 return [action.request valueForHTTPHeaderField:@"Referer"]; | 56 return [action.request valueForHTTPHeaderField:@"Referer"]; |
56 } | 57 } |
57 | 58 |
58 NSString* const kScriptMessageName = @"crwebinvoke"; | 59 NSString* const kScriptMessageName = @"crwebinvoke"; |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
128 scoped_ptr<WKNavigationType> _pendingNavigationTypeForMainFrame; | 129 scoped_ptr<WKNavigationType> _pendingNavigationTypeForMainFrame; |
129 | 130 |
130 // Whether the web page is currently performing window.history.pushState or | 131 // Whether the web page is currently performing window.history.pushState or |
131 // window.history.replaceState | 132 // window.history.replaceState |
132 // Set to YES on window.history.willChangeState message. To NO on | 133 // Set to YES on window.history.willChangeState message. To NO on |
133 // window.history.didPushState or window.history.didReplaceState. | 134 // window.history.didPushState or window.history.didReplaceState. |
134 BOOL _changingHistoryState; | 135 BOOL _changingHistoryState; |
135 | 136 |
136 // CRWWebUIManager object for loading WebUI pages. | 137 // CRWWebUIManager object for loading WebUI pages. |
137 base::scoped_nsobject<CRWWebUIManager> _webUIManager; | 138 base::scoped_nsobject<CRWWebUIManager> _webUIManager; |
139 | |
140 // Controller used for certs verification to help with blocking requests with | |
141 // bad SSL cert, presenting SSL interstitials and determining SSL status for | |
142 // Navigation Items. | |
143 base::scoped_nsobject<CRWCertVerificationController> | |
144 _certVerificationController; | |
138 } | 145 } |
139 | 146 |
140 // Response's MIME type of the last known navigation. | 147 // Response's MIME type of the last known navigation. |
141 @property(nonatomic, copy) NSString* documentMIMEType; | 148 @property(nonatomic, copy) NSString* documentMIMEType; |
142 | 149 |
143 // Dictionary where keys are the names of WKWebView properties and values are | 150 // Dictionary where keys are the names of WKWebView properties and values are |
144 // selector names which should be called when a corresponding property has | 151 // selector names which should be called when a corresponding property has |
145 // changed. e.g. @{ @"URL" : @"webViewURLDidChange" } means that | 152 // changed. e.g. @{ @"URL" : @"webViewURLDidChange" } means that |
146 // -[self webViewURLDidChange] must be called every time when WKWebView.URL is | 153 // -[self webViewURLDidChange] must be called every time when WKWebView.URL is |
147 // changed. | 154 // changed. |
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
280 // Called when WKWebView URL has been changed. | 287 // Called when WKWebView URL has been changed. |
281 - (void)webViewURLDidChange; | 288 - (void)webViewURLDidChange; |
282 | 289 |
283 @end | 290 @end |
284 | 291 |
285 @implementation CRWWKWebViewWebController | 292 @implementation CRWWKWebViewWebController |
286 | 293 |
287 #pragma mark CRWWebController public methods | 294 #pragma mark CRWWebController public methods |
288 | 295 |
289 - (instancetype)initWithWebState:(scoped_ptr<web::WebStateImpl>)webState { | 296 - (instancetype)initWithWebState:(scoped_ptr<web::WebStateImpl>)webState { |
290 return [super initWithWebState:webState.Pass()]; | 297 DCHECK(webState); |
298 web::BrowserState* browserState = webState->GetBrowserState(); | |
299 self = [super initWithWebState:webState.Pass()]; | |
300 if (self) { | |
301 _certVerificationController.reset([[CRWCertVerificationController alloc] | |
302 initWithBrowserState:browserState]); | |
303 } | |
304 return self; | |
291 } | 305 } |
292 | 306 |
293 - (BOOL)keyboardDisplayRequiresUserAction { | 307 - (BOOL)keyboardDisplayRequiresUserAction { |
294 // TODO(stuartmorgan): Find out whether YES or NO is correct; see comment | 308 // TODO(stuartmorgan): Find out whether YES or NO is correct; see comment |
295 // in protected header. | 309 // in protected header. |
296 NOTIMPLEMENTED(); | 310 NOTIMPLEMENTED(); |
297 return NO; | 311 return NO; |
298 } | 312 } |
299 | 313 |
300 - (void)setKeyboardDisplayRequiresUserAction:(BOOL)requiresUserAction { | 314 - (void)setKeyboardDisplayRequiresUserAction:(BOOL)requiresUserAction { |
(...skipping 21 matching lines...) Expand all Loading... | |
322 [super terminateNetworkActivity]; | 336 [super terminateNetworkActivity]; |
323 } | 337 } |
324 #endif // #if !defined(ENABLE_CHROME_NET_STACK_FOR_WKWEBVIEW) | 338 #endif // #if !defined(ENABLE_CHROME_NET_STACK_FOR_WKWEBVIEW) |
325 | 339 |
326 - (void)setPageDialogOpenPolicy:(web::PageDialogOpenPolicy)policy { | 340 - (void)setPageDialogOpenPolicy:(web::PageDialogOpenPolicy)policy { |
327 // TODO(eugenebut): implement dialogs/windows suppression using | 341 // TODO(eugenebut): implement dialogs/windows suppression using |
328 // WKNavigationDelegate methods where possible. | 342 // WKNavigationDelegate methods where possible. |
329 [super setPageDialogOpenPolicy:policy]; | 343 [super setPageDialogOpenPolicy:policy]; |
330 } | 344 } |
331 | 345 |
346 - (void)close { | |
347 [_certVerificationController shutDown]; | |
348 [super close]; | |
349 } | |
350 | |
332 #pragma mark - | 351 #pragma mark - |
333 #pragma mark Testing-Only Methods | 352 #pragma mark Testing-Only Methods |
334 | 353 |
335 - (void)injectWebViewContentView:(CRWWebViewContentView*)webViewContentView { | 354 - (void)injectWebViewContentView:(CRWWebViewContentView*)webViewContentView { |
336 [super injectWebViewContentView:webViewContentView]; | 355 [super injectWebViewContentView:webViewContentView]; |
337 [self setWebView:static_cast<WKWebView*>(webViewContentView.webView)]; | 356 [self setWebView:static_cast<WKWebView*>(webViewContentView.webView)]; |
338 } | 357 } |
339 | 358 |
340 #pragma mark - Protected property implementations | 359 #pragma mark - Protected property implementations |
341 | 360 |
(...skipping 976 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1318 withError:(NSError *)error { | 1337 withError:(NSError *)error { |
1319 [self handleLoadError:WKWebViewErrorWithSource(error, NAVIGATION) | 1338 [self handleLoadError:WKWebViewErrorWithSource(error, NAVIGATION) |
1320 inMainFrame:YES]; | 1339 inMainFrame:YES]; |
1321 } | 1340 } |
1322 | 1341 |
1323 - (void)webView:(WKWebView *)webView | 1342 - (void)webView:(WKWebView *)webView |
1324 didReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge | 1343 didReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge |
1325 completionHandler: | 1344 completionHandler: |
1326 (void (^)(NSURLSessionAuthChallengeDisposition disposition, | 1345 (void (^)(NSURLSessionAuthChallengeDisposition disposition, |
1327 NSURLCredential *credential))completionHandler { | 1346 NSURLCredential *credential))completionHandler { |
1328 NOTIMPLEMENTED(); | 1347 if (![challenge.protectionSpace.authenticationMethod |
1329 completionHandler(NSURLSessionAuthChallengeRejectProtectionSpace, nil); | 1348 isEqual:NSURLAuthenticationMethodServerTrust]) { |
1349 completionHandler(NSURLSessionAuthChallengePerformDefaultHandling, nil); | |
1350 return; | |
1351 } | |
1352 | |
1353 SecTrustRef trust = challenge.protectionSpace.serverTrust; | |
1354 scoped_refptr<net::X509Certificate> cert = web::CreateCertFromTrust(trust); | |
1355 [_certVerificationController | |
1356 decidePolicyForCert:cert | |
1357 host:challenge.protectionSpace.host | |
1358 completionHandler:^(web::CertAcceptPolicy policy, | |
1359 net::CertStatus status) { | |
1360 completionHandler(NSURLSessionAuthChallengeRejectProtectionSpace, | |
1361 nil); | |
1362 }]; | |
1330 } | 1363 } |
1331 | 1364 |
1332 - (void)webViewWebContentProcessDidTerminate:(WKWebView*)webView { | 1365 - (void)webViewWebContentProcessDidTerminate:(WKWebView*)webView { |
1333 [self webViewWebProcessDidCrash]; | 1366 [self webViewWebProcessDidCrash]; |
1334 } | 1367 } |
1335 | 1368 |
1336 #pragma mark WKUIDelegate Methods | 1369 #pragma mark WKUIDelegate Methods |
1337 | 1370 |
1338 - (WKWebView*)webView:(WKWebView*)webView | 1371 - (WKWebView*)webView:(WKWebView*)webView |
1339 createWebViewWithConfiguration:(WKWebViewConfiguration*)configuration | 1372 createWebViewWithConfiguration:(WKWebViewConfiguration*)configuration |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1418 placeholderText:defaultText | 1451 placeholderText:defaultText |
1419 requestURL: | 1452 requestURL: |
1420 net::GURLWithNSURL(frame.request.URL) | 1453 net::GURLWithNSURL(frame.request.URL) |
1421 completionHandler:completionHandler]; | 1454 completionHandler:completionHandler]; |
1422 } else if (completionHandler) { | 1455 } else if (completionHandler) { |
1423 completionHandler(nil); | 1456 completionHandler(nil); |
1424 } | 1457 } |
1425 } | 1458 } |
1426 | 1459 |
1427 @end | 1460 @end |
OLD | NEW |