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/web_client.h" | 22 #include "ios/web/public/web_client.h" |
24 #import "ios/web/public/web_state/js/crw_js_injection_manager.h" | 23 #import "ios/web/public/web_state/js/crw_js_injection_manager.h" |
25 #import "ios/web/public/web_state/ui/crw_native_content_provider.h" | 24 #import "ios/web/public/web_state/ui/crw_native_content_provider.h" |
26 #import "ios/web/public/web_state/ui/crw_web_view_content_view.h" | 25 #import "ios/web/public/web_state/ui/crw_web_view_content_view.h" |
27 #import "ios/web/ui_web_view_util.h" | 26 #import "ios/web/ui_web_view_util.h" |
28 #include "ios/web/web_state/blocked_popup_info.h" | 27 #include "ios/web/web_state/blocked_popup_info.h" |
29 #import "ios/web/web_state/error_translation_util.h" | 28 #import "ios/web/web_state/error_translation_util.h" |
30 #include "ios/web/web_state/frame_info.h" | 29 #include "ios/web/web_state/frame_info.h" |
31 #import "ios/web/web_state/js/crw_js_window_id_manager.h" | 30 #import "ios/web/web_state/js/crw_js_window_id_manager.h" |
32 #import "ios/web/web_state/js/page_script_util.h" | 31 #import "ios/web/web_state/js/page_script_util.h" |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
129 scoped_ptr<WKNavigationType> _pendingNavigationTypeForMainFrame; | 128 scoped_ptr<WKNavigationType> _pendingNavigationTypeForMainFrame; |
130 | 129 |
131 // Whether the web page is currently performing window.history.pushState or | 130 // Whether the web page is currently performing window.history.pushState or |
132 // window.history.replaceState | 131 // window.history.replaceState |
133 // Set to YES on window.history.willChangeState message. To NO on | 132 // Set to YES on window.history.willChangeState message. To NO on |
134 // window.history.didPushState or window.history.didReplaceState. | 133 // window.history.didPushState or window.history.didReplaceState. |
135 BOOL _changingHistoryState; | 134 BOOL _changingHistoryState; |
136 | 135 |
137 // CRWWebUIManager object for loading WebUI pages. | 136 // CRWWebUIManager object for loading WebUI pages. |
138 base::scoped_nsobject<CRWWebUIManager> _webUIManager; | 137 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; | |
145 } | 138 } |
146 | 139 |
147 // Response's MIME type of the last known navigation. | 140 // Response's MIME type of the last known navigation. |
148 @property(nonatomic, copy) NSString* documentMIMEType; | 141 @property(nonatomic, copy) NSString* documentMIMEType; |
149 | 142 |
150 // Dictionary where keys are the names of WKWebView properties and values are | 143 // Dictionary where keys are the names of WKWebView properties and values are |
151 // selector names which should be called when a corresponding property has | 144 // selector names which should be called when a corresponding property has |
152 // changed. e.g. @{ @"URL" : @"webViewURLDidChange" } means that | 145 // changed. e.g. @{ @"URL" : @"webViewURLDidChange" } means that |
153 // -[self webViewURLDidChange] must be called every time when WKWebView.URL is | 146 // -[self webViewURLDidChange] must be called every time when WKWebView.URL is |
154 // changed. | 147 // changed. |
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
287 // Called when WKWebView URL has been changed. | 280 // Called when WKWebView URL has been changed. |
288 - (void)webViewURLDidChange; | 281 - (void)webViewURLDidChange; |
289 | 282 |
290 @end | 283 @end |
291 | 284 |
292 @implementation CRWWKWebViewWebController | 285 @implementation CRWWKWebViewWebController |
293 | 286 |
294 #pragma mark CRWWebController public methods | 287 #pragma mark CRWWebController public methods |
295 | 288 |
296 - (instancetype)initWithWebState:(scoped_ptr<web::WebStateImpl>)webState { | 289 - (instancetype)initWithWebState:(scoped_ptr<web::WebStateImpl>)webState { |
297 DCHECK(webState); | 290 return [super initWithWebState:webState.Pass()]; |
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; | |
305 } | 291 } |
306 | 292 |
307 - (BOOL)keyboardDisplayRequiresUserAction { | 293 - (BOOL)keyboardDisplayRequiresUserAction { |
308 // TODO(stuartmorgan): Find out whether YES or NO is correct; see comment | 294 // TODO(stuartmorgan): Find out whether YES or NO is correct; see comment |
309 // in protected header. | 295 // in protected header. |
310 NOTIMPLEMENTED(); | 296 NOTIMPLEMENTED(); |
311 return NO; | 297 return NO; |
312 } | 298 } |
313 | 299 |
314 - (void)setKeyboardDisplayRequiresUserAction:(BOOL)requiresUserAction { | 300 - (void)setKeyboardDisplayRequiresUserAction:(BOOL)requiresUserAction { |
(...skipping 21 matching lines...) Expand all Loading... |
336 [super terminateNetworkActivity]; | 322 [super terminateNetworkActivity]; |
337 } | 323 } |
338 #endif // #if !defined(ENABLE_CHROME_NET_STACK_FOR_WKWEBVIEW) | 324 #endif // #if !defined(ENABLE_CHROME_NET_STACK_FOR_WKWEBVIEW) |
339 | 325 |
340 - (void)setPageDialogOpenPolicy:(web::PageDialogOpenPolicy)policy { | 326 - (void)setPageDialogOpenPolicy:(web::PageDialogOpenPolicy)policy { |
341 // TODO(eugenebut): implement dialogs/windows suppression using | 327 // TODO(eugenebut): implement dialogs/windows suppression using |
342 // WKNavigationDelegate methods where possible. | 328 // WKNavigationDelegate methods where possible. |
343 [super setPageDialogOpenPolicy:policy]; | 329 [super setPageDialogOpenPolicy:policy]; |
344 } | 330 } |
345 | 331 |
346 - (void)close { | |
347 [_certVerificationController shutDown]; | |
348 [super close]; | |
349 } | |
350 | |
351 #pragma mark - | 332 #pragma mark - |
352 #pragma mark Testing-Only Methods | 333 #pragma mark Testing-Only Methods |
353 | 334 |
354 - (void)injectWebViewContentView:(CRWWebViewContentView*)webViewContentView { | 335 - (void)injectWebViewContentView:(CRWWebViewContentView*)webViewContentView { |
355 [super injectWebViewContentView:webViewContentView]; | 336 [super injectWebViewContentView:webViewContentView]; |
356 [self setWebView:static_cast<WKWebView*>(webViewContentView.webView)]; | 337 [self setWebView:static_cast<WKWebView*>(webViewContentView.webView)]; |
357 } | 338 } |
358 | 339 |
359 #pragma mark - Protected property implementations | 340 #pragma mark - Protected property implementations |
360 | 341 |
(...skipping 976 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1337 withError:(NSError *)error { | 1318 withError:(NSError *)error { |
1338 [self handleLoadError:WKWebViewErrorWithSource(error, NAVIGATION) | 1319 [self handleLoadError:WKWebViewErrorWithSource(error, NAVIGATION) |
1339 inMainFrame:YES]; | 1320 inMainFrame:YES]; |
1340 } | 1321 } |
1341 | 1322 |
1342 - (void)webView:(WKWebView *)webView | 1323 - (void)webView:(WKWebView *)webView |
1343 didReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge | 1324 didReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge |
1344 completionHandler: | 1325 completionHandler: |
1345 (void (^)(NSURLSessionAuthChallengeDisposition disposition, | 1326 (void (^)(NSURLSessionAuthChallengeDisposition disposition, |
1346 NSURLCredential *credential))completionHandler { | 1327 NSURLCredential *credential))completionHandler { |
1347 if (![challenge.protectionSpace.authenticationMethod | 1328 NOTIMPLEMENTED(); |
1348 isEqual:NSURLAuthenticationMethodServerTrust]) { | 1329 completionHandler(NSURLSessionAuthChallengeRejectProtectionSpace, nil); |
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 }]; | |
1363 } | 1330 } |
1364 | 1331 |
1365 - (void)webViewWebContentProcessDidTerminate:(WKWebView*)webView { | 1332 - (void)webViewWebContentProcessDidTerminate:(WKWebView*)webView { |
1366 [self webViewWebProcessDidCrash]; | 1333 [self webViewWebProcessDidCrash]; |
1367 } | 1334 } |
1368 | 1335 |
1369 #pragma mark WKUIDelegate Methods | 1336 #pragma mark WKUIDelegate Methods |
1370 | 1337 |
1371 - (WKWebView*)webView:(WKWebView*)webView | 1338 - (WKWebView*)webView:(WKWebView*)webView |
1372 createWebViewWithConfiguration:(WKWebViewConfiguration*)configuration | 1339 createWebViewWithConfiguration:(WKWebViewConfiguration*)configuration |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1451 placeholderText:defaultText | 1418 placeholderText:defaultText |
1452 requestURL: | 1419 requestURL: |
1453 net::GURLWithNSURL(frame.request.URL) | 1420 net::GURLWithNSURL(frame.request.URL) |
1454 completionHandler:completionHandler]; | 1421 completionHandler:completionHandler]; |
1455 } else if (completionHandler) { | 1422 } else if (completionHandler) { |
1456 completionHandler(nil); | 1423 completionHandler(nil); |
1457 } | 1424 } |
1458 } | 1425 } |
1459 | 1426 |
1460 @end | 1427 @end |
OLD | NEW |