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 17 matching lines...) Expand all Loading... |
28 void FaviconWebUIHandler::HandleGetFaviconDominantColor(const ListValue* args) { | 28 void FaviconWebUIHandler::HandleGetFaviconDominantColor(const ListValue* args) { |
29 std::string path; | 29 std::string path; |
30 CHECK(args->GetString(0, &path)); | 30 CHECK(args->GetString(0, &path)); |
31 DCHECK(StartsWithASCII(path, "chrome://favicon/size/32/", false)) << | 31 DCHECK(StartsWithASCII(path, "chrome://favicon/size/32/", false)) << |
32 "path is " << path; | 32 "path is " << path; |
33 path = path.substr(arraysize("chrome://favicon/size/32/") - 1); | 33 path = path.substr(arraysize("chrome://favicon/size/32/") - 1); |
34 | 34 |
35 double id; | 35 double id; |
36 CHECK(args->GetDouble(1, &id)); | 36 CHECK(args->GetDouble(1, &id)); |
37 | 37 |
| 38 std::string callback_name; |
| 39 CHECK(args->GetString(2, &callback_name)); |
| 40 callbacks_map_[static_cast<int>(id)] = callback_name; |
| 41 |
38 FaviconService* favicon_service = | 42 FaviconService* favicon_service = |
39 Profile::FromWebUI(web_ui_)->GetFaviconService(Profile::EXPLICIT_ACCESS); | 43 Profile::FromWebUI(web_ui_)->GetFaviconService(Profile::EXPLICIT_ACCESS); |
40 if (!favicon_service || path.empty()) | 44 if (!favicon_service || path.empty()) |
41 return; | 45 return; |
42 | 46 |
43 FaviconService::Handle handle = favicon_service->GetFaviconForURL( | 47 FaviconService::Handle handle = favicon_service->GetFaviconForURL( |
44 GURL(path), | 48 GURL(path), |
45 history::FAVICON, | 49 history::FAVICON, |
46 &consumer_, | 50 &consumer_, |
47 NewCallback(this, &FaviconWebUIHandler::OnFaviconDataAvailable)); | 51 NewCallback(this, &FaviconWebUIHandler::OnFaviconDataAvailable)); |
(...skipping 17 matching lines...) Expand all Loading... |
65 sampler); | 69 sampler); |
66 std::string css_color = base::StringPrintf("rgb(%d, %d, %d)", | 70 std::string css_color = base::StringPrintf("rgb(%d, %d, %d)", |
67 SkColorGetR(color), | 71 SkColorGetR(color), |
68 SkColorGetG(color), | 72 SkColorGetG(color), |
69 SkColorGetB(color)); | 73 SkColorGetB(color)); |
70 color_value.reset(new StringValue(css_color)); | 74 color_value.reset(new StringValue(css_color)); |
71 } else { | 75 } else { |
72 color_value.reset(new StringValue("#919191")); | 76 color_value.reset(new StringValue("#919191")); |
73 } | 77 } |
74 | 78 |
75 web_ui_->CallJavascriptFunction("ntp4.setFaviconDominantColor", | 79 web_ui_->CallJavascriptFunction(callbacks_map_[id], id_value, *color_value); |
76 id_value, *color_value); | 80 callbacks_map_.erase(id); |
77 } | 81 } |
OLD | NEW |