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

Unified Diff: chrome/browser/favicon/favicon_handler.cc

Issue 9852012: Fix favicon exact match logic and add test. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix url fragment logic Created 8 years, 9 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 | « chrome/browser/favicon/favicon_handler.h ('k') | chrome/browser/favicon/favicon_handler_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/favicon/favicon_handler.cc
diff --git a/chrome/browser/favicon/favicon_handler.cc b/chrome/browser/favicon/favicon_handler.cc
index a94a8d7e8d2908810964f43a6cfac987c9b0b207..81480bc36da69ecf8781e674213df88c127c5a17 100644
--- a/chrome/browser/favicon/favicon_handler.cc
+++ b/chrome/browser/favicon/favicon_handler.cc
@@ -49,6 +49,18 @@ bool DoUrlAndIconMatch(const FaviconURL& favicon_url,
favicon_url.icon_type == static_cast<FaviconURL::IconType>(icon_type);
}
+std::string UrlWithoutFragment(const GURL& gurl) {
+ std::string url = gurl.spec();
sky 2012/03/25 18:46:46 I believe you want ReplaceComponents.
stevenjb 2012/03/25 22:00:15 So I do, thanks. Done.
+ std::string::size_type n = url.rfind(gurl.ref());
+ if (n != std::string::npos && n > 0)
+ url = url.substr(0, n-1); // Trim fragment, including the leading '#'.
+ return url;
+}
+
+bool UrlMatches(const GURL& gurl_a, const GURL& gurl_b) {
+ return UrlWithoutFragment(gurl_a) == UrlWithoutFragment(gurl_b);
+}
+
} // namespace
////////////////////////////////////////////////////////////////////////////////
@@ -154,10 +166,11 @@ bool FaviconHandler::UpdateFaviconCandidate(const GURL& url,
const gfx::Image& image,
history::IconType icon_type) {
bool update_candidate = false;
- bool exact_match = false;
SkBitmap bitmap = *(image.ToSkBitmap());
int bitmap_size = std::max(bitmap.width(), bitmap.height());
+ bool exact_match = (bitmap_size == preferred_icon_size());
if (preferred_icon_size() == 0) {
+ // No preferred size, use this icon.
update_candidate = true;
exact_match = true;
} else if (favicon_candidate_.icon_type == history::INVALID_ICON) {
@@ -167,7 +180,6 @@ bool FaviconHandler::UpdateFaviconCandidate(const GURL& url,
if (bitmap_size == preferred_icon_size()) {
// Exact match, use this.
update_candidate = true;
- exact_match = true;
} else {
// Compare against current candidate.
int cur_size = favicon_candidate_.bitmap_size;
@@ -201,7 +213,7 @@ void FaviconHandler::SetFavicon(
SetHistoryFavicon(url, image_url, image_data, icon_type);
}
- if (url == url_ && icon_type == history::FAVICON) {
+ if (UrlMatches(url, url_) && icon_type == history::FAVICON) {
NavigationEntry* entry = GetEntry();
if (entry) {
entry->GetFavicon().url = image_url;
@@ -323,7 +335,7 @@ void FaviconHandler::OnDidDownloadFavicon(int id,
NavigationEntry* FaviconHandler::GetEntry() {
NavigationEntry* entry = delegate_->GetActiveEntry();
- if (entry && entry->GetURL() == url_)
+ if (entry && UrlMatches(entry->GetURL(), url_))
return entry;
// If the URL has changed out from under us (as will happen with redirects)
« no previous file with comments | « chrome/browser/favicon/favicon_handler.h ('k') | chrome/browser/favicon/favicon_handler_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698