OLD | NEW |
---|---|
(Empty) | |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #include "chrome/browser/ui/webui/fallback_icon_source.h" | |
6 | |
7 #include <string> | |
8 #include <vector> | |
9 | |
10 #include "base/memory/ref_counted_memory.h" | |
11 #include "chrome/browser/search/instant_io_context.h" | |
12 #include "chrome/common/favicon/fallback_icon_url_parser.h" | |
13 #include "chrome/common/url_constants.h" | |
14 #include "grit/platform_locale_settings.h" | |
15 #include "net/url_request/url_request.h" | |
16 #include "ui/base/l10n/l10n_util.h" | |
17 #include "ui/gfx/favicon_size.h" | |
18 | |
19 FallbackIconSource::FallbackIconSource() { | |
20 std::vector<std::string> font_list; | |
21 #if defined(OS_CHROMEOS) | |
22 const std::string kChromeOSFontFamily = "Noto Sans"; | |
23 font_list.push_back(kChromeOSFontFamily); | |
24 #elif defined(OS_IOS) | |
25 const std::string kIOSFontFamily = "Helvetica Neue"; | |
Evan Stade
2015/03/05 02:54:42
just inline the string literal imo
huangs
2015/03/05 19:47:46
Done.
| |
26 font_list.push_back(kIOSFontFamily); | |
27 #else | |
28 font_list.push_back(l10n_util::GetStringUTF8(IDS_SANS_SERIF_FONT_FAMILY)); | |
29 #endif | |
30 fallback_icon_service_.reset( | |
31 new favicon_base::FallbackIconService(font_list)); | |
32 } | |
33 | |
34 FallbackIconSource::~FallbackIconSource() { | |
35 } | |
36 | |
37 std::string FallbackIconSource::GetSource() const { | |
38 return chrome::kChromeUIFallbackIconHost; | |
39 } | |
40 | |
41 void FallbackIconSource::StartDataRequest( | |
42 const std::string& path, | |
43 int render_process_id, | |
44 int render_frame_id, | |
45 const content::URLDataSource::GotDataCallback& callback) { | |
46 chrome::ParsedFallbackIconPath parsed; | |
47 bool success = parsed.Parse(path); | |
48 if (!success) { | |
49 SendDefaultResponse(callback); | |
50 return; | |
51 } | |
52 | |
53 GURL url(parsed.url()); | |
54 std::vector<unsigned char> bitmap_data = | |
55 fallback_icon_service_->RenderFallbackIconBitmap( | |
56 url, parsed.size_in_pixels(), parsed.style()); | |
57 callback.Run(base::RefCountedBytes::TakeVector(&bitmap_data)); | |
58 } | |
59 | |
60 std::string FallbackIconSource::GetMimeType(const std::string&) const { | |
61 // We need to explicitly return a mime type, otherwise if the user tries to | |
62 // drag the image they get no extension. | |
63 return "image/png"; | |
64 } | |
65 | |
66 bool FallbackIconSource::ShouldReplaceExistingSource() const { | |
67 // Leave the existing DataSource in place, otherwise we'll drop any pending | |
68 // requests on the floor. | |
69 return false; | |
70 } | |
71 | |
72 bool FallbackIconSource::ShouldServiceRequest( | |
73 const net::URLRequest* request) const { | |
74 if (request->url().SchemeIs(chrome::kChromeSearchScheme)) | |
75 return InstantIOContext::ShouldServiceRequest(request); | |
76 return URLDataSource::ShouldServiceRequest(request); | |
77 } | |
78 | |
79 void FallbackIconSource::SendDefaultResponse( | |
80 const content::URLDataSource::GotDataCallback& callback) { | |
81 std::vector<unsigned char> bitmap_data = | |
82 fallback_icon_service_->RenderFallbackIconBitmap( | |
83 GURL(), gfx::kFaviconSize, favicon_base::FallbackIconStyle()); | |
84 callback.Run(base::RefCountedBytes::TakeVector(&bitmap_data)); | |
85 } | |
OLD | NEW |