Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #import "ios/chrome/browser/tabs/tab_model_selected_tab_observer.h" | |
| 6 | |
| 7 #include "base/logging.h" | |
| 8 #import "ios/chrome/browser/tabs/legacy_tab_helper.h" | |
| 9 #import "ios/chrome/browser/tabs/tab.h" | |
| 10 #import "ios/chrome/browser/tabs/tab_model.h" | |
| 11 | |
| 12 @implementation TabModelSelectedTabObserver { | |
| 13 __weak TabModel* _tabModel; | |
|
sdefresne
2017/02/21 17:09:49
This is an Objective-C class because I cannot use
| |
| 14 } | |
| 15 | |
| 16 - (instancetype)initWithTabModel:(TabModel*)tabModel { | |
| 17 DCHECK(tabModel); | |
| 18 if ((self = [super init])) { | |
| 19 _tabModel = tabModel; | |
| 20 } | |
| 21 return self; | |
| 22 } | |
| 23 | |
| 24 #pragma mark WebStateListObserving | |
| 25 | |
| 26 - (void)webStateList:(WebStateList*)webStateList | |
| 27 didChangeActiveWebState:(web::WebState*)newWebState | |
| 28 oldWebState:(web::WebState*)oldWebState | |
| 29 atIndex:(int)atIndex | |
| 30 userAction:(BOOL)userAction { | |
| 31 Tab* oldTab = nil; | |
| 32 Tab* newTab = nil; | |
| 33 if (oldWebState) { | |
| 34 // Save state, such as scroll position, before switching tabs. | |
|
rohitrao (ping after 24h)
2017/02/22 15:13:43
This comment is half stale, because we no longer s
sdefresne
2017/02/23 15:43:48
Fixed the comment.
| |
| 35 oldTab = LegacyTabHelper::GetTabForWebState(oldWebState); | |
| 36 if (userAction) | |
| 37 [oldTab recordStateInHistory]; | |
| 38 | |
| 39 [[NSNotificationCenter defaultCenter] | |
| 40 postNotificationName:kTabModelTabDeselectedNotification | |
| 41 object:@{kTabModelTabKey : oldTab}]; | |
| 42 } | |
| 43 | |
| 44 if (newWebState) { | |
| 45 newTab = LegacyTabHelper::GetTabForWebState(newWebState); | |
| 46 [newTab updateLastVisitedTimestamp]; | |
| 47 | |
| 48 // Persist the session state. | |
| 49 if (newTab.loadFinished) | |
| 50 [_tabModel saveSessionImmediately:NO]; | |
| 51 } | |
| 52 } | |
| 53 | |
| 54 @end | |
| OLD | NEW |