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

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

Issue 10870022: Change FaviconData to be able to return data for multiple bitmaps for same icon URL (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: 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
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"
11 #include "base/stringprintf.h" 11 #include "base/stringprintf.h"
12 #include "base/values.h" 12 #include "base/values.h"
13 #include "chrome/browser/history/top_sites.h" 13 #include "chrome/browser/history/top_sites.h"
14 #include "chrome/browser/extensions/extension_icon_manager.h" 14 #include "chrome/browser/extensions/extension_icon_manager.h"
15 #include "chrome/browser/extensions/extension_service.h" 15 #include "chrome/browser/extensions/extension_service.h"
16 #include "chrome/browser/favicon/favicon_service_factory.h" 16 #include "chrome/browser/favicon/favicon_service_factory.h"
17 #include "chrome/browser/profiles/profile.h" 17 #include "chrome/browser/profiles/profile.h"
18 #include "chrome/common/extensions/extension_resource.h" 18 #include "chrome/common/extensions/extension_resource.h"
19 #include "chrome/common/url_constants.h" 19 #include "chrome/common/url_constants.h"
20 #include "content/public/browser/web_ui.h" 20 #include "content/public/browser/web_ui.h"
21 #include "grit/ui_resources.h" 21 #include "grit/ui_resources.h"
22 #include "third_party/skia/include/core/SkBitmap.h" 22 #include "third_party/skia/include/core/SkBitmap.h"
23 #include "ui/base/l10n/l10n_util.h" 23 #include "ui/base/l10n/l10n_util.h"
24 #include "ui/gfx/codec/png_codec.h" 24 #include "ui/gfx/codec/png_codec.h"
25 #include "ui/gfx/color_analysis.h" 25 #include "ui/gfx/color_analysis.h"
26 #include "ui/gfx/favicon_size.h"
26 27
27 namespace { 28 namespace {
28 29
29 StringValue* SkColorToCss(SkColor color) { 30 StringValue* SkColorToCss(SkColor color) {
30 return new StringValue(base::StringPrintf("rgb(%d, %d, %d)", 31 return new StringValue(base::StringPrintf("rgb(%d, %d, %d)",
31 SkColorGetR(color), 32 SkColorGetR(color),
32 SkColorGetG(color), 33 SkColorGetG(color),
33 SkColorGetB(color))); 34 SkColorGetB(color)));
34 } 35 }
35 36
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
102 StringValue dom_id_value(dom_id); 103 StringValue dom_id_value(dom_id);
103 scoped_ptr<StringValue> color( 104 scoped_ptr<StringValue> color(
104 SkColorToCss(history::kPrepopulatedPages[i].color)); 105 SkColorToCss(history::kPrepopulatedPages[i].color));
105 web_ui()->CallJavascriptFunction("ntp.setStripeColor", 106 web_ui()->CallJavascriptFunction("ntp.setStripeColor",
106 dom_id_value, *color); 107 dom_id_value, *color);
107 return; 108 return;
108 } 109 }
109 } 110 }
110 111
111 dom_id_map_[id_] = dom_id; 112 dom_id_map_[id_] = dom_id;
112 FaviconService::Handle handle = favicon_service->GetFaviconForURL( 113 FaviconService::Handle handle = favicon_service->GetRawFaviconForURL(
113 Profile::FromWebUI(web_ui()), 114 Profile::FromWebUI(web_ui()),
114 url, 115 url,
115 history::FAVICON, 116 history::FAVICON,
117 gfx::kFaviconSize,
118 ui::SCALE_FACTOR_100P,
116 &consumer_, 119 &consumer_,
117 base::Bind(&FaviconWebUIHandler::OnFaviconDataAvailable, 120 base::Bind(&FaviconWebUIHandler::OnFaviconDataAvailable,
118 base::Unretained(this))); 121 base::Unretained(this)));
119 consumer_.SetClientData(favicon_service, handle, id_++); 122 consumer_.SetClientData(favicon_service, handle, id_++);
120 } 123 }
121 124
122 void FaviconWebUIHandler::OnFaviconDataAvailable( 125 void FaviconWebUIHandler::OnFaviconDataAvailable(
123 FaviconService::Handle request_handle, 126 FaviconService::Handle request_handle,
124 history::FaviconData favicon) { 127 const history::FaviconBitmapResult& bitmap_result) {
125 FaviconService* favicon_service = FaviconServiceFactory::GetForProfile( 128 FaviconService* favicon_service = FaviconServiceFactory::GetForProfile(
126 Profile::FromWebUI(web_ui()), Profile::EXPLICIT_ACCESS); 129 Profile::FromWebUI(web_ui()), Profile::EXPLICIT_ACCESS);
127 int id = consumer_.GetClientData(favicon_service, request_handle); 130 int id = consumer_.GetClientData(favicon_service, request_handle);
128 scoped_ptr<StringValue> color_value; 131 scoped_ptr<StringValue> color_value;
129 132
130 if (favicon.is_valid()) 133 if (bitmap_result.is_valid())
131 color_value.reset(GetDominantColorCssString(favicon.image_data)); 134 color_value.reset(GetDominantColorCssString(bitmap_result.bitmap_data));
132 else 135 else
133 color_value.reset(new StringValue("#919191")); 136 color_value.reset(new StringValue("#919191"));
134 137
135 StringValue dom_id(dom_id_map_[id]); 138 StringValue dom_id(dom_id_map_[id]);
136 web_ui()->CallJavascriptFunction("ntp.setStripeColor", dom_id, *color_value); 139 web_ui()->CallJavascriptFunction("ntp.setStripeColor", dom_id, *color_value);
137 dom_id_map_.erase(id); 140 dom_id_map_.erase(id);
138 } 141 }
139 142
140 void FaviconWebUIHandler::HandleGetAppIconDominantColor( 143 void FaviconWebUIHandler::HandleGetAppIconDominantColor(
141 const ListValue* args) { 144 const ListValue* args) {
(...skipping 15 matching lines...) Expand all
157 std::vector<unsigned char> bits; 160 std::vector<unsigned char> bits;
158 if (!gfx::PNGCodec::EncodeBGRASkBitmap(bitmap, true, &bits)) 161 if (!gfx::PNGCodec::EncodeBGRASkBitmap(bitmap, true, &bits))
159 return; 162 return;
160 scoped_refptr<base::RefCountedStaticMemory> bits_mem( 163 scoped_refptr<base::RefCountedStaticMemory> bits_mem(
161 new base::RefCountedStaticMemory(&bits.front(), bits.size())); 164 new base::RefCountedStaticMemory(&bits.front(), bits.size()));
162 scoped_ptr<StringValue> color_value(GetDominantColorCssString(bits_mem)); 165 scoped_ptr<StringValue> color_value(GetDominantColorCssString(bits_mem));
163 StringValue id(extension_id); 166 StringValue id(extension_id);
164 web_ui()->CallJavascriptFunction( 167 web_ui()->CallJavascriptFunction(
165 "ntp.setStripeColor", id, *color_value); 168 "ntp.setStripeColor", id, *color_value);
166 } 169 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698