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 458 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
469 // Returns the navigation item for the current page. | 469 // Returns the navigation item for the current page. |
470 @property(nonatomic, readonly) web::NavigationItemImpl* currentNavItem; | 470 @property(nonatomic, readonly) web::NavigationItemImpl* currentNavItem; |
471 // Returns the current transition type. | 471 // Returns the current transition type. |
472 @property(nonatomic, readonly) ui::PageTransition currentTransition; | 472 @property(nonatomic, readonly) ui::PageTransition currentTransition; |
473 // Returns the referrer for current navigation item. May be empty. | 473 // Returns the referrer for current navigation item. May be empty. |
474 @property(nonatomic, readonly) web::Referrer currentNavItemReferrer; | 474 @property(nonatomic, readonly) web::Referrer currentNavItemReferrer; |
475 // The HTTP headers associated with the current navigation item. These are nil | 475 // The HTTP headers associated with the current navigation item. These are nil |
476 // unless the request was a POST. | 476 // unless the request was a POST. |
477 @property(nonatomic, readonly) NSDictionary* currentHTTPHeaders; | 477 @property(nonatomic, readonly) NSDictionary* currentHTTPHeaders; |
478 | 478 |
| 479 // TODO(crbug.com/684098): Remove these methods and inline their content. |
| 480 // Called before finishing a history navigation from a page with the given |
| 481 // UserAgentType. |
| 482 - (void)webWillFinishHistoryNavigationWithPreviousUserAgentType: |
| 483 (web::UserAgentType)userAgentType; |
479 // Requires page reconstruction if |item| has a non-NONE UserAgentType and it | 484 // Requires page reconstruction if |item| has a non-NONE UserAgentType and it |
480 // differs from that of |fromItem|. | 485 // differs from that of |fromItem|. |
481 - (void)updateDesktopUserAgentForItem:(web::NavigationItem*)item | 486 - (void)updateDesktopUserAgentForItem:(web::NavigationItem*)item |
482 previousUserAgentType:(web::UserAgentType)userAgentType; | 487 previousUserAgentType:(web::UserAgentType)userAgentType; |
483 | 488 |
484 // Removes the container view from the hierarchy and resets the ivar. | 489 // Removes the container view from the hierarchy and resets the ivar. |
485 - (void)resetContainerView; | 490 - (void)resetContainerView; |
486 // Called when the web page has changed document and/or URL, and so the page | 491 // Called when the web page has changed document and/or URL, and so the page |
487 // navigation should be reported to the delegate, and internal state updated to | 492 // navigation should be reported to the delegate, and internal state updated to |
488 // reflect the fact that the navigation has occurred. | 493 // reflect the fact that the navigation has occurred. |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
591 - (void)didFinishNavigation; | 596 - (void)didFinishNavigation; |
592 // Update the appropriate parts of the model and broadcast to the embedder. This | 597 // Update the appropriate parts of the model and broadcast to the embedder. This |
593 // may be called multiple times and thus must be idempotent. | 598 // may be called multiple times and thus must be idempotent. |
594 - (void)loadCompleteWithSuccess:(BOOL)loadSuccess; | 599 - (void)loadCompleteWithSuccess:(BOOL)loadSuccess; |
595 // Called after URL is finished loading and _loadPhase is set to PAGE_LOADED. | 600 // Called after URL is finished loading and _loadPhase is set to PAGE_LOADED. |
596 - (void)didFinishWithURL:(const GURL&)currentURL loadSuccess:(BOOL)loadSuccess; | 601 - (void)didFinishWithURL:(const GURL&)currentURL loadSuccess:(BOOL)loadSuccess; |
597 // Navigates forwards or backwards by |delta| pages. No-op if delta is out of | 602 // Navigates forwards or backwards by |delta| pages. No-op if delta is out of |
598 // bounds. Reloads if delta is 0. | 603 // bounds. Reloads if delta is 0. |
599 // TODO(crbug.com/661316): Move this method to NavigationManager. | 604 // TODO(crbug.com/661316): Move this method to NavigationManager. |
600 - (void)goDelta:(int)delta; | 605 - (void)goDelta:(int)delta; |
| 606 // Loads a new URL if the current entry is not from a pushState() navigation. |
| 607 // |fromURL| is the URL of the previous NavigationItem, |fromUserAgentType| is |
| 608 // that item's UserAgentType, and |sameDocument| is YES if the navigation is |
| 609 // between two pages with the same document. |
| 610 - (void)finishHistoryNavigationFromURL:(const GURL&)fromURL |
| 611 userAgentType:(web::UserAgentType)fromUserAgentType |
| 612 sameDocument:(BOOL)sameDocument; |
601 // Informs the native controller if web usage is allowed or not. | 613 // Informs the native controller if web usage is allowed or not. |
602 - (void)setNativeControllerWebUsageEnabled:(BOOL)webUsageEnabled; | 614 - (void)setNativeControllerWebUsageEnabled:(BOOL)webUsageEnabled; |
603 // Called when web controller receives a new message from the web page. | 615 // Called when web controller receives a new message from the web page. |
604 - (void)didReceiveScriptMessage:(WKScriptMessage*)message; | 616 - (void)didReceiveScriptMessage:(WKScriptMessage*)message; |
605 // Returns a new script which wraps |script| with windowID check so |script| is | 617 // Returns a new script which wraps |script| with windowID check so |script| is |
606 // not evaluated on windowID mismatch. | 618 // not evaluated on windowID mismatch. |
607 - (NSString*)scriptByAddingWindowIDCheckForScript:(NSString*)script; | 619 - (NSString*)scriptByAddingWindowIDCheckForScript:(NSString*)script; |
608 // Attempts to handle a script message. Returns YES on success, NO otherwise. | 620 // Attempts to handle a script message. Returns YES on success, NO otherwise. |
609 - (BOOL)respondToWKScriptMessage:(WKScriptMessage*)scriptMessage; | 621 - (BOOL)respondToWKScriptMessage:(WKScriptMessage*)scriptMessage; |
610 // Registers load request with empty referrer and link or client redirect | 622 // Registers load request with empty referrer and link or client redirect |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
699 - (BOOL)isCurrentNavigationBackForward; | 711 - (BOOL)isCurrentNavigationBackForward; |
700 // Returns whether the given navigation is triggered by a user link click. | 712 // Returns whether the given navigation is triggered by a user link click. |
701 - (BOOL)isLinkNavigation:(WKNavigationType)navigationType; | 713 - (BOOL)isLinkNavigation:(WKNavigationType)navigationType; |
702 | 714 |
703 // Inject windowID if not yet injected. | 715 // Inject windowID if not yet injected. |
704 - (void)injectWindowID; | 716 - (void)injectWindowID; |
705 | 717 |
706 // Returns YES if the given WKBackForwardListItem is valid to use for | 718 // Returns YES if the given WKBackForwardListItem is valid to use for |
707 // navigation. | 719 // navigation. |
708 - (BOOL)isBackForwardListItemValid:(WKBackForwardListItem*)item; | 720 - (BOOL)isBackForwardListItemValid:(WKBackForwardListItem*)item; |
| 721 // Compares the two URLs being navigated between during a history navigation to |
| 722 // determine if a # needs to be appended to the URL of |toItem| to trigger a |
| 723 // hashchange event. If so, also saves the modified URL into |toItem|. |
| 724 - (GURL)URLForHistoryNavigationToItem:(web::NavigationItem*)toItem |
| 725 previousURL:(const GURL&)previousURL; |
709 // 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 |
710 // interfere with scroll to top when tapping the statusbar. | 727 // interfere with scroll to top when tapping the statusbar. |
711 - (void)optOutScrollsToTopForSubviews; | 728 - (void)optOutScrollsToTopForSubviews; |
712 // 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. |
713 - (void)setNativeController:(id<CRWNativeContent>)nativeController; | 730 - (void)setNativeController:(id<CRWNativeContent>)nativeController; |
714 // Returns whether |url| should be opened. | 731 // Returns whether |url| should be opened. |
715 - (BOOL)shouldOpenURL:(const GURL&)url | 732 - (BOOL)shouldOpenURL:(const GURL&)url |
716 mainDocumentURL:(const GURL&)mainDocumentURL | 733 mainDocumentURL:(const GURL&)mainDocumentURL |
717 linkClicked:(BOOL)linkClicked; | 734 linkClicked:(BOOL)linkClicked; |
718 // 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. |
(...skipping 664 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1383 | 1400 |
1384 - (BOOL)isBackForwardListItemValid:(WKBackForwardListItem*)item { | 1401 - (BOOL)isBackForwardListItemValid:(WKBackForwardListItem*)item { |
1385 // The current back-forward list item MUST be in the WKWebView's back-forward | 1402 // The current back-forward list item MUST be in the WKWebView's back-forward |
1386 // list to be valid. | 1403 // list to be valid. |
1387 WKBackForwardList* list = [_webView backForwardList]; | 1404 WKBackForwardList* list = [_webView backForwardList]; |
1388 return list.currentItem == item || | 1405 return list.currentItem == item || |
1389 [list.forwardList indexOfObject:item] != NSNotFound || | 1406 [list.forwardList indexOfObject:item] != NSNotFound || |
1390 [list.backList indexOfObject:item] != NSNotFound; | 1407 [list.backList indexOfObject:item] != NSNotFound; |
1391 } | 1408 } |
1392 | 1409 |
| 1410 - (GURL)URLForHistoryNavigationToItem:(web::NavigationItem*)toItem |
| 1411 previousURL:(const GURL&)previousURL { |
| 1412 // If navigating with native API, i.e. using a back forward list item, |
| 1413 // hashchange events will be triggered automatically, so no URL tampering is |
| 1414 // required. |
| 1415 web::WKBackForwardListItemHolder* holder = |
| 1416 web::WKBackForwardListItemHolder::FromNavigationItem(toItem); |
| 1417 if (holder->back_forward_list_item()) { |
| 1418 return toItem->GetURL(); |
| 1419 } |
| 1420 |
| 1421 const GURL& URL = toItem->GetURL(); |
| 1422 |
| 1423 // Check the state of the fragments on both URLs (aka, is there a '#' in the |
| 1424 // url or not). |
| 1425 if (!previousURL.has_ref() || URL.has_ref()) { |
| 1426 return URL; |
| 1427 } |
| 1428 |
| 1429 // startURL contains a fragment and endURL doesn't. Remove the fragment from |
| 1430 // startURL and compare the resulting string to endURL. If they are equal, add |
| 1431 // # to endURL to cause a hashchange event. |
| 1432 GURL hashless = web::GURLByRemovingRefFromGURL(previousURL); |
| 1433 |
| 1434 if (hashless != URL) |
| 1435 return URL; |
| 1436 |
| 1437 url::StringPieceReplacements<std::string> emptyRef; |
| 1438 emptyRef.SetRefStr(""); |
| 1439 GURL newEndURL = URL.ReplaceComponents(emptyRef); |
| 1440 toItem->SetURL(newEndURL); |
| 1441 return newEndURL; |
| 1442 } |
| 1443 |
1393 - (void)injectWindowID { | 1444 - (void)injectWindowID { |
1394 // Default value for shouldSuppressDialogs is NO, so updating them only | 1445 // Default value for shouldSuppressDialogs is NO, so updating them only |
1395 // when necessary is a good optimization. | 1446 // when necessary is a good optimization. |
1396 if (_shouldSuppressDialogsOnWindowIDInjection) { | 1447 if (_shouldSuppressDialogsOnWindowIDInjection) { |
1397 self.shouldSuppressDialogs = YES; | 1448 self.shouldSuppressDialogs = YES; |
1398 _shouldSuppressDialogsOnWindowIDInjection = NO; | 1449 _shouldSuppressDialogsOnWindowIDInjection = NO; |
1399 } | 1450 } |
1400 | 1451 |
1401 [_windowIDJSManager inject]; | 1452 [_windowIDJSManager inject]; |
1402 } | 1453 } |
(...skipping 385 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1788 referrer:referrer | 1839 referrer:referrer |
1789 transition:self.currentTransition]; | 1840 transition:self.currentTransition]; |
1790 [self loadNativeViewWithSuccess:YES]; | 1841 [self loadNativeViewWithSuccess:YES]; |
1791 } | 1842 } |
1792 | 1843 |
1793 - (void)loadWithParams:(const NavigationManager::WebLoadParams&)originalParams { | 1844 - (void)loadWithParams:(const NavigationManager::WebLoadParams&)originalParams { |
1794 // Make a copy of |params|, as some of the delegate methods may modify it. | 1845 // Make a copy of |params|, as some of the delegate methods may modify it. |
1795 NavigationManager::WebLoadParams params(originalParams); | 1846 NavigationManager::WebLoadParams params(originalParams); |
1796 | 1847 |
1797 // Initiating a navigation from the UI, record the current page state before | 1848 // Initiating a navigation from the UI, record the current page state before |
1798 // the new page loads. | 1849 // the new page loads. Don't record for back/forward, as the current entry |
| 1850 // has already been moved to the next entry in the history. Do, however, |
| 1851 // record it for general reload. |
| 1852 // TODO(jimblackler): consider a single unified call to record state whenever |
| 1853 // the page is about to be changed. This cannot currently be done after |
| 1854 // addPendingItem is called. |
1799 | 1855 |
1800 [_delegate webWillInitiateLoadWithParams:params]; | 1856 [_delegate webWillInitiateLoadWithParams:params]; |
1801 | 1857 |
1802 GURL navUrl = params.url; | 1858 GURL navUrl = params.url; |
1803 ui::PageTransition transition = params.transition_type; | 1859 ui::PageTransition transition = params.transition_type; |
1804 DCHECK(!(transition & ui::PAGE_TRANSITION_FORWARD_BACK)); | |
1805 DCHECK(!(transition & ui::PAGE_TRANSITION_RELOAD)); | |
1806 | 1860 |
1807 BOOL initialNavigation = NO; | 1861 BOOL initialNavigation = NO; |
1808 // Clear transient view before making any changes to history and navigation | 1862 BOOL forwardBack = |
1809 // manager. TODO(stuartmorgan): Drive Transient Item clearing from | 1863 PageTransitionCoreTypeIs(transition, ui::PAGE_TRANSITION_RELOAD) && |
1810 // navigation system, rather than from WebController. | 1864 (transition & ui::PAGE_TRANSITION_FORWARD_BACK); |
1811 [self clearTransientContentView]; | 1865 if (forwardBack) { |
| 1866 // Setting these for back/forward is not supported. |
| 1867 DCHECK(!params.extra_headers); |
| 1868 DCHECK(!params.post_data); |
| 1869 } else { |
| 1870 // Clear transient view before making any changes to history and navigation |
| 1871 // manager. TODO(stuartmorgan): Drive Transient Item clearing from |
| 1872 // navigation system, rather than from WebController. |
| 1873 [self clearTransientContentView]; |
1812 | 1874 |
1813 [self recordStateInHistory]; | 1875 // TODO(stuartmorgan): Why doesn't recordStateInHistory get called for |
| 1876 // forward/back transitions? |
| 1877 [self recordStateInHistory]; |
1814 | 1878 |
1815 if (!self.currentNavItem) | 1879 if (!self.currentNavItem) |
1816 initialNavigation = YES; | 1880 initialNavigation = YES; |
1817 | 1881 |
1818 web::NavigationInitiationType navigationInitiationType = | 1882 web::NavigationInitiationType navigationInitiationType = |
1819 params.is_renderer_initiated | 1883 params.is_renderer_initiated |
1820 ? web::NavigationInitiationType::RENDERER_INITIATED | 1884 ? web::NavigationInitiationType::RENDERER_INITIATED |
1821 : web::NavigationInitiationType::USER_INITIATED; | 1885 : web::NavigationInitiationType::USER_INITIATED; |
1822 self.navigationManagerImpl->AddPendingItem( | 1886 self.navigationManagerImpl->AddPendingItem( |
1823 navUrl, params.referrer, transition, navigationInitiationType); | 1887 navUrl, params.referrer, transition, navigationInitiationType); |
1824 | 1888 |
1825 web::NavigationItemImpl* addedItem = self.currentNavItem; | 1889 web::NavigationItemImpl* addedItem = self.currentNavItem; |
1826 DCHECK(addedItem); | 1890 DCHECK(addedItem); |
1827 if (params.extra_headers) | 1891 if (params.extra_headers) |
1828 addedItem->AddHttpRequestHeaders(params.extra_headers); | 1892 addedItem->AddHttpRequestHeaders(params.extra_headers); |
1829 if (params.post_data) { | 1893 if (params.post_data) { |
1830 DCHECK([addedItem->GetHttpRequestHeaders() objectForKey:@"Content-Type"]) | 1894 DCHECK([addedItem->GetHttpRequestHeaders() objectForKey:@"Content-Type"]) |
1831 << "Post data should have an associated content type"; | 1895 << "Post data should have an associated content type"; |
1832 addedItem->SetPostData(params.post_data); | 1896 addedItem->SetPostData(params.post_data); |
1833 addedItem->SetShouldSkipRepostFormConfirmation(true); | 1897 addedItem->SetShouldSkipRepostFormConfirmation(true); |
| 1898 } |
1834 } | 1899 } |
1835 | 1900 |
1836 [_delegate webDidUpdateSessionForLoadWithParams:params | 1901 [_delegate webDidUpdateSessionForLoadWithParams:params |
1837 wasInitialNavigation:initialNavigation]; | 1902 wasInitialNavigation:initialNavigation]; |
1838 | 1903 |
1839 [self loadCurrentURL]; | 1904 [self loadCurrentURL]; |
1840 } | 1905 } |
1841 | 1906 |
1842 - (void)loadCurrentURL { | 1907 - (void)loadCurrentURL { |
1843 // If the content view doesn't exist, the tab has either been evicted, or | 1908 // If the content view doesn't exist, the tab has either been evicted, or |
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2027 CRWSessionController* sessionController = self.sessionController; | 2092 CRWSessionController* sessionController = self.sessionController; |
2028 const web::ScopedNavigationItemImplList& items = sessionController.items; | 2093 const web::ScopedNavigationItemImplList& items = sessionController.items; |
2029 if (index < 0 || index >= static_cast<int>(items.size())) { | 2094 if (index < 0 || index >= static_cast<int>(items.size())) { |
2030 NOTREACHED(); | 2095 NOTREACHED(); |
2031 return; | 2096 return; |
2032 } | 2097 } |
2033 | 2098 |
2034 if (!_webStateImpl->IsShowingWebInterstitial()) | 2099 if (!_webStateImpl->IsShowingWebInterstitial()) |
2035 [self recordStateInHistory]; | 2100 [self recordStateInHistory]; |
2036 | 2101 |
2037 [self clearTransientContentView]; | |
2038 | |
2039 // Update the user agent before attempting the navigation. | |
2040 web::NavigationItem* toItem = items[index].get(); | |
2041 web::NavigationItem* previousItem = sessionController.currentItem; | 2102 web::NavigationItem* previousItem = sessionController.currentItem; |
| 2103 GURL previousURL = previousItem ? previousItem->GetURL() : GURL::EmptyGURL(); |
2042 web::UserAgentType previousUserAgentType = | 2104 web::UserAgentType previousUserAgentType = |
2043 previousItem ? previousItem->GetUserAgentType() | 2105 previousItem ? previousItem->GetUserAgentType() |
2044 : web::UserAgentType::NONE; | 2106 : web::UserAgentType::NONE; |
2045 [self updateDesktopUserAgentForItem:toItem | 2107 web::NavigationItem* toItem = items[index].get(); |
2046 previousUserAgentType:previousUserAgentType]; | |
2047 | |
2048 BOOL sameDocumentNavigation = | 2108 BOOL sameDocumentNavigation = |
2049 [sessionController isSameDocumentNavigationBetweenItem:previousItem | 2109 [sessionController isSameDocumentNavigationBetweenItem:previousItem |
2050 andItem:toItem]; | 2110 andItem:toItem]; |
2051 if (sameDocumentNavigation) { | 2111 |
| 2112 NSUserDefaults* userDefaults = [NSUserDefaults standardUserDefaults]; |
| 2113 if (![userDefaults boolForKey:@"PendingIndexNavigationDisabled"]) { |
| 2114 [self clearTransientContentView]; |
| 2115 |
| 2116 // Update the user agent before attempting the navigation. |
| 2117 [self updateDesktopUserAgentForItem:toItem |
| 2118 previousUserAgentType:previousUserAgentType]; |
| 2119 |
| 2120 if (sameDocumentNavigation) { |
| 2121 [sessionController goToItemAtIndex:index]; |
| 2122 [self updateHTML5HistoryState]; |
| 2123 } else { |
| 2124 [sessionController discardNonCommittedItems]; |
| 2125 [sessionController setPendingItemIndex:index]; |
| 2126 |
| 2127 web::NavigationItemImpl* pendingItem = sessionController.pendingItem; |
| 2128 pendingItem->SetTransitionType(ui::PageTransitionFromInt( |
| 2129 pendingItem->GetTransitionType() | ui::PAGE_TRANSITION_FORWARD_BACK)); |
| 2130 |
| 2131 [self loadCurrentURL]; |
| 2132 } |
| 2133 } else { |
2052 [sessionController goToItemAtIndex:index]; | 2134 [sessionController goToItemAtIndex:index]; |
2053 [self updateHTML5HistoryState]; | 2135 if (previousURL.is_valid()) { |
2054 } else { | 2136 [self finishHistoryNavigationFromURL:previousURL |
2055 [sessionController discardNonCommittedItems]; | 2137 userAgentType:previousUserAgentType |
2056 [sessionController setPendingItemIndex:index]; | 2138 sameDocument:sameDocumentNavigation]; |
2057 | 2139 } |
2058 web::NavigationItemImpl* pendingItem = sessionController.pendingItem; | |
2059 pendingItem->SetTransitionType(ui::PageTransitionFromInt( | |
2060 pendingItem->GetTransitionType() | ui::PAGE_TRANSITION_FORWARD_BACK)); | |
2061 | |
2062 [self loadCurrentURL]; | |
2063 } | 2140 } |
2064 } | 2141 } |
2065 | 2142 |
2066 - (BOOL)isLoaded { | 2143 - (BOOL)isLoaded { |
2067 return _loadPhase == web::PAGE_LOADED; | 2144 return _loadPhase == web::PAGE_LOADED; |
2068 } | 2145 } |
2069 | 2146 |
2070 - (void)didFinishNavigation { | 2147 - (void)didFinishNavigation { |
2071 // This can be called at multiple times after the document has loaded. Do | 2148 // This can be called at multiple times after the document has loaded. Do |
2072 // nothing if the document has already loaded. | 2149 // nothing if the document has already loaded. |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2146 [self reload]; | 2223 [self reload]; |
2147 return; | 2224 return; |
2148 } | 2225 } |
2149 | 2226 |
2150 if (self.navigationManagerImpl->CanGoToOffset(delta)) { | 2227 if (self.navigationManagerImpl->CanGoToOffset(delta)) { |
2151 NSInteger index = self.navigationManagerImpl->GetIndexForOffset(delta); | 2228 NSInteger index = self.navigationManagerImpl->GetIndexForOffset(delta); |
2152 [self goToItemAtIndex:index]; | 2229 [self goToItemAtIndex:index]; |
2153 } | 2230 } |
2154 } | 2231 } |
2155 | 2232 |
| 2233 - (void)finishHistoryNavigationFromURL:(const GURL&)fromURL |
| 2234 userAgentType:(web::UserAgentType)fromUserAgentType |
| 2235 sameDocument:(BOOL)sameDocument { |
| 2236 [self webWillFinishHistoryNavigationWithPreviousUserAgentType: |
| 2237 fromUserAgentType]; |
| 2238 |
| 2239 // Only load the new URL if it has a different document than |fromEntry| to |
| 2240 // prevent extra page loads from NavigationItems created by hash changes or |
| 2241 // calls to window.history.pushState(). |
| 2242 web::NavigationItem* currentItem = self.currentNavItem; |
| 2243 GURL endURL = |
| 2244 [self URLForHistoryNavigationToItem:currentItem previousURL:fromURL]; |
| 2245 if (!sameDocument) { |
| 2246 ui::PageTransition transition = ui::PageTransitionFromInt( |
| 2247 ui::PAGE_TRANSITION_RELOAD | ui::PAGE_TRANSITION_FORWARD_BACK); |
| 2248 |
| 2249 NavigationManager::WebLoadParams params(endURL); |
| 2250 if (currentItem) { |
| 2251 params.referrer = currentItem->GetReferrer(); |
| 2252 } |
| 2253 params.transition_type = transition; |
| 2254 [self loadWithParams:params]; |
| 2255 } |
| 2256 // If this is a same-document navigation, update the HTML5 history state |
| 2257 // immediately. For cross-document navigations, the history state will be |
| 2258 // updated after the navigation is committed, as attempting to replace the URL |
| 2259 // here will result in a JavaScript SecurityError due to the URLs having |
| 2260 // different origins. |
| 2261 if (sameDocument) |
| 2262 [self updateHTML5HistoryState]; |
| 2263 } |
| 2264 |
2156 - (void)addGestureRecognizerToWebView:(UIGestureRecognizer*)recognizer { | 2265 - (void)addGestureRecognizerToWebView:(UIGestureRecognizer*)recognizer { |
2157 if ([_gestureRecognizers containsObject:recognizer]) | 2266 if ([_gestureRecognizers containsObject:recognizer]) |
2158 return; | 2267 return; |
2159 | 2268 |
2160 [_webView addGestureRecognizer:recognizer]; | 2269 [_webView addGestureRecognizer:recognizer]; |
2161 [_gestureRecognizers addObject:recognizer]; | 2270 [_gestureRecognizers addObject:recognizer]; |
2162 } | 2271 } |
2163 | 2272 |
2164 - (void)removeGestureRecognizerFromWebView:(UIGestureRecognizer*)recognizer { | 2273 - (void)removeGestureRecognizerFromWebView:(UIGestureRecognizer*)recognizer { |
2165 if (![_gestureRecognizers containsObject:recognizer]) | 2274 if (![_gestureRecognizers containsObject:recognizer]) |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2235 [delegate webController:strongSelf didLoadPassKitObject:data]; | 2344 [delegate webController:strongSelf didLoadPassKitObject:data]; |
2236 } | 2345 } |
2237 }; | 2346 }; |
2238 web::BrowserState* browserState = self.webStateImpl->GetBrowserState(); | 2347 web::BrowserState* browserState = self.webStateImpl->GetBrowserState(); |
2239 _passKitDownloader.reset([[CRWPassKitDownloader alloc] | 2348 _passKitDownloader.reset([[CRWPassKitDownloader alloc] |
2240 initWithContextGetter:browserState->GetRequestContext() | 2349 initWithContextGetter:browserState->GetRequestContext() |
2241 completionHandler:passKitCompletion]); | 2350 completionHandler:passKitCompletion]); |
2242 return _passKitDownloader.get(); | 2351 return _passKitDownloader.get(); |
2243 } | 2352 } |
2244 | 2353 |
| 2354 - (void)webWillFinishHistoryNavigationWithPreviousUserAgentType: |
| 2355 (web::UserAgentType)userAgentType { |
| 2356 [self updateDesktopUserAgentForItem:self.currentNavItem |
| 2357 previousUserAgentType:userAgentType]; |
| 2358 [_delegate webWillFinishHistoryNavigation]; |
| 2359 } |
| 2360 |
2245 - (void)updateDesktopUserAgentForItem:(web::NavigationItem*)item | 2361 - (void)updateDesktopUserAgentForItem:(web::NavigationItem*)item |
2246 previousUserAgentType:(web::UserAgentType)userAgentType { | 2362 previousUserAgentType:(web::UserAgentType)userAgentType { |
2247 if (!item) | 2363 if (!item) |
2248 return; | 2364 return; |
2249 web::UserAgentType itemUserAgentType = item->GetUserAgentType(); | 2365 web::UserAgentType itemUserAgentType = item->GetUserAgentType(); |
2250 if (itemUserAgentType == web::UserAgentType::NONE) | 2366 if (itemUserAgentType == web::UserAgentType::NONE) |
2251 return; | 2367 return; |
2252 if (itemUserAgentType != userAgentType) | 2368 if (itemUserAgentType != userAgentType) |
2253 [self requirePageReconstruction]; | 2369 [self requirePageReconstruction]; |
2254 } | 2370 } |
(...skipping 2819 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5074 - (void)simulateLoadRequestWithURL:(const GURL&)URL { | 5190 - (void)simulateLoadRequestWithURL:(const GURL&)URL { |
5075 _lastRegisteredRequestURL = URL; | 5191 _lastRegisteredRequestURL = URL; |
5076 _loadPhase = web::LOAD_REQUESTED; | 5192 _loadPhase = web::LOAD_REQUESTED; |
5077 } | 5193 } |
5078 | 5194 |
5079 - (NSString*)referrerFromNavigationAction:(WKNavigationAction*)action { | 5195 - (NSString*)referrerFromNavigationAction:(WKNavigationAction*)action { |
5080 return [action.request valueForHTTPHeaderField:kReferrerHeaderName]; | 5196 return [action.request valueForHTTPHeaderField:kReferrerHeaderName]; |
5081 } | 5197 } |
5082 | 5198 |
5083 @end | 5199 @end |
OLD | NEW |