| 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/devtools/render_frame_devtools_agent_host.h" | 19 #include "content/browser/devtools/render_frame_devtools_agent_host.h" |
| 21 #include "content/browser/frame_host/cross_process_frame_connector.h" | 20 #include "content/browser/frame_host/cross_process_frame_connector.h" |
| 22 #include "content/browser/frame_host/cross_site_transferring_request.h" | 21 #include "content/browser/frame_host/cross_site_transferring_request.h" |
| 23 #include "content/browser/frame_host/frame_mojo_shell.h" | 22 #include "content/browser/frame_host/frame_mojo_shell.h" |
| 24 #include "content/browser/frame_host/frame_tree.h" | 23 #include "content/browser/frame_host/frame_tree.h" |
| 25 #include "content/browser/frame_host/frame_tree_node.h" | 24 #include "content/browser/frame_host/frame_tree_node.h" |
| 26 #include "content/browser/frame_host/navigation_handle_impl.h" | 25 #include "content/browser/frame_host/navigation_handle_impl.h" |
| 27 #include "content/browser/frame_host/navigation_request.h" | 26 #include "content/browser/frame_host/navigation_request.h" |
| 28 #include "content/browser/frame_host/navigator.h" | 27 #include "content/browser/frame_host/navigator.h" |
| (...skipping 429 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 458 OnRunJavaScriptMessage) | 457 OnRunJavaScriptMessage) |
| 459 IPC_MESSAGE_HANDLER_DELAY_REPLY(FrameHostMsg_RunBeforeUnloadConfirm, | 458 IPC_MESSAGE_HANDLER_DELAY_REPLY(FrameHostMsg_RunBeforeUnloadConfirm, |
| 460 OnRunBeforeUnloadConfirm) | 459 OnRunBeforeUnloadConfirm) |
| 461 IPC_MESSAGE_HANDLER(FrameHostMsg_DidAccessInitialDocument, | 460 IPC_MESSAGE_HANDLER(FrameHostMsg_DidAccessInitialDocument, |
| 462 OnDidAccessInitialDocument) | 461 OnDidAccessInitialDocument) |
| 463 IPC_MESSAGE_HANDLER(FrameHostMsg_DidChangeOpener, OnDidChangeOpener) | 462 IPC_MESSAGE_HANDLER(FrameHostMsg_DidChangeOpener, OnDidChangeOpener) |
| 464 IPC_MESSAGE_HANDLER(FrameHostMsg_DidChangeName, OnDidChangeName) | 463 IPC_MESSAGE_HANDLER(FrameHostMsg_DidChangeName, OnDidChangeName) |
| 465 IPC_MESSAGE_HANDLER(FrameHostMsg_DidAssignPageId, OnDidAssignPageId) | 464 IPC_MESSAGE_HANDLER(FrameHostMsg_DidAssignPageId, OnDidAssignPageId) |
| 466 IPC_MESSAGE_HANDLER(FrameHostMsg_DidChangeSandboxFlags, | 465 IPC_MESSAGE_HANDLER(FrameHostMsg_DidChangeSandboxFlags, |
| 467 OnDidChangeSandboxFlags) | 466 OnDidChangeSandboxFlags) |
| 467 IPC_MESSAGE_HANDLER(FrameHostMsg_DidChangeFrameOwnerProperties, |
| 468 OnDidChangeFrameOwnerProperties) |
| 468 IPC_MESSAGE_HANDLER(FrameHostMsg_UpdateTitle, OnUpdateTitle) | 469 IPC_MESSAGE_HANDLER(FrameHostMsg_UpdateTitle, OnUpdateTitle) |
| 469 IPC_MESSAGE_HANDLER(FrameHostMsg_UpdateEncoding, OnUpdateEncoding) | 470 IPC_MESSAGE_HANDLER(FrameHostMsg_UpdateEncoding, OnUpdateEncoding) |
| 470 IPC_MESSAGE_HANDLER(FrameHostMsg_BeginNavigation, | 471 IPC_MESSAGE_HANDLER(FrameHostMsg_BeginNavigation, |
| 471 OnBeginNavigation) | 472 OnBeginNavigation) |
| 472 IPC_MESSAGE_HANDLER(FrameHostMsg_DispatchLoad, OnDispatchLoad) | 473 IPC_MESSAGE_HANDLER(FrameHostMsg_DispatchLoad, OnDispatchLoad) |
| 473 IPC_MESSAGE_HANDLER(FrameHostMsg_TextSurroundingSelectionResponse, | 474 IPC_MESSAGE_HANDLER(FrameHostMsg_TextSurroundingSelectionResponse, |
| 474 OnTextSurroundingSelectionResponse) | 475 OnTextSurroundingSelectionResponse) |
| 475 IPC_MESSAGE_HANDLER(AccessibilityHostMsg_Events, OnAccessibilityEvents) | 476 IPC_MESSAGE_HANDLER(AccessibilityHostMsg_Events, OnAccessibilityEvents) |
| 476 IPC_MESSAGE_HANDLER(AccessibilityHostMsg_LocationChanges, | 477 IPC_MESSAGE_HANDLER(AccessibilityHostMsg_LocationChanges, |
| 477 OnAccessibilityLocationChanges) | 478 OnAccessibilityLocationChanges) |
| (...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 628 | 629 |
| 629 DCHECK(GetProcess()->HasConnection()); | 630 DCHECK(GetProcess()->HasConnection()); |
| 630 | 631 |
| 631 FrameMsg_NewFrame_Params params; | 632 FrameMsg_NewFrame_Params params; |
| 632 params.routing_id = routing_id_; | 633 params.routing_id = routing_id_; |
| 633 params.proxy_routing_id = proxy_routing_id; | 634 params.proxy_routing_id = proxy_routing_id; |
| 634 params.opener_routing_id = opener_routing_id; | 635 params.opener_routing_id = opener_routing_id; |
| 635 params.parent_routing_id = parent_routing_id; | 636 params.parent_routing_id = parent_routing_id; |
| 636 params.previous_sibling_routing_id = previous_sibling_routing_id; | 637 params.previous_sibling_routing_id = previous_sibling_routing_id; |
| 637 params.replication_state = frame_tree_node()->current_replication_state(); | 638 params.replication_state = frame_tree_node()->current_replication_state(); |
| 639 params.frame_owner_properties = frame_tree_node()->frame_owner_properties(); |
| 638 | 640 |
| 639 if (render_widget_host_) { | 641 if (render_widget_host_) { |
| 640 params.widget_params.routing_id = render_widget_host_->GetRoutingID(); | 642 params.widget_params.routing_id = render_widget_host_->GetRoutingID(); |
| 641 params.widget_params.hidden = render_widget_host_->is_hidden(); | 643 params.widget_params.hidden = render_widget_host_->is_hidden(); |
| 642 } else { | 644 } else { |
| 643 // MSG_ROUTING_NONE will prevent a new RenderWidget from being created in | 645 // MSG_ROUTING_NONE will prevent a new RenderWidget from being created in |
| 644 // the renderer process. | 646 // the renderer process. |
| 645 params.widget_params.routing_id = MSG_ROUTING_NONE; | 647 params.widget_params.routing_id = MSG_ROUTING_NONE; |
| 646 params.widget_params.hidden = true; | 648 params.widget_params.hidden = true; |
| 647 } | 649 } |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 717 logging::LogMessage("CONSOLE", line_no, resolved_level).stream() | 719 logging::LogMessage("CONSOLE", line_no, resolved_level).stream() |
| 718 << "\"" << message << "\", source: " << source_id << " (" << line_no | 720 << "\"" << message << "\", source: " << source_id << " (" << line_no |
| 719 << ")"; | 721 << ")"; |
| 720 } | 722 } |
| 721 } | 723 } |
| 722 | 724 |
| 723 void RenderFrameHostImpl::OnCreateChildFrame( | 725 void RenderFrameHostImpl::OnCreateChildFrame( |
| 724 int new_routing_id, | 726 int new_routing_id, |
| 725 blink::WebTreeScopeType scope, | 727 blink::WebTreeScopeType scope, |
| 726 const std::string& frame_name, | 728 const std::string& frame_name, |
| 727 blink::WebSandboxFlags sandbox_flags) { | 729 blink::WebSandboxFlags sandbox_flags, |
| 730 const blink::WebFrameOwnerProperties& frame_owner_properties) { |
| 728 // It is possible that while a new RenderFrameHost was committed, the | 731 // It is possible that while a new RenderFrameHost was committed, the |
| 729 // RenderFrame corresponding to this host sent an IPC message to create a | 732 // RenderFrame corresponding to this host sent an IPC message to create a |
| 730 // frame and it is delivered after this host is swapped out. | 733 // frame and it is delivered after this host is swapped out. |
| 731 // Ignore such messages, as we know this RenderFrameHost is going away. | 734 // Ignore such messages, as we know this RenderFrameHost is going away. |
| 732 if (rfh_state_ != RenderFrameHostImpl::STATE_DEFAULT) | 735 if (rfh_state_ != RenderFrameHostImpl::STATE_DEFAULT) |
| 733 return; | 736 return; |
| 734 | 737 |
| 735 RenderFrameHostImpl* new_frame = | 738 RenderFrameHostImpl* new_frame = frame_tree_->AddFrame( |
| 736 frame_tree_->AddFrame(frame_tree_node_, GetProcess()->GetID(), | 739 frame_tree_node_, GetProcess()->GetID(), new_routing_id, scope, |
| 737 new_routing_id, scope, frame_name, sandbox_flags); | 740 frame_name, sandbox_flags, frame_owner_properties); |
| 738 if (!new_frame) | 741 if (!new_frame) |
| 739 return; | 742 return; |
| 740 | 743 |
| 741 // We know that the RenderFrame has been created in this case, immediately | 744 // We know that the RenderFrame has been created in this case, immediately |
| 742 // after the CreateChildFrame IPC was sent. | 745 // after the CreateChildFrame IPC was sent. |
| 743 new_frame->SetRenderFrameCreated(true); | 746 new_frame->SetRenderFrameCreated(true); |
| 744 } | 747 } |
| 745 | 748 |
| 746 void RenderFrameHostImpl::OnDetach() { | 749 void RenderFrameHostImpl::OnDetach() { |
| 747 frame_tree_->RemoveFrame(frame_tree_node_); | 750 frame_tree_->RemoveFrame(frame_tree_node_); |
| (...skipping 555 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1303 | 1306 |
| 1304 void RenderFrameHostImpl::OnDidAssignPageId(int32 page_id) { | 1307 void RenderFrameHostImpl::OnDidAssignPageId(int32 page_id) { |
| 1305 // Update the RVH's current page ID so that future IPCs from the renderer | 1308 // Update the RVH's current page ID so that future IPCs from the renderer |
| 1306 // correspond to the new page. | 1309 // correspond to the new page. |
| 1307 render_view_host_->page_id_ = page_id; | 1310 render_view_host_->page_id_ = page_id; |
| 1308 } | 1311 } |
| 1309 | 1312 |
| 1310 void RenderFrameHostImpl::OnDidChangeSandboxFlags( | 1313 void RenderFrameHostImpl::OnDidChangeSandboxFlags( |
| 1311 int32 frame_routing_id, | 1314 int32 frame_routing_id, |
| 1312 blink::WebSandboxFlags flags) { | 1315 blink::WebSandboxFlags flags) { |
| 1313 FrameTree* frame_tree = frame_tree_node()->frame_tree(); | 1316 // Ensure that a frame can only update sandbox flags for its immediate |
| 1314 FrameTreeNode* child = | 1317 // children. If this is not the case, the renderer is considered malicious |
| 1315 frame_tree->FindByRoutingID(GetProcess()->GetID(), frame_routing_id); | 1318 // and is killed. |
| 1319 FrameTreeNode* child = CheckAndGetIfChild( |
| 1320 frame_routing_id, bad_message::RFH_SANDBOX_FLAGS); |
| 1316 if (!child) | 1321 if (!child) |
| 1317 return; | 1322 return; |
| 1318 | 1323 |
| 1319 // Ensure that a frame can only update sandbox flags for its immediate | |
| 1320 // children. If this is not the case, the renderer is considered malicious | |
| 1321 // and is killed. | |
| 1322 if (child->parent() != frame_tree_node()) { | |
| 1323 bad_message::ReceivedBadMessage(GetProcess(), | |
| 1324 bad_message::RFH_SANDBOX_FLAGS); | |
| 1325 return; | |
| 1326 } | |
| 1327 | |
| 1328 child->set_sandbox_flags(flags); | 1324 child->set_sandbox_flags(flags); |
| 1329 | 1325 |
| 1330 // Notify the RenderFrame if it lives in a different process from its | 1326 // Notify the RenderFrame if it lives in a different process from its |
| 1331 // parent. The frame's proxies in other processes also need to learn about | 1327 // parent. The frame's proxies in other processes also need to learn about |
| 1332 // the updated sandbox flags, but these notifications are sent later in | 1328 // the updated sandbox flags, but these notifications are sent later in |
| 1333 // RenderFrameHostManager::CommitPendingSandboxFlags(), when the frame | 1329 // RenderFrameHostManager::CommitPendingSandboxFlags(), when the frame |
| 1334 // navigates and the new sandbox flags take effect. | 1330 // navigates and the new sandbox flags take effect. |
| 1335 RenderFrameHost* child_rfh = child->current_frame_host(); | 1331 RenderFrameHost* child_rfh = child->current_frame_host(); |
| 1336 if (child_rfh->GetSiteInstance() != GetSiteInstance()) { | 1332 if (child_rfh->GetSiteInstance() != GetSiteInstance()) { |
| 1337 child_rfh->Send( | 1333 child_rfh->Send( |
| 1338 new FrameMsg_DidUpdateSandboxFlags(child_rfh->GetRoutingID(), flags)); | 1334 new FrameMsg_DidUpdateSandboxFlags(child_rfh->GetRoutingID(), flags)); |
| 1339 } | 1335 } |
| 1340 } | 1336 } |
| 1341 | 1337 |
| 1338 FrameTreeNode* RenderFrameHostImpl::CheckAndGetIfChild( |
| 1339 int32 child_frame_routing_id, |
| 1340 bad_message::BadMessageReason reason) { |
| 1341 FrameTreeNode* child = frame_tree_node()->frame_tree()->FindByRoutingID( |
| 1342 GetProcess()->GetID(), child_frame_routing_id); |
| 1343 if (child && child->parent() != frame_tree_node()) { |
| 1344 bad_message::ReceivedBadMessage(GetProcess(), reason); |
| 1345 return nullptr; |
| 1346 } |
| 1347 return child; |
| 1348 } |
| 1349 |
| 1350 void RenderFrameHostImpl::OnDidChangeFrameOwnerProperties( |
| 1351 int32 frame_routing_id, |
| 1352 const blink::WebFrameOwnerProperties& frame_owner_properties) { |
| 1353 FrameTreeNode* child = CheckAndGetIfChild( |
| 1354 frame_routing_id, bad_message::RFH_OWNER_PROPERTY); |
| 1355 if (!child) |
| 1356 return; |
| 1357 |
| 1358 child->set_frame_owner_properties(frame_owner_properties); |
| 1359 |
| 1360 // Notify the RenderFrame if it lives in a different process from its |
| 1361 // parent. |
| 1362 RenderFrameHost* child_rfh = child->current_frame_host(); |
| 1363 if (child_rfh->GetSiteInstance() != GetSiteInstance()) { |
| 1364 child_rfh->Send(new FrameMsg_SetFrameOwnerProperties( |
| 1365 child_rfh->GetRoutingID(), frame_owner_properties)); |
| 1366 } |
| 1367 } |
| 1368 |
| 1342 void RenderFrameHostImpl::OnUpdateTitle( | 1369 void RenderFrameHostImpl::OnUpdateTitle( |
| 1343 const base::string16& title, | 1370 const base::string16& title, |
| 1344 blink::WebTextDirection title_direction) { | 1371 blink::WebTextDirection title_direction) { |
| 1345 // This message is only sent for top-level frames. TODO(avi): when frame tree | 1372 // This message is only sent for top-level frames. TODO(avi): when frame tree |
| 1346 // mirroring works correctly, add a check here to enforce it. | 1373 // mirroring works correctly, add a check here to enforce it. |
| 1347 if (title.length() > kMaxTitleChars) { | 1374 if (title.length() > kMaxTitleChars) { |
| 1348 NOTREACHED() << "Renderer sent too many characters in title."; | 1375 NOTREACHED() << "Renderer sent too many characters in title."; |
| 1349 return; | 1376 return; |
| 1350 } | 1377 } |
| 1351 | 1378 |
| (...skipping 915 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2267 BrowserPluginInstanceIDToAXTreeID(value))); | 2294 BrowserPluginInstanceIDToAXTreeID(value))); |
| 2268 break; | 2295 break; |
| 2269 case AX_CONTENT_INT_ATTRIBUTE_LAST: | 2296 case AX_CONTENT_INT_ATTRIBUTE_LAST: |
| 2270 NOTREACHED(); | 2297 NOTREACHED(); |
| 2271 break; | 2298 break; |
| 2272 } | 2299 } |
| 2273 } | 2300 } |
| 2274 } | 2301 } |
| 2275 | 2302 |
| 2276 } // namespace content | 2303 } // namespace content |
| OLD | NEW |