Chromium Code Reviews| 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 "components/favicon/core/favicon_handler.h" | 5 #include "components/favicon/core/favicon_handler.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <cmath> | 8 #include <cmath> |
| 9 #include <utility> | 9 #include <utility> |
| 10 #include <vector> | 10 #include <vector> |
| 11 | 11 |
| 12 #include "base/bind.h" | 12 #include "base/bind.h" |
| 13 #include "base/bind_helpers.h" | 13 #include "base/bind_helpers.h" |
| 14 #include "base/memory/ref_counted_memory.h" | 14 #include "base/memory/ref_counted_memory.h" |
| 15 #include "build/build_config.h" | 15 #include "build/build_config.h" |
| 16 #include "components/favicon/core/favicon_service.h" | 16 #include "components/favicon/core/favicon_service.h" |
| 17 #include "components/favicon_base/favicon_util.h" | 17 #include "components/favicon_base/favicon_util.h" |
| 18 #include "components/favicon_base/select_favicon_frames.h" | 18 #include "components/favicon_base/select_favicon_frames.h" |
| 19 #include "skia/ext/image_operations.h" | 19 #include "skia/ext/image_operations.h" |
| 20 #include "ui/gfx/codec/png_codec.h" | 20 #include "ui/gfx/codec/png_codec.h" |
| 21 #include "ui/gfx/image/image_skia.h" | 21 #include "ui/gfx/image/image_skia.h" |
| 22 #include "ui/gfx/image/image_util.h" | 22 #include "ui/gfx/image/image_util.h" |
| 23 | 23 |
| 24 namespace favicon { | 24 namespace favicon { |
| 25 namespace { | 25 namespace { |
| 26 | 26 |
| 27 const int kNonTouchLargestIconSize = 192; | 27 #if defined(OS_IOS) |
| 28 | |
| 29 // Size (along each axis) of a touch icon. This currently corresponds to | 28 // Size (along each axis) of a touch icon. This currently corresponds to |
| 30 // the apple touch icon for iPad. | 29 // the apple touch icon for iPad. |
| 31 const int kTouchIconSize = 144; | 30 const int kLargestIconSize = 144; |
| 31 #else | |
| 32 const int kLargestIconSize = 192; | |
| 33 #endif | |
| 32 | 34 |
| 33 // Returns true if all of the icon URLs and icon types in |bitmap_results| are | 35 // Returns true if all of the icon URLs and icon types in |bitmap_results| are |
| 34 // identical and if they match |icon_url| and |icon_type|. Returns false if | 36 // identical and if they match |icon_url| and |icon_type|. Returns false if |
| 35 // |bitmap_results| is empty. | 37 // |bitmap_results| is empty. |
| 36 bool DoUrlsAndIconsMatch( | 38 bool DoUrlsAndIconsMatch( |
| 37 const GURL& icon_url, | 39 const GURL& icon_url, |
| 38 favicon_base::IconType icon_type, | 40 favicon_base::IconType icon_type, |
| 39 const std::vector<favicon_base::FaviconRawBitmapResult>& bitmap_results) { | 41 const std::vector<favicon_base::FaviconRawBitmapResult>& bitmap_results) { |
| 40 if (bitmap_results.empty()) | 42 if (bitmap_results.empty()) |
| 41 return false; | 43 return false; |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 113 FaviconDriverObserver::NotificationIconType handler_type) { | 115 FaviconDriverObserver::NotificationIconType handler_type) { |
| 114 switch (handler_type) { | 116 switch (handler_type) { |
| 115 case FaviconDriverObserver::NON_TOUCH_16_DIP: { | 117 case FaviconDriverObserver::NON_TOUCH_16_DIP: { |
| 116 std::vector<int> pixel_sizes; | 118 std::vector<int> pixel_sizes; |
| 117 for (float scale_factor : favicon_base::GetFaviconScales()) { | 119 for (float scale_factor : favicon_base::GetFaviconScales()) { |
| 118 pixel_sizes.push_back( | 120 pixel_sizes.push_back( |
| 119 static_cast<int>(ceil(scale_factor * gfx::kFaviconSize))); | 121 static_cast<int>(ceil(scale_factor * gfx::kFaviconSize))); |
| 120 } | 122 } |
| 121 return pixel_sizes; | 123 return pixel_sizes; |
| 122 } | 124 } |
| 123 case FaviconDriverObserver::NON_TOUCH_LARGEST: | 125 case FaviconDriverObserver::LARGEST: |
| 124 return std::vector<int>(1U, kNonTouchLargestIconSize); | 126 return std::vector<int>(1U, kLargestIconSize); |
| 125 case FaviconDriverObserver::TOUCH_LARGEST: | |
| 126 return std::vector<int>(1U, kTouchIconSize); | |
| 127 } | 127 } |
| 128 NOTREACHED(); | 128 NOTREACHED(); |
| 129 return std::vector<int>(); | 129 return std::vector<int>(); |
| 130 } | 130 } |
| 131 | 131 |
| 132 } // namespace | 132 } // namespace |
| 133 | 133 |
| 134 //////////////////////////////////////////////////////////////////////////////// | 134 //////////////////////////////////////////////////////////////////////////////// |
| 135 | 135 |
| 136 // static | 136 // static |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 154 | 154 |
| 155 FaviconHandler::FaviconHandler( | 155 FaviconHandler::FaviconHandler( |
| 156 FaviconService* service, | 156 FaviconService* service, |
| 157 Delegate* delegate, | 157 Delegate* delegate, |
| 158 FaviconDriverObserver::NotificationIconType handler_type) | 158 FaviconDriverObserver::NotificationIconType handler_type) |
| 159 : handler_type_(handler_type), | 159 : handler_type_(handler_type), |
| 160 got_favicon_from_history_(false), | 160 got_favicon_from_history_(false), |
| 161 initial_history_result_expired_or_incomplete_(false), | 161 initial_history_result_expired_or_incomplete_(false), |
| 162 redownload_icons_(false), | 162 redownload_icons_(false), |
| 163 icon_types_(FaviconHandler::GetIconTypesFromHandlerType(handler_type)), | 163 icon_types_(FaviconHandler::GetIconTypesFromHandlerType(handler_type)), |
| 164 download_largest_icon_( | 164 download_largest_icon_(handler_type == FaviconDriverObserver::LARGEST), |
| 165 handler_type == FaviconDriverObserver::NON_TOUCH_LARGEST || | |
| 166 handler_type == FaviconDriverObserver::TOUCH_LARGEST), | |
| 167 notification_icon_type_(favicon_base::INVALID_ICON), | 165 notification_icon_type_(favicon_base::INVALID_ICON), |
| 168 service_(service), | 166 service_(service), |
| 169 delegate_(delegate), | 167 delegate_(delegate), |
| 170 current_candidate_index_(0u) { | 168 current_candidate_index_(0u) { |
| 171 DCHECK(delegate_); | 169 DCHECK(delegate_); |
| 172 } | 170 } |
| 173 | 171 |
| 174 FaviconHandler::~FaviconHandler() { | 172 FaviconHandler::~FaviconHandler() { |
| 175 } | 173 } |
| 176 | 174 |
| 177 // static | 175 // static |
| 178 int FaviconHandler::GetIconTypesFromHandlerType( | 176 int FaviconHandler::GetIconTypesFromHandlerType( |
| 179 FaviconDriverObserver::NotificationIconType handler_type) { | 177 FaviconDriverObserver::NotificationIconType handler_type) { |
| 180 switch (handler_type) { | 178 switch (handler_type) { |
| 181 case FaviconDriverObserver::NON_TOUCH_16_DIP: | 179 case FaviconDriverObserver::NON_TOUCH_16_DIP: |
| 182 case FaviconDriverObserver::NON_TOUCH_LARGEST: | |
| 183 return favicon_base::FAVICON; | 180 return favicon_base::FAVICON; |
| 184 case FaviconDriverObserver::TOUCH_LARGEST: | 181 case FaviconDriverObserver::LARGEST: |
| 185 return favicon_base::TOUCH_ICON | favicon_base::TOUCH_PRECOMPOSED_ICON; | 182 return favicon_base::FAVICON | favicon_base::TOUCH_ICON | |
| 183 favicon_base::TOUCH_PRECOMPOSED_ICON; | |
| 186 } | 184 } |
| 187 return 0; | 185 return 0; |
| 188 } | 186 } |
| 189 | 187 |
| 190 void FaviconHandler::FetchFavicon(const GURL& url) { | 188 void FaviconHandler::FetchFavicon(const GURL& url) { |
| 191 cancelable_task_tracker_.TryCancelAll(); | 189 cancelable_task_tracker_.TryCancelAll(); |
| 192 | 190 |
| 193 url_ = url; | 191 url_ = url; |
| 194 | 192 |
| 195 initial_history_result_expired_or_incomplete_ = false; | 193 initial_history_result_expired_or_incomplete_ = false; |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 237 best_favicon_.candidate.score; | 235 best_favicon_.candidate.score; |
| 238 } else { | 236 } else { |
| 239 return best_favicon_.candidate.score == 1; | 237 return best_favicon_.candidate.score == 1; |
| 240 } | 238 } |
| 241 } | 239 } |
| 242 | 240 |
| 243 void FaviconHandler::SetFavicon(const GURL& icon_url, | 241 void FaviconHandler::SetFavicon(const GURL& icon_url, |
| 244 const gfx::Image& image, | 242 const gfx::Image& image, |
| 245 favicon_base::IconType icon_type) { | 243 favicon_base::IconType icon_type) { |
| 246 if (service_ && ShouldSaveFavicon()) | 244 if (service_ && ShouldSaveFavicon()) |
| 247 service_->SetFavicons(url_, icon_url, icon_type, image); | 245 service_->SetFavicons(url_, icon_url, icon_type, image); |
|
pkotwicz
2017/04/04 13:58:10
In a separate CL you will need to update HistoryBa
| |
| 248 | 246 |
| 249 NotifyFaviconUpdated(icon_url, icon_type, image); | 247 NotifyFaviconUpdated(icon_url, icon_type, image); |
| 250 } | 248 } |
| 251 | 249 |
| 252 void FaviconHandler::NotifyFaviconUpdated( | 250 void FaviconHandler::NotifyFaviconUpdated( |
| 253 const std::vector<favicon_base::FaviconRawBitmapResult>& | 251 const std::vector<favicon_base::FaviconRawBitmapResult>& |
| 254 favicon_bitmap_results) { | 252 favicon_bitmap_results) { |
| 255 if (favicon_bitmap_results.empty()) | 253 if (favicon_bitmap_results.empty()) |
| 256 return; | 254 return; |
| 257 | 255 |
| (...skipping 278 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 536 // A max bitmap size is specified to avoid receiving huge bitmaps in | 534 // A max bitmap size is specified to avoid receiving huge bitmaps in |
| 537 // OnDidDownloadFavicon(). See FaviconDriver::StartDownload() | 535 // OnDidDownloadFavicon(). See FaviconDriver::StartDownload() |
| 538 // for more details about the max bitmap size. | 536 // for more details about the max bitmap size. |
| 539 const int download_id = | 537 const int download_id = |
| 540 delegate_->DownloadImage(image_url, GetMaximalIconSize(handler_type_), | 538 delegate_->DownloadImage(image_url, GetMaximalIconSize(handler_type_), |
| 541 download_request_.callback()); | 539 download_request_.callback()); |
| 542 DCHECK_NE(download_id, 0); | 540 DCHECK_NE(download_id, 0); |
| 543 } | 541 } |
| 544 | 542 |
| 545 } // namespace favicon | 543 } // namespace favicon |
| OLD | NEW |