| 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/logging.h" | 10 #include "base/logging.h" |
| 11 #include "base/message_loop/message_loop.h" | 11 #include "base/message_loop/message_loop.h" |
| 12 #include "content/child/image_decoder.h" | 12 #include "content/child/image_decoder.h" |
| 13 #include "content/public/renderer/render_frame.h" | 13 #include "content/public/renderer/render_frame.h" |
| 14 #include "content/renderer/fetchers/multi_resolution_image_resource_fetcher.h" | 14 #include "content/renderer/fetchers/multi_resolution_image_resource_fetcher.h" |
| 15 #include "mojo/common/url_type_converters.h" | 15 #include "mojo/common/url_type_converters.h" |
| 16 #include "mojo/converters/geometry/geometry_type_converters.h" | 16 #include "mojo/converters/geometry/geometry_type_converters.h" |
| 17 #include "net/base/data_url.h" | 17 #include "net/base/data_url.h" |
| 18 #include "skia/ext/image_operations.h" | 18 #include "skia/ext/image_operations.h" |
| 19 #include "skia/public/type_converters.h" | |
| 20 #include "third_party/WebKit/public/platform/WebURLRequest.h" | 19 #include "third_party/WebKit/public/platform/WebURLRequest.h" |
| 21 #include "third_party/WebKit/public/platform/WebVector.h" | 20 #include "third_party/WebKit/public/platform/WebVector.h" |
| 22 #include "third_party/WebKit/public/web/WebLocalFrame.h" | 21 #include "third_party/WebKit/public/web/WebLocalFrame.h" |
| 23 #include "third_party/WebKit/public/web/WebView.h" | 22 #include "third_party/WebKit/public/web/WebView.h" |
| 24 #include "ui/gfx/favicon_size.h" | 23 #include "ui/gfx/favicon_size.h" |
| 25 #include "ui/gfx/geometry/size.h" | 24 #include "ui/gfx/geometry/size.h" |
| 26 #include "ui/gfx/skbitmap_operations.h" | 25 #include "ui/gfx/skbitmap_operations.h" |
| 27 #include "url/url_constants.h" | 26 #include "url/url_constants.h" |
| 28 | 27 |
| 29 using blink::WebFrame; | 28 using blink::WebFrame; |
| (...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 155 gfx::Size(data_image.width(), data_image.height())); | 154 gfx::Size(data_image.width(), data_image.height())); |
| 156 } | 155 } |
| 157 } else { | 156 } else { |
| 158 if (FetchImage(image_url, is_favicon, max_image_size, bypass_cache, | 157 if (FetchImage(image_url, is_favicon, max_image_size, bypass_cache, |
| 159 callback)) { | 158 callback)) { |
| 160 // Will complete asynchronously via ImageDownloaderImpl::DidFetchImage | 159 // Will complete asynchronously via ImageDownloaderImpl::DidFetchImage |
| 161 return; | 160 return; |
| 162 } | 161 } |
| 163 } | 162 } |
| 164 | 163 |
| 165 ReplyDownloadResult(0, result_images, result_original_image_sizes, callback); | 164 ReplyDownloadResult(0, &result_images, result_original_image_sizes, callback); |
| 166 } | 165 } |
| 167 | 166 |
| 168 bool ImageDownloaderImpl::FetchImage(const GURL& image_url, | 167 bool ImageDownloaderImpl::FetchImage(const GURL& image_url, |
| 169 bool is_favicon, | 168 bool is_favicon, |
| 170 uint32_t max_image_size, | 169 uint32_t max_image_size, |
| 171 bool bypass_cache, | 170 bool bypass_cache, |
| 172 const DownloadImageCallback& callback) { | 171 const DownloadImageCallback& callback) { |
| 173 blink::WebLocalFrame* frame = render_frame()->GetWebFrame(); | 172 blink::WebLocalFrame* frame = render_frame()->GetWebFrame(); |
| 174 DCHECK(frame); | 173 DCHECK(frame); |
| 175 | 174 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 187 void ImageDownloaderImpl::DidFetchImage( | 186 void ImageDownloaderImpl::DidFetchImage( |
| 188 uint32_t max_image_size, | 187 uint32_t max_image_size, |
| 189 const DownloadImageCallback& callback, | 188 const DownloadImageCallback& callback, |
| 190 MultiResolutionImageResourceFetcher* fetcher, | 189 MultiResolutionImageResourceFetcher* fetcher, |
| 191 const std::vector<SkBitmap>& images) { | 190 const std::vector<SkBitmap>& images) { |
| 192 std::vector<SkBitmap> result_images; | 191 std::vector<SkBitmap> result_images; |
| 193 std::vector<gfx::Size> result_original_image_sizes; | 192 std::vector<gfx::Size> result_original_image_sizes; |
| 194 FilterAndResizeImagesForMaximalSize(images, max_image_size, &result_images, | 193 FilterAndResizeImagesForMaximalSize(images, max_image_size, &result_images, |
| 195 &result_original_image_sizes); | 194 &result_original_image_sizes); |
| 196 | 195 |
| 197 ReplyDownloadResult(fetcher->http_status_code(), result_images, | 196 ReplyDownloadResult(fetcher->http_status_code(), &result_images, |
| 198 result_original_image_sizes, callback); | 197 result_original_image_sizes, callback); |
| 199 | 198 |
| 200 // Remove the image fetcher from our pending list. We're in the callback from | 199 // Remove the image fetcher from our pending list. We're in the callback from |
| 201 // MultiResolutionImageResourceFetcher, best to delay deletion. | 200 // MultiResolutionImageResourceFetcher, best to delay deletion. |
| 202 ImageResourceFetcherList::iterator iter = | 201 ImageResourceFetcherList::iterator iter = |
| 203 std::find(image_fetchers_.begin(), image_fetchers_.end(), fetcher); | 202 std::find(image_fetchers_.begin(), image_fetchers_.end(), fetcher); |
| 204 if (iter != image_fetchers_.end()) { | 203 if (iter != image_fetchers_.end()) { |
| 205 image_fetchers_.weak_erase(iter); | 204 image_fetchers_.weak_erase(iter); |
| 206 base::MessageLoop::current()->DeleteSoon(FROM_HERE, fetcher); | 205 base::MessageLoop::current()->DeleteSoon(FROM_HERE, fetcher); |
| 207 } | 206 } |
| 208 } | 207 } |
| 209 | 208 |
| 210 void ImageDownloaderImpl::ReplyDownloadResult( | 209 void ImageDownloaderImpl::ReplyDownloadResult( |
| 211 int32_t http_status_code, | 210 int32_t http_status_code, |
| 212 const std::vector<SkBitmap>& result_images, | 211 std::vector<SkBitmap>* result_images, |
| 213 const std::vector<gfx::Size>& result_original_image_sizes, | 212 const std::vector<gfx::Size>& result_original_image_sizes, |
| 214 const DownloadImageCallback& callback) { | 213 const DownloadImageCallback& callback) { |
| 215 image_downloader::DownloadResultPtr result = | 214 image_downloader::DownloadResultPtr result = |
| 216 image_downloader::DownloadResult::New(); | 215 image_downloader::DownloadResult::New(); |
| 217 | 216 |
| 218 result->http_status_code = http_status_code; | 217 result->http_status_code = http_status_code; |
| 219 result->images = mojo::Array<skia::BitmapPtr>::From(result_images); | 218 result->images.Swap(result_images); |
| 220 result->original_image_sizes = | 219 result->original_image_sizes = |
| 221 mojo::Array<mojo::SizePtr>::From(result_original_image_sizes); | 220 mojo::Array<mojo::SizePtr>::From(result_original_image_sizes); |
| 222 | 221 |
| 223 callback.Run(std::move(result)); | 222 callback.Run(std::move(result)); |
| 224 } | 223 } |
| 225 | 224 |
| 226 } // namespace content | 225 } // namespace content |
| OLD | NEW |