Chromium Code Reviews| 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> |
| 11 | 11 |
| 12 #include <cmath> | 12 #include <cmath> |
| 13 #include <memory> | 13 #include <memory> |
| 14 #include <utility> | 14 #include <utility> |
| 15 | 15 |
| 16 #include "base/callback.h" | |
| 16 #include "base/containers/mru_cache.h" | 17 #include "base/containers/mru_cache.h" |
| 17 #include "base/ios/block_types.h" | 18 #include "base/ios/block_types.h" |
| 18 #include "base/ios/ios_util.h" | 19 #include "base/ios/ios_util.h" |
| 19 #import "base/ios/ns_error_util.h" | 20 #import "base/ios/ns_error_util.h" |
| 20 #include "base/ios/weak_nsobject.h" | 21 #include "base/ios/weak_nsobject.h" |
| 21 #include "base/json/json_reader.h" | 22 #include "base/json/json_reader.h" |
| 22 #include "base/json/json_writer.h" | 23 #include "base/json/json_writer.h" |
| 23 #include "base/json/string_escape.h" | 24 #include "base/json/string_escape.h" |
| 24 #include "base/logging.h" | 25 #include "base/logging.h" |
| 25 #include "base/mac/bind_objc_block.h" | 26 #include "base/mac/bind_objc_block.h" |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 47 #import "ios/web/navigation/crw_session_entry.h" | 48 #import "ios/web/navigation/crw_session_entry.h" |
| 48 #import "ios/web/navigation/navigation_item_impl.h" | 49 #import "ios/web/navigation/navigation_item_impl.h" |
| 49 #import "ios/web/navigation/navigation_manager_impl.h" | 50 #import "ios/web/navigation/navigation_manager_impl.h" |
| 50 #include "ios/web/net/cert_host_pair.h" | 51 #include "ios/web/net/cert_host_pair.h" |
| 51 #import "ios/web/net/crw_cert_verification_controller.h" | 52 #import "ios/web/net/crw_cert_verification_controller.h" |
| 52 #import "ios/web/net/crw_ssl_status_updater.h" | 53 #import "ios/web/net/crw_ssl_status_updater.h" |
| 53 #include "ios/web/net/request_group_util.h" | 54 #include "ios/web/net/request_group_util.h" |
| 54 #include "ios/web/public/browser_state.h" | 55 #include "ios/web/public/browser_state.h" |
| 55 #include "ios/web/public/cert_store.h" | 56 #include "ios/web/public/cert_store.h" |
| 56 #include "ios/web/public/favicon_url.h" | 57 #include "ios/web/public/favicon_url.h" |
| 58 #include "ios/web/public/javascript_dialog_presenter.h" | |
|
Eugene But (OOO till 7-30)
2016/06/27 21:09:37
s/include/import
michaeldo
2016/06/27 22:25:10
Done.
| |
| 59 #include "ios/web/public/javascript_dialog_type.h" | |
| 57 #include "ios/web/public/navigation_item.h" | 60 #include "ios/web/public/navigation_item.h" |
| 58 #import "ios/web/public/navigation_manager.h" | 61 #import "ios/web/public/navigation_manager.h" |
| 59 #import "ios/web/public/origin_util.h" | 62 #import "ios/web/public/origin_util.h" |
| 60 #include "ios/web/public/referrer.h" | 63 #include "ios/web/public/referrer.h" |
| 61 #include "ios/web/public/referrer_util.h" | 64 #include "ios/web/public/referrer_util.h" |
| 62 #include "ios/web/public/ssl_status.h" | 65 #include "ios/web/public/ssl_status.h" |
| 63 #import "ios/web/public/url_scheme_util.h" | 66 #import "ios/web/public/url_scheme_util.h" |
| 64 #include "ios/web/public/url_util.h" | 67 #include "ios/web/public/url_util.h" |
| 65 #include "ios/web/public/user_metrics.h" | 68 #include "ios/web/public/user_metrics.h" |
| 66 #include "ios/web/public/web_client.h" | 69 #include "ios/web/public/web_client.h" |
| (...skipping 778 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 845 completionHandler: | 848 completionHandler: |
| 846 (void (^)(NSURLSessionAuthChallengeDisposition, | 849 (void (^)(NSURLSessionAuthChallengeDisposition, |
| 847 NSURLCredential*))completionHandler; | 850 NSURLCredential*))completionHandler; |
| 848 // Used in webView:didReceiveAuthenticationChallenge:completionHandler: to reply | 851 // Used in webView:didReceiveAuthenticationChallenge:completionHandler: to reply |
| 849 // with NSURLSessionAuthChallengeDisposition and credentials. | 852 // with NSURLSessionAuthChallengeDisposition and credentials. |
| 850 + (void)processHTTPAuthForUser:(NSString*)user | 853 + (void)processHTTPAuthForUser:(NSString*)user |
| 851 password:(NSString*)password | 854 password:(NSString*)password |
| 852 completionHandler:(void (^)(NSURLSessionAuthChallengeDisposition, | 855 completionHandler:(void (^)(NSURLSessionAuthChallengeDisposition, |
| 853 NSURLCredential*))completionHandler; | 856 NSURLCredential*))completionHandler; |
| 854 | 857 |
| 858 // Helper to respond to |webView:runJavaScript...| delegate methods. | |
| 859 // |completionHandler| must not be nil. | |
| 860 - (void)runJavaScriptDialogOfType:(web::JavaScriptDialogType)type | |
| 861 initiatedByFrame:(WKFrameInfo*)frame | |
| 862 message:(NSString*)message | |
| 863 defaultText:(NSString*)defaultText | |
| 864 completion:(void (^)(BOOL, NSString*))completionHandler; | |
| 865 | |
| 855 // Called when WKWebView estimatedProgress has been changed. | 866 // Called when WKWebView estimatedProgress has been changed. |
| 856 - (void)webViewEstimatedProgressDidChange; | 867 - (void)webViewEstimatedProgressDidChange; |
| 857 // Called when WKWebView certificateChain or hasOnlySecureContent property has | 868 // Called when WKWebView certificateChain or hasOnlySecureContent property has |
| 858 // changed. | 869 // changed. |
| 859 - (void)webViewSecurityFeaturesDidChange; | 870 - (void)webViewSecurityFeaturesDidChange; |
| 860 // Called when WKWebView loading state has been changed. | 871 // Called when WKWebView loading state has been changed. |
| 861 - (void)webViewLoadingStateDidChange; | 872 - (void)webViewLoadingStateDidChange; |
| 862 // Called when WKWebView title has been changed. | 873 // Called when WKWebView title has been changed. |
| 863 - (void)webViewTitleDidChange; | 874 - (void)webViewTitleDidChange; |
| 864 // Called when WKWebView URL has been changed. | 875 // Called when WKWebView URL has been changed. |
| (...skipping 2888 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3753 } | 3764 } |
| 3754 completionHandler( | 3765 completionHandler( |
| 3755 NSURLSessionAuthChallengeUseCredential, | 3766 NSURLSessionAuthChallengeUseCredential, |
| 3756 [NSURLCredential | 3767 [NSURLCredential |
| 3757 credentialWithUser:user | 3768 credentialWithUser:user |
| 3758 password:password | 3769 password:password |
| 3759 persistence:NSURLCredentialPersistenceForSession]); | 3770 persistence:NSURLCredentialPersistenceForSession]); |
| 3760 } | 3771 } |
| 3761 | 3772 |
| 3762 #pragma mark - | 3773 #pragma mark - |
| 3774 #pragma mark JavaScript Dialog | |
| 3775 | |
| 3776 - (void)runJavaScriptDialogOfType:(web::JavaScriptDialogType)type | |
| 3777 initiatedByFrame:(WKFrameInfo*)frame | |
| 3778 message:(NSString*)message | |
| 3779 defaultText:(NSString*)defaultText | |
| 3780 completion:(void (^)(BOOL, NSString*))completionHandler { | |
| 3781 completionHandler = [completionHandler copy]; | |
|
Eugene But (OOO till 7-30)
2016/06/27 21:09:37
Why do you need this? |completionHandler| should b
michaeldo
2016/06/27 22:25:10
You are correct, I don't need this copy.
| |
| 3782 self.webStateImpl->RunJavaScriptDialog( | |
| 3783 net::GURLWithNSURL(frame.request.URL), type, message, defaultText, | |
| 3784 base::BindBlock(^(bool success, NSString* input) { | |
| 3785 completionHandler(success, input); | |
| 3786 [completionHandler release]; | |
| 3787 })); | |
| 3788 } | |
| 3789 | |
| 3790 #pragma mark - | |
| 3763 #pragma mark TouchTracking | 3791 #pragma mark TouchTracking |
| 3764 | 3792 |
| 3765 - (void)touched:(BOOL)touched { | 3793 - (void)touched:(BOOL)touched { |
| 3766 _clickInProgress = touched; | 3794 _clickInProgress = touched; |
| 3767 if (touched) { | 3795 if (touched) { |
| 3768 self.userInteractionRegistered = YES; | 3796 self.userInteractionRegistered = YES; |
| 3769 _userInteractedWithWebController = YES; | 3797 _userInteractedWithWebController = YES; |
| 3770 if (_isBeingDestroyed) | 3798 if (_isBeingDestroyed) |
| 3771 return; | 3799 return; |
| 3772 const web::NavigationManagerImpl& navigationManager = | 3800 const web::NavigationManagerImpl& navigationManager = |
| (...skipping 913 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 4686 [self setDocumentURL:_defaultURL]; | 4714 [self setDocumentURL:_defaultURL]; |
| 4687 } | 4715 } |
| 4688 | 4716 |
| 4689 - (void)removeWebViewAllowingCachedReconstruction:(BOOL)allowCache { | 4717 - (void)removeWebViewAllowingCachedReconstruction:(BOOL)allowCache { |
| 4690 if (!_webView) | 4718 if (!_webView) |
| 4691 return; | 4719 return; |
| 4692 | 4720 |
| 4693 SEL cancelDialogsSelector = @selector(cancelDialogsForWebController:); | 4721 SEL cancelDialogsSelector = @selector(cancelDialogsForWebController:); |
| 4694 if ([self.UIDelegate respondsToSelector:cancelDialogsSelector]) | 4722 if ([self.UIDelegate respondsToSelector:cancelDialogsSelector]) |
| 4695 [self.UIDelegate cancelDialogsForWebController:self]; | 4723 [self.UIDelegate cancelDialogsForWebController:self]; |
| 4724 _webStateImpl->CancelActiveAndPendingDialogs(); | |
| 4696 | 4725 |
| 4697 if (allowCache) | 4726 if (allowCache) |
| 4698 _expectedReconstructionURL = [self currentNavigationURL]; | 4727 _expectedReconstructionURL = [self currentNavigationURL]; |
| 4699 else | 4728 else |
| 4700 _expectedReconstructionURL = GURL(); | 4729 _expectedReconstructionURL = GURL(); |
| 4701 | 4730 |
| 4702 [self abortLoad]; | 4731 [self abortLoad]; |
| 4703 [_webView removeFromSuperview]; | 4732 [_webView removeFromSuperview]; |
| 4704 [_containerView resetContent]; | 4733 [_containerView resetContent]; |
| 4705 [self setWebView:nil]; | 4734 [self setWebView:nil]; |
| 4706 } | 4735 } |
| 4707 | 4736 |
| 4708 - (void)webViewWebProcessDidCrash { | 4737 - (void)webViewWebProcessDidCrash { |
| 4709 _webProcessIsDead = YES; | 4738 _webProcessIsDead = YES; |
| 4710 | 4739 |
| 4711 SEL cancelDialogsSelector = @selector(cancelDialogsForWebController:); | 4740 SEL cancelDialogsSelector = @selector(cancelDialogsForWebController:); |
| 4712 if ([self.UIDelegate respondsToSelector:cancelDialogsSelector]) | 4741 if ([self.UIDelegate respondsToSelector:cancelDialogsSelector]) |
| 4713 [self.UIDelegate cancelDialogsForWebController:self]; | 4742 [self.UIDelegate cancelDialogsForWebController:self]; |
| 4743 _webStateImpl->CancelActiveAndPendingDialogs(); | |
| 4714 | 4744 |
| 4715 SEL rendererCrashSelector = @selector(webControllerWebProcessDidCrash:); | 4745 SEL rendererCrashSelector = @selector(webControllerWebProcessDidCrash:); |
| 4716 if ([self.delegate respondsToSelector:rendererCrashSelector]) | 4746 if ([self.delegate respondsToSelector:rendererCrashSelector]) |
| 4717 [self.delegate webControllerWebProcessDidCrash:self]; | 4747 [self.delegate webControllerWebProcessDidCrash:self]; |
| 4718 } | 4748 } |
| 4719 | 4749 |
| 4720 - (web::WKWebViewConfigurationProvider&)webViewConfigurationProvider { | 4750 - (web::WKWebViewConfigurationProvider&)webViewConfigurationProvider { |
| 4721 web::BrowserState* browserState = self.webStateImpl->GetBrowserState(); | 4751 web::BrowserState* browserState = self.webStateImpl->GetBrowserState(); |
| 4722 return web::WKWebViewConfigurationProvider::FromBrowserState(browserState); | 4752 return web::WKWebViewConfigurationProvider::FromBrowserState(browserState); |
| 4723 } | 4753 } |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 4831 [self.delegate webPageOrderedClose]; | 4861 [self.delegate webPageOrderedClose]; |
| 4832 } | 4862 } |
| 4833 } | 4863 } |
| 4834 | 4864 |
| 4835 - (void)webView:(WKWebView*)webView | 4865 - (void)webView:(WKWebView*)webView |
| 4836 runJavaScriptAlertPanelWithMessage:(NSString*)message | 4866 runJavaScriptAlertPanelWithMessage:(NSString*)message |
| 4837 initiatedByFrame:(WKFrameInfo*)frame | 4867 initiatedByFrame:(WKFrameInfo*)frame |
| 4838 completionHandler:(void (^)())completionHandler { | 4868 completionHandler:(void (^)())completionHandler { |
| 4839 if (self.shouldSuppressDialogs) { | 4869 if (self.shouldSuppressDialogs) { |
| 4840 [self didSuppressDialog]; | 4870 [self didSuppressDialog]; |
| 4841 completionHandler(); | 4871 if (completionHandler) { |
|
Eugene But (OOO till 7-30)
2016/06/27 21:09:37
Optional NIT: We never had crashes here, so I beli
michaeldo
2016/06/27 22:25:10
The if check was here, I simply moved it from the
Eugene But (OOO till 7-30)
2016/06/27 22:33:56
Right, so if block is nil then we'll crash. But ac
michaeldo
2016/06/28 17:44:47
Yes, you are right! I'll remove the check.
| |
| 4872 completionHandler(); | |
| 4873 } | |
| 4842 return; | 4874 return; |
| 4843 } | 4875 } |
| 4844 | 4876 |
| 4845 SEL alertSelector = @selector(webController: | 4877 SEL alertSelector = @selector(webController: |
| 4846 runJavaScriptAlertPanelWithMessage: | 4878 runJavaScriptAlertPanelWithMessage: |
| 4847 requestURL: | 4879 requestURL: |
| 4848 completionHandler:); | 4880 completionHandler:); |
| 4849 if ([self.UIDelegate respondsToSelector:alertSelector]) { | 4881 if ([self.UIDelegate respondsToSelector:alertSelector]) { |
| 4850 [self.UIDelegate webController:self | 4882 [self.UIDelegate webController:self |
| 4851 runJavaScriptAlertPanelWithMessage:message | 4883 runJavaScriptAlertPanelWithMessage:message |
| 4852 requestURL:net::GURLWithNSURL(frame.request.URL) | 4884 requestURL:net::GURLWithNSURL(frame.request.URL) |
| 4853 completionHandler:completionHandler]; | 4885 completionHandler:completionHandler]; |
| 4854 } else if (completionHandler) { | 4886 } else { |
| 4855 completionHandler(); | 4887 [self runJavaScriptDialogOfType:web::JAVASCRIPT_DIALOG_TYPE_ALERT |
| 4888 initiatedByFrame:frame | |
| 4889 message:message | |
| 4890 defaultText:nil | |
| 4891 completion:^(BOOL, NSString*) { | |
| 4892 if (completionHandler) { | |
| 4893 completionHandler(); | |
| 4894 } | |
| 4895 }]; | |
| 4856 } | 4896 } |
| 4857 } | 4897 } |
| 4858 | 4898 |
| 4859 - (void)webView:(WKWebView*)webView | 4899 - (void)webView:(WKWebView*)webView |
| 4860 runJavaScriptConfirmPanelWithMessage:(NSString*)message | 4900 runJavaScriptConfirmPanelWithMessage:(NSString*)message |
| 4861 initiatedByFrame:(WKFrameInfo*)frame | 4901 initiatedByFrame:(WKFrameInfo*)frame |
| 4862 completionHandler: | 4902 completionHandler: |
| 4863 (void (^)(BOOL result))completionHandler { | 4903 (void (^)(BOOL result))completionHandler { |
| 4864 if (self.shouldSuppressDialogs) { | 4904 if (self.shouldSuppressDialogs) { |
| 4865 [self didSuppressDialog]; | 4905 [self didSuppressDialog]; |
| 4866 completionHandler(NO); | 4906 completionHandler(NO); |
| 4867 return; | 4907 return; |
| 4868 } | 4908 } |
| 4869 | 4909 |
| 4870 SEL confirmationSelector = @selector(webController: | 4910 SEL confirmationSelector = @selector(webController: |
| 4871 runJavaScriptConfirmPanelWithMessage: | 4911 runJavaScriptConfirmPanelWithMessage: |
| 4872 requestURL: | 4912 requestURL: |
| 4873 completionHandler:); | 4913 completionHandler:); |
| 4874 if ([self.UIDelegate respondsToSelector:confirmationSelector]) { | 4914 if ([self.UIDelegate respondsToSelector:confirmationSelector]) { |
| 4875 [self.UIDelegate webController:self | 4915 [self.UIDelegate webController:self |
| 4876 runJavaScriptConfirmPanelWithMessage:message | 4916 runJavaScriptConfirmPanelWithMessage:message |
| 4877 requestURL:net::GURLWithNSURL( | 4917 requestURL:net::GURLWithNSURL( |
| 4878 frame.request.URL) | 4918 frame.request.URL) |
| 4879 completionHandler:completionHandler]; | 4919 completionHandler:completionHandler]; |
| 4880 } else if (completionHandler) { | 4920 } else { |
| 4881 completionHandler(NO); | 4921 [self runJavaScriptDialogOfType:web::JAVASCRIPT_DIALOG_TYPE_CONFIRM |
| 4922 initiatedByFrame:frame | |
| 4923 message:message | |
| 4924 defaultText:nil | |
| 4925 completion:^(BOOL success, NSString*) { | |
| 4926 if (completionHandler) { | |
| 4927 completionHandler(success); | |
| 4928 } | |
| 4929 }]; | |
| 4882 } | 4930 } |
| 4883 } | 4931 } |
| 4884 | 4932 |
| 4885 - (void)webView:(WKWebView*)webView | 4933 - (void)webView:(WKWebView*)webView |
| 4886 runJavaScriptTextInputPanelWithPrompt:(NSString*)prompt | 4934 runJavaScriptTextInputPanelWithPrompt:(NSString*)prompt |
| 4887 defaultText:(NSString*)defaultText | 4935 defaultText:(NSString*)defaultText |
| 4888 initiatedByFrame:(WKFrameInfo*)frame | 4936 initiatedByFrame:(WKFrameInfo*)frame |
| 4889 completionHandler: | 4937 completionHandler: |
| 4890 (void (^)(NSString* result))completionHandler { | 4938 (void (^)(NSString* result))completionHandler { |
| 4891 GURL origin(web::GURLOriginWithWKSecurityOrigin(frame.securityOrigin)); | 4939 GURL origin(web::GURLOriginWithWKSecurityOrigin(frame.securityOrigin)); |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 4908 defaultText: | 4956 defaultText: |
| 4909 requestURL: | 4957 requestURL: |
| 4910 completionHandler:); | 4958 completionHandler:); |
| 4911 if ([self.UIDelegate respondsToSelector:textInputSelector]) { | 4959 if ([self.UIDelegate respondsToSelector:textInputSelector]) { |
| 4912 GURL requestURL = net::GURLWithNSURL(frame.request.URL); | 4960 GURL requestURL = net::GURLWithNSURL(frame.request.URL); |
| 4913 [self.UIDelegate webController:self | 4961 [self.UIDelegate webController:self |
| 4914 runJavaScriptTextInputPanelWithPrompt:prompt | 4962 runJavaScriptTextInputPanelWithPrompt:prompt |
| 4915 defaultText:defaultText | 4963 defaultText:defaultText |
| 4916 requestURL:requestURL | 4964 requestURL:requestURL |
| 4917 completionHandler:completionHandler]; | 4965 completionHandler:completionHandler]; |
| 4918 } else if (completionHandler) { | 4966 } else { |
| 4919 completionHandler(nil); | 4967 [self runJavaScriptDialogOfType:web::JAVASCRIPT_DIALOG_TYPE_PROMPT |
| 4968 initiatedByFrame:frame | |
| 4969 message:prompt | |
| 4970 defaultText:defaultText | |
| 4971 completion:^(BOOL, NSString* input) { | |
| 4972 if (completionHandler) { | |
| 4973 completionHandler(input); | |
| 4974 } | |
| 4975 }]; | |
| 4920 } | 4976 } |
| 4921 } | 4977 } |
| 4922 | 4978 |
| 4923 #pragma mark - | 4979 #pragma mark - |
| 4924 #pragma mark WKNavigationDelegate Methods | 4980 #pragma mark WKNavigationDelegate Methods |
| 4925 | 4981 |
| 4926 - (void)webView:(WKWebView*)webView | 4982 - (void)webView:(WKWebView*)webView |
| 4927 decidePolicyForNavigationAction:(WKNavigationAction*)action | 4983 decidePolicyForNavigationAction:(WKNavigationAction*)action |
| 4928 decisionHandler: | 4984 decisionHandler: |
| 4929 (void (^)(WKNavigationActionPolicy))decisionHandler { | 4985 (void (^)(WKNavigationActionPolicy))decisionHandler { |
| (...skipping 676 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 5606 } | 5662 } |
| 5607 | 5663 |
| 5608 return web::WEB_VIEW_DOCUMENT_TYPE_GENERIC; | 5664 return web::WEB_VIEW_DOCUMENT_TYPE_GENERIC; |
| 5609 } | 5665 } |
| 5610 | 5666 |
| 5611 - (NSString*)refererFromNavigationAction:(WKNavigationAction*)action { | 5667 - (NSString*)refererFromNavigationAction:(WKNavigationAction*)action { |
| 5612 return [action.request valueForHTTPHeaderField:@"Referer"]; | 5668 return [action.request valueForHTTPHeaderField:@"Referer"]; |
| 5613 } | 5669 } |
| 5614 | 5670 |
| 5615 @end | 5671 @end |
| OLD | NEW |