OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/fav_icon_helper.h" | 5 #include "chrome/browser/fav_icon_helper.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 |
11 #include "base/callback.h" | 11 #include "base/callback.h" |
12 #include "base/ref_counted_memory.h" | 12 #include "base/ref_counted_memory.h" |
| 13 #include "chrome/browser/bookmarks/bookmark_model.h" |
13 #include "chrome/browser/profiles/profile.h" | 14 #include "chrome/browser/profiles/profile.h" |
14 #include "chrome/browser/renderer_host/render_view_host.h" | 15 #include "chrome/browser/renderer_host/render_view_host.h" |
15 #include "chrome/browser/tab_contents/navigation_controller.h" | 16 #include "chrome/browser/tab_contents/navigation_controller.h" |
16 #include "chrome/browser/tab_contents/navigation_entry.h" | 17 #include "chrome/browser/tab_contents/navigation_entry.h" |
17 #include "chrome/browser/tab_contents/tab_contents_delegate.h" | 18 #include "chrome/browser/tab_contents/tab_contents_delegate.h" |
18 #include "chrome/browser/tab_contents/tab_contents.h" | 19 #include "chrome/browser/tab_contents/tab_contents.h" |
19 #include "gfx/codec/png_codec.h" | 20 #include "gfx/codec/png_codec.h" |
20 #include "gfx/favicon_size.h" | 21 #include "gfx/favicon_size.h" |
21 #include "skia/ext/image_operations.h" | 22 #include "skia/ext/image_operations.h" |
22 | 23 |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
71 } | 72 } |
72 | 73 |
73 void FavIconHelper::SetFavIcon( | 74 void FavIconHelper::SetFavIcon( |
74 const GURL& url, | 75 const GURL& url, |
75 const GURL& image_url, | 76 const GURL& image_url, |
76 const SkBitmap& image) { | 77 const SkBitmap& image) { |
77 const SkBitmap& sized_image = | 78 const SkBitmap& sized_image = |
78 (image.width() == kFavIconSize && image.height() == kFavIconSize) | 79 (image.width() == kFavIconSize && image.height() == kFavIconSize) |
79 ? image : ConvertToFavIconSize(image); | 80 ? image : ConvertToFavIconSize(image); |
80 | 81 |
81 if (GetFaviconService() && !profile()->IsOffTheRecord()) { | 82 if (GetFaviconService() && ShouldSaveFavicon(url)) { |
82 std::vector<unsigned char> image_data; | 83 std::vector<unsigned char> image_data; |
83 gfx::PNGCodec::EncodeBGRASkBitmap(sized_image, false, &image_data); | 84 gfx::PNGCodec::EncodeBGRASkBitmap(sized_image, false, &image_data); |
84 GetFaviconService()->SetFavicon(url, image_url, image_data); | 85 GetFaviconService()->SetFavicon(url, image_url, image_data); |
85 } | 86 } |
86 | 87 |
87 if (url == url_) { | 88 if (url == url_) { |
88 NavigationEntry* entry = GetEntry(); | 89 NavigationEntry* entry = GetEntry(); |
89 if (entry) | 90 if (entry) |
90 UpdateFavIcon(entry, sized_image); | 91 UpdateFavIcon(entry, sized_image); |
91 } | 92 } |
(...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
289 int width = image.width(); | 290 int width = image.width(); |
290 int height = image.height(); | 291 int height = image.height(); |
291 if (width > 0 && height > 0) { | 292 if (width > 0 && height > 0) { |
292 calc_favicon_target_size(&width, &height); | 293 calc_favicon_target_size(&width, &height); |
293 return skia::ImageOperations::Resize( | 294 return skia::ImageOperations::Resize( |
294 image, skia::ImageOperations::RESIZE_LANCZOS3, | 295 image, skia::ImageOperations::RESIZE_LANCZOS3, |
295 width, height); | 296 width, height); |
296 } | 297 } |
297 return image; | 298 return image; |
298 } | 299 } |
| 300 |
| 301 bool FavIconHelper::ShouldSaveFavicon(const GURL& url) { |
| 302 if (!profile()->IsOffTheRecord()) |
| 303 return true; |
| 304 |
| 305 // Otherwise store the favicon if the page is bookmarked. |
| 306 BookmarkModel* bookmark_model = profile()->GetBookmarkModel(); |
| 307 return bookmark_model && bookmark_model->IsBookmarked(url); |
| 308 } |
OLD | NEW |