| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/frame_host/render_frame_host_impl.h" | 5 #include "content/browser/frame_host/render_frame_host_impl.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
| 9 #include "base/containers/hash_tables.h" | 9 #include "base/containers/hash_tables.h" |
| 10 #include "base/lazy_instance.h" | 10 #include "base/lazy_instance.h" |
| 11 #include "base/metrics/histogram.h" | 11 #include "base/metrics/histogram.h" |
| 12 #include "base/process/kill.h" | 12 #include "base/process/kill.h" |
| 13 #include "base/time/time.h" | 13 #include "base/time/time.h" |
| 14 #include "content/browser/accessibility/accessibility_mode_helper.h" | 14 #include "content/browser/accessibility/accessibility_mode_helper.h" |
| 15 #include "content/browser/accessibility/ax_tree_id_registry.h" | 15 #include "content/browser/accessibility/ax_tree_id_registry.h" |
| 16 #include "content/browser/accessibility/browser_accessibility_manager.h" | 16 #include "content/browser/accessibility/browser_accessibility_manager.h" |
| 17 #include "content/browser/accessibility/browser_accessibility_state_impl.h" | 17 #include "content/browser/accessibility/browser_accessibility_state_impl.h" |
| 18 #include "content/browser/child_process_security_policy_impl.h" | 18 #include "content/browser/child_process_security_policy_impl.h" |
| 19 #include "content/browser/child_process_security_policy_impl.h" |
| 19 #include "content/browser/devtools/render_frame_devtools_agent_host.h" | 20 #include "content/browser/devtools/render_frame_devtools_agent_host.h" |
| 20 #include "content/browser/frame_host/cross_process_frame_connector.h" | 21 #include "content/browser/frame_host/cross_process_frame_connector.h" |
| 21 #include "content/browser/frame_host/cross_site_transferring_request.h" | 22 #include "content/browser/frame_host/cross_site_transferring_request.h" |
| 22 #include "content/browser/frame_host/frame_mojo_shell.h" | 23 #include "content/browser/frame_host/frame_mojo_shell.h" |
| 23 #include "content/browser/frame_host/frame_tree.h" | 24 #include "content/browser/frame_host/frame_tree.h" |
| 24 #include "content/browser/frame_host/frame_tree_node.h" | 25 #include "content/browser/frame_host/frame_tree_node.h" |
| 25 #include "content/browser/frame_host/navigation_handle_impl.h" | 26 #include "content/browser/frame_host/navigation_handle_impl.h" |
| 26 #include "content/browser/frame_host/navigation_request.h" | 27 #include "content/browser/frame_host/navigation_request.h" |
| 27 #include "content/browser/frame_host/navigator.h" | 28 #include "content/browser/frame_host/navigator.h" |
| 28 #include "content/browser/frame_host/navigator_impl.h" | 29 #include "content/browser/frame_host/navigator_impl.h" |
| 29 #include "content/browser/frame_host/render_frame_host_delegate.h" | 30 #include "content/browser/frame_host/render_frame_host_delegate.h" |
| 30 #include "content/browser/frame_host/render_frame_proxy_host.h" | 31 #include "content/browser/frame_host/render_frame_proxy_host.h" |
| 31 #include "content/browser/frame_host/render_widget_host_view_child_frame.h" | 32 #include "content/browser/frame_host/render_widget_host_view_child_frame.h" |
| 32 #include "content/browser/geolocation/geolocation_service_context.h" | 33 #include "content/browser/geolocation/geolocation_service_context.h" |
| 33 #include "content/browser/permissions/permission_service_context.h" | 34 #include "content/browser/permissions/permission_service_context.h" |
| 34 #include "content/browser/permissions/permission_service_impl.h" | 35 #include "content/browser/permissions/permission_service_impl.h" |
| 35 #include "content/browser/presentation/presentation_service_impl.h" | 36 #include "content/browser/presentation/presentation_service_impl.h" |
| 36 #include "content/browser/renderer_host/input/input_router.h" | 37 #include "content/browser/renderer_host/input/input_router.h" |
| 37 #include "content/browser/renderer_host/input/timeout_monitor.h" | 38 #include "content/browser/renderer_host/input/timeout_monitor.h" |
| 38 #include "content/browser/renderer_host/render_process_host_impl.h" | 39 #include "content/browser/renderer_host/render_process_host_impl.h" |
| 39 #include "content/browser/renderer_host/render_view_host_delegate.h" | 40 #include "content/browser/renderer_host/render_view_host_delegate.h" |
| 40 #include "content/browser/renderer_host/render_view_host_delegate_view.h" | 41 #include "content/browser/renderer_host/render_view_host_delegate_view.h" |
| 41 #include "content/browser/renderer_host/render_view_host_impl.h" | 42 #include "content/browser/renderer_host/render_view_host_impl.h" |
| 42 #include "content/browser/renderer_host/render_widget_host_impl.h" | 43 #include "content/browser/renderer_host/render_widget_host_impl.h" |
| 43 #include "content/browser/renderer_host/render_widget_host_view_base.h" | 44 #include "content/browser/renderer_host/render_widget_host_view_base.h" |
| 44 #include "content/browser/wake_lock/wake_lock_service_context.h" | 45 #include "content/browser/wake_lock/wake_lock_service_context.h" |
| 46 #include "content/browser/webui/web_ui_controller_factory_registry.h" |
| 45 #include "content/common/accessibility_messages.h" | 47 #include "content/common/accessibility_messages.h" |
| 46 #include "content/common/frame_messages.h" | 48 #include "content/common/frame_messages.h" |
| 47 #include "content/common/input_messages.h" | 49 #include "content/common/input_messages.h" |
| 48 #include "content/common/inter_process_time_ticks_converter.h" | 50 #include "content/common/inter_process_time_ticks_converter.h" |
| 49 #include "content/common/navigation_params.h" | 51 #include "content/common/navigation_params.h" |
| 50 #include "content/common/render_frame_setup.mojom.h" | 52 #include "content/common/render_frame_setup.mojom.h" |
| 51 #include "content/common/site_isolation_policy.h" | 53 #include "content/common/site_isolation_policy.h" |
| 52 #include "content/common/swapped_out_messages.h" | 54 #include "content/common/swapped_out_messages.h" |
| 53 #include "content/public/browser/ax_event_notification_details.h" | 55 #include "content/public/browser/ax_event_notification_details.h" |
| 54 #include "content/public/browser/browser_accessibility_state.h" | 56 #include "content/public/browser/browser_accessibility_state.h" |
| (...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 187 render_frame_created_(false), | 189 render_frame_created_(false), |
| 188 navigations_suspended_(false), | 190 navigations_suspended_(false), |
| 189 is_waiting_for_beforeunload_ack_(false), | 191 is_waiting_for_beforeunload_ack_(false), |
| 190 unload_ack_is_for_navigation_(false), | 192 unload_ack_is_for_navigation_(false), |
| 191 is_loading_(false), | 193 is_loading_(false), |
| 192 pending_commit_(false), | 194 pending_commit_(false), |
| 193 nav_entry_id_(0), | 195 nav_entry_id_(0), |
| 194 accessibility_reset_token_(0), | 196 accessibility_reset_token_(0), |
| 195 accessibility_reset_count_(0), | 197 accessibility_reset_count_(0), |
| 196 no_create_browser_accessibility_manager_for_testing_(false), | 198 no_create_browser_accessibility_manager_for_testing_(false), |
| 199 web_ui_type_(WebUI::kNoWebUI), |
| 197 weak_ptr_factory_(this) { | 200 weak_ptr_factory_(this) { |
| 198 bool is_swapped_out = !!(flags & CREATE_RF_SWAPPED_OUT); | 201 bool is_swapped_out = !!(flags & CREATE_RF_SWAPPED_OUT); |
| 199 bool hidden = !!(flags & CREATE_RF_HIDDEN); | 202 bool hidden = !!(flags & CREATE_RF_HIDDEN); |
| 200 frame_tree_->AddRenderViewHostRef(render_view_host_); | 203 frame_tree_->AddRenderViewHostRef(render_view_host_); |
| 201 GetProcess()->AddRoute(routing_id_, this); | 204 GetProcess()->AddRoute(routing_id_, this); |
| 202 g_routing_id_frame_map.Get().insert(std::make_pair( | 205 g_routing_id_frame_map.Get().insert(std::make_pair( |
| 203 RenderFrameHostID(GetProcess()->GetID(), routing_id_), | 206 RenderFrameHostID(GetProcess()->GetID(), routing_id_), |
| 204 this)); | 207 this)); |
| 205 | 208 |
| 206 if (is_swapped_out) { | 209 if (is_swapped_out) { |
| (...skipping 19 matching lines...) Expand all Loading... |
| 226 render_widget_host_ = new RenderWidgetHostImpl(rwh_delegate, GetProcess(), | 229 render_widget_host_ = new RenderWidgetHostImpl(rwh_delegate, GetProcess(), |
| 227 widget_routing_id, hidden); | 230 widget_routing_id, hidden); |
| 228 render_widget_host_->set_owned_by_render_frame_host(true); | 231 render_widget_host_->set_owned_by_render_frame_host(true); |
| 229 } else { | 232 } else { |
| 230 DCHECK(!render_widget_host_->owned_by_render_frame_host()); | 233 DCHECK(!render_widget_host_->owned_by_render_frame_host()); |
| 231 } | 234 } |
| 232 } | 235 } |
| 233 } | 236 } |
| 234 | 237 |
| 235 RenderFrameHostImpl::~RenderFrameHostImpl() { | 238 RenderFrameHostImpl::~RenderFrameHostImpl() { |
| 239 // Release the WebUI before all else as the WebUI accesses the RenderFrameHost |
| 240 // during cleanup. |
| 241 ResetWebUI(); |
| 242 |
| 236 GetProcess()->RemoveRoute(routing_id_); | 243 GetProcess()->RemoveRoute(routing_id_); |
| 237 g_routing_id_frame_map.Get().erase( | 244 g_routing_id_frame_map.Get().erase( |
| 238 RenderFrameHostID(GetProcess()->GetID(), routing_id_)); | 245 RenderFrameHostID(GetProcess()->GetID(), routing_id_)); |
| 239 | 246 |
| 240 if (delegate_ && render_frame_created_) | 247 if (delegate_ && render_frame_created_) |
| 241 delegate_->RenderFrameDeleted(this); | 248 delegate_->RenderFrameDeleted(this); |
| 242 | 249 |
| 243 // If this was swapped out, it already decremented the active frame count of | 250 // If this was swapped out, it already decremented the active frame count of |
| 244 // the SiteInstance it belongs to. | 251 // the SiteInstance it belongs to. |
| 245 if (IsRFHStateActive(rfh_state_)) | 252 if (IsRFHStateActive(rfh_state_)) |
| (...skipping 963 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1209 } | 1216 } |
| 1210 | 1217 |
| 1211 void RenderFrameHostImpl::OnSwappedOut() { | 1218 void RenderFrameHostImpl::OnSwappedOut() { |
| 1212 // Ignore spurious swap out ack. | 1219 // Ignore spurious swap out ack. |
| 1213 if (rfh_state_ != STATE_PENDING_SWAP_OUT) | 1220 if (rfh_state_ != STATE_PENDING_SWAP_OUT) |
| 1214 return; | 1221 return; |
| 1215 | 1222 |
| 1216 TRACE_EVENT_ASYNC_END0("navigation", "RenderFrameHostImpl::SwapOut", this); | 1223 TRACE_EVENT_ASYNC_END0("navigation", "RenderFrameHostImpl::SwapOut", this); |
| 1217 swapout_event_monitor_timeout_->Stop(); | 1224 swapout_event_monitor_timeout_->Stop(); |
| 1218 | 1225 |
| 1226 ResetWebUI(); |
| 1219 | 1227 |
| 1220 // If this is a main frame RFH that's about to be deleted, update its RVH's | 1228 // If this is a main frame RFH that's about to be deleted, update its RVH's |
| 1221 // swapped-out state here, since SetState won't be called once this RFH is | 1229 // swapped-out state here, since SetState won't be called once this RFH is |
| 1222 // deleted below. https://crbug.com/505887 | 1230 // deleted below. https://crbug.com/505887 |
| 1223 if (frame_tree_node_->IsMainFrame() && | 1231 if (frame_tree_node_->IsMainFrame() && |
| 1224 frame_tree_node_->render_manager()->IsPendingDeletion(this)) { | 1232 frame_tree_node_->render_manager()->IsPendingDeletion(this)) { |
| 1225 render_view_host_->set_is_active(false); | 1233 render_view_host_->set_is_active(false); |
| 1226 render_view_host_->set_is_swapped_out(true); | 1234 render_view_host_->set_is_swapped_out(true); |
| 1227 } | 1235 } |
| 1228 | 1236 |
| (...skipping 813 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2042 bool RenderFrameHostImpl::IsFocused() { | 2050 bool RenderFrameHostImpl::IsFocused() { |
| 2043 // TODO(mlamouri,kenrb): call GetRenderWidgetHost() directly when it stops | 2051 // TODO(mlamouri,kenrb): call GetRenderWidgetHost() directly when it stops |
| 2044 // returning nullptr in some cases. See https://crbug.com/455245. | 2052 // returning nullptr in some cases. See https://crbug.com/455245. |
| 2045 return RenderWidgetHostImpl::From( | 2053 return RenderWidgetHostImpl::From( |
| 2046 GetView()->GetRenderWidgetHost())->is_focused() && | 2054 GetView()->GetRenderWidgetHost())->is_focused() && |
| 2047 frame_tree_->GetFocusedFrame() && | 2055 frame_tree_->GetFocusedFrame() && |
| 2048 (frame_tree_->GetFocusedFrame() == frame_tree_node() || | 2056 (frame_tree_->GetFocusedFrame() == frame_tree_node() || |
| 2049 frame_tree_->GetFocusedFrame()->IsDescendantOf(frame_tree_node())); | 2057 frame_tree_->GetFocusedFrame()->IsDescendantOf(frame_tree_node())); |
| 2050 } | 2058 } |
| 2051 | 2059 |
| 2060 bool RenderFrameHostImpl::UpdateWebUI(const GURL& dest_url, |
| 2061 int entry_bindings) { |
| 2062 WebUI::TypeID new_web_ui_type = WebUI::kNoWebUI; |
| 2063 if (dest_url.is_valid()) { |
| 2064 new_web_ui_type = |
| 2065 WebUIControllerFactoryRegistry::GetInstance()->GetWebUIType( |
| 2066 GetSiteInstance()->GetBrowserContext(), dest_url); |
| 2067 } |
| 2068 |
| 2069 WebUIImpl* prev_web_ui = web_ui_.get(); |
| 2070 if (new_web_ui_type == WebUI::kNoWebUI) { |
| 2071 ResetWebUI(); |
| 2072 } else { |
| 2073 // The current WebUI should be reused when dest_url requires a WebUI and its |
| 2074 // type matches the current. Otherwise replace it with a new one. |
| 2075 if (web_ui_type_ != new_web_ui_type) { |
| 2076 web_ui_ = delegate_->CreateWebUIForRenderFrameHost(dest_url); |
| 2077 DCHECK(web_ui_); |
| 2078 web_ui_type_ = new_web_ui_type; |
| 2079 |
| 2080 // If we have assigned (zero or more) bindings to the NavigationEntry in |
| 2081 // the past, make sure we're not granting it different bindings than it |
| 2082 // had before. If so, note it and don't give it any bindings, to avoid a |
| 2083 // potential privilege escalation. |
| 2084 if (entry_bindings != NavigationEntryImpl::kInvalidBindings && |
| 2085 web_ui_->GetBindings() != entry_bindings) { |
| 2086 RecordAction( |
| 2087 base::UserMetricsAction("ProcessSwapBindingsMismatch_RVHM")); |
| 2088 ResetWebUI(); |
| 2089 return !!prev_web_ui; |
| 2090 } |
| 2091 } |
| 2092 } |
| 2093 DCHECK_EQ(!web_ui_, web_ui_type_ == WebUI::kNoWebUI); |
| 2094 |
| 2095 // Check RenderViewHost for proper bindings. |
| 2096 if (web_ui_ && !render_view_host_->GetProcess()->IsForGuestsOnly()) { |
| 2097 // If a WebUI was created for the URL and the RenderView is not in a guest |
| 2098 // process, then enable missing bindings with the RenderViewHost. |
| 2099 int new_bindings = web_ui_->GetBindings(); |
| 2100 if ((render_view_host_->GetEnabledBindings() & new_bindings) != |
| 2101 new_bindings) { |
| 2102 render_view_host_->AllowBindings(new_bindings); |
| 2103 } |
| 2104 } else if (render_view_host_->is_active()) { |
| 2105 // If the ongoing navigation is not to a WebUI or the RenderView is in a |
| 2106 // guest process, ensure that we don't create an unprivileged RenderView in |
| 2107 // a WebUI-enabled process unless it's swapped out. |
| 2108 bool url_acceptable_for_webui = |
| 2109 WebUIControllerFactoryRegistry::GetInstance()->IsURLAcceptableForWebUI( |
| 2110 GetSiteInstance()->GetBrowserContext(), dest_url); |
| 2111 if (!url_acceptable_for_webui) { |
| 2112 CHECK(!ChildProcessSecurityPolicyImpl::GetInstance()->HasWebUIBindings( |
| 2113 GetProcess()->GetID())); |
| 2114 } |
| 2115 } |
| 2116 return prev_web_ui != web_ui_.get(); |
| 2117 } |
| 2118 |
| 2052 const image_downloader::ImageDownloaderPtr& | 2119 const image_downloader::ImageDownloaderPtr& |
| 2053 RenderFrameHostImpl::GetMojoImageDownloader() { | 2120 RenderFrameHostImpl::GetMojoImageDownloader() { |
| 2054 if (!mojo_image_downloader_.get() && GetServiceRegistry()) { | 2121 if (!mojo_image_downloader_.get() && GetServiceRegistry()) { |
| 2055 GetServiceRegistry()->ConnectToRemoteService( | 2122 GetServiceRegistry()->ConnectToRemoteService( |
| 2056 mojo::GetProxy(&mojo_image_downloader_)); | 2123 mojo::GetProxy(&mojo_image_downloader_)); |
| 2057 } | 2124 } |
| 2058 return mojo_image_downloader_; | 2125 return mojo_image_downloader_; |
| 2059 } | 2126 } |
| 2060 | 2127 |
| 2061 bool RenderFrameHostImpl::IsSameSiteInstance( | 2128 bool RenderFrameHostImpl::IsSameSiteInstance( |
| (...skipping 291 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2353 // Copy the common fields. | 2420 // Copy the common fields. |
| 2354 *dst = src; | 2421 *dst = src; |
| 2355 | 2422 |
| 2356 if (src.routing_id != -1) | 2423 if (src.routing_id != -1) |
| 2357 dst->tree_id = RoutingIDToAXTreeID(src.routing_id); | 2424 dst->tree_id = RoutingIDToAXTreeID(src.routing_id); |
| 2358 | 2425 |
| 2359 if (src.parent_routing_id != -1) | 2426 if (src.parent_routing_id != -1) |
| 2360 dst->parent_tree_id = RoutingIDToAXTreeID(src.parent_routing_id); | 2427 dst->parent_tree_id = RoutingIDToAXTreeID(src.parent_routing_id); |
| 2361 } | 2428 } |
| 2362 | 2429 |
| 2430 void RenderFrameHostImpl::ResetWebUI() { |
| 2431 web_ui_type_ = WebUI::kNoWebUI; |
| 2432 web_ui_.reset(); |
| 2433 } |
| 2434 |
| 2363 } // namespace content | 2435 } // namespace content |
| OLD | NEW |