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 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
80 content::PAGE_TRANSITION_RELOAD, std::string()); | 80 content::PAGE_TRANSITION_RELOAD, std::string()); |
81 } | 81 } |
82 | 82 |
83 // Run favicon callbck with image result. If no favicon was available then | 83 // Run favicon callbck with image result. If no favicon was available then |
84 // |image| will be empty. | 84 // |image| will be empty. |
85 void RunFaviconCallbackAsync( | 85 void RunFaviconCallbackAsync( |
86 const FaviconService::FaviconResultsCallback& callback, | 86 const FaviconService::FaviconResultsCallback& callback, |
87 const gfx::Image& image) { | 87 const gfx::Image& image) { |
88 std::vector<history::FaviconBitmapResult>* favicon_bitmap_results = | 88 std::vector<history::FaviconBitmapResult>* favicon_bitmap_results = |
89 new std::vector<history::FaviconBitmapResult>(); | 89 new std::vector<history::FaviconBitmapResult>(); |
90 history::IconURLSizesMap* icon_url_sizes = new history::IconURLSizesMap(); | |
91 | 90 |
92 const std::vector<gfx::ImageSkiaRep>& image_reps = | 91 const std::vector<gfx::ImageSkiaRep>& image_reps = |
93 image.AsImageSkia().image_reps(); | 92 image.AsImageSkia().image_reps(); |
94 for (size_t i = 0; i < image_reps.size(); ++i) { | 93 for (size_t i = 0; i < image_reps.size(); ++i) { |
95 const gfx::ImageSkiaRep& image_rep = image_reps[i]; | 94 const gfx::ImageSkiaRep& image_rep = image_reps[i]; |
96 scoped_refptr<base::RefCountedBytes> bitmap_data( | 95 scoped_refptr<base::RefCountedBytes> bitmap_data( |
97 new base::RefCountedBytes()); | 96 new base::RefCountedBytes()); |
98 if (gfx::PNGCodec::EncodeBGRASkBitmap(image_rep.sk_bitmap(), | 97 if (gfx::PNGCodec::EncodeBGRASkBitmap(image_rep.sk_bitmap(), |
99 false, | 98 false, |
100 &bitmap_data->data())) { | 99 &bitmap_data->data())) { |
101 history::FaviconBitmapResult bitmap_result; | 100 history::FaviconBitmapResult bitmap_result; |
102 bitmap_result.bitmap_data = bitmap_data; | 101 bitmap_result.bitmap_data = bitmap_data; |
103 bitmap_result.pixel_size = gfx::Size(image_rep.pixel_width(), | 102 bitmap_result.pixel_size = gfx::Size(image_rep.pixel_width(), |
104 image_rep.pixel_height()); | 103 image_rep.pixel_height()); |
105 // Leave |bitmap_result|'s icon URL as the default of GURL(). | 104 // Leave |bitmap_result|'s icon URL as the default of GURL(). |
106 bitmap_result.icon_type = history::FAVICON; | 105 bitmap_result.icon_type = history::FAVICON; |
107 | 106 |
108 favicon_bitmap_results->push_back(bitmap_result); | 107 favicon_bitmap_results->push_back(bitmap_result); |
109 } else { | 108 } else { |
110 NOTREACHED() << "Could not encode extension favicon"; | 109 NOTREACHED() << "Could not encode extension favicon"; |
111 } | 110 } |
112 } | 111 } |
113 | 112 |
114 // Populate IconURLSizesMap such that all the icon URLs in | |
115 // |favicon_bitmap_results| are present in |icon_url_sizes|. | |
116 // Populate the favicon sizes with the relevant pixel sizes in the | |
117 // extension's icon set. | |
118 for (size_t i = 0; i < favicon_bitmap_results->size(); ++i) { | |
119 const history::FaviconBitmapResult& bitmap_result = | |
120 (*favicon_bitmap_results)[i]; | |
121 const GURL& icon_url = bitmap_result.icon_url; | |
122 (*icon_url_sizes)[icon_url].push_back(bitmap_result.pixel_size); | |
123 } | |
124 | |
125 base::MessageLoopProxy::current()->PostTask( | 113 base::MessageLoopProxy::current()->PostTask( |
126 FROM_HERE, | 114 FROM_HERE, |
127 base::Bind(&FaviconService::FaviconResultsCallbackRunner, | 115 base::Bind(&FaviconService::FaviconResultsCallbackRunner, |
128 callback, | 116 callback, |
129 base::Owned(favicon_bitmap_results), | 117 base::Owned(favicon_bitmap_results))); |
130 base::Owned(icon_url_sizes))); | |
131 } | 118 } |
132 | 119 |
133 } // namespace | 120 } // namespace |
134 | 121 |
135 const char ExtensionWebUI::kExtensionURLOverrides[] = | 122 const char ExtensionWebUI::kExtensionURLOverrides[] = |
136 "extensions.chrome_url_overrides"; | 123 "extensions.chrome_url_overrides"; |
137 | 124 |
138 ExtensionWebUI::ExtensionWebUI(content::WebUI* web_ui, const GURL& url) | 125 ExtensionWebUI::ExtensionWebUI(content::WebUI* web_ui, const GURL& url) |
139 : WebUIController(web_ui), | 126 : WebUIController(web_ui), |
140 url_(url) { | 127 url_(url) { |
(...skipping 302 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
443 extensions::ImageLoader::ImageRepresentation::ALWAYS_RESIZE, | 430 extensions::ImageLoader::ImageRepresentation::ALWAYS_RESIZE, |
444 gfx::Size(pixel_size, pixel_size), | 431 gfx::Size(pixel_size, pixel_size), |
445 scale_factors[i])); | 432 scale_factors[i])); |
446 } | 433 } |
447 | 434 |
448 // LoadImagesAsync actually can run callback synchronously. We want to force | 435 // LoadImagesAsync actually can run callback synchronously. We want to force |
449 // async. | 436 // async. |
450 extensions::ImageLoader::Get(profile)->LoadImagesAsync( | 437 extensions::ImageLoader::Get(profile)->LoadImagesAsync( |
451 extension, info_list, base::Bind(&RunFaviconCallbackAsync, callback)); | 438 extension, info_list, base::Bind(&RunFaviconCallbackAsync, callback)); |
452 } | 439 } |
OLD | NEW |