Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(515)

Side by Side Diff: ios/web/web_state/ui/crw_wk_web_view_web_controller.mm

Issue 1230033005: WKWebView: Added cert verification API to web controller. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Updated comment (s/used/user); Created 5 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « ios/web/public/test/test_browser_state.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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"
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
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
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
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
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
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
OLDNEW
« no previous file with comments | « ios/web/public/test/test_browser_state.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698