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