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" | |
19 #include "content/browser/child_process_security_policy_impl.h" | 18 #include "content/browser/child_process_security_policy_impl.h" |
20 #include "content/browser/frame_host/cross_process_frame_connector.h" | 19 #include "content/browser/frame_host/cross_process_frame_connector.h" |
21 #include "content/browser/frame_host/cross_site_transferring_request.h" | 20 #include "content/browser/frame_host/cross_site_transferring_request.h" |
22 #include "content/browser/frame_host/frame_mojo_shell.h" | 21 #include "content/browser/frame_host/frame_mojo_shell.h" |
23 #include "content/browser/frame_host/frame_tree.h" | 22 #include "content/browser/frame_host/frame_tree.h" |
24 #include "content/browser/frame_host/frame_tree_node.h" | 23 #include "content/browser/frame_host/frame_tree_node.h" |
25 #include "content/browser/frame_host/navigation_handle_impl.h" | 24 #include "content/browser/frame_host/navigation_handle_impl.h" |
26 #include "content/browser/frame_host/navigation_request.h" | 25 #include "content/browser/frame_host/navigation_request.h" |
27 #include "content/browser/frame_host/navigator.h" | 26 #include "content/browser/frame_host/navigator.h" |
28 #include "content/browser/frame_host/navigator_impl.h" | 27 #include "content/browser/frame_host/navigator_impl.h" |
(...skipping 424 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
453 OnRunJavaScriptMessage) | 452 OnRunJavaScriptMessage) |
454 IPC_MESSAGE_HANDLER_DELAY_REPLY(FrameHostMsg_RunBeforeUnloadConfirm, | 453 IPC_MESSAGE_HANDLER_DELAY_REPLY(FrameHostMsg_RunBeforeUnloadConfirm, |
455 OnRunBeforeUnloadConfirm) | 454 OnRunBeforeUnloadConfirm) |
456 IPC_MESSAGE_HANDLER(FrameHostMsg_DidAccessInitialDocument, | 455 IPC_MESSAGE_HANDLER(FrameHostMsg_DidAccessInitialDocument, |
457 OnDidAccessInitialDocument) | 456 OnDidAccessInitialDocument) |
458 IPC_MESSAGE_HANDLER(FrameHostMsg_DidChangeOpener, OnDidChangeOpener) | 457 IPC_MESSAGE_HANDLER(FrameHostMsg_DidChangeOpener, OnDidChangeOpener) |
459 IPC_MESSAGE_HANDLER(FrameHostMsg_DidChangeName, OnDidChangeName) | 458 IPC_MESSAGE_HANDLER(FrameHostMsg_DidChangeName, OnDidChangeName) |
460 IPC_MESSAGE_HANDLER(FrameHostMsg_DidAssignPageId, OnDidAssignPageId) | 459 IPC_MESSAGE_HANDLER(FrameHostMsg_DidAssignPageId, OnDidAssignPageId) |
461 IPC_MESSAGE_HANDLER(FrameHostMsg_DidChangeSandboxFlags, | 460 IPC_MESSAGE_HANDLER(FrameHostMsg_DidChangeSandboxFlags, |
462 OnDidChangeSandboxFlags) | 461 OnDidChangeSandboxFlags) |
462 IPC_MESSAGE_HANDLER(FrameHostMsg_DidChangeFrameOwnerProperties, | |
463 OnDidChangeFrameOwnerProperties) | |
463 IPC_MESSAGE_HANDLER(FrameHostMsg_UpdateTitle, OnUpdateTitle) | 464 IPC_MESSAGE_HANDLER(FrameHostMsg_UpdateTitle, OnUpdateTitle) |
464 IPC_MESSAGE_HANDLER(FrameHostMsg_UpdateEncoding, OnUpdateEncoding) | 465 IPC_MESSAGE_HANDLER(FrameHostMsg_UpdateEncoding, OnUpdateEncoding) |
465 IPC_MESSAGE_HANDLER(FrameHostMsg_BeginNavigation, | 466 IPC_MESSAGE_HANDLER(FrameHostMsg_BeginNavigation, |
466 OnBeginNavigation) | 467 OnBeginNavigation) |
467 IPC_MESSAGE_HANDLER(FrameHostMsg_DispatchLoad, OnDispatchLoad) | 468 IPC_MESSAGE_HANDLER(FrameHostMsg_DispatchLoad, OnDispatchLoad) |
468 IPC_MESSAGE_HANDLER(FrameHostMsg_TextSurroundingSelectionResponse, | 469 IPC_MESSAGE_HANDLER(FrameHostMsg_TextSurroundingSelectionResponse, |
469 OnTextSurroundingSelectionResponse) | 470 OnTextSurroundingSelectionResponse) |
470 IPC_MESSAGE_HANDLER(AccessibilityHostMsg_Events, OnAccessibilityEvents) | 471 IPC_MESSAGE_HANDLER(AccessibilityHostMsg_Events, OnAccessibilityEvents) |
471 IPC_MESSAGE_HANDLER(AccessibilityHostMsg_LocationChanges, | 472 IPC_MESSAGE_HANDLER(AccessibilityHostMsg_LocationChanges, |
472 OnAccessibilityLocationChanges) | 473 OnAccessibilityLocationChanges) |
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
618 | 619 |
619 DCHECK(GetProcess()->HasConnection()); | 620 DCHECK(GetProcess()->HasConnection()); |
620 | 621 |
621 FrameMsg_NewFrame_Params params; | 622 FrameMsg_NewFrame_Params params; |
622 params.routing_id = routing_id_; | 623 params.routing_id = routing_id_; |
623 params.proxy_routing_id = proxy_routing_id; | 624 params.proxy_routing_id = proxy_routing_id; |
624 params.opener_routing_id = opener_routing_id; | 625 params.opener_routing_id = opener_routing_id; |
625 params.parent_routing_id = parent_routing_id; | 626 params.parent_routing_id = parent_routing_id; |
626 params.previous_sibling_routing_id = previous_sibling_routing_id; | 627 params.previous_sibling_routing_id = previous_sibling_routing_id; |
627 params.replication_state = frame_tree_node()->current_replication_state(); | 628 params.replication_state = frame_tree_node()->current_replication_state(); |
629 params.frame_owner_properties = frame_tree_node()->frame_owner_properties(); | |
628 | 630 |
629 if (render_widget_host_) { | 631 if (render_widget_host_) { |
630 params.widget_params.routing_id = render_widget_host_->GetRoutingID(); | 632 params.widget_params.routing_id = render_widget_host_->GetRoutingID(); |
631 params.widget_params.surface_id = render_widget_host_->surface_id(); | 633 params.widget_params.surface_id = render_widget_host_->surface_id(); |
632 params.widget_params.hidden = render_widget_host_->is_hidden(); | 634 params.widget_params.hidden = render_widget_host_->is_hidden(); |
633 } else { | 635 } else { |
634 // MSG_ROUTING_NONE will prevent a new RenderWidget from being created in | 636 // MSG_ROUTING_NONE will prevent a new RenderWidget from being created in |
635 // the renderer process. | 637 // the renderer process. |
636 params.widget_params.routing_id = MSG_ROUTING_NONE; | 638 params.widget_params.routing_id = MSG_ROUTING_NONE; |
637 params.widget_params.surface_id = 0; | 639 params.widget_params.surface_id = 0; |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
709 logging::LogMessage("CONSOLE", line_no, resolved_level).stream() | 711 logging::LogMessage("CONSOLE", line_no, resolved_level).stream() |
710 << "\"" << message << "\", source: " << source_id << " (" << line_no | 712 << "\"" << message << "\", source: " << source_id << " (" << line_no |
711 << ")"; | 713 << ")"; |
712 } | 714 } |
713 } | 715 } |
714 | 716 |
715 void RenderFrameHostImpl::OnCreateChildFrame( | 717 void RenderFrameHostImpl::OnCreateChildFrame( |
716 int new_routing_id, | 718 int new_routing_id, |
717 blink::WebTreeScopeType scope, | 719 blink::WebTreeScopeType scope, |
718 const std::string& frame_name, | 720 const std::string& frame_name, |
719 blink::WebSandboxFlags sandbox_flags) { | 721 blink::WebSandboxFlags sandbox_flags, |
722 const blink::WebFrameOwnerProperties& frame_owner_properties) { | |
720 // It is possible that while a new RenderFrameHost was committed, the | 723 // It is possible that while a new RenderFrameHost was committed, the |
721 // RenderFrame corresponding to this host sent an IPC message to create a | 724 // RenderFrame corresponding to this host sent an IPC message to create a |
722 // frame and it is delivered after this host is swapped out. | 725 // frame and it is delivered after this host is swapped out. |
723 // Ignore such messages, as we know this RenderFrameHost is going away. | 726 // Ignore such messages, as we know this RenderFrameHost is going away. |
724 if (rfh_state_ != RenderFrameHostImpl::STATE_DEFAULT) | 727 if (rfh_state_ != RenderFrameHostImpl::STATE_DEFAULT) |
725 return; | 728 return; |
726 | 729 |
727 RenderFrameHostImpl* new_frame = | 730 RenderFrameHostImpl* new_frame = frame_tree_->AddFrame( |
728 frame_tree_->AddFrame(frame_tree_node_, GetProcess()->GetID(), | 731 frame_tree_node_, GetProcess()->GetID(), new_routing_id, scope, |
729 new_routing_id, scope, frame_name, sandbox_flags); | 732 frame_name, sandbox_flags, frame_owner_properties); |
730 if (!new_frame) | 733 if (!new_frame) |
731 return; | 734 return; |
732 | 735 |
733 // We know that the RenderFrame has been created in this case, immediately | 736 // We know that the RenderFrame has been created in this case, immediately |
734 // after the CreateChildFrame IPC was sent. | 737 // after the CreateChildFrame IPC was sent. |
735 new_frame->SetRenderFrameCreated(true); | 738 new_frame->SetRenderFrameCreated(true); |
736 } | 739 } |
737 | 740 |
738 void RenderFrameHostImpl::OnDetach() { | 741 void RenderFrameHostImpl::OnDetach() { |
739 frame_tree_->RemoveFrame(frame_tree_node_); | 742 frame_tree_->RemoveFrame(frame_tree_node_); |
(...skipping 556 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1296 | 1299 |
1297 void RenderFrameHostImpl::OnDidAssignPageId(int32 page_id) { | 1300 void RenderFrameHostImpl::OnDidAssignPageId(int32 page_id) { |
1298 // Update the RVH's current page ID so that future IPCs from the renderer | 1301 // Update the RVH's current page ID so that future IPCs from the renderer |
1299 // correspond to the new page. | 1302 // correspond to the new page. |
1300 render_view_host_->page_id_ = page_id; | 1303 render_view_host_->page_id_ = page_id; |
1301 } | 1304 } |
1302 | 1305 |
1303 void RenderFrameHostImpl::OnDidChangeSandboxFlags( | 1306 void RenderFrameHostImpl::OnDidChangeSandboxFlags( |
1304 int32 frame_routing_id, | 1307 int32 frame_routing_id, |
1305 blink::WebSandboxFlags flags) { | 1308 blink::WebSandboxFlags flags) { |
1306 FrameTree* frame_tree = frame_tree_node()->frame_tree(); | 1309 // Ensure that a frame can only update sandbox flags for its immediate |
1307 FrameTreeNode* child = | 1310 // children. If this is not the case, the renderer is considered malicious |
1308 frame_tree->FindByRoutingID(GetProcess()->GetID(), frame_routing_id); | 1311 // and is killed. |
1312 FrameTreeNode* child = CheckAndGetIfImmediateChild( | |
alexmos
2015/09/21 18:53:22
I'm wondering if there's a better name for this.
lazyboy
2015/09/22 02:38:54
EnsureIfImmediateChildAndReturn? or maybe just dro
alexmos
2015/09/22 16:56:52
I actually like what you currently have a bit more
| |
1313 frame_routing_id, bad_message::RFH_SANDBOX_FLAGS); | |
1309 if (!child) | 1314 if (!child) |
1310 return; | 1315 return; |
1311 | 1316 |
1312 // Ensure that a frame can only update sandbox flags for its immediate | |
1313 // children. If this is not the case, the renderer is considered malicious | |
1314 // and is killed. | |
1315 if (child->parent() != frame_tree_node()) { | |
1316 bad_message::ReceivedBadMessage(GetProcess(), | |
1317 bad_message::RFH_SANDBOX_FLAGS); | |
1318 return; | |
1319 } | |
1320 | |
1321 child->set_sandbox_flags(flags); | 1317 child->set_sandbox_flags(flags); |
1322 | 1318 |
1323 // Notify the RenderFrame if it lives in a different process from its | 1319 // Notify the RenderFrame if it lives in a different process from its |
1324 // parent. The frame's proxies in other processes also need to learn about | 1320 // parent. The frame's proxies in other processes also need to learn about |
1325 // the updated sandbox flags, but these notifications are sent later in | 1321 // the updated sandbox flags, but these notifications are sent later in |
1326 // RenderFrameHostManager::CommitPendingSandboxFlags(), when the frame | 1322 // RenderFrameHostManager::CommitPendingSandboxFlags(), when the frame |
1327 // navigates and the new sandbox flags take effect. | 1323 // navigates and the new sandbox flags take effect. |
1328 RenderFrameHost* child_rfh = child->current_frame_host(); | 1324 RenderFrameHost* child_rfh = child->current_frame_host(); |
1329 if (child_rfh->GetSiteInstance() != GetSiteInstance()) { | 1325 if (child_rfh->GetSiteInstance() != GetSiteInstance()) { |
1330 child_rfh->Send( | 1326 child_rfh->Send( |
1331 new FrameMsg_DidUpdateSandboxFlags(child_rfh->GetRoutingID(), flags)); | 1327 new FrameMsg_DidUpdateSandboxFlags(child_rfh->GetRoutingID(), flags)); |
1332 } | 1328 } |
1333 } | 1329 } |
1334 | 1330 |
1331 FrameTreeNode* RenderFrameHostImpl::CheckAndGetIfImmediateChild( | |
1332 int32 child_frame_routing_id, bad_message::BadMessageReason reason) { | |
1333 FrameTreeNode* child = frame_tree_node()->frame_tree()->FindByRoutingID( | |
1334 GetProcess()->GetID(), child_frame_routing_id); | |
1335 if (child && child->parent() != frame_tree_node()) { | |
1336 bad_message::ReceivedBadMessage(GetProcess(), reason); | |
1337 return nullptr; | |
1338 } | |
1339 return child; | |
1340 } | |
1341 | |
1342 void RenderFrameHostImpl::OnDidChangeFrameOwnerProperties( | |
1343 int32 frame_routing_id, | |
1344 const blink::WebFrameOwnerProperties& frame_owner_properties) { | |
1345 FrameTreeNode* child = CheckAndGetIfImmediateChild( | |
1346 frame_routing_id, bad_message::RFH_OWNER_PROPERTY); | |
1347 if (!child) | |
1348 return; | |
1349 | |
1350 child->SetFrameOwnerProperties(frame_owner_properties); | |
1351 | |
1352 // Notify the RenderFrame if it lives in a different process from its | |
1353 // parent. | |
1354 RenderFrameHost* child_rfh = child->current_frame_host(); | |
1355 if (child_rfh->GetSiteInstance() != GetSiteInstance()) { | |
1356 child_rfh->Send(new FrameMsg_SetFrameOwnerProperties( | |
1357 child_rfh->GetRoutingID(), child->frame_owner_properties())); | |
1358 } | |
1359 } | |
1360 | |
1335 void RenderFrameHostImpl::OnUpdateTitle( | 1361 void RenderFrameHostImpl::OnUpdateTitle( |
1336 const base::string16& title, | 1362 const base::string16& title, |
1337 blink::WebTextDirection title_direction) { | 1363 blink::WebTextDirection title_direction) { |
1338 // This message is only sent for top-level frames. TODO(avi): when frame tree | 1364 // This message is only sent for top-level frames. TODO(avi): when frame tree |
1339 // mirroring works correctly, add a check here to enforce it. | 1365 // mirroring works correctly, add a check here to enforce it. |
1340 if (title.length() > kMaxTitleChars) { | 1366 if (title.length() > kMaxTitleChars) { |
1341 NOTREACHED() << "Renderer sent too many characters in title."; | 1367 NOTREACHED() << "Renderer sent too many characters in title."; |
1342 return; | 1368 return; |
1343 } | 1369 } |
1344 | 1370 |
(...skipping 897 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2242 BrowserPluginInstanceIDToAXTreeID(value))); | 2268 BrowserPluginInstanceIDToAXTreeID(value))); |
2243 break; | 2269 break; |
2244 case AX_CONTENT_INT_ATTRIBUTE_LAST: | 2270 case AX_CONTENT_INT_ATTRIBUTE_LAST: |
2245 NOTREACHED(); | 2271 NOTREACHED(); |
2246 break; | 2272 break; |
2247 } | 2273 } |
2248 } | 2274 } |
2249 } | 2275 } |
2250 | 2276 |
2251 } // namespace content | 2277 } // namespace content |
OLD | NEW |