| 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/extensions/extension_web_ui.h" | 5 #include "chrome/browser/extensions/extension_web_ui.h" |
| 6 | 6 |
| 7 #include <set> | 7 #include <set> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 116 } | 116 } |
| 117 | 117 |
| 118 private: | 118 private: |
| 119 ~ExtensionWebUIImageLoadingTracker() {} | 119 ~ExtensionWebUIImageLoadingTracker() {} |
| 120 | 120 |
| 121 // Forwards the result of the request. If no favicon was available then | 121 // Forwards the result of the request. If no favicon was available then |
| 122 // |icon| will be empty. Once the result has been forwarded the instance is | 122 // |icon| will be empty. Once the result has been forwarded the instance is |
| 123 // deleted. | 123 // deleted. |
| 124 void ForwardResult(const gfx::Image& icon) { | 124 void ForwardResult(const gfx::Image& icon) { |
| 125 std::vector<history::FaviconBitmapResult> favicon_bitmap_results; | 125 std::vector<history::FaviconBitmapResult> favicon_bitmap_results; |
| 126 history::IconURLSizesMap icon_url_sizes; |
| 126 SkBitmap icon_bitmap = icon.AsBitmap(); | 127 SkBitmap icon_bitmap = icon.AsBitmap(); |
| 127 if (!icon_bitmap.empty()) { | 128 if (!icon_bitmap.empty()) { |
| 128 scoped_refptr<base::RefCountedBytes> icon_data( | 129 scoped_refptr<base::RefCountedBytes> icon_data( |
| 129 new base::RefCountedBytes()); | 130 new base::RefCountedBytes()); |
| 130 if (gfx::PNGCodec::EncodeBGRASkBitmap(icon_bitmap, false, | 131 if (gfx::PNGCodec::EncodeBGRASkBitmap(icon_bitmap, false, |
| 131 &icon_data->data())) { | 132 &icon_data->data())) { |
| 132 history::FaviconBitmapResult bitmap_result; | 133 history::FaviconBitmapResult bitmap_result; |
| 133 bitmap_result.bitmap_data = icon_data; | 134 bitmap_result.bitmap_data = icon_data; |
| 134 bitmap_result.pixel_size = gfx::Size(icon_bitmap.width(), | 135 bitmap_result.pixel_size = gfx::Size(icon_bitmap.width(), |
| 135 icon_bitmap.height()); | 136 icon_bitmap.height()); |
| 137 // Leave |bitmap_result|'s icon URL as the default of GURL(). |
| 136 bitmap_result.icon_type = history::FAVICON; | 138 bitmap_result.icon_type = history::FAVICON; |
| 137 | 139 |
| 138 favicon_bitmap_results.push_back(bitmap_result); | 140 favicon_bitmap_results.push_back(bitmap_result); |
| 141 |
| 142 // Build IconURLSizesMap such that the requirement that all the icon |
| 143 // URLs in |favicon_bitmap_results| be present in |icon_url_sizes| |
| 144 // holds. Set the favicon sizes to the pixel size of |icon_bitmap|. |
| 145 icon_url_sizes[GURL()].push_back(bitmap_result.pixel_size); |
| 139 } else { | 146 } else { |
| 140 NOTREACHED() << "Could not encode extension favicon"; | 147 NOTREACHED() << "Could not encode extension favicon"; |
| 141 } | 148 } |
| 142 } | 149 } |
| 143 | 150 |
| 144 request_->ForwardResultAsync(request_->handle(), favicon_bitmap_results, | 151 request_->ForwardResultAsync(request_->handle(), favicon_bitmap_results, |
| 145 history::IconURLSizesMap()); | 152 icon_url_sizes); |
| 146 delete this; | 153 delete this; |
| 147 } | 154 } |
| 148 | 155 |
| 149 ImageLoadingTracker tracker_; | 156 ImageLoadingTracker tracker_; |
| 150 scoped_refptr<FaviconService::GetFaviconRequest> request_; | 157 scoped_refptr<FaviconService::GetFaviconRequest> request_; |
| 151 const Extension* extension_; | 158 const Extension* extension_; |
| 152 | 159 |
| 153 DISALLOW_COPY_AND_ASSIGN(ExtensionWebUIImageLoadingTracker); | 160 DISALLOW_COPY_AND_ASSIGN(ExtensionWebUIImageLoadingTracker); |
| 154 }; | 161 }; |
| 155 | 162 |
| (...skipping 273 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 429 } | 436 } |
| 430 | 437 |
| 431 // static | 438 // static |
| 432 void ExtensionWebUI::GetFaviconForURL(Profile* profile, | 439 void ExtensionWebUI::GetFaviconForURL(Profile* profile, |
| 433 FaviconService::GetFaviconRequest* request, const GURL& page_url) { | 440 FaviconService::GetFaviconRequest* request, const GURL& page_url) { |
| 434 // tracker deletes itself when done. | 441 // tracker deletes itself when done. |
| 435 ExtensionWebUIImageLoadingTracker* tracker = | 442 ExtensionWebUIImageLoadingTracker* tracker = |
| 436 new ExtensionWebUIImageLoadingTracker(profile, request, page_url); | 443 new ExtensionWebUIImageLoadingTracker(profile, request, page_url); |
| 437 tracker->Init(); | 444 tracker->Init(); |
| 438 } | 445 } |
| OLD | NEW |