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

Side by Side Diff: chrome/browser/ui/webui/fallback_icon_source.cc

Issue 1010783002: [Icons NTP] Working prototype to fetch, store, and display big icons. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Tweaks and unit test fix. Created 5 years, 9 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
« no previous file with comments | « no previous file | chrome/common/favicon/fallback_icon_url_parser.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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/fallback_icon_source.h" 5 #include "chrome/browser/ui/webui/fallback_icon_source.h"
6 6
7 #include <string> 7 #include <string>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/memory/ref_counted_memory.h" 10 #include "base/memory/ref_counted_memory.h"
11 #include "chrome/browser/search/instant_io_context.h" 11 #include "chrome/browser/search/instant_io_context.h"
12 #include "chrome/common/favicon/fallback_icon_url_parser.h" 12 #include "chrome/common/favicon/fallback_icon_url_parser.h"
13 #include "chrome/common/url_constants.h" 13 #include "chrome/common/url_constants.h"
14 #include "grit/platform_locale_settings.h" 14 #include "grit/platform_locale_settings.h"
15 #include "net/url_request/url_request.h" 15 #include "net/url_request/url_request.h"
16 #include "ui/base/l10n/l10n_util.h" 16 #include "ui/base/l10n/l10n_util.h"
17 #include "ui/gfx/favicon_size.h" 17 #include "ui/gfx/favicon_size.h"
18 #include "url/gurl.h"
18 19
19 FallbackIconSource::FallbackIconSource() { 20 FallbackIconSource::FallbackIconSource() {
20 std::vector<std::string> font_list; 21 std::vector<std::string> font_list;
21 #if defined(OS_CHROMEOS) 22 #if defined(OS_CHROMEOS)
22 font_list.push_back("Noto Sans"); 23 font_list.push_back("Noto Sans");
23 #elif defined(OS_IOS) 24 #elif defined(OS_IOS)
24 font_list.push_back("Helvetica Neue"); 25 font_list.push_back("Helvetica Neue");
25 #else 26 #else
26 font_list.push_back(l10n_util::GetStringUTF8(IDS_SANS_SERIF_FONT_FAMILY)); 27 font_list.push_back(l10n_util::GetStringUTF8(IDS_SANS_SERIF_FONT_FAMILY));
27 #endif 28 #endif
(...skipping 12 matching lines...) Expand all
40 const std::string& path, 41 const std::string& path,
41 int render_process_id, 42 int render_process_id,
42 int render_frame_id, 43 int render_frame_id,
43 const content::URLDataSource::GotDataCallback& callback) { 44 const content::URLDataSource::GotDataCallback& callback) {
44 chrome::ParsedFallbackIconPath parsed; 45 chrome::ParsedFallbackIconPath parsed;
45 bool success = parsed.Parse(path); 46 bool success = parsed.Parse(path);
46 if (!success) { 47 if (!success) {
47 SendDefaultResponse(callback); 48 SendDefaultResponse(callback);
48 return; 49 return;
49 } 50 }
50 51 GURL url(parsed.url_string());
51 GURL url(parsed.url()); 52 if (url.is_empty() || !url.is_valid()) {
53 SendDefaultResponse(callback);
54 return;
55 }
52 std::vector<unsigned char> bitmap_data = 56 std::vector<unsigned char> bitmap_data =
53 fallback_icon_service_->RenderFallbackIconBitmap( 57 fallback_icon_service_->RenderFallbackIconBitmap(
54 url, parsed.size_in_pixels(), parsed.style()); 58 url, parsed.size_in_pixels(), parsed.style());
55 callback.Run(base::RefCountedBytes::TakeVector(&bitmap_data)); 59 callback.Run(base::RefCountedBytes::TakeVector(&bitmap_data));
56 } 60 }
57 61
58 std::string FallbackIconSource::GetMimeType(const std::string&) const { 62 std::string FallbackIconSource::GetMimeType(const std::string&) const {
59 // We need to explicitly return a mime type, otherwise if the user tries to 63 // We need to explicitly return a mime type, otherwise if the user tries to
60 // drag the image they get no extension. 64 // drag the image they get no extension.
61 return "image/png"; 65 return "image/png";
(...skipping 12 matching lines...) Expand all
74 return URLDataSource::ShouldServiceRequest(request); 78 return URLDataSource::ShouldServiceRequest(request);
75 } 79 }
76 80
77 void FallbackIconSource::SendDefaultResponse( 81 void FallbackIconSource::SendDefaultResponse(
78 const content::URLDataSource::GotDataCallback& callback) { 82 const content::URLDataSource::GotDataCallback& callback) {
79 std::vector<unsigned char> bitmap_data = 83 std::vector<unsigned char> bitmap_data =
80 fallback_icon_service_->RenderFallbackIconBitmap( 84 fallback_icon_service_->RenderFallbackIconBitmap(
81 GURL(), gfx::kFaviconSize, favicon_base::FallbackIconStyle()); 85 GURL(), gfx::kFaviconSize, favicon_base::FallbackIconStyle());
82 callback.Run(base::RefCountedBytes::TakeVector(&bitmap_data)); 86 callback.Run(base::RefCountedBytes::TakeVector(&bitmap_data));
83 } 87 }
OLDNEW
« no previous file with comments | « no previous file | chrome/common/favicon/fallback_icon_url_parser.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698