| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "content/renderer/image_downloader/image_downloader_impl.h" | 5 #include "content/renderer/image_downloader/image_downloader_impl.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/location.h" | 10 #include "base/location.h" |
| 11 #include "base/logging.h" | 11 #include "base/logging.h" |
| 12 #include "base/single_thread_task_runner.h" | 12 #include "base/single_thread_task_runner.h" |
| 13 #include "base/threading/thread_task_runner_handle.h" | 13 #include "base/threading/thread_task_runner_handle.h" |
| 14 #include "content/child/image_decoder.h" | 14 #include "content/child/image_decoder.h" |
| 15 #include "content/public/renderer/render_frame.h" | 15 #include "content/public/renderer/render_frame.h" |
| 16 #include "content/public/renderer/render_thread.h" | 16 #include "content/public/renderer/render_thread.h" |
| 17 #include "content/renderer/fetchers/multi_resolution_image_resource_fetcher.h" | 17 #include "content/renderer/fetchers/multi_resolution_image_resource_fetcher.h" |
| 18 #include "mojo/common/url_type_converters.h" | |
| 19 #include "net/base/data_url.h" | 18 #include "net/base/data_url.h" |
| 20 #include "skia/ext/image_operations.h" | 19 #include "skia/ext/image_operations.h" |
| 21 #include "third_party/WebKit/public/platform/WebURLRequest.h" | 20 #include "third_party/WebKit/public/platform/WebURLRequest.h" |
| 22 #include "third_party/WebKit/public/platform/WebVector.h" | 21 #include "third_party/WebKit/public/platform/WebVector.h" |
| 23 #include "third_party/WebKit/public/web/WebLocalFrame.h" | 22 #include "third_party/WebKit/public/web/WebLocalFrame.h" |
| 24 #include "third_party/WebKit/public/web/WebView.h" | 23 #include "third_party/WebKit/public/web/WebView.h" |
| 25 #include "ui/gfx/favicon_size.h" | 24 #include "ui/gfx/favicon_size.h" |
| 26 #include "ui/gfx/geometry/size.h" | 25 #include "ui/gfx/geometry/size.h" |
| 27 #include "ui/gfx/skbitmap_operations.h" | 26 #include "ui/gfx/skbitmap_operations.h" |
| 28 #include "url/url_constants.h" | 27 #include "url/url_constants.h" |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 138 | 137 |
| 139 new ImageDownloaderImpl(render_frame, std::move(request)); | 138 new ImageDownloaderImpl(render_frame, std::move(request)); |
| 140 } | 139 } |
| 141 | 140 |
| 142 // Ensure all loaders cleared before calling blink::shutdown. | 141 // Ensure all loaders cleared before calling blink::shutdown. |
| 143 void ImageDownloaderImpl::OnRenderProcessShutdown() { | 142 void ImageDownloaderImpl::OnRenderProcessShutdown() { |
| 144 image_fetchers_.clear(); | 143 image_fetchers_.clear(); |
| 145 } | 144 } |
| 146 | 145 |
| 147 // ImageDownloader methods: | 146 // ImageDownloader methods: |
| 148 void ImageDownloaderImpl::DownloadImage(const mojo::String& url, | 147 void ImageDownloaderImpl::DownloadImage(const GURL& image_url, |
| 149 bool is_favicon, | 148 bool is_favicon, |
| 150 uint32_t max_bitmap_size, | 149 uint32_t max_bitmap_size, |
| 151 bool bypass_cache, | 150 bool bypass_cache, |
| 152 const DownloadImageCallback& callback) { | 151 const DownloadImageCallback& callback) { |
| 153 const GURL image_url = url.To<GURL>(); | |
| 154 | |
| 155 std::vector<SkBitmap> result_images; | 152 std::vector<SkBitmap> result_images; |
| 156 std::vector<gfx::Size> result_original_image_sizes; | 153 std::vector<gfx::Size> result_original_image_sizes; |
| 157 | 154 |
| 158 if (image_url.SchemeIs(url::kDataScheme)) { | 155 if (image_url.SchemeIs(url::kDataScheme)) { |
| 159 SkBitmap data_image = ImageFromDataUrl(image_url); | 156 SkBitmap data_image = ImageFromDataUrl(image_url); |
| 160 if (!data_image.empty()) { | 157 if (!data_image.empty()) { |
| 161 result_images.push_back(ResizeImage(data_image, max_bitmap_size)); | 158 result_images.push_back(ResizeImage(data_image, max_bitmap_size)); |
| 162 result_original_image_sizes.push_back( | 159 result_original_image_sizes.push_back( |
| 163 gfx::Size(data_image.width(), data_image.height())); | 160 gfx::Size(data_image.width(), data_image.height())); |
| 164 } | 161 } |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 222 const DownloadImageCallback& callback) { | 219 const DownloadImageCallback& callback) { |
| 223 callback.Run(http_status_code, mojo::Array<SkBitmap>::From(result_images), | 220 callback.Run(http_status_code, mojo::Array<SkBitmap>::From(result_images), |
| 224 result_original_image_sizes); | 221 result_original_image_sizes); |
| 225 } | 222 } |
| 226 | 223 |
| 227 void ImageDownloaderImpl::OnDestruct() { | 224 void ImageDownloaderImpl::OnDestruct() { |
| 228 delete this; | 225 delete this; |
| 229 } | 226 } |
| 230 | 227 |
| 231 } // namespace content | 228 } // namespace content |
| OLD | NEW |