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

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

Issue 2883053003: Delete unused chrome://fallback-icon/ handling (Closed)
Patch Set: Merge branch 'master' into searchbox3 Created 3 years, 7 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 | « chrome/browser/ui/webui/fallback_icon_source.h ('k') | chrome/common/url_constants.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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 <vector>
8
9 #include "base/memory/ref_counted_memory.h"
10 #include "chrome/browser/search/instant_io_context.h"
11 #include "chrome/common/url_constants.h"
12 #include "components/favicon/core/fallback_icon_service.h"
13 #include "components/favicon_base/fallback_icon_url_parser.h"
14 #include "components/keyed_service/core/service_access_type.h"
15 #include "net/url_request/url_request.h"
16 #include "ui/gfx/favicon_size.h"
17 #include "url/gurl.h"
18
19 FallbackIconSource::FallbackIconSource(
20 favicon::FallbackIconService* fallback_icon_service)
21 : fallback_icon_service_(fallback_icon_service) {
22 }
23
24 FallbackIconSource::~FallbackIconSource() {
25 }
26
27 std::string FallbackIconSource::GetSource() const {
28 return chrome::kChromeUIFallbackIconHost;
29 }
30
31 void FallbackIconSource::StartDataRequest(
32 const std::string& path,
33 const content::ResourceRequestInfo::WebContentsGetter& wc_getter,
34 const content::URLDataSource::GotDataCallback& callback) {
35 chrome::ParsedFallbackIconPath parsed;
36 bool success = parsed.Parse(path);
37 if (!success) {
38 SendDefaultResponse(callback);
39 return;
40 }
41
42 GURL url(parsed.url_string());
43 if (url.is_empty() || !url.is_valid()) {
44 SendDefaultResponse(callback);
45 return;
46 }
47
48 SendFallbackIconHelper(
49 url, parsed.size_in_pixels(), parsed.style(), callback);
50 }
51
52 std::string FallbackIconSource::GetMimeType(const std::string&) const {
53 // We need to explicitly return a mime type, otherwise if the user tries to
54 // drag the image they get no extension.
55 return "image/png";
56 }
57
58 bool FallbackIconSource::AllowCaching() const {
59 return false;
60 }
61
62 bool FallbackIconSource::ShouldReplaceExistingSource() const {
63 // Leave the existing DataSource in place, otherwise we'll drop any pending
64 // requests on the floor.
65 return false;
66 }
67
68 bool FallbackIconSource::ShouldServiceRequest(
69 const GURL& url,
70 content::ResourceContext* resource_context,
71 int render_process_id) const {
72 if (url.SchemeIs(chrome::kChromeSearchScheme)) {
73 return InstantIOContext::ShouldServiceRequest(url, resource_context,
74 render_process_id);
75 }
76 return URLDataSource::ShouldServiceRequest(url, resource_context,
77 render_process_id);
78 }
79
80 void FallbackIconSource::SendFallbackIconHelper(
81 const GURL& url,
82 int size_in_pixels,
83 const favicon_base::FallbackIconStyle& style,
84 const content::URLDataSource::GotDataCallback& callback) {
85 if (!fallback_icon_service_) { // Can be null for tests.
86 callback.Run(nullptr); // Trigger "Not Found" response.
87 return;
88 }
89 std::vector<unsigned char> bitmap_data =
90 fallback_icon_service_->RenderFallbackIconBitmap(
91 url, size_in_pixels, style);
92 callback.Run(base::RefCountedBytes::TakeVector(&bitmap_data));
93 }
94
95 void FallbackIconSource::SendDefaultResponse(
96 const content::URLDataSource::GotDataCallback& callback) {
97 favicon_base::FallbackIconStyle default_style;
98 SendFallbackIconHelper(GURL(), gfx::kFaviconSize, default_style, callback);
99 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/webui/fallback_icon_source.h ('k') | chrome/common/url_constants.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698