| 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 #include <stddef.h> | 8 #include <stddef.h> |
| 9 | 9 |
| 10 #include <utility> | 10 #include <utility> |
| (...skipping 439 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 450 - (void)evaluateUserJavaScript:(NSString*)script { | 450 - (void)evaluateUserJavaScript:(NSString*)script { |
| 451 [self setUserInteractionRegistered:YES]; | 451 [self setUserInteractionRegistered:YES]; |
| 452 web::EvaluateJavaScript(_wkWebView, script, nil); | 452 web::EvaluateJavaScript(_wkWebView, script, nil); |
| 453 } | 453 } |
| 454 | 454 |
| 455 - (void)terminateNetworkActivity { | 455 - (void)terminateNetworkActivity { |
| 456 web::CertStore::GetInstance()->RemoveCertsForGroup(self.certGroupID); | 456 web::CertStore::GetInstance()->RemoveCertsForGroup(self.certGroupID); |
| 457 [super terminateNetworkActivity]; | 457 [super terminateNetworkActivity]; |
| 458 } | 458 } |
| 459 | 459 |
| 460 - (void)setPageDialogOpenPolicy:(web::PageDialogOpenPolicy)policy { | |
| 461 // TODO(eugenebut): implement dialogs/windows suppression using | |
| 462 // WKNavigationDelegate methods where possible. | |
| 463 [super setPageDialogOpenPolicy:policy]; | |
| 464 } | |
| 465 | |
| 466 - (void)close { | 460 - (void)close { |
| 467 [_certVerificationController shutDown]; | 461 [_certVerificationController shutDown]; |
| 468 [super close]; | 462 [super close]; |
| 469 } | 463 } |
| 470 | 464 |
| 471 - (void)stopLoading { | 465 - (void)stopLoading { |
| 472 _stoppedWKNavigation.reset(_latestWKNavigation); | 466 _stoppedWKNavigation.reset(_latestWKNavigation); |
| 473 [super stopLoading]; | 467 [super stopLoading]; |
| 474 } | 468 } |
| 475 | 469 |
| (...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 690 - (void)abortWebLoad { | 684 - (void)abortWebLoad { |
| 691 [_wkWebView stopLoading]; | 685 [_wkWebView stopLoading]; |
| 692 [_pendingNavigationInfo setCancelled:YES]; | 686 [_pendingNavigationInfo setCancelled:YES]; |
| 693 _certVerificationErrors->Clear(); | 687 _certVerificationErrors->Clear(); |
| 694 } | 688 } |
| 695 | 689 |
| 696 - (void)resetLoadState { | 690 - (void)resetLoadState { |
| 697 // Nothing to do. | 691 // Nothing to do. |
| 698 } | 692 } |
| 699 | 693 |
| 700 - (void)setSuppressDialogsWithHelperScript:(NSString*)script { | |
| 701 [self evaluateJavaScript:script stringResultHandler:nil]; | |
| 702 } | |
| 703 | |
| 704 - (void)applyWebViewScrollZoomScaleFromZoomState: | 694 - (void)applyWebViewScrollZoomScaleFromZoomState: |
| 705 (const web::PageZoomState&)zoomState { | 695 (const web::PageZoomState&)zoomState { |
| 706 // After rendering a web page, WKWebView keeps the |minimumZoomScale| and | 696 // After rendering a web page, WKWebView keeps the |minimumZoomScale| and |
| 707 // |maximumZoomScale| properties of its scroll view constant while adjusting | 697 // |maximumZoomScale| properties of its scroll view constant while adjusting |
| 708 // the |zoomScale| property accordingly. The maximum-scale or minimum-scale | 698 // the |zoomScale| property accordingly. The maximum-scale or minimum-scale |
| 709 // meta tags of a page may have changed since the state was recorded, so clamp | 699 // meta tags of a page may have changed since the state was recorded, so clamp |
| 710 // the zoom scale to the current range if necessary. | 700 // the zoom scale to the current range if necessary. |
| 711 DCHECK(zoomState.IsValid()); | 701 DCHECK(zoomState.IsValid()); |
| 712 // Legacy-format scroll states cannot be applied to WKWebViews. | 702 // Legacy-format scroll states cannot be applied to WKWebViews. |
| 713 if (zoomState.IsLegacyFormat()) | 703 if (zoomState.IsLegacyFormat()) |
| (...skipping 494 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1208 - (void)handleHTTPAuthForChallenge:(NSURLAuthenticationChallenge*)challenge | 1198 - (void)handleHTTPAuthForChallenge:(NSURLAuthenticationChallenge*)challenge |
| 1209 completionHandler: | 1199 completionHandler: |
| 1210 (void (^)(NSURLSessionAuthChallengeDisposition, | 1200 (void (^)(NSURLSessionAuthChallengeDisposition, |
| 1211 NSURLCredential*))completionHandler { | 1201 NSURLCredential*))completionHandler { |
| 1212 NSURLProtectionSpace* space = challenge.protectionSpace; | 1202 NSURLProtectionSpace* space = challenge.protectionSpace; |
| 1213 DCHECK( | 1203 DCHECK( |
| 1214 [space.authenticationMethod isEqual:NSURLAuthenticationMethodHTTPBasic] || | 1204 [space.authenticationMethod isEqual:NSURLAuthenticationMethodHTTPBasic] || |
| 1215 [space.authenticationMethod isEqual:NSURLAuthenticationMethodNTLM] || | 1205 [space.authenticationMethod isEqual:NSURLAuthenticationMethodNTLM] || |
| 1216 [space.authenticationMethod isEqual:NSURLAuthenticationMethodHTTPDigest]); | 1206 [space.authenticationMethod isEqual:NSURLAuthenticationMethodHTTPDigest]); |
| 1217 | 1207 |
| 1208 if (self.suppressDialogs) { |
| 1209 [self didSuppressDialog]; |
| 1210 completionHandler(NSURLSessionAuthChallengeRejectProtectionSpace, nil); |
| 1211 return; |
| 1212 } |
| 1213 |
| 1218 SEL selector = @selector(webController: | 1214 SEL selector = @selector(webController: |
| 1219 runAuthDialogForProtectionSpace: | 1215 runAuthDialogForProtectionSpace: |
| 1220 proposedCredential: | 1216 proposedCredential: |
| 1221 completionHandler:); | 1217 completionHandler:); |
| 1222 if (![self.UIDelegate respondsToSelector:selector]) { | 1218 if (![self.UIDelegate respondsToSelector:selector]) { |
| 1223 // Embedder does not support HTTP Authentication. | 1219 // Embedder does not support HTTP Authentication. |
| 1224 completionHandler(NSURLSessionAuthChallengeRejectProtectionSpace, nil); | 1220 completionHandler(NSURLSessionAuthChallengeRejectProtectionSpace, nil); |
| 1225 return; | 1221 return; |
| 1226 } | 1222 } |
| 1227 | 1223 |
| (...skipping 746 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1974 _certVerificationErrors->Clear(); | 1970 _certVerificationErrors->Clear(); |
| 1975 [self webViewWebProcessDidCrash]; | 1971 [self webViewWebProcessDidCrash]; |
| 1976 } | 1972 } |
| 1977 | 1973 |
| 1978 #pragma mark WKUIDelegate Methods | 1974 #pragma mark WKUIDelegate Methods |
| 1979 | 1975 |
| 1980 - (WKWebView*)webView:(WKWebView*)webView | 1976 - (WKWebView*)webView:(WKWebView*)webView |
| 1981 createWebViewWithConfiguration:(WKWebViewConfiguration*)configuration | 1977 createWebViewWithConfiguration:(WKWebViewConfiguration*)configuration |
| 1982 forNavigationAction:(WKNavigationAction*)navigationAction | 1978 forNavigationAction:(WKNavigationAction*)navigationAction |
| 1983 windowFeatures:(WKWindowFeatures*)windowFeatures { | 1979 windowFeatures:(WKWindowFeatures*)windowFeatures { |
| 1980 if (self.suppressDialogs) { |
| 1981 [self didSuppressDialog]; |
| 1982 return nil; |
| 1983 } |
| 1984 |
| 1984 GURL requestURL = net::GURLWithNSURL(navigationAction.request.URL); | 1985 GURL requestURL = net::GURLWithNSURL(navigationAction.request.URL); |
| 1985 | 1986 |
| 1986 if (![self userIsInteracting]) { | 1987 if (![self userIsInteracting]) { |
| 1987 NSString* referer = GetRefererFromNavigationAction(navigationAction); | 1988 NSString* referer = GetRefererFromNavigationAction(navigationAction); |
| 1988 GURL referrerURL = | 1989 GURL referrerURL = |
| 1989 referer ? GURL(base::SysNSStringToUTF8(referer)) : [self currentURL]; | 1990 referer ? GURL(base::SysNSStringToUTF8(referer)) : [self currentURL]; |
| 1990 if ([self shouldBlockPopupWithURL:requestURL sourceURL:referrerURL]) { | 1991 if ([self shouldBlockPopupWithURL:requestURL sourceURL:referrerURL]) { |
| 1991 [self didBlockPopupWithURL:requestURL sourceURL:referrerURL]; | 1992 [self didBlockPopupWithURL:requestURL sourceURL:referrerURL]; |
| 1992 // Desktop Chrome does not return a window for the blocked popups; | 1993 // Desktop Chrome does not return a window for the blocked popups; |
| 1993 // follow the same approach by returning nil; | 1994 // follow the same approach by returning nil; |
| (...skipping 15 matching lines...) Expand all Loading... |
| 2009 - (void)webViewDidClose:(WKWebView*)webView { | 2010 - (void)webViewDidClose:(WKWebView*)webView { |
| 2010 if (self.sessionController.openedByDOM) { | 2011 if (self.sessionController.openedByDOM) { |
| 2011 [self.delegate webPageOrderedClose]; | 2012 [self.delegate webPageOrderedClose]; |
| 2012 } | 2013 } |
| 2013 } | 2014 } |
| 2014 | 2015 |
| 2015 - (void)webView:(WKWebView*)webView | 2016 - (void)webView:(WKWebView*)webView |
| 2016 runJavaScriptAlertPanelWithMessage:(NSString*)message | 2017 runJavaScriptAlertPanelWithMessage:(NSString*)message |
| 2017 initiatedByFrame:(WKFrameInfo*)frame | 2018 initiatedByFrame:(WKFrameInfo*)frame |
| 2018 completionHandler:(void(^)())completionHandler { | 2019 completionHandler:(void(^)())completionHandler { |
| 2020 if (self.suppressDialogs) { |
| 2021 [self didSuppressDialog]; |
| 2022 completionHandler(); |
| 2023 return; |
| 2024 } |
| 2025 |
| 2019 SEL alertSelector = @selector(webController: | 2026 SEL alertSelector = @selector(webController: |
| 2020 runJavaScriptAlertPanelWithMessage: | 2027 runJavaScriptAlertPanelWithMessage: |
| 2021 requestURL: | 2028 requestURL: |
| 2022 completionHandler:); | 2029 completionHandler:); |
| 2023 if ([self.UIDelegate respondsToSelector:alertSelector]) { | 2030 if ([self.UIDelegate respondsToSelector:alertSelector]) { |
| 2024 [self.UIDelegate webController:self | 2031 [self.UIDelegate webController:self |
| 2025 runJavaScriptAlertPanelWithMessage:message | 2032 runJavaScriptAlertPanelWithMessage:message |
| 2026 requestURL:net::GURLWithNSURL(frame.request.URL) | 2033 requestURL:net::GURLWithNSURL(frame.request.URL) |
| 2027 completionHandler:completionHandler]; | 2034 completionHandler:completionHandler]; |
| 2028 } else if (completionHandler) { | 2035 } else if (completionHandler) { |
| 2029 completionHandler(); | 2036 completionHandler(); |
| 2030 } | 2037 } |
| 2031 } | 2038 } |
| 2032 | 2039 |
| 2033 - (void)webView:(WKWebView*)webView | 2040 - (void)webView:(WKWebView*)webView |
| 2034 runJavaScriptConfirmPanelWithMessage:(NSString*)message | 2041 runJavaScriptConfirmPanelWithMessage:(NSString*)message |
| 2035 initiatedByFrame:(WKFrameInfo*)frame | 2042 initiatedByFrame:(WKFrameInfo*)frame |
| 2036 completionHandler: | 2043 completionHandler: |
| 2037 (void (^)(BOOL result))completionHandler { | 2044 (void (^)(BOOL result))completionHandler { |
| 2045 if (self.suppressDialogs) { |
| 2046 [self didSuppressDialog]; |
| 2047 completionHandler(NO); |
| 2048 return; |
| 2049 } |
| 2050 |
| 2038 SEL confirmationSelector = @selector(webController: | 2051 SEL confirmationSelector = @selector(webController: |
| 2039 runJavaScriptConfirmPanelWithMessage: | 2052 runJavaScriptConfirmPanelWithMessage: |
| 2040 requestURL: | 2053 requestURL: |
| 2041 completionHandler:); | 2054 completionHandler:); |
| 2042 if ([self.UIDelegate respondsToSelector:confirmationSelector]) { | 2055 if ([self.UIDelegate respondsToSelector:confirmationSelector]) { |
| 2043 [self.UIDelegate webController:self | 2056 [self.UIDelegate webController:self |
| 2044 runJavaScriptConfirmPanelWithMessage:message | 2057 runJavaScriptConfirmPanelWithMessage:message |
| 2045 requestURL: | 2058 requestURL: |
| 2046 net::GURLWithNSURL(frame.request.URL) | 2059 net::GURLWithNSURL(frame.request.URL) |
| 2047 completionHandler:completionHandler]; | 2060 completionHandler:completionHandler]; |
| 2048 } else if (completionHandler) { | 2061 } else if (completionHandler) { |
| 2049 completionHandler(NO); | 2062 completionHandler(NO); |
| 2050 } | 2063 } |
| 2051 } | 2064 } |
| 2052 | 2065 |
| 2053 - (void)webView:(WKWebView*)webView | 2066 - (void)webView:(WKWebView*)webView |
| 2054 runJavaScriptTextInputPanelWithPrompt:(NSString*)prompt | 2067 runJavaScriptTextInputPanelWithPrompt:(NSString*)prompt |
| 2055 defaultText:(NSString*)defaultText | 2068 defaultText:(NSString*)defaultText |
| 2056 initiatedByFrame:(WKFrameInfo*)frame | 2069 initiatedByFrame:(WKFrameInfo*)frame |
| 2057 completionHandler: | 2070 completionHandler: |
| 2058 (void (^)(NSString *result))completionHandler { | 2071 (void (^)(NSString *result))completionHandler { |
| 2072 if (self.suppressDialogs) { |
| 2073 [self didSuppressDialog]; |
| 2074 completionHandler(nil); |
| 2075 return; |
| 2076 } |
| 2077 |
| 2059 SEL textInputSelector = @selector(webController: | 2078 SEL textInputSelector = @selector(webController: |
| 2060 runJavaScriptTextInputPanelWithPrompt: | 2079 runJavaScriptTextInputPanelWithPrompt: |
| 2061 defaultText: | 2080 defaultText: |
| 2062 requestURL: | 2081 requestURL: |
| 2063 completionHandler:); | 2082 completionHandler:); |
| 2064 if ([self.UIDelegate respondsToSelector:textInputSelector]) { | 2083 if ([self.UIDelegate respondsToSelector:textInputSelector]) { |
| 2065 GURL requestURL = net::GURLWithNSURL(frame.request.URL); | 2084 GURL requestURL = net::GURLWithNSURL(frame.request.URL); |
| 2066 [self.UIDelegate webController:self | 2085 [self.UIDelegate webController:self |
| 2067 runJavaScriptTextInputPanelWithPrompt:prompt | 2086 runJavaScriptTextInputPanelWithPrompt:prompt |
| 2068 defaultText:defaultText | 2087 defaultText:defaultText |
| 2069 requestURL:requestURL | 2088 requestURL:requestURL |
| 2070 completionHandler:completionHandler]; | 2089 completionHandler:completionHandler]; |
| 2071 } else if (completionHandler) { | 2090 } else if (completionHandler) { |
| 2072 completionHandler(nil); | 2091 completionHandler(nil); |
| 2073 } | 2092 } |
| 2074 } | 2093 } |
| 2075 | 2094 |
| 2076 @end | 2095 @end |
| OLD | NEW |