| OLD | NEW |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 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/chrome/browser/web/navigation_manager_util.h" | 5 #import "ios/chrome/browser/web/navigation_manager_util.h" |
| 6 | 6 |
| 7 #if !defined(__has_feature) || !__has_feature(objc_arc) | 7 #if !defined(__has_feature) || !__has_feature(objc_arc) |
| 8 #error "This file requires ARC support." | 8 #error "This file requires ARC support." |
| 9 #endif | 9 #endif |
| 10 | |
| 11 web::NavigationItem* GetLastNonRedirectedItem( | |
| 12 web::NavigationManager* nav_manager) { | |
| 13 if (!nav_manager || !nav_manager->GetItemCount()) | |
| 14 return nullptr; | |
| 15 int index = nav_manager->GetCurrentItemIndex(); | |
| 16 web::NavigationItem* item = nullptr; | |
| 17 while (index >= 0) { | |
| 18 item = nav_manager->GetItemAtIndex(index); | |
| 19 // Returns the first non-Redirect item found. | |
| 20 if ((item->GetTransitionType() & ui::PAGE_TRANSITION_IS_REDIRECT_MASK) == 0) | |
| 21 break; | |
| 22 --index; | |
| 23 } | |
| 24 return item; | |
| 25 } | |
| OLD | NEW |