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..bc867750778962db06457bcfab58d7b3b5ffec08 100644 |
| --- a/ios/web/navigation/navigation_manager_impl.mm |
| +++ b/ios/web/navigation/navigation_manager_impl.mm |
| @@ -343,6 +343,43 @@ 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 the page with the |
| + // original request url of the last non-redirect item (including pending item) |
| + // because a redirect may either 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, so in this case, we want to request 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(); |
| + int index = GetLastCommittedItemIndex(); |
| + while (index >= 0) { |
| + if (!IsRedirectItemAtIndex(index)) { |
| + last_non_redirect_item = GetItemAtIndex(index); |
| + break; |
| + } |
| + |
| + [session_controller_ goToItemAtIndex:(index - 1)]; |
| + bool item_removed_successfuly = RemoveItemAtIndex(index); |
| + 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 +475,7 @@ bool AreURLsInPageNavigation(const GURL& existing_url, const GURL& new_url) { |
| } |
| bool NavigationManagerImpl::IsRedirectItemAtIndex(int index) const { |
| - DCHECK_GT(index, 0); |
|
liaoyuke
2017/03/22 23:46:23
I don't see any reason why index cannot be 0. Am I
Eugene But (OOO till 7-30)
2017/03/23 00:08:19
This was a bug :)
|
| + DCHECK_GE(index, 0); |
| DCHECK_LT(index, GetItemCount()); |
| ui::PageTransition transition = GetItemAtIndex(index)->GetTransitionType(); |
| return transition & ui::PAGE_TRANSITION_IS_REDIRECT_MASK; |