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/ui/ash/launcher/launcher_favicon_loader.h" | 5 #include "chrome/browser/ui/ash/launcher/launcher_favicon_loader.h" |
6 | 6 |
7 #include "ash/shelf/shelf_constants.h" | 7 #include "ash/shelf/shelf_constants.h" |
8 #include "base/bind.h" | 8 #include "base/bind.h" |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/macros.h" | 10 #include "base/macros.h" |
11 #include "base/memory/weak_ptr.h" | 11 #include "base/memory/weak_ptr.h" |
12 #include "content/public/browser/render_view_host.h" | 12 #include "content/public/browser/render_view_host.h" |
13 #include "content/public/browser/web_contents.h" | 13 #include "content/public/browser/web_contents.h" |
14 #include "content/public/browser/web_contents_observer.h" | 14 #include "content/public/browser/web_contents_observer.h" |
15 #include "third_party/skia/include/core/SkBitmap.h" | 15 #include "third_party/skia/include/core/SkBitmap.h" |
16 #include "url/gurl.h" | 16 #include "url/gurl.h" |
17 | 17 |
18 namespace internal { | 18 namespace internal { |
19 | 19 |
20 const int kMaxBitmapSize = 256; | 20 const int kMaxBitmapSize = 256; |
21 | 21 |
22 //////////////////////////////////////////////////////////////////////////////// | 22 //////////////////////////////////////////////////////////////////////////////// |
23 // FaviconRawBitmapHandler fetchs all bitmaps with the 'icon' (or 'shortcut | 23 // FaviconRawBitmapHandler fetchs all bitmaps with the 'icon' (or 'shortcut |
24 // icon') link tag, storing the one that best matches ash::SHELF_SIZE. These | 24 // icon') link tag, storing the one that best matches ash::kShelfSize. These |
25 // icon bitmaps are not resized and are not cached beyond the lifetime of the | 25 // icon bitmaps are not resized and are not cached beyond the lifetime of the |
26 // class. Bitmaps larger than kMaxBitmapSize are ignored. | 26 // class. Bitmaps larger than kMaxBitmapSize are ignored. |
27 | 27 |
28 class FaviconRawBitmapHandler : public content::WebContentsObserver { | 28 class FaviconRawBitmapHandler : public content::WebContentsObserver { |
29 public: | 29 public: |
30 FaviconRawBitmapHandler(content::WebContents* web_contents, | 30 FaviconRawBitmapHandler(content::WebContents* web_contents, |
31 LauncherFaviconLoader::Delegate* delegate) | 31 LauncherFaviconLoader::Delegate* delegate) |
32 : content::WebContentsObserver(web_contents), | 32 : content::WebContentsObserver(web_contents), |
33 delegate_(delegate), | 33 delegate_(delegate), |
34 weak_ptr_factory_(this) {} | 34 weak_ptr_factory_(this) {} |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
137 if (!bitmaps.empty()) | 137 if (!bitmaps.empty()) |
138 AddFavicon(image_url, bitmaps[0]); | 138 AddFavicon(image_url, bitmaps[0]); |
139 } | 139 } |
140 | 140 |
141 void FaviconRawBitmapHandler::AddFavicon(const GURL& image_url, | 141 void FaviconRawBitmapHandler::AddFavicon(const GURL& image_url, |
142 const SkBitmap& new_bitmap) { | 142 const SkBitmap& new_bitmap) { |
143 processed_requests_.insert(image_url); | 143 processed_requests_.insert(image_url); |
144 if (new_bitmap.height() > kMaxBitmapSize || | 144 if (new_bitmap.height() > kMaxBitmapSize || |
145 new_bitmap.width() > kMaxBitmapSize) | 145 new_bitmap.width() > kMaxBitmapSize) |
146 return; | 146 return; |
147 if (new_bitmap.height() < ash::GetShelfConstant(ash::SHELF_SIZE)) | 147 if (new_bitmap.height() < ash::kShelfSize) |
148 return; | 148 return; |
149 if (!bitmap_.isNull()) { | 149 if (!bitmap_.isNull()) { |
150 // We want the smallest icon that is large enough. | 150 // We want the smallest icon that is large enough. |
151 if (new_bitmap.height() > bitmap_.height()) | 151 if (new_bitmap.height() > bitmap_.height()) |
152 return; | 152 return; |
153 } | 153 } |
154 bitmap_url_ = image_url; | 154 bitmap_url_ = image_url; |
155 bitmap_ = new_bitmap; | 155 bitmap_ = new_bitmap; |
156 delegate_->FaviconUpdated(); | 156 delegate_->FaviconUpdated(); |
157 } | 157 } |
(...skipping 12 matching lines...) Expand all Loading... |
170 LauncherFaviconLoader::~LauncherFaviconLoader() { | 170 LauncherFaviconLoader::~LauncherFaviconLoader() { |
171 } | 171 } |
172 | 172 |
173 SkBitmap LauncherFaviconLoader::GetFavicon() const { | 173 SkBitmap LauncherFaviconLoader::GetFavicon() const { |
174 return favicon_handler_->bitmap(); | 174 return favicon_handler_->bitmap(); |
175 } | 175 } |
176 | 176 |
177 bool LauncherFaviconLoader::HasPendingDownloads() const { | 177 bool LauncherFaviconLoader::HasPendingDownloads() const { |
178 return favicon_handler_->HasPendingDownloads(); | 178 return favicon_handler_->HasPendingDownloads(); |
179 } | 179 } |
OLD | NEW |