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/stringprintf.h" | 9 #include "base/stringprintf.h" |
10 #include "base/values.h" | 10 #include "base/values.h" |
(...skipping 11 matching lines...) Expand all Loading... |
22 } | 22 } |
23 | 23 |
24 void FaviconWebUIHandler::RegisterMessages() { | 24 void FaviconWebUIHandler::RegisterMessages() { |
25 web_ui_->RegisterMessageCallback("getFaviconDominantColor", | 25 web_ui_->RegisterMessageCallback("getFaviconDominantColor", |
26 NewCallback(this, &FaviconWebUIHandler::HandleGetFaviconDominantColor)); | 26 NewCallback(this, &FaviconWebUIHandler::HandleGetFaviconDominantColor)); |
27 } | 27 } |
28 | 28 |
29 void FaviconWebUIHandler::HandleGetFaviconDominantColor(const ListValue* args) { | 29 void FaviconWebUIHandler::HandleGetFaviconDominantColor(const ListValue* args) { |
30 std::string path; | 30 std::string path; |
31 CHECK(args->GetString(0, &path)); | 31 CHECK(args->GetString(0, &path)); |
32 DCHECK(StartsWithASCII(path, "chrome://favicon/size/32/", false)) << | 32 DCHECK(StartsWithASCII(path, "chrome://favicon/size/16/", false)) << |
33 "path is " << path; | 33 "path is " << path; |
34 path = path.substr(arraysize("chrome://favicon/size/32/") - 1); | 34 path = path.substr(arraysize("chrome://favicon/size/16/") - 1); |
35 | 35 |
36 double id; | 36 double id; |
37 CHECK(args->GetDouble(1, &id)); | 37 CHECK(args->GetDouble(1, &id)); |
38 | 38 |
39 std::string callback_name; | 39 std::string callback_name; |
40 CHECK(args->GetString(2, &callback_name)); | 40 CHECK(args->GetString(2, &callback_name)); |
41 callbacks_map_[static_cast<int>(id)] = callback_name; | 41 callbacks_map_[static_cast<int>(id)] = callback_name; |
42 | 42 |
43 FaviconService* favicon_service = | 43 FaviconService* favicon_service = |
44 Profile::FromWebUI(web_ui_)->GetFaviconService(Profile::EXPLICIT_ACCESS); | 44 Profile::FromWebUI(web_ui_)->GetFaviconService(Profile::EXPLICIT_ACCESS); |
(...skipping 28 matching lines...) Expand all Loading... |
73 SkColorGetG(color), | 73 SkColorGetG(color), |
74 SkColorGetB(color)); | 74 SkColorGetB(color)); |
75 color_value.reset(new StringValue(css_color)); | 75 color_value.reset(new StringValue(css_color)); |
76 } else { | 76 } else { |
77 color_value.reset(new StringValue("#919191")); | 77 color_value.reset(new StringValue("#919191")); |
78 } | 78 } |
79 | 79 |
80 web_ui_->CallJavascriptFunction(callbacks_map_[id], id_value, *color_value); | 80 web_ui_->CallJavascriptFunction(callbacks_map_[id], id_value, *color_value); |
81 callbacks_map_.erase(id); | 81 callbacks_map_.erase(id); |
82 } | 82 } |
OLD | NEW |