OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/callback.h" | 7 #include "base/callback.h" |
8 #include "base/string_util.h" | 8 #include "base/string_util.h" |
9 #include "base/values.h" | 9 #include "base/values.h" |
10 #include "chrome/browser/profiles/profile.h" | 10 #include "chrome/browser/profiles/profile.h" |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
47 NewCallback(this, &FaviconWebUIHandler::OnFaviconDataAvailable)); | 47 NewCallback(this, &FaviconWebUIHandler::OnFaviconDataAvailable)); |
48 consumer_.SetClientData(favicon_service, handle, static_cast<int>(id)); | 48 consumer_.SetClientData(favicon_service, handle, static_cast<int>(id)); |
49 } | 49 } |
50 | 50 |
51 void FaviconWebUIHandler::OnFaviconDataAvailable( | 51 void FaviconWebUIHandler::OnFaviconDataAvailable( |
52 FaviconService::Handle request_handle, | 52 FaviconService::Handle request_handle, |
53 history::FaviconData favicon) { | 53 history::FaviconData favicon) { |
54 FaviconService* favicon_service = | 54 FaviconService* favicon_service = |
55 Profile::FromWebUI(web_ui_)->GetFaviconService(Profile::EXPLICIT_ACCESS); | 55 Profile::FromWebUI(web_ui_)->GetFaviconService(Profile::EXPLICIT_ACCESS); |
56 int id = consumer_.GetClientData(favicon_service, request_handle); | 56 int id = consumer_.GetClientData(favicon_service, request_handle); |
57 base::FundamentalValue id_value(id); | 57 base::NumberValue id_value(id); |
58 scoped_ptr<StringValue> color_value; | 58 scoped_ptr<StringValue> color_value; |
59 | 59 |
60 if (favicon.is_valid()) { | 60 if (favicon.is_valid()) { |
61 // TODO(estade): cache the response | 61 // TODO(estade): cache the response |
62 color_utils::GridSampler sampler; | 62 color_utils::GridSampler sampler; |
63 SkColor color = | 63 SkColor color = |
64 color_utils::CalculateKMeanColorOfPNG(favicon.image_data, 100, 665, | 64 color_utils::CalculateKMeanColorOfPNG(favicon.image_data, 100, 665, |
65 sampler); | 65 sampler); |
66 std::string css_color = base::StringPrintf("rgb(%d, %d, %d)", | 66 std::string css_color = base::StringPrintf("rgb(%d, %d, %d)", |
67 SkColorGetR(color), | 67 SkColorGetR(color), |
68 SkColorGetG(color), | 68 SkColorGetG(color), |
69 SkColorGetB(color)); | 69 SkColorGetB(color)); |
70 color_value.reset(new StringValue(css_color)); | 70 color_value.reset(base::StringValue::New(css_color)); |
71 } else { | 71 } else { |
72 color_value.reset(new StringValue("#919191")); | 72 color_value.reset(base::StringValue::New("#919191")); |
73 } | 73 } |
74 | 74 |
75 web_ui_->CallJavascriptFunction("ntp4.setFaviconDominantColor", | 75 web_ui_->CallJavascriptFunction("ntp4.setFaviconDominantColor", |
76 id_value, *color_value); | 76 id_value, *color_value); |
77 } | 77 } |
OLD | NEW |