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

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

Issue 1730363003: Don't call WebContents::DownloadImage() callback if the WebContents were deleted (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@2623
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 136 matching lines...) Expand 10 before | Expand all | Expand 10 after
147 const int kMinimumDelayBetweenLoadingUpdatesMS = 100; 147 const int kMinimumDelayBetweenLoadingUpdatesMS = 100;
148 const char kDotGoogleDotCom[] = ".google.com"; 148 const char kDotGoogleDotCom[] = ".google.com";
149 149
150 #if defined(OS_ANDROID) 150 #if defined(OS_ANDROID)
151 const char kWebContentsAndroidKey[] = "web_contents_android"; 151 const char kWebContentsAndroidKey[] = "web_contents_android";
152 #endif // OS_ANDROID 152 #endif // OS_ANDROID
153 153
154 base::LazyInstance<std::vector<WebContentsImpl::CreatedCallback> > 154 base::LazyInstance<std::vector<WebContentsImpl::CreatedCallback> >
155 g_created_callbacks = LAZY_INSTANCE_INITIALIZER; 155 g_created_callbacks = LAZY_INSTANCE_INITIALIZER;
156 156
157 static void DidDownloadImage(const WebContents::ImageDownloadCallback& callback,
158 int id,
159 const GURL& image_url,
160 image_downloader::DownloadResultPtr result) {
161 DCHECK(result);
162
163 const std::vector<SkBitmap> images =
164 result->images.To<std::vector<SkBitmap>>();
165 const std::vector<gfx::Size> original_image_sizes =
166 result->original_image_sizes.To<std::vector<gfx::Size>>();
167
168 callback.Run(id, result->http_status_code, image_url, images,
169 original_image_sizes);
170 }
171
172 void NotifyCacheOnIO( 157 void NotifyCacheOnIO(
173 scoped_refptr<net::URLRequestContextGetter> request_context, 158 scoped_refptr<net::URLRequestContextGetter> request_context,
174 const GURL& url, 159 const GURL& url,
175 const std::string& http_method) { 160 const std::string& http_method) {
176 net::HttpCache* cache = request_context->GetURLRequestContext()-> 161 net::HttpCache* cache = request_context->GetURLRequestContext()->
177 http_transaction_factory()->GetCache(); 162 http_transaction_factory()->GetCache();
178 if (cache) 163 if (cache)
179 cache->OnExternalCacheHit(url, http_method); 164 cache->OnExternalCacheHit(url, http_method);
180 } 165 }
181 166
(...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after
408 fullscreen_widget_had_focus_at_shutdown_(false), 393 fullscreen_widget_had_focus_at_shutdown_(false),
409 is_subframe_(false), 394 is_subframe_(false),
410 force_disable_overscroll_content_(false), 395 force_disable_overscroll_content_(false),
411 last_dialog_suppressed_(false), 396 last_dialog_suppressed_(false),
412 geolocation_service_context_(new GeolocationServiceContext()), 397 geolocation_service_context_(new GeolocationServiceContext()),
413 accessibility_mode_( 398 accessibility_mode_(
414 BrowserAccessibilityStateImpl::GetInstance()->accessibility_mode()), 399 BrowserAccessibilityStateImpl::GetInstance()->accessibility_mode()),
415 audio_stream_monitor_(this), 400 audio_stream_monitor_(this),
416 virtual_keyboard_requested_(false), 401 virtual_keyboard_requested_(false),
417 page_scale_factor_is_one_(true), 402 page_scale_factor_is_one_(true),
418 loading_weak_factory_(this) { 403 loading_weak_factory_(this),
404 weak_factory_(this) {
419 frame_tree_.SetFrameRemoveListener( 405 frame_tree_.SetFrameRemoveListener(
420 base::Bind(&WebContentsImpl::OnFrameRemoved, 406 base::Bind(&WebContentsImpl::OnFrameRemoved,
421 base::Unretained(this))); 407 base::Unretained(this)));
422 #if defined(OS_ANDROID) 408 #if defined(OS_ANDROID)
423 media_web_contents_observer_.reset(new MediaWebContentsObserverAndroid(this)); 409 media_web_contents_observer_.reset(new MediaWebContentsObserverAndroid(this));
424 #else 410 #else
425 media_web_contents_observer_.reset(new MediaWebContentsObserver(this)); 411 media_web_contents_observer_.reset(new MediaWebContentsObserver(this));
426 #endif 412 #endif
427 wake_lock_service_context_.reset(new WakeLockServiceContext(this)); 413 wake_lock_service_context_.reset(new WakeLockServiceContext(this));
428 } 414 }
(...skipping 2382 matching lines...) Expand 10 before | Expand all | Expand 10 after
2811 DCHECK_CURRENTLY_ON(BrowserThread::UI); 2797 DCHECK_CURRENTLY_ON(BrowserThread::UI);
2812 static int next_image_download_id = 0; 2798 static int next_image_download_id = 0;
2813 const image_downloader::ImageDownloaderPtr& mojo_image_downloader = 2799 const image_downloader::ImageDownloaderPtr& mojo_image_downloader =
2814 GetMainFrame()->GetMojoImageDownloader(); 2800 GetMainFrame()->GetMojoImageDownloader();
2815 const int download_id = ++next_image_download_id; 2801 const int download_id = ++next_image_download_id;
2816 if (!mojo_image_downloader) { 2802 if (!mojo_image_downloader) {
2817 // If the renderer process is dead (i.e. crash, or memory pressure on 2803 // If the renderer process is dead (i.e. crash, or memory pressure on
2818 // Android), the downloader service will be invalid. Pre-Mojo, this would 2804 // Android), the downloader service will be invalid. Pre-Mojo, this would
2819 // hang the callback indefinetly since the IPC would be dropped. Now, 2805 // hang the callback indefinetly since the IPC would be dropped. Now,
2820 // respond with a 400 HTTP error code to indicate that something went wrong. 2806 // respond with a 400 HTTP error code to indicate that something went wrong.
2807 image_downloader::DownloadResultPtr result =
2808 image_downloader::DownloadResult::New();
2809 result->http_status_code = 400;
2821 BrowserThread::PostTask( 2810 BrowserThread::PostTask(
2822 BrowserThread::UI, FROM_HERE, 2811 BrowserThread::UI, FROM_HERE,
2823 base::Bind(&WebContents::ImageDownloadCallback::Run, 2812 base::Bind(&WebContentsImpl::OnDidDownloadImage,
2824 base::Owned(new ImageDownloadCallback(callback)), 2813 weak_factory_.GetWeakPtr(), callback, download_id, url,
2825 download_id, 400, url, std::vector<SkBitmap>(), 2814 base::Passed(&result)));
2826 std::vector<gfx::Size>()));
2827 return download_id; 2815 return download_id;
2828 } 2816 }
2829 2817
2830 image_downloader::DownloadRequestPtr req = 2818 image_downloader::DownloadRequestPtr req =
2831 image_downloader::DownloadRequest::New(); 2819 image_downloader::DownloadRequest::New();
2832 2820
2833 req->url = mojo::String::From(url); 2821 req->url = mojo::String::From(url);
2834 req->is_favicon = is_favicon; 2822 req->is_favicon = is_favicon;
2835 req->max_bitmap_size = max_bitmap_size; 2823 req->max_bitmap_size = max_bitmap_size;
2836 req->bypass_cache = bypass_cache; 2824 req->bypass_cache = bypass_cache;
2837 2825
2838 mojo_image_downloader->DownloadImage( 2826 mojo_image_downloader->DownloadImage(
2839 std::move(req), 2827 std::move(req), base::Bind(&WebContentsImpl::OnDidDownloadImage,
2840 base::Bind(&DidDownloadImage, callback, download_id, url)); 2828 weak_factory_.GetWeakPtr(), callback,
2829 download_id, url));
2841 return download_id; 2830 return download_id;
2842 } 2831 }
2843 2832
2844 bool WebContentsImpl::IsSubframe() const { 2833 bool WebContentsImpl::IsSubframe() const {
2845 return is_subframe_; 2834 return is_subframe_;
2846 } 2835 }
2847 2836
2848 void WebContentsImpl::Find(int request_id, 2837 void WebContentsImpl::Find(int request_id,
2849 const base::string16& search_text, 2838 const base::string16& search_text,
2850 const blink::WebFindOptions& options) { 2839 const blink::WebFindOptions& options) {
(...skipping 1758 matching lines...) Expand 10 before | Expand all | Expand 10 after
4609 void WebContentsImpl::SetAllowOtherViews(bool allow) { 4598 void WebContentsImpl::SetAllowOtherViews(bool allow) {
4610 view_->SetAllowOtherViews(allow); 4599 view_->SetAllowOtherViews(allow);
4611 } 4600 }
4612 4601
4613 bool WebContentsImpl::GetAllowOtherViews() { 4602 bool WebContentsImpl::GetAllowOtherViews() {
4614 return view_->GetAllowOtherViews(); 4603 return view_->GetAllowOtherViews();
4615 } 4604 }
4616 4605
4617 #endif 4606 #endif
4618 4607
4608 void WebContentsImpl::OnDidDownloadImage(
4609 const ImageDownloadCallback& callback,
4610 int id,
4611 const GURL& image_url,
4612 image_downloader::DownloadResultPtr result) {
4613 const std::vector<SkBitmap> images =
4614 result->images.To<std::vector<SkBitmap>>();
4615 const std::vector<gfx::Size> original_image_sizes =
4616 result->original_image_sizes.To<std::vector<gfx::Size>>();
4617
4618 callback.Run(id, result->http_status_code, image_url, images,
4619 original_image_sizes);
4620 }
4621
4619 void WebContentsImpl::OnDialogClosed(int render_process_id, 4622 void WebContentsImpl::OnDialogClosed(int render_process_id,
4620 int render_frame_id, 4623 int render_frame_id,
4621 IPC::Message* reply_msg, 4624 IPC::Message* reply_msg,
4622 bool dialog_was_suppressed, 4625 bool dialog_was_suppressed,
4623 bool success, 4626 bool success,
4624 const base::string16& user_input) { 4627 const base::string16& user_input) {
4625 RenderFrameHostImpl* rfh = RenderFrameHostImpl::FromID(render_process_id, 4628 RenderFrameHostImpl* rfh = RenderFrameHostImpl::FromID(render_process_id,
4626 render_frame_id); 4629 render_frame_id);
4627 last_dialog_suppressed_ = dialog_was_suppressed; 4630 last_dialog_suppressed_ = dialog_was_suppressed;
4628 4631
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
4749 const WebContentsObserver::MediaPlayerId& id) { 4752 const WebContentsObserver::MediaPlayerId& id) {
4750 FOR_EACH_OBSERVER(WebContentsObserver, observers_, MediaStartedPlaying(id)); 4753 FOR_EACH_OBSERVER(WebContentsObserver, observers_, MediaStartedPlaying(id));
4751 } 4754 }
4752 4755
4753 void WebContentsImpl::MediaStoppedPlaying( 4756 void WebContentsImpl::MediaStoppedPlaying(
4754 const WebContentsObserver::MediaPlayerId& id) { 4757 const WebContentsObserver::MediaPlayerId& id) {
4755 FOR_EACH_OBSERVER(WebContentsObserver, observers_, MediaStoppedPlaying(id)); 4758 FOR_EACH_OBSERVER(WebContentsObserver, observers_, MediaStoppedPlaying(id));
4756 } 4759 }
4757 4760
4758 } // namespace content 4761 } // 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