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/string_split.h" | 9 #include "base/string_split.h" |
10 #include "base/string_util.h" | 10 #include "base/string_util.h" |
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
118 } | 118 } |
119 | 119 |
120 void FaviconWebUIHandler::OnFaviconDataAvailable( | 120 void FaviconWebUIHandler::OnFaviconDataAvailable( |
121 FaviconService::Handle request_handle, | 121 FaviconService::Handle request_handle, |
122 history::FaviconData favicon) { | 122 history::FaviconData favicon) { |
123 FaviconService* favicon_service = | 123 FaviconService* favicon_service = |
124 Profile::FromWebUI(web_ui())->GetFaviconService(Profile::EXPLICIT_ACCESS); | 124 Profile::FromWebUI(web_ui())->GetFaviconService(Profile::EXPLICIT_ACCESS); |
125 int id = consumer_.GetClientData(favicon_service, request_handle); | 125 int id = consumer_.GetClientData(favicon_service, request_handle); |
126 scoped_ptr<StringValue> color_value; | 126 scoped_ptr<StringValue> color_value; |
127 | 127 |
128 if (favicon.is_valid()) | 128 if (favicon.is_valid() && favicon.variants.size() > 0) { |
129 color_value.reset(GetDominantColorCssString(favicon.bitmap_data)); | 129 color_value.reset( |
130 else | 130 GetDominantColorCssString(favicon.variants[0].bitmap_data)); |
| 131 } else { |
131 color_value.reset(new StringValue("#919191")); | 132 color_value.reset(new StringValue("#919191")); |
| 133 } |
132 | 134 |
133 StringValue dom_id(dom_id_map_[id]); | 135 StringValue dom_id(dom_id_map_[id]); |
134 web_ui()->CallJavascriptFunction("ntp.setStripeColor", dom_id, *color_value); | 136 web_ui()->CallJavascriptFunction("ntp.setStripeColor", dom_id, *color_value); |
135 dom_id_map_.erase(id); | 137 dom_id_map_.erase(id); |
136 } | 138 } |
137 | 139 |
138 void FaviconWebUIHandler::HandleGetAppIconDominantColor( | 140 void FaviconWebUIHandler::HandleGetAppIconDominantColor( |
139 const ListValue* args) { | 141 const ListValue* args) { |
140 std::string extension_id; | 142 std::string extension_id; |
141 CHECK(args->GetString(0, &extension_id)); | 143 CHECK(args->GetString(0, &extension_id)); |
(...skipping 13 matching lines...) Expand all Loading... |
155 std::vector<unsigned char> bits; | 157 std::vector<unsigned char> bits; |
156 if (!gfx::PNGCodec::EncodeBGRASkBitmap(bitmap, true, &bits)) | 158 if (!gfx::PNGCodec::EncodeBGRASkBitmap(bitmap, true, &bits)) |
157 return; | 159 return; |
158 scoped_refptr<base::RefCountedStaticMemory> bits_mem( | 160 scoped_refptr<base::RefCountedStaticMemory> bits_mem( |
159 new base::RefCountedStaticMemory(&bits.front(), bits.size())); | 161 new base::RefCountedStaticMemory(&bits.front(), bits.size())); |
160 scoped_ptr<StringValue> color_value(GetDominantColorCssString(bits_mem)); | 162 scoped_ptr<StringValue> color_value(GetDominantColorCssString(bits_mem)); |
161 StringValue id(extension_id); | 163 StringValue id(extension_id); |
162 web_ui()->CallJavascriptFunction( | 164 web_ui()->CallJavascriptFunction( |
163 "ntp.setStripeColor", id, *color_value); | 165 "ntp.setStripeColor", id, *color_value); |
164 } | 166 } |
OLD | NEW |