| 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 496 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 507 params.transition_type = transition; | 507 params.transition_type = transition; |
| 508 // Tabs open by DOM are always renderer initiated. | 508 // Tabs open by DOM are always renderer initiated. |
| 509 params.is_renderer_initiated = openedByDOM; | 509 params.is_renderer_initiated = openedByDOM; |
| 510 return [self insertTabWithLoadParams:params | 510 return [self insertTabWithLoadParams:params |
| 511 opener:parentTab | 511 opener:parentTab |
| 512 openedByDOM:openedByDOM | 512 openedByDOM:openedByDOM |
| 513 atIndex:index | 513 atIndex:index |
| 514 inBackground:inBackground]; | 514 inBackground:inBackground]; |
| 515 } | 515 } |
| 516 | 516 |
| 517 - (Tab*)insertTabWithWebState:(std::unique_ptr<web::WebState>)webState | 517 - (Tab*)insertTabWithNavigationItems: |
| 518 atIndex:(NSUInteger)index { | 518 (web::ScopedNavigationItemList)navigationItems |
| 519 selectedNavigationIndex:(int)selectedNavigationIndex |
| 520 atIndex:(NSUInteger)index |
| 521 inBackground:(BOOL)inBackground { |
| 519 DCHECK(_browserState); | 522 DCHECK(_browserState); |
| 520 DCHECK_EQ(webState->GetBrowserState(), _browserState); | 523 auto webState = base::MakeUnique<web::WebStateImpl>(_browserState); |
| 524 webState->GetNavigationManagerImpl().ReplaceSessionHistory( |
| 525 std::move(navigationItems), selectedNavigationIndex); |
| 521 base::scoped_nsobject<Tab> tab( | 526 base::scoped_nsobject<Tab> tab( |
| 522 [[Tab alloc] initWithWebState:std::move(webState) model:self]); | 527 [[Tab alloc] initWithWebState:std::move(webState) model:self]); |
| 523 [tab webController].webUsageEnabled = webUsageEnabled_; | 528 [tab webController].webUsageEnabled = webUsageEnabled_; |
| 524 [self insertTab:tab atIndex:index]; | 529 [self insertTab:tab atIndex:index]; |
| 530 if (!inBackground) |
| 531 [self setCurrentTab:tab]; |
| 525 return tab; | 532 return tab; |
| 526 } | 533 } |
| 527 | 534 |
| 528 - (void)insertTab:(Tab*)tab | 535 - (void)insertTab:(Tab*)tab |
| 529 atIndex:(NSUInteger)index | 536 atIndex:(NSUInteger)index |
| 530 opener:(Tab*)parentTab | 537 opener:(Tab*)parentTab |
| 531 transition:(ui::PageTransition)transition { | 538 transition:(ui::PageTransition)transition { |
| 532 DCHECK(tab); | 539 DCHECK(tab); |
| 533 DCHECK(![_tabRetainer containsObject:tab]); | 540 DCHECK(![_tabRetainer containsObject:tab]); |
| 534 | 541 |
| (...skipping 330 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 865 // at an index larger than n). Then in a second pass fix the openers. | 872 // at an index larger than n). Then in a second pass fix the openers. |
| 866 for (CRWSessionStorage* session in sessions) { | 873 for (CRWSessionStorage* session in sessions) { |
| 867 std::unique_ptr<web::WebState> webState = | 874 std::unique_ptr<web::WebState> webState = |
| 868 web::WebState::Create(params, session); | 875 web::WebState::Create(params, session); |
| 869 base::scoped_nsobject<Tab> tab( | 876 base::scoped_nsobject<Tab> tab( |
| 870 [[Tab alloc] initWithWebState:std::move(webState) model:self]); | 877 [[Tab alloc] initWithWebState:std::move(webState) model:self]); |
| 871 [tab webController].webUsageEnabled = webUsageEnabled_; | 878 [tab webController].webUsageEnabled = webUsageEnabled_; |
| 872 [tab webController].usePlaceholderOverlay = YES; | 879 [tab webController].usePlaceholderOverlay = YES; |
| 873 | 880 |
| 874 // Restore the CertificatePolicyCache (note that webState is invalid after | 881 // Restore the CertificatePolicyCache (note that webState is invalid after |
| 875 // passing it via move semantic to -insertTabWithWebState:atIndex:). | 882 // passing it via move semantic to -initWithWebState:model:). |
| 876 UpdateCertificatePolicyCacheFromWebState(policyCache, [tab webState]); | 883 UpdateCertificatePolicyCacheFromWebState(policyCache, [tab webState]); |
| 877 [self insertTab:tab atIndex:self.count opener:nil]; | 884 [self insertTab:tab atIndex:self.count opener:nil]; |
| 878 [restoredTabs addObject:tab.get()]; | 885 [restoredTabs addObject:tab.get()]; |
| 879 } | 886 } |
| 880 | 887 |
| 881 DCHECK_EQ(sessions.count, [restoredTabs count]); | 888 DCHECK_EQ(sessions.count, [restoredTabs count]); |
| 882 DCHECK_GT(_webStateList.count(), oldCount); | 889 DCHECK_GT(_webStateList.count(), oldCount); |
| 883 | 890 |
| 884 // Fix openers now that all Tabs have been restored. Only look for an opener | 891 // Fix openers now that all Tabs have been restored. Only look for an opener |
| 885 // Tab in the newly restored Tabs and not in the already open Tabs. | 892 // Tab in the newly restored Tabs and not in the already open Tabs. |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 965 } | 972 } |
| 966 | 973 |
| 967 // Called when UIApplicationWillEnterForegroundNotification is received. | 974 // Called when UIApplicationWillEnterForegroundNotification is received. |
| 968 - (void)applicationWillEnterForeground:(NSNotification*)notify { | 975 - (void)applicationWillEnterForeground:(NSNotification*)notify { |
| 969 if (_tabUsageRecorder) { | 976 if (_tabUsageRecorder) { |
| 970 _tabUsageRecorder->AppWillEnterForeground(); | 977 _tabUsageRecorder->AppWillEnterForeground(); |
| 971 } | 978 } |
| 972 } | 979 } |
| 973 | 980 |
| 974 @end | 981 @end |
| OLD | NEW |