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" |
11 #include "base/strings/stringprintf.h" | 11 #include "base/strings/stringprintf.h" |
12 #include "base/values.h" | 12 #include "base/values.h" |
13 #include "chrome/browser/extensions/extension_icon_manager.h" | 13 #include "chrome/browser/extensions/extension_icon_manager.h" |
14 #include "chrome/browser/favicon/favicon_service.h" | 14 #include "chrome/browser/favicon/favicon_service.h" |
15 #include "chrome/browser/favicon/favicon_service_factory.h" | 15 #include "chrome/browser/favicon/favicon_service_factory.h" |
16 #include "chrome/browser/history/top_sites.h" | 16 #include "chrome/browser/history/top_sites_factory.h" |
17 #include "chrome/browser/profiles/profile.h" | 17 #include "chrome/browser/profiles/profile.h" |
18 #include "chrome/common/url_constants.h" | 18 #include "chrome/common/url_constants.h" |
| 19 #include "components/history/core/browser/top_sites.h" |
19 #include "content/public/browser/web_ui.h" | 20 #include "content/public/browser/web_ui.h" |
20 #include "extensions/browser/extension_registry.h" | 21 #include "extensions/browser/extension_registry.h" |
21 #include "third_party/skia/include/core/SkBitmap.h" | 22 #include "third_party/skia/include/core/SkBitmap.h" |
22 #include "ui/base/l10n/l10n_util.h" | 23 #include "ui/base/l10n/l10n_util.h" |
23 #include "ui/gfx/codec/png_codec.h" | 24 #include "ui/gfx/codec/png_codec.h" |
24 #include "ui/gfx/color_analysis.h" | 25 #include "ui/gfx/color_analysis.h" |
25 #include "ui/gfx/favicon_size.h" | 26 #include "ui/gfx/favicon_size.h" |
26 | 27 |
27 namespace { | 28 namespace { |
28 | 29 |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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()), ServiceAccessType::EXPLICIT_ACCESS); | 95 Profile::FromWebUI(web_ui()), ServiceAccessType::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); |
99 // Intercept requests for prepopulated pages. | 100 // Intercept requests for prepopulated pages if TopSites exists. |
100 for (size_t i = 0; i < history::kPrepopulatedPagesCount; i++) { | 101 scoped_refptr<history::TopSites> top_sites = |
101 if (url.spec() == | 102 TopSitesFactory::GetForProfile(Profile::FromWebUI(web_ui())); |
102 l10n_util::GetStringUTF8(history::kPrepopulatedPages[i].url_id)) { | 103 if (top_sites) { |
103 base::StringValue dom_id_value(dom_id); | 104 for (const auto& prepopulated_page : top_sites->GetPrepopulatedPages()) { |
104 scoped_ptr<base::StringValue> color( | 105 if (url == prepopulated_page.most_visited.url) { |
105 SkColorToCss(history::kPrepopulatedPages[i].color)); | 106 base::StringValue dom_id_value(dom_id); |
106 web_ui()->CallJavascriptFunction("ntp.setFaviconDominantColor", | 107 scoped_ptr<base::StringValue> color( |
107 dom_id_value, *color); | 108 SkColorToCss(prepopulated_page.color)); |
108 return; | 109 web_ui()->CallJavascriptFunction("ntp.setFaviconDominantColor", |
| 110 dom_id_value, *color); |
| 111 return; |
| 112 } |
109 } | 113 } |
110 } | 114 } |
111 | 115 |
112 dom_id_map_[id_] = dom_id; | 116 dom_id_map_[id_] = dom_id; |
113 favicon_service->GetRawFaviconForPageURL( | 117 favicon_service->GetRawFaviconForPageURL( |
114 url, | 118 url, |
115 favicon_base::FAVICON, | 119 favicon_base::FAVICON, |
116 gfx::kFaviconSize, | 120 gfx::kFaviconSize, |
117 base::Bind(&FaviconWebUIHandler::OnFaviconDataAvailable, | 121 base::Bind(&FaviconWebUIHandler::OnFaviconDataAvailable, |
118 base::Unretained(this), | 122 base::Unretained(this), |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
158 if (!gfx::PNGCodec::EncodeBGRASkBitmap(bitmap, true, &bits)) | 162 if (!gfx::PNGCodec::EncodeBGRASkBitmap(bitmap, true, &bits)) |
159 return; | 163 return; |
160 scoped_refptr<base::RefCountedStaticMemory> bits_mem( | 164 scoped_refptr<base::RefCountedStaticMemory> bits_mem( |
161 new base::RefCountedStaticMemory(&bits.front(), bits.size())); | 165 new base::RefCountedStaticMemory(&bits.front(), bits.size())); |
162 scoped_ptr<base::StringValue> color_value( | 166 scoped_ptr<base::StringValue> color_value( |
163 GetDominantColorCssString(bits_mem)); | 167 GetDominantColorCssString(bits_mem)); |
164 base::StringValue id(extension_id); | 168 base::StringValue id(extension_id); |
165 web_ui()->CallJavascriptFunction( | 169 web_ui()->CallJavascriptFunction( |
166 "ntp.setFaviconDominantColor", id, *color_value); | 170 "ntp.setFaviconDominantColor", id, *color_value); |
167 } | 171 } |
OLD | NEW |