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 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
84 CHECK(args->GetString(0, &path)); | 84 CHECK(args->GetString(0, &path)); |
85 std::string prefix = "chrome://favicon/size/"; | 85 std::string prefix = "chrome://favicon/size/"; |
86 DCHECK(StartsWithASCII(path, prefix, false)) << "path is " << path; | 86 DCHECK(StartsWithASCII(path, prefix, false)) << "path is " << path; |
87 size_t slash = path.find("/", prefix.length()); | 87 size_t slash = path.find("/", prefix.length()); |
88 path = path.substr(slash + 1); | 88 path = path.substr(slash + 1); |
89 | 89 |
90 std::string dom_id; | 90 std::string dom_id; |
91 CHECK(args->GetString(1, &dom_id)); | 91 CHECK(args->GetString(1, &dom_id)); |
92 | 92 |
93 FaviconService* favicon_service = FaviconServiceFactory::GetForProfile( | 93 FaviconService* favicon_service = FaviconServiceFactory::GetForProfile( |
94 Profile::FromWebUI(web_ui()), Profile::EXPLICIT_ACCESS); | 94 Profile::FromWebUI(web_ui()), ServiceAccessType::EXPLICIT_ACCESS); |
95 if (!favicon_service || path.empty()) | 95 if (!favicon_service || path.empty()) |
96 return; | 96 return; |
97 | 97 |
98 GURL url(path); | 98 GURL url(path); |
99 // Intercept requests for prepopulated pages. | 99 // Intercept requests for prepopulated pages. |
100 for (size_t i = 0; i < history::kPrepopulatedPagesCount; i++) { | 100 for (size_t i = 0; i < history::kPrepopulatedPagesCount; i++) { |
101 if (url.spec() == | 101 if (url.spec() == |
102 l10n_util::GetStringUTF8(history::kPrepopulatedPages[i].url_id)) { | 102 l10n_util::GetStringUTF8(history::kPrepopulatedPages[i].url_id)) { |
103 base::StringValue dom_id_value(dom_id); | 103 base::StringValue dom_id_value(dom_id); |
104 scoped_ptr<base::StringValue> color( | 104 scoped_ptr<base::StringValue> color( |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
158 if (!gfx::PNGCodec::EncodeBGRASkBitmap(bitmap, true, &bits)) | 158 if (!gfx::PNGCodec::EncodeBGRASkBitmap(bitmap, true, &bits)) |
159 return; | 159 return; |
160 scoped_refptr<base::RefCountedStaticMemory> bits_mem( | 160 scoped_refptr<base::RefCountedStaticMemory> bits_mem( |
161 new base::RefCountedStaticMemory(&bits.front(), bits.size())); | 161 new base::RefCountedStaticMemory(&bits.front(), bits.size())); |
162 scoped_ptr<base::StringValue> color_value( | 162 scoped_ptr<base::StringValue> color_value( |
163 GetDominantColorCssString(bits_mem)); | 163 GetDominantColorCssString(bits_mem)); |
164 base::StringValue id(extension_id); | 164 base::StringValue id(extension_id); |
165 web_ui()->CallJavascriptFunction( | 165 web_ui()->CallJavascriptFunction( |
166 "ntp.setFaviconDominantColor", id, *color_value); | 166 "ntp.setFaviconDominantColor", id, *color_value); |
167 } | 167 } |
OLD | NEW |