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 "content/browser/image_downloader/image_downloader_dispatcher.h" |
| 6 |
| 7 #include "content/public/browser/render_frame_host.h" |
| 8 #include "content/public/common/service_registry.h" |
| 9 #include "mojo/common/url_type_converters.h" |
| 10 #include "mojo/converters/geometry/geometry_type_converters.h" |
| 11 #include "skia/public/type_converters.h" |
| 12 #include "third_party/skia/include/core/SkBitmap.h" |
| 13 #include "ui/gfx/geometry/size.h" |
| 14 #include "url/gurl.h" |
| 15 |
| 16 namespace content { |
| 17 namespace { |
| 18 |
| 19 void DidDownload(const WebContents::ImageDownloadCallback& callback, |
| 20 int id, |
| 21 image_downloader::DownloadResultPtr result) { |
| 22 DCHECK(result); |
| 23 |
| 24 const GURL image_url = result->url.To<GURL>(); |
| 25 const std::vector<SkBitmap> images = |
| 26 result->images.To<std::vector<SkBitmap>>(); |
| 27 const std::vector<gfx::Size> original_image_sizes = |
| 28 result->original_image_sizes.To<std::vector<gfx::Size>>(); |
| 29 |
| 30 callback.Run(id, result->http_status_code, image_url, images, |
| 31 original_image_sizes); |
| 32 } |
| 33 |
| 34 } // namespace |
| 35 |
| 36 // static |
| 37 int ImageDownloaderDispatcher::next_image_download_id_ = 0; |
| 38 |
| 39 ImageDownloaderDispatcher::ImageDownloaderDispatcher( |
| 40 RenderFrameHost* render_frame_host) |
| 41 : render_frame_host_(render_frame_host) { |
| 42 DCHECK(render_frame_host_); |
| 43 } |
| 44 |
| 45 ImageDownloaderDispatcher::~ImageDownloaderDispatcher() { |
| 46 } |
| 47 |
| 48 int ImageDownloaderDispatcher::StartDownload( |
| 49 const GURL& url, |
| 50 bool is_favicon, |
| 51 uint32_t max_bitmap_size, |
| 52 bool bypass_cache, |
| 53 const WebContents::ImageDownloadCallback& callback) { |
| 54 image_downloader::DownloadReqPtr req = image_downloader::DownloadReq::New(); |
| 55 |
| 56 if (!downloader_.get()) { |
| 57 render_frame_host_->GetServiceRegistry()->ConnectToRemoteService( |
| 58 &downloader_); |
| 59 downloader_.set_error_handler(this); |
| 60 } |
| 61 |
| 62 req->url = mojo::String::From(url); |
| 63 req->is_favicon = is_favicon; |
| 64 req->max_bitmap_size = max_bitmap_size; |
| 65 req->bypass_cache = bypass_cache; |
| 66 |
| 67 downloader_->DownloadImage(req.Pass(), base::Bind(&DidDownload, callback, |
| 68 ++next_image_download_id_)); |
| 69 return next_image_download_id_; |
| 70 } |
| 71 |
| 72 void ImageDownloaderDispatcher::OnConnectionError() { |
| 73 downloader_.reset(); |
| 74 } |
| 75 |
| 76 } // namespace content |
OLD | NEW |