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 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
98 void Init() { | 98 void Init() { |
99 if (extension_) { | 99 if (extension_) { |
100 ExtensionResource icon_resource = | 100 ExtensionResource icon_resource = |
101 extension_->GetIconResource(extension_misc::EXTENSION_ICON_BITTY, | 101 extension_->GetIconResource(extension_misc::EXTENSION_ICON_BITTY, |
102 ExtensionIconSet::MATCH_EXACTLY); | 102 ExtensionIconSet::MATCH_EXACTLY); |
103 | 103 |
104 tracker_.LoadImage(extension_, icon_resource, | 104 tracker_.LoadImage(extension_, icon_resource, |
105 gfx::Size(gfx::kFaviconSize, gfx::kFaviconSize), | 105 gfx::Size(gfx::kFaviconSize, gfx::kFaviconSize), |
106 ImageLoadingTracker::DONT_CACHE); | 106 ImageLoadingTracker::DONT_CACHE); |
107 } else { | 107 } else { |
108 ForwardResult(NULL); | 108 ForwardResult(gfx::Image()); |
109 } | 109 } |
110 } | 110 } |
111 | 111 |
112 virtual void OnImageLoaded(const gfx::Image& image, | 112 virtual void OnImageLoaded(const gfx::Image& image, |
113 const std::string& extension_id, | 113 const std::string& extension_id, |
114 int index) OVERRIDE { | 114 int index) OVERRIDE { |
115 if (!image.IsEmpty()) { | 115 ForwardResult(image); |
116 std::vector<unsigned char> image_data; | |
117 if (!gfx::PNGCodec::EncodeBGRASkBitmap(*image.ToSkBitmap(), false, | |
118 &image_data)) { | |
119 NOTREACHED() << "Could not encode extension favicon"; | |
120 } | |
121 ForwardResult(base::RefCountedBytes::TakeVector(&image_data)); | |
122 } else { | |
123 ForwardResult(NULL); | |
124 } | |
125 } | 116 } |
126 | 117 |
127 private: | 118 private: |
128 ~ExtensionWebUIImageLoadingTracker() {} | 119 ~ExtensionWebUIImageLoadingTracker() {} |
129 | 120 |
130 // Forwards the result on the request. If no favicon was available then | 121 // Forwards the result of the request. If no favicon was available then |
131 // |icon_data| may be backed by NULL. Once the result has been forwarded the | 122 // |icon| will be empty. Once the result has been forwarded the instance is |
132 // instance is deleted. | 123 // deleted. |
133 void ForwardResult(scoped_refptr<base::RefCountedMemory> icon_data) { | 124 void ForwardResult(const gfx::Image& icon) { |
134 history::FaviconData favicon; | 125 std::vector<history::FaviconBitmapResult> favicon_bitmap_results; |
135 favicon.known_icon = icon_data.get() != NULL && icon_data->size() > 0; | 126 SkBitmap icon_bitmap = icon.AsBitmap(); |
136 favicon.image_data = icon_data; | 127 if (!icon_bitmap.empty()) { |
137 favicon.icon_type = history::FAVICON; | 128 scoped_refptr<base::RefCountedBytes> icon_data( |
138 request_->ForwardResultAsync(request_->handle(), favicon); | 129 new base::RefCountedBytes()); |
| 130 if (gfx::PNGCodec::EncodeBGRASkBitmap(icon_bitmap, false, |
| 131 &icon_data->data())) { |
| 132 history::FaviconBitmapResult bitmap_result; |
| 133 bitmap_result.bitmap_data = icon_data; |
| 134 bitmap_result.pixel_size = gfx::Size(icon_bitmap.width(), |
| 135 icon_bitmap.height()); |
| 136 bitmap_result.icon_type = history::FAVICON; |
| 137 |
| 138 favicon_bitmap_results.push_back(bitmap_result); |
| 139 } else { |
| 140 NOTREACHED() << "Could not encode extension favicon"; |
| 141 } |
| 142 } |
| 143 |
| 144 request_->ForwardResultAsync(request_->handle(), favicon_bitmap_results, |
| 145 history::IconURLSizesMap()); |
139 delete this; | 146 delete this; |
140 } | 147 } |
141 | 148 |
142 ImageLoadingTracker tracker_; | 149 ImageLoadingTracker tracker_; |
143 scoped_refptr<FaviconService::GetFaviconRequest> request_; | 150 scoped_refptr<FaviconService::GetFaviconRequest> request_; |
144 const Extension* extension_; | 151 const Extension* extension_; |
145 | 152 |
146 DISALLOW_COPY_AND_ASSIGN(ExtensionWebUIImageLoadingTracker); | 153 DISALLOW_COPY_AND_ASSIGN(ExtensionWebUIImageLoadingTracker); |
147 }; | 154 }; |
148 | 155 |
(...skipping 273 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
422 } | 429 } |
423 | 430 |
424 // static | 431 // static |
425 void ExtensionWebUI::GetFaviconForURL(Profile* profile, | 432 void ExtensionWebUI::GetFaviconForURL(Profile* profile, |
426 FaviconService::GetFaviconRequest* request, const GURL& page_url) { | 433 FaviconService::GetFaviconRequest* request, const GURL& page_url) { |
427 // tracker deletes itself when done. | 434 // tracker deletes itself when done. |
428 ExtensionWebUIImageLoadingTracker* tracker = | 435 ExtensionWebUIImageLoadingTracker* tracker = |
429 new ExtensionWebUIImageLoadingTracker(profile, request, page_url); | 436 new ExtensionWebUIImageLoadingTracker(profile, request, page_url); |
430 tracker->Init(); | 437 tracker->Init(); |
431 } | 438 } |
OLD | NEW |