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/bad_message.h" | 18 #include "content/browser/bad_message.h" |
19 #include "content/browser/child_process_security_policy_impl.h" | 19 #include "content/browser/child_process_security_policy_impl.h" |
| 20 #include "content/browser/child_process_security_policy_impl.h" |
20 #include "content/browser/devtools/render_frame_devtools_agent_host.h" | 21 #include "content/browser/devtools/render_frame_devtools_agent_host.h" |
21 #include "content/browser/frame_host/cross_process_frame_connector.h" | 22 #include "content/browser/frame_host/cross_process_frame_connector.h" |
22 #include "content/browser/frame_host/cross_site_transferring_request.h" | 23 #include "content/browser/frame_host/cross_site_transferring_request.h" |
23 #include "content/browser/frame_host/frame_mojo_shell.h" | 24 #include "content/browser/frame_host/frame_mojo_shell.h" |
24 #include "content/browser/frame_host/frame_tree.h" | 25 #include "content/browser/frame_host/frame_tree.h" |
25 #include "content/browser/frame_host/frame_tree_node.h" | 26 #include "content/browser/frame_host/frame_tree_node.h" |
26 #include "content/browser/frame_host/navigation_handle_impl.h" | 27 #include "content/browser/frame_host/navigation_handle_impl.h" |
27 #include "content/browser/frame_host/navigation_request.h" | 28 #include "content/browser/frame_host/navigation_request.h" |
28 #include "content/browser/frame_host/navigator.h" | 29 #include "content/browser/frame_host/navigator.h" |
29 #include "content/browser/frame_host/navigator_impl.h" | 30 #include "content/browser/frame_host/navigator_impl.h" |
30 #include "content/browser/frame_host/render_frame_host_delegate.h" | 31 #include "content/browser/frame_host/render_frame_host_delegate.h" |
31 #include "content/browser/frame_host/render_frame_proxy_host.h" | 32 #include "content/browser/frame_host/render_frame_proxy_host.h" |
32 #include "content/browser/frame_host/render_widget_host_view_child_frame.h" | 33 #include "content/browser/frame_host/render_widget_host_view_child_frame.h" |
33 #include "content/browser/geolocation/geolocation_service_context.h" | 34 #include "content/browser/geolocation/geolocation_service_context.h" |
34 #include "content/browser/permissions/permission_service_context.h" | 35 #include "content/browser/permissions/permission_service_context.h" |
35 #include "content/browser/permissions/permission_service_impl.h" | 36 #include "content/browser/permissions/permission_service_impl.h" |
36 #include "content/browser/presentation/presentation_service_impl.h" | 37 #include "content/browser/presentation/presentation_service_impl.h" |
37 #include "content/browser/renderer_host/input/input_router.h" | 38 #include "content/browser/renderer_host/input/input_router.h" |
38 #include "content/browser/renderer_host/input/timeout_monitor.h" | 39 #include "content/browser/renderer_host/input/timeout_monitor.h" |
39 #include "content/browser/renderer_host/render_process_host_impl.h" | 40 #include "content/browser/renderer_host/render_process_host_impl.h" |
40 #include "content/browser/renderer_host/render_view_host_delegate.h" | 41 #include "content/browser/renderer_host/render_view_host_delegate.h" |
41 #include "content/browser/renderer_host/render_view_host_delegate_view.h" | 42 #include "content/browser/renderer_host/render_view_host_delegate_view.h" |
42 #include "content/browser/renderer_host/render_view_host_impl.h" | 43 #include "content/browser/renderer_host/render_view_host_impl.h" |
43 #include "content/browser/renderer_host/render_widget_host_impl.h" | 44 #include "content/browser/renderer_host/render_widget_host_impl.h" |
44 #include "content/browser/renderer_host/render_widget_host_view_base.h" | 45 #include "content/browser/renderer_host/render_widget_host_view_base.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 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
186 routing_id_(routing_id), | 188 routing_id_(routing_id), |
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 accessibility_reset_token_(0), | 195 accessibility_reset_token_(0), |
194 accessibility_reset_count_(0), | 196 accessibility_reset_count_(0), |
195 no_create_browser_accessibility_manager_for_testing_(false), | 197 no_create_browser_accessibility_manager_for_testing_(false), |
| 198 web_ui_type_(WebUI::kNoWebUI), |
| 199 pending_web_ui_type_(WebUI::kNoWebUI), |
| 200 should_reuse_web_ui_(false), |
196 weak_ptr_factory_(this) { | 201 weak_ptr_factory_(this) { |
197 bool is_swapped_out = !!(flags & CREATE_RF_SWAPPED_OUT); | 202 bool is_swapped_out = !!(flags & CREATE_RF_SWAPPED_OUT); |
198 bool hidden = !!(flags & CREATE_RF_HIDDEN); | 203 bool hidden = !!(flags & CREATE_RF_HIDDEN); |
199 frame_tree_->AddRenderViewHostRef(render_view_host_); | 204 frame_tree_->AddRenderViewHostRef(render_view_host_); |
200 GetProcess()->AddRoute(routing_id_, this); | 205 GetProcess()->AddRoute(routing_id_, this); |
201 g_routing_id_frame_map.Get().insert(std::make_pair( | 206 g_routing_id_frame_map.Get().insert(std::make_pair( |
202 RenderFrameHostID(GetProcess()->GetID(), routing_id_), | 207 RenderFrameHostID(GetProcess()->GetID(), routing_id_), |
203 this)); | 208 this)); |
204 | 209 |
205 if (is_swapped_out) { | 210 if (is_swapped_out) { |
206 rfh_state_ = STATE_SWAPPED_OUT; | 211 rfh_state_ = STATE_SWAPPED_OUT; |
207 } else { | 212 } else { |
208 rfh_state_ = STATE_DEFAULT; | 213 rfh_state_ = STATE_DEFAULT; |
209 GetSiteInstance()->increment_active_frame_count(); | 214 GetSiteInstance()->increment_active_frame_count(); |
210 } | 215 } |
211 | 216 |
212 SetUpMojoIfNeeded(); | 217 SetUpMojoIfNeeded(); |
213 swapout_event_monitor_timeout_.reset(new TimeoutMonitor(base::Bind( | 218 swapout_event_monitor_timeout_.reset(new TimeoutMonitor(base::Bind( |
214 &RenderFrameHostImpl::OnSwappedOut, weak_ptr_factory_.GetWeakPtr()))); | 219 &RenderFrameHostImpl::OnSwappedOut, weak_ptr_factory_.GetWeakPtr()))); |
215 | 220 |
216 if (widget_routing_id != MSG_ROUTING_NONE) { | 221 if (widget_routing_id != MSG_ROUTING_NONE) { |
217 render_widget_host_ = new RenderWidgetHostImpl(rwh_delegate, GetProcess(), | 222 render_widget_host_ = new RenderWidgetHostImpl(rwh_delegate, GetProcess(), |
218 widget_routing_id, hidden); | 223 widget_routing_id, hidden); |
219 render_widget_host_->set_owned_by_render_frame_host(true); | 224 render_widget_host_->set_owned_by_render_frame_host(true); |
220 } | 225 } |
221 } | 226 } |
222 | 227 |
223 RenderFrameHostImpl::~RenderFrameHostImpl() { | 228 RenderFrameHostImpl::~RenderFrameHostImpl() { |
| 229 // Release the WebUI before all else as the WebUI accesses the RenderFrameHost |
| 230 // during cleanup. |
| 231 ResetWebUI(); |
| 232 |
224 GetProcess()->RemoveRoute(routing_id_); | 233 GetProcess()->RemoveRoute(routing_id_); |
225 g_routing_id_frame_map.Get().erase( | 234 g_routing_id_frame_map.Get().erase( |
226 RenderFrameHostID(GetProcess()->GetID(), routing_id_)); | 235 RenderFrameHostID(GetProcess()->GetID(), routing_id_)); |
227 | 236 |
228 if (delegate_ && render_frame_created_) | 237 if (delegate_ && render_frame_created_) |
229 delegate_->RenderFrameDeleted(this); | 238 delegate_->RenderFrameDeleted(this); |
230 | 239 |
231 // If this was swapped out, it already decremented the active frame count of | 240 // If this was swapped out, it already decremented the active frame count of |
232 // the SiteInstance it belongs to. | 241 // the SiteInstance it belongs to. |
233 if (IsRFHStateActive(rfh_state_)) | 242 if (IsRFHStateActive(rfh_state_)) |
(...skipping 785 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1019 // gone through this, therefore just return. | 1028 // gone through this, therefore just return. |
1020 if (rfh_state_ != RenderFrameHostImpl::STATE_DEFAULT) { | 1029 if (rfh_state_ != RenderFrameHostImpl::STATE_DEFAULT) { |
1021 NOTREACHED() << "RFH should be in default state when calling SwapOut."; | 1030 NOTREACHED() << "RFH should be in default state when calling SwapOut."; |
1022 return; | 1031 return; |
1023 } | 1032 } |
1024 | 1033 |
1025 SetState(RenderFrameHostImpl::STATE_PENDING_SWAP_OUT); | 1034 SetState(RenderFrameHostImpl::STATE_PENDING_SWAP_OUT); |
1026 swapout_event_monitor_timeout_->Start( | 1035 swapout_event_monitor_timeout_->Start( |
1027 base::TimeDelta::FromMilliseconds(RenderViewHostImpl::kUnloadTimeoutMS)); | 1036 base::TimeDelta::FromMilliseconds(RenderViewHostImpl::kUnloadTimeoutMS)); |
1028 | 1037 |
| 1038 ResetWebUI(); |
| 1039 |
1029 // There may be no proxy if there are no active views in the process. | 1040 // There may be no proxy if there are no active views in the process. |
1030 int proxy_routing_id = MSG_ROUTING_NONE; | 1041 int proxy_routing_id = MSG_ROUTING_NONE; |
1031 FrameReplicationState replication_state; | 1042 FrameReplicationState replication_state; |
1032 if (proxy) { | 1043 if (proxy) { |
1033 set_render_frame_proxy_host(proxy); | 1044 set_render_frame_proxy_host(proxy); |
1034 proxy_routing_id = proxy->GetRoutingID(); | 1045 proxy_routing_id = proxy->GetRoutingID(); |
1035 replication_state = proxy->frame_tree_node()->current_replication_state(); | 1046 replication_state = proxy->frame_tree_node()->current_replication_state(); |
1036 } | 1047 } |
1037 | 1048 |
1038 if (IsRenderFrameLive()) { | 1049 if (IsRenderFrameLive()) { |
(...skipping 936 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1975 bool RenderFrameHostImpl::IsFocused() { | 1986 bool RenderFrameHostImpl::IsFocused() { |
1976 // TODO(mlamouri,kenrb): call GetRenderWidgetHost() directly when it stops | 1987 // TODO(mlamouri,kenrb): call GetRenderWidgetHost() directly when it stops |
1977 // returning nullptr in some cases. See https://crbug.com/455245. | 1988 // returning nullptr in some cases. See https://crbug.com/455245. |
1978 return RenderWidgetHostImpl::From( | 1989 return RenderWidgetHostImpl::From( |
1979 GetView()->GetRenderWidgetHost())->is_focused() && | 1990 GetView()->GetRenderWidgetHost())->is_focused() && |
1980 frame_tree_->GetFocusedFrame() && | 1991 frame_tree_->GetFocusedFrame() && |
1981 (frame_tree_->GetFocusedFrame() == frame_tree_node() || | 1992 (frame_tree_->GetFocusedFrame() == frame_tree_node() || |
1982 frame_tree_->GetFocusedFrame()->IsDescendantOf(frame_tree_node())); | 1993 frame_tree_->GetFocusedFrame()->IsDescendantOf(frame_tree_node())); |
1983 } | 1994 } |
1984 | 1995 |
| 1996 void RenderFrameHostImpl::UpdatePendingWebUI(const GURL& dest_url, |
| 1997 int entry_bindings) { |
| 1998 WebUI::TypeID new_web_ui_type = |
| 1999 WebUIControllerFactoryRegistry::GetInstance()->GetWebUIType( |
| 2000 GetSiteInstance()->GetBrowserContext(), dest_url); |
| 2001 |
| 2002 // The current WebUI should be reused when dest_url requires a WebUI and its |
| 2003 // type matches the current. |
| 2004 should_reuse_web_ui_ = false; |
| 2005 if (new_web_ui_type != WebUI::kNoWebUI && web_ui_type_ == new_web_ui_type) { |
| 2006 DCHECK(web_ui_); |
| 2007 should_reuse_web_ui_ = true; |
| 2008 |
| 2009 // Reset the pending WebUI as the current one will be reused. |
| 2010 pending_web_ui_.reset(); |
| 2011 pending_web_ui_type_ = WebUI::kNoWebUI; |
| 2012 } else if (pending_web_ui_type_ != new_web_ui_type) { |
| 2013 // Otherwise create, update or reset the pending one if its type doesn't |
| 2014 // match the new type (if new type is kNoWebUI then it will be reset). |
| 2015 pending_web_ui_ = |
| 2016 CreateWebUI(dest_url, entry_bindings, &pending_web_ui_type_); |
| 2017 } |
| 2018 |
| 2019 DCHECK_EQ(!pending_web_ui_, pending_web_ui_type_ == WebUI::kNoWebUI); |
| 2020 } |
| 2021 |
| 2022 void RenderFrameHostImpl::CommitPendingWebUI() { |
| 2023 if (should_reuse_web_ui_) { |
| 2024 DCHECK(!pending_web_ui_ && pending_web_ui_type_ == WebUI::kNoWebUI); |
| 2025 should_reuse_web_ui_ = false; |
| 2026 } else { |
| 2027 web_ui_ = pending_web_ui_.Pass(); |
| 2028 web_ui_type_ = pending_web_ui_type_; |
| 2029 pending_web_ui_type_ = WebUI::kNoWebUI; |
| 2030 } |
| 2031 } |
| 2032 |
| 2033 void RenderFrameHostImpl::DiscardPendingWebUI() { |
| 2034 pending_web_ui_.reset(); |
| 2035 pending_web_ui_type_ = WebUI::kNoWebUI; |
| 2036 should_reuse_web_ui_ = false; |
| 2037 } |
| 2038 |
1985 const image_downloader::ImageDownloaderPtr& | 2039 const image_downloader::ImageDownloaderPtr& |
1986 RenderFrameHostImpl::GetMojoImageDownloader() { | 2040 RenderFrameHostImpl::GetMojoImageDownloader() { |
1987 if (!mojo_image_downloader_.get() && GetServiceRegistry()) { | 2041 if (!mojo_image_downloader_.get() && GetServiceRegistry()) { |
1988 GetServiceRegistry()->ConnectToRemoteService( | 2042 GetServiceRegistry()->ConnectToRemoteService( |
1989 mojo::GetProxy(&mojo_image_downloader_)); | 2043 mojo::GetProxy(&mojo_image_downloader_)); |
1990 } | 2044 } |
1991 return mojo_image_downloader_; | 2045 return mojo_image_downloader_; |
1992 } | 2046 } |
1993 | 2047 |
1994 bool RenderFrameHostImpl::IsSameSiteInstance( | 2048 bool RenderFrameHostImpl::IsSameSiteInstance( |
(...skipping 289 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2284 // Copy the common fields. | 2338 // Copy the common fields. |
2285 *dst = src; | 2339 *dst = src; |
2286 | 2340 |
2287 if (src.routing_id != -1) | 2341 if (src.routing_id != -1) |
2288 dst->tree_id = RoutingIDToAXTreeID(src.routing_id); | 2342 dst->tree_id = RoutingIDToAXTreeID(src.routing_id); |
2289 | 2343 |
2290 if (src.parent_routing_id != -1) | 2344 if (src.parent_routing_id != -1) |
2291 dst->parent_tree_id = RoutingIDToAXTreeID(src.parent_routing_id); | 2345 dst->parent_tree_id = RoutingIDToAXTreeID(src.parent_routing_id); |
2292 } | 2346 } |
2293 | 2347 |
| 2348 scoped_ptr<WebUIImpl> RenderFrameHostImpl::CreateWebUI( |
| 2349 const GURL& dest_url, |
| 2350 int entry_bindings, |
| 2351 WebUI::TypeID* web_ui_type) { |
| 2352 if (!dest_url.is_valid()) { |
| 2353 *web_ui_type = WebUI::kNoWebUI; |
| 2354 return nullptr; |
| 2355 } |
| 2356 |
| 2357 scoped_ptr<WebUIImpl> web_ui; |
| 2358 *web_ui_type = WebUIControllerFactoryRegistry::GetInstance()->GetWebUIType( |
| 2359 GetSiteInstance()->GetBrowserContext(), dest_url); |
| 2360 if (*web_ui_type != WebUI::kNoWebUI) { |
| 2361 web_ui = delegate_->CreateWebUIForRenderFrameHost(dest_url); |
| 2362 DCHECK(web_ui); |
| 2363 |
| 2364 // If we have assigned (zero or more) bindings to the NavigationEntry in the |
| 2365 // past, make sure we're not granting it different bindings than it had |
| 2366 // before. If so, note it and don't give it any bindings, to avoid a |
| 2367 // potential privilege escalation. |
| 2368 if (entry_bindings != NavigationEntryImpl::kInvalidBindings && |
| 2369 web_ui->GetBindings() != entry_bindings) { |
| 2370 RecordAction(base::UserMetricsAction("ProcessSwapBindingsMismatch_RVHM")); |
| 2371 *web_ui_type = WebUI::kNoWebUI; |
| 2372 return nullptr; |
| 2373 } |
| 2374 } |
| 2375 |
| 2376 // Check RenderViewHost for proper bindings. |
| 2377 if (web_ui && !render_view_host_->GetProcess()->IsForGuestsOnly()) { |
| 2378 // If a WebUI was created for the URL and the RenderView is not in a guest |
| 2379 // process, then enable missing bindings with the RenderViewHost. |
| 2380 int new_bindings = web_ui->GetBindings(); |
| 2381 if ((render_view_host_->GetEnabledBindings() & new_bindings) != |
| 2382 new_bindings) { |
| 2383 render_view_host_->AllowBindings(new_bindings); |
| 2384 } |
| 2385 } else if (render_view_host_->is_active()) { |
| 2386 // If the ongoing navigation is not to a WebUI or the RenderView is in a |
| 2387 // guest process, ensure that we don't create an unprivileged RenderView in |
| 2388 // a WebUI-enabled process unless it's swapped out. |
| 2389 bool url_acceptable_for_webui = |
| 2390 WebUIControllerFactoryRegistry::GetInstance()->IsURLAcceptableForWebUI( |
| 2391 GetSiteInstance()->GetBrowserContext(), dest_url); |
| 2392 if (!url_acceptable_for_webui) { |
| 2393 CHECK(!ChildProcessSecurityPolicyImpl::GetInstance()->HasWebUIBindings( |
| 2394 GetProcess()->GetID())); |
| 2395 } |
| 2396 } |
| 2397 |
| 2398 CHECK_EQ(!web_ui, *web_ui_type == WebUI::kNoWebUI); |
| 2399 return web_ui.Pass(); |
| 2400 } |
| 2401 |
| 2402 void RenderFrameHostImpl::ResetWebUI() { |
| 2403 web_ui_type_ = WebUI::kNoWebUI; |
| 2404 web_ui_.reset(); |
| 2405 pending_web_ui_type_ = WebUI::kNoWebUI; |
| 2406 pending_web_ui_.reset(); |
| 2407 } |
| 2408 |
2294 } // namespace content | 2409 } // namespace content |
OLD | NEW |