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/render_view_host_manager.h" | 5 #include "content/browser/web_contents/render_view_host_manager.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/logging.h" | 10 #include "base/logging.h" |
11 #include "content/browser/devtools/render_view_devtools_agent_host.h" | 11 #include "content/browser/devtools/render_view_devtools_agent_host.h" |
12 #include "content/browser/renderer_host/render_process_host_impl.h" | 12 #include "content/browser/renderer_host/render_process_host_impl.h" |
13 #include "content/browser/renderer_host/render_view_host_factory.h" | 13 #include "content/browser/renderer_host/render_view_host_factory.h" |
14 #include "content/browser/renderer_host/render_view_host_impl.h" | 14 #include "content/browser/renderer_host/render_view_host_impl.h" |
15 #include "content/browser/site_instance_impl.h" | 15 #include "content/browser/site_instance_impl.h" |
16 #include "content/browser/web_contents/interstitial_page_impl.h" | 16 #include "content/browser/web_contents/interstitial_page_impl.h" |
17 #include "content/browser/web_contents/navigation_controller_impl.h" | 17 #include "content/browser/web_contents/navigation_controller_impl.h" |
18 #include "content/browser/web_contents/navigation_entry_impl.h" | 18 #include "content/browser/web_contents/navigation_entry_impl.h" |
19 #include "content/browser/webui/web_ui_controller_factory_registry.h" | 19 #include "content/browser/webui/web_ui_controller_factory_registry.h" |
20 #include "content/browser/webui/web_ui_impl.h" | 20 #include "content/browser/webui/web_ui_impl.h" |
21 #include "content/common/view_messages.h" | 21 #include "content/common/view_messages.h" |
22 #include "content/port/browser/render_widget_host_view_port.h" | 22 #include "content/port/browser/render_widget_host_view_port.h" |
23 #include "content/public/browser/content_browser_client.h" | 23 #include "content/public/browser/content_browser_client.h" |
24 #include "content/public/browser/notification_service.h" | 24 #include "content/public/browser/notification_service.h" |
25 #include "content/public/browser/notification_types.h" | 25 #include "content/public/browser/notification_types.h" |
| 26 #include "content/public/browser/user_metrics.h" |
26 #include "content/public/browser/web_contents_view.h" | 27 #include "content/public/browser/web_contents_view.h" |
27 #include "content/public/browser/web_ui_controller.h" | 28 #include "content/public/browser/web_ui_controller.h" |
28 #include "content/public/common/content_switches.h" | 29 #include "content/public/common/content_switches.h" |
29 #include "content/public/common/url_constants.h" | 30 #include "content/public/common/url_constants.h" |
30 | 31 |
31 namespace content { | 32 namespace content { |
32 | 33 |
33 RenderViewHostManager::RenderViewHostManager( | 34 RenderViewHostManager::RenderViewHostManager( |
34 RenderViewHostDelegate* render_view_delegate, | 35 RenderViewHostDelegate* render_view_delegate, |
35 RenderWidgetHostDelegate* render_widget_delegate, | 36 RenderWidgetHostDelegate* render_widget_delegate, |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
90 } | 91 } |
91 | 92 |
92 RenderWidgetHostView* RenderViewHostManager::GetRenderWidgetHostView() const { | 93 RenderWidgetHostView* RenderViewHostManager::GetRenderWidgetHostView() const { |
93 if (interstitial_page_) | 94 if (interstitial_page_) |
94 return interstitial_page_->GetView(); | 95 return interstitial_page_->GetView(); |
95 if (!render_view_host_) | 96 if (!render_view_host_) |
96 return NULL; | 97 return NULL; |
97 return render_view_host_->GetView(); | 98 return render_view_host_->GetView(); |
98 } | 99 } |
99 | 100 |
| 101 void RenderViewHostManager::SetPendingWebUI(const NavigationEntryImpl& entry) { |
| 102 pending_web_ui_.reset( |
| 103 delegate_->CreateWebUIForRenderManager(entry.GetURL())); |
| 104 pending_and_current_web_ui_.reset(); |
| 105 |
| 106 // If we have assigned (zero or more) bindings to this NavigationEntry in the |
| 107 // past, make sure we're not granting it different bindings than it had |
| 108 // before. If so, note it and don't give it any bindings, to avoid a |
| 109 // potential privilege escalation. |
| 110 if (pending_web_ui_.get() && |
| 111 entry.bindings() != NavigationEntryImpl::kInvalidBindings && |
| 112 pending_web_ui_->GetBindings() != entry.bindings()) { |
| 113 RecordAction(UserMetricsAction("ProcessSwapBindingsMismatch_RVHM")); |
| 114 pending_web_ui_.reset(); |
| 115 } |
| 116 } |
| 117 |
100 RenderViewHostImpl* RenderViewHostManager::Navigate( | 118 RenderViewHostImpl* RenderViewHostManager::Navigate( |
101 const NavigationEntryImpl& entry) { | 119 const NavigationEntryImpl& entry) { |
102 // Create a pending RenderViewHost. It will give us the one we should use | 120 // Create a pending RenderViewHost. It will give us the one we should use |
103 RenderViewHostImpl* dest_render_view_host = | 121 RenderViewHostImpl* dest_render_view_host = |
104 static_cast<RenderViewHostImpl*>(UpdateRendererStateForNavigate(entry)); | 122 static_cast<RenderViewHostImpl*>(UpdateRendererStateForNavigate(entry)); |
105 if (!dest_render_view_host) | 123 if (!dest_render_view_host) |
106 return NULL; // We weren't able to create a pending render view host. | 124 return NULL; // We weren't able to create a pending render view host. |
107 | 125 |
108 // If the current render_view_host_ isn't live, we should create it so | 126 // If the current render_view_host_ isn't live, we should create it so |
109 // that we don't show a sad tab while the dest_render_view_host fetches | 127 // that we don't show a sad tab while the dest_render_view_host fetches |
(...skipping 693 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
803 if (!is_guest_scheme && (new_instance != curr_instance || force_swap)) { | 821 if (!is_guest_scheme && (new_instance != curr_instance || force_swap)) { |
804 // New SiteInstance. | 822 // New SiteInstance. |
805 DCHECK(!cross_navigation_pending_); | 823 DCHECK(!cross_navigation_pending_); |
806 | 824 |
807 // This will possibly create (set to NULL) a Web UI object for the pending | 825 // This will possibly create (set to NULL) a Web UI object for the pending |
808 // page. We'll use this later to give the page special access. This must | 826 // page. We'll use this later to give the page special access. This must |
809 // happen before the new renderer is created below so it will get bindings. | 827 // happen before the new renderer is created below so it will get bindings. |
810 // It must also happen after the above conditional call to CancelPending(), | 828 // It must also happen after the above conditional call to CancelPending(), |
811 // otherwise CancelPending may clear the pending_web_ui_ and the page will | 829 // otherwise CancelPending may clear the pending_web_ui_ and the page will |
812 // not have its bindings set appropriately. | 830 // not have its bindings set appropriately. |
813 pending_web_ui_.reset( | 831 SetPendingWebUI(entry); |
814 delegate_->CreateWebUIForRenderManager(entry.GetURL())); | |
815 pending_and_current_web_ui_.reset(); | |
816 | 832 |
817 // Ensure that we have created RVHs for the new RVH's opener chain if | 833 // Ensure that we have created RVHs for the new RVH's opener chain if |
818 // we are staying in the same BrowsingInstance. This allows the pending RVH | 834 // we are staying in the same BrowsingInstance. This allows the pending RVH |
819 // to send cross-process script calls to its opener(s). | 835 // to send cross-process script calls to its opener(s). |
820 int opener_route_id = MSG_ROUTING_NONE; | 836 int opener_route_id = MSG_ROUTING_NONE; |
821 if (new_instance->IsRelatedSiteInstance(curr_instance)) { | 837 if (new_instance->IsRelatedSiteInstance(curr_instance)) { |
822 opener_route_id = | 838 opener_route_id = |
823 delegate_->CreateOpenerRenderViewsForRenderManager(new_instance); | 839 delegate_->CreateOpenerRenderViewsForRenderManager(new_instance); |
824 } | 840 } |
825 | 841 |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
870 // doesn't otherwise know that the cross-site request is happening. This | 886 // doesn't otherwise know that the cross-site request is happening. This |
871 // will trigger a call to ShouldClosePage with the reply. | 887 // will trigger a call to ShouldClosePage with the reply. |
872 render_view_host_->FirePageBeforeUnload(true); | 888 render_view_host_->FirePageBeforeUnload(true); |
873 | 889 |
874 return pending_render_view_host_; | 890 return pending_render_view_host_; |
875 } else { | 891 } else { |
876 if (ShouldReuseWebUI(curr_entry, &entry)) { | 892 if (ShouldReuseWebUI(curr_entry, &entry)) { |
877 pending_web_ui_.reset(); | 893 pending_web_ui_.reset(); |
878 pending_and_current_web_ui_ = web_ui_->AsWeakPtr(); | 894 pending_and_current_web_ui_ = web_ui_->AsWeakPtr(); |
879 } else { | 895 } else { |
880 pending_and_current_web_ui_.reset(); | 896 SetPendingWebUI(entry); |
881 pending_web_ui_.reset( | |
882 delegate_->CreateWebUIForRenderManager(entry.GetURL())); | |
883 } | 897 } |
884 | 898 |
885 if (pending_web_ui() && render_view_host_->IsRenderViewLive()) | 899 if (pending_web_ui() && render_view_host_->IsRenderViewLive()) |
886 pending_web_ui()->GetController()->RenderViewReused(render_view_host_); | 900 pending_web_ui()->GetController()->RenderViewReused(render_view_host_); |
887 | 901 |
888 // The renderer can exit view source mode when any error or cancellation | 902 // The renderer can exit view source mode when any error or cancellation |
889 // happen. We must overwrite to recover the mode. | 903 // happen. We must overwrite to recover the mode. |
890 if (entry.IsViewSourceMode()) { | 904 if (entry.IsViewSourceMode()) { |
891 render_view_host_->Send( | 905 render_view_host_->Send( |
892 new ViewMsg_EnableViewSourceMode(render_view_host_->GetRoutingID())); | 906 new ViewMsg_EnableViewSourceMode(render_view_host_->GetRoutingID())); |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
969 RenderViewHostImpl* RenderViewHostManager::GetSwappedOutRenderViewHost( | 983 RenderViewHostImpl* RenderViewHostManager::GetSwappedOutRenderViewHost( |
970 SiteInstance* instance) { | 984 SiteInstance* instance) { |
971 RenderViewHostMap::iterator iter = swapped_out_hosts_.find(instance->GetId()); | 985 RenderViewHostMap::iterator iter = swapped_out_hosts_.find(instance->GetId()); |
972 if (iter != swapped_out_hosts_.end()) | 986 if (iter != swapped_out_hosts_.end()) |
973 return iter->second; | 987 return iter->second; |
974 | 988 |
975 return NULL; | 989 return NULL; |
976 } | 990 } |
977 | 991 |
978 } // namespace content | 992 } // namespace content |
OLD | NEW |