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

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: 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..64e18de5c98f1064e0f8a18856d4f03a14c676f5 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>
sczs 2017/05/26 16:12:52 Could we also move the WebstateListObserverving to
edchin 2017/05/26 18:09:00 WSLO is needed by the subclasses so it is exposed.
sczs 2017/05/30 02:32:02 Acknowledged.
+@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
@@ -104,6 +110,17 @@
userAction:(BOOL)userAction {
DCHECK(self.consumer);
[self.consumer selectItemAtIndex:atIndex];
+ _webStateObserver =
+ base::MakeUnique<web::WebStateObserverBridge>(newWebState, self);
+}
+
+#pragma mark - CRWWebStateObserver
+
+- (void)webState:(web::WebState*)webState didLoadPageWithSuccess:(BOOL)success {
rohitrao (ping after 24h) 2017/05/26 12:44:01 Please add a comment explaining why we listen for
edchin 2017/05/26 18:09:00 Done.
+ int index = self.webStateList->GetIndexOfWebState(webState);
+ [self.consumer
+ replaceItemAtIndex:index
+ withItem:[self tabCollectionItemFromWebState:webState]];
}
#pragma mark - Private
@@ -140,6 +157,9 @@
[self.consumer populateItems:[self tabCollectionItemsFromWebStateList:
self.webStateList]];
[self.consumer selectItemAtIndex:self.webStateList->active_index()];
+ web::WebState* webState = self.webStateList->GetActiveWebState();
+ _webStateObserver =
+ base::MakeUnique<web::WebStateObserverBridge>(webState, self);
}
}

Powered by Google App Engine
This is Rietveld 408576698