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

Unified Diff: components/favicon/content/content_favicon_driver.cc

Issue 2799273002: Add support to process favicons from Web Manifests (Closed)
Patch Set: Browsertest comments addressed. 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
« no previous file with comments | « components/favicon/content/content_favicon_driver.h ('k') | components/favicon/core/favicon_driver_impl.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 e5935ffcc381da3ab051b5bf3ac46f35ad66a9fd..00442d00fa7dc27d77de5d90406c2c39d8354bb5 100644
--- a/components/favicon/content/content_favicon_driver.cc
+++ b/components/favicon/content/content_favicon_driver.cc
@@ -17,11 +17,26 @@
#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(
+ const ContentFaviconDriver::ManifestDownloadCallback& callback,
+ const GURL& manifest_url,
+ const content::Manifest& manifest) {
+ std::vector<FaviconURL> candidates;
+ for (const content::Manifest::Icon& icon : manifest.icons) {
+ candidates.emplace_back(icon.src, favicon_base::FAVICON, icon.sizes);
+ }
+ callback.Run(candidates);
+}
+
+} // namespace
// static
void ContentFaviconDriver::CreateForWebContents(
@@ -118,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();
@@ -156,8 +176,31 @@ void ContentFaviconDriver::DidUpdateFaviconURL(
return;
favicon_urls_ = candidates;
+
OnUpdateCandidates(entry->GetURL(),
- FaviconURLsFromContentFaviconURLs(candidates));
+ FaviconURLsFromContentFaviconURLs(candidates),
+ manifest_url_);
+}
+
+void ContentFaviconDriver::DidUpdateWebManifestURL(
+ 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;
+
+ manifest_url_ = manifest_url.value_or(GURL());
+
+ // On regular page loads, DidUpdateManifestURL() is guaranteed to be called
+ // before DidUpdateFaviconURL(). However, a page can update the favicons via
+ // javascript.
+ if (favicon_urls_.has_value()) {
+ OnUpdateCandidates(entry->GetURL(),
+ FaviconURLsFromContentFaviconURLs(*favicon_urls_),
+ manifest_url_);
+ }
}
void ContentFaviconDriver::DidStartNavigation(
@@ -165,6 +208,9 @@ void ContentFaviconDriver::DidStartNavigation(
if (!navigation_handle->IsInMainFrame())
return;
+ favicon_urls_.reset();
+ manifest_url_ = GURL();
+
content::ReloadType reload_type = navigation_handle->GetReloadType();
if (reload_type == content::ReloadType::NONE || IsOffTheRecord())
return;
@@ -183,8 +229,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
« no previous file with comments | « components/favicon/content/content_favicon_driver.h ('k') | components/favicon/core/favicon_driver_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698