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