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

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

Issue 2671773005: Updated CRWSessionController interface to use NavigationItems. (Closed)
Patch Set: Eugene's comments Created 3 years, 10 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
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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/navigation_manager_impl.h" 5 #import "ios/web/navigation/navigation_manager_impl.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <utility> 9 #include <utility>
10 10
(...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after
216 216
217 NavigationItem* NavigationManagerImpl::GetPendingItem() const { 217 NavigationItem* NavigationManagerImpl::GetPendingItem() const {
218 return [[session_controller_ pendingEntry] navigationItem]; 218 return [[session_controller_ pendingEntry] navigationItem];
219 } 219 }
220 220
221 NavigationItem* NavigationManagerImpl::GetTransientItem() const { 221 NavigationItem* NavigationManagerImpl::GetTransientItem() const {
222 return [[session_controller_ transientEntry] navigationItem]; 222 return [[session_controller_ transientEntry] navigationItem];
223 } 223 }
224 224
225 void NavigationManagerImpl::DiscardNonCommittedItems() { 225 void NavigationManagerImpl::DiscardNonCommittedItems() {
226 [session_controller_ discardNonCommittedEntries]; 226 [session_controller_ discardNonCommittedItems];
227 } 227 }
228 228
229 void NavigationManagerImpl::LoadIfNecessary() { 229 void NavigationManagerImpl::LoadIfNecessary() {
230 // Nothing to do; iOS loads lazily. 230 // Nothing to do; iOS loads lazily.
231 } 231 }
232 232
233 void NavigationManagerImpl::LoadURLWithParams( 233 void NavigationManagerImpl::LoadURLWithParams(
234 const NavigationManager::WebLoadParams& params) { 234 const NavigationManager::WebLoadParams& params) {
235 delegate_->LoadURLWithParams(params); 235 delegate_->LoadURLWithParams(params);
236 } 236 }
(...skipping 15 matching lines...) Expand all
252 NavigationItem* NavigationManagerImpl::GetItemAtIndex(size_t index) const { 252 NavigationItem* NavigationManagerImpl::GetItemAtIndex(size_t index) const {
253 NSArray* entries = [session_controller_ entries]; 253 NSArray* entries = [session_controller_ entries];
254 return index < entries.count ? [entries[index] navigationItem] : nullptr; 254 return index < entries.count ? [entries[index] navigationItem] : nullptr;
255 } 255 }
256 256
257 int NavigationManagerImpl::GetCurrentItemIndex() const { 257 int NavigationManagerImpl::GetCurrentItemIndex() const {
258 return [session_controller_ currentNavigationIndex]; 258 return [session_controller_ currentNavigationIndex];
259 } 259 }
260 260
261 int NavigationManagerImpl::GetPendingItemIndex() const { 261 int NavigationManagerImpl::GetPendingItemIndex() const {
262 if ([session_controller_ hasPendingEntry]) { 262 if ([session_controller_ pendingEntry]) {
263 if ([session_controller_ pendingEntryIndex] != -1) { 263 if ([session_controller_ pendingItemIndex] != -1) {
264 return [session_controller_ pendingEntryIndex]; 264 return [session_controller_ pendingItemIndex];
265 } 265 }
266 // TODO(crbug.com/665189): understand why current item index is 266 // TODO(crbug.com/665189): understand why current item index is
267 // returned here. 267 // returned here.
268 return GetCurrentItemIndex(); 268 return GetCurrentItemIndex();
269 } 269 }
270 return -1; 270 return -1;
271 } 271 }
272 272
273 int NavigationManagerImpl::GetLastCommittedItemIndex() const { 273 int NavigationManagerImpl::GetLastCommittedItemIndex() const {
274 if (![[session_controller_ entries] count]) 274 if (![[session_controller_ entries] count])
275 return -1; 275 return -1;
276 return [session_controller_ currentNavigationIndex]; 276 return [session_controller_ currentNavigationIndex];
277 } 277 }
278 278
279 bool NavigationManagerImpl::RemoveItemAtIndex(int index) { 279 bool NavigationManagerImpl::RemoveItemAtIndex(int index) {
280 if (index == GetLastCommittedItemIndex() || index == GetPendingItemIndex()) 280 if (index == GetLastCommittedItemIndex() || index == GetPendingItemIndex())
281 return false; 281 return false;
282 282
283 NSUInteger idx = static_cast<NSUInteger>(index); 283 NSUInteger idx = static_cast<NSUInteger>(index);
284 NSArray* entries = [session_controller_ entries]; 284 NSArray* entries = [session_controller_ entries];
285 if (idx >= entries.count) 285 if (idx >= entries.count)
286 return false; 286 return false;
287 287
288 [session_controller_ removeEntryAtIndex:index]; 288 [session_controller_ removeItemAtIndex:index];
289 return true; 289 return true;
290 } 290 }
291 291
292 bool NavigationManagerImpl::CanGoBack() const { 292 bool NavigationManagerImpl::CanGoBack() const {
293 return CanGoToOffset(-1); 293 return CanGoToOffset(-1);
294 } 294 }
295 295
296 bool NavigationManagerImpl::CanGoForward() const { 296 bool NavigationManagerImpl::CanGoForward() const {
297 return CanGoToOffset(1); 297 return CanGoToOffset(1);
298 } 298 }
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
335 void NavigationManagerImpl::RemoveTransientURLRewriters() { 335 void NavigationManagerImpl::RemoveTransientURLRewriters() {
336 transient_url_rewriters_.reset(); 336 transient_url_rewriters_.reset();
337 } 337 }
338 338
339 void NavigationManagerImpl::CopyState( 339 void NavigationManagerImpl::CopyState(
340 NavigationManagerImpl* navigation_manager) { 340 NavigationManagerImpl* navigation_manager) {
341 SetSessionController([navigation_manager->GetSessionController() copy]); 341 SetSessionController([navigation_manager->GetSessionController() copy]);
342 } 342 }
343 343
344 int NavigationManagerImpl::GetIndexForOffset(int offset) const { 344 int NavigationManagerImpl::GetIndexForOffset(int offset) const {
345 int result = [session_controller_ pendingEntryIndex] == -1 345 int result = [session_controller_ pendingItemIndex] == -1
346 ? GetCurrentItemIndex() 346 ? GetCurrentItemIndex()
347 : static_cast<int>([session_controller_ pendingEntryIndex]); 347 : static_cast<int>([session_controller_ pendingItemIndex]);
348 348
349 if (offset < 0) { 349 if (offset < 0) {
350 if (GetTransientItem() && [session_controller_ pendingEntryIndex] == -1) { 350 if (GetTransientItem() && [session_controller_ pendingItemIndex] == -1) {
351 // Going back from transient item that added to the end navigation stack 351 // Going back from transient item that added to the end navigation stack
352 // is a matter of discarding it as there is no need to move navigation 352 // is a matter of discarding it as there is no need to move navigation
353 // index back. 353 // index back.
354 offset++; 354 offset++;
355 } 355 }
356 356
357 while (offset < 0 && result > 0) { 357 while (offset < 0 && result > 0) {
358 // To stop the user getting 'stuck' on redirecting pages they weren't 358 // To stop the user getting 'stuck' on redirecting pages they weren't
359 // even aware existed, it is necessary to pass over pages that would 359 // even aware existed, it is necessary to pass over pages that would
360 // immediately result in a redirect (the item *before* the redirected 360 // immediately result in a redirect (the item *before* the redirected
361 // page). 361 // page).
362 while (result > 0 && IsRedirectItemAtIndex(result)) { 362 while (result > 0 && IsRedirectItemAtIndex(result)) {
363 --result; 363 --result;
364 } 364 }
365 --result; 365 --result;
366 ++offset; 366 ++offset;
367 } 367 }
368 // Result may be out of bounds, so stop trying to skip redirect items and 368 // Result may be out of bounds, so stop trying to skip redirect items and
369 // simply add the remainder. 369 // simply add the remainder.
370 result += offset; 370 result += offset;
371 if (result > GetItemCount() /* overflow */) 371 if (result > GetItemCount() /* overflow */)
372 result = INT_MIN; 372 result = INT_MIN;
373 } else if (offset > 0) { 373 } else if (offset > 0) {
374 if (GetPendingItem() && [session_controller_ pendingEntryIndex] == -1) { 374 if (GetPendingItem() && [session_controller_ pendingItemIndex] == -1) {
375 // Chrome for iOS does not allow forward navigation if there is another 375 // Chrome for iOS does not allow forward navigation if there is another
376 // pending navigation in progress. Returning invalid index indicates that 376 // pending navigation in progress. Returning invalid index indicates that
377 // forward navigation will not be allowed (and |INT_MAX| works for that). 377 // forward navigation will not be allowed (and |INT_MAX| works for that).
378 // This is different from other platforms which allow forward navigation 378 // This is different from other platforms which allow forward navigation
379 // if pending item exist. 379 // if pending item exist.
380 // TODO(crbug.com/661858): Remove this once back-forward navigation uses 380 // TODO(crbug.com/661858): Remove this once back-forward navigation uses
381 // pending index. 381 // pending index.
382 return INT_MAX; 382 return INT_MAX;
383 } 383 }
384 while (offset > 0 && result < GetItemCount()) { 384 while (offset > 0 && result < GetItemCount()) {
(...skipping 15 matching lines...) Expand all
400 } 400 }
401 401
402 bool NavigationManagerImpl::IsRedirectItemAtIndex(int index) const { 402 bool NavigationManagerImpl::IsRedirectItemAtIndex(int index) const {
403 DCHECK_GT(index, 0); 403 DCHECK_GT(index, 0);
404 DCHECK_LT(index, GetItemCount()); 404 DCHECK_LT(index, GetItemCount());
405 ui::PageTransition transition = GetItemAtIndex(index)->GetTransitionType(); 405 ui::PageTransition transition = GetItemAtIndex(index)->GetTransitionType();
406 return transition & ui::PAGE_TRANSITION_IS_REDIRECT_MASK; 406 return transition & ui::PAGE_TRANSITION_IS_REDIRECT_MASK;
407 } 407 }
408 408
409 } // namespace web 409 } // namespace web
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698