| 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 742 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 753 - (BOOL)isBackForwardListItemValid:(WKBackForwardListItem*)item; | 753 - (BOOL)isBackForwardListItemValid:(WKBackForwardListItem*)item; |
| 754 // Finds all the scrollviews in the view hierarchy and makes sure they do not | 754 // Finds all the scrollviews in the view hierarchy and makes sure they do not |
| 755 // interfere with scroll to top when tapping the statusbar. | 755 // interfere with scroll to top when tapping the statusbar. |
| 756 - (void)optOutScrollsToTopForSubviews; | 756 - (void)optOutScrollsToTopForSubviews; |
| 757 // Tears down the old native controller, and then replaces it with the new one. | 757 // Tears down the old native controller, and then replaces it with the new one. |
| 758 - (void)setNativeController:(id<CRWNativeContent>)nativeController; | 758 - (void)setNativeController:(id<CRWNativeContent>)nativeController; |
| 759 // Returns whether |url| should be opened. | 759 // Returns whether |url| should be opened. |
| 760 - (BOOL)shouldOpenURL:(const GURL&)url | 760 - (BOOL)shouldOpenURL:(const GURL&)url |
| 761 mainDocumentURL:(const GURL&)mainDocumentURL | 761 mainDocumentURL:(const GURL&)mainDocumentURL |
| 762 linkClicked:(BOOL)linkClicked; | 762 linkClicked:(BOOL)linkClicked; |
| 763 // Called when |URL| needs to be opened in a matching native app. | |
| 764 // Returns YES if the url was succesfully opened in the native app. | |
| 765 - (BOOL)urlTriggersNativeAppLaunch:(const GURL&)URL | |
| 766 sourceURL:(const GURL&)sourceURL | |
| 767 linkActivatedNavigation:(BOOL)linkActivatedNavigation; | |
| 768 // Returns YES if the navigation action is associated with a main frame request. | 763 // Returns YES if the navigation action is associated with a main frame request. |
| 769 - (BOOL)isMainFrameNavigationAction:(WKNavigationAction*)action; | 764 - (BOOL)isMainFrameNavigationAction:(WKNavigationAction*)action; |
| 770 // Returns whether external URL navigation action should be opened. | 765 // Returns whether external URL navigation action should be opened. |
| 771 - (BOOL)shouldOpenExternalURLForNavigationAction:(WKNavigationAction*)action; | 766 - (BOOL)shouldOpenExternalURLForNavigationAction:(WKNavigationAction*)action; |
| 772 // Returns the header height. | 767 // Returns the header height. |
| 773 - (CGFloat)headerHeight; | 768 - (CGFloat)headerHeight; |
| 774 // Updates SSL status for the current navigation item based on the information | 769 // Updates SSL status for the current navigation item based on the information |
| 775 // provided by web view. | 770 // provided by web view. |
| 776 - (void)updateSSLStatusForCurrentNavigationItem; | 771 - (void)updateSSLStatusForCurrentNavigationItem; |
| 777 // Called when a load ends in an SSL error and certificate chain. | 772 // Called when a load ends in an SSL error and certificate chain. |
| (...skipping 2184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2962 DCHECK_EQ(1u, [cookieKeys count]); | 2957 DCHECK_EQ(1u, [cookieKeys count]); |
| 2963 item->RemoveHttpRequestHeaderForKey([cookieKeys anyObject]); | 2958 item->RemoveHttpRequestHeaderForKey([cookieKeys anyObject]); |
| 2964 } | 2959 } |
| 2965 } | 2960 } |
| 2966 } | 2961 } |
| 2967 | 2962 |
| 2968 // TODO(stuartmorgan): This is mostly logic from the original UIWebView delegate | 2963 // TODO(stuartmorgan): This is mostly logic from the original UIWebView delegate |
| 2969 // method, which provides less information than the WKWebView version. Audit | 2964 // method, which provides less information than the WKWebView version. Audit |
| 2970 // this for things that should be handled in the subclass instead. | 2965 // this for things that should be handled in the subclass instead. |
| 2971 - (BOOL)shouldAllowLoadWithNavigationAction:(WKNavigationAction*)action { | 2966 - (BOOL)shouldAllowLoadWithNavigationAction:(WKNavigationAction*)action { |
| 2972 NSURLRequest* request = action.request; | |
| 2973 GURL requestURL = net::GURLWithNSURL(request.URL); | |
| 2974 | |
| 2975 // External application launcher needs |isNavigationTypeLinkActivated| to | 2967 // External application launcher needs |isNavigationTypeLinkActivated| to |
| 2976 // decide if the user intended to open the application by clicking on a link. | 2968 // decide if the user intended to open the application by clicking on a link. |
| 2977 BOOL isNavigationTypeLinkActivated = | 2969 BOOL isNavigationTypeLinkActivated = |
| 2978 action.navigationType == WKNavigationTypeLinkActivated; | 2970 action.navigationType == WKNavigationTypeLinkActivated; |
| 2979 | 2971 |
| 2980 // Checks if the link navigation leads to a launch of an external app. | |
| 2981 // TODO(crbug.com/704417): External apps will not be launched from clicking | |
| 2982 // a Bookmarked URL or a Recently Closed URL. | |
| 2983 // TODO(crbug.com/607780): Revise the logic of allowing external app launch | |
| 2984 // and move it to externalAppLauncher. | |
| 2985 BOOL isOpenInNewTabNavigation = !(self.navigationManagerImpl->GetItemCount()); | |
| 2986 BOOL isPossibleLinkClick = [self isLinkNavigation:action.navigationType]; | |
| 2987 if (isPossibleLinkClick || isOpenInNewTabNavigation) { | |
| 2988 web::NavigationItem* item = self.currentNavItem; | |
| 2989 const GURL currentNavigationURL = | |
| 2990 item ? item->GetVirtualURL() : GURL::EmptyGURL(); | |
| 2991 // Check If the URL is handled by a native app. | |
| 2992 if ([self urlTriggersNativeAppLaunch:requestURL | |
| 2993 sourceURL:currentNavigationURL | |
| 2994 linkActivatedNavigation:isNavigationTypeLinkActivated]) { | |
| 2995 // External app has been launched successfully. Stop the current page | |
| 2996 // load operation (e.g. notifying all observers) and record the URL so | |
| 2997 // that errors reported following the 'NO' reply can be safely ignored. | |
| 2998 if ([self shouldClosePageOnNativeApplicationLoad]) | |
| 2999 _webStateImpl->CloseWebState(); | |
| 3000 [self stopLoading]; | |
| 3001 [_openedApplicationURL addObject:request.URL]; | |
| 3002 return NO; | |
| 3003 } | |
| 3004 } | |
| 3005 | |
| 3006 // The WebDelegate may instruct the CRWWebController to stop loading, and | 2972 // The WebDelegate may instruct the CRWWebController to stop loading, and |
| 3007 // instead instruct the next page to be loaded in an animation. | 2973 // instead instruct the next page to be loaded in an animation. |
| 2974 NSURLRequest* request = action.request; |
| 2975 GURL requestURL = net::GURLWithNSURL(request.URL); |
| 3008 GURL mainDocumentURL = net::GURLWithNSURL(request.mainDocumentURL); | 2976 GURL mainDocumentURL = net::GURLWithNSURL(request.mainDocumentURL); |
| 2977 BOOL isPossibleLinkClick = [self isLinkNavigation:action.navigationType]; |
| 3009 DCHECK(_webView); | 2978 DCHECK(_webView); |
| 3010 if (![self shouldOpenURL:requestURL | 2979 if (![self shouldOpenURL:requestURL |
| 3011 mainDocumentURL:mainDocumentURL | 2980 mainDocumentURL:mainDocumentURL |
| 3012 linkClicked:isPossibleLinkClick]) { | 2981 linkClicked:isPossibleLinkClick]) { |
| 3013 return NO; | 2982 return NO; |
| 3014 } | 2983 } |
| 3015 | 2984 |
| 3016 // If the URL doesn't look like one we can show, try to open the link with an | 2985 // If the URL doesn't look like one we can show, try to open the link with an |
| 3017 // external application. | 2986 // external application. |
| 3018 // TODO(droger): Check transition type before opening an external | 2987 // TODO(droger): Check transition type before opening an external |
| (...skipping 817 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3836 if (requestStatus == SUBFRAME_BLOCKED) { | 3805 if (requestStatus == SUBFRAME_BLOCKED) { |
| 3837 return NO; | 3806 return NO; |
| 3838 } | 3807 } |
| 3839 | 3808 |
| 3840 GURL requestURL = net::GURLWithNSURL(action.request.URL); | 3809 GURL requestURL = net::GURLWithNSURL(action.request.URL); |
| 3841 return [_delegate respondsToSelector:@selector(webController: | 3810 return [_delegate respondsToSelector:@selector(webController: |
| 3842 shouldOpenExternalURL:)] && | 3811 shouldOpenExternalURL:)] && |
| 3843 [_delegate webController:self shouldOpenExternalURL:requestURL]; | 3812 [_delegate webController:self shouldOpenExternalURL:requestURL]; |
| 3844 } | 3813 } |
| 3845 | 3814 |
| 3846 - (BOOL)urlTriggersNativeAppLaunch:(const GURL&)URL | |
| 3847 sourceURL:(const GURL&)sourceURL | |
| 3848 linkActivatedNavigation:(BOOL)linkActivatedNavigation { | |
| 3849 if (![_delegate respondsToSelector:@selector(urlTriggersNativeAppLaunch: | |
| 3850 sourceURL: | |
| 3851 linkClicked:)]) { | |
| 3852 return NO; | |
| 3853 } | |
| 3854 return [_delegate urlTriggersNativeAppLaunch:URL | |
| 3855 sourceURL:sourceURL | |
| 3856 linkClicked:linkActivatedNavigation]; | |
| 3857 } | |
| 3858 | |
| 3859 - (CGFloat)headerHeight { | 3815 - (CGFloat)headerHeight { |
| 3860 if (![_delegate respondsToSelector:@selector(headerHeightForWebController:)]) | 3816 if (![_delegate respondsToSelector:@selector(headerHeightForWebController:)]) |
| 3861 return 0.0f; | 3817 return 0.0f; |
| 3862 return [_delegate headerHeightForWebController:self]; | 3818 return [_delegate headerHeightForWebController:self]; |
| 3863 } | 3819 } |
| 3864 | 3820 |
| 3865 - (void)updateSSLStatusForCurrentNavigationItem { | 3821 - (void)updateSSLStatusForCurrentNavigationItem { |
| 3866 if (_isBeingDestroyed) { | 3822 if (_isBeingDestroyed) { |
| 3867 return; | 3823 return; |
| 3868 } | 3824 } |
| (...skipping 1372 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5241 - (NSUInteger)observerCount { | 5197 - (NSUInteger)observerCount { |
| 5242 DCHECK_EQ(_observerBridges.size(), [_observers count]); | 5198 DCHECK_EQ(_observerBridges.size(), [_observers count]); |
| 5243 return [_observers count]; | 5199 return [_observers count]; |
| 5244 } | 5200 } |
| 5245 | 5201 |
| 5246 - (NSString*)referrerFromNavigationAction:(WKNavigationAction*)action { | 5202 - (NSString*)referrerFromNavigationAction:(WKNavigationAction*)action { |
| 5247 return [action.request valueForHTTPHeaderField:kReferrerHeaderName]; | 5203 return [action.request valueForHTTPHeaderField:kReferrerHeaderName]; |
| 5248 } | 5204 } |
| 5249 | 5205 |
| 5250 @end | 5206 @end |
| OLD | NEW |