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 bool bypass_cache) { |
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 bypass_cache)) { |
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 bool bypass_cache) { |
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, render_frame()->GetWebFrame(), id, |
142 render_frame()->GetWebFrame(), | |
143 id, | |
144 is_favicon ? WebURLRequest::RequestContextFavicon | 147 is_favicon ? WebURLRequest::RequestContextFavicon |
145 : WebURLRequest::RequestContextImage, | 148 : WebURLRequest::RequestContextImage, |
146 base::Bind(&ImageLoadingHelper::DidDownloadImage, | 149 bypass_cache ? WebURLRequest::ReloadBypassingCache |
147 base::Unretained(this), | 150 : WebURLRequest::UseProtocolCachePolicy, |
| 151 base::Bind(&ImageLoadingHelper::DidDownloadImage, base::Unretained(this), |
148 max_image_size))); | 152 max_image_size))); |
149 return true; | 153 return true; |
150 } | 154 } |
151 | 155 |
152 void ImageLoadingHelper::DidDownloadImage( | 156 void ImageLoadingHelper::DidDownloadImage( |
153 uint32_t max_image_size, | 157 uint32_t max_image_size, |
154 MultiResolutionImageResourceFetcher* fetcher, | 158 MultiResolutionImageResourceFetcher* fetcher, |
155 const std::vector<SkBitmap>& images) { | 159 const std::vector<SkBitmap>& images) { |
156 std::vector<SkBitmap> result_images; | 160 std::vector<SkBitmap> result_images; |
157 std::vector<gfx::Size> result_original_image_sizes; | 161 std::vector<gfx::Size> result_original_image_sizes; |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
194 bool handled = true; | 198 bool handled = true; |
195 IPC_BEGIN_MESSAGE_MAP(ImageLoadingHelper, message) | 199 IPC_BEGIN_MESSAGE_MAP(ImageLoadingHelper, message) |
196 IPC_MESSAGE_HANDLER(ImageMsg_DownloadImage, OnDownloadImage) | 200 IPC_MESSAGE_HANDLER(ImageMsg_DownloadImage, OnDownloadImage) |
197 IPC_MESSAGE_UNHANDLED(handled = false) | 201 IPC_MESSAGE_UNHANDLED(handled = false) |
198 IPC_END_MESSAGE_MAP() | 202 IPC_END_MESSAGE_MAP() |
199 | 203 |
200 return handled; | 204 return handled; |
201 } | 205 } |
202 | 206 |
203 } // namespace content | 207 } // namespace content |
OLD | NEW |