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

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

Issue 2766453002: Implement Reload for ORIGINAL_REQUEST_URL in NavigationManagerImpl. (Closed)
Patch Set: self review Created 3 years, 9 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 325 matching lines...) Expand 10 before | Expand all | Expand 10 after
336 NavigationItemList NavigationManagerImpl::GetBackwardItems() const { 336 NavigationItemList NavigationManagerImpl::GetBackwardItems() const {
337 return [session_controller_ backwardItems]; 337 return [session_controller_ backwardItems];
338 } 338 }
339 339
340 NavigationItemList NavigationManagerImpl::GetForwardItems() const { 340 NavigationItemList NavigationManagerImpl::GetForwardItems() const {
341 return [session_controller_ forwardItems]; 341 return [session_controller_ forwardItems];
342 } 342 }
343 343
344 void NavigationManagerImpl::Reload(ReloadType reload_type, 344 void NavigationManagerImpl::Reload(ReloadType reload_type,
345 bool check_for_reposts) { 345 bool check_for_reposts) {
346 // For request desktop/mobile site, we want to reload the page with the
347 // original request url of the last non-redirect item (including pending item)
348 // because a redirect may either change the url of the current item or add a
349 // new item. For example, an user visits www.youtube.com and is then
350 // redirected to m.youtube.com, so in this case, we want to request desktop
351 // version of www.youtube.com for the user instead of m.youtube.com.
352 if (reload_type == web::ReloadType::ORIGINAL_REQUEST_URL) {
353 web::UserAgentType type =
354 [session_controller_ currentItem]->GetUserAgentType();
355 web::NavigationItem* last_non_redirect_item = nullptr;
356
357 if (GetPendingItem() && ((GetPendingItem()->GetTransitionType() &
358 ui::PAGE_TRANSITION_IS_REDIRECT_MASK) == 0)) {
359 last_non_redirect_item = GetPendingItem();
360 } else {
361 DiscardNonCommittedItems();
362 int index = GetLastCommittedItemIndex();
363 while (index >= 0) {
364 if (!IsRedirectItemAtIndex(index)) {
365 last_non_redirect_item = GetItemAtIndex(index);
366 break;
367 }
368
369 [session_controller_ goToItemAtIndex:(index - 1)];
370 bool item_removed_successfuly = RemoveItemAtIndex(index);
371 DCHECK(item_removed_successfuly);
372
373 --index;
374 }
375 }
376
377 DCHECK(last_non_redirect_item);
378 last_non_redirect_item->SetURL(
379 last_non_redirect_item->GetOriginalRequestURL());
380 last_non_redirect_item->SetUserAgentType(type);
381 }
382
346 delegate_->Reload(); 383 delegate_->Reload();
347 } 384 }
348 385
349 void NavigationManagerImpl::CopyStateFromAndPrune( 386 void NavigationManagerImpl::CopyStateFromAndPrune(
350 const NavigationManager* manager) { 387 const NavigationManager* manager) {
351 DCHECK(manager); 388 DCHECK(manager);
352 CRWSessionController* other_session = 389 CRWSessionController* other_session =
353 static_cast<const NavigationManagerImpl*>(manager)->session_controller_; 390 static_cast<const NavigationManagerImpl*>(manager)->session_controller_;
354 [session_controller_ copyStateFromSessionControllerAndPrune:other_session]; 391 [session_controller_ copyStateFromSessionControllerAndPrune:other_session];
355 } 392 }
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
431 // The desktop user agent cannot be used for a pending navigation to an 468 // The desktop user agent cannot be used for a pending navigation to an
432 // app-specific URL. 469 // app-specific URL.
433 DCHECK_NE(pending_item->GetUserAgentType(), UserAgentType::NONE); 470 DCHECK_NE(pending_item->GetUserAgentType(), UserAgentType::NONE);
434 pending_item->SetUserAgentType(UserAgentType::DESKTOP); 471 pending_item->SetUserAgentType(UserAgentType::DESKTOP);
435 } else { 472 } else {
436 override_desktop_user_agent_for_next_pending_item_ = true; 473 override_desktop_user_agent_for_next_pending_item_ = true;
437 } 474 }
438 } 475 }
439 476
440 bool NavigationManagerImpl::IsRedirectItemAtIndex(int index) const { 477 bool NavigationManagerImpl::IsRedirectItemAtIndex(int index) const {
441 DCHECK_GT(index, 0); 478 DCHECK_GE(index, 0);
liaoyuke 2017/03/22 23:46:23 I don't see any reason why index cannot be 0. Am I
Eugene But (OOO till 7-30) 2017/03/23 00:08:19 This was a bug :)
442 DCHECK_LT(index, GetItemCount()); 479 DCHECK_LT(index, GetItemCount());
443 ui::PageTransition transition = GetItemAtIndex(index)->GetTransitionType(); 480 ui::PageTransition transition = GetItemAtIndex(index)->GetTransitionType();
444 return transition & ui::PAGE_TRANSITION_IS_REDIRECT_MASK; 481 return transition & ui::PAGE_TRANSITION_IS_REDIRECT_MASK;
445 } 482 }
446 483
447 NavigationItem* NavigationManagerImpl::GetLastCommittedNonAppSpecificItem() 484 NavigationItem* NavigationManagerImpl::GetLastCommittedNonAppSpecificItem()
448 const { 485 const {
449 int index = GetCurrentItemIndex(); 486 int index = GetCurrentItemIndex();
450 if (index == -1) 487 if (index == -1)
451 return nullptr; 488 return nullptr;
452 WebClient* client = GetWebClient(); 489 WebClient* client = GetWebClient();
453 const ScopedNavigationItemImplList& items = [session_controller_ items]; 490 const ScopedNavigationItemImplList& items = [session_controller_ items];
454 while (index >= 0) { 491 while (index >= 0) {
455 NavigationItem* item = items[index--].get(); 492 NavigationItem* item = items[index--].get();
456 if (!client->IsAppSpecificURL(item->GetVirtualURL())) 493 if (!client->IsAppSpecificURL(item->GetVirtualURL()))
457 return item; 494 return item;
458 } 495 }
459 return nullptr; 496 return nullptr;
460 } 497 }
461 498
462 } // namespace web 499 } // namespace web
OLDNEW
« no previous file with comments | « ios/chrome/browser/web/navigation_manager_util_unittest.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