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 609 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
620 | 620 |
621 int index = _webStateList.GetIndexOfWebState(oldTab.webState); | 621 int index = _webStateList.GetIndexOfWebState(oldTab.webState); |
622 DCHECK_NE(index, WebStateList::kInvalidIndex); | 622 DCHECK_NE(index, WebStateList::kInvalidIndex); |
623 DCHECK_GE(index, 0); | 623 DCHECK_GE(index, 0); |
624 | 624 |
625 base::scoped_nsobject<Tab> tabSaver([oldTab retain]); | 625 base::scoped_nsobject<Tab> tabSaver([oldTab retain]); |
626 [_tabRetainer removeObject:oldTab]; | 626 [_tabRetainer removeObject:oldTab]; |
627 [_tabRetainer addObject:newTab]; | 627 [_tabRetainer addObject:newTab]; |
628 [newTab setParentTabModel:self]; | 628 [newTab setParentTabModel:self]; |
629 | 629 |
630 _webStateList.ReplaceWebStateAt(index, newTab.webState, | 630 // The WebState is owned by the associated Tab, so it is safe to ignore |
631 GetOpenerForTab(self, newTab).webState); | 631 // the result and won't cause a memory leak. Once the ownershipd is moved |
rohitrao (ping after 24h)
2017/02/28 22:35:58
Typo: ownership.
sdefresne
2017/03/01 01:22:53
Done.
| |
632 // to WebStateList, this function will return a std::unique_ptr<> and the | |
633 // object destroyed as expected, so it will fine to ignore the result then | |
634 // too. See http://crbug.com/546222 for progress of changing the ownership | |
635 // of the WebStates. | |
636 ignore_result(_webStateList.ReplaceWebStateAt( | |
637 index, newTab.webState, GetOpenerForTab(self, newTab).webState)); | |
632 | 638 |
633 if (self.currentTab == oldTab) | 639 if (self.currentTab == oldTab) |
634 [self changeSelectedTabFrom:nil to:newTab persistState:NO]; | 640 [self changeSelectedTabFrom:nil to:newTab persistState:NO]; |
635 | 641 |
636 [oldTab setParentTabModel:nil]; | 642 [oldTab setParentTabModel:nil]; |
637 [oldTab close]; | 643 [oldTab close]; |
638 } | 644 } |
639 | 645 |
640 - (void)closeTabAtIndex:(NSUInteger)index { | 646 - (void)closeTabAtIndex:(NSUInteger)index { |
641 DCHECK(index < self.count); | 647 DCHECK(index < self.count); |
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
785 // If closing the current tab, clear |_currentTab| before sending any | 791 // If closing the current tab, clear |_currentTab| before sending any |
786 // notification. This avoids various parts of the code getting confused | 792 // notification. This avoids various parts of the code getting confused |
787 // when the current tab isn't in the tab model. | 793 // when the current tab isn't in the tab model. |
788 Tab* savedCurrentTab = _currentTab; | 794 Tab* savedCurrentTab = _currentTab; |
789 if (closedTab == _currentTab) | 795 if (closedTab == _currentTab) |
790 _currentTab.reset(nil); | 796 _currentTab.reset(nil); |
791 | 797 |
792 DCHECK([_tabRetainer containsObject:closedTab]); | 798 DCHECK([_tabRetainer containsObject:closedTab]); |
793 [_tabRetainer removeObject:closedTab]; | 799 [_tabRetainer removeObject:closedTab]; |
794 | 800 |
795 _webStateList.DetachWebStateAt(closedTabIndex); | 801 // The WebState is owned by the associated Tab, so it is safe to ignore |
802 // the result and won't cause a memory leak. Once the ownershipd is moved | |
rohitrao (ping after 24h)
2017/02/28 22:35:58
Typo: ownership.
sdefresne
2017/03/01 01:22:53
Done.
| |
803 // to WebStateList, this function will return a std::unique_ptr<> and the | |
804 // object destroyed as expected, so it will fine to ignore the result then | |
805 // too. See http://crbug.com/546222 for progress of changing the ownership | |
806 // of the WebStates. | |
807 ignore_result(_webStateList.DetachWebStateAt(closedTabIndex)); | |
796 | 808 |
797 // Current tab has closed, update the selected tab and swap in its | 809 // Current tab has closed, update the selected tab and swap in its |
798 // contents. There is nothing to do if a non-selected tab is closed as | 810 // contents. There is nothing to do if a non-selected tab is closed as |
799 // the selection isn't index-based, therefore it hasn't changed. | 811 // the selection isn't index-based, therefore it hasn't changed. |
800 // -changeSelectedTabFrom: will persist the state change, so only do it | 812 // -changeSelectedTabFrom: will persist the state change, so only do it |
801 // if the selection isn't changing. | 813 // if the selection isn't changing. |
802 if (closedTab == savedCurrentTab) { | 814 if (closedTab == savedCurrentTab) { |
803 [self changeSelectedTabFrom:closedTab to:newSelection persistState:NO]; | 815 [self changeSelectedTabFrom:closedTab to:newSelection persistState:NO]; |
804 } else { | 816 } else { |
805 [self saveSessionImmediately:NO]; | 817 [self saveSessionImmediately:NO]; |
(...skipping 331 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1137 web::NavigationManager::WebLoadParams params(URL); | 1149 web::NavigationManager::WebLoadParams params(URL); |
1138 params.referrer = referrer; | 1150 params.referrer = referrer; |
1139 params.transition_type = ui::PAGE_TRANSITION_TYPED; | 1151 params.transition_type = ui::PAGE_TRANSITION_TYPED; |
1140 [[tab webController] loadWithParams:params]; | 1152 [[tab webController] loadWithParams:params]; |
1141 [tab webController].webUsageEnabled = webUsageEnabled_; | 1153 [tab webController].webUsageEnabled = webUsageEnabled_; |
1142 [self insertTab:tab atIndex:index opener:parentTab]; | 1154 [self insertTab:tab atIndex:index opener:parentTab]; |
1143 return tab; | 1155 return tab; |
1144 } | 1156 } |
1145 | 1157 |
1146 @end | 1158 @end |
OLD | NEW |