| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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_loading_helper.h" | 5 #include "content/renderer/image_loading_helper.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/message_loop/message_loop.h" | 8 #include "base/message_loop/message_loop.h" |
| 9 #include "content/child/image_decoder.h" | 9 #include "content/child/image_decoder.h" |
| 10 #include "content/common/image_messages.h" | 10 #include "content/common/image_messages.h" |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 97 | 97 |
| 98 namespace content { | 98 namespace content { |
| 99 | 99 |
| 100 ImageLoadingHelper::ImageLoadingHelper(RenderFrame* render_frame) | 100 ImageLoadingHelper::ImageLoadingHelper(RenderFrame* render_frame) |
| 101 : RenderFrameObserver(render_frame) { | 101 : RenderFrameObserver(render_frame) { |
| 102 } | 102 } |
| 103 | 103 |
| 104 ImageLoadingHelper::~ImageLoadingHelper() { | 104 ImageLoadingHelper::~ImageLoadingHelper() { |
| 105 } | 105 } |
| 106 | 106 |
| 107 void ImageLoadingHelper::OnDownloadImage(int id, | 107 void ImageLoadingHelper::OnDownloadImage( |
| 108 const GURL& image_url, | 108 int id, |
| 109 bool is_favicon, | 109 const GURL& image_url, |
| 110 uint32_t max_image_size) { | 110 bool is_favicon, |
| 111 uint32_t max_image_size, |
| 112 blink::WebURLRequest::CachePolicy cache_policy) { |
| 111 std::vector<SkBitmap> result_images; | 113 std::vector<SkBitmap> result_images; |
| 112 std::vector<gfx::Size> result_original_image_sizes; | 114 std::vector<gfx::Size> result_original_image_sizes; |
| 113 if (image_url.SchemeIs(url::kDataScheme)) { | 115 if (image_url.SchemeIs(url::kDataScheme)) { |
| 114 SkBitmap data_image = ImageFromDataUrl(image_url); | 116 SkBitmap data_image = ImageFromDataUrl(image_url); |
| 115 if (!data_image.empty()) { | 117 if (!data_image.empty()) { |
| 116 result_images.push_back(ResizeImage(data_image, max_image_size)); | 118 result_images.push_back(ResizeImage(data_image, max_image_size)); |
| 117 result_original_image_sizes.push_back( | 119 result_original_image_sizes.push_back( |
| 118 gfx::Size(data_image.width(), data_image.height())); | 120 gfx::Size(data_image.width(), data_image.height())); |
| 119 } | 121 } |
| 120 } else { | 122 } else { |
| 121 if (DownloadImage(id, image_url, is_favicon, max_image_size)) { | 123 if (DownloadImage(id, image_url, is_favicon, max_image_size, |
| 124 cache_policy)) { |
| 122 // Will complete asynchronously via ImageLoadingHelper::DidDownloadImage | 125 // Will complete asynchronously via ImageLoadingHelper::DidDownloadImage |
| 123 return; | 126 return; |
| 124 } | 127 } |
| 125 } | 128 } |
| 126 | 129 |
| 127 Send(new ImageHostMsg_DidDownloadImage(routing_id(), | 130 Send(new ImageHostMsg_DidDownloadImage(routing_id(), |
| 128 id, | 131 id, |
| 129 0, | 132 0, |
| 130 image_url, | 133 image_url, |
| 131 result_images, | 134 result_images, |
| 132 result_original_image_sizes)); | 135 result_original_image_sizes)); |
| 133 } | 136 } |
| 134 | 137 |
| 135 bool ImageLoadingHelper::DownloadImage(int id, | 138 bool ImageLoadingHelper::DownloadImage( |
| 136 const GURL& image_url, | 139 int id, |
| 137 bool is_favicon, | 140 const GURL& image_url, |
| 138 uint32_t max_image_size) { | 141 bool is_favicon, |
| 142 uint32_t max_image_size, |
| 143 blink::WebURLRequest::CachePolicy cache_policy) { |
| 139 // Create an image resource fetcher and assign it with a call back object. | 144 // Create an image resource fetcher and assign it with a call back object. |
| 140 image_fetchers_.push_back(new MultiResolutionImageResourceFetcher( | 145 image_fetchers_.push_back(new MultiResolutionImageResourceFetcher( |
| 141 image_url, | 146 image_url, |
| 142 render_frame()->GetWebFrame(), | 147 render_frame()->GetWebFrame(), |
| 143 id, | 148 id, |
| 144 is_favicon ? WebURLRequest::RequestContextFavicon | 149 is_favicon ? WebURLRequest::RequestContextFavicon |
| 145 : WebURLRequest::RequestContextImage, | 150 : WebURLRequest::RequestContextImage, |
| 151 cache_policy, |
| 146 base::Bind(&ImageLoadingHelper::DidDownloadImage, | 152 base::Bind(&ImageLoadingHelper::DidDownloadImage, |
| 147 base::Unretained(this), | 153 base::Unretained(this), |
| 148 max_image_size))); | 154 max_image_size))); |
| 149 return true; | 155 return true; |
| 150 } | 156 } |
| 151 | 157 |
| 152 void ImageLoadingHelper::DidDownloadImage( | 158 void ImageLoadingHelper::DidDownloadImage( |
| 153 uint32_t max_image_size, | 159 uint32_t max_image_size, |
| 154 MultiResolutionImageResourceFetcher* fetcher, | 160 MultiResolutionImageResourceFetcher* fetcher, |
| 155 const std::vector<SkBitmap>& images) { | 161 const std::vector<SkBitmap>& images) { |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 194 bool handled = true; | 200 bool handled = true; |
| 195 IPC_BEGIN_MESSAGE_MAP(ImageLoadingHelper, message) | 201 IPC_BEGIN_MESSAGE_MAP(ImageLoadingHelper, message) |
| 196 IPC_MESSAGE_HANDLER(ImageMsg_DownloadImage, OnDownloadImage) | 202 IPC_MESSAGE_HANDLER(ImageMsg_DownloadImage, OnDownloadImage) |
| 197 IPC_MESSAGE_UNHANDLED(handled = false) | 203 IPC_MESSAGE_UNHANDLED(handled = false) |
| 198 IPC_END_MESSAGE_MAP() | 204 IPC_END_MESSAGE_MAP() |
| 199 | 205 |
| 200 return handled; | 206 return handled; |
| 201 } | 207 } |
| 202 | 208 |
| 203 } // namespace content | 209 } // namespace content |
| OLD | NEW |