Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(77)

Unified Diff: ios/clean/chrome/browser/ui/tab_collection/tab_collection_mediator.mm

Issue 2904053002: [ios] Active web state observer in tab collection. (Closed)
Patch Set: Address comments. Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: ios/clean/chrome/browser/ui/tab_collection/tab_collection_mediator.mm
diff --git a/ios/clean/chrome/browser/ui/tab_collection/tab_collection_mediator.mm b/ios/clean/chrome/browser/ui/tab_collection/tab_collection_mediator.mm
index 58839e6bbda687110437202ee12a8eca962361f4..052aef751ef88e78c488553f07ee95a9b5528c38 100644
--- a/ios/clean/chrome/browser/ui/tab_collection/tab_collection_mediator.mm
+++ b/ios/clean/chrome/browser/ui/tab_collection/tab_collection_mediator.mm
@@ -11,15 +11,20 @@
#import "ios/clean/chrome/browser/ui/tab_collection/tab_collection_consumer.h"
#import "ios/clean/chrome/browser/ui/tab_collection/tab_collection_item.h"
#include "ios/web/public/web_state/web_state.h"
+#import "ios/web/public/web_state/web_state_observer_bridge.h"
#if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support."
#endif
+@interface TabCollectionMediator ()<CRWWebStateObserver>
+@end
+
@implementation TabCollectionMediator {
std::unique_ptr<WebStateListObserverBridge> _webStateListObserver;
std::unique_ptr<ScopedObserver<WebStateList, WebStateListObserverBridge>>
_scopedWebStateListObserver;
+ std::unique_ptr<web::WebStateObserverBridge> _webStateObserver;
}
@synthesize webStateList = _webStateList;
@@ -44,6 +49,7 @@
- (void)disconnect {
self.webStateList = nullptr;
+ _webStateObserver.reset();
}
#pragma mark - Properties
@@ -69,7 +75,8 @@
atIndex:(int)index {
DCHECK(self.consumer);
[self.consumer insertItem:[self tabCollectionItemFromWebState:webState]
- atIndex:index];
+ atIndex:index
+ selectedIndex:webStateList->active_index()];
}
- (void)webStateList:(WebStateList*)webStateList
@@ -77,7 +84,9 @@
fromIndex:(int)fromIndex
toIndex:(int)toIndex {
DCHECK(self.consumer);
- [self.consumer moveItemFromIndex:fromIndex toIndex:toIndex];
+ [self.consumer moveItemFromIndex:fromIndex
+ toIndex:toIndex
+ selectedIndex:webStateList->active_index()];
}
- (void)webStateList:(WebStateList*)webStateList
@@ -94,7 +103,8 @@
didDetachWebState:(web::WebState*)webState
atIndex:(int)index {
DCHECK(self.consumer);
- [self.consumer deleteItemAtIndex:index];
+ [self.consumer deleteItemAtIndex:index
+ selectedIndex:webStateList->active_index()];
}
- (void)webStateList:(WebStateList*)webStateList
@@ -104,6 +114,19 @@
userAction:(BOOL)userAction {
DCHECK(self.consumer);
[self.consumer selectItemAtIndex:atIndex];
+ _webStateObserver =
+ base::MakeUnique<web::WebStateObserverBridge>(newWebState, self);
+}
+
+#pragma mark - CRWWebStateObserver
+
+// Navigational changes to the web state update the tab collection, such as
+// the title and snapshot.
+- (void)webState:(web::WebState*)webState didLoadPageWithSuccess:(BOOL)success {
+ int index = self.webStateList->GetIndexOfWebState(webState);
+ [self.consumer
+ replaceItemAtIndex:index
+ withItem:[self tabCollectionItemFromWebState:webState]];
}
#pragma mark - Private
marq (ping after 24h) 2017/05/30 11:09:43 Each private method needs a comment.
@@ -137,9 +160,13 @@
- (void)populateConsumerItems {
if (self.consumer && self.webStateList) {
- [self.consumer populateItems:[self tabCollectionItemsFromWebStateList:
- self.webStateList]];
- [self.consumer selectItemAtIndex:self.webStateList->active_index()];
+ [self.consumer
+ populateItems:[self
+ tabCollectionItemsFromWebStateList:self.webStateList]
+ selectedIndex:self.webStateList->active_index()];
+ web::WebState* webState = self.webStateList->GetActiveWebState();
+ _webStateObserver =
marq (ping after 24h) 2017/05/30 11:09:43 Setting the WSO seems disconnected from populating
edchin 2017/06/01 23:52:28 Moved to a more appropriate place. It should be se
+ base::MakeUnique<web::WebStateObserverBridge>(webState, self);
}
}

Powered by Google App Engine
This is Rietveld 408576698