Chromium Code Reviews| Index: ios/web/web_state/ui/crw_web_controller.mm |
| diff --git a/ios/web/web_state/ui/crw_web_controller.mm b/ios/web/web_state/ui/crw_web_controller.mm |
| index aff3c438794cd324c3227074480020cf417b8fca..653a4918fb8dd4f7b15b8920b0d22b01c2589f72 100644 |
| --- a/ios/web/web_state/ui/crw_web_controller.mm |
| +++ b/ios/web/web_state/ui/crw_web_controller.mm |
| @@ -43,7 +43,6 @@ |
| #import "ios/web/interstitials/web_interstitial_impl.h" |
| #import "ios/web/navigation/crw_session_certificate_policy_manager.h" |
| #import "ios/web/navigation/crw_session_controller.h" |
| -#import "ios/web/navigation/crw_session_entry.h" |
| #import "ios/web/navigation/navigation_item_impl.h" |
| #import "ios/web/navigation/navigation_manager_impl.h" |
| #include "ios/web/net/cert_host_pair.h" |
| @@ -463,14 +462,22 @@ @interface CRWWebController ()<CRWContextMenuDelegate, |
| // Facade for Mojo API. |
| @property(nonatomic, readonly) web::MojoFacade* mojoFacade; |
| -// Updates Desktop User Agent and calls webWillFinishHistoryNavigationFromEntry: |
| +// TODO(crbug.com/692871): Remove these functions and replace with more |
| +// appropriate NavigationItem getters. |
| +// Returns the navigation item for the current page. |
| +@property(nonatomic, readonly) web::NavigationItemImpl* currentNavItem; |
| +// Returns the current transition type. |
| +@property(nonatomic, readonly) ui::PageTransition currentTransition; |
| +// Returns the referrer for current navigation item. May be empty. |
| +@property(nonatomic, readonly) web::Referrer currentNavItemReferrer; |
| +// The HTTP headers associated with the current navigation item. These are nil |
| +// unless the request was a POST. |
| +@property(nonatomic, readonly) NSDictionary* currentHTTPHeaders; |
| + |
| +// Updates Desktop User Agent and calls webWillFinishHistoryNavigation |
| // on CRWWebDelegate. TODO(crbug.com/684098): Remove this method and inline its |
| // content. |
| -- (void)webWillFinishHistoryNavigationFromEntry:(CRWSessionEntry*)fromEntry; |
| -// Recreates web view if |entry| and |fromEntry| have different value for |
| -// IsOverridingUserAgent() flag. |
| -- (void)updateDesktopUserAgentForEntry:(CRWSessionEntry*)entry |
| - fromEntry:(CRWSessionEntry*)fromEntry; |
| +- (void)webWillFinishHistoryNavigationFromItem:(web::NavigationItem*)item; |
| // Removes the container view from the hierarchy and resets the ivar. |
| - (void)resetContainerView; |
| // Called when the web page has changed document and/or URL, and so the page |
| @@ -498,23 +505,6 @@ - (void)addPlaceholderOverlay; |
| // Removes placeholder overlay. |
| - (void)removePlaceholderOverlay; |
| -// Returns the current entry from the underlying session controller. |
| -// TODO(stuartmorgan): Audit all calls to these methods; these are just wrappers |
| -// around the same logic as GetActiveEntry, so should probably not be used for |
| -// the same reason that GetActiveEntry is deprecated. (E.g., page operations |
| -// should generally be dealing with the last commited entry, not a pending |
| -// entry). |
| -- (CRWSessionEntry*)currentSessionEntry; |
| -// Returns the navigation item for the current page. |
| -- (web::NavigationItem*)currentNavItem; |
| -// Returns the current transition type. |
| -- (ui::PageTransition)currentTransition; |
| -// Returns the referrer for current navigation item. May be empty. |
| -- (web::Referrer)currentSessionEntryReferrer; |
| -// The HTTP headers associated with the current navigation item. These are nil |
| -// unless the request was a POST. |
| -- (NSDictionary*)currentHTTPHeaders; |
| - |
| // Creates a web view if it's not yet created. |
| - (void)ensureWebViewCreated; |
| // Creates a web view with given |config|. No-op if web view is already created. |
| @@ -606,9 +596,9 @@ - (void)didFinishWithURL:(const GURL&)currentURL loadSuccess:(BOOL)loadSuccess; |
| // TODO(crbug.com/661316): Move this method to NavigationManager. |
| - (void)goDelta:(int)delta; |
| // Loads a new URL if the current entry is not from a pushState() navigation. |
| -// |fromEntry| is the CRWSessionEntry that was the current entry prior to the |
| +// |item| is the NavigationItem that was the current entry prior to the |
| // navigation. |
| -- (void)finishHistoryNavigationFromEntry:(CRWSessionEntry*)fromEntry; |
| +- (void)finishHistoryNavigationFromItem:(web::NavigationItem*)item; |
| // Informs the native controller if web usage is allowed or not. |
| - (void)setNativeControllerWebUsageEnabled:(BOOL)webUsageEnabled; |
| // Called when web controller receives a new message from the web page. |
| @@ -1292,7 +1282,7 @@ - (GURL)currentURLWithTrustLevel:(web::URLVerificationTrustLevel*)trustLevel { |
| return [self.nativeController url]; |
| } |
| } |
| - web::NavigationItem* item = [self currentNavItem]; |
| + web::NavigationItem* item = self.currentNavItem; |
| return item ? item->GetVirtualURL() : GURL::EmptyGURL(); |
| } |
| @@ -1320,7 +1310,7 @@ - (GURL)currentURL { |
| if ([referrerString length] == 0) |
| return web::Referrer(); |
| - web::NavigationItem* item = [self currentNavItem]; |
| + web::NavigationItem* item = self.currentNavItem; |
| GURL navigationURL = item ? item->GetVirtualURL() : GURL::EmptyGURL(); |
| NSString* previousURLString = base::SysUTF8ToNSString(navigationURL.spec()); |
| // Check if the referrer is equal to the previous URL minus the hash symbol. |
| @@ -1407,7 +1397,7 @@ - (BOOL)isCurrentNavigationItemPOST { |
| } |
| - (BOOL)isCurrentNavigationBackForward { |
| - if (![self currentNavItem]) |
| + if (!self.currentNavItem) |
| return NO; |
| WKNavigationType currentNavigationType = |
| [self currentBackForwardListItemHolder]->navigation_type(); |
| @@ -1588,8 +1578,7 @@ - (void)registerLoadRequest:(const GURL&)requestURL |
| } |
| - (void)updateHTML5HistoryState { |
| - web::NavigationItemImpl* currentItem = |
| - static_cast<web::NavigationItemImpl*>([self currentNavItem]); |
| + web::NavigationItemImpl* currentItem = self.currentNavItem; |
| if (!currentItem) |
| return; |
| @@ -1601,9 +1590,8 @@ - (void)updateHTML5HistoryState { |
| // WKWebView doesn't send hashchange events for same-document non-BFLI |
| // navigations, so one must be dispatched manually for hash change same- |
| // document navigations. |
| - web::NavigationItem* previousItem = |
| - self.sessionController.previousEntry.navigationItem; |
| const GURL URL = currentItem->GetURL(); |
| + web::NavigationItem* previousItem = self.sessionController.previousItem; |
| const GURL oldURL = previousItem ? previousItem->GetURL() : GURL(); |
| BOOL shouldDispatchHashchange = sameDocumentNavigation && previousItem && |
| (web::GURLByRemovingRefFromGURL(URL) == |
| @@ -1656,8 +1644,7 @@ - (NSString*)javaScriptToDispatchHashChangeWithOldURL:(const GURL&)oldURL |
| - (void)injectHTML5HistoryScriptWithHashChange:(BOOL)dispatchHashChange |
| sameDocumentNavigation:(BOOL)sameDocumentNavigation { |
| - web::NavigationItemImpl* currentItem = |
| - static_cast<web::NavigationItemImpl*>([self currentNavItem]); |
| + web::NavigationItemImpl* currentItem = self.currentNavItem; |
| if (!currentItem) |
| return; |
| @@ -1672,7 +1659,7 @@ - (void)injectHTML5HistoryScriptWithHashChange:(BOOL)dispatchHashChange |
| } |
| if (dispatchHashChange) { |
| web::NavigationItemImpl* previousItem = |
| - self.sessionController.previousEntry.navigationItemImpl; |
| + self.sessionController.previousItem; |
| const GURL oldURL = previousItem ? previousItem->GetURL() : GURL(); |
| [script appendString:[self javaScriptToDispatchHashChangeWithOldURL:oldURL |
| newURL:URL]]; |
| @@ -1693,7 +1680,7 @@ - (void)loadCurrentURLInWebView { |
| // Clear the set of URLs opened in external applications. |
| _openedApplicationURL.reset([[NSMutableSet alloc] init]); |
| - web::NavigationItem* item = [self currentNavItem]; |
| + web::NavigationItem* item = self.currentNavItem; |
| GURL targetURL = item ? item->GetVirtualURL() : GURL::EmptyGURL(); |
| // Load the url. The UIWebView delegate callbacks take care of updating the |
| // session history and UI. |
| @@ -1748,12 +1735,12 @@ - (void)commitPendingNavigationInfo { |
| } |
| - (NSMutableURLRequest*)requestForCurrentNavigationItem { |
| - web::NavigationItem* item = [self currentNavItem]; |
| + web::NavigationItem* item = self.currentNavItem; |
| const GURL currentNavigationURL = |
| item ? item->GetVirtualURL() : GURL::EmptyGURL(); |
| NSMutableURLRequest* request = [NSMutableURLRequest |
| requestWithURL:net::NSURLWithGURL(currentNavigationURL)]; |
| - const web::Referrer referrer([self currentSessionEntryReferrer]); |
| + const web::Referrer referrer(self.currentNavItemReferrer); |
| if (referrer.url.is_valid()) { |
| std::string referrerValue = |
| web::ReferrerHeaderValueForNavigation(currentNavigationURL, referrer); |
| @@ -1766,7 +1753,7 @@ - (NSMutableURLRequest*)requestForCurrentNavigationItem { |
| // If there are headers in the current session entry add them to |request|. |
| // Headers that would overwrite fields already present in |request| are |
| // skipped. |
| - NSDictionary* headers = [self currentHTTPHeaders]; |
| + NSDictionary* headers = self.currentHTTPHeaders; |
| for (NSString* headerName in headers) { |
| if (![request valueForHTTPHeaderField:headerName]) { |
| [request setValue:[headers objectForKey:headerName] |
| @@ -1778,7 +1765,7 @@ - (NSMutableURLRequest*)requestForCurrentNavigationItem { |
| } |
| - (web::WKBackForwardListItemHolder*)currentBackForwardListItemHolder { |
| - web::NavigationItem* item = [self currentSessionEntry].navigationItemImpl; |
| + web::NavigationItem* item = self.currentNavItem; |
| DCHECK(item); |
| web::WKBackForwardListItemHolder* holder = |
| web::WKBackForwardListItemHolder::FromNavigationItem(item); |
| @@ -1834,7 +1821,7 @@ - (void)loadNativeViewWithSuccess:(BOOL)loadSuccess { |
| - (void)loadErrorInNativeView:(NSError*)error { |
| [self removeWebViewAllowingCachedReconstruction:NO]; |
| - web::NavigationItem* item = [self currentNavItem]; |
| + web::NavigationItem* item = self.currentNavItem; |
| const GURL currentURL = item ? item->GetVirtualURL() : GURL::EmptyGURL(); |
| if (web::IsWKWebViewSSLCertError(error)) { |
| @@ -1862,7 +1849,7 @@ - (void)loadCurrentURLInNativeView { |
| // Free the web view. |
| [self removeWebViewAllowingCachedReconstruction:NO]; |
| - web::NavigationItem* item = [self currentNavItem]; |
| + web::NavigationItem* item = self.currentNavItem; |
| const GURL targetURL = item ? item->GetURL() : GURL::EmptyGURL(); |
| const web::Referrer referrer; |
| id<CRWNativeContent> nativeContent = |
| @@ -1876,7 +1863,7 @@ - (void)loadCurrentURLInNativeView { |
| [self registerLoadRequest:targetURL |
| referrer:referrer |
| - transition:[self currentTransition]]; |
| + transition:self.currentTransition]; |
| [self loadNativeViewWithSuccess:YES]; |
| } |
| @@ -1917,14 +1904,13 @@ - (void)loadWithParams:(const NavigationManager::WebLoadParams&)originalParams { |
| CRWSessionController* history = |
| _webStateImpl->GetNavigationManagerImpl().GetSessionController(); |
| - if (!self.currentSessionEntry) |
| + if (!history.currentItem) |
| initialNavigation = YES; |
| [history addPendingItem:navUrl |
| referrer:params.referrer |
| transition:transition |
| rendererInitiated:params.is_renderer_initiated]; |
| - web::NavigationItemImpl* addedItem = |
| - [self currentSessionEntry].navigationItemImpl; |
| + web::NavigationItemImpl* addedItem = history.currentItem; |
| DCHECK(addedItem); |
| if (params.extra_headers) |
| addedItem->AddHttpRequestHeaders(params.extra_headers); |
| @@ -1960,7 +1946,7 @@ - (void)loadCurrentURL { |
| // Remove the transient content view. |
| [self clearTransientContentView]; |
| - web::NavigationItem* item = [self currentNavItem]; |
| + web::NavigationItem* item = self.currentNavItem; |
| const GURL currentURL = item ? item->GetURL() : GURL::EmptyGURL(); |
| // If it's a chrome URL, but not a native one, create the WebUI instance. |
| if (web::GetWebClient()->IsAppSpecificURL(currentURL) && |
| @@ -2028,7 +2014,7 @@ - (void)triggerPendingLoad { |
| [_containerView addGestureRecognizer:[self touchTrackingRecognizer]]; |
| // Is |currentUrl| a web scheme or native chrome scheme. |
| - web::NavigationItem* item = [self currentNavItem]; |
| + web::NavigationItem* item = self.currentNavItem; |
| const GURL currentNavigationURL = |
| item ? item->GetVirtualURL() : GURL::EmptyGURL(); |
| BOOL isChromeScheme = |
| @@ -2143,29 +2129,29 @@ - (void)loadCancelled { |
| - (void)goToItemAtIndex:(int)index { |
| CRWSessionController* sessionController = self.sessionController; |
| - NSArray* entries = sessionController.entries; |
| - if (index < 0 || index >= static_cast<int>(entries.count)) { |
| + web::NavigationItemList items = sessionController.items; |
| + if (index < 0 || index >= static_cast<int>(items.size())) { |
| NOTREACHED(); |
| return; |
| } |
| if (!_webStateImpl->IsShowingWebInterstitial()) |
| [self recordStateInHistory]; |
| - CRWSessionEntry* fromEntry = sessionController.currentEntry; |
| - CRWSessionEntry* toEntry = entries[index]; |
| + web::NavigationItem* fromItem = sessionController.currentItem; |
| + web::NavigationItem* toItem = items[index]; |
| NSUserDefaults* userDefaults = [NSUserDefaults standardUserDefaults]; |
| if (![userDefaults boolForKey:@"PendingIndexNavigationDisabled"]) { |
| [self clearTransientContentView]; |
| BOOL sameDocumentNavigation = [sessionController |
| - isSameDocumentNavigationBetweenItem:fromEntry.navigationItem |
| - andItem:toEntry.navigationItem]; |
| + isSameDocumentNavigationBetweenItem:fromItem |
| + andItem:toItem]; |
| if (sameDocumentNavigation) { |
| [self.sessionController goToItemAtIndex:index]; |
| // TODO(crbug.com/684098): move this call out this block to avoid code |
| // duplication. |
| - [self webWillFinishHistoryNavigationFromEntry:fromEntry]; |
| + [self webWillFinishHistoryNavigationFromItem:fromItem]; |
| [self updateHTML5HistoryState]; |
| } else { |
| [sessionController discardNonCommittedItems]; |
| @@ -2173,10 +2159,9 @@ - (void)goToItemAtIndex:(int)index { |
| // TODO(crbug.com/684098): move this call out this block to avoid code |
| // duplication. |
| - [self webWillFinishHistoryNavigationFromEntry:fromEntry]; |
| + [self webWillFinishHistoryNavigationFromItem:fromItem]; |
| - web::NavigationItemImpl* pendingItem = |
| - sessionController.pendingEntry.navigationItemImpl; |
| + web::NavigationItemImpl* pendingItem = sessionController.pendingItem; |
| pendingItem->SetTransitionType(ui::PageTransitionFromInt( |
| pendingItem->GetTransitionType() | ui::PAGE_TRANSITION_FORWARD_BACK)); |
| @@ -2184,8 +2169,8 @@ - (void)goToItemAtIndex:(int)index { |
| } |
| } else { |
| [self.sessionController goToItemAtIndex:index]; |
| - if (fromEntry) |
| - [self finishHistoryNavigationFromEntry:fromEntry]; |
| + if (fromItem) |
| + [self finishHistoryNavigationFromItem:fromItem]; |
| } |
| } |
| @@ -2249,7 +2234,7 @@ - (void)didFinishWithURL:(const GURL&)currentURL loadSuccess:(BOOL)loadSuccess { |
| // NSURLRequest. |
| if (_webUIManager) { |
| web::NavigationItem* lastNavigationItem = |
| - self.sessionController.previousEntry.navigationItem; |
| + self.sessionController.previousItem; |
| if (lastNavigationItem) { |
| web::WKBackForwardListItemHolder* holder = |
| web::WKBackForwardListItemHolder::FromNavigationItem( |
| @@ -2280,19 +2265,18 @@ - (void)goDelta:(int)delta { |
| } |
| } |
| -- (void)finishHistoryNavigationFromEntry:(CRWSessionEntry*)fromEntry { |
| - [self webWillFinishHistoryNavigationFromEntry:fromEntry]; |
| +- (void)finishHistoryNavigationFromItem:(web::NavigationItem*)item { |
| + [self webWillFinishHistoryNavigationFromItem:item]; |
| // Only load the new URL if it has a different document than |fromEntry| to |
| // prevent extra page loads from NavigationItems created by hash changes or |
| // calls to window.history.pushState(). |
| BOOL shouldLoadURL = |
| ![_webStateImpl->GetNavigationManagerImpl().GetSessionController() |
| - isSameDocumentNavigationBetweenItem:fromEntry.navigationItem |
| + isSameDocumentNavigationBetweenItem:item |
| andItem:self.currentNavItem]; |
| - web::NavigationItemImpl* currentItem = |
| - self.currentSessionEntry.navigationItemImpl; |
| - GURL endURL = [self URLForHistoryNavigationFromItem:fromEntry.navigationItem |
| + web::NavigationItemImpl* currentItem = self.currentNavItem; |
| + GURL endURL = [self URLForHistoryNavigationFromItem:item |
| toItem:currentItem]; |
| if (shouldLoadURL) { |
| ui::PageTransition transition = ui::PageTransitionFromInt( |
| @@ -2364,7 +2348,7 @@ - (BOOL)shouldClosePageOnNativeApplicationLoad { |
| } |
| - (BOOL)useDesktopUserAgent { |
| - web::NavigationItem* item = [self currentNavItem]; |
| + web::NavigationItem* item = self.currentNavItem; |
| return item && item->IsOverridingUserAgent(); |
| } |
| @@ -2404,23 +2388,16 @@ - (CRWPassKitDownloader*)passKitDownloader { |
| return _passKitDownloader.get(); |
| } |
| -- (void)webWillFinishHistoryNavigationFromEntry:(CRWSessionEntry*)fromEntry { |
| - DCHECK(fromEntry); |
| - [self updateDesktopUserAgentForEntry:self.currentSessionEntry |
| - fromEntry:fromEntry]; |
| - [_delegate webWillFinishHistoryNavigationFromEntry:fromEntry]; |
| -} |
| - |
| -- (void)updateDesktopUserAgentForEntry:(CRWSessionEntry*)entry |
| - fromEntry:(CRWSessionEntry*)fromEntry { |
| - web::NavigationItemImpl* item = entry.navigationItemImpl; |
| - web::NavigationItemImpl* fromItem = fromEntry.navigationItemImpl; |
| - if (!item || !fromItem) |
| - return; |
| - bool useDesktopUserAgent = item->IsOverridingUserAgent(); |
| - if (useDesktopUserAgent != fromItem->IsOverridingUserAgent()) { |
| +- (void)webWillFinishHistoryNavigationFromItem:(web::NavigationItem*)item { |
| + DCHECK(item); |
| + // Require page reconstruction if the current NavigationItem and |item| have |
| + // a different user agent. |
| + if (self.currentNavItem->IsOverridingUserAgent() != |
| + item->IsOverridingUserAgent()) { |
| [self requirePageReconstruction]; |
| } |
| + // Inform the delegate. |
| + [_delegate webWillFinishHistoryNavigation]; |
| } |
| #pragma mark - |
| @@ -2871,7 +2848,7 @@ - (BOOL)handleWindowHashChangeMessage:(base::DictionaryValue*)message |
| _dispatchingSameDocumentHashChangeEvent = NO; |
| } else { |
| web::NavigationItemImpl* item = |
| - static_cast<web::NavigationItemImpl*>([self currentNavItem]); |
| + static_cast<web::NavigationItemImpl*>(self.currentNavItem); |
|
Eugene But (OOO till 7-30)
2017/02/21 23:29:24
Do you need this cast? |currentNavItem| returns we
kkhorimoto
2017/03/02 22:01:11
Removed
|
| DCHECK(item); |
| item->SetIsCreatedFromHashChange(true); |
| } |
| @@ -2919,7 +2896,7 @@ - (BOOL)handleWindowHistoryDidPushStateMessage:(base::DictionaryValue*)message |
| // previous page, ignore it and allow the previously registered navigation to |
| // continue. This can ocur if a pushState is issued from an anchor tag |
| // onClick event, as the click would have already been registered. |
| - if ([self sessionController].pendingEntry) |
| + if ([self sessionController].pendingItem) |
| return NO; |
| std::string pageURL; |
| @@ -2936,13 +2913,13 @@ - (BOOL)handleWindowHistoryDidPushStateMessage:(base::DictionaryValue*)message |
| pushURL = URLEscapedForHistory(pushURL); |
| if (!pushURL.is_valid()) |
| return YES; |
| - web::NavigationItem* navItem = [self currentNavItem]; |
| + web::NavigationItem* navItem = self.currentNavItem; |
| // PushState happened before first navigation entry or called when the |
| // navigation entry does not contain a valid URL. |
| if (!navItem || !navItem->GetURL().is_valid()) |
| return YES; |
| if (!web::history_state_util::IsHistoryStateChangeValid( |
| - [self currentNavItem]->GetURL(), pushURL)) { |
| + self.currentNavItem->GetURL(), pushURL)) { |
| // If the current session entry URL origin still doesn't match pushURL's |
| // origin, ignore the pushState. This can happen if a new URL is loaded |
| // just before the pushState. |
| @@ -3005,14 +2982,14 @@ - (BOOL)handleWindowHistoryDidReplaceStateMessage: |
| return YES; |
| const NavigationManagerImpl& navigationManager = |
| _webStateImpl->GetNavigationManagerImpl(); |
| - web::NavigationItem* navItem = [self currentNavItem]; |
| + web::NavigationItem* navItem = self.currentNavItem; |
| // ReplaceState happened before first navigation entry or called right |
| // after window.open when the url is empty/not valid. |
| if (!navItem || |
| (navigationManager.GetItemCount() <= 1 && navItem->GetURL().is_empty())) |
| return YES; |
| if (!web::history_state_util::IsHistoryStateChangeValid( |
| - [self currentNavItem]->GetURL(), replaceURL)) { |
| + self.currentNavItem->GetURL(), replaceURL)) { |
| // If the current session entry URL origin still doesn't match |
| // replaceURL's origin, ignore the replaceState. This can happen if a |
| // new URL is loaded just before the replaceState. |
| @@ -3068,7 +3045,7 @@ - (void)webPageChanged { |
| // If no referrer was known in advance, record it now. (If there was one, |
| // keep it since it will have a more accurate URL and policy than what can |
| // be extracted from the landing page.) |
| - web::NavigationItem* currentItem = [self currentNavItem]; |
| + web::NavigationItem* currentItem = self.currentNavItem; |
| if (!currentItem->GetReferrer().url.is_valid()) { |
| currentItem->SetReferrer(referrer); |
| } |
| @@ -3128,18 +3105,17 @@ - (BOOL)userInteractionRegistered { |
| } |
| - (void)cachePOSTDataForRequest:(NSURLRequest*)request |
| - inSessionEntry:(CRWSessionEntry*)currentSessionEntry { |
| + inNavigationItem:(web::NavigationItemImpl*)item { |
| NSUInteger maxPOSTDataSizeInBytes = 4096; |
| NSString* cookieHeaderName = @"cookie"; |
| - web::NavigationItemImpl* currentItem = currentSessionEntry.navigationItemImpl; |
| - DCHECK(currentItem); |
| + DCHECK(item); |
| const bool shouldUpdateEntry = |
| - ui::PageTransitionCoreTypeIs(currentItem->GetTransitionType(), |
| + ui::PageTransitionCoreTypeIs(item->GetTransitionType(), |
| ui::PAGE_TRANSITION_FORM_SUBMIT) && |
| ![request HTTPBodyStream] && // Don't cache streams. |
| - !currentItem->HasPostData() && |
| - currentItem->GetURL() == net::GURLWithNSURL([request URL]); |
| + !item->HasPostData() && |
| + item->GetURL() == net::GURLWithNSURL([request URL]); |
| const bool belowSizeCap = |
| [[request HTTPBody] length] < maxPOSTDataSizeInBytes; |
| DLOG_IF(WARNING, shouldUpdateEntry && !belowSizeCap) |
| @@ -3147,15 +3123,15 @@ - (void)cachePOSTDataForRequest:(NSURLRequest*)request |
| << " bytes), and will not be cached."; |
| if (shouldUpdateEntry && belowSizeCap) { |
| - currentItem->SetPostData([request HTTPBody]); |
| - currentItem->ResetHttpRequestHeaders(); |
| - currentItem->AddHttpRequestHeaders([request allHTTPHeaderFields]); |
| + item->SetPostData([request HTTPBody]); |
| + item->ResetHttpRequestHeaders(); |
| + item->AddHttpRequestHeaders([request allHTTPHeaderFields]); |
| // Don't cache the "Cookie" header. |
| // According to NSURLRequest documentation, |-valueForHTTPHeaderField:| is |
| // case insensitive, so it's enough to test the lower case only. |
| if ([request valueForHTTPHeaderField:cookieHeaderName]) { |
| // Case insensitive search in |headers|. |
| - NSSet* cookieKeys = [currentItem->GetHttpRequestHeaders() |
| + NSSet* cookieKeys = [item->GetHttpRequestHeaders() |
| keysOfEntriesPassingTest:^(id key, id obj, BOOL* stop) { |
| NSString* header = (NSString*)key; |
| const BOOL found = |
| @@ -3165,7 +3141,7 @@ - (void)cachePOSTDataForRequest:(NSURLRequest*)request |
| return found; |
| }]; |
| DCHECK_EQ(1u, [cookieKeys count]); |
| - currentItem->RemoveHttpRequestHeaderForKey([cookieKeys anyObject]); |
| + item->RemoveHttpRequestHeaderForKey([cookieKeys anyObject]); |
| } |
| } |
| } |
| @@ -3189,9 +3165,9 @@ - (BOOL)shouldAllowLoadWithNavigationAction:(WKNavigationAction*)action { |
| !_webStateImpl->GetNavigationManager()->GetItemCount(); |
| BOOL isPossibleLinkClick = [self isLinkNavigation:action.navigationType]; |
| if (isPossibleLinkClick || isOpenInNewTabNavigation || |
| - PageTransitionCoreTypeIs([self currentTransition], |
| + PageTransitionCoreTypeIs(self.currentTransition, |
| ui::PAGE_TRANSITION_AUTO_BOOKMARK)) { |
| - web::NavigationItem* item = [self currentNavItem]; |
| + web::NavigationItem* item = self.currentNavItem; |
| const GURL currentNavigationURL = |
| item ? item->GetVirtualURL() : GURL::EmptyGURL(); |
| // Check If the URL is handled by a native app. |
| @@ -3259,11 +3235,11 @@ - (BOOL)shouldAllowLoadWithNavigationAction:(WKNavigationAction*)action { |
| } |
| if ([[request HTTPMethod] isEqualToString:@"POST"]) { |
| - CRWSessionEntry* currentEntry = [self currentSessionEntry]; |
| + web::NavigationItemImpl* item = self.currentNavItem; |
| // TODO(crbug.com/570699): Remove this check once it's no longer possible to |
| // have no current entries. |
| - if (currentEntry) |
| - [self cachePOSTDataForRequest:request inSessionEntry:currentEntry]; |
| + if (item) |
| + [self cachePOSTDataForRequest:request inNavigationItem:item]; |
| } |
| return YES; |
| @@ -3662,35 +3638,31 @@ - (CRWSessionController*)sessionController { |
| : nil; |
| } |
| -- (CRWSessionEntry*)currentSessionEntry { |
| - return [[self sessionController] currentEntry]; |
| -} |
| - |
| -- (web::NavigationItem*)currentNavItem { |
| +- (web::NavigationItemImpl*)currentNavItem { |
| // This goes through the legacy Session* interface rather than Navigation* |
| // because it is itself a legacy method that should not exist, and this |
| // avoids needing to add a GetActiveItem to NavigationManager. If/when this |
| // method chain becomes a blocker to eliminating SessionController, the logic |
| // can be moved here, using public NavigationManager getters. That's not |
| // done now in order to avoid code duplication. |
| - return [[self currentSessionEntry] navigationItem]; |
| + return [[self sessionController] currentItem]; |
| } |
| - (ui::PageTransition)currentTransition { |
| - if ([self currentNavItem]) |
| - return [self currentNavItem]->GetTransitionType(); |
| + if (self.currentNavItem) |
| + return self.currentNavItem->GetTransitionType(); |
| else |
| return ui::PageTransitionFromInt(0); |
| } |
| -- (web::Referrer)currentSessionEntryReferrer { |
| - web::NavigationItem* currentItem = [self currentNavItem]; |
| +- (web::Referrer)currentNavItemReferrer { |
| + web::NavigationItem* currentItem = self.currentNavItem; |
| return currentItem ? currentItem->GetReferrer() : web::Referrer(); |
| } |
| - (NSDictionary*)currentHTTPHeaders { |
| - DCHECK([self currentSessionEntry]); |
| - return [self currentSessionEntry].navigationItem->GetHttpRequestHeaders(); |
| + web::NavigationItem* currentItem = self.currentNavItem; |
| + return currentItem ? currentItem->GetHttpRequestHeaders() : nil; |
| } |
| #pragma mark - |
| @@ -3716,7 +3688,7 @@ - (void)webViewScrollViewDidZoom: |
| - (void)webViewScrollViewDidResetContentSize: |
| (CRWWebViewScrollViewProxy*)webViewScrollViewProxy { |
| - web::NavigationItem* currentItem = [self currentNavItem]; |
| + web::NavigationItem* currentItem = self.currentNavItem; |
| if (webViewScrollViewProxy.isZooming || _applyingPageState || !currentItem) |
| return; |
| CGSize contentSize = webViewScrollViewProxy.contentSize; |
| @@ -3761,17 +3733,17 @@ - (void)recordStateInHistory { |
| // Only record the state if: |
| // - the current NavigationItem's URL matches the current URL, and |
| // - the user has interacted with the page. |
| - CRWSessionEntry* current = [self currentSessionEntry]; |
| - if (current && [current navigationItem]->GetURL() == [self currentURL] && |
| + web::NavigationItem* item = self.currentNavItem; |
| + if (item && item->GetURL() == [self currentURL] && |
| self.userInteractionRegistered) { |
| - [current navigationItem]->SetPageDisplayState(self.pageDisplayState); |
| + item->SetPageDisplayState(self.pageDisplayState); |
| } |
| } |
| - (void)restoreStateFromHistory { |
| - CRWSessionEntry* current = [self currentSessionEntry]; |
| - if ([current navigationItem]) |
| - self.pageDisplayState = [current navigationItem]->GetPageDisplayState(); |
| + web::NavigationItem* item = self.currentNavItem; |
| + if (item) |
| + self.pageDisplayState = item->GetPageDisplayState(); |
| } |
| - (web::PageDisplayState)pageDisplayState { |
| @@ -3812,7 +3784,7 @@ - (void)setPageDisplayState:(web::PageDisplayState)displayState { |
| - (void)extractViewportTagWithCompletion:(ViewportStateCompletion)completion { |
| DCHECK(completion); |
| - web::NavigationItem* currentItem = [self currentNavItem]; |
| + web::NavigationItem* currentItem = self.currentNavItem; |
| if (!currentItem) { |
| completion(nullptr); |
| return; |
| @@ -3885,7 +3857,7 @@ - (void)applyPageDisplayState:(const web::PageDisplayState&)displayState |
| // Early return if |scrollState| doesn't match the current NavigationItem. |
| // This can sometimes occur in tests, as navigation occurs programmatically |
| // and |-applyPageScrollState:| is asynchronous. |
| - web::NavigationItem* currentItem = [self currentSessionEntry].navigationItem; |
| + web::NavigationItem* currentItem = self.currentNavItem; |
| if (currentItem && currentItem->GetPageDisplayState() != displayState) |
| return; |
| DCHECK(displayState.IsValid()); |
| @@ -4338,7 +4310,7 @@ - (void)removeWebViewAllowingCachedReconstruction:(BOOL)allowCache { |
| _webStateImpl->CancelDialogs(); |
| - web::NavigationItem* item = [self currentNavItem]; |
| + web::NavigationItem* item = self.currentNavItem; |
| if (allowCache && item) { |
| _expectedReconstructionURL = item->GetVirtualURL(); |
| } else { |
| @@ -4420,7 +4392,7 @@ - (void)stopLoading { |
| // observers of the change via |-abortLoad|. |
| [[self sessionController] discardNonCommittedItems]; |
| [self abortLoad]; |
| - web::NavigationItem* item = [self currentNavItem]; |
| + web::NavigationItem* item = self.currentNavItem; |
| GURL navigationURL = item ? item->GetVirtualURL() : GURL::EmptyGURL(); |
| // If discarding the non-committed entries results in an app-specific URL, |
| // reload it in its native view. |
| @@ -4673,7 +4645,7 @@ - (void)webView:(WKWebView*)webView |
| } |
| } |
| - if (![self currentSessionEntry]) { |
| + if (!self.currentNavItem) { |
| // In this state CRWWebController will crash in |didCommitNavigation:| |
| // (crbug.com/676458). It's unclear if web controller could get into this |
| // state but it's one of the guesses for crbug.com/676458 root cause. Report |
| @@ -5151,7 +5123,7 @@ - (BOOL)isLoadRequestPendingForURL:(const GURL&)targetURL { |
| - (void)loadRequestForCurrentNavigationItem { |
| DCHECK(_webView && !self.nativeController); |
| - DCHECK([self currentSessionEntry]); |
| + DCHECK(self.currentNavItem); |
| // If a load is kicked off on a WKWebView with a frame whose size is {0, 0} or |
| // that has a negative dimension for a size, rendering issues occur that |
| // manifest in erroneous scrolling and tap handling (crbug.com/574996, |
| @@ -5165,8 +5137,7 @@ - (void)loadRequestForCurrentNavigationItem { |
| [holder->http_method() isEqual:@"POST"] && |
| (holder->navigation_type() == WKNavigationTypeFormResubmitted || |
| holder->navigation_type() == WKNavigationTypeFormSubmitted); |
| - web::NavigationItemImpl* currentItem = |
| - [self currentSessionEntry].navigationItemImpl; |
| + web::NavigationItemImpl* currentItem = self.currentNavItem; |
| NSData* POSTData = currentItem->GetPostData(); |
| NSMutableURLRequest* request = [self requestForCurrentNavigationItem]; |
| @@ -5175,22 +5146,22 @@ - (void)loadRequestForCurrentNavigationItem { |
| if (POSTData.length && !repostedForm) { |
| [request setHTTPMethod:@"POST"]; |
| [request setHTTPBody:POSTData]; |
| - [request setAllHTTPHeaderFields:[self currentHTTPHeaders]]; |
| + [request setAllHTTPHeaderFields:self.currentHTTPHeaders]; |
| GURL navigationURL = |
| currentItem ? currentItem->GetURL() : GURL::EmptyGURL(); |
| [self registerLoadRequest:navigationURL |
| - referrer:[self currentSessionEntryReferrer] |
| - transition:[self currentTransition]]; |
| + referrer:self.currentNavItemReferrer |
| + transition:self.currentTransition]; |
| [self loadPOSTRequest:request]; |
| return; |
| } |
| ProceduralBlock defaultNavigationBlock = ^{ |
| - web::NavigationItem* item = [self currentNavItem]; |
| + web::NavigationItem* item = self.currentNavItem; |
| GURL navigationURL = item ? item->GetURL() : GURL::EmptyGURL(); |
| [self registerLoadRequest:navigationURL |
| - referrer:[self currentSessionEntryReferrer] |
| - transition:[self currentTransition]]; |
| + referrer:self.currentNavItemReferrer |
| + transition:self.currentTransition]; |
| [self loadRequest:request]; |
| }; |
| @@ -5221,11 +5192,11 @@ - (void)loadRequestForCurrentNavigationItem { |
| // page, that means the user requested a reload. |goToBackForwardListItem| |
| // will be a no-op when it is passed the current back forward list item, |
| // so |reload| must be explicitly called. |
| - web::NavigationItem* item = [self currentNavItem]; |
| + web::NavigationItem* item = self.currentNavItem; |
| GURL navigationURL = item ? item->GetURL() : GURL::EmptyGURL(); |
| [self registerLoadRequest:navigationURL |
| - referrer:[self currentSessionEntryReferrer] |
| - transition:[self currentTransition]]; |
| + referrer:self.currentNavItemReferrer |
| + transition:self.currentTransition]; |
| if (navigationURL == net::GURLWithNSURL([_webView URL])) { |
| [_navigationStates setState:web::WKNavigationState::REQUESTED |
| forNavigation:[_webView reload]]; |