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_impl.h" | 19 #include "content/browser/webui/web_ui_impl.h" |
20 #include "content/common/view_messages.h" | 20 #include "content/common/view_messages.h" |
21 #include "content/port/browser/render_widget_host_view_port.h" | 21 #include "content/port/browser/render_widget_host_view_port.h" |
22 #include "content/public/browser/content_browser_client.h" | 22 #include "content/public/browser/content_browser_client.h" |
23 #include "content/public/browser/notification_service.h" | 23 #include "content/public/browser/notification_service.h" |
24 #include "content/public/browser/notification_types.h" | 24 #include "content/public/browser/notification_types.h" |
| 25 #include "content/public/browser/user_metrics.h" |
25 #include "content/public/browser/web_contents_view.h" | 26 #include "content/public/browser/web_contents_view.h" |
26 #include "content/public/browser/web_ui_controller.h" | 27 #include "content/public/browser/web_ui_controller.h" |
27 #include "content/public/browser/web_ui_controller_factory.h" | 28 #include "content/public/browser/web_ui_controller_factory.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, |
(...skipping 55 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 this is an existing NavigationEntry, make sure we're not granting it |
| 107 // different bindings than it had before. If so, note it and don't give it |
| 108 // any bindings, to avoid a potential privilege escalation. |
| 109 if (pending_web_ui_.get() && |
| 110 !entry.GetContentState().empty() && |
| 111 pending_web_ui_->GetBindings() != entry.bindings()) { |
| 112 RecordAction(UserMetricsAction("ProcessSwapBindingsMismatch_RVHM")); |
| 113 pending_web_ui_.reset(); |
| 114 } |
| 115 } |
| 116 |
100 RenderViewHostImpl* RenderViewHostManager::Navigate( | 117 RenderViewHostImpl* RenderViewHostManager::Navigate( |
101 const NavigationEntryImpl& entry) { | 118 const NavigationEntryImpl& entry) { |
102 // Create a pending RenderViewHost. It will give us the one we should use | 119 // Create a pending RenderViewHost. It will give us the one we should use |
103 RenderViewHostImpl* dest_render_view_host = | 120 RenderViewHostImpl* dest_render_view_host = |
104 static_cast<RenderViewHostImpl*>(UpdateRendererStateForNavigate(entry)); | 121 static_cast<RenderViewHostImpl*>(UpdateRendererStateForNavigate(entry)); |
105 if (!dest_render_view_host) | 122 if (!dest_render_view_host) |
106 return NULL; // We weren't able to create a pending render view host. | 123 return NULL; // We weren't able to create a pending render view host. |
107 | 124 |
108 // If the current render_view_host_ isn't live, we should create it so | 125 // 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 | 126 // that we don't show a sad tab while the dest_render_view_host fetches |
(...skipping 697 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
807 if (!is_guest_scheme && (new_instance != curr_instance || force_swap)) { | 824 if (!is_guest_scheme && (new_instance != curr_instance || force_swap)) { |
808 // New SiteInstance. | 825 // New SiteInstance. |
809 DCHECK(!cross_navigation_pending_); | 826 DCHECK(!cross_navigation_pending_); |
810 | 827 |
811 // This will possibly create (set to NULL) a Web UI object for the pending | 828 // This will possibly create (set to NULL) a Web UI object for the pending |
812 // page. We'll use this later to give the page special access. This must | 829 // page. We'll use this later to give the page special access. This must |
813 // happen before the new renderer is created below so it will get bindings. | 830 // happen before the new renderer is created below so it will get bindings. |
814 // It must also happen after the above conditional call to CancelPending(), | 831 // It must also happen after the above conditional call to CancelPending(), |
815 // otherwise CancelPending may clear the pending_web_ui_ and the page will | 832 // otherwise CancelPending may clear the pending_web_ui_ and the page will |
816 // not have its bindings set appropriately. | 833 // not have its bindings set appropriately. |
817 pending_web_ui_.reset( | 834 SetPendingWebUI(entry); |
818 delegate_->CreateWebUIForRenderManager(entry.GetURL())); | |
819 pending_and_current_web_ui_.reset(); | |
820 | 835 |
821 // Ensure that we have created RVHs for the new RVH's opener chain if | 836 // Ensure that we have created RVHs for the new RVH's opener chain if |
822 // we are staying in the same BrowsingInstance. This allows the pending RVH | 837 // we are staying in the same BrowsingInstance. This allows the pending RVH |
823 // to send cross-process script calls to its opener(s). | 838 // to send cross-process script calls to its opener(s). |
824 int opener_route_id = MSG_ROUTING_NONE; | 839 int opener_route_id = MSG_ROUTING_NONE; |
825 if (new_instance->IsRelatedSiteInstance(curr_instance)) { | 840 if (new_instance->IsRelatedSiteInstance(curr_instance)) { |
826 opener_route_id = | 841 opener_route_id = |
827 delegate_->CreateOpenerRenderViewsForRenderManager(new_instance); | 842 delegate_->CreateOpenerRenderViewsForRenderManager(new_instance); |
828 } | 843 } |
829 | 844 |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
874 // doesn't otherwise know that the cross-site request is happening. This | 889 // doesn't otherwise know that the cross-site request is happening. This |
875 // will trigger a call to ShouldClosePage with the reply. | 890 // will trigger a call to ShouldClosePage with the reply. |
876 render_view_host_->FirePageBeforeUnload(true); | 891 render_view_host_->FirePageBeforeUnload(true); |
877 | 892 |
878 return pending_render_view_host_; | 893 return pending_render_view_host_; |
879 } else { | 894 } else { |
880 if (ShouldReuseWebUI(curr_entry, &entry)) { | 895 if (ShouldReuseWebUI(curr_entry, &entry)) { |
881 pending_web_ui_.reset(); | 896 pending_web_ui_.reset(); |
882 pending_and_current_web_ui_ = web_ui_->AsWeakPtr(); | 897 pending_and_current_web_ui_ = web_ui_->AsWeakPtr(); |
883 } else { | 898 } else { |
884 pending_and_current_web_ui_.reset(); | 899 SetPendingWebUI(entry); |
885 pending_web_ui_.reset( | |
886 delegate_->CreateWebUIForRenderManager(entry.GetURL())); | |
887 } | 900 } |
888 | 901 |
889 if (pending_web_ui() && render_view_host_->IsRenderViewLive()) | 902 if (pending_web_ui() && render_view_host_->IsRenderViewLive()) |
890 pending_web_ui()->GetController()->RenderViewReused(render_view_host_); | 903 pending_web_ui()->GetController()->RenderViewReused(render_view_host_); |
891 | 904 |
892 // The renderer can exit view source mode when any error or cancellation | 905 // The renderer can exit view source mode when any error or cancellation |
893 // happen. We must overwrite to recover the mode. | 906 // happen. We must overwrite to recover the mode. |
894 if (entry.IsViewSourceMode()) { | 907 if (entry.IsViewSourceMode()) { |
895 render_view_host_->Send( | 908 render_view_host_->Send( |
896 new ViewMsg_EnableViewSourceMode(render_view_host_->GetRoutingID())); | 909 new ViewMsg_EnableViewSourceMode(render_view_host_->GetRoutingID())); |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
973 RenderViewHostImpl* RenderViewHostManager::GetSwappedOutRenderViewHost( | 986 RenderViewHostImpl* RenderViewHostManager::GetSwappedOutRenderViewHost( |
974 SiteInstance* instance) { | 987 SiteInstance* instance) { |
975 RenderViewHostMap::iterator iter = swapped_out_hosts_.find(instance->GetId()); | 988 RenderViewHostMap::iterator iter = swapped_out_hosts_.find(instance->GetId()); |
976 if (iter != swapped_out_hosts_.end()) | 989 if (iter != swapped_out_hosts_.end()) |
977 return iter->second; | 990 return iter->second; |
978 | 991 |
979 return NULL; | 992 return NULL; |
980 } | 993 } |
981 | 994 |
982 } // namespace content | 995 } // namespace content |
OLD | NEW |