Commit 528205c9 authored by olivierrobin's avatar olivierrobin Committed by Commit bot

[Reading List] Display the redirected URL's favicon.

If the page is distilled and led to a redirection, the favicon to display
is the favicon of the final page.

BUG=688273

Review-Url: https://codereview.chromium.org/2673003002
Cr-Commit-Position: refs/heads/master@{#447997}
parent 9ea51a5f
......@@ -82,6 +82,8 @@ class ReadingListDistillerPage : public dom_distiller::DistillerPageIOS {
// Continue the distillation on the page that is currently loaded in
// |CurrentWebState()|.
void ContinuePageDistillation();
// Starts the fetching of |page_url|'s favicon.
void FetchFavicon(const GURL& page_url);
// Continues distillation by calling superclass |OnLoadURLDone|.
void DelayedOnLoadURLDone();
......
......@@ -54,17 +54,23 @@ void ReadingListDistillerPage::DistillPageImpl(const GURL& url,
}
std::unique_ptr<web::WebState> new_web_state =
web_state_dispatcher_->RequestWebState();
if (new_web_state) {
favicon::WebFaviconDriver* favicon_driver =
favicon::WebFaviconDriver::FromWebState(new_web_state.get());
favicon_driver->FetchFavicon(url);
}
AttachWebState(std::move(new_web_state));
original_url_ = url;
FetchFavicon(url);
DistillerPageIOS::DistillPageImpl(url, script);
}
void ReadingListDistillerPage::FetchFavicon(const GURL& page_url) {
if (!CurrentWebState() || !page_url.is_valid()) {
return;
}
favicon::WebFaviconDriver* favicon_driver =
favicon::WebFaviconDriver::FromWebState(CurrentWebState());
DCHECK(favicon_driver);
favicon_driver->FetchFavicon(page_url);
}
void ReadingListDistillerPage::OnDistillationDone(const GURL& page_url,
const base::Value* value) {
std::unique_ptr<web::WebState> old_web_state = DetachWebState();
......@@ -117,6 +123,8 @@ void ReadingListDistillerPage::OnLoadURLDone(
DistillerPageIOS::OnLoadURLDone(load_completion_status);
return;
}
FetchFavicon(CurrentWebState()->GetVisibleURL());
// Page is loaded but rendering may not be done yet. Give a delay to the page.
base::WeakPtr<ReadingListDistillerPage> weak_this =
weak_ptr_factory_.GetWeakPtr();
......@@ -213,6 +221,7 @@ bool ReadingListDistillerPage::HandleGoogleCachedAMPPageJavaScriptResult(
if (!new_gurl.is_valid()) {
return false;
}
FetchFavicon(new_gurl);
web::NavigationManager::WebLoadParams params(new_gurl);
CurrentWebState()->GetNavigationManager()->LoadURLWithParams(params);
return true;
......
......@@ -21,6 +21,8 @@ class GURL;
@property(nonatomic, copy) NSString* detailText;
// The URL of the Reading List entry.
@property(nonatomic, readonly) const GURL& url;
// The URL of the page presenting the favicon to display.
@property(nonatomic, assign) GURL faviconPageURL;
// Status of the offline version.
@property(nonatomic, assign)
ReadingListEntry::DistillationState distillationState;
......
......@@ -64,6 +64,7 @@ const CGFloat kDistillationIndicatorSize = 18;
@synthesize text = _text;
@synthesize detailText = _detailText;
@synthesize url = _url;
@synthesize faviconPageURL = _faviconPageURL;
@synthesize displayedCell = _displayedCell;
@synthesize distillationState = _distillationState;
......@@ -78,22 +79,27 @@ const CGFloat kDistillationIndicatorSize = 18;
_faviconAttributesProvider = provider;
_url = url;
_distillationState = state;
return self;
}
- (void)setFaviconPageURL:(GURL)url {
_faviconPageURL = url;
// |self| owns |provider|, |provider| owns the block, so a week self reference
// is necessary.
__weak ReadingListCollectionViewItem* weakSelf = self;
[provider
[_faviconAttributesProvider
fetchFaviconAttributesForURL:url
completion:^(FaviconAttributes* _Nonnull attributes) {
ReadingListCollectionViewItem* strongSelf = weakSelf;
if (!strongSelf) {
return;
}
strongSelf.attributes = attributes;
[strongSelf.displayedCell.faviconView
configureWithAttributes:attributes];
configureWithAttributes:strongSelf.attributes];
}];
return self;
}
#pragma mark - property
......
......@@ -589,6 +589,7 @@ using ItemsMapByDate = std::multimap<int64_t, ReadingListCollectionViewItem*>;
if (oldItem.url == newItem.url) {
oldItem.text = newItem.text;
oldItem.distillationState = newItem.distillationState;
oldItem.faviconPageURL = newItem.faviconPageURL;
}
if (![oldItem isEqual:newItem]) {
return YES;
......@@ -609,6 +610,8 @@ using ItemsMapByDate = std::multimap<int64_t, ReadingListCollectionViewItem*>;
base::string16 urlString = url_formatter::FormatUrl(url);
item.text = base::SysUTF8ToNSString(entry.Title());
item.detailText = base::SysUTF16ToNSString(urlString);
item.faviconPageURL =
entry.DistilledURL().is_valid() ? entry.DistilledURL() : url;
return item;
}
......
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