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 #include "ios/web/navigation/navigation_manager_util.h" | 5 #include "ios/web/navigation/navigation_manager_util.h" |
6 | 6 |
7 #import "ios/web/public/navigation_item.h" | 7 #import "ios/web/public/navigation_item.h" |
8 #import "ios/web/public/navigation_manager.h" | 8 #import "ios/web/public/navigation_manager.h" |
9 | 9 |
10 #if !defined(__has_feature) || !__has_feature(objc_arc) | 10 #if !defined(__has_feature) || !__has_feature(objc_arc) |
11 #error "This file requires ARC support." | 11 #error "This file requires ARC support." |
12 #endif | 12 #endif |
13 | 13 |
14 namespace web { | 14 namespace web { |
15 | 15 |
| 16 NavigationItem* GetItemWithUniqueID(NavigationManager* navigation_manager, |
| 17 int unique_id) { |
| 18 NavigationItem* transient_item = navigation_manager->GetTransientItem(); |
| 19 if (transient_item && transient_item->GetUniqueID() == unique_id) |
| 20 return transient_item; |
| 21 |
| 22 NavigationItem* pending_item = navigation_manager->GetPendingItem(); |
| 23 if (pending_item && pending_item->GetUniqueID() == unique_id) |
| 24 return pending_item; |
| 25 |
| 26 return GetCommittedItemWithUniqueID(navigation_manager, unique_id); |
| 27 } |
| 28 |
16 NavigationItem* GetCommittedItemWithUniqueID( | 29 NavigationItem* GetCommittedItemWithUniqueID( |
17 NavigationManager* navigation_manager, | 30 NavigationManager* navigation_manager, |
18 int unique_id) { | 31 int unique_id) { |
19 int index = GetCommittedItemIndexWithUniqueID(navigation_manager, unique_id); | 32 int index = GetCommittedItemIndexWithUniqueID(navigation_manager, unique_id); |
20 return index != -1 ? navigation_manager->GetItemAtIndex(index) : nullptr; | 33 return index != -1 ? navigation_manager->GetItemAtIndex(index) : nullptr; |
21 } | 34 } |
22 | 35 |
23 int GetCommittedItemIndexWithUniqueID(NavigationManager* navigation_manager, | 36 int GetCommittedItemIndexWithUniqueID(NavigationManager* navigation_manager, |
24 int unique_id) { | 37 int unique_id) { |
25 for (int i = 0; i < navigation_manager->GetItemCount(); i++) { | 38 for (int i = 0; i < navigation_manager->GetItemCount(); i++) { |
26 web::NavigationItem* item = navigation_manager->GetItemAtIndex(i); | 39 web::NavigationItem* item = navigation_manager->GetItemAtIndex(i); |
27 if (item->GetUniqueID() == unique_id) { | 40 if (item->GetUniqueID() == unique_id) { |
28 return i; | 41 return i; |
29 } | 42 } |
30 } | 43 } |
31 return -1; | 44 return -1; |
32 } | 45 } |
33 | 46 |
34 } // namespace web | 47 } // namespace web |
OLD | NEW |