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/strings/string_split.h" | 9 #include "base/strings/string_split.h" |
10 #include "base/strings/string_util.h" | 10 #include "base/strings/string_util.h" |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
77 web_ui()->RegisterMessageCallback("getAppIconDominantColor", | 77 web_ui()->RegisterMessageCallback("getAppIconDominantColor", |
78 base::Bind(&FaviconWebUIHandler::HandleGetAppIconDominantColor, | 78 base::Bind(&FaviconWebUIHandler::HandleGetAppIconDominantColor, |
79 base::Unretained(this))); | 79 base::Unretained(this))); |
80 } | 80 } |
81 | 81 |
82 void FaviconWebUIHandler::HandleGetFaviconDominantColor( | 82 void FaviconWebUIHandler::HandleGetFaviconDominantColor( |
83 const base::ListValue* args) { | 83 const base::ListValue* args) { |
84 std::string path; | 84 std::string path; |
85 CHECK(args->GetString(0, &path)); | 85 CHECK(args->GetString(0, &path)); |
86 std::string prefix = "chrome://favicon/size/"; | 86 std::string prefix = "chrome://favicon/size/"; |
87 DCHECK(base::StartsWithASCII(path, prefix, false)) << "path is " << path; | 87 DCHECK(base::StartsWith(path, prefix, base::CompareCase::INSENSITIVE_ASCII)) |
| 88 << "path is " << path; |
88 size_t slash = path.find("/", prefix.length()); | 89 size_t slash = path.find("/", prefix.length()); |
89 path = path.substr(slash + 1); | 90 path = path.substr(slash + 1); |
90 | 91 |
91 std::string dom_id; | 92 std::string dom_id; |
92 CHECK(args->GetString(1, &dom_id)); | 93 CHECK(args->GetString(1, &dom_id)); |
93 | 94 |
94 favicon::FaviconService* favicon_service = | 95 favicon::FaviconService* favicon_service = |
95 FaviconServiceFactory::GetForProfile(Profile::FromWebUI(web_ui()), | 96 FaviconServiceFactory::GetForProfile(Profile::FromWebUI(web_ui()), |
96 ServiceAccessType::EXPLICIT_ACCESS); | 97 ServiceAccessType::EXPLICIT_ACCESS); |
97 if (!favicon_service || path.empty()) | 98 if (!favicon_service || path.empty()) |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
163 if (!gfx::PNGCodec::EncodeBGRASkBitmap(bitmap, true, &bits)) | 164 if (!gfx::PNGCodec::EncodeBGRASkBitmap(bitmap, true, &bits)) |
164 return; | 165 return; |
165 scoped_refptr<base::RefCountedStaticMemory> bits_mem( | 166 scoped_refptr<base::RefCountedStaticMemory> bits_mem( |
166 new base::RefCountedStaticMemory(&bits.front(), bits.size())); | 167 new base::RefCountedStaticMemory(&bits.front(), bits.size())); |
167 scoped_ptr<base::StringValue> color_value( | 168 scoped_ptr<base::StringValue> color_value( |
168 GetDominantColorCssString(bits_mem)); | 169 GetDominantColorCssString(bits_mem)); |
169 base::StringValue id(extension_id); | 170 base::StringValue id(extension_id); |
170 web_ui()->CallJavascriptFunction( | 171 web_ui()->CallJavascriptFunction( |
171 "ntp.setFaviconDominantColor", id, *color_value); | 172 "ntp.setFaviconDominantColor", id, *color_value); |
172 } | 173 } |
OLD | NEW |