Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(60)

Side by Side Diff: ios/web/navigation/crw_session_controller.mm

Issue 2838003002: Fix missing back navigation item when pending item is displayed. (Closed)
Patch Set: Fix edge case (no committed item) and added unit test to cover. Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | ios/web/navigation/crw_session_controller_unittest.mm » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2012 The Chromium Authors. All rights reserved. 1 // Copyright 2012 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/web/navigation/crw_session_controller.h" 5 #import "ios/web/navigation/crw_session_controller.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <algorithm> 9 #include <algorithm>
10 #include <utility> 10 #include <utility>
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after
195 return index == -1 ? nullptr : self.items[index].get(); 195 return index == -1 ? nullptr : self.items[index].get();
196 } 196 }
197 197
198 - (web::NavigationItemImpl*)previousItem { 198 - (web::NavigationItemImpl*)previousItem {
199 NSInteger index = self.previousItemIndex; 199 NSInteger index = self.previousItemIndex;
200 return index == -1 || self.items.empty() ? nullptr : self.items[index].get(); 200 return index == -1 || self.items.empty() ? nullptr : self.items[index].get();
201 } 201 }
202 202
203 - (web::NavigationItemList)backwardItems { 203 - (web::NavigationItemList)backwardItems {
204 web::NavigationItemList items; 204 web::NavigationItemList items;
205 for (size_t index = _lastCommittedItemIndex; index > 0; --index) { 205
206 if (![self isRedirectTransitionForItemAtIndex:index]) 206 // This explicit check is necessary to protect the loop below which uses an
207 items.push_back(self.items[index - 1].get()); 207 // unsafe signed (NSInteger) to unsigned (size_t) conversion.
208 if (_lastCommittedItemIndex > -1) {
209 // If the current navigation item is a transient item (e.g. SSL
210 // interstitial), the last committed item should also be considered part of
211 // the backward history.
212 DCHECK(self.lastCommittedItem);
213 if (self.transientItem) {
214 items.push_back(self.lastCommittedItem);
215 }
216
217 for (size_t index = _lastCommittedItemIndex; index > 0; --index) {
218 if (![self isRedirectTransitionForItemAtIndex:index])
219 items.push_back(self.items[index - 1].get());
220 }
208 } 221 }
209 return items; 222 return items;
210 } 223 }
211 224
212 - (web::NavigationItemList)forwardItems { 225 - (web::NavigationItemList)forwardItems {
213 web::NavigationItemList items; 226 web::NavigationItemList items;
214 NSUInteger lastNonRedirectedIndex = _lastCommittedItemIndex + 1; 227 NSUInteger lastNonRedirectedIndex = _lastCommittedItemIndex + 1;
215 while (lastNonRedirectedIndex < self.items.size()) { 228 while (lastNonRedirectedIndex < self.items.size()) {
216 web::NavigationItem* item = self.items[lastNonRedirectedIndex].get(); 229 web::NavigationItem* item = self.items[lastNonRedirectedIndex].get();
217 if (!ui::PageTransitionIsRedirect(item->GetTransitionType())) 230 if (!ui::PageTransitionIsRedirect(item->GetTransitionType()))
(...skipping 439 matching lines...) Expand 10 before | Expand all | Expand 10 after
657 return item; 670 return item;
658 } 671 }
659 672
660 - (BOOL)isRedirectTransitionForItemAtIndex:(size_t)index { 673 - (BOOL)isRedirectTransitionForItemAtIndex:(size_t)index {
661 DCHECK_LT(index, self.items.size()); 674 DCHECK_LT(index, self.items.size());
662 ui::PageTransition transition = self.items[index]->GetTransitionType(); 675 ui::PageTransition transition = self.items[index]->GetTransitionType();
663 return (transition & ui::PAGE_TRANSITION_IS_REDIRECT_MASK) ? YES : NO; 676 return (transition & ui::PAGE_TRANSITION_IS_REDIRECT_MASK) ? YES : NO;
664 } 677 }
665 678
666 @end 679 @end
OLDNEW
« no previous file with comments | « no previous file | ios/web/navigation/crw_session_controller_unittest.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698