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

Side by Side Diff: chrome/browser/fav_icon_helper.cc

Issue 243076: Move the JPEG and PNG codecs from base/gfx to app/gfx/codec. Move the classes... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 2 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2009 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 "app/gfx/codec/png_codec.h"
9 #include "app/gfx/favicon_size.h" 10 #include "app/gfx/favicon_size.h"
10 #include "base/gfx/png_decoder.h"
11 #include "base/gfx/png_encoder.h"
12 #include "chrome/browser/profile.h" 11 #include "chrome/browser/profile.h"
13 #include "chrome/browser/renderer_host/render_view_host.h" 12 #include "chrome/browser/renderer_host/render_view_host.h"
14 #include "chrome/browser/tab_contents/navigation_controller.h" 13 #include "chrome/browser/tab_contents/navigation_controller.h"
15 #include "chrome/browser/tab_contents/navigation_entry.h" 14 #include "chrome/browser/tab_contents/navigation_entry.h"
16 #include "chrome/browser/tab_contents/tab_contents_delegate.h" 15 #include "chrome/browser/tab_contents/tab_contents_delegate.h"
17 #include "chrome/browser/tab_contents/tab_contents.h" 16 #include "chrome/browser/tab_contents/tab_contents.h"
18 #include "skia/ext/image_operations.h" 17 #include "skia/ext/image_operations.h"
19 18
20 FavIconHelper::FavIconHelper(TabContents* tab_contents) 19 FavIconHelper::FavIconHelper(TabContents* tab_contents)
21 : tab_contents_(tab_contents), 20 : tab_contents_(tab_contents),
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
58 // possible to get here. 57 // possible to get here.
59 return; 58 return;
60 } 59 }
61 60
62 const SkBitmap& sized_image = 61 const SkBitmap& sized_image =
63 (image.width() == kFavIconSize && image.height() == kFavIconSize) 62 (image.width() == kFavIconSize && image.height() == kFavIconSize)
64 ? image : ConvertToFavIconSize(image); 63 ? image : ConvertToFavIconSize(image);
65 64
66 if (GetFaviconService() && !profile()->IsOffTheRecord()) { 65 if (GetFaviconService() && !profile()->IsOffTheRecord()) {
67 std::vector<unsigned char> image_data; 66 std::vector<unsigned char> image_data;
68 PNGEncoder::EncodeBGRASkBitmap(sized_image, false, &image_data); 67 gfx::PNGCodec::EncodeBGRASkBitmap(sized_image, false, &image_data);
69 GetFaviconService()->SetFavicon(i->second.url, i->second.fav_icon_url, 68 GetFaviconService()->SetFavicon(i->second.url, i->second.fav_icon_url,
70 image_data); 69 image_data);
71 } 70 }
72 71
73 if (i->second.url == url_) { 72 if (i->second.url == url_) {
74 NavigationEntry* entry = GetEntry(); 73 NavigationEntry* entry = GetEntry();
75 if (entry) 74 if (entry)
76 UpdateFavIcon(entry, sized_image); 75 UpdateFavIcon(entry, sized_image);
77 } 76 }
78 77
79 download_requests_.erase(i); 78 download_requests_.erase(i);
80 } 79 }
81 80
82 void FavIconHelper::FavIconDownloadFailed(int download_id) { 81 void FavIconHelper::FavIconDownloadFailed(int download_id) {
83 DownloadRequests::iterator i = download_requests_.find(download_id); 82 DownloadRequests::iterator i = download_requests_.find(download_id);
84 if (i != download_requests_.end()) 83 if (i != download_requests_.end())
85 download_requests_.erase(i); 84 download_requests_.erase(i);
86 } 85 }
87 86
88 void FavIconHelper::UpdateFavIcon(NavigationEntry* entry, 87 void FavIconHelper::UpdateFavIcon(NavigationEntry* entry,
89 const std::vector<unsigned char>& data) { 88 const std::vector<unsigned char>& data) {
90 SkBitmap image; 89 SkBitmap image;
91 PNGDecoder::Decode(&data, &image); 90 gfx::PNGCodec::Decode(&data, &image);
92 UpdateFavIcon(entry, image); 91 UpdateFavIcon(entry, image);
93 } 92 }
94 93
95 void FavIconHelper::UpdateFavIcon(NavigationEntry* entry, 94 void FavIconHelper::UpdateFavIcon(NavigationEntry* entry,
96 const SkBitmap& image) { 95 const SkBitmap& image) {
97 // No matter what happens, we need to mark the favicon as being set. 96 // No matter what happens, we need to mark the favicon as being set.
98 entry->favicon().set_is_valid(true); 97 entry->favicon().set_is_valid(true);
99 98
100 if (image.empty()) 99 if (image.empty())
101 return; 100 return;
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after
263 int width = image.width(); 262 int width = image.width();
264 int height = image.height(); 263 int height = image.height();
265 if (width > 0 && height > 0) { 264 if (width > 0 && height > 0) {
266 calc_favicon_target_size(&width, &height); 265 calc_favicon_target_size(&width, &height);
267 return skia::ImageOperations::Resize( 266 return skia::ImageOperations::Resize(
268 image, skia::ImageOperations::RESIZE_LANCZOS3, 267 image, skia::ImageOperations::RESIZE_LANCZOS3,
269 width, height); 268 width, height);
270 } 269 }
271 return image; 270 return image;
272 } 271 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698