Chromium Code Reviews| Index: content/browser/web_contents/web_contents_impl.cc |
| diff --git a/content/browser/web_contents/web_contents_impl.cc b/content/browser/web_contents/web_contents_impl.cc |
| index 2af90aecf7e9f8bc0ae9737d16266481040e3efc..db612dfdc6b298fc744385ffa33f0a2f9e13f24f 100644 |
| --- a/content/browser/web_contents/web_contents_impl.cc |
| +++ b/content/browser/web_contents/web_contents_impl.cc |
| @@ -152,21 +152,6 @@ const char kWebContentsAndroidKey[] = "web_contents_android"; |
| base::LazyInstance<std::vector<WebContentsImpl::CreatedCallback> > |
| g_created_callbacks = LAZY_INSTANCE_INITIALIZER; |
| -static void DidDownloadImage(const WebContents::ImageDownloadCallback& callback, |
| - int id, |
| - const GURL& image_url, |
| - image_downloader::DownloadResultPtr result) { |
| - DCHECK(result); |
| - |
| - const std::vector<SkBitmap> images = |
| - result->images.To<std::vector<SkBitmap>>(); |
| - const std::vector<gfx::Size> original_image_sizes = |
| - result->original_image_sizes.To<std::vector<gfx::Size>>(); |
| - |
| - callback.Run(id, result->http_status_code, image_url, images, |
| - original_image_sizes); |
| -} |
| - |
| void NotifyCacheOnIO( |
| scoped_refptr<net::URLRequestContextGetter> request_context, |
| const GURL& url, |
| @@ -376,6 +361,7 @@ WebContentsImpl::WebContentsImpl(BrowserContext* browser_context) |
| audio_stream_monitor_(this), |
| virtual_keyboard_requested_(false), |
| page_scale_factor_is_one_(true), |
| + download_image_weak_factory_(this), |
| loading_weak_factory_(this) { |
| frame_tree_.SetFrameRemoveListener( |
| base::Bind(&WebContentsImpl::OnFrameRemoved, |
| @@ -2823,12 +2809,14 @@ int WebContentsImpl::DownloadImage( |
| // Android), the downloader service will be invalid. Pre-Mojo, this would |
| // hang the callback indefinetly since the IPC would be dropped. Now, |
| // respond with a 400 HTTP error code to indicate that something went wrong. |
| + image_downloader::DownloadResultPtr result = |
| + image_downloader::DownloadResult::New(); |
| + result->http_status_code = 400; |
| BrowserThread::PostTask( |
| BrowserThread::UI, FROM_HERE, |
| - base::Bind(&WebContents::ImageDownloadCallback::Run, |
| - base::Owned(new ImageDownloadCallback(callback)), |
| - download_id, 400, url, std::vector<SkBitmap>(), |
| - std::vector<gfx::Size>())); |
| + base::Bind(&WebContentsImpl::OnDidDownloadImage, |
| + download_image_weak_factory_.GetWeakPtr(), callback, |
| + download_id, url, base::Passed(&result))); |
| return download_id; |
| } |
| @@ -2841,8 +2829,9 @@ int WebContentsImpl::DownloadImage( |
| req->bypass_cache = bypass_cache; |
| mojo_image_downloader->DownloadImage( |
| - std::move(req), |
| - base::Bind(&DidDownloadImage, callback, download_id, url)); |
| + std::move(req), base::Bind(&WebContentsImpl::OnDidDownloadImage, |
| + download_image_weak_factory_.GetWeakPtr(), |
| + callback, download_id, url)); |
| return download_id; |
| } |
| @@ -4623,6 +4612,22 @@ bool WebContentsImpl::GetAllowOtherViews() { |
| #endif |
| +void WebContentsImpl::OnDidDownloadImage( |
| + const ImageDownloadCallback& callback, |
| + int id, |
| + const GURL& image_url, |
| + image_downloader::DownloadResultPtr result) { |
| + DCHECK(result); |
|
jam
2016/02/12 23:31:42
this is unnecessary. in release builds, it does no
|
| + |
| + const std::vector<SkBitmap> images = |
| + result->images.To<std::vector<SkBitmap>>(); |
| + const std::vector<gfx::Size> original_image_sizes = |
| + result->original_image_sizes.To<std::vector<gfx::Size>>(); |
| + |
| + callback.Run(id, result->http_status_code, image_url, images, |
| + original_image_sizes); |
| +} |
| + |
| void WebContentsImpl::OnDialogClosed(int render_process_id, |
| int render_frame_id, |
| IPC::Message* reply_msg, |