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

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

Issue 2766453002: Implement Reload for ORIGINAL_REQUEST_URL in NavigationManagerImpl. (Closed)
Patch Set: addressed 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 with the original
Eugene But (OOO till 7-30) 2017/03/23 00:08:19 Avoid "we" in the comments (go/avoidwe)
Eugene But (OOO till 7-30) 2017/03/23 00:08:20 This method is written in generic way, independent
liaoyuke 2017/03/27 16:22:42 Done. Thank you for providing the link. :)
liaoyuke 2017/03/27 16:22:43 Done.
347 // request url of the last non-redirect item (including pending item) because
348 // a server or client redirect may 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, when the user clicks "Request Desktop Site",
351 // we want to request the desktop version of www.youtube.com for the user
352 // instead of m.youtube.com.
353 if (reload_type == web::ReloadType::ORIGINAL_REQUEST_URL) {
354 web::UserAgentType type =
355 [session_controller_ currentItem]->GetUserAgentType();
356 web::NavigationItem* last_non_redirect_item = nullptr;
357
358 if (GetPendingItem() && ((GetPendingItem()->GetTransitionType() &
359 ui::PAGE_TRANSITION_IS_REDIRECT_MASK) == 0)) {
360 last_non_redirect_item = GetPendingItem();
361 } else {
362 DiscardNonCommittedItems();
Eugene But (OOO till 7-30) 2017/03/23 00:08:19 Is this necessary? Maybe CRWWebController already
liaoyuke 2017/03/27 16:22:42 Addressed per offline discussion.
363 DCHECK(!GetPendingItem());
364
365 int index = GetLastCommittedItemIndex();
366 while (index >= 0) {
Eugene But (OOO till 7-30) 2017/03/23 00:08:20 Searching for last non-redirect item can be factor
liaoyuke 2017/03/27 16:22:42 |GetLastNonRedirectedItem()| in NavigationManagerU
367 if (!IsRedirectItemAtIndex(index)) {
368 last_non_redirect_item = GetItemAtIndex(index);
369 break;
370 }
371
372 [session_controller_ goToItemAtIndex:(index - 1)];
373 bool item_removed_successfuly = RemoveItemAtIndex(index);
Eugene But (OOO till 7-30) 2017/03/23 00:08:20 Current implementation of Reload does not destroy
liaoyuke 2017/03/27 16:22:43 Addressed per offline discussion.
374 DCHECK(item_removed_successfuly);
375
376 --index;
377 }
378 }
379
380 DCHECK(last_non_redirect_item);
381 last_non_redirect_item->SetURL(
382 last_non_redirect_item->GetOriginalRequestURL());
383 last_non_redirect_item->SetUserAgentType(type);
384 }
385
346 delegate_->Reload(); 386 delegate_->Reload();
347 } 387 }
348 388
349 void NavigationManagerImpl::CopyStateFromAndPrune( 389 void NavigationManagerImpl::CopyStateFromAndPrune(
350 const NavigationManager* manager) { 390 const NavigationManager* manager) {
351 DCHECK(manager); 391 DCHECK(manager);
352 CRWSessionController* other_session = 392 CRWSessionController* other_session =
353 static_cast<const NavigationManagerImpl*>(manager)->session_controller_; 393 static_cast<const NavigationManagerImpl*>(manager)->session_controller_;
354 [session_controller_ copyStateFromSessionControllerAndPrune:other_session]; 394 [session_controller_ copyStateFromSessionControllerAndPrune:other_session];
355 } 395 }
(...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 471 // The desktop user agent cannot be used for a pending navigation to an
432 // app-specific URL. 472 // app-specific URL.
433 DCHECK_NE(pending_item->GetUserAgentType(), UserAgentType::NONE); 473 DCHECK_NE(pending_item->GetUserAgentType(), UserAgentType::NONE);
434 pending_item->SetUserAgentType(UserAgentType::DESKTOP); 474 pending_item->SetUserAgentType(UserAgentType::DESKTOP);
435 } else { 475 } else {
436 override_desktop_user_agent_for_next_pending_item_ = true; 476 override_desktop_user_agent_for_next_pending_item_ = true;
437 } 477 }
438 } 478 }
439 479
440 bool NavigationManagerImpl::IsRedirectItemAtIndex(int index) const { 480 bool NavigationManagerImpl::IsRedirectItemAtIndex(int index) const {
441 DCHECK_GT(index, 0); 481 DCHECK_GE(index, 0);
442 DCHECK_LT(index, GetItemCount()); 482 DCHECK_LT(index, GetItemCount());
443 ui::PageTransition transition = GetItemAtIndex(index)->GetTransitionType(); 483 ui::PageTransition transition = GetItemAtIndex(index)->GetTransitionType();
444 return transition & ui::PAGE_TRANSITION_IS_REDIRECT_MASK; 484 return transition & ui::PAGE_TRANSITION_IS_REDIRECT_MASK;
445 } 485 }
446 486
447 NavigationItem* NavigationManagerImpl::GetLastCommittedNonAppSpecificItem() 487 NavigationItem* NavigationManagerImpl::GetLastCommittedNonAppSpecificItem()
448 const { 488 const {
449 int index = GetCurrentItemIndex(); 489 int index = GetCurrentItemIndex();
450 if (index == -1) 490 if (index == -1)
451 return nullptr; 491 return nullptr;
452 WebClient* client = GetWebClient(); 492 WebClient* client = GetWebClient();
453 const ScopedNavigationItemImplList& items = [session_controller_ items]; 493 const ScopedNavigationItemImplList& items = [session_controller_ items];
454 while (index >= 0) { 494 while (index >= 0) {
455 NavigationItem* item = items[index--].get(); 495 NavigationItem* item = items[index--].get();
456 if (!client->IsAppSpecificURL(item->GetVirtualURL())) 496 if (!client->IsAppSpecificURL(item->GetVirtualURL()))
457 return item; 497 return item;
458 } 498 }
459 return nullptr; 499 return nullptr;
460 } 500 }
461 501
462 } // namespace web 502 } // namespace web
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698