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

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

Issue 10873022: Revert 152904 - Moving FaviconService to a ProfileKeyedService. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 8 years, 4 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/ntp/app_launcher_handler.cc ('k') | chrome/chrome_browser.gypi » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Property Changes:
Deleted: svn:mergeinfo
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"
17 #include "chrome/browser/profiles/profile.h" 16 #include "chrome/browser/profiles/profile.h"
18 #include "chrome/common/extensions/extension_resource.h" 17 #include "chrome/common/extensions/extension_resource.h"
19 #include "chrome/common/url_constants.h" 18 #include "chrome/common/url_constants.h"
20 #include "content/public/browser/web_ui.h" 19 #include "content/public/browser/web_ui.h"
21 #include "grit/ui_resources.h" 20 #include "grit/ui_resources.h"
22 #include "third_party/skia/include/core/SkBitmap.h" 21 #include "third_party/skia/include/core/SkBitmap.h"
23 #include "ui/base/l10n/l10n_util.h" 22 #include "ui/base/l10n/l10n_util.h"
24 #include "ui/gfx/codec/png_codec.h" 23 #include "ui/gfx/codec/png_codec.h"
25 #include "ui/gfx/color_analysis.h" 24 #include "ui/gfx/color_analysis.h"
26 25
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
82 void FaviconWebUIHandler::HandleGetFaviconDominantColor(const ListValue* args) { 81 void FaviconWebUIHandler::HandleGetFaviconDominantColor(const ListValue* args) {
83 std::string path; 82 std::string path;
84 CHECK(args->GetString(0, &path)); 83 CHECK(args->GetString(0, &path));
85 DCHECK(StartsWithASCII(path, "chrome://favicon/size/16/", false)) << 84 DCHECK(StartsWithASCII(path, "chrome://favicon/size/16/", false)) <<
86 "path is " << path; 85 "path is " << path;
87 path = path.substr(arraysize("chrome://favicon/size/16/") - 1); 86 path = path.substr(arraysize("chrome://favicon/size/16/") - 1);
88 87
89 std::string dom_id; 88 std::string dom_id;
90 CHECK(args->GetString(1, &dom_id)); 89 CHECK(args->GetString(1, &dom_id));
91 90
92 FaviconService* favicon_service = FaviconServiceFactory::GetForProfile( 91 FaviconService* favicon_service =
93 Profile::FromWebUI(web_ui()), Profile::EXPLICIT_ACCESS); 92 Profile::FromWebUI(web_ui())->GetFaviconService(Profile::EXPLICIT_ACCESS);
94 if (!favicon_service || path.empty()) 93 if (!favicon_service || path.empty())
95 return; 94 return;
96 95
97 GURL url(path); 96 GURL url(path);
98 // Intercept requests for prepopulated pages. 97 // Intercept requests for prepopulated pages.
99 for (size_t i = 0; i < arraysize(history::kPrepopulatedPages); i++) { 98 for (size_t i = 0; i < arraysize(history::kPrepopulatedPages); i++) {
100 if (url.spec() == 99 if (url.spec() ==
101 l10n_util::GetStringUTF8(history::kPrepopulatedPages[i].url_id)) { 100 l10n_util::GetStringUTF8(history::kPrepopulatedPages[i].url_id)) {
102 StringValue dom_id_value(dom_id); 101 StringValue dom_id_value(dom_id);
103 scoped_ptr<StringValue> color( 102 scoped_ptr<StringValue> color(
104 SkColorToCss(history::kPrepopulatedPages[i].color)); 103 SkColorToCss(history::kPrepopulatedPages[i].color));
105 web_ui()->CallJavascriptFunction("ntp.setStripeColor", 104 web_ui()->CallJavascriptFunction("ntp.setStripeColor",
106 dom_id_value, *color); 105 dom_id_value, *color);
107 return; 106 return;
108 } 107 }
109 } 108 }
110 109
111 dom_id_map_[id_] = dom_id; 110 dom_id_map_[id_] = dom_id;
112 FaviconService::Handle handle = favicon_service->GetFaviconForURL( 111 FaviconService::Handle handle = favicon_service->GetFaviconForURL(
113 Profile::FromWebUI(web_ui()),
114 url, 112 url,
115 history::FAVICON, 113 history::FAVICON,
116 &consumer_, 114 &consumer_,
117 base::Bind(&FaviconWebUIHandler::OnFaviconDataAvailable, 115 base::Bind(&FaviconWebUIHandler::OnFaviconDataAvailable,
118 base::Unretained(this))); 116 base::Unretained(this)));
119 consumer_.SetClientData(favicon_service, handle, id_++); 117 consumer_.SetClientData(favicon_service, handle, id_++);
120 } 118 }
121 119
122 void FaviconWebUIHandler::OnFaviconDataAvailable( 120 void FaviconWebUIHandler::OnFaviconDataAvailable(
123 FaviconService::Handle request_handle, 121 FaviconService::Handle request_handle,
124 history::FaviconData favicon) { 122 history::FaviconData favicon) {
125 FaviconService* favicon_service = FaviconServiceFactory::GetForProfile( 123 FaviconService* favicon_service =
126 Profile::FromWebUI(web_ui()), Profile::EXPLICIT_ACCESS); 124 Profile::FromWebUI(web_ui())->GetFaviconService(Profile::EXPLICIT_ACCESS);
127 int id = consumer_.GetClientData(favicon_service, request_handle); 125 int id = consumer_.GetClientData(favicon_service, request_handle);
128 scoped_ptr<StringValue> color_value; 126 scoped_ptr<StringValue> color_value;
129 127
130 if (favicon.is_valid()) 128 if (favicon.is_valid())
131 color_value.reset(GetDominantColorCssString(favicon.image_data)); 129 color_value.reset(GetDominantColorCssString(favicon.image_data));
132 else 130 else
133 color_value.reset(new StringValue("#919191")); 131 color_value.reset(new StringValue("#919191"));
134 132
135 StringValue dom_id(dom_id_map_[id]); 133 StringValue dom_id(dom_id_map_[id]);
136 web_ui()->CallJavascriptFunction("ntp.setStripeColor", dom_id, *color_value); 134 web_ui()->CallJavascriptFunction("ntp.setStripeColor", dom_id, *color_value);
(...skipping 20 matching lines...) Expand all
157 std::vector<unsigned char> bits; 155 std::vector<unsigned char> bits;
158 if (!gfx::PNGCodec::EncodeBGRASkBitmap(bitmap, true, &bits)) 156 if (!gfx::PNGCodec::EncodeBGRASkBitmap(bitmap, true, &bits))
159 return; 157 return;
160 scoped_refptr<base::RefCountedStaticMemory> bits_mem( 158 scoped_refptr<base::RefCountedStaticMemory> bits_mem(
161 new base::RefCountedStaticMemory(&bits.front(), bits.size())); 159 new base::RefCountedStaticMemory(&bits.front(), bits.size()));
162 scoped_ptr<StringValue> color_value(GetDominantColorCssString(bits_mem)); 160 scoped_ptr<StringValue> color_value(GetDominantColorCssString(bits_mem));
163 StringValue id(extension_id); 161 StringValue id(extension_id);
164 web_ui()->CallJavascriptFunction( 162 web_ui()->CallJavascriptFunction(
165 "ntp.setStripeColor", id, *color_value); 163 "ntp.setStripeColor", id, *color_value);
166 } 164 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/webui/ntp/app_launcher_handler.cc ('k') | chrome/chrome_browser.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698