| 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 408 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 524 // Sets the value of the webView property, and performs its basic setup. | 524 // Sets the value of the webView property, and performs its basic setup. |
| 525 - (void)setWebView:(WKWebView*)webView; | 525 - (void)setWebView:(WKWebView*)webView; |
| 526 // Removes webView, optionally tracking the URL of the evicted | 526 // Removes webView, optionally tracking the URL of the evicted |
| 527 // page for later cache-based reconstruction. | 527 // page for later cache-based reconstruction. |
| 528 - (void)removeWebViewAllowingCachedReconstruction:(BOOL)allowCache; | 528 - (void)removeWebViewAllowingCachedReconstruction:(BOOL)allowCache; |
| 529 // Called when web view process has been terminated. | 529 // Called when web view process has been terminated. |
| 530 - (void)webViewWebProcessDidCrash; | 530 - (void)webViewWebProcessDidCrash; |
| 531 // Returns the WKWebViewConfigurationProvider associated with the web | 531 // Returns the WKWebViewConfigurationProvider associated with the web |
| 532 // controller's BrowserState. | 532 // controller's BrowserState. |
| 533 - (web::WKWebViewConfigurationProvider&)webViewConfigurationProvider; | 533 - (web::WKWebViewConfigurationProvider&)webViewConfigurationProvider; |
| 534 // Extracts Referer value from WKNavigationAction request header. | 534 // Extracts "Referer" [sic] value from WKNavigationAction request header. |
| 535 - (NSString*)refererFromNavigationAction:(WKNavigationAction*)action; | 535 - (NSString*)referrerFromNavigationAction:(WKNavigationAction*)action; |
| 536 | 536 |
| 537 // Returns the current URL of the web view, and sets |trustLevel| accordingly | 537 // Returns the current URL of the web view, and sets |trustLevel| accordingly |
| 538 // based on the confidence in the verification. | 538 // based on the confidence in the verification. |
| 539 - (GURL)webURLWithTrustLevel:(web::URLVerificationTrustLevel*)trustLevel; | 539 - (GURL)webURLWithTrustLevel:(web::URLVerificationTrustLevel*)trustLevel; |
| 540 // Returns |YES| if |url| should be loaded in a native view. | 540 // Returns |YES| if |url| should be loaded in a native view. |
| 541 - (BOOL)shouldLoadURLInNativeView:(const GURL&)url; | 541 - (BOOL)shouldLoadURLInNativeView:(const GURL&)url; |
| 542 // Loads the request into the |webView|. | 542 // Loads the request into the |webView|. |
| 543 - (void)loadRequest:(NSMutableURLRequest*)request; | 543 - (void)loadRequest:(NSMutableURLRequest*)request; |
| 544 // Loads POST request with body in |_wkWebView| by constructing an HTML page | 544 // Loads POST request with body in |_wkWebView| by constructing an HTML page |
| 545 // that executes the request through JavaScript and replaces document with the | 545 // that executes the request through JavaScript and replaces document with the |
| (...skipping 134 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 209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1707 | 1676 |
| 1708 [self loadRequestForCurrentNavigationItem]; | 1677 [self loadRequestForCurrentNavigationItem]; |
| 1709 } | 1678 } |
| 1710 | 1679 |
| 1711 - (void)updatePendingNavigationInfoFromNavigationAction: | 1680 - (void)updatePendingNavigationInfoFromNavigationAction: |
| 1712 (WKNavigationAction*)action { | 1681 (WKNavigationAction*)action { |
| 1713 if (action.targetFrame.mainFrame) { | 1682 if (action.targetFrame.mainFrame) { |
| 1714 _pendingNavigationInfo.reset( | 1683 _pendingNavigationInfo.reset( |
| 1715 [[CRWWebControllerPendingNavigationInfo alloc] init]); | 1684 [[CRWWebControllerPendingNavigationInfo alloc] init]); |
| 1716 [_pendingNavigationInfo | 1685 [_pendingNavigationInfo |
| 1717 setReferrer:[self refererFromNavigationAction:action]]; | 1686 setReferrer:[self referrerFromNavigationAction:action]]; |
| 1718 [_pendingNavigationInfo setNavigationType:action.navigationType]; | 1687 [_pendingNavigationInfo setNavigationType:action.navigationType]; |
| 1719 [_pendingNavigationInfo setHTTPMethod:action.request.HTTPMethod]; | 1688 [_pendingNavigationInfo setHTTPMethod:action.request.HTTPMethod]; |
| 1720 } | 1689 } |
| 1721 } | 1690 } |
| 1722 | 1691 |
| 1723 - (void)updatePendingNavigationInfoFromNavigationResponse: | 1692 - (void)updatePendingNavigationInfoFromNavigationResponse: |
| 1724 (WKNavigationResponse*)response { | 1693 (WKNavigationResponse*)response { |
| 1725 if (response.isForMainFrame) { | 1694 if (response.isForMainFrame) { |
| 1726 if (!_pendingNavigationInfo) { | 1695 if (!_pendingNavigationInfo) { |
| 1727 _pendingNavigationInfo.reset( | 1696 _pendingNavigationInfo.reset( |
| (...skipping 1675 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3403 _webUIManager.reset( | 3372 _webUIManager.reset( |
| 3404 [[CRWWebUIManager alloc] initWithWebState:self.webStateImpl]); | 3373 [[CRWWebUIManager alloc] initWithWebState:self.webStateImpl]); |
| 3405 } | 3374 } |
| 3406 | 3375 |
| 3407 - (void)clearWebUI { | 3376 - (void)clearWebUI { |
| 3408 _webStateImpl->ClearWebUI(); | 3377 _webStateImpl->ClearWebUI(); |
| 3409 _webUIManager.reset(); | 3378 _webUIManager.reset(); |
| 3410 } | 3379 } |
| 3411 | 3380 |
| 3412 #pragma mark - | 3381 #pragma mark - |
| 3413 #pragma mark Popup handling | |
| 3414 | |
| 3415 - (BOOL)shouldBlockPopupWithURL:(const GURL&)popupURL | |
| 3416 sourceURL:(const GURL&)sourceURL { | |
| 3417 if (![_delegate respondsToSelector:@selector(webController: | |
| 3418 shouldBlockPopupWithURL: | |
| 3419 sourceURL:)]) { | |
| 3420 return NO; | |
| 3421 } | |
| 3422 return [_delegate webController:self | |
| 3423 shouldBlockPopupWithURL:popupURL | |
| 3424 sourceURL:sourceURL]; | |
| 3425 } | |
| 3426 | |
| 3427 #pragma mark - | |
| 3428 #pragma mark Auth Challenge | 3382 #pragma mark Auth Challenge |
| 3429 | 3383 |
| 3430 - (void)processAuthChallenge:(NSURLAuthenticationChallenge*)challenge | 3384 - (void)processAuthChallenge:(NSURLAuthenticationChallenge*)challenge |
| 3431 forCertAcceptPolicy:(web::CertAcceptPolicy)policy | 3385 forCertAcceptPolicy:(web::CertAcceptPolicy)policy |
| 3432 certStatus:(net::CertStatus)certStatus | 3386 certStatus:(net::CertStatus)certStatus |
| 3433 completionHandler:(void (^)(NSURLSessionAuthChallengeDisposition, | 3387 completionHandler:(void (^)(NSURLSessionAuthChallengeDisposition, |
| 3434 NSURLCredential*))completionHandler { | 3388 NSURLCredential*))completionHandler { |
| 3435 SecTrustRef trust = challenge.protectionSpace.serverTrust; | 3389 SecTrustRef trust = challenge.protectionSpace.serverTrust; |
| 3436 if (policy == web::CERT_ACCEPT_POLICY_RECOVERABLE_ERROR_ACCEPTED_BY_USER) { | 3390 if (policy == web::CERT_ACCEPT_POLICY_RECOVERABLE_ERROR_ACCEPTED_BY_USER) { |
| 3437 // Cert is invalid, but user agreed to proceed, override default behavior. | 3391 // Cert is invalid, but user agreed to proceed, override default behavior. |
| (...skipping 564 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4002 shouldOpenURL:url | 3956 shouldOpenURL:url |
| 4003 mainDocumentURL:mainDocumentURL | 3957 mainDocumentURL:mainDocumentURL |
| 4004 linkClicked:linkClicked]; | 3958 linkClicked:linkClicked]; |
| 4005 } | 3959 } |
| 4006 | 3960 |
| 4007 - (void)didSuppressDialog { | 3961 - (void)didSuppressDialog { |
| 4008 if ([_delegate respondsToSelector:@selector(webControllerDidSuppressDialog:)]) | 3962 if ([_delegate respondsToSelector:@selector(webControllerDidSuppressDialog:)]) |
| 4009 [_delegate webControllerDidSuppressDialog:self]; | 3963 [_delegate webControllerDidSuppressDialog:self]; |
| 4010 } | 3964 } |
| 4011 | 3965 |
| 4012 - (void)didBlockPopupWithURL:(GURL)popupURL | |
| 4013 sourceURL:(GURL)sourceURL | |
| 4014 referrerPolicy:(const std::string&)referrerPolicyString { | |
| 4015 web::ReferrerPolicy referrerPolicy = | |
| 4016 web::ReferrerPolicyFromString(referrerPolicyString); | |
| 4017 web::Referrer referrer(sourceURL, referrerPolicy); | |
| 4018 NSString* const kWindowName = @""; // obsoleted | |
| 4019 base::WeakNSObject<CRWWebController> weakSelf(self); | |
| 4020 void (^showPopupHandler)() = ^{ | |
| 4021 // On Desktop cross-window comunication is not supported for unblocked | |
| 4022 // popups; so it's ok to create a new independent page. | |
| 4023 CRWWebController* child = | |
| 4024 [[weakSelf delegate] webPageOrderedOpen:popupURL | |
| 4025 referrer:referrer | |
| 4026 windowName:kWindowName | |
| 4027 inBackground:NO]; | |
| 4028 DCHECK(!child || child.sessionController.openedByDOM); | |
| 4029 }; | |
| 4030 | |
| 4031 web::BlockedPopupInfo info(popupURL, referrer, kWindowName, showPopupHandler); | |
| 4032 [self.delegate webController:self didBlockPopup:info]; | |
| 4033 } | |
| 4034 | |
| 4035 - (void)didBlockPopupWithURL:(GURL)popupURL sourceURL:(GURL)sourceURL { | |
| 4036 if ([_delegate respondsToSelector:@selector(webController:didBlockPopup:)]) { | |
| 4037 base::WeakNSObject<CRWWebController> weakSelf(self); | |
| 4038 dispatch_async(dispatch_get_main_queue(), ^{ | |
| 4039 [self queryPageReferrerPolicy:^(NSString* policy) { | |
| 4040 [weakSelf didBlockPopupWithURL:popupURL | |
| 4041 sourceURL:sourceURL | |
| 4042 referrerPolicy:base::SysNSStringToUTF8(policy)]; | |
| 4043 }]; | |
| 4044 }); | |
| 4045 } | |
| 4046 } | |
| 4047 | |
| 4048 - (BOOL)isMainFrameNavigationAction:(WKNavigationAction*)action { | 3966 - (BOOL)isMainFrameNavigationAction:(WKNavigationAction*)action { |
| 4049 if (action.targetFrame) { | 3967 if (action.targetFrame) { |
| 4050 return action.targetFrame.mainFrame; | 3968 return action.targetFrame.mainFrame; |
| 4051 } | 3969 } |
| 4052 // According to WKNavigationAction documentation, in the case of a new window | 3970 // According to WKNavigationAction documentation, in the case of a new window |
| 4053 // navigation, target frame will be nil. In this case check if the | 3971 // navigation, target frame will be nil. In this case check if the |
| 4054 // |sourceFrame| is the mainFrame. | 3972 // |sourceFrame| is the mainFrame. |
| 4055 return action.sourceFrame.mainFrame; | 3973 return action.sourceFrame.mainFrame; |
| 4056 } | 3974 } |
| 4057 | 3975 |
| (...skipping 374 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4432 | 4350 |
| 4433 - (WKWebView*)webView:(WKWebView*)webView | 4351 - (WKWebView*)webView:(WKWebView*)webView |
| 4434 createWebViewWithConfiguration:(WKWebViewConfiguration*)configuration | 4352 createWebViewWithConfiguration:(WKWebViewConfiguration*)configuration |
| 4435 forNavigationAction:(WKNavigationAction*)action | 4353 forNavigationAction:(WKNavigationAction*)action |
| 4436 windowFeatures:(WKWindowFeatures*)windowFeatures { | 4354 windowFeatures:(WKWindowFeatures*)windowFeatures { |
| 4437 if (self.shouldSuppressDialogs) { | 4355 if (self.shouldSuppressDialogs) { |
| 4438 [self didSuppressDialog]; | 4356 [self didSuppressDialog]; |
| 4439 return nil; | 4357 return nil; |
| 4440 } | 4358 } |
| 4441 | 4359 |
| 4360 // Do not create windows for non-empty invalid URLs. |
| 4442 GURL requestURL = net::GURLWithNSURL(action.request.URL); | 4361 GURL requestURL = net::GURLWithNSURL(action.request.URL); |
| 4443 | |
| 4444 // Don't create windows for non-empty invalid URLs. | |
| 4445 if (!requestURL.is_empty() && !requestURL.is_valid()) { | 4362 if (!requestURL.is_empty() && !requestURL.is_valid()) { |
| 4446 DLOG(WARNING) << "Unable to open a window with invalid URL: " | 4363 DLOG(WARNING) << "Unable to open a window with invalid URL: " |
| 4447 << requestURL.spec(); | 4364 << requestURL.spec(); |
| 4448 return nil; | 4365 return nil; |
| 4449 } | 4366 } |
| 4450 | 4367 |
| 4451 if (![self userIsInteracting]) { | 4368 NSString* referrer = [self referrerFromNavigationAction:action]; |
| 4452 NSString* referer = [self refererFromNavigationAction:action]; | 4369 GURL openerURL = |
| 4453 GURL referrerURL = | 4370 referrer ? GURL(base::SysNSStringToUTF8(referrer)) : _documentURL; |
| 4454 referer ? GURL(base::SysNSStringToUTF8(referer)) : [self currentURL]; | 4371 CRWWebController* child = [_delegate webController:self |
| 4455 if ([self shouldBlockPopupWithURL:requestURL sourceURL:referrerURL]) { | 4372 createWebControllerForURL:requestURL |
| 4456 [self didBlockPopupWithURL:requestURL sourceURL:referrerURL]; | 4373 openerURL:openerURL |
| 4457 // Desktop Chrome does not return a window for the blocked popups; | 4374 initiatedByUser:[self userIsInteracting]]; |
| 4458 // follow the same approach by returning nil; | 4375 DCHECK(!child || child.sessionController.openedByDOM); |
| 4459 return nil; | |
| 4460 } | |
| 4461 } | |
| 4462 | 4376 |
| 4463 CRWWebController* child = [self createChildWebController]; | |
| 4464 // WKWebView requires WKUIDelegate to return a child view created with | 4377 // WKWebView requires WKUIDelegate to return a child view created with |
| 4465 // exactly the same |configuration| object (exception is raised if config is | 4378 // exactly the same |configuration| object (exception is raised if config is |
| 4466 // different). |configuration| param and config returned by | 4379 // different). |configuration| param and config returned by |
| 4467 // WKWebViewConfigurationProvider are different objects because WKWebView | 4380 // WKWebViewConfigurationProvider are different objects because WKWebView |
| 4468 // makes a shallow copy of the config inside init, so every WKWebView | 4381 // makes a shallow copy of the config inside init, so every WKWebView |
| 4469 // owns a separate shallow copy of WKWebViewConfiguration. | 4382 // owns a separate shallow copy of WKWebViewConfiguration. |
| 4470 [child ensureWebViewCreatedWithConfiguration:configuration]; | 4383 [child ensureWebViewCreatedWithConfiguration:configuration]; |
| 4471 return child.webView; | 4384 return child.webView; |
| 4472 } | 4385 } |
| 4473 | 4386 |
| (...skipping 836 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5310 - (NSUInteger)observerCount { | 5223 - (NSUInteger)observerCount { |
| 5311 DCHECK_EQ(_observerBridges.size(), [_observers count]); | 5224 DCHECK_EQ(_observerBridges.size(), [_observers count]); |
| 5312 return [_observers count]; | 5225 return [_observers count]; |
| 5313 } | 5226 } |
| 5314 | 5227 |
| 5315 - (void)simulateLoadRequestWithURL:(const GURL&)URL { | 5228 - (void)simulateLoadRequestWithURL:(const GURL&)URL { |
| 5316 _lastRegisteredRequestURL = URL; | 5229 _lastRegisteredRequestURL = URL; |
| 5317 _loadPhase = web::LOAD_REQUESTED; | 5230 _loadPhase = web::LOAD_REQUESTED; |
| 5318 } | 5231 } |
| 5319 | 5232 |
| 5320 - (NSString*)refererFromNavigationAction:(WKNavigationAction*)action { | 5233 - (NSString*)referrerFromNavigationAction:(WKNavigationAction*)action { |
| 5321 return [action.request valueForHTTPHeaderField:@"Referer"]; | 5234 return [action.request valueForHTTPHeaderField:kReferrerHeaderName]; |
| 5322 } | 5235 } |
| 5323 | 5236 |
| 5324 @end | 5237 @end |
| OLD | NEW |