OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/favicon/favicon_handler.h" | 5 #include "chrome/browser/favicon/favicon_handler.h" |
6 | 6 |
7 #include "build/build_config.h" | 7 #include "build/build_config.h" |
8 | 8 |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
42 return history::INVALID_ICON; | 42 return history::INVALID_ICON; |
43 } | 43 } |
44 | 44 |
45 bool DoUrlAndIconMatch(const FaviconURL& favicon_url, | 45 bool DoUrlAndIconMatch(const FaviconURL& favicon_url, |
46 const GURL& url, | 46 const GURL& url, |
47 history::IconType icon_type) { | 47 history::IconType icon_type) { |
48 return favicon_url.icon_url == url && | 48 return favicon_url.icon_url == url && |
49 favicon_url.icon_type == static_cast<FaviconURL::IconType>(icon_type); | 49 favicon_url.icon_type == static_cast<FaviconURL::IconType>(icon_type); |
50 } | 50 } |
51 | 51 |
52 bool UrlMatches(const GURL& gurl_a, const GURL& gurl_b) { | |
53 std::string a = gurl_a.spec(); | |
54 std::string b = gurl_b.spec(); | |
55 // Compare the URL spec without the fragment. | |
56 return a.substr(0, a.rfind('#')) == b.substr(0, b.rfind('#')); | |
stevenjb
2012/03/24 19:07:56
This addresses a pre-existing inconsistency in fav
sky
2012/03/25 03:59:23
This makes me nervous as I'm not sure of the rules
stevenjb
2012/03/25 18:38:23
Good point, trimming gurl.ref() will be much more
| |
57 } | |
58 | |
52 } // namespace | 59 } // namespace |
53 | 60 |
54 //////////////////////////////////////////////////////////////////////////////// | 61 //////////////////////////////////////////////////////////////////////////////// |
55 | 62 |
56 FaviconHandler::DownloadRequest::DownloadRequest() | 63 FaviconHandler::DownloadRequest::DownloadRequest() |
57 : icon_type(history::INVALID_ICON) { | 64 : icon_type(history::INVALID_ICON) { |
58 } | 65 } |
59 | 66 |
60 FaviconHandler::DownloadRequest::~DownloadRequest() { | 67 FaviconHandler::DownloadRequest::~DownloadRequest() { |
61 } | 68 } |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
147 | 154 |
148 FaviconService* FaviconHandler::GetFaviconService() { | 155 FaviconService* FaviconHandler::GetFaviconService() { |
149 return profile_->GetFaviconService(Profile::EXPLICIT_ACCESS); | 156 return profile_->GetFaviconService(Profile::EXPLICIT_ACCESS); |
150 } | 157 } |
151 | 158 |
152 bool FaviconHandler::UpdateFaviconCandidate(const GURL& url, | 159 bool FaviconHandler::UpdateFaviconCandidate(const GURL& url, |
153 const GURL& image_url, | 160 const GURL& image_url, |
154 const gfx::Image& image, | 161 const gfx::Image& image, |
155 history::IconType icon_type) { | 162 history::IconType icon_type) { |
156 bool update_candidate = false; | 163 bool update_candidate = false; |
157 bool exact_match = false; | |
158 SkBitmap bitmap = *(image.ToSkBitmap()); | 164 SkBitmap bitmap = *(image.ToSkBitmap()); |
159 int bitmap_size = std::max(bitmap.width(), bitmap.height()); | 165 int bitmap_size = std::max(bitmap.width(), bitmap.height()); |
166 bool exact_match = (bitmap_size == preferred_icon_size()); | |
160 if (preferred_icon_size() == 0) { | 167 if (preferred_icon_size() == 0) { |
168 // No preferred size, use this icon. | |
161 update_candidate = true; | 169 update_candidate = true; |
162 exact_match = true; | 170 exact_match = true; |
163 } else if (favicon_candidate_.icon_type == history::INVALID_ICON) { | 171 } else if (favicon_candidate_.icon_type == history::INVALID_ICON) { |
164 // No current candidate, use this. | 172 // No current candidate, use this. |
165 update_candidate = true; | 173 update_candidate = true; |
stevenjb
2012/03/24 19:07:56
The real bug was that exact_match was not getting
| |
166 } else { | 174 } else { |
167 if (bitmap_size == preferred_icon_size()) { | 175 if (bitmap_size == preferred_icon_size()) { |
168 // Exact match, use this. | 176 // Exact match, use this. |
169 update_candidate = true; | 177 update_candidate = true; |
170 exact_match = true; | |
171 } else { | 178 } else { |
172 // Compare against current candidate. | 179 // Compare against current candidate. |
173 int cur_size = favicon_candidate_.bitmap_size; | 180 int cur_size = favicon_candidate_.bitmap_size; |
174 if ((bitmap_size >= preferred_icon_size() && bitmap_size < cur_size) || | 181 if ((bitmap_size >= preferred_icon_size() && bitmap_size < cur_size) || |
175 (cur_size < preferred_icon_size() && bitmap_size > cur_size)) { | 182 (cur_size < preferred_icon_size() && bitmap_size > cur_size)) { |
176 update_candidate = true; | 183 update_candidate = true; |
177 } | 184 } |
178 } | 185 } |
179 } | 186 } |
180 if (update_candidate) { | 187 if (update_candidate) { |
(...skipping 13 matching lines...) Expand all Loading... | |
194 (preferred_icon_size() == bitmap.width() && | 201 (preferred_icon_size() == bitmap.width() && |
195 preferred_icon_size() == bitmap.height())) ? | 202 preferred_icon_size() == bitmap.height())) ? |
196 image : ResizeFaviconIfNeeded(image); | 203 image : ResizeFaviconIfNeeded(image); |
197 | 204 |
198 if (GetFaviconService() && ShouldSaveFavicon(url)) { | 205 if (GetFaviconService() && ShouldSaveFavicon(url)) { |
199 std::vector<unsigned char> image_data; | 206 std::vector<unsigned char> image_data; |
200 if (gfx::PNGEncodedDataFromImage(sized_image, &image_data)) | 207 if (gfx::PNGEncodedDataFromImage(sized_image, &image_data)) |
201 SetHistoryFavicon(url, image_url, image_data, icon_type); | 208 SetHistoryFavicon(url, image_url, image_data, icon_type); |
202 } | 209 } |
203 | 210 |
204 if (url == url_ && icon_type == history::FAVICON) { | 211 if (UrlMatches(url, url_) && icon_type == history::FAVICON) { |
205 NavigationEntry* entry = GetEntry(); | 212 NavigationEntry* entry = GetEntry(); |
206 if (entry) { | 213 if (entry) { |
207 entry->GetFavicon().url = image_url; | 214 entry->GetFavicon().url = image_url; |
208 UpdateFavicon(entry, &sized_image); | 215 UpdateFavicon(entry, &sized_image); |
209 } | 216 } |
210 } | 217 } |
211 } | 218 } |
212 | 219 |
213 void FaviconHandler::UpdateFavicon(NavigationEntry* entry, | 220 void FaviconHandler::UpdateFavicon(NavigationEntry* entry, |
214 scoped_refptr<RefCountedMemory> data) { | 221 scoped_refptr<RefCountedMemory> data) { |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
316 // Reset candidate. | 323 // Reset candidate. |
317 image_urls_.clear(); | 324 image_urls_.clear(); |
318 favicon_candidate_ = FaviconCandidate(); | 325 favicon_candidate_ = FaviconCandidate(); |
319 } | 326 } |
320 } | 327 } |
321 download_requests_.erase(i); | 328 download_requests_.erase(i); |
322 } | 329 } |
323 | 330 |
324 NavigationEntry* FaviconHandler::GetEntry() { | 331 NavigationEntry* FaviconHandler::GetEntry() { |
325 NavigationEntry* entry = delegate_->GetActiveEntry(); | 332 NavigationEntry* entry = delegate_->GetActiveEntry(); |
326 if (entry && entry->GetURL() == url_) | 333 if (entry && UrlMatches(entry->GetURL(), url_)) |
327 return entry; | 334 return entry; |
328 | 335 |
329 // If the URL has changed out from under us (as will happen with redirects) | 336 // If the URL has changed out from under us (as will happen with redirects) |
330 // return NULL. | 337 // return NULL. |
331 return NULL; | 338 return NULL; |
332 } | 339 } |
333 | 340 |
334 int FaviconHandler::DownloadFavicon(const GURL& image_url, int image_size) { | 341 int FaviconHandler::DownloadFavicon(const GURL& image_url, int image_size) { |
335 if (!image_url.is_valid()) { | 342 if (!image_url.is_valid()) { |
336 NOTREACHED(); | 343 NOTREACHED(); |
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
524 int height = bitmap.height(); | 531 int height = bitmap.height(); |
525 if (width > 0 && height > 0) { | 532 if (width > 0 && height > 0) { |
526 gfx::CalculateFaviconTargetSize(&width, &height); | 533 gfx::CalculateFaviconTargetSize(&width, &height); |
527 return gfx::Image(skia::ImageOperations::Resize( | 534 return gfx::Image(skia::ImageOperations::Resize( |
528 bitmap, skia::ImageOperations::RESIZE_LANCZOS3, | 535 bitmap, skia::ImageOperations::RESIZE_LANCZOS3, |
529 width, height)); | 536 width, height)); |
530 } | 537 } |
531 | 538 |
532 return image; | 539 return image; |
533 } | 540 } |
OLD | NEW |