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 1971 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1982 [self loadNativeViewWithSuccess:NO]; | 1982 [self loadNativeViewWithSuccess:NO]; |
1983 } | 1983 } |
1984 | 1984 |
1985 // Load the current URL in a native controller, retrieved from the native | 1985 // Load the current URL in a native controller, retrieved from the native |
1986 // provider. Call |loadNativeViewWithSuccess:YES| to load the native controller. | 1986 // provider. Call |loadNativeViewWithSuccess:YES| to load the native controller. |
1987 - (void)loadCurrentURLInNativeView { | 1987 - (void)loadCurrentURLInNativeView { |
1988 // Free the web view. | 1988 // Free the web view. |
1989 [self removeWebViewAllowingCachedReconstruction:NO]; | 1989 [self removeWebViewAllowingCachedReconstruction:NO]; |
1990 | 1990 |
1991 web::NavigationItem* item = [self currentNavItem]; | 1991 web::NavigationItem* item = [self currentNavItem]; |
1992 const GURL targetURL = item ? item->GetVirtualURL() : GURL::EmptyGURL(); | 1992 const GURL virtualURL = item ? item->GetVirtualURL() : GURL::EmptyGURL(); |
1993 const web::Referrer referrer; | 1993 const web::Referrer referrer; |
1994 id<CRWNativeContent> nativeContent = | 1994 id<CRWNativeContent> nativeContent = |
1995 [_nativeProvider controllerForURL:targetURL]; | 1995 [_nativeProvider controllerForURL:virtualURL]; |
1996 // Unlike the WebView case, always create a new controller and view. | 1996 // Unlike the WebView case, always create a new controller and view. |
1997 // TODO(pinkerton): What to do if this does return nil? | 1997 // TODO(pinkerton): What to do if this does return nil? |
1998 [self setNativeController:nativeContent]; | 1998 [self setNativeController:nativeContent]; |
1999 if ([nativeContent respondsToSelector:@selector(virtualURL)]) { | 1999 if ([nativeContent respondsToSelector:@selector(virtualURL)]) { |
2000 item->SetVirtualURL([nativeContent virtualURL]); | 2000 item->SetVirtualURL([nativeContent virtualURL]); |
2001 } | 2001 } |
| 2002 const GURL targetURL = item ? item->GetURL() : GURL::EmptyGURL(); |
2002 [self registerLoadRequest:targetURL | 2003 [self registerLoadRequest:targetURL |
2003 referrer:referrer | 2004 referrer:referrer |
2004 transition:[self currentTransition]]; | 2005 transition:[self currentTransition]]; |
2005 [self loadNativeViewWithSuccess:YES]; | 2006 [self loadNativeViewWithSuccess:YES]; |
2006 } | 2007 } |
2007 | 2008 |
2008 - (void)loadWithParams:(const NavigationManager::WebLoadParams&)originalParams { | 2009 - (void)loadWithParams:(const NavigationManager::WebLoadParams&)originalParams { |
2009 // Make a copy of |params|, as some of the delegate methods may modify it. | 2010 // Make a copy of |params|, as some of the delegate methods may modify it. |
2010 NavigationManager::WebLoadParams params(originalParams); | 2011 NavigationManager::WebLoadParams params(originalParams); |
2011 | 2012 |
(...skipping 3610 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5622 NSData* POSTData = currentItem->GetPostData(); | 5623 NSData* POSTData = currentItem->GetPostData(); |
5623 NSMutableURLRequest* request = [self requestForCurrentNavigationItem]; | 5624 NSMutableURLRequest* request = [self requestForCurrentNavigationItem]; |
5624 | 5625 |
5625 // If the request has POST data and is not a form resubmission, configure and | 5626 // If the request has POST data and is not a form resubmission, configure and |
5626 // run the POST request. | 5627 // run the POST request. |
5627 if (POSTData.length && !isFormPOSTResubmission) { | 5628 if (POSTData.length && !isFormPOSTResubmission) { |
5628 [request setHTTPMethod:@"POST"]; | 5629 [request setHTTPMethod:@"POST"]; |
5629 [request setHTTPBody:POSTData]; | 5630 [request setHTTPBody:POSTData]; |
5630 [request setAllHTTPHeaderFields:[self currentHTTPHeaders]]; | 5631 [request setAllHTTPHeaderFields:[self currentHTTPHeaders]]; |
5631 GURL navigationURL = | 5632 GURL navigationURL = |
5632 currentItem ? currentItem->GetVirtualURL() : GURL::EmptyGURL(); | 5633 currentItem ? currentItem->GetURL() : GURL::EmptyGURL(); |
5633 [self registerLoadRequest:navigationURL | 5634 [self registerLoadRequest:navigationURL |
5634 referrer:[self currentSessionEntryReferrer] | 5635 referrer:[self currentSessionEntryReferrer] |
5635 transition:[self currentTransition]]; | 5636 transition:[self currentTransition]]; |
5636 [self loadPOSTRequest:request]; | 5637 [self loadPOSTRequest:request]; |
5637 return; | 5638 return; |
5638 } | 5639 } |
5639 | 5640 |
5640 ProceduralBlock defaultNavigationBlock = ^{ | 5641 ProceduralBlock defaultNavigationBlock = ^{ |
5641 web::NavigationItem* item = [self currentNavItem]; | 5642 web::NavigationItem* item = [self currentNavItem]; |
5642 GURL navigationURL = item ? item->GetVirtualURL() : GURL::EmptyGURL(); | 5643 GURL navigationURL = item ? item->GetURL() : GURL::EmptyGURL(); |
5643 [self registerLoadRequest:navigationURL | 5644 [self registerLoadRequest:navigationURL |
5644 referrer:[self currentSessionEntryReferrer] | 5645 referrer:[self currentSessionEntryReferrer] |
5645 transition:[self currentTransition]]; | 5646 transition:[self currentTransition]]; |
5646 [self loadRequest:request]; | 5647 [self loadRequest:request]; |
5647 }; | 5648 }; |
5648 | 5649 |
5649 // When navigating via WKBackForwardListItem to pages created or updated by | 5650 // When navigating via WKBackForwardListItem to pages created or updated by |
5650 // calls to pushState() and replaceState(), sometimes core.js is not injected | 5651 // calls to pushState() and replaceState(), sometimes core.js is not injected |
5651 // correctly. This means that calling window.history navigation functions | 5652 // correctly. This means that calling window.history navigation functions |
5652 // will invoke WKWebView's non-overridden implementations, causing a mismatch | 5653 // will invoke WKWebView's non-overridden implementations, causing a mismatch |
(...skipping 14 matching lines...) Expand all Loading... |
5667 defaultNavigationBlock(); | 5668 defaultNavigationBlock(); |
5668 return; | 5669 return; |
5669 } | 5670 } |
5670 | 5671 |
5671 ProceduralBlock webViewNavigationBlock = ^{ | 5672 ProceduralBlock webViewNavigationBlock = ^{ |
5672 // If the current navigation URL is the same as the URL of the visible | 5673 // If the current navigation URL is the same as the URL of the visible |
5673 // page, that means the user requested a reload. |goToBackForwardListItem| | 5674 // page, that means the user requested a reload. |goToBackForwardListItem| |
5674 // will be a no-op when it is passed the current back forward list item, | 5675 // will be a no-op when it is passed the current back forward list item, |
5675 // so |reload| must be explicitly called. | 5676 // so |reload| must be explicitly called. |
5676 web::NavigationItem* item = [self currentNavItem]; | 5677 web::NavigationItem* item = [self currentNavItem]; |
5677 GURL navigationURL = item ? item->GetVirtualURL() : GURL::EmptyGURL(); | 5678 GURL navigationURL = item ? item->GetURL() : GURL::EmptyGURL(); |
5678 [self registerLoadRequest:navigationURL | 5679 [self registerLoadRequest:navigationURL |
5679 referrer:[self currentSessionEntryReferrer] | 5680 referrer:[self currentSessionEntryReferrer] |
5680 transition:[self currentTransition]]; | 5681 transition:[self currentTransition]]; |
5681 if (navigationURL == net::GURLWithNSURL([_webView URL])) { | 5682 if (navigationURL == net::GURLWithNSURL([_webView URL])) { |
5682 [_webView reload]; | 5683 [_webView reload]; |
5683 } else { | 5684 } else { |
5684 // |didCommitNavigation:| may not be called for fast navigation, so update | 5685 // |didCommitNavigation:| may not be called for fast navigation, so update |
5685 // the navigation type now as it is already known. | 5686 // the navigation type now as it is already known. |
5686 holder->set_navigation_type(WKNavigationTypeBackForward); | 5687 holder->set_navigation_type(WKNavigationTypeBackForward); |
5687 [_webView goToBackForwardListItem:holder->back_forward_list_item()]; | 5688 [_webView goToBackForwardListItem:holder->back_forward_list_item()]; |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5783 } | 5784 } |
5784 | 5785 |
5785 return web::WEB_VIEW_DOCUMENT_TYPE_GENERIC; | 5786 return web::WEB_VIEW_DOCUMENT_TYPE_GENERIC; |
5786 } | 5787 } |
5787 | 5788 |
5788 - (NSString*)refererFromNavigationAction:(WKNavigationAction*)action { | 5789 - (NSString*)refererFromNavigationAction:(WKNavigationAction*)action { |
5789 return [action.request valueForHTTPHeaderField:@"Referer"]; | 5790 return [action.request valueForHTTPHeaderField:@"Referer"]; |
5790 } | 5791 } |
5791 | 5792 |
5792 @end | 5793 @end |
OLD | NEW |