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/webui/ntp/favicon_webui_handler.h" | 5 #include "chrome/browser/ui/webui/ntp/favicon_webui_handler.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
9 #include "base/strings/string_split.h" | 9 #include "base/strings/string_split.h" |
10 #include "base/strings/string_util.h" | 10 #include "base/strings/string_util.h" |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
104 base::StringValue dom_id_value(dom_id); | 104 base::StringValue dom_id_value(dom_id); |
105 scoped_ptr<base::StringValue> color( | 105 scoped_ptr<base::StringValue> color( |
106 SkColorToCss(history::kPrepopulatedPages[i].color)); | 106 SkColorToCss(history::kPrepopulatedPages[i].color)); |
107 web_ui()->CallJavascriptFunction("ntp.setFaviconDominantColor", | 107 web_ui()->CallJavascriptFunction("ntp.setFaviconDominantColor", |
108 dom_id_value, *color); | 108 dom_id_value, *color); |
109 return; | 109 return; |
110 } | 110 } |
111 } | 111 } |
112 | 112 |
113 dom_id_map_[id_] = dom_id; | 113 dom_id_map_[id_] = dom_id; |
114 favicon_service->GetRawFaviconForURL( | 114 favicon_service->GetRawFaviconForPageURL( |
115 FaviconService::FaviconForURLParams( | 115 FaviconService::FaviconForPageURLParams( |
116 url, favicon_base::FAVICON, gfx::kFaviconSize), | 116 url, favicon_base::FAVICON, gfx::kFaviconSize), |
117 ui::SCALE_FACTOR_100P, | 117 ui::SCALE_FACTOR_100P, |
118 base::Bind(&FaviconWebUIHandler::OnFaviconDataAvailable, | 118 base::Bind(&FaviconWebUIHandler::OnFaviconDataAvailable, |
119 base::Unretained(this), | 119 base::Unretained(this), |
120 id_++), | 120 id_++), |
121 &cancelable_task_tracker_); | 121 &cancelable_task_tracker_); |
122 } | 122 } |
123 | 123 |
124 void FaviconWebUIHandler::OnFaviconDataAvailable( | 124 void FaviconWebUIHandler::OnFaviconDataAvailable( |
125 int id, | 125 int id, |
126 const favicon_base::FaviconBitmapResult& bitmap_result) { | 126 const favicon_base::FaviconRawBitmapResult& bitmap_result) { |
127 scoped_ptr<base::StringValue> color_value; | 127 scoped_ptr<base::StringValue> color_value; |
128 | 128 |
129 if (bitmap_result.is_valid()) | 129 if (bitmap_result.is_valid()) |
130 color_value.reset(GetDominantColorCssString(bitmap_result.bitmap_data)); | 130 color_value.reset(GetDominantColorCssString(bitmap_result.bitmap_data)); |
131 else | 131 else |
132 color_value.reset(new base::StringValue("#919191")); | 132 color_value.reset(new base::StringValue("#919191")); |
133 | 133 |
134 base::StringValue dom_id(dom_id_map_[id]); | 134 base::StringValue dom_id(dom_id_map_[id]); |
135 web_ui()->CallJavascriptFunction("ntp.setFaviconDominantColor", | 135 web_ui()->CallJavascriptFunction("ntp.setFaviconDominantColor", |
136 dom_id, *color_value); | 136 dom_id, *color_value); |
(...skipping 21 matching lines...) Expand all Loading... |
158 if (!gfx::PNGCodec::EncodeBGRASkBitmap(bitmap, true, &bits)) | 158 if (!gfx::PNGCodec::EncodeBGRASkBitmap(bitmap, true, &bits)) |
159 return; | 159 return; |
160 scoped_refptr<base::RefCountedStaticMemory> bits_mem( | 160 scoped_refptr<base::RefCountedStaticMemory> bits_mem( |
161 new base::RefCountedStaticMemory(&bits.front(), bits.size())); | 161 new base::RefCountedStaticMemory(&bits.front(), bits.size())); |
162 scoped_ptr<base::StringValue> color_value( | 162 scoped_ptr<base::StringValue> color_value( |
163 GetDominantColorCssString(bits_mem)); | 163 GetDominantColorCssString(bits_mem)); |
164 base::StringValue id(extension_id); | 164 base::StringValue id(extension_id); |
165 web_ui()->CallJavascriptFunction( | 165 web_ui()->CallJavascriptFunction( |
166 "ntp.setFaviconDominantColor", id, *color_value); | 166 "ntp.setFaviconDominantColor", id, *color_value); |
167 } | 167 } |
OLD | NEW |