| OLD | NEW |
| 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/chrome/browser/tabs/tab_model.h" | 5 #import "ios/chrome/browser/tabs/tab_model.h" |
| 6 | 6 |
| 7 #include <cstdint> | 7 #include <cstdint> |
| 8 #include <utility> | 8 #include <utility> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| (...skipping 531 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 542 atIndex:(NSUInteger)index { | 542 atIndex:(NSUInteger)index { |
| 543 DCHECK(_browserState); | 543 DCHECK(_browserState); |
| 544 DCHECK_EQ(webState->GetBrowserState(), _browserState); | 544 DCHECK_EQ(webState->GetBrowserState(), _browserState); |
| 545 base::scoped_nsobject<Tab> tab( | 545 base::scoped_nsobject<Tab> tab( |
| 546 [[Tab alloc] initWithWebState:std::move(webState) model:self]); | 546 [[Tab alloc] initWithWebState:std::move(webState) model:self]); |
| 547 [tab webController].webUsageEnabled = webUsageEnabled_; | 547 [tab webController].webUsageEnabled = webUsageEnabled_; |
| 548 [self insertTab:tab atIndex:index]; | 548 [self insertTab:tab atIndex:index]; |
| 549 return tab; | 549 return tab; |
| 550 } | 550 } |
| 551 | 551 |
| 552 - (void)insertTab:(Tab*)tab atIndex:(NSUInteger)index { | 552 - (void)insertTab:(Tab*)tab |
| 553 atIndex:(NSUInteger)index |
| 554 transition:(ui::PageTransition)transition { |
| 553 DCHECK(tab); | 555 DCHECK(tab); |
| 554 DCHECK(![_tabRetainer containsObject:tab]); | 556 DCHECK(![_tabRetainer containsObject:tab]); |
| 555 DCHECK_LE(index, static_cast<NSUInteger>(INT_MAX)); | 557 |
| 558 int insertion_index; |
| 559 if (index == TabModelConstants::kTabPositionAutomatically) { |
| 560 insertion_index = WebStateList::kInvalidIndex; |
| 561 } else { |
| 562 DCHECK_LE(index, static_cast<NSUInteger>(INT_MAX)); |
| 563 insertion_index = static_cast<int>(index); |
| 564 } |
| 556 | 565 |
| 557 [_tabRetainer addObject:tab]; | 566 [_tabRetainer addObject:tab]; |
| 558 _webStateList.InsertWebState( | 567 _webStateList.AddWebState(insertion_index, transition, tab.webState, |
| 559 static_cast<int>(index), tab.webState, | 568 GetOpenerForWebState(_webStateList, tab.webState)); |
| 560 GetOpenerForWebState(_webStateList, tab.webState)); | |
| 561 | 569 |
| 562 // Persist the session due to a new tab being inserted. If this is a | 570 // Persist the session due to a new tab being inserted. If this is a |
| 563 // background tab (will not become active), saving now will capture the | 571 // background tab (will not become active), saving now will capture the |
| 564 // state properly. If it does eventually become active, another save will | 572 // state properly. If it does eventually become active, another save will |
| 565 // be triggered to properly capture the end result. | 573 // be triggered to properly capture the end result. |
| 566 [self saveSessionImmediately:NO]; | 574 [self saveSessionImmediately:NO]; |
| 567 | 575 |
| 568 ++_newTabCount; | 576 ++_newTabCount; |
| 569 } | 577 } |
| 570 | 578 |
| 579 - (void)insertTab:(Tab*)tab atIndex:(NSUInteger)index { |
| 580 DCHECK(tab); |
| 581 DCHECK(![_tabRetainer containsObject:tab]); |
| 582 DCHECK_LE(index, static_cast<NSUInteger>(INT_MAX)); |
| 583 |
| 584 [self insertTab:tab atIndex:index transition:ui::PAGE_TRANSITION_GENERATED]; |
| 585 } |
| 586 |
| 571 - (void)moveTab:(Tab*)tab toIndex:(NSUInteger)toIndex { | 587 - (void)moveTab:(Tab*)tab toIndex:(NSUInteger)toIndex { |
| 572 DCHECK([_tabRetainer containsObject:tab]); | 588 DCHECK([_tabRetainer containsObject:tab]); |
| 573 DCHECK_LE(toIndex, static_cast<NSUInteger>(INT_MAX)); | 589 DCHECK_LE(toIndex, static_cast<NSUInteger>(INT_MAX)); |
| 574 int fromIndex = _webStateList.GetIndexOfWebState(tab.webState); | 590 int fromIndex = _webStateList.GetIndexOfWebState(tab.webState); |
| 575 _webStateList.MoveWebStateAt(fromIndex, static_cast<int>(toIndex)); | 591 _webStateList.MoveWebStateAt(fromIndex, static_cast<int>(toIndex)); |
| 576 } | 592 } |
| 577 | 593 |
| 578 - (void)replaceTab:(Tab*)oldTab withTab:(Tab*)newTab { | 594 - (void)replaceTab:(Tab*)oldTab withTab:(Tab*)newTab { |
| 579 DCHECK([_tabRetainer containsObject:oldTab]); | 595 DCHECK([_tabRetainer containsObject:oldTab]); |
| 580 DCHECK(![_tabRetainer containsObject:newTab]); | 596 DCHECK(![_tabRetainer containsObject:newTab]); |
| (...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 850 inBackground:(BOOL)inBackground { | 866 inBackground:(BOOL)inBackground { |
| 851 DCHECK(_browserState); | 867 DCHECK(_browserState); |
| 852 base::scoped_nsobject<Tab> tab([[Tab alloc] | 868 base::scoped_nsobject<Tab> tab([[Tab alloc] |
| 853 initWithWindowName:windowName | 869 initWithWindowName:windowName |
| 854 opener:parentTab | 870 opener:parentTab |
| 855 openedByDOM:openedByDOM | 871 openedByDOM:openedByDOM |
| 856 model:self | 872 model:self |
| 857 browserState:_browserState]); | 873 browserState:_browserState]); |
| 858 [tab webController].webUsageEnabled = webUsageEnabled_; | 874 [tab webController].webUsageEnabled = webUsageEnabled_; |
| 859 | 875 |
| 860 if ((PageTransitionCoreTypeIs(params.transition_type, | 876 [self insertTab:tab atIndex:index transition:params.transition_type]; |
| 861 ui::PAGE_TRANSITION_LINK)) && | |
| 862 (index == TabModelConstants::kTabPositionAutomatically)) { | |
| 863 DCHECK(!parentTab || [self indexOfTab:parentTab] != NSNotFound); | |
| 864 // Assume tabs opened via link clicks are part of the same "task" as their | |
| 865 // parent and are grouped together. | |
| 866 TabModelOrderConstants::InsertionAdjacency adjacency = | |
| 867 inBackground ? TabModelOrderConstants::kAdjacentAfter | |
| 868 : TabModelOrderConstants::kAdjacentBefore; | |
| 869 index = [_orderController insertionIndexForTab:tab | |
| 870 transition:params.transition_type | |
| 871 opener:parentTab | |
| 872 adjacency:adjacency]; | |
| 873 } else { | |
| 874 // For all other types, respect what was passed to us, normalizing values | |
| 875 // that are too large. | |
| 876 if (index >= self.count) | |
| 877 index = [_orderController insertionIndexForAppending]; | |
| 878 } | |
| 879 | |
| 880 if (PageTransitionCoreTypeIs(params.transition_type, | |
| 881 ui::PAGE_TRANSITION_TYPED) && | |
| 882 index == self.count) { | |
| 883 // Also, any tab opened at the end of the TabStrip with a "TYPED" | |
| 884 // transition inherit group as well. This covers the cases where the user | |
| 885 // creates a New Tab (e.g. Ctrl+T, or clicks the New Tab button), or types | |
| 886 // in the address bar and presses Alt+Enter. This allows for opening a new | |
| 887 // Tab to quickly look up something. When this Tab is closed, the old one | |
| 888 // is re-selected, not the next-adjacent. | |
| 889 // TODO(crbug.com/661988): Make this work. | |
| 890 } | |
| 891 | |
| 892 [self insertTab:tab atIndex:index]; | |
| 893 | 877 |
| 894 if (!inBackground && _tabUsageRecorder) | 878 if (!inBackground && _tabUsageRecorder) |
| 895 _tabUsageRecorder->TabCreatedForSelection(tab); | 879 _tabUsageRecorder->TabCreatedForSelection(tab); |
| 896 | 880 |
| 897 [[tab webController] loadWithParams:params]; | 881 [[tab webController] loadWithParams:params]; |
| 898 // Force the page to start loading even if it's in the background. | 882 // Force the page to start loading even if it's in the background. |
| 899 if (webUsageEnabled_) | 883 if (webUsageEnabled_) |
| 900 [[tab webController] triggerPendingLoad]; | 884 [[tab webController] triggerPendingLoad]; |
| 901 NSDictionary* userInfo = @{ | 885 NSDictionary* userInfo = @{ |
| 902 kTabModelTabKey : tab, | 886 kTabModelTabKey : tab, |
| (...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1080 | 1064 |
| 1081 @implementation TabModel (PrivateForTestingOnly) | 1065 @implementation TabModel (PrivateForTestingOnly) |
| 1082 | 1066 |
| 1083 - (Tab*)addTabWithURL:(const GURL&)URL | 1067 - (Tab*)addTabWithURL:(const GURL&)URL |
| 1084 referrer:(const web::Referrer&)referrer | 1068 referrer:(const web::Referrer&)referrer |
| 1085 windowName:(NSString*)windowName { | 1069 windowName:(NSString*)windowName { |
| 1086 return [self insertTabWithURL:URL | 1070 return [self insertTabWithURL:URL |
| 1087 referrer:referrer | 1071 referrer:referrer |
| 1088 windowName:windowName | 1072 windowName:windowName |
| 1089 opener:nil | 1073 opener:nil |
| 1090 atIndex:[_orderController insertionIndexForAppending]]; | 1074 atIndex:self.count]; |
| 1091 } | 1075 } |
| 1092 | 1076 |
| 1093 - (Tab*)insertTabWithURL:(const GURL&)URL | 1077 - (Tab*)insertTabWithURL:(const GURL&)URL |
| 1094 referrer:(const web::Referrer&)referrer | 1078 referrer:(const web::Referrer&)referrer |
| 1095 windowName:(NSString*)windowName | 1079 windowName:(NSString*)windowName |
| 1096 opener:(Tab*)parentTab | 1080 opener:(Tab*)parentTab |
| 1097 atIndex:(NSUInteger)index { | 1081 atIndex:(NSUInteger)index { |
| 1098 DCHECK(_browserState); | 1082 DCHECK(_browserState); |
| 1099 base::scoped_nsobject<Tab> tab([[Tab alloc] | 1083 base::scoped_nsobject<Tab> tab([[Tab alloc] |
| 1100 initWithWindowName:windowName | 1084 initWithWindowName:windowName |
| 1101 opener:parentTab | 1085 opener:parentTab |
| 1102 openedByDOM:NO | 1086 openedByDOM:NO |
| 1103 model:self | 1087 model:self |
| 1104 browserState:_browserState]); | 1088 browserState:_browserState]); |
| 1105 web::NavigationManager::WebLoadParams params(URL); | 1089 web::NavigationManager::WebLoadParams params(URL); |
| 1106 params.referrer = referrer; | 1090 params.referrer = referrer; |
| 1107 params.transition_type = ui::PAGE_TRANSITION_TYPED; | 1091 params.transition_type = ui::PAGE_TRANSITION_TYPED; |
| 1108 [[tab webController] loadWithParams:params]; | 1092 [[tab webController] loadWithParams:params]; |
| 1109 [tab webController].webUsageEnabled = webUsageEnabled_; | 1093 [tab webController].webUsageEnabled = webUsageEnabled_; |
| 1110 [self insertTab:tab atIndex:index]; | 1094 [self insertTab:tab atIndex:index]; |
| 1111 return tab; | 1095 return tab; |
| 1112 } | 1096 } |
| 1113 | 1097 |
| 1114 @end | 1098 @end |
| OLD | NEW |