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 428 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
457 OnRunJavaScriptMessage) | 456 OnRunJavaScriptMessage) |
458 IPC_MESSAGE_HANDLER_DELAY_REPLY(FrameHostMsg_RunBeforeUnloadConfirm, | 457 IPC_MESSAGE_HANDLER_DELAY_REPLY(FrameHostMsg_RunBeforeUnloadConfirm, |
459 OnRunBeforeUnloadConfirm) | 458 OnRunBeforeUnloadConfirm) |
460 IPC_MESSAGE_HANDLER(FrameHostMsg_DidAccessInitialDocument, | 459 IPC_MESSAGE_HANDLER(FrameHostMsg_DidAccessInitialDocument, |
461 OnDidAccessInitialDocument) | 460 OnDidAccessInitialDocument) |
462 IPC_MESSAGE_HANDLER(FrameHostMsg_DidChangeOpener, OnDidChangeOpener) | 461 IPC_MESSAGE_HANDLER(FrameHostMsg_DidChangeOpener, OnDidChangeOpener) |
463 IPC_MESSAGE_HANDLER(FrameHostMsg_DidChangeName, OnDidChangeName) | 462 IPC_MESSAGE_HANDLER(FrameHostMsg_DidChangeName, OnDidChangeName) |
464 IPC_MESSAGE_HANDLER(FrameHostMsg_DidAssignPageId, OnDidAssignPageId) | 463 IPC_MESSAGE_HANDLER(FrameHostMsg_DidAssignPageId, OnDidAssignPageId) |
465 IPC_MESSAGE_HANDLER(FrameHostMsg_DidChangeSandboxFlags, | 464 IPC_MESSAGE_HANDLER(FrameHostMsg_DidChangeSandboxFlags, |
466 OnDidChangeSandboxFlags) | 465 OnDidChangeSandboxFlags) |
466 IPC_MESSAGE_HANDLER(FrameHostMsg_DidChangeFrameOwnerProperties, | |
467 OnDidChangeFrameOwnerProperties) | |
467 IPC_MESSAGE_HANDLER(FrameHostMsg_UpdateTitle, OnUpdateTitle) | 468 IPC_MESSAGE_HANDLER(FrameHostMsg_UpdateTitle, OnUpdateTitle) |
468 IPC_MESSAGE_HANDLER(FrameHostMsg_UpdateEncoding, OnUpdateEncoding) | 469 IPC_MESSAGE_HANDLER(FrameHostMsg_UpdateEncoding, OnUpdateEncoding) |
469 IPC_MESSAGE_HANDLER(FrameHostMsg_BeginNavigation, | 470 IPC_MESSAGE_HANDLER(FrameHostMsg_BeginNavigation, |
470 OnBeginNavigation) | 471 OnBeginNavigation) |
471 IPC_MESSAGE_HANDLER(FrameHostMsg_DispatchLoad, OnDispatchLoad) | 472 IPC_MESSAGE_HANDLER(FrameHostMsg_DispatchLoad, OnDispatchLoad) |
472 IPC_MESSAGE_HANDLER(FrameHostMsg_TextSurroundingSelectionResponse, | 473 IPC_MESSAGE_HANDLER(FrameHostMsg_TextSurroundingSelectionResponse, |
473 OnTextSurroundingSelectionResponse) | 474 OnTextSurroundingSelectionResponse) |
474 IPC_MESSAGE_HANDLER(AccessibilityHostMsg_Events, OnAccessibilityEvents) | 475 IPC_MESSAGE_HANDLER(AccessibilityHostMsg_Events, OnAccessibilityEvents) |
475 IPC_MESSAGE_HANDLER(AccessibilityHostMsg_LocationChanges, | 476 IPC_MESSAGE_HANDLER(AccessibilityHostMsg_LocationChanges, |
476 OnAccessibilityLocationChanges) | 477 OnAccessibilityLocationChanges) |
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
622 | 623 |
623 DCHECK(GetProcess()->HasConnection()); | 624 DCHECK(GetProcess()->HasConnection()); |
624 | 625 |
625 FrameMsg_NewFrame_Params params; | 626 FrameMsg_NewFrame_Params params; |
626 params.routing_id = routing_id_; | 627 params.routing_id = routing_id_; |
627 params.proxy_routing_id = proxy_routing_id; | 628 params.proxy_routing_id = proxy_routing_id; |
628 params.opener_routing_id = opener_routing_id; | 629 params.opener_routing_id = opener_routing_id; |
629 params.parent_routing_id = parent_routing_id; | 630 params.parent_routing_id = parent_routing_id; |
630 params.previous_sibling_routing_id = previous_sibling_routing_id; | 631 params.previous_sibling_routing_id = previous_sibling_routing_id; |
631 params.replication_state = frame_tree_node()->current_replication_state(); | 632 params.replication_state = frame_tree_node()->current_replication_state(); |
633 params.frame_owner_properties = frame_tree_node()->frame_owner_properties(); | |
632 | 634 |
633 if (render_widget_host_) { | 635 if (render_widget_host_) { |
634 params.widget_params.routing_id = render_widget_host_->GetRoutingID(); | 636 params.widget_params.routing_id = render_widget_host_->GetRoutingID(); |
635 params.widget_params.hidden = render_widget_host_->is_hidden(); | 637 params.widget_params.hidden = render_widget_host_->is_hidden(); |
636 } else { | 638 } else { |
637 // MSG_ROUTING_NONE will prevent a new RenderWidget from being created in | 639 // MSG_ROUTING_NONE will prevent a new RenderWidget from being created in |
638 // the renderer process. | 640 // the renderer process. |
639 params.widget_params.routing_id = MSG_ROUTING_NONE; | 641 params.widget_params.routing_id = MSG_ROUTING_NONE; |
640 params.widget_params.hidden = true; | 642 params.widget_params.hidden = true; |
641 } | 643 } |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
711 logging::LogMessage("CONSOLE", line_no, resolved_level).stream() | 713 logging::LogMessage("CONSOLE", line_no, resolved_level).stream() |
712 << "\"" << message << "\", source: " << source_id << " (" << line_no | 714 << "\"" << message << "\", source: " << source_id << " (" << line_no |
713 << ")"; | 715 << ")"; |
714 } | 716 } |
715 } | 717 } |
716 | 718 |
717 void RenderFrameHostImpl::OnCreateChildFrame( | 719 void RenderFrameHostImpl::OnCreateChildFrame( |
718 int new_routing_id, | 720 int new_routing_id, |
719 blink::WebTreeScopeType scope, | 721 blink::WebTreeScopeType scope, |
720 const std::string& frame_name, | 722 const std::string& frame_name, |
721 blink::WebSandboxFlags sandbox_flags) { | 723 blink::WebSandboxFlags sandbox_flags, |
724 const blink::WebFrameOwnerProperties& frame_owner_properties) { | |
722 // It is possible that while a new RenderFrameHost was committed, the | 725 // It is possible that while a new RenderFrameHost was committed, the |
723 // RenderFrame corresponding to this host sent an IPC message to create a | 726 // RenderFrame corresponding to this host sent an IPC message to create a |
724 // frame and it is delivered after this host is swapped out. | 727 // frame and it is delivered after this host is swapped out. |
725 // Ignore such messages, as we know this RenderFrameHost is going away. | 728 // Ignore such messages, as we know this RenderFrameHost is going away. |
726 if (rfh_state_ != RenderFrameHostImpl::STATE_DEFAULT) | 729 if (rfh_state_ != RenderFrameHostImpl::STATE_DEFAULT) |
727 return; | 730 return; |
728 | 731 |
729 RenderFrameHostImpl* new_frame = | 732 RenderFrameHostImpl* new_frame = frame_tree_->AddFrame( |
730 frame_tree_->AddFrame(frame_tree_node_, GetProcess()->GetID(), | 733 frame_tree_node_, GetProcess()->GetID(), new_routing_id, scope, |
731 new_routing_id, scope, frame_name, sandbox_flags); | 734 frame_name, sandbox_flags, frame_owner_properties); |
732 if (!new_frame) | 735 if (!new_frame) |
733 return; | 736 return; |
734 | 737 |
735 // We know that the RenderFrame has been created in this case, immediately | 738 // We know that the RenderFrame has been created in this case, immediately |
736 // after the CreateChildFrame IPC was sent. | 739 // after the CreateChildFrame IPC was sent. |
737 new_frame->SetRenderFrameCreated(true); | 740 new_frame->SetRenderFrameCreated(true); |
738 } | 741 } |
739 | 742 |
740 void RenderFrameHostImpl::OnDetach() { | 743 void RenderFrameHostImpl::OnDetach() { |
741 frame_tree_->RemoveFrame(frame_tree_node_); | 744 frame_tree_->RemoveFrame(frame_tree_node_); |
(...skipping 556 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1298 | 1301 |
1299 void RenderFrameHostImpl::OnDidAssignPageId(int32 page_id) { | 1302 void RenderFrameHostImpl::OnDidAssignPageId(int32 page_id) { |
1300 // Update the RVH's current page ID so that future IPCs from the renderer | 1303 // Update the RVH's current page ID so that future IPCs from the renderer |
1301 // correspond to the new page. | 1304 // correspond to the new page. |
1302 render_view_host_->page_id_ = page_id; | 1305 render_view_host_->page_id_ = page_id; |
1303 } | 1306 } |
1304 | 1307 |
1305 void RenderFrameHostImpl::OnDidChangeSandboxFlags( | 1308 void RenderFrameHostImpl::OnDidChangeSandboxFlags( |
1306 int32 frame_routing_id, | 1309 int32 frame_routing_id, |
1307 blink::WebSandboxFlags flags) { | 1310 blink::WebSandboxFlags flags) { |
1308 FrameTree* frame_tree = frame_tree_node()->frame_tree(); | 1311 // Ensure that a frame can only update sandbox flags for its immediate |
1309 FrameTreeNode* child = | 1312 // children. If this is not the case, the renderer is considered malicious |
1310 frame_tree->FindByRoutingID(GetProcess()->GetID(), frame_routing_id); | 1313 // and is killed. |
1314 FrameTreeNode* child = CheckAndGetIfImmediateChild( | |
1315 frame_routing_id, bad_message::RFH_SANDBOX_FLAGS); | |
1311 if (!child) | 1316 if (!child) |
1312 return; | 1317 return; |
1313 | 1318 |
1314 // Ensure that a frame can only update sandbox flags for its immediate | |
1315 // children. If this is not the case, the renderer is considered malicious | |
1316 // and is killed. | |
1317 if (child->parent() != frame_tree_node()) { | |
1318 bad_message::ReceivedBadMessage(GetProcess(), | |
1319 bad_message::RFH_SANDBOX_FLAGS); | |
1320 return; | |
1321 } | |
1322 | |
1323 child->set_sandbox_flags(flags); | 1319 child->set_sandbox_flags(flags); |
1324 | 1320 |
1325 // Notify the RenderFrame if it lives in a different process from its | 1321 // Notify the RenderFrame if it lives in a different process from its |
1326 // parent. The frame's proxies in other processes also need to learn about | 1322 // parent. The frame's proxies in other processes also need to learn about |
1327 // the updated sandbox flags, but these notifications are sent later in | 1323 // the updated sandbox flags, but these notifications are sent later in |
1328 // RenderFrameHostManager::CommitPendingSandboxFlags(), when the frame | 1324 // RenderFrameHostManager::CommitPendingSandboxFlags(), when the frame |
1329 // navigates and the new sandbox flags take effect. | 1325 // navigates and the new sandbox flags take effect. |
1330 RenderFrameHost* child_rfh = child->current_frame_host(); | 1326 RenderFrameHost* child_rfh = child->current_frame_host(); |
1331 if (child_rfh->GetSiteInstance() != GetSiteInstance()) { | 1327 if (child_rfh->GetSiteInstance() != GetSiteInstance()) { |
1332 child_rfh->Send( | 1328 child_rfh->Send( |
1333 new FrameMsg_DidUpdateSandboxFlags(child_rfh->GetRoutingID(), flags)); | 1329 new FrameMsg_DidUpdateSandboxFlags(child_rfh->GetRoutingID(), flags)); |
1334 } | 1330 } |
1335 } | 1331 } |
1336 | 1332 |
1333 FrameTreeNode* RenderFrameHostImpl::CheckAndGetIfImmediateChild( | |
1334 int32 child_frame_routing_id, bad_message::BadMessageReason reason) { | |
alexmos
2015/10/02 21:24:20
nit: second parameter on separate line?
lazyboy
2015/10/05 22:16:08
Done.
| |
1335 FrameTreeNode* child = frame_tree_node()->frame_tree()->FindByRoutingID( | |
1336 GetProcess()->GetID(), child_frame_routing_id); | |
1337 if (child && child->parent() != frame_tree_node()) { | |
1338 bad_message::ReceivedBadMessage(GetProcess(), reason); | |
1339 return nullptr; | |
1340 } | |
1341 return child; | |
1342 } | |
1343 | |
1344 void RenderFrameHostImpl::OnDidChangeFrameOwnerProperties( | |
1345 int32 frame_routing_id, | |
1346 const blink::WebFrameOwnerProperties& frame_owner_properties) { | |
1347 FrameTreeNode* child = CheckAndGetIfImmediateChild( | |
1348 frame_routing_id, bad_message::RFH_OWNER_PROPERTY); | |
1349 if (!child) | |
1350 return; | |
1351 | |
1352 child->set_frame_owner_properties(frame_owner_properties); | |
1353 | |
1354 // Notify the RenderFrame if it lives in a different process from its | |
1355 // parent. | |
1356 RenderFrameHost* child_rfh = child->current_frame_host(); | |
1357 if (child_rfh->GetSiteInstance() != GetSiteInstance()) { | |
1358 child_rfh->Send(new FrameMsg_SetFrameOwnerProperties( | |
1359 child_rfh->GetRoutingID(), child->frame_owner_properties())); | |
alexmos
2015/10/02 21:24:19
nit: why not just pass |frame_owner_properties|?
lazyboy
2015/10/05 22:16:08
Done.
| |
1360 } | |
1361 } | |
1362 | |
1337 void RenderFrameHostImpl::OnUpdateTitle( | 1363 void RenderFrameHostImpl::OnUpdateTitle( |
1338 const base::string16& title, | 1364 const base::string16& title, |
1339 blink::WebTextDirection title_direction) { | 1365 blink::WebTextDirection title_direction) { |
1340 // This message is only sent for top-level frames. TODO(avi): when frame tree | 1366 // This message is only sent for top-level frames. TODO(avi): when frame tree |
1341 // mirroring works correctly, add a check here to enforce it. | 1367 // mirroring works correctly, add a check here to enforce it. |
1342 if (title.length() > kMaxTitleChars) { | 1368 if (title.length() > kMaxTitleChars) { |
1343 NOTREACHED() << "Renderer sent too many characters in title."; | 1369 NOTREACHED() << "Renderer sent too many characters in title."; |
1344 return; | 1370 return; |
1345 } | 1371 } |
1346 | 1372 |
(...skipping 901 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2248 BrowserPluginInstanceIDToAXTreeID(value))); | 2274 BrowserPluginInstanceIDToAXTreeID(value))); |
2249 break; | 2275 break; |
2250 case AX_CONTENT_INT_ATTRIBUTE_LAST: | 2276 case AX_CONTENT_INT_ATTRIBUTE_LAST: |
2251 NOTREACHED(); | 2277 NOTREACHED(); |
2252 break; | 2278 break; |
2253 } | 2279 } |
2254 } | 2280 } |
2255 } | 2281 } |
2256 | 2282 |
2257 } // namespace content | 2283 } // namespace content |
OLD | NEW |