OLD | NEW |
---|---|
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 Loading... | |
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 Loading... | |
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), |
364 download_image_weak_factory_(this), | |
379 loading_weak_factory_(this) { | 365 loading_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)); |
(...skipping 2427 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2816 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 2802 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
2817 static int next_image_download_id = 0; | 2803 static int next_image_download_id = 0; |
2818 const image_downloader::ImageDownloaderPtr& mojo_image_downloader = | 2804 const image_downloader::ImageDownloaderPtr& mojo_image_downloader = |
2819 GetMainFrame()->GetMojoImageDownloader(); | 2805 GetMainFrame()->GetMojoImageDownloader(); |
2820 const int download_id = ++next_image_download_id; | 2806 const int download_id = ++next_image_download_id; |
2821 if (!mojo_image_downloader) { | 2807 if (!mojo_image_downloader) { |
2822 // If the renderer process is dead (i.e. crash, or memory pressure on | 2808 // If the renderer process is dead (i.e. crash, or memory pressure on |
2823 // Android), the downloader service will be invalid. Pre-Mojo, this would | 2809 // Android), the downloader service will be invalid. Pre-Mojo, this would |
2824 // hang the callback indefinetly since the IPC would be dropped. Now, | 2810 // hang the callback indefinetly since the IPC would be dropped. Now, |
2825 // respond with a 400 HTTP error code to indicate that something went wrong. | 2811 // respond with a 400 HTTP error code to indicate that something went wrong. |
2812 image_downloader::DownloadResultPtr result = | |
2813 image_downloader::DownloadResult::New(); | |
2814 result->http_status_code = 400; | |
2826 BrowserThread::PostTask( | 2815 BrowserThread::PostTask( |
2827 BrowserThread::UI, FROM_HERE, | 2816 BrowserThread::UI, FROM_HERE, |
2828 base::Bind(&WebContents::ImageDownloadCallback::Run, | 2817 base::Bind(&WebContentsImpl::OnDidDownloadImage, |
2829 base::Owned(new ImageDownloadCallback(callback)), | 2818 download_image_weak_factory_.GetWeakPtr(), callback, |
2830 download_id, 400, url, std::vector<SkBitmap>(), | 2819 download_id, url, base::Passed(&result))); |
2831 std::vector<gfx::Size>())); | |
2832 return download_id; | 2820 return download_id; |
2833 } | 2821 } |
2834 | 2822 |
2835 image_downloader::DownloadRequestPtr req = | 2823 image_downloader::DownloadRequestPtr req = |
2836 image_downloader::DownloadRequest::New(); | 2824 image_downloader::DownloadRequest::New(); |
2837 | 2825 |
2838 req->url = mojo::String::From(url); | 2826 req->url = mojo::String::From(url); |
2839 req->is_favicon = is_favicon; | 2827 req->is_favicon = is_favicon; |
2840 req->max_bitmap_size = max_bitmap_size; | 2828 req->max_bitmap_size = max_bitmap_size; |
2841 req->bypass_cache = bypass_cache; | 2829 req->bypass_cache = bypass_cache; |
2842 | 2830 |
2843 mojo_image_downloader->DownloadImage( | 2831 mojo_image_downloader->DownloadImage( |
2844 std::move(req), | 2832 std::move(req), base::Bind(&WebContentsImpl::OnDidDownloadImage, |
2845 base::Bind(&DidDownloadImage, callback, download_id, url)); | 2833 download_image_weak_factory_.GetWeakPtr(), |
2834 callback, download_id, url)); | |
2846 return download_id; | 2835 return download_id; |
2847 } | 2836 } |
2848 | 2837 |
2849 bool WebContentsImpl::IsSubframe() const { | 2838 bool WebContentsImpl::IsSubframe() const { |
2850 return is_subframe_; | 2839 return is_subframe_; |
2851 } | 2840 } |
2852 | 2841 |
2853 void WebContentsImpl::Find(int request_id, | 2842 void WebContentsImpl::Find(int request_id, |
2854 const base::string16& search_text, | 2843 const base::string16& search_text, |
2855 const blink::WebFindOptions& options) { | 2844 const blink::WebFindOptions& options) { |
(...skipping 1760 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
4616 void WebContentsImpl::SetAllowOtherViews(bool allow) { | 4605 void WebContentsImpl::SetAllowOtherViews(bool allow) { |
4617 view_->SetAllowOtherViews(allow); | 4606 view_->SetAllowOtherViews(allow); |
4618 } | 4607 } |
4619 | 4608 |
4620 bool WebContentsImpl::GetAllowOtherViews() { | 4609 bool WebContentsImpl::GetAllowOtherViews() { |
4621 return view_->GetAllowOtherViews(); | 4610 return view_->GetAllowOtherViews(); |
4622 } | 4611 } |
4623 | 4612 |
4624 #endif | 4613 #endif |
4625 | 4614 |
4615 void WebContentsImpl::OnDidDownloadImage( | |
4616 const ImageDownloadCallback& callback, | |
4617 int id, | |
4618 const GURL& image_url, | |
4619 image_downloader::DownloadResultPtr result) { | |
4620 DCHECK(result); | |
jam
2016/02/12 23:31:42
this is unnecessary. in release builds, it does no
| |
4621 | |
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 | |
4626 void WebContentsImpl::OnDialogClosed(int render_process_id, | 4631 void WebContentsImpl::OnDialogClosed(int render_process_id, |
4627 int render_frame_id, | 4632 int render_frame_id, |
4628 IPC::Message* reply_msg, | 4633 IPC::Message* reply_msg, |
4629 bool dialog_was_suppressed, | 4634 bool dialog_was_suppressed, |
4630 bool success, | 4635 bool success, |
4631 const base::string16& user_input) { | 4636 const base::string16& user_input) { |
4632 RenderFrameHostImpl* rfh = RenderFrameHostImpl::FromID(render_process_id, | 4637 RenderFrameHostImpl* rfh = RenderFrameHostImpl::FromID(render_process_id, |
4633 render_frame_id); | 4638 render_frame_id); |
4634 last_dialog_suppressed_ = dialog_was_suppressed; | 4639 last_dialog_suppressed_ = dialog_was_suppressed; |
4635 | 4640 |
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
4756 const WebContentsObserver::MediaPlayerId& id) { | 4761 const WebContentsObserver::MediaPlayerId& id) { |
4757 FOR_EACH_OBSERVER(WebContentsObserver, observers_, MediaStartedPlaying(id)); | 4762 FOR_EACH_OBSERVER(WebContentsObserver, observers_, MediaStartedPlaying(id)); |
4758 } | 4763 } |
4759 | 4764 |
4760 void WebContentsImpl::MediaStoppedPlaying( | 4765 void WebContentsImpl::MediaStoppedPlaying( |
4761 const WebContentsObserver::MediaPlayerId& id) { | 4766 const WebContentsObserver::MediaPlayerId& id) { |
4762 FOR_EACH_OBSERVER(WebContentsObserver, observers_, MediaStoppedPlaying(id)); | 4767 FOR_EACH_OBSERVER(WebContentsObserver, observers_, MediaStoppedPlaying(id)); |
4763 } | 4768 } |
4764 | 4769 |
4765 } // namespace content | 4770 } // namespace content |
OLD | NEW |