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 719 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
730 - (void)setNativeController:(id<CRWNativeContent>)nativeController; | 730 - (void)setNativeController:(id<CRWNativeContent>)nativeController; |
731 // Returns whether |url| should be opened. | 731 // Returns whether |url| should be opened. |
732 - (BOOL)shouldOpenURL:(const GURL&)url | 732 - (BOOL)shouldOpenURL:(const GURL&)url |
733 mainDocumentURL:(const GURL&)mainDocumentURL | 733 mainDocumentURL:(const GURL&)mainDocumentURL |
734 linkClicked:(BOOL)linkClicked; | 734 linkClicked:(BOOL)linkClicked; |
735 // Called when |URL| needs to be opened in a matching native app. | 735 // Called when |URL| needs to be opened in a matching native app. |
736 // Returns YES if the url was succesfully opened in the native app. | 736 // Returns YES if the url was succesfully opened in the native app. |
737 - (BOOL)urlTriggersNativeAppLaunch:(const GURL&)URL | 737 - (BOOL)urlTriggersNativeAppLaunch:(const GURL&)URL |
738 sourceURL:(const GURL&)sourceURL | 738 sourceURL:(const GURL&)sourceURL |
739 linkActivatedNavigation:(BOOL)linkActivatedNavigation; | 739 linkActivatedNavigation:(BOOL)linkActivatedNavigation; |
740 // Called when a JavaScript dialog, HTTP authentication dialog or window.open | |
741 // call has been suppressed. | |
742 - (void)didSuppressDialog; | |
743 // Returns YES if the navigation action is associated with a main frame request. | 740 // Returns YES if the navigation action is associated with a main frame request. |
744 - (BOOL)isMainFrameNavigationAction:(WKNavigationAction*)action; | 741 - (BOOL)isMainFrameNavigationAction:(WKNavigationAction*)action; |
745 // Returns whether external URL navigation action should be opened. | 742 // Returns whether external URL navigation action should be opened. |
746 - (BOOL)shouldOpenExternalURLForNavigationAction:(WKNavigationAction*)action; | 743 - (BOOL)shouldOpenExternalURLForNavigationAction:(WKNavigationAction*)action; |
747 // Updates SSL status for the current navigation item based on the information | 744 // Updates SSL status for the current navigation item based on the information |
748 // provided by web view. | 745 // provided by web view. |
749 - (void)updateSSLStatusForCurrentNavigationItem; | 746 - (void)updateSSLStatusForCurrentNavigationItem; |
750 // Called when a load ends in an SSL error and certificate chain. | 747 // Called when a load ends in an SSL error and certificate chain. |
751 - (void)handleSSLCertError:(NSError*)error; | 748 - (void)handleSSLCertError:(NSError*)error; |
752 | 749 |
(...skipping 1850 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2603 DLOG(WARNING) << "JS message parameter not found: origin"; | 2600 DLOG(WARNING) << "JS message parameter not found: origin"; |
2604 return NO; | 2601 return NO; |
2605 } | 2602 } |
2606 | 2603 |
2607 DVLOG(0) << origin << " [" << method << "] " << consoleMessage; | 2604 DVLOG(0) << origin << " [" << method << "] " << consoleMessage; |
2608 return YES; | 2605 return YES; |
2609 } | 2606 } |
2610 | 2607 |
2611 - (BOOL)handleGeolocationDialogSuppressedMessage:(base::DictionaryValue*)message | 2608 - (BOOL)handleGeolocationDialogSuppressedMessage:(base::DictionaryValue*)message |
2612 context:(NSDictionary*)context { | 2609 context:(NSDictionary*)context { |
2613 [self didSuppressDialog]; | 2610 _webStateImpl->OnDialogSuppressed(); |
2614 return YES; | 2611 return YES; |
2615 } | 2612 } |
2616 | 2613 |
2617 - (BOOL)handleDocumentFaviconsMessage:(base::DictionaryValue*)message | 2614 - (BOOL)handleDocumentFaviconsMessage:(base::DictionaryValue*)message |
2618 context:(NSDictionary*)context { | 2615 context:(NSDictionary*)context { |
2619 base::ListValue* favicons = nullptr; | 2616 base::ListValue* favicons = nullptr; |
2620 if (!message->GetList("favicons", &favicons)) { | 2617 if (!message->GetList("favicons", &favicons)) { |
2621 DLOG(WARNING) << "JS message parameter not found: favicons"; | 2618 DLOG(WARNING) << "JS message parameter not found: favicons"; |
2622 return NO; | 2619 return NO; |
2623 } | 2620 } |
(...skipping 770 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3394 completionHandler: | 3391 completionHandler: |
3395 (void (^)(NSURLSessionAuthChallengeDisposition, | 3392 (void (^)(NSURLSessionAuthChallengeDisposition, |
3396 NSURLCredential*))completionHandler { | 3393 NSURLCredential*))completionHandler { |
3397 NSURLProtectionSpace* space = challenge.protectionSpace; | 3394 NSURLProtectionSpace* space = challenge.protectionSpace; |
3398 DCHECK( | 3395 DCHECK( |
3399 [space.authenticationMethod isEqual:NSURLAuthenticationMethodHTTPBasic] || | 3396 [space.authenticationMethod isEqual:NSURLAuthenticationMethodHTTPBasic] || |
3400 [space.authenticationMethod isEqual:NSURLAuthenticationMethodNTLM] || | 3397 [space.authenticationMethod isEqual:NSURLAuthenticationMethodNTLM] || |
3401 [space.authenticationMethod isEqual:NSURLAuthenticationMethodHTTPDigest]); | 3398 [space.authenticationMethod isEqual:NSURLAuthenticationMethodHTTPDigest]); |
3402 | 3399 |
3403 if (self.shouldSuppressDialogs) { | 3400 if (self.shouldSuppressDialogs) { |
3404 [self didSuppressDialog]; | 3401 // TODO(crbug.com/702381): Web Controller should not assume that embedder |
| 3402 // handles HTTP Authentication by showing the dialog. |
| 3403 _webStateImpl->OnDialogSuppressed(); |
3405 completionHandler(NSURLSessionAuthChallengeRejectProtectionSpace, nil); | 3404 completionHandler(NSURLSessionAuthChallengeRejectProtectionSpace, nil); |
3406 return; | 3405 return; |
3407 } | 3406 } |
3408 | 3407 |
3409 _webStateImpl->OnAuthRequired( | 3408 _webStateImpl->OnAuthRequired( |
3410 space, challenge.proposedCredential, | 3409 space, challenge.proposedCredential, |
3411 base::BindBlock(^(NSString* user, NSString* password) { | 3410 base::BindBlock(^(NSString* user, NSString* password) { |
3412 [CRWWebController processHTTPAuthForUser:user | 3411 [CRWWebController processHTTPAuthForUser:user |
3413 password:password | 3412 password:password |
3414 completionHandler:completionHandler]; | 3413 completionHandler:completionHandler]; |
(...skipping 21 matching lines...) Expand all Loading... |
3436 #pragma mark - | 3435 #pragma mark - |
3437 #pragma mark JavaScript Dialog | 3436 #pragma mark JavaScript Dialog |
3438 | 3437 |
3439 - (void)runJavaScriptDialogOfType:(web::JavaScriptDialogType)type | 3438 - (void)runJavaScriptDialogOfType:(web::JavaScriptDialogType)type |
3440 initiatedByFrame:(WKFrameInfo*)frame | 3439 initiatedByFrame:(WKFrameInfo*)frame |
3441 message:(NSString*)message | 3440 message:(NSString*)message |
3442 defaultText:(NSString*)defaultText | 3441 defaultText:(NSString*)defaultText |
3443 completion:(void (^)(BOOL, NSString*))completionHandler { | 3442 completion:(void (^)(BOOL, NSString*))completionHandler { |
3444 DCHECK(completionHandler); | 3443 DCHECK(completionHandler); |
3445 if (self.shouldSuppressDialogs) { | 3444 if (self.shouldSuppressDialogs) { |
3446 [self didSuppressDialog]; | 3445 _webStateImpl->OnDialogSuppressed(); |
3447 completionHandler(NO, nil); | 3446 completionHandler(NO, nil); |
3448 return; | 3447 return; |
3449 } | 3448 } |
3450 | 3449 |
3451 self.webStateImpl->RunJavaScriptDialog( | 3450 self.webStateImpl->RunJavaScriptDialog( |
3452 net::GURLWithNSURL(frame.request.URL), type, message, defaultText, | 3451 net::GURLWithNSURL(frame.request.URL), type, message, defaultText, |
3453 base::BindBlock(^(bool success, NSString* input) { | 3452 base::BindBlock(^(bool success, NSString* input) { |
3454 completionHandler(success, input); | 3453 completionHandler(success, input); |
3455 })); | 3454 })); |
3456 } | 3455 } |
(...skipping 464 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3921 mainDocumentURL: | 3920 mainDocumentURL: |
3922 linkClicked:)]) { | 3921 linkClicked:)]) { |
3923 return YES; | 3922 return YES; |
3924 } | 3923 } |
3925 return [_delegate webController:self | 3924 return [_delegate webController:self |
3926 shouldOpenURL:url | 3925 shouldOpenURL:url |
3927 mainDocumentURL:mainDocumentURL | 3926 mainDocumentURL:mainDocumentURL |
3928 linkClicked:linkClicked]; | 3927 linkClicked:linkClicked]; |
3929 } | 3928 } |
3930 | 3929 |
3931 - (void)didSuppressDialog { | |
3932 if ([_delegate respondsToSelector:@selector(webControllerDidSuppressDialog:)]) | |
3933 [_delegate webControllerDidSuppressDialog:self]; | |
3934 } | |
3935 | |
3936 - (BOOL)isMainFrameNavigationAction:(WKNavigationAction*)action { | 3930 - (BOOL)isMainFrameNavigationAction:(WKNavigationAction*)action { |
3937 if (action.targetFrame) { | 3931 if (action.targetFrame) { |
3938 return action.targetFrame.mainFrame; | 3932 return action.targetFrame.mainFrame; |
3939 } | 3933 } |
3940 // According to WKNavigationAction documentation, in the case of a new window | 3934 // According to WKNavigationAction documentation, in the case of a new window |
3941 // navigation, target frame will be nil. In this case check if the | 3935 // navigation, target frame will be nil. In this case check if the |
3942 // |sourceFrame| is the mainFrame. | 3936 // |sourceFrame| is the mainFrame. |
3943 return action.sourceFrame.mainFrame; | 3937 return action.sourceFrame.mainFrame; |
3944 } | 3938 } |
3945 | 3939 |
(...skipping 358 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4304 } | 4298 } |
4305 | 4299 |
4306 #pragma mark - | 4300 #pragma mark - |
4307 #pragma mark WKUIDelegate Methods | 4301 #pragma mark WKUIDelegate Methods |
4308 | 4302 |
4309 - (WKWebView*)webView:(WKWebView*)webView | 4303 - (WKWebView*)webView:(WKWebView*)webView |
4310 createWebViewWithConfiguration:(WKWebViewConfiguration*)configuration | 4304 createWebViewWithConfiguration:(WKWebViewConfiguration*)configuration |
4311 forNavigationAction:(WKNavigationAction*)action | 4305 forNavigationAction:(WKNavigationAction*)action |
4312 windowFeatures:(WKWindowFeatures*)windowFeatures { | 4306 windowFeatures:(WKWindowFeatures*)windowFeatures { |
4313 if (self.shouldSuppressDialogs) { | 4307 if (self.shouldSuppressDialogs) { |
4314 [self didSuppressDialog]; | 4308 _webStateImpl->OnDialogSuppressed(); |
4315 return nil; | 4309 return nil; |
4316 } | 4310 } |
4317 | 4311 |
4318 // Do not create windows for non-empty invalid URLs. | 4312 // Do not create windows for non-empty invalid URLs. |
4319 GURL requestURL = net::GURLWithNSURL(action.request.URL); | 4313 GURL requestURL = net::GURLWithNSURL(action.request.URL); |
4320 if (!requestURL.is_empty() && !requestURL.is_valid()) { | 4314 if (!requestURL.is_empty() && !requestURL.is_valid()) { |
4321 DLOG(WARNING) << "Unable to open a window with invalid URL: " | 4315 DLOG(WARNING) << "Unable to open a window with invalid URL: " |
4322 << requestURL.spec(); | 4316 << requestURL.spec(); |
4323 return nil; | 4317 return nil; |
4324 } | 4318 } |
(...skipping 865 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5190 - (void)simulateLoadRequestWithURL:(const GURL&)URL { | 5184 - (void)simulateLoadRequestWithURL:(const GURL&)URL { |
5191 _lastRegisteredRequestURL = URL; | 5185 _lastRegisteredRequestURL = URL; |
5192 _loadPhase = web::LOAD_REQUESTED; | 5186 _loadPhase = web::LOAD_REQUESTED; |
5193 } | 5187 } |
5194 | 5188 |
5195 - (NSString*)referrerFromNavigationAction:(WKNavigationAction*)action { | 5189 - (NSString*)referrerFromNavigationAction:(WKNavigationAction*)action { |
5196 return [action.request valueForHTTPHeaderField:kReferrerHeaderName]; | 5190 return [action.request valueForHTTPHeaderField:kReferrerHeaderName]; |
5197 } | 5191 } |
5198 | 5192 |
5199 @end | 5193 @end |
OLD | NEW |