Commit c25d842f authored by edchin's avatar edchin Committed by Commit Bot

[ios] Improve favicon in tab grid

The tab grid cell titles were previously being updated too late
on "page loaded", rather than earlier on "title changed".

This CL also sets a default icon for cells.

This CL also removes an old snapshot in the tab grid once the
title has changed, so that the title and snapshot are in sync.

Video:
https://drive.google.com/open?id=1NvSuQ039jsl0YTqO6ua_IREk7f2Z807C


Bug: 860245, 853569
Cq-Include-Trybots: luci.chromium.try:ios-simulator-full-configs;master.tryserver.chromium.mac:ios-simulator-cronet
Change-Id: Ic3317ddc50ceb16fe0d89b41e8b26fc2bac203e9
Reviewed-on: https://chromium-review.googlesource.com/1136836Reviewed-by: default avatarRohit Rao <rohitrao@chromium.org>
Reviewed-by: default avataredchin <edchin@chromium.org>
Commit-Queue: edchin <edchin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#575078}
parent 8119ab89
...@@ -11,6 +11,7 @@ ...@@ -11,6 +11,7 @@
#include "components/favicon/ios/web_favicon_driver.h" #include "components/favicon/ios/web_favicon_driver.h"
#include "ios/chrome/browser/browser_state/chrome_browser_state.h" #include "ios/chrome/browser/browser_state/chrome_browser_state.h"
#include "ios/chrome/browser/chrome_url_constants.h" #include "ios/chrome/browser/chrome_url_constants.h"
#include "ios/chrome/browser/experimental_flags.h"
#import "ios/chrome/browser/snapshots/snapshot_cache.h" #import "ios/chrome/browser/snapshots/snapshot_cache.h"
#import "ios/chrome/browser/snapshots/snapshot_cache_factory.h" #import "ios/chrome/browser/snapshots/snapshot_cache_factory.h"
#import "ios/chrome/browser/snapshots/snapshot_tab_helper.h" #import "ios/chrome/browser/snapshots/snapshot_tab_helper.h"
...@@ -205,8 +206,9 @@ web::WebState* GetWebStateWithId(WebStateList* web_state_list, ...@@ -205,8 +206,9 @@ web::WebState* GetWebStateWithId(WebStateList* web_state_list,
#pragma mark - CRWWebStateObserver #pragma mark - CRWWebStateObserver
- (void)webState:(web::WebState*)webState didLoadPageWithSuccess:(BOOL)success { - (void)webStateDidChangeTitle:(web::WebState*)webState {
// Assumption: the ID of the webState didn't change as a result of this load. // Assumption: the ID of the webState didn't change as a result of this load.
SnapshotTabHelper::FromWebState(webState)->RemoveSnapshot();
TabIdTabHelper* tabHelper = TabIdTabHelper::FromWebState(webState); TabIdTabHelper* tabHelper = TabIdTabHelper::FromWebState(webState);
NSString* itemID = tabHelper->tab_id(); NSString* itemID = tabHelper->tab_id();
[self.consumer replaceItemID:itemID withItem:CreateItem(webState)]; [self.consumer replaceItemID:itemID withItem:CreateItem(webState)];
...@@ -314,14 +316,22 @@ web::WebState* GetWebStateWithId(WebStateList* web_state_list, ...@@ -314,14 +316,22 @@ web::WebState* GetWebStateWithId(WebStateList* web_state_list,
- (void)faviconForIdentifier:(NSString*)identifier - (void)faviconForIdentifier:(NSString*)identifier
completion:(void (^)(UIImage*))completion { completion:(void (^)(UIImage*))completion {
web::WebState* webState = GetWebStateWithId(self.webStateList, identifier); web::WebState* webState = GetWebStateWithId(self.webStateList, identifier);
if (webState) { if (!webState) {
favicon::FaviconDriver* faviconDriver = return;
favicon::WebFaviconDriver::FromWebState(webState); }
if (faviconDriver) { UIImage* defaultFavicon;
gfx::Image favicon = faviconDriver->GetFavicon(); if (experimental_flags::IsCollectionsUIRebootEnabled()) {
if (!favicon.IsEmpty()) defaultFavicon = [UIImage imageNamed:@"default_world_favicon"];
completion(favicon.ToUIImage()); }
} defaultFavicon = [UIImage imageNamed:@"default_favicon"];
completion(defaultFavicon);
favicon::FaviconDriver* faviconDriver =
favicon::WebFaviconDriver::FromWebState(webState);
if (faviconDriver) {
gfx::Image favicon = faviconDriver->GetFavicon();
if (!favicon.IsEmpty())
completion(favicon.ToUIImage());
} }
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment