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 "chrome/browser/search/instant_io_context.h" |
| 8 #include "chrome/common/favicon/fallback_icon_url_parser.h" |
| 9 #include "chrome/common/url_constants.h" |
| 10 #include "net/url_request/url_request.h" |
| 11 |
| 12 FallbackIconSource::FallbackIconSource() { |
| 13 } |
| 14 |
| 15 FallbackIconSource::~FallbackIconSource() { |
| 16 } |
| 17 |
| 18 std::string FallbackIconSource::GetSource() const { |
| 19 return chrome::kChromeUIFallbackIconHost; |
| 20 } |
| 21 |
| 22 void FallbackIconSource::StartDataRequest( |
| 23 const std::string& path, |
| 24 int render_process_id, |
| 25 int render_frame_id, |
| 26 const content::URLDataSource::GotDataCallback& callback) { |
| 27 chrome::ParsedFallbackIconPath parsed; |
| 28 bool success = chrome::ParseFallbackIconPath(path, &parsed); |
| 29 if (!success) { |
| 30 SendDefaultResponse(callback); |
| 31 return; |
| 32 } |
| 33 |
| 34 GURL url(parsed.url); |
| 35 int desired_size_in_pixel = |
| 36 std::ceil(parsed.size_in_dip * parsed.device_scale_factor); |
| 37 |
| 38 std::vector<unsigned char> bitmap_data = |
| 39 fallback_icon_service_.RenderFallbackIconBitmap( |
| 40 url, desired_size_in_pixel, parsed.style_builder.Build()); |
| 41 callback.Run(base::RefCountedBytes::TakeVector(&bitmap_data)); |
| 42 } |
| 43 |
| 44 std::string FallbackIconSource::GetMimeType(const std::string&) const { |
| 45 // We need to explicitly return a mime type, otherwise if the user tries to |
| 46 // drag the image they get no extension. |
| 47 return "image/png"; |
| 48 } |
| 49 |
| 50 bool FallbackIconSource::ShouldReplaceExistingSource() const { |
| 51 // Leave the existing DataSource in place, otherwise we'll drop any pending |
| 52 // requests on the floor. |
| 53 return false; |
| 54 } |
| 55 |
| 56 bool FallbackIconSource::ShouldServiceRequest( |
| 57 const net::URLRequest* request) const { |
| 58 if (request->url().SchemeIs(chrome::kChromeSearchScheme)) |
| 59 return InstantIOContext::ShouldServiceRequest(request); |
| 60 return URLDataSource::ShouldServiceRequest(request); |
| 61 } |
| 62 |
| 63 void FallbackIconSource::SendDefaultResponse( |
| 64 const content::URLDataSource::GotDataCallback& callback) { |
| 65 favicon_base::FallbackIconStyleBuilder builder; |
| 66 std::vector<unsigned char> bitmap_data = |
| 67 fallback_icon_service_.RenderFallbackIconBitmap( |
| 68 GURL(), 16, builder.Build()); |
| 69 callback.Run(base::RefCountedBytes::TakeVector(&bitmap_data)); |
| 70 } |
OLD | NEW |