Chromium Code Reviews| Index: components/favicon/content/content_favicon_driver.cc |
| diff --git a/components/favicon/content/content_favicon_driver.cc b/components/favicon/content/content_favicon_driver.cc |
| index d6bbcac5d8f4465732789f634c9778e2e8779099..f87ca164737b7cc43f8b759f6bbc053037358c76 100644 |
| --- a/components/favicon/content/content_favicon_driver.cc |
| +++ b/components/favicon/content/content_favicon_driver.cc |
| @@ -16,11 +16,28 @@ |
| #include "content/public/browser/navigation_entry.h" |
| #include "content/public/browser/navigation_handle.h" |
| #include "content/public/common/favicon_url.h" |
| +#include "content/public/common/manifest.h" |
| #include "ui/gfx/image/image.h" |
| DEFINE_WEB_CONTENTS_USER_DATA_KEY(favicon::ContentFaviconDriver); |
| namespace favicon { |
| +namespace { |
| + |
| +void ExtractManifestIcons( |
| + ContentFaviconDriver::ManifestDownloadCallback callback, |
| + const GURL& manifest_url, |
| + const content::Manifest& manifest) { |
| + // TODO/DONOTSUBMIT(mastiz): This should distinguish 404s from other status |
| + // codes. |
| + std::vector<FaviconURL> candidates; |
| + for (const content::Manifest::Icon& icon : manifest.icons) { |
| + candidates.emplace_back(icon.src, favicon_base::FAVICON, icon.sizes); |
| + } |
| + callback.Run(/*status_code=*/200, candidates); |
| +} |
| + |
| +} // namespace |
| // static |
| void ContentFaviconDriver::CreateForWebContents( |
| @@ -116,6 +133,11 @@ int ContentFaviconDriver::DownloadImage(const GURL& url, |
| callback); |
| } |
| +void ContentFaviconDriver::DownloadManifest(const GURL& url, |
| + ManifestDownloadCallback callback) { |
| + web_contents()->GetManifest(base::Bind(&ExtractManifestIcons, callback)); |
| +} |
| + |
| bool ContentFaviconDriver::IsOffTheRecord() { |
| DCHECK(web_contents()); |
| return web_contents()->GetBrowserContext()->IsOffTheRecord(); |
| @@ -154,8 +176,20 @@ void ContentFaviconDriver::DidUpdateFaviconURL( |
| return; |
| favicon_urls_ = candidates; |
|
pkotwicz
2017/04/24 14:42:15
I don't understand how this logic works. Both the
mastiz
2017/04/27 13:54:50
The assumption here is that DidUpdateManifestURL()
|
| - OnUpdateFaviconURL(entry->GetURL(), |
| - FaviconURLsFromContentFaviconURLs(candidates)); |
| +} |
| + |
| +void ContentFaviconDriver::DidUpdateManifestURL( |
| + const base::Optional<GURL>& manifest_url) { |
| + // Ignore the update if there is no last committed navigation entry. This can |
| + // occur when loading an initially blank page. |
| + content::NavigationEntry* entry = |
| + web_contents()->GetController().GetLastCommittedEntry(); |
| + if (!entry) |
| + return; |
| + |
| + OnUpdateCandidates(entry->GetURL(), |
| + FaviconURLsFromContentFaviconURLs(favicon_urls_), |
| + manifest_url); |
| } |
| void ContentFaviconDriver::DidStartNavigation( |
| @@ -163,6 +197,8 @@ void ContentFaviconDriver::DidStartNavigation( |
| if (!navigation_handle->IsInMainFrame()) |
| return; |
| + favicon_urls_.clear(); |
| + |
| content::ReloadType reload_type = navigation_handle->GetReloadType(); |
| if (reload_type == content::ReloadType::NONE || IsOffTheRecord()) |
| return; |
| @@ -181,8 +217,6 @@ void ContentFaviconDriver::DidFinishNavigation( |
| return; |
| } |
| - favicon_urls_.clear(); |
| - |
| // Wait till the user navigates to a new URL to start checking the cache |
| // again. The cache may be ignored for non-reload navigations (e.g. |
| // history.replace() in-page navigation). This is allowed to increase the |