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

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

Issue 2698773002: [iOS] Refactoring web CRWSessionController user agent code. (Closed)
Patch Set: 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 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 349 matching lines...) Expand 10 before | Expand all | Expand 10 after
360 // Note: CRWSessionController currently has the responsibility to distinguish 360 // Note: CRWSessionController currently has the responsibility to distinguish
361 // between new navigations and history stack navigation, hence the inclusion 361 // between new navigations and history stack navigation, hence the inclusion
362 // of specific transiton type logic here, in order to make it reliable with 362 // of specific transiton type logic here, in order to make it reliable with
363 // real-world observed behavior. 363 // real-world observed behavior.
364 // TODO(crbug.com/676129): Fix the way changes are detected/reported elsewhere 364 // TODO(crbug.com/676129): Fix the way changes are detected/reported elsewhere
365 // in the web layer so that this hack can be removed. 365 // in the web layer so that this hack can be removed.
366 // Remove the workaround code from -presentSafeBrowsingWarningForResource:. 366 // Remove the workaround code from -presentSafeBrowsingWarningForResource:.
367 CRWSessionEntry* currentEntry = self.currentEntry; 367 CRWSessionEntry* currentEntry = self.currentEntry;
368 if (currentEntry) { 368 if (currentEntry) {
369 web::NavigationItem* item = [currentEntry navigationItem]; 369 web::NavigationItem* item = [currentEntry navigationItem];
370 if (item->GetURL() == url && 370 BOOL isPendingItemEqualsCurrentItem = NO;
kkhorimoto 2017/02/15 23:02:05 As long as we're refactoring this for readability,
liaoyuke 2017/02/16 01:49:04 Done.
liaoyuke 2017/02/16 01:49:04 Makes sense!
371 (!PageTransitionCoreTypeIs(trans, ui::PAGE_TRANSITION_FORM_SUBMIT) || 371
372 PageTransitionCoreTypeIs(item->GetTransitionType(), 372 BOOL hasSameUrl = item->GetURL() == url;
kkhorimoto 2017/02/15 23:02:06 s/hasSameUrl/hasSameURL
liaoyuke 2017/02/16 01:49:04 Done.
373 ui::PAGE_TRANSITION_FORM_SUBMIT))) { 373 BOOL isPendingItemPageTransitionFormSubmit =
374 PageTransitionCoreTypeIs(trans, ui::PAGE_TRANSITION_FORM_SUBMIT);
375 BOOL isCurrentItemPageTransitionFormSubmit = PageTransitionCoreTypeIs(
kkhorimoto 2017/02/15 23:02:05 You can make these variable names a little less ve
liaoyuke 2017/02/16 01:49:05 Done.
376 item->GetTransitionType(), ui::PAGE_TRANSITION_FORM_SUBMIT);
377
liaoyuke 2017/02/15 22:26:51 No structural changes. Just happened to find this
liaoyuke 2017/02/16 01:49:04 Done.
378 if (hasSameUrl) {
379 if (!isPendingItemPageTransitionFormSubmit ||
380 isCurrentItemPageTransitionFormSubmit) {
381 isPendingItemPageTransitionFormSubmit = YES;
382 }
383 }
384
385 if (isPendingItemEqualsCurrentItem) {
374 // Send the notification anyway, to preserve old behavior. It's unknown 386 // Send the notification anyway, to preserve old behavior. It's unknown
375 // whether anything currently relies on this, but since both this whole 387 // whether anything currently relies on this, but since both this whole
376 // hack and the content facade will both be going away, it's not worth 388 // hack and the content facade will both be going away, it's not worth
377 // trying to unwind. 389 // trying to unwind.
378 if (_navigationManager && _navigationManager->GetFacadeDelegate()) { 390 if (_navigationManager && _navigationManager->GetFacadeDelegate()) {
379 _navigationManager->GetFacadeDelegate()->OnNavigationItemPending(); 391 _navigationManager->GetFacadeDelegate()->OnNavigationItemPending();
380 } 392 }
381 return; 393 return;
382 } 394 }
383 } 395 }
384 396
385 BOOL useDesktopUserAgent =
386 _useDesktopUserAgentForNextPendingItem ||
387 (self.currentEntry.navigationItem &&
388 self.currentEntry.navigationItem->IsOverridingUserAgent());
389 _useDesktopUserAgentForNextPendingItem = NO;
390 _pendingEntry.reset([self sessionEntryWithURL:url 397 _pendingEntry.reset([self sessionEntryWithURL:url
391 referrer:ref 398 referrer:ref
392 transition:trans 399 transition:trans
393 useDesktopUserAgent:useDesktopUserAgent 400 useDesktopUserAgent:NO
kkhorimoto 2017/02/15 23:02:05 useDesktopUserAgent is always NO after this change
liaoyuke 2017/02/16 01:49:04 Done.
394 rendererInitiated:rendererInitiated]); 401 rendererInitiated:rendererInitiated]);
395 402
396 if (_navigationManager && _navigationManager->GetFacadeDelegate()) { 403 if (_navigationManager && _navigationManager->GetFacadeDelegate()) {
397 _navigationManager->GetFacadeDelegate()->OnNavigationItemPending(); 404 _navigationManager->GetFacadeDelegate()->OnNavigationItemPending();
398 } 405 }
399 } 406 }
400 407
401 - (void)updatePendingItem:(const GURL&)url { 408 - (void)updatePendingItem:(const GURL&)url {
402 // If there is no pending entry, navigation is probably happening within the 409 // If there is no pending entry, navigation is probably happening within the
403 // session history. Don't modify the entry list. 410 // session history. Don't modify the entry list.
(...skipping 268 matching lines...) Expand 10 before | Expand all | Expand 10 after
672 679
673 NSInteger index = _currentNavigationIndex; 680 NSInteger index = _currentNavigationIndex;
674 // This will return the first session entry if all other entries are 681 // This will return the first session entry if all other entries are
675 // redirects, regardless of the transition state of the first entry. 682 // redirects, regardless of the transition state of the first entry.
676 while (index > 0 && [self isRedirectTransitionForItemAtIndex:index]) { 683 while (index > 0 && [self isRedirectTransitionForItemAtIndex:index]) {
677 --index; 684 --index;
678 } 685 }
679 return [_entries objectAtIndex:index]; 686 return [_entries objectAtIndex:index];
680 } 687 }
681 688
682 - (void)useDesktopUserAgentForNextPendingItem {
683 if (_pendingEntry)
684 [_pendingEntry navigationItem]->SetIsOverridingUserAgent(true);
685 else
686 _useDesktopUserAgentForNextPendingItem = YES;
687 }
688
689 - (NSInteger)indexOfItem:(const web::NavigationItem*)item { 689 - (NSInteger)indexOfItem:(const web::NavigationItem*)item {
690 web::NavigationItemList items = self.items; 690 web::NavigationItemList items = self.items;
691 for (NSInteger i = 0; i < static_cast<NSInteger>(items.size()); ++i) { 691 for (NSInteger i = 0; i < static_cast<NSInteger>(items.size()); ++i) {
692 if (items[i] == item) 692 if (items[i] == item)
693 return i; 693 return i;
694 } 694 }
695 return NSNotFound; 695 return NSNotFound;
696 } 696 }
697 697
698 #pragma mark - 698 #pragma mark -
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
745 } 745 }
746 746
747 - (web::NavigationItemList)itemListForEntryList:(NSArray*)entries { 747 - (web::NavigationItemList)itemListForEntryList:(NSArray*)entries {
748 web::NavigationItemList list(entries.count); 748 web::NavigationItemList list(entries.count);
749 for (size_t index = 0; index < entries.count; ++index) 749 for (size_t index = 0; index < entries.count; ++index)
750 list[index] = [entries[index] navigationItem]; 750 list[index] = [entries[index] navigationItem];
751 return list; 751 return list;
752 } 752 }
753 753
754 @end 754 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698