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 <utility> | 7 #include <utility> |
8 | 8 |
9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
10 #include "base/debug/trace_event.h" | 10 #include "base/debug/trace_event.h" |
(...skipping 550 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
561 OnOpenDateTimeDialog) | 561 OnOpenDateTimeDialog) |
562 #endif | 562 #endif |
563 IPC_MESSAGE_UNHANDLED(handled = false) | 563 IPC_MESSAGE_UNHANDLED(handled = false) |
564 IPC_END_MESSAGE_MAP() | 564 IPC_END_MESSAGE_MAP() |
565 render_view_message_source_ = NULL; | 565 render_view_message_source_ = NULL; |
566 render_frame_message_source_ = NULL; | 566 render_frame_message_source_ = NULL; |
567 | 567 |
568 return handled; | 568 return handled; |
569 } | 569 } |
570 | 570 |
| 571 bool WebContentsImpl::HasValidFrameSource() { |
| 572 if (!render_frame_message_source_) { |
| 573 DCHECK(render_view_message_source_); |
| 574 RecordAction(base::UserMetricsAction("BadMessageTerminate_WC")); |
| 575 GetRenderProcessHost()->ReceivedBadMessage(); |
| 576 return false; |
| 577 } |
| 578 |
| 579 return true; |
| 580 } |
| 581 |
571 void WebContentsImpl::RunFileChooser( | 582 void WebContentsImpl::RunFileChooser( |
572 RenderViewHost* render_view_host, | 583 RenderViewHost* render_view_host, |
573 const FileChooserParams& params) { | 584 const FileChooserParams& params) { |
574 if (delegate_) | 585 if (delegate_) |
575 delegate_->RunFileChooser(this, params); | 586 delegate_->RunFileChooser(this, params); |
576 } | 587 } |
577 | 588 |
578 NavigationControllerImpl& WebContentsImpl::GetController() { | 589 NavigationControllerImpl& WebContentsImpl::GetController() { |
579 return controller_; | 590 return controller_; |
580 } | 591 } |
(...skipping 2176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2757 RecordAction(base::UserMetricsAction("SSL.RanInsecureContent")); | 2768 RecordAction(base::UserMetricsAction("SSL.RanInsecureContent")); |
2758 if (EndsWith(security_origin, kDotGoogleDotCom, false)) | 2769 if (EndsWith(security_origin, kDotGoogleDotCom, false)) |
2759 RecordAction(base::UserMetricsAction("SSL.RanInsecureContentGoogle")); | 2770 RecordAction(base::UserMetricsAction("SSL.RanInsecureContentGoogle")); |
2760 controller_.ssl_manager()->DidRunInsecureContent(security_origin); | 2771 controller_.ssl_manager()->DidRunInsecureContent(security_origin); |
2761 displayed_insecure_content_ = true; | 2772 displayed_insecure_content_ = true; |
2762 SSLManager::NotifySSLInternalStateChanged( | 2773 SSLManager::NotifySSLInternalStateChanged( |
2763 GetController().GetBrowserContext()); | 2774 GetController().GetBrowserContext()); |
2764 } | 2775 } |
2765 | 2776 |
2766 void WebContentsImpl::OnDocumentLoadedInFrame() { | 2777 void WebContentsImpl::OnDocumentLoadedInFrame() { |
2767 if (!render_frame_message_source_) { | 2778 if (!HasValidFrameSource()) |
2768 RecordAction(base::UserMetricsAction("BadMessageTerminate_WC")); | |
2769 GetRenderProcessHost()->ReceivedBadMessage(); | |
2770 return; | 2779 return; |
2771 } | |
2772 | 2780 |
2773 RenderFrameHostImpl* rfh = | 2781 RenderFrameHostImpl* rfh = |
2774 static_cast<RenderFrameHostImpl*>(render_frame_message_source_); | 2782 static_cast<RenderFrameHostImpl*>(render_frame_message_source_); |
2775 FOR_EACH_OBSERVER( | 2783 FOR_EACH_OBSERVER( |
2776 WebContentsObserver, observers_, DocumentLoadedInFrame(rfh)); | 2784 WebContentsObserver, observers_, DocumentLoadedInFrame(rfh)); |
2777 } | 2785 } |
2778 | 2786 |
2779 void WebContentsImpl::OnDidFinishLoad(const GURL& url) { | 2787 void WebContentsImpl::OnDidFinishLoad(const GURL& url) { |
2780 if (!render_frame_message_source_) { | 2788 if (!HasValidFrameSource()) |
2781 RecordAction(base::UserMetricsAction("BadMessageTerminate_WC")); | |
2782 GetRenderProcessHost()->ReceivedBadMessage(); | |
2783 return; | 2789 return; |
2784 } | |
2785 | 2790 |
2786 GURL validated_url(url); | 2791 GURL validated_url(url); |
2787 RenderProcessHost* render_process_host = | 2792 RenderProcessHost* render_process_host = |
2788 render_frame_message_source_->GetProcess(); | 2793 render_frame_message_source_->GetProcess(); |
2789 render_process_host->FilterURL(false, &validated_url); | 2794 render_process_host->FilterURL(false, &validated_url); |
2790 | 2795 |
2791 RenderFrameHostImpl* rfh = | 2796 RenderFrameHostImpl* rfh = |
2792 static_cast<RenderFrameHostImpl*>(render_frame_message_source_); | 2797 static_cast<RenderFrameHostImpl*>(render_frame_message_source_); |
2793 FOR_EACH_OBSERVER( | 2798 FOR_EACH_OBSERVER( |
2794 WebContentsObserver, observers_, DidFinishLoad(rfh, validated_url)); | 2799 WebContentsObserver, observers_, DidFinishLoad(rfh, validated_url)); |
2795 } | 2800 } |
2796 | 2801 |
2797 void WebContentsImpl::OnDidStartLoading(bool to_different_document) { | 2802 void WebContentsImpl::OnDidStartLoading(bool to_different_document) { |
| 2803 if (!HasValidFrameSource()) |
| 2804 return; |
| 2805 |
2798 RenderFrameHostImpl* rfh = | 2806 RenderFrameHostImpl* rfh = |
2799 static_cast<RenderFrameHostImpl*>(render_frame_message_source_); | 2807 static_cast<RenderFrameHostImpl*>(render_frame_message_source_); |
2800 int64 render_frame_id = rfh->frame_tree_node()->frame_tree_node_id(); | 2808 int64 render_frame_id = rfh->frame_tree_node()->frame_tree_node_id(); |
2801 | 2809 |
2802 // Any main frame load to a new document should reset the load progress, since | 2810 // Any main frame load to a new document should reset the load progress, since |
2803 // it will replace the current page and any frames. | 2811 // it will replace the current page and any frames. |
2804 if (to_different_document && !rfh->GetParent()) { | 2812 if (to_different_document && !rfh->GetParent()) { |
2805 ResetLoadProgressState(); | 2813 ResetLoadProgressState(); |
2806 loading_frames_in_progress_ = 0; | 2814 loading_frames_in_progress_ = 0; |
2807 rfh->frame_tree_node()->set_is_loading(false); | 2815 rfh->frame_tree_node()->set_is_loading(false); |
(...skipping 22 matching lines...) Expand all Loading... |
2830 rfh->frame_tree_node()->set_is_loading(true); | 2838 rfh->frame_tree_node()->set_is_loading(true); |
2831 | 2839 |
2832 // Notify the RenderFrameHostManager of the event. | 2840 // Notify the RenderFrameHostManager of the event. |
2833 rfh->frame_tree_node()->render_manager()->OnDidStartLoading(); | 2841 rfh->frame_tree_node()->render_manager()->OnDidStartLoading(); |
2834 | 2842 |
2835 loading_progresses_[render_frame_id] = kMinimumLoadingProgress; | 2843 loading_progresses_[render_frame_id] = kMinimumLoadingProgress; |
2836 SendLoadProgressChanged(); | 2844 SendLoadProgressChanged(); |
2837 } | 2845 } |
2838 | 2846 |
2839 void WebContentsImpl::OnDidStopLoading() { | 2847 void WebContentsImpl::OnDidStopLoading() { |
| 2848 if (!HasValidFrameSource()) |
| 2849 return; |
| 2850 |
2840 RenderFrameHostImpl* rfh = | 2851 RenderFrameHostImpl* rfh = |
2841 static_cast<RenderFrameHostImpl*>(render_frame_message_source_); | 2852 static_cast<RenderFrameHostImpl*>(render_frame_message_source_); |
2842 int64 render_frame_id = rfh->frame_tree_node()->frame_tree_node_id(); | 2853 int64 render_frame_id = rfh->frame_tree_node()->frame_tree_node_id(); |
2843 rfh->frame_tree_node()->set_is_loading(false); | 2854 rfh->frame_tree_node()->set_is_loading(false); |
2844 | 2855 |
2845 if (loading_progresses_.find(render_frame_id) != loading_progresses_.end()) { | 2856 if (loading_progresses_.find(render_frame_id) != loading_progresses_.end()) { |
2846 // Load stopped while we were still tracking load. Make sure we update | 2857 // Load stopped while we were still tracking load. Make sure we update |
2847 // progress based on this frame's completion. | 2858 // progress based on this frame's completion. |
2848 loading_progresses_[render_frame_id] = 1.0; | 2859 loading_progresses_[render_frame_id] = 1.0; |
2849 SendLoadProgressChanged(); | 2860 SendLoadProgressChanged(); |
2850 // Then we clean-up our states. | 2861 // Then we clean-up our states. |
2851 if (loading_total_progress_ == 1.0) | 2862 if (loading_total_progress_ == 1.0) |
2852 ResetLoadProgressState(); | 2863 ResetLoadProgressState(); |
2853 } | 2864 } |
2854 | 2865 |
2855 // Notify the RenderFrameHostManager of the event. | 2866 // Notify the RenderFrameHostManager of the event. |
2856 rfh->frame_tree_node()->render_manager()->OnDidStopLoading(); | 2867 rfh->frame_tree_node()->render_manager()->OnDidStopLoading(); |
2857 | 2868 |
2858 // TODO(japhet): This should be a DCHECK, but the pdf plugin sometimes | 2869 // TODO(japhet): This should be a DCHECK, but the pdf plugin sometimes |
2859 // calls DidStopLoading() without a matching DidStartLoading(). | 2870 // calls DidStopLoading() without a matching DidStartLoading(). |
2860 if (loading_frames_in_progress_ == 0) | 2871 if (loading_frames_in_progress_ == 0) |
2861 return; | 2872 return; |
2862 --loading_frames_in_progress_; | 2873 --loading_frames_in_progress_; |
2863 if (loading_frames_in_progress_ == 0) | 2874 if (loading_frames_in_progress_ == 0) |
2864 DidStopLoading(rfh); | 2875 DidStopLoading(rfh); |
2865 } | 2876 } |
2866 | 2877 |
2867 void WebContentsImpl::OnDidChangeLoadProgress(double load_progress) { | 2878 void WebContentsImpl::OnDidChangeLoadProgress(double load_progress) { |
| 2879 if (!HasValidFrameSource()) |
| 2880 return; |
| 2881 |
2868 RenderFrameHostImpl* rfh = | 2882 RenderFrameHostImpl* rfh = |
2869 static_cast<RenderFrameHostImpl*>(render_frame_message_source_); | 2883 static_cast<RenderFrameHostImpl*>(render_frame_message_source_); |
2870 int64 render_frame_id = rfh->frame_tree_node()->frame_tree_node_id(); | 2884 int64 render_frame_id = rfh->frame_tree_node()->frame_tree_node_id(); |
2871 | 2885 |
2872 loading_progresses_[render_frame_id] = load_progress; | 2886 loading_progresses_[render_frame_id] = load_progress; |
2873 | 2887 |
2874 // We notify progress change immediately for the first and last updates. | 2888 // We notify progress change immediately for the first and last updates. |
2875 // Also, since the message loop may be pretty busy when a page is loaded, it | 2889 // Also, since the message loop may be pretty busy when a page is loaded, it |
2876 // might not execute a posted task in a timely manner so we make sure to | 2890 // might not execute a posted task in a timely manner so we make sure to |
2877 // immediately send progress report if enough time has passed. | 2891 // immediately send progress report if enough time has passed. |
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2994 bool blocked_by_policy) { | 3008 bool blocked_by_policy) { |
2995 // Notify observers about navigation. | 3009 // Notify observers about navigation. |
2996 FOR_EACH_OBSERVER(WebContentsObserver, observers_, | 3010 FOR_EACH_OBSERVER(WebContentsObserver, observers_, |
2997 AppCacheAccessed(manifest_url, blocked_by_policy)); | 3011 AppCacheAccessed(manifest_url, blocked_by_policy)); |
2998 } | 3012 } |
2999 | 3013 |
3000 void WebContentsImpl::OnOpenColorChooser( | 3014 void WebContentsImpl::OnOpenColorChooser( |
3001 int color_chooser_id, | 3015 int color_chooser_id, |
3002 SkColor color, | 3016 SkColor color, |
3003 const std::vector<ColorSuggestion>& suggestions) { | 3017 const std::vector<ColorSuggestion>& suggestions) { |
3004 // Protect against malicious renderer. See http://crbug.com/449777 | 3018 if (!HasValidFrameSource()) |
3005 if (!render_frame_message_source_) | |
3006 return; | 3019 return; |
| 3020 |
3007 ColorChooser* new_color_chooser = delegate_ ? | 3021 ColorChooser* new_color_chooser = delegate_ ? |
3008 delegate_->OpenColorChooser(this, color, suggestions) : | 3022 delegate_->OpenColorChooser(this, color, suggestions) : |
3009 NULL; | 3023 NULL; |
3010 if (!new_color_chooser) | 3024 if (!new_color_chooser) |
3011 return; | 3025 return; |
3012 if (color_chooser_info_.get()) | 3026 if (color_chooser_info_.get()) |
3013 color_chooser_info_->chooser->End(); | 3027 color_chooser_info_->chooser->End(); |
3014 | 3028 |
3015 color_chooser_info_.reset(new ColorChooserInfo( | 3029 color_chooser_info_.reset(new ColorChooserInfo( |
3016 render_frame_message_source_->GetProcess()->GetID(), | 3030 render_frame_message_source_->GetProcess()->GetID(), |
(...skipping 1388 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4405 void WebContentsImpl::OnPreferredSizeChanged(const gfx::Size& old_size) { | 4419 void WebContentsImpl::OnPreferredSizeChanged(const gfx::Size& old_size) { |
4406 if (!delegate_) | 4420 if (!delegate_) |
4407 return; | 4421 return; |
4408 const gfx::Size new_size = GetPreferredSize(); | 4422 const gfx::Size new_size = GetPreferredSize(); |
4409 if (new_size != old_size) | 4423 if (new_size != old_size) |
4410 delegate_->UpdatePreferredSize(this, new_size); | 4424 delegate_->UpdatePreferredSize(this, new_size); |
4411 } | 4425 } |
4412 | 4426 |
4413 void WebContentsImpl::AddMediaPlayerEntry(int64 player_cookie, | 4427 void WebContentsImpl::AddMediaPlayerEntry(int64 player_cookie, |
4414 ActiveMediaPlayerMap* player_map) { | 4428 ActiveMediaPlayerMap* player_map) { |
| 4429 if (!HasValidFrameSource()) |
| 4430 return; |
| 4431 |
4415 const uintptr_t key = | 4432 const uintptr_t key = |
4416 reinterpret_cast<uintptr_t>(render_frame_message_source_); | 4433 reinterpret_cast<uintptr_t>(render_frame_message_source_); |
4417 DCHECK(std::find((*player_map)[key].begin(), | 4434 DCHECK(std::find((*player_map)[key].begin(), |
4418 (*player_map)[key].end(), | 4435 (*player_map)[key].end(), |
4419 player_cookie) == (*player_map)[key].end()); | 4436 player_cookie) == (*player_map)[key].end()); |
4420 (*player_map)[key].push_back(player_cookie); | 4437 (*player_map)[key].push_back(player_cookie); |
4421 } | 4438 } |
4422 | 4439 |
4423 void WebContentsImpl::RemoveMediaPlayerEntry(int64 player_cookie, | 4440 void WebContentsImpl::RemoveMediaPlayerEntry(int64 player_cookie, |
4424 ActiveMediaPlayerMap* player_map) { | 4441 ActiveMediaPlayerMap* player_map) { |
| 4442 if (!HasValidFrameSource()) |
| 4443 return; |
| 4444 |
4425 const uintptr_t key = | 4445 const uintptr_t key = |
4426 reinterpret_cast<uintptr_t>(render_frame_message_source_); | 4446 reinterpret_cast<uintptr_t>(render_frame_message_source_); |
4427 ActiveMediaPlayerMap::iterator it = player_map->find(key); | 4447 ActiveMediaPlayerMap::iterator it = player_map->find(key); |
4428 if (it == player_map->end()) | 4448 if (it == player_map->end()) |
4429 return; | 4449 return; |
4430 | 4450 |
4431 // Remove the player. | 4451 // Remove the player. |
4432 PlayerList::iterator player_it = | 4452 PlayerList::iterator player_it = |
4433 std::find(it->second.begin(), it->second.end(), player_cookie); | 4453 std::find(it->second.begin(), it->second.end(), player_cookie); |
4434 if (player_it != it->second.end()) | 4454 if (player_it != it->second.end()) |
(...skipping 19 matching lines...) Expand all Loading... |
4454 node->render_manager()->ResumeResponseDeferredAtStart(); | 4474 node->render_manager()->ResumeResponseDeferredAtStart(); |
4455 } | 4475 } |
4456 | 4476 |
4457 void WebContentsImpl::SetForceDisableOverscrollContent(bool force_disable) { | 4477 void WebContentsImpl::SetForceDisableOverscrollContent(bool force_disable) { |
4458 force_disable_overscroll_content_ = force_disable; | 4478 force_disable_overscroll_content_ = force_disable; |
4459 if (view_) | 4479 if (view_) |
4460 view_->SetOverscrollControllerEnabled(CanOverscrollContent()); | 4480 view_->SetOverscrollControllerEnabled(CanOverscrollContent()); |
4461 } | 4481 } |
4462 | 4482 |
4463 } // namespace content | 4483 } // namespace content |
OLD | NEW |