Chromium Code Reviews| Index: ios/web/navigation/navigation_manager_impl.mm |
| diff --git a/ios/web/navigation/navigation_manager_impl.mm b/ios/web/navigation/navigation_manager_impl.mm |
| index 8d3ccad5d1c72df4f5f424ea43a86b2aae556e7f..9179f3c3308f84b0e662eb443d000e9db4d3f565 100644 |
| --- a/ios/web/navigation/navigation_manager_impl.mm |
| +++ b/ios/web/navigation/navigation_manager_impl.mm |
| @@ -343,6 +343,46 @@ bool AreURLsInPageNavigation(const GURL& existing_url, const GURL& new_url) { |
| void NavigationManagerImpl::Reload(ReloadType reload_type, |
| bool check_for_reposts) { |
| + // For Request Desktop/Mobile Site, we want to reload with the original |
|
Eugene But (OOO till 7-30)
2017/03/23 00:08:19
Avoid "we" in the comments (go/avoidwe)
Eugene But (OOO till 7-30)
2017/03/23 00:08:20
This method is written in generic way, independent
liaoyuke
2017/03/27 16:22:42
Done. Thank you for providing the link. :)
liaoyuke
2017/03/27 16:22:43
Done.
|
| + // request url of the last non-redirect item (including pending item) because |
| + // a server or client redirect may change the url of the current item or add a |
| + // new item. For example, an user visits www.youtube.com and is then |
| + // redirected to m.youtube.com, when the user clicks "Request Desktop Site", |
| + // we want to request the desktop version of www.youtube.com for the user |
| + // instead of m.youtube.com. |
| + if (reload_type == web::ReloadType::ORIGINAL_REQUEST_URL) { |
| + web::UserAgentType type = |
| + [session_controller_ currentItem]->GetUserAgentType(); |
| + web::NavigationItem* last_non_redirect_item = nullptr; |
| + |
| + if (GetPendingItem() && ((GetPendingItem()->GetTransitionType() & |
| + ui::PAGE_TRANSITION_IS_REDIRECT_MASK) == 0)) { |
| + last_non_redirect_item = GetPendingItem(); |
| + } else { |
| + DiscardNonCommittedItems(); |
|
Eugene But (OOO till 7-30)
2017/03/23 00:08:19
Is this necessary? Maybe CRWWebController already
liaoyuke
2017/03/27 16:22:42
Addressed per offline discussion.
|
| + DCHECK(!GetPendingItem()); |
| + |
| + int index = GetLastCommittedItemIndex(); |
| + while (index >= 0) { |
|
Eugene But (OOO till 7-30)
2017/03/23 00:08:20
Searching for last non-redirect item can be factor
liaoyuke
2017/03/27 16:22:42
|GetLastNonRedirectedItem()| in NavigationManagerU
|
| + if (!IsRedirectItemAtIndex(index)) { |
| + last_non_redirect_item = GetItemAtIndex(index); |
| + break; |
| + } |
| + |
| + [session_controller_ goToItemAtIndex:(index - 1)]; |
| + bool item_removed_successfuly = RemoveItemAtIndex(index); |
|
Eugene But (OOO till 7-30)
2017/03/23 00:08:20
Current implementation of Reload does not destroy
liaoyuke
2017/03/27 16:22:43
Addressed per offline discussion.
|
| + DCHECK(item_removed_successfuly); |
| + |
| + --index; |
| + } |
| + } |
| + |
| + DCHECK(last_non_redirect_item); |
| + last_non_redirect_item->SetURL( |
| + last_non_redirect_item->GetOriginalRequestURL()); |
| + last_non_redirect_item->SetUserAgentType(type); |
| + } |
| + |
| delegate_->Reload(); |
| } |
| @@ -438,7 +478,7 @@ bool AreURLsInPageNavigation(const GURL& existing_url, const GURL& new_url) { |
| } |
| bool NavigationManagerImpl::IsRedirectItemAtIndex(int index) const { |
| - DCHECK_GT(index, 0); |
| + DCHECK_GE(index, 0); |
| DCHECK_LT(index, GetItemCount()); |
| ui::PageTransition transition = GetItemAtIndex(index)->GetTransitionType(); |
| return transition & ui::PAGE_TRANSITION_IS_REDIRECT_MASK; |