| 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 15 matching lines...) Expand all Loading... |
| 26 namespace { | 26 namespace { |
| 27 | 27 |
| 28 StringValue* SkColorToCss(SkColor color) { | 28 StringValue* SkColorToCss(SkColor color) { |
| 29 return new StringValue(base::StringPrintf("rgb(%d, %d, %d)", | 29 return new StringValue(base::StringPrintf("rgb(%d, %d, %d)", |
| 30 SkColorGetR(color), | 30 SkColorGetR(color), |
| 31 SkColorGetG(color), | 31 SkColorGetG(color), |
| 32 SkColorGetB(color))); | 32 SkColorGetB(color))); |
| 33 } | 33 } |
| 34 | 34 |
| 35 base::StringValue* GetDominantColorCssString( | 35 base::StringValue* GetDominantColorCssString( |
| 36 scoped_refptr<RefCountedMemory> png) { | 36 scoped_refptr<base::RefCountedMemory> png) { |
| 37 color_utils::GridSampler sampler; | 37 color_utils::GridSampler sampler; |
| 38 SkColor color = color_utils::CalculateKMeanColorOfPNG(png, 100, 665, sampler); | 38 SkColor color = color_utils::CalculateKMeanColorOfPNG(png, 100, 665, sampler); |
| 39 return SkColorToCss(color); | 39 return SkColorToCss(color); |
| 40 } | 40 } |
| 41 | 41 |
| 42 } // namespace | 42 } // namespace |
| 43 | 43 |
| 44 // Thin inheritance-dependent trampoline to forward notification of app | 44 // Thin inheritance-dependent trampoline to forward notification of app |
| 45 // icon loads to the FaviconWebUIHandler. Base class does caching of icons. | 45 // icon loads to the FaviconWebUIHandler. Base class does caching of icons. |
| 46 class ExtensionIconColorManager : public ExtensionIconManager { | 46 class ExtensionIconColorManager : public ExtensionIconManager { |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 155 std::vector<unsigned char> bits; | 155 std::vector<unsigned char> bits; |
| 156 if (!gfx::PNGCodec::EncodeBGRASkBitmap(bitmap, true, &bits)) | 156 if (!gfx::PNGCodec::EncodeBGRASkBitmap(bitmap, true, &bits)) |
| 157 return; | 157 return; |
| 158 scoped_refptr<base::RefCountedStaticMemory> bits_mem( | 158 scoped_refptr<base::RefCountedStaticMemory> bits_mem( |
| 159 new base::RefCountedStaticMemory(&bits.front(), bits.size())); | 159 new base::RefCountedStaticMemory(&bits.front(), bits.size())); |
| 160 scoped_ptr<StringValue> color_value(GetDominantColorCssString(bits_mem)); | 160 scoped_ptr<StringValue> color_value(GetDominantColorCssString(bits_mem)); |
| 161 StringValue id(extension_id); | 161 StringValue id(extension_id); |
| 162 web_ui()->CallJavascriptFunction( | 162 web_ui()->CallJavascriptFunction( |
| 163 "ntp.setStripeColor", id, *color_value); | 163 "ntp.setStripeColor", id, *color_value); |
| 164 } | 164 } |
| OLD | NEW |