Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(37)

Side by Side Diff: content/browser/web_contents/web_contents_impl.cc

Issue 1685343004: Don't call WebContents::DownloadImage() callback if the WebContents were deleted (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « content/browser/web_contents/web_contents_impl.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/browser/web_contents/web_contents_impl.h" 5 #include "content/browser/web_contents/web_contents_impl.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <cmath> 9 #include <cmath>
10 #include <utility> 10 #include <utility>
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
145 const int kMinimumDelayBetweenLoadingUpdatesMS = 100; 145 const int kMinimumDelayBetweenLoadingUpdatesMS = 100;
146 const char kDotGoogleDotCom[] = ".google.com"; 146 const char kDotGoogleDotCom[] = ".google.com";
147 147
148 #if defined(OS_ANDROID) 148 #if defined(OS_ANDROID)
149 const char kWebContentsAndroidKey[] = "web_contents_android"; 149 const char kWebContentsAndroidKey[] = "web_contents_android";
150 #endif // OS_ANDROID 150 #endif // OS_ANDROID
151 151
152 base::LazyInstance<std::vector<WebContentsImpl::CreatedCallback> > 152 base::LazyInstance<std::vector<WebContentsImpl::CreatedCallback> >
153 g_created_callbacks = LAZY_INSTANCE_INITIALIZER; 153 g_created_callbacks = LAZY_INSTANCE_INITIALIZER;
154 154
155 static void DidDownloadImage(const WebContents::ImageDownloadCallback& callback,
156 int id,
157 const GURL& image_url,
158 image_downloader::DownloadResultPtr result) {
159 DCHECK(result);
160
161 const std::vector<SkBitmap> images =
162 result->images.To<std::vector<SkBitmap>>();
163 const std::vector<gfx::Size> original_image_sizes =
164 result->original_image_sizes.To<std::vector<gfx::Size>>();
165
166 callback.Run(id, result->http_status_code, image_url, images,
167 original_image_sizes);
168 }
169
170 void NotifyCacheOnIO( 155 void NotifyCacheOnIO(
171 scoped_refptr<net::URLRequestContextGetter> request_context, 156 scoped_refptr<net::URLRequestContextGetter> request_context,
172 const GURL& url, 157 const GURL& url,
173 const std::string& http_method) { 158 const std::string& http_method) {
174 net::HttpCache* cache = request_context->GetURLRequestContext()-> 159 net::HttpCache* cache = request_context->GetURLRequestContext()->
175 http_transaction_factory()->GetCache(); 160 http_transaction_factory()->GetCache();
176 if (cache) 161 if (cache)
177 cache->OnExternalCacheHit(url, http_method); 162 cache->OnExternalCacheHit(url, http_method);
178 } 163 }
179 164
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after
369 fullscreen_widget_had_focus_at_shutdown_(false), 354 fullscreen_widget_had_focus_at_shutdown_(false),
370 is_subframe_(false), 355 is_subframe_(false),
371 force_disable_overscroll_content_(false), 356 force_disable_overscroll_content_(false),
372 last_dialog_suppressed_(false), 357 last_dialog_suppressed_(false),
373 geolocation_service_context_(new GeolocationServiceContext()), 358 geolocation_service_context_(new GeolocationServiceContext()),
374 accessibility_mode_( 359 accessibility_mode_(
375 BrowserAccessibilityStateImpl::GetInstance()->accessibility_mode()), 360 BrowserAccessibilityStateImpl::GetInstance()->accessibility_mode()),
376 audio_stream_monitor_(this), 361 audio_stream_monitor_(this),
377 virtual_keyboard_requested_(false), 362 virtual_keyboard_requested_(false),
378 page_scale_factor_is_one_(true), 363 page_scale_factor_is_one_(true),
379 loading_weak_factory_(this) { 364 loading_weak_factory_(this),
365 weak_factory_(this) {
380 frame_tree_.SetFrameRemoveListener( 366 frame_tree_.SetFrameRemoveListener(
381 base::Bind(&WebContentsImpl::OnFrameRemoved, 367 base::Bind(&WebContentsImpl::OnFrameRemoved,
382 base::Unretained(this))); 368 base::Unretained(this)));
383 #if defined(OS_ANDROID) 369 #if defined(OS_ANDROID)
384 media_web_contents_observer_.reset(new MediaWebContentsObserverAndroid(this)); 370 media_web_contents_observer_.reset(new MediaWebContentsObserverAndroid(this));
385 #else 371 #else
386 media_web_contents_observer_.reset(new MediaWebContentsObserver(this)); 372 media_web_contents_observer_.reset(new MediaWebContentsObserver(this));
387 #endif 373 #endif
388 loader_io_thread_notifier_.reset(new LoaderIOThreadNotifier(this)); 374 loader_io_thread_notifier_.reset(new LoaderIOThreadNotifier(this));
389 wake_lock_service_context_.reset(new WakeLockServiceContext(this)); 375 wake_lock_service_context_.reset(new WakeLockServiceContext(this));
(...skipping 2428 matching lines...) Expand 10 before | Expand all | Expand 10 after
2818 DCHECK_CURRENTLY_ON(BrowserThread::UI); 2804 DCHECK_CURRENTLY_ON(BrowserThread::UI);
2819 static int next_image_download_id = 0; 2805 static int next_image_download_id = 0;
2820 const image_downloader::ImageDownloaderPtr& mojo_image_downloader = 2806 const image_downloader::ImageDownloaderPtr& mojo_image_downloader =
2821 GetMainFrame()->GetMojoImageDownloader(); 2807 GetMainFrame()->GetMojoImageDownloader();
2822 const int download_id = ++next_image_download_id; 2808 const int download_id = ++next_image_download_id;
2823 if (!mojo_image_downloader) { 2809 if (!mojo_image_downloader) {
2824 // If the renderer process is dead (i.e. crash, or memory pressure on 2810 // If the renderer process is dead (i.e. crash, or memory pressure on
2825 // Android), the downloader service will be invalid. Pre-Mojo, this would 2811 // Android), the downloader service will be invalid. Pre-Mojo, this would
2826 // hang the callback indefinetly since the IPC would be dropped. Now, 2812 // hang the callback indefinetly since the IPC would be dropped. Now,
2827 // respond with a 400 HTTP error code to indicate that something went wrong. 2813 // respond with a 400 HTTP error code to indicate that something went wrong.
2814 image_downloader::DownloadResultPtr result =
2815 image_downloader::DownloadResult::New();
2816 result->http_status_code = 400;
2828 BrowserThread::PostTask( 2817 BrowserThread::PostTask(
2829 BrowserThread::UI, FROM_HERE, 2818 BrowserThread::UI, FROM_HERE,
2830 base::Bind(&WebContents::ImageDownloadCallback::Run, 2819 base::Bind(&WebContentsImpl::OnDidDownloadImage,
2831 base::Owned(new ImageDownloadCallback(callback)), 2820 weak_factory_.GetWeakPtr(), callback, download_id, url,
2832 download_id, 400, url, std::vector<SkBitmap>(), 2821 base::Passed(&result)));
2833 std::vector<gfx::Size>()));
2834 return download_id; 2822 return download_id;
2835 } 2823 }
2836 2824
2837 image_downloader::DownloadRequestPtr req = 2825 image_downloader::DownloadRequestPtr req =
2838 image_downloader::DownloadRequest::New(); 2826 image_downloader::DownloadRequest::New();
2839 2827
2840 req->url = mojo::String::From(url); 2828 req->url = mojo::String::From(url);
2841 req->is_favicon = is_favicon; 2829 req->is_favicon = is_favicon;
2842 req->max_bitmap_size = max_bitmap_size; 2830 req->max_bitmap_size = max_bitmap_size;
2843 req->bypass_cache = bypass_cache; 2831 req->bypass_cache = bypass_cache;
2844 2832
2845 mojo_image_downloader->DownloadImage( 2833 mojo_image_downloader->DownloadImage(
2846 std::move(req), 2834 std::move(req), base::Bind(&WebContentsImpl::OnDidDownloadImage,
2847 base::Bind(&DidDownloadImage, callback, download_id, url)); 2835 weak_factory_.GetWeakPtr(), callback,
2836 download_id, url));
2848 return download_id; 2837 return download_id;
2849 } 2838 }
2850 2839
2851 bool WebContentsImpl::IsSubframe() const { 2840 bool WebContentsImpl::IsSubframe() const {
2852 return is_subframe_; 2841 return is_subframe_;
2853 } 2842 }
2854 2843
2855 void WebContentsImpl::Find(int request_id, 2844 void WebContentsImpl::Find(int request_id,
2856 const base::string16& search_text, 2845 const base::string16& search_text,
2857 const blink::WebFindOptions& options) { 2846 const blink::WebFindOptions& options) {
(...skipping 1760 matching lines...) Expand 10 before | Expand all | Expand 10 after
4618 void WebContentsImpl::SetAllowOtherViews(bool allow) { 4607 void WebContentsImpl::SetAllowOtherViews(bool allow) {
4619 view_->SetAllowOtherViews(allow); 4608 view_->SetAllowOtherViews(allow);
4620 } 4609 }
4621 4610
4622 bool WebContentsImpl::GetAllowOtherViews() { 4611 bool WebContentsImpl::GetAllowOtherViews() {
4623 return view_->GetAllowOtherViews(); 4612 return view_->GetAllowOtherViews();
4624 } 4613 }
4625 4614
4626 #endif 4615 #endif
4627 4616
4617 void WebContentsImpl::OnDidDownloadImage(
4618 const ImageDownloadCallback& callback,
4619 int id,
4620 const GURL& image_url,
4621 image_downloader::DownloadResultPtr result) {
4622 const std::vector<SkBitmap> images =
4623 result->images.To<std::vector<SkBitmap>>();
4624 const std::vector<gfx::Size> original_image_sizes =
4625 result->original_image_sizes.To<std::vector<gfx::Size>>();
4626
4627 callback.Run(id, result->http_status_code, image_url, images,
4628 original_image_sizes);
4629 }
4630
4628 void WebContentsImpl::OnDialogClosed(int render_process_id, 4631 void WebContentsImpl::OnDialogClosed(int render_process_id,
4629 int render_frame_id, 4632 int render_frame_id,
4630 IPC::Message* reply_msg, 4633 IPC::Message* reply_msg,
4631 bool dialog_was_suppressed, 4634 bool dialog_was_suppressed,
4632 bool success, 4635 bool success,
4633 const base::string16& user_input) { 4636 const base::string16& user_input) {
4634 RenderFrameHostImpl* rfh = RenderFrameHostImpl::FromID(render_process_id, 4637 RenderFrameHostImpl* rfh = RenderFrameHostImpl::FromID(render_process_id,
4635 render_frame_id); 4638 render_frame_id);
4636 last_dialog_suppressed_ = dialog_was_suppressed; 4639 last_dialog_suppressed_ = dialog_was_suppressed;
4637 4640
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
4758 const WebContentsObserver::MediaPlayerId& id) { 4761 const WebContentsObserver::MediaPlayerId& id) {
4759 FOR_EACH_OBSERVER(WebContentsObserver, observers_, MediaStartedPlaying(id)); 4762 FOR_EACH_OBSERVER(WebContentsObserver, observers_, MediaStartedPlaying(id));
4760 } 4763 }
4761 4764
4762 void WebContentsImpl::MediaStoppedPlaying( 4765 void WebContentsImpl::MediaStoppedPlaying(
4763 const WebContentsObserver::MediaPlayerId& id) { 4766 const WebContentsObserver::MediaPlayerId& id) {
4764 FOR_EACH_OBSERVER(WebContentsObserver, observers_, MediaStoppedPlaying(id)); 4767 FOR_EACH_OBSERVER(WebContentsObserver, observers_, MediaStoppedPlaying(id));
4765 } 4768 }
4766 4769
4767 } // namespace content 4770 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/web_contents/web_contents_impl.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698