Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(88)

Side by Side Diff: chrome/browser/ui/webui/ntp/favicon_webui_handler.cc

Issue 10909236: Add support for favicon scale factor in WebUI (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix HandleGetFaviconDominantColor. Created 8 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/browser/ui/webui/favicon_source.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/string_split.h" 9 #include "base/string_split.h"
10 #include "base/string_util.h" 10 #include "base/string_util.h"
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
76 base::Bind(&FaviconWebUIHandler::HandleGetFaviconDominantColor, 76 base::Bind(&FaviconWebUIHandler::HandleGetFaviconDominantColor,
77 base::Unretained(this))); 77 base::Unretained(this)));
78 web_ui()->RegisterMessageCallback("getAppIconDominantColor", 78 web_ui()->RegisterMessageCallback("getAppIconDominantColor",
79 base::Bind(&FaviconWebUIHandler::HandleGetAppIconDominantColor, 79 base::Bind(&FaviconWebUIHandler::HandleGetAppIconDominantColor,
80 base::Unretained(this))); 80 base::Unretained(this)));
81 } 81 }
82 82
83 void FaviconWebUIHandler::HandleGetFaviconDominantColor(const ListValue* args) { 83 void FaviconWebUIHandler::HandleGetFaviconDominantColor(const ListValue* args) {
84 std::string path; 84 std::string path;
85 CHECK(args->GetString(0, &path)); 85 CHECK(args->GetString(0, &path));
86 DCHECK(StartsWithASCII(path, "chrome://favicon/size/16/", false)) << 86 std::string prefix = "chrome://favicon/size/";
87 "path is " << path; 87 DCHECK(StartsWithASCII(path, prefix, false)) << "path is " << path;
88 path = path.substr(arraysize("chrome://favicon/size/16/") - 1); 88 size_t slash = path.find("/", prefix.length());
89 path = path.substr(slash + 1);
89 90
90 std::string dom_id; 91 std::string dom_id;
91 CHECK(args->GetString(1, &dom_id)); 92 CHECK(args->GetString(1, &dom_id));
92 93
93 FaviconService* favicon_service = FaviconServiceFactory::GetForProfile( 94 FaviconService* favicon_service = FaviconServiceFactory::GetForProfile(
94 Profile::FromWebUI(web_ui()), Profile::EXPLICIT_ACCESS); 95 Profile::FromWebUI(web_ui()), Profile::EXPLICIT_ACCESS);
95 if (!favicon_service || path.empty()) 96 if (!favicon_service || path.empty())
96 return; 97 return;
97 98
98 GURL url(path); 99 GURL url(path);
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
162 std::vector<unsigned char> bits; 163 std::vector<unsigned char> bits;
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<StringValue> color_value(GetDominantColorCssString(bits_mem)); 168 scoped_ptr<StringValue> color_value(GetDominantColorCssString(bits_mem));
168 StringValue id(extension_id); 169 StringValue id(extension_id);
169 web_ui()->CallJavascriptFunction( 170 web_ui()->CallJavascriptFunction(
170 "ntp.setFaviconDominantColor", id, *color_value); 171 "ntp.setFaviconDominantColor", id, *color_value);
171 } 172 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/webui/favicon_source.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698