Chromium Code Reviews| 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 266 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 277 | 277 |
| 278 - (BOOL)isOffTheRecord { | 278 - (BOOL)isOffTheRecord { |
| 279 return _browserState && _browserState->IsOffTheRecord(); | 279 return _browserState && _browserState->IsOffTheRecord(); |
| 280 } | 280 } |
| 281 | 281 |
| 282 - (BOOL)isEmpty { | 282 - (BOOL)isEmpty { |
| 283 return _webStateList.empty(); | 283 return _webStateList.empty(); |
| 284 } | 284 } |
| 285 | 285 |
| 286 - (NSUInteger)count { | 286 - (NSUInteger)count { |
| 287 DCHECK_GT(_webStateList.count(), 0); | 287 DCHECK_GT(_webStateList.count(), 0); |
|
rohitrao (ping after 24h)
2017/02/14 16:27:53
DCHECK_GE? 0 should be a valid count.
sdefresne
2017/02/14 16:44:36
Good catch, fixed in dependent CL.
| |
| 288 return static_cast<NSUInteger>(_webStateList.count()); | 288 return static_cast<NSUInteger>(_webStateList.count()); |
| 289 } | 289 } |
| 290 | 290 |
| 291 - (instancetype)initWithSessionWindow:(SessionWindowIOS*)window | 291 - (instancetype)initWithSessionWindow:(SessionWindowIOS*)window |
| 292 sessionService:(SessionServiceIOS*)service | 292 sessionService:(SessionServiceIOS*)service |
| 293 browserState:(ios::ChromeBrowserState*)browserState { | 293 browserState:(ios::ChromeBrowserState*)browserState { |
| 294 if ((self = [super init])) { | 294 if ((self = [super init])) { |
| 295 _tabRetainer.reset([[NSMutableSet alloc] init]); | 295 _tabRetainer.reset([[NSMutableSet alloc] init]); |
| 296 _observers.reset([[TabModelObservers observers] retain]); | 296 _observers.reset([[TabModelObservers observers] retain]); |
| 297 | 297 |
| (...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 422 Tab* current = [self tabAtIndex:i]; | 422 Tab* current = [self tabAtIndex:i]; |
| 423 DCHECK([current navigationManager]); | 423 DCHECK([current navigationManager]); |
| 424 CRWSessionController* sessionController = | 424 CRWSessionController* sessionController = |
| 425 [current navigationManager]->GetSessionController(); | 425 [current navigationManager]->GetSessionController(); |
| 426 if ([sessionController.openerId isEqualToString:parentID]) | 426 if ([sessionController.openerId isEqualToString:parentID]) |
| 427 return current; | 427 return current; |
| 428 } | 428 } |
| 429 return nil; | 429 return nil; |
| 430 } | 430 } |
| 431 | 431 |
| 432 - (Tab*)firstTabWithOpener:(Tab*)tab { | |
| 433 if (!tab) | |
| 434 return nil; | |
| 435 NSUInteger stopIndex = [self indexOfTab:tab]; | |
| 436 if (stopIndex == NSNotFound) | |
| 437 return nil; | |
| 438 NSString* parentID = tab.tabId; | |
| 439 // Match the navigation index as well as the session id, to better match the | |
| 440 // state of the tab. I.e. two tabs are opened via a link from tab A, and then | |
| 441 // a new url is loaded into tab A, and more tabs opened from that url, the | |
| 442 // latter two tabs should not be grouped with the former two. The navigation | |
| 443 // index is the simplest way to detect navigation changes. | |
| 444 DCHECK([tab navigationManager]); | |
| 445 NSInteger parentNavIndex = [tab navigationManager]->GetCurrentItemIndex(); | |
| 446 for (NSUInteger i = 0; i < stopIndex; ++i) { | |
| 447 Tab* tabToCheck = [self tabAtIndex:i]; | |
| 448 DCHECK([tabToCheck navigationManager]); | |
| 449 CRWSessionController* sessionController = | |
| 450 [tabToCheck navigationManager]->GetSessionController(); | |
| 451 if ([sessionController.openerId isEqualToString:parentID] && | |
| 452 sessionController.openerNavigationIndex == parentNavIndex) { | |
| 453 return tabToCheck; | |
| 454 } | |
| 455 } | |
| 456 return nil; | |
| 457 } | |
| 458 | |
| 459 - (Tab*)lastTabWithOpener:(Tab*)tab { | 432 - (Tab*)lastTabWithOpener:(Tab*)tab { |
| 460 NSUInteger startIndex = [self indexOfTab:tab]; | 433 NSUInteger startIndex = [self indexOfTab:tab]; |
| 461 if (startIndex == NSNotFound) | 434 if (startIndex == NSNotFound) |
| 462 return nil; | 435 return nil; |
| 463 // There is at least one tab in the model, because otherwise the above check | 436 // There is at least one tab in the model, because otherwise the above check |
| 464 // would have returned. | 437 // would have returned. |
| 465 NSString* parentID = tab.tabId; | 438 NSString* parentID = tab.tabId; |
| 466 DCHECK([tab navigationManager]); | 439 DCHECK([tab navigationManager]); |
| 467 NSInteger parentNavIndex = [tab navigationManager]->GetCurrentItemIndex(); | 440 NSInteger parentNavIndex = [tab navigationManager]->GetCurrentItemIndex(); |
| 468 | 441 |
| (...skipping 666 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1135 web::NavigationManager::WebLoadParams params(URL); | 1108 web::NavigationManager::WebLoadParams params(URL); |
| 1136 params.referrer = referrer; | 1109 params.referrer = referrer; |
| 1137 params.transition_type = ui::PAGE_TRANSITION_TYPED; | 1110 params.transition_type = ui::PAGE_TRANSITION_TYPED; |
| 1138 [[tab webController] loadWithParams:params]; | 1111 [[tab webController] loadWithParams:params]; |
| 1139 [tab webController].webUsageEnabled = webUsageEnabled_; | 1112 [tab webController].webUsageEnabled = webUsageEnabled_; |
| 1140 [self insertTab:tab atIndex:index]; | 1113 [self insertTab:tab atIndex:index]; |
| 1141 return tab; | 1114 return tab; |
| 1142 } | 1115 } |
| 1143 | 1116 |
| 1144 @end | 1117 @end |
| OLD | NEW |