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