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

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

Issue 2672723003: Converted CRWSessionController to use NavigationItems. (Closed)
Patch Set: test fixes, self review 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 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
79 79
80 [session_controller_ setNavigationManager:nullptr]; 80 [session_controller_ setNavigationManager:nullptr];
81 } 81 }
82 82
83 void NavigationManagerImpl::SetDelegate(NavigationManagerDelegate* delegate) { 83 void NavigationManagerImpl::SetDelegate(NavigationManagerDelegate* delegate) {
84 delegate_ = delegate; 84 delegate_ = delegate;
85 } 85 }
86 86
87 void NavigationManagerImpl::SetBrowserState(BrowserState* browser_state) { 87 void NavigationManagerImpl::SetBrowserState(BrowserState* browser_state) {
88 browser_state_ = browser_state; 88 browser_state_ = browser_state;
89 [session_controller_ setBrowserState:(browser_state)];
89 } 90 }
90 91
91 void NavigationManagerImpl::SetSessionController( 92 void NavigationManagerImpl::SetSessionController(
92 CRWSessionController* session_controller) { 93 CRWSessionController* session_controller) {
93 session_controller_.reset(session_controller); 94 session_controller_.reset(session_controller);
94 [session_controller_ setNavigationManager:this]; 95 [session_controller_ setNavigationManager:this];
95 } 96 }
96 97
97 void NavigationManagerImpl::InitializeSession(NSString* window_name, 98 void NavigationManagerImpl::InitializeSession(NSString* window_name,
98 NSString* opener_id, 99 NSString* opener_id,
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
215 216
216 NavigationItem* NavigationManagerImpl::GetPendingItem() const { 217 NavigationItem* NavigationManagerImpl::GetPendingItem() const {
217 return [[session_controller_ pendingEntry] navigationItem]; 218 return [[session_controller_ pendingEntry] navigationItem];
218 } 219 }
219 220
220 NavigationItem* NavigationManagerImpl::GetTransientItem() const { 221 NavigationItem* NavigationManagerImpl::GetTransientItem() const {
221 return [[session_controller_ transientEntry] navigationItem]; 222 return [[session_controller_ transientEntry] navigationItem];
222 } 223 }
223 224
224 void NavigationManagerImpl::DiscardNonCommittedItems() { 225 void NavigationManagerImpl::DiscardNonCommittedItems() {
225 [session_controller_ discardNonCommittedEntries]; 226 [session_controller_ discardNonCommittedItems];
226 } 227 }
227 228
228 void NavigationManagerImpl::LoadIfNecessary() { 229 void NavigationManagerImpl::LoadIfNecessary() {
229 // Nothing to do; iOS loads lazily. 230 // Nothing to do; iOS loads lazily.
230 } 231 }
231 232
232 void NavigationManagerImpl::LoadURLWithParams( 233 void NavigationManagerImpl::LoadURLWithParams(
233 const NavigationManager::WebLoadParams& params) { 234 const NavigationManager::WebLoadParams& params) {
234 delegate_->LoadURLWithParams(params); 235 delegate_->LoadURLWithParams(params);
235 } 236 }
(...skipping 15 matching lines...) Expand all
251 NavigationItem* NavigationManagerImpl::GetItemAtIndex(size_t index) const { 252 NavigationItem* NavigationManagerImpl::GetItemAtIndex(size_t index) const {
252 NSArray* entries = [session_controller_ entries]; 253 NSArray* entries = [session_controller_ entries];
253 return index < entries.count ? [entries[index] navigationItem] : nullptr; 254 return index < entries.count ? [entries[index] navigationItem] : nullptr;
254 } 255 }
255 256
256 int NavigationManagerImpl::GetCurrentItemIndex() const { 257 int NavigationManagerImpl::GetCurrentItemIndex() const {
257 return [session_controller_ currentNavigationIndex]; 258 return [session_controller_ currentNavigationIndex];
258 } 259 }
259 260
260 int NavigationManagerImpl::GetPendingItemIndex() const { 261 int NavigationManagerImpl::GetPendingItemIndex() const {
261 if ([session_controller_ hasPendingEntry]) { 262 if ([session_controller_ pendingEntry]) {
262 if ([session_controller_ pendingEntryIndex] != -1) { 263 if ([session_controller_ pendingItemIndex] != -1) {
263 return [session_controller_ pendingEntryIndex]; 264 return [session_controller_ pendingItemIndex];
264 } 265 }
265 // TODO(crbug.com/665189): understand why current item index is 266 // TODO(crbug.com/665189): understand why current item index is
266 // returned here. 267 // returned here.
267 return GetCurrentItemIndex(); 268 return GetCurrentItemIndex();
268 } 269 }
269 return -1; 270 return -1;
270 } 271 }
271 272
272 int NavigationManagerImpl::GetLastCommittedItemIndex() const { 273 int NavigationManagerImpl::GetLastCommittedItemIndex() const {
273 if (![[session_controller_ entries] count]) 274 if (![[session_controller_ entries] count])
274 return -1; 275 return -1;
275 return [session_controller_ currentNavigationIndex]; 276 return [session_controller_ currentNavigationIndex];
276 } 277 }
277 278
278 bool NavigationManagerImpl::RemoveItemAtIndex(int index) { 279 bool NavigationManagerImpl::RemoveItemAtIndex(int index) {
279 if (index == GetLastCommittedItemIndex() || index == GetPendingItemIndex()) 280 if (index == GetLastCommittedItemIndex() || index == GetPendingItemIndex())
280 return false; 281 return false;
281 282
282 NSUInteger idx = static_cast<NSUInteger>(index); 283 NSUInteger idx = static_cast<NSUInteger>(index);
283 NSArray* entries = [session_controller_ entries]; 284 NSArray* entries = [session_controller_ entries];
284 if (idx >= entries.count) 285 if (idx >= entries.count)
285 return false; 286 return false;
286 287
287 [session_controller_ removeEntryAtIndex:index]; 288 [session_controller_ removeItemAtIndex:index];
288 return true; 289 return true;
289 } 290 }
290 291
291 bool NavigationManagerImpl::CanGoBack() const { 292 bool NavigationManagerImpl::CanGoBack() const {
292 return CanGoToOffset(-1); 293 return CanGoToOffset(-1);
293 } 294 }
294 295
295 bool NavigationManagerImpl::CanGoForward() const { 296 bool NavigationManagerImpl::CanGoForward() const {
296 return CanGoToOffset(1); 297 return CanGoToOffset(1);
297 } 298 }
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
334 void NavigationManagerImpl::RemoveTransientURLRewriters() { 335 void NavigationManagerImpl::RemoveTransientURLRewriters() {
335 transient_url_rewriters_.reset(); 336 transient_url_rewriters_.reset();
336 } 337 }
337 338
338 void NavigationManagerImpl::CopyState( 339 void NavigationManagerImpl::CopyState(
339 NavigationManagerImpl* navigation_manager) { 340 NavigationManagerImpl* navigation_manager) {
340 SetSessionController([navigation_manager->GetSessionController() copy]); 341 SetSessionController([navigation_manager->GetSessionController() copy]);
341 } 342 }
342 343
343 int NavigationManagerImpl::GetIndexForOffset(int offset) const { 344 int NavigationManagerImpl::GetIndexForOffset(int offset) const {
344 int result = [session_controller_ pendingEntryIndex] == -1 345 int result = [session_controller_ pendingItemIndex] == -1
345 ? GetCurrentItemIndex() 346 ? GetCurrentItemIndex()
346 : static_cast<int>([session_controller_ pendingEntryIndex]); 347 : static_cast<int>([session_controller_ pendingItemIndex]);
347 348
348 if (offset < 0) { 349 if (offset < 0) {
349 if (GetTransientItem() && [session_controller_ pendingEntryIndex] == -1) { 350 if (GetTransientItem() && [session_controller_ pendingItemIndex] == -1) {
350 // 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
351 // 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
352 // index back. 353 // index back.
353 offset++; 354 offset++;
354 } 355 }
355 356
356 while (offset < 0 && result > 0) { 357 while (offset < 0 && result > 0) {
357 // 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
358 // 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
359 // immediately result in a redirect (the item *before* the redirected 360 // immediately result in a redirect (the item *before* the redirected
360 // page). 361 // page).
361 while (result > 0 && IsRedirectItemAtIndex(result)) { 362 while (result > 0 && IsRedirectItemAtIndex(result)) {
362 --result; 363 --result;
363 } 364 }
364 --result; 365 --result;
365 ++offset; 366 ++offset;
366 } 367 }
367 // 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
368 // simply add the remainder. 369 // simply add the remainder.
369 result += offset; 370 result += offset;
370 if (result > GetItemCount() /* overflow */) 371 if (result > GetItemCount() /* overflow */)
371 result = INT_MIN; 372 result = INT_MIN;
372 } else if (offset > 0) { 373 } else if (offset > 0) {
373 if (GetPendingItem() && [session_controller_ pendingEntryIndex] == -1) { 374 if (GetPendingItem() && [session_controller_ pendingItemIndex] == -1) {
374 // 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
375 // pending navigation in progress. Returning invalid index indicates that 376 // pending navigation in progress. Returning invalid index indicates that
376 // 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).
377 // This is different from other platforms which allow forward navigation 378 // This is different from other platforms which allow forward navigation
378 // if pending item exist. 379 // if pending item exist.
379 // TODO(crbug.com/661858): Remove this once back-forward navigation uses 380 // TODO(crbug.com/661858): Remove this once back-forward navigation uses
380 // pending index. 381 // pending index.
381 return INT_MAX; 382 return INT_MAX;
382 } 383 }
383 while (offset > 0 && result < GetItemCount()) { 384 while (offset > 0 && result < GetItemCount()) {
(...skipping 15 matching lines...) Expand all
399 } 400 }
400 401
401 bool NavigationManagerImpl::IsRedirectItemAtIndex(int index) const { 402 bool NavigationManagerImpl::IsRedirectItemAtIndex(int index) const {
402 DCHECK_GT(index, 0); 403 DCHECK_GT(index, 0);
403 DCHECK_LT(index, GetItemCount()); 404 DCHECK_LT(index, GetItemCount());
404 ui::PageTransition transition = GetItemAtIndex(index)->GetTransitionType(); 405 ui::PageTransition transition = GetItemAtIndex(index)->GetTransitionType();
405 return transition & ui::PAGE_TRANSITION_IS_REDIRECT_MASK; 406 return transition & ui::PAGE_TRANSITION_IS_REDIRECT_MASK;
406 } 407 }
407 408
408 } // namespace web 409 } // namespace web
OLDNEW
« no previous file with comments | « ios/web/navigation/navigation_item_impl_list.mm ('k') | ios/web/navigation/navigation_manager_impl_unittest.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698