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> |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 71 #import "ios/web/public/web_state/js/crw_js_injection_receiver.h" | 71 #import "ios/web/public/web_state/js/crw_js_injection_receiver.h" |
| 72 #import "ios/web/public/web_state/page_display_state.h" | 72 #import "ios/web/public/web_state/page_display_state.h" |
| 73 #import "ios/web/public/web_state/ui/crw_content_view.h" | 73 #import "ios/web/public/web_state/ui/crw_content_view.h" |
| 74 #import "ios/web/public/web_state/ui/crw_context_menu_delegate.h" | 74 #import "ios/web/public/web_state/ui/crw_context_menu_delegate.h" |
| 75 #import "ios/web/public/web_state/ui/crw_native_content.h" | 75 #import "ios/web/public/web_state/ui/crw_native_content.h" |
| 76 #import "ios/web/public/web_state/ui/crw_native_content_provider.h" | 76 #import "ios/web/public/web_state/ui/crw_native_content_provider.h" |
| 77 #import "ios/web/public/web_state/ui/crw_web_view_content_view.h" | 77 #import "ios/web/public/web_state/ui/crw_web_view_content_view.h" |
| 78 #include "ios/web/public/web_state/url_verification_constants.h" | 78 #include "ios/web/public/web_state/url_verification_constants.h" |
| 79 #import "ios/web/public/web_state/web_state.h" | 79 #import "ios/web/public/web_state/web_state.h" |
| 80 #include "ios/web/public/webui/web_ui_ios.h" | 80 #include "ios/web/public/webui/web_ui_ios.h" |
| 81 #import "ios/web/web_state/blocked_popup_info.h" | |
| 82 #import "ios/web/web_state/crw_pass_kit_downloader.h" | 81 #import "ios/web/web_state/crw_pass_kit_downloader.h" |
| 83 #import "ios/web/web_state/crw_web_view_proxy_impl.h" | 82 #import "ios/web/web_state/crw_web_view_proxy_impl.h" |
| 84 #import "ios/web/web_state/error_translation_util.h" | 83 #import "ios/web/web_state/error_translation_util.h" |
| 85 #import "ios/web/web_state/js/crw_js_plugin_placeholder_manager.h" | 84 #import "ios/web/web_state/js/crw_js_plugin_placeholder_manager.h" |
| 86 #import "ios/web/web_state/js/crw_js_post_request_loader.h" | 85 #import "ios/web/web_state/js/crw_js_post_request_loader.h" |
| 87 #import "ios/web/web_state/js/crw_js_window_id_manager.h" | 86 #import "ios/web/web_state/js/crw_js_window_id_manager.h" |
| 88 #import "ios/web/web_state/page_viewport_state.h" | 87 #import "ios/web/web_state/page_viewport_state.h" |
| 89 #import "ios/web/web_state/ui/crw_context_menu_controller.h" | 88 #import "ios/web/web_state/ui/crw_context_menu_controller.h" |
| 90 #import "ios/web/web_state/ui/crw_swipe_recognizer_provider.h" | 89 #import "ios/web/web_state/ui/crw_swipe_recognizer_provider.h" |
| 91 #import "ios/web/web_state/ui/crw_web_controller.h" | 90 #import "ios/web/web_state/ui/crw_web_controller.h" |
| 92 #import "ios/web/web_state/ui/crw_web_controller_container_view.h" | 91 #import "ios/web/web_state/ui/crw_web_controller_container_view.h" |
| 93 #import "ios/web/web_state/ui/crw_wk_navigation_states.h" | 92 #import "ios/web/web_state/ui/crw_wk_navigation_states.h" |
| 94 #import "ios/web/web_state/ui/crw_wk_script_message_router.h" | 93 #import "ios/web/web_state/ui/crw_wk_script_message_router.h" |
| 95 #import "ios/web/web_state/ui/wk_back_forward_list_item_holder.h" | 94 #import "ios/web/web_state/ui/wk_back_forward_list_item_holder.h" |
| 96 #import "ios/web/web_state/ui/wk_web_view_configuration_provider.h" | 95 #import "ios/web/web_state/ui/wk_web_view_configuration_provider.h" |
| 97 #import "ios/web/web_state/web_controller_observer_bridge.h" | 96 #import "ios/web/web_state/web_controller_observer_bridge.h" |
| 98 #include "ios/web/web_state/web_state_facade_delegate.h" | 97 #include "ios/web/web_state/web_state_facade_delegate.h" |
| 99 #import "ios/web/web_state/web_state_impl.h" | 98 #import "ios/web/web_state/web_state_impl.h" |
| 100 #import "ios/web/web_state/web_view_internal_creation_util.h" | 99 #import "ios/web/web_state/web_view_internal_creation_util.h" |
| 101 #import "ios/web/web_state/wk_web_view_security_util.h" | 100 #import "ios/web/web_state/wk_web_view_security_util.h" |
| 102 #import "ios/web/webui/crw_web_ui_manager.h" | 101 #import "ios/web/webui/crw_web_ui_manager.h" |
| 103 #import "ios/web/webui/mojo_facade.h" | 102 #import "ios/web/webui/mojo_facade.h" |
| 104 #import "net/base/mac/url_conversions.h" | 103 #import "net/base/mac/url_conversions.h" |
| 105 #include "net/base/net_errors.h" | 104 #include "net/base/net_errors.h" |
| 105 #include "net/ssl/ssl_info.h" | |
| 106 #include "services/service_manager/public/cpp/interface_registry.h" | 106 #include "services/service_manager/public/cpp/interface_registry.h" |
| 107 #include "ui/base/page_transition_types.h" | 107 #include "ui/base/page_transition_types.h" |
| 108 #include "url/gurl.h" | 108 #include "url/gurl.h" |
| 109 #include "url/url_constants.h" | 109 #include "url/url_constants.h" |
| 110 | 110 |
| 111 using base::UserMetricsAction; | 111 using base::UserMetricsAction; |
| 112 using web::NavigationManager; | 112 using web::NavigationManager; |
| 113 using web::NavigationManagerImpl; | 113 using web::NavigationManagerImpl; |
| 114 using web::WebState; | 114 using web::WebState; |
| 115 using web::WebStateImpl; | 115 using web::WebStateImpl; |
| (...skipping 564 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 680 // This is called after |-applyWebViewScrollZoomScaleFromScrollState:|. | 680 // This is called after |-applyWebViewScrollZoomScaleFromScrollState:|. |
| 681 - (void)finishApplyingWebViewScrollZoomScale; | 681 - (void)finishApplyingWebViewScrollZoomScale; |
| 682 // Sets zoom scale value for webview scroll view from |zoomState|. | 682 // Sets zoom scale value for webview scroll view from |zoomState|. |
| 683 - (void)applyWebViewScrollZoomScaleFromZoomState: | 683 - (void)applyWebViewScrollZoomScaleFromZoomState: |
| 684 (const web::PageZoomState&)zoomState; | 684 (const web::PageZoomState&)zoomState; |
| 685 // Sets scroll offset value for webview scroll view from |scrollState|. | 685 // Sets scroll offset value for webview scroll view from |scrollState|. |
| 686 - (void)applyWebViewScrollOffsetFromScrollState: | 686 - (void)applyWebViewScrollOffsetFromScrollState: |
| 687 (const web::PageScrollState&)scrollState; | 687 (const web::PageScrollState&)scrollState; |
| 688 // Returns the referrer for the current page. | 688 // Returns the referrer for the current page. |
| 689 - (web::Referrer)currentReferrer; | 689 - (web::Referrer)currentReferrer; |
| 690 // Asynchronously returns the referrer policy for the current page. | |
| 691 - (void)queryPageReferrerPolicy:(void (^)(NSString*))responseHandler; | |
| 692 // Adds a new CRWSessionEntry with the given URL and state object to the history | 690 // Adds a new CRWSessionEntry with the given URL and state object to the history |
| 693 // stack. A state object is a serialized generic JavaScript object that contains | 691 // stack. A state object is a serialized generic JavaScript object that contains |
| 694 // details of the UI's state for a given CRWSessionEntry/URL. | 692 // details of the UI's state for a given CRWSessionEntry/URL. |
| 695 // TODO(stuartmorgan): Move the pushState/replaceState logic into | 693 // TODO(stuartmorgan): Move the pushState/replaceState logic into |
| 696 // NavigationManager. | 694 // NavigationManager. |
| 697 - (void)pushStateWithPageURL:(const GURL&)pageURL | 695 - (void)pushStateWithPageURL:(const GURL&)pageURL |
| 698 stateObject:(NSString*)stateObject | 696 stateObject:(NSString*)stateObject |
| 699 transition:(ui::PageTransition)transition; | 697 transition:(ui::PageTransition)transition; |
| 700 // Assigns the given URL and state object to the current CRWSessionEntry. | 698 // Assigns the given URL and state object to the current CRWSessionEntry. |
| 701 - (void)replaceStateWithPageURL:(const GURL&)pageUrl | 699 - (void)replaceStateWithPageURL:(const GURL&)pageUrl |
| 702 stateObject:(NSString*)stateObject; | 700 stateObject:(NSString*)stateObject; |
| 703 // Sets _documentURL to newURL, and updates any relevant state information. | 701 // Sets _documentURL to newURL, and updates any relevant state information. |
| 704 - (void)setDocumentURL:(const GURL&)newURL; | 702 - (void)setDocumentURL:(const GURL&)newURL; |
| 705 // Sets last committed NavigationItem's title to the given |title|, which can | 703 // Sets last committed NavigationItem's title to the given |title|, which can |
| 706 // not be nil. | 704 // not be nil. |
| 707 - (void)setNavigationItemTitle:(NSString*)title; | 705 - (void)setNavigationItemTitle:(NSString*)title; |
| 708 // Returns YES if the current navigation item corresponds to a web page | 706 // Returns YES if the current navigation item corresponds to a web page |
| 709 // loaded by a POST request. | 707 // loaded by a POST request. |
| 710 - (BOOL)isCurrentNavigationItemPOST; | 708 - (BOOL)isCurrentNavigationItemPOST; |
| 711 // Returns YES if current navigation item is WKNavigationTypeBackForward. | 709 // Returns YES if current navigation item is WKNavigationTypeBackForward. |
| 712 - (BOOL)isCurrentNavigationBackForward; | 710 - (BOOL)isCurrentNavigationBackForward; |
| 713 // Returns whether the given navigation is triggered by a user link click. | 711 // Returns whether the given navigation is triggered by a user link click. |
| 714 - (BOOL)isLinkNavigation:(WKNavigationType)navigationType; | 712 - (BOOL)isLinkNavigation:(WKNavigationType)navigationType; |
| 715 | 713 |
| 716 // Inject windowID if not yet injected. | 714 // Inject windowID if not yet injected. |
| 717 - (void)injectWindowID; | 715 - (void)injectWindowID; |
| 718 // Creates a new opened by DOM window and returns its autoreleased web | |
| 719 // controller. | |
| 720 - (CRWWebController*)createChildWebController; | |
| 721 | 716 |
| 722 // Returns YES if the given WKBackForwardListItem is valid to use for | 717 // Returns YES if the given WKBackForwardListItem is valid to use for |
| 723 // navigation. | 718 // navigation. |
| 724 - (BOOL)isBackForwardListItemValid:(WKBackForwardListItem*)item; | 719 - (BOOL)isBackForwardListItemValid:(WKBackForwardListItem*)item; |
| 725 // Compares the two URLs being navigated between during a history navigation to | 720 // Compares the two URLs being navigated between during a history navigation to |
| 726 // determine if a # needs to be appended to the URL of |toItem| to trigger a | 721 // determine if a # needs to be appended to the URL of |toItem| to trigger a |
| 727 // hashchange event. If so, also saves the modified URL into |toItem|. | 722 // hashchange event. If so, also saves the modified URL into |toItem|. |
| 728 - (GURL)URLForHistoryNavigationFromItem:(web::NavigationItem*)fromItem | 723 - (GURL)URLForHistoryNavigationFromItem:(web::NavigationItem*)fromItem |
| 729 toItem:(web::NavigationItem*)toItem; | 724 toItem:(web::NavigationItem*)toItem; |
| 730 | 725 |
| 731 // Finds all the scrollviews in the view hierarchy and makes sure they do not | 726 // Finds all the scrollviews in the view hierarchy and makes sure they do not |
| 732 // interfere with scroll to top when tapping the statusbar. | 727 // interfere with scroll to top when tapping the statusbar. |
| 733 - (void)optOutScrollsToTopForSubviews; | 728 - (void)optOutScrollsToTopForSubviews; |
| 734 // Tears down the old native controller, and then replaces it with the new one. | 729 // Tears down the old native controller, and then replaces it with the new one. |
| 735 - (void)setNativeController:(id<CRWNativeContent>)nativeController; | 730 - (void)setNativeController:(id<CRWNativeContent>)nativeController; |
| 736 // Returns whether |url| should be opened. | 731 // Returns whether |url| should be opened. |
| 737 - (BOOL)shouldOpenURL:(const GURL&)url | 732 - (BOOL)shouldOpenURL:(const GURL&)url |
| 738 mainDocumentURL:(const GURL&)mainDocumentURL | 733 mainDocumentURL:(const GURL&)mainDocumentURL |
| 739 linkClicked:(BOOL)linkClicked; | 734 linkClicked:(BOOL)linkClicked; |
| 740 // 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. |
| 741 // 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. |
| 742 - (BOOL)urlTriggersNativeAppLaunch:(const GURL&)URL | 737 - (BOOL)urlTriggersNativeAppLaunch:(const GURL&)URL |
| 743 sourceURL:(const GURL&)sourceURL | 738 sourceURL:(const GURL&)sourceURL |
| 744 linkActivatedNavigation:(BOOL)linkActivatedNavigation; | 739 linkActivatedNavigation:(BOOL)linkActivatedNavigation; |
| 745 // Called when a JavaScript dialog, HTTP authentication dialog or window.open | 740 // Called when a JavaScript dialog, HTTP authentication dialog or window.open |
| 746 // call has been suppressed. | 741 // call has been suppressed. |
| 747 - (void)didSuppressDialog; | 742 - (void)didSuppressDialog; |
| 748 // Convenience method to inform CWRWebDelegate about a blocked popup. | |
| 749 - (void)didBlockPopupWithURL:(GURL)popupURL sourceURL:(GURL)sourceURL; | |
| 750 // Informs CWRWebDelegate that CRWWebController has detected and blocked a | |
| 751 // popup. | |
| 752 - (void)didBlockPopupWithURL:(GURL)popupURL | |
| 753 sourceURL:(GURL)sourceURL | |
| 754 referrerPolicy:(const std::string&)referrerPolicyString; | |
| 755 // Returns YES if the navigation action is associated with a main frame request. | 743 // Returns YES if the navigation action is associated with a main frame request. |
| 756 - (BOOL)isMainFrameNavigationAction:(WKNavigationAction*)action; | 744 - (BOOL)isMainFrameNavigationAction:(WKNavigationAction*)action; |
| 757 // Returns whether external URL navigation action should be opened. | 745 // Returns whether external URL navigation action should be opened. |
| 758 - (BOOL)shouldOpenExternalURLForNavigationAction:(WKNavigationAction*)action; | 746 - (BOOL)shouldOpenExternalURLForNavigationAction:(WKNavigationAction*)action; |
| 759 // Called when a page updates its history stack using pushState or replaceState. | 747 // Called when a page updates its history stack using pushState or replaceState. |
| 760 - (void)didUpdateHistoryStateWithPageURL:(const GURL&)url; | 748 - (void)didUpdateHistoryStateWithPageURL:(const GURL&)url; |
| 761 // Updates SSL status for the current navigation item based on the information | 749 // Updates SSL status for the current navigation item based on the information |
| 762 // provided by web view. | 750 // provided by web view. |
| 763 - (void)updateSSLStatusForCurrentNavigationItem; | 751 - (void)updateSSLStatusForCurrentNavigationItem; |
| 764 // Called when SSL status has been updated for the current navigation item. | 752 // Called when SSL status has been updated for the current navigation item. |
| 765 - (void)didUpdateSSLStatusForCurrentNavigationItem; | 753 - (void)didUpdateSSLStatusForCurrentNavigationItem; |
| 766 // Called when a load ends in an SSL error and certificate chain. | 754 // Called when a load ends in an SSL error and certificate chain. |
| 767 - (void)handleSSLCertError:(NSError*)error; | 755 - (void)handleSSLCertError:(NSError*)error; |
| 768 | 756 |
| 769 // Returns YES if the popup should be blocked, NO otherwise. | |
| 770 - (BOOL)shouldBlockPopupWithURL:(const GURL&)popupURL | |
| 771 sourceURL:(const GURL&)sourceURL; | |
| 772 | |
| 773 // Used in webView:didReceiveAuthenticationChallenge:completionHandler: to | 757 // Used in webView:didReceiveAuthenticationChallenge:completionHandler: to |
| 774 // reply with NSURLSessionAuthChallengeDisposition and credentials. | 758 // reply with NSURLSessionAuthChallengeDisposition and credentials. |
| 775 - (void)processAuthChallenge:(NSURLAuthenticationChallenge*)challenge | 759 - (void)processAuthChallenge:(NSURLAuthenticationChallenge*)challenge |
| 776 forCertAcceptPolicy:(web::CertAcceptPolicy)policy | 760 forCertAcceptPolicy:(web::CertAcceptPolicy)policy |
| 777 certStatus:(net::CertStatus)certStatus | 761 certStatus:(net::CertStatus)certStatus |
| 778 completionHandler:(void (^)(NSURLSessionAuthChallengeDisposition, | 762 completionHandler:(void (^)(NSURLSessionAuthChallengeDisposition, |
| 779 NSURLCredential*))completionHandler; | 763 NSURLCredential*))completionHandler; |
| 780 // Used in webView:didReceiveAuthenticationChallenge:completionHandler: to reply | 764 // Used in webView:didReceiveAuthenticationChallenge:completionHandler: to reply |
| 781 // with NSURLSessionAuthChallengeDisposition and credentials. | 765 // with NSURLSessionAuthChallengeDisposition and credentials. |
| 782 - (void)handleHTTPAuthForChallenge:(NSURLAuthenticationChallenge*)challenge | 766 - (void)handleHTTPAuthForChallenge:(NSURLAuthenticationChallenge*)challenge |
| (...skipping 548 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1331 // policy from the origin has *already* been applied. Since the extracted URL | 1315 // policy from the origin has *already* been applied. Since the extracted URL |
| 1332 // is the post-policy value, and the source policy is no longer available, | 1316 // is the post-policy value, and the source policy is no longer available, |
| 1333 // the policy is set to Always so that whatever WebKit decided to send will be | 1317 // the policy is set to Always so that whatever WebKit decided to send will be |
| 1334 // re-sent when replaying the entry. | 1318 // re-sent when replaying the entry. |
| 1335 // TODO(stuartmorgan): When possible, get the real referrer and policy in | 1319 // TODO(stuartmorgan): When possible, get the real referrer and policy in |
| 1336 // advance and use that instead. https://crbug.com/227769. | 1320 // advance and use that instead. https://crbug.com/227769. |
| 1337 return web::Referrer(GURL(base::SysNSStringToUTF8(referrerString)), | 1321 return web::Referrer(GURL(base::SysNSStringToUTF8(referrerString)), |
| 1338 web::ReferrerPolicyAlways); | 1322 web::ReferrerPolicyAlways); |
| 1339 } | 1323 } |
| 1340 | 1324 |
| 1341 - (void)queryPageReferrerPolicy:(void (^)(NSString*))responseHandler { | |
| 1342 DCHECK(responseHandler); | |
| 1343 [self executeJavaScript:@"__gCrWeb.getPageReferrerPolicy()" | |
| 1344 completionHandler:^(id referrer, NSError* error) { | |
| 1345 DCHECK_NE(error.code, WKErrorJavaScriptExceptionOccurred); | |
| 1346 responseHandler(base::mac::ObjCCast<NSString>(referrer)); | |
| 1347 }]; | |
| 1348 } | |
| 1349 | |
| 1350 - (void)pushStateWithPageURL:(const GURL&)pageURL | 1325 - (void)pushStateWithPageURL:(const GURL&)pageURL |
| 1351 stateObject:(NSString*)stateObject | 1326 stateObject:(NSString*)stateObject |
| 1352 transition:(ui::PageTransition)transition { | 1327 transition:(ui::PageTransition)transition { |
| 1353 [[self sessionController] pushNewItemWithURL:pageURL | 1328 [[self sessionController] pushNewItemWithURL:pageURL |
| 1354 stateObject:stateObject | 1329 stateObject:stateObject |
| 1355 transition:transition]; | 1330 transition:transition]; |
| 1356 [self didUpdateHistoryStateWithPageURL:pageURL]; | 1331 [self didUpdateHistoryStateWithPageURL:pageURL]; |
| 1357 self.userInteractionRegistered = NO; | 1332 self.userInteractionRegistered = NO; |
| 1358 } | 1333 } |
| 1359 | 1334 |
| (...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1472 // Default value for shouldSuppressDialogs is NO, so updating them only | 1447 // Default value for shouldSuppressDialogs is NO, so updating them only |
| 1473 // when necessary is a good optimization. | 1448 // when necessary is a good optimization. |
| 1474 if (_shouldSuppressDialogsOnWindowIDInjection) { | 1449 if (_shouldSuppressDialogsOnWindowIDInjection) { |
| 1475 self.shouldSuppressDialogs = YES; | 1450 self.shouldSuppressDialogs = YES; |
| 1476 _shouldSuppressDialogsOnWindowIDInjection = NO; | 1451 _shouldSuppressDialogsOnWindowIDInjection = NO; |
| 1477 } | 1452 } |
| 1478 | 1453 |
| 1479 [_windowIDJSManager inject]; | 1454 [_windowIDJSManager inject]; |
| 1480 } | 1455 } |
| 1481 | 1456 |
| 1482 - (CRWWebController*)createChildWebController { | |
| 1483 CRWWebController* result = [self.delegate webPageOrderedOpen]; | |
| 1484 DCHECK(!result || result.sessionController.openedByDOM); | |
| 1485 return result; | |
| 1486 } | |
| 1487 | |
| 1488 - (BOOL)canUseViewForGeneratingOverlayPlaceholderView { | 1457 - (BOOL)canUseViewForGeneratingOverlayPlaceholderView { |
| 1489 return _containerView != nil; | 1458 return _containerView != nil; |
| 1490 } | 1459 } |
| 1491 | 1460 |
| 1492 - (UIView*)view { | 1461 - (UIView*)view { |
| 1493 // Kick off the process of lazily creating the view and starting the load if | 1462 // Kick off the process of lazily creating the view and starting the load if |
| 1494 // necessary; this creates _containerView if it doesn't exist. | 1463 // necessary; this creates _containerView if it doesn't exist. |
| 1495 [self triggerPendingLoad]; | 1464 [self triggerPendingLoad]; |
| 1496 DCHECK(_containerView); | 1465 DCHECK(_containerView); |
| 1497 return _containerView; | 1466 return _containerView; |
| (...skipping 1903 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3401 _webUIManager.reset( | 3370 _webUIManager.reset( |
| 3402 [[CRWWebUIManager alloc] initWithWebState:self.webStateImpl]); | 3371 [[CRWWebUIManager alloc] initWithWebState:self.webStateImpl]); |
| 3403 } | 3372 } |
| 3404 | 3373 |
| 3405 - (void)clearWebUI { | 3374 - (void)clearWebUI { |
| 3406 _webStateImpl->ClearWebUI(); | 3375 _webStateImpl->ClearWebUI(); |
| 3407 _webUIManager.reset(); | 3376 _webUIManager.reset(); |
| 3408 } | 3377 } |
| 3409 | 3378 |
| 3410 #pragma mark - | 3379 #pragma mark - |
| 3411 #pragma mark Popup handling | |
| 3412 | |
| 3413 - (BOOL)shouldBlockPopupWithURL:(const GURL&)popupURL | |
| 3414 sourceURL:(const GURL&)sourceURL { | |
| 3415 if (![_delegate respondsToSelector:@selector(webController: | |
| 3416 shouldBlockPopupWithURL: | |
| 3417 sourceURL:)]) { | |
| 3418 return NO; | |
| 3419 } | |
| 3420 return [_delegate webController:self | |
| 3421 shouldBlockPopupWithURL:popupURL | |
| 3422 sourceURL:sourceURL]; | |
| 3423 } | |
| 3424 | |
| 3425 #pragma mark - | |
| 3426 #pragma mark Auth Challenge | 3380 #pragma mark Auth Challenge |
| 3427 | 3381 |
| 3428 - (void)processAuthChallenge:(NSURLAuthenticationChallenge*)challenge | 3382 - (void)processAuthChallenge:(NSURLAuthenticationChallenge*)challenge |
| 3429 forCertAcceptPolicy:(web::CertAcceptPolicy)policy | 3383 forCertAcceptPolicy:(web::CertAcceptPolicy)policy |
| 3430 certStatus:(net::CertStatus)certStatus | 3384 certStatus:(net::CertStatus)certStatus |
| 3431 completionHandler:(void (^)(NSURLSessionAuthChallengeDisposition, | 3385 completionHandler:(void (^)(NSURLSessionAuthChallengeDisposition, |
| 3432 NSURLCredential*))completionHandler { | 3386 NSURLCredential*))completionHandler { |
| 3433 SecTrustRef trust = challenge.protectionSpace.serverTrust; | 3387 SecTrustRef trust = challenge.protectionSpace.serverTrust; |
| 3434 if (policy == web::CERT_ACCEPT_POLICY_RECOVERABLE_ERROR_ACCEPTED_BY_USER) { | 3388 if (policy == web::CERT_ACCEPT_POLICY_RECOVERABLE_ERROR_ACCEPTED_BY_USER) { |
| 3435 // Cert is invalid, but user agreed to proceed, override default behavior. | 3389 // Cert is invalid, but user agreed to proceed, override default behavior. |
| (...skipping 564 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 4000 shouldOpenURL:url | 3954 shouldOpenURL:url |
| 4001 mainDocumentURL:mainDocumentURL | 3955 mainDocumentURL:mainDocumentURL |
| 4002 linkClicked:linkClicked]; | 3956 linkClicked:linkClicked]; |
| 4003 } | 3957 } |
| 4004 | 3958 |
| 4005 - (void)didSuppressDialog { | 3959 - (void)didSuppressDialog { |
| 4006 if ([_delegate respondsToSelector:@selector(webControllerDidSuppressDialog:)]) | 3960 if ([_delegate respondsToSelector:@selector(webControllerDidSuppressDialog:)]) |
| 4007 [_delegate webControllerDidSuppressDialog:self]; | 3961 [_delegate webControllerDidSuppressDialog:self]; |
| 4008 } | 3962 } |
| 4009 | 3963 |
| 4010 - (void)didBlockPopupWithURL:(GURL)popupURL | |
| 4011 sourceURL:(GURL)sourceURL | |
| 4012 referrerPolicy:(const std::string&)referrerPolicyString { | |
| 4013 web::ReferrerPolicy referrerPolicy = | |
| 4014 web::ReferrerPolicyFromString(referrerPolicyString); | |
| 4015 web::Referrer referrer(sourceURL, referrerPolicy); | |
| 4016 NSString* const kWindowName = @""; // obsoleted | |
| 4017 base::WeakNSObject<CRWWebController> weakSelf(self); | |
| 4018 void (^showPopupHandler)() = ^{ | |
| 4019 // On Desktop cross-window comunication is not supported for unblocked | |
| 4020 // popups; so it's ok to create a new independent page. | |
| 4021 CRWWebController* child = | |
| 4022 [[weakSelf delegate] webPageOrderedOpen:popupURL | |
| 4023 referrer:referrer | |
| 4024 windowName:kWindowName | |
| 4025 inBackground:NO]; | |
| 4026 DCHECK(!child || child.sessionController.openedByDOM); | |
| 4027 }; | |
| 4028 | |
| 4029 web::BlockedPopupInfo info(popupURL, referrer, kWindowName, showPopupHandler); | |
| 4030 [self.delegate webController:self didBlockPopup:info]; | |
| 4031 } | |
| 4032 | |
| 4033 - (void)didBlockPopupWithURL:(GURL)popupURL sourceURL:(GURL)sourceURL { | |
| 4034 if ([_delegate respondsToSelector:@selector(webController:didBlockPopup:)]) { | |
| 4035 base::WeakNSObject<CRWWebController> weakSelf(self); | |
| 4036 dispatch_async(dispatch_get_main_queue(), ^{ | |
| 4037 [self queryPageReferrerPolicy:^(NSString* policy) { | |
| 4038 [weakSelf didBlockPopupWithURL:popupURL | |
| 4039 sourceURL:sourceURL | |
| 4040 referrerPolicy:base::SysNSStringToUTF8(policy)]; | |
| 4041 }]; | |
| 4042 }); | |
| 4043 } | |
| 4044 } | |
| 4045 | |
| 4046 - (BOOL)isMainFrameNavigationAction:(WKNavigationAction*)action { | 3964 - (BOOL)isMainFrameNavigationAction:(WKNavigationAction*)action { |
| 4047 if (action.targetFrame) { | 3965 if (action.targetFrame) { |
| 4048 return action.targetFrame.mainFrame; | 3966 return action.targetFrame.mainFrame; |
| 4049 } | 3967 } |
| 4050 // According to WKNavigationAction documentation, in the case of a new window | 3968 // According to WKNavigationAction documentation, in the case of a new window |
| 4051 // navigation, target frame will be nil. In this case check if the | 3969 // navigation, target frame will be nil. In this case check if the |
| 4052 // |sourceFrame| is the mainFrame. | 3970 // |sourceFrame| is the mainFrame. |
| 4053 return action.sourceFrame.mainFrame; | 3971 return action.sourceFrame.mainFrame; |
| 4054 } | 3972 } |
| 4055 | 3973 |
| (...skipping 374 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 4430 | 4348 |
| 4431 - (WKWebView*)webView:(WKWebView*)webView | 4349 - (WKWebView*)webView:(WKWebView*)webView |
| 4432 createWebViewWithConfiguration:(WKWebViewConfiguration*)configuration | 4350 createWebViewWithConfiguration:(WKWebViewConfiguration*)configuration |
| 4433 forNavigationAction:(WKNavigationAction*)action | 4351 forNavigationAction:(WKNavigationAction*)action |
| 4434 windowFeatures:(WKWindowFeatures*)windowFeatures { | 4352 windowFeatures:(WKWindowFeatures*)windowFeatures { |
| 4435 if (self.shouldSuppressDialogs) { | 4353 if (self.shouldSuppressDialogs) { |
| 4436 [self didSuppressDialog]; | 4354 [self didSuppressDialog]; |
| 4437 return nil; | 4355 return nil; |
| 4438 } | 4356 } |
| 4439 | 4357 |
| 4358 // Do not create windows for non-empty invalid URLs. | |
| 4440 GURL requestURL = net::GURLWithNSURL(action.request.URL); | 4359 GURL requestURL = net::GURLWithNSURL(action.request.URL); |
| 4441 | |
| 4442 // Don't create windows for non-empty invalid URLs. | |
| 4443 if (!requestURL.is_empty() && !requestURL.is_valid()) { | 4360 if (!requestURL.is_empty() && !requestURL.is_valid()) { |
| 4444 DLOG(WARNING) << "Unable to open a window with invalid URL: " | 4361 DLOG(WARNING) << "Unable to open a window with invalid URL: " |
| 4445 << requestURL.spec(); | 4362 << requestURL.spec(); |
| 4446 return nil; | 4363 return nil; |
| 4447 } | 4364 } |
| 4448 | 4365 |
| 4449 if (![self userIsInteracting]) { | 4366 NSString* referer = [self refererFromNavigationAction:action]; |
|
marq (ping after 24h)
2017/02/15 10:34:10
We should be consistent in our spelling of 'referr
Eugene But (OOO till 7-30)
2017/02/15 16:46:59
Done.
| |
| 4450 NSString* referer = [self refererFromNavigationAction:action]; | 4367 GURL openerURL = |
| 4451 GURL referrerURL = | 4368 referer ? GURL(base::SysNSStringToUTF8(referer)) : _documentURL; |
| 4452 referer ? GURL(base::SysNSStringToUTF8(referer)) : [self currentURL]; | 4369 CRWWebController* child = [_delegate webController:self |
| 4453 if ([self shouldBlockPopupWithURL:requestURL sourceURL:referrerURL]) { | 4370 createWebControllerForURL:requestURL |
| 4454 [self didBlockPopupWithURL:requestURL sourceURL:referrerURL]; | 4371 openerURL:openerURL |
| 4455 // Desktop Chrome does not return a window for the blocked popups; | 4372 initiatedByUser:[self userIsInteracting]]; |
| 4456 // follow the same approach by returning nil; | 4373 DCHECK(!child || child.sessionController.openedByDOM); |
| 4457 return nil; | |
| 4458 } | |
| 4459 } | |
| 4460 | 4374 |
| 4461 CRWWebController* child = [self createChildWebController]; | |
| 4462 // WKWebView requires WKUIDelegate to return a child view created with | 4375 // WKWebView requires WKUIDelegate to return a child view created with |
| 4463 // exactly the same |configuration| object (exception is raised if config is | 4376 // exactly the same |configuration| object (exception is raised if config is |
| 4464 // different). |configuration| param and config returned by | 4377 // different). |configuration| param and config returned by |
| 4465 // WKWebViewConfigurationProvider are different objects because WKWebView | 4378 // WKWebViewConfigurationProvider are different objects because WKWebView |
| 4466 // makes a shallow copy of the config inside init, so every WKWebView | 4379 // makes a shallow copy of the config inside init, so every WKWebView |
| 4467 // owns a separate shallow copy of WKWebViewConfiguration. | 4380 // owns a separate shallow copy of WKWebViewConfiguration. |
| 4468 [child ensureWebViewCreatedWithConfiguration:configuration]; | 4381 [child ensureWebViewCreatedWithConfiguration:configuration]; |
| 4469 return child.webView; | 4382 return child.webView; |
| 4470 } | 4383 } |
| 4471 | 4384 |
| (...skipping 841 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 5313 - (void)simulateLoadRequestWithURL:(const GURL&)URL { | 5226 - (void)simulateLoadRequestWithURL:(const GURL&)URL { |
| 5314 _lastRegisteredRequestURL = URL; | 5227 _lastRegisteredRequestURL = URL; |
| 5315 _loadPhase = web::LOAD_REQUESTED; | 5228 _loadPhase = web::LOAD_REQUESTED; |
| 5316 } | 5229 } |
| 5317 | 5230 |
| 5318 - (NSString*)refererFromNavigationAction:(WKNavigationAction*)action { | 5231 - (NSString*)refererFromNavigationAction:(WKNavigationAction*)action { |
| 5319 return [action.request valueForHTTPHeaderField:@"Referer"]; | 5232 return [action.request valueForHTTPHeaderField:@"Referer"]; |
| 5320 } | 5233 } |
| 5321 | 5234 |
| 5322 @end | 5235 @end |
| OLD | NEW |