| 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/metrics/user_metrics_action.h" | |
| 13 #include "base/process/kill.h" | 12 #include "base/process/kill.h" |
| 14 #include "base/time/time.h" | 13 #include "base/time/time.h" |
| 15 #include "content/browser/accessibility/accessibility_mode_helper.h" | 14 #include "content/browser/accessibility/accessibility_mode_helper.h" |
| 16 #include "content/browser/accessibility/browser_accessibility_manager.h" | 15 #include "content/browser/accessibility/browser_accessibility_manager.h" |
| 17 #include "content/browser/accessibility/browser_accessibility_state_impl.h" | 16 #include "content/browser/accessibility/browser_accessibility_state_impl.h" |
| 17 #include "content/browser/bad_message.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/frame_host/cross_process_frame_connector.h" | 19 #include "content/browser/frame_host/cross_process_frame_connector.h" |
| 20 #include "content/browser/frame_host/cross_site_transferring_request.h" | 20 #include "content/browser/frame_host/cross_site_transferring_request.h" |
| 21 #include "content/browser/frame_host/frame_accessibility.h" | 21 #include "content/browser/frame_host/frame_accessibility.h" |
| 22 #include "content/browser/frame_host/frame_tree.h" | 22 #include "content/browser/frame_host/frame_tree.h" |
| 23 #include "content/browser/frame_host/frame_tree_node.h" | 23 #include "content/browser/frame_host/frame_tree_node.h" |
| 24 #include "content/browser/frame_host/navigation_request.h" | 24 #include "content/browser/frame_host/navigation_request.h" |
| 25 #include "content/browser/frame_host/navigator.h" | 25 #include "content/browser/frame_host/navigator.h" |
| 26 #include "content/browser/frame_host/navigator_impl.h" | 26 #include "content/browser/frame_host/navigator_impl.h" |
| 27 #include "content/browser/frame_host/render_frame_host_delegate.h" | 27 #include "content/browser/frame_host/render_frame_host_delegate.h" |
| (...skipping 783 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 811 } | 811 } |
| 812 | 812 |
| 813 RenderProcessHost* process = GetProcess(); | 813 RenderProcessHost* process = GetProcess(); |
| 814 | 814 |
| 815 // Attempts to commit certain off-limits URL should be caught more strictly | 815 // Attempts to commit certain off-limits URL should be caught more strictly |
| 816 // than our FilterURL checks below. If a renderer violates this policy, it | 816 // than our FilterURL checks below. If a renderer violates this policy, it |
| 817 // should be killed. | 817 // should be killed. |
| 818 if (!CanCommitURL(validated_params.url)) { | 818 if (!CanCommitURL(validated_params.url)) { |
| 819 VLOG(1) << "Blocked URL " << validated_params.url.spec(); | 819 VLOG(1) << "Blocked URL " << validated_params.url.spec(); |
| 820 validated_params.url = GURL(url::kAboutBlankURL); | 820 validated_params.url = GURL(url::kAboutBlankURL); |
| 821 RecordAction(base::UserMetricsAction("CanCommitURL_BlockedAndKilled")); | |
| 822 // Kills the process. | 821 // Kills the process. |
| 823 process->ReceivedBadMessage(); | 822 bad_message::ReceivedBadMessage(process, |
| 823 bad_message::RFH_CAN_COMMIT_URL_BLOCKED); |
| 824 } | 824 } |
| 825 | 825 |
| 826 // Without this check, an evil renderer can trick the browser into creating | 826 // Without this check, an evil renderer can trick the browser into creating |
| 827 // a navigation entry for a banned URL. If the user clicks the back button | 827 // a navigation entry for a banned URL. If the user clicks the back button |
| 828 // followed by the forward button (or clicks reload, or round-trips through | 828 // followed by the forward button (or clicks reload, or round-trips through |
| 829 // session restore, etc), we'll think that the browser commanded the | 829 // session restore, etc), we'll think that the browser commanded the |
| 830 // renderer to load the URL and grant the renderer the privileges to request | 830 // renderer to load the URL and grant the renderer the privileges to request |
| 831 // the URL. To prevent this attack, we block the renderer from inserting | 831 // the URL. To prevent this attack, we block the renderer from inserting |
| 832 // banned URLs into the navigation controller in the first place. | 832 // banned URLs into the navigation controller in the first place. |
| 833 process->FilterURL(false, &validated_params.url); | 833 process->FilterURL(false, &validated_params.url); |
| 834 process->FilterURL(true, &validated_params.referrer.url); | 834 process->FilterURL(true, &validated_params.referrer.url); |
| 835 for (std::vector<GURL>::iterator it(validated_params.redirects.begin()); | 835 for (std::vector<GURL>::iterator it(validated_params.redirects.begin()); |
| 836 it != validated_params.redirects.end(); ++it) { | 836 it != validated_params.redirects.end(); ++it) { |
| 837 process->FilterURL(false, &(*it)); | 837 process->FilterURL(false, &(*it)); |
| 838 } | 838 } |
| 839 process->FilterURL(true, &validated_params.searchable_form_url); | 839 process->FilterURL(true, &validated_params.searchable_form_url); |
| 840 | 840 |
| 841 // Without this check, the renderer can trick the browser into using | 841 // Without this check, the renderer can trick the browser into using |
| 842 // filenames it can't access in a future session restore. | 842 // filenames it can't access in a future session restore. |
| 843 if (!render_view_host_->CanAccessFilesOfPageState( | 843 if (!render_view_host_->CanAccessFilesOfPageState( |
| 844 validated_params.page_state)) { | 844 validated_params.page_state)) { |
| 845 GetProcess()->ReceivedBadMessage(); | 845 bad_message::ReceivedBadMessage( |
| 846 GetProcess(), bad_message::RFH_CAN_ACCESS_FILES_OF_PAGE_STATE); |
| 846 return; | 847 return; |
| 847 } | 848 } |
| 848 | 849 |
| 849 accessibility_reset_count_ = 0; | 850 accessibility_reset_count_ = 0; |
| 850 frame_tree_node()->navigator()->DidNavigate(this, validated_params); | 851 frame_tree_node()->navigator()->DidNavigate(this, validated_params); |
| 851 } | 852 } |
| 852 | 853 |
| 853 void RenderFrameHostImpl::OnDidDropNavigation() { | 854 void RenderFrameHostImpl::OnDidDropNavigation() { |
| 854 // At the end of Navigate(), the delegate's DidStartLoading is called to force | 855 // At the end of Navigate(), the delegate's DidStartLoading is called to force |
| 855 // the spinner to start, even if the renderer didn't yet begin the load. If it | 856 // the spinner to start, even if the renderer didn't yet begin the load. If it |
| (...skipping 360 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1216 FrameTree* frame_tree = frame_tree_node()->frame_tree(); | 1217 FrameTree* frame_tree = frame_tree_node()->frame_tree(); |
| 1217 FrameTreeNode* child = | 1218 FrameTreeNode* child = |
| 1218 frame_tree->FindByRoutingID(GetProcess()->GetID(), frame_routing_id); | 1219 frame_tree->FindByRoutingID(GetProcess()->GetID(), frame_routing_id); |
| 1219 if (!child) | 1220 if (!child) |
| 1220 return; | 1221 return; |
| 1221 | 1222 |
| 1222 // Ensure that a frame can only update sandbox flags for its immediate | 1223 // Ensure that a frame can only update sandbox flags for its immediate |
| 1223 // children. If this is not the case, the renderer is considered malicious | 1224 // children. If this is not the case, the renderer is considered malicious |
| 1224 // and is killed. | 1225 // and is killed. |
| 1225 if (child->parent() != frame_tree_node()) { | 1226 if (child->parent() != frame_tree_node()) { |
| 1226 RecordAction(base::UserMetricsAction("BadMessageTerminate_RFH")); | 1227 bad_message::ReceivedBadMessage(GetProcess(), |
| 1227 GetProcess()->ReceivedBadMessage(); | 1228 bad_message::RFH_SANDBOX_FLAGS); |
| 1228 return; | 1229 return; |
| 1229 } | 1230 } |
| 1230 | 1231 |
| 1231 child->set_sandbox_flags(flags); | 1232 child->set_sandbox_flags(flags); |
| 1232 | 1233 |
| 1233 // Notify the RenderFrame if it lives in a different process from its | 1234 // Notify the RenderFrame if it lives in a different process from its |
| 1234 // parent. The frame's proxies in other processes also need to learn about | 1235 // parent. The frame's proxies in other processes also need to learn about |
| 1235 // the updated sandbox flags, but these notifications are sent later in | 1236 // the updated sandbox flags, but these notifications are sent later in |
| 1236 // RenderFrameHostManager::CommitPendingSandboxFlags(), when the frame | 1237 // RenderFrameHostManager::CommitPendingSandboxFlags(), when the frame |
| 1237 // navigates and the new sandbox flags take effect. | 1238 // navigates and the new sandbox flags take effect. |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1274 } | 1275 } |
| 1275 | 1276 |
| 1276 void RenderFrameHostImpl::OnDispatchLoad() { | 1277 void RenderFrameHostImpl::OnDispatchLoad() { |
| 1277 CHECK(base::CommandLine::ForCurrentProcess()->HasSwitch( | 1278 CHECK(base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 1278 switches::kSitePerProcess)); | 1279 switches::kSitePerProcess)); |
| 1279 // Only frames with an out-of-process parent frame should be sending this | 1280 // Only frames with an out-of-process parent frame should be sending this |
| 1280 // message. | 1281 // message. |
| 1281 RenderFrameProxyHost* proxy = | 1282 RenderFrameProxyHost* proxy = |
| 1282 frame_tree_node()->render_manager()->GetProxyToParent(); | 1283 frame_tree_node()->render_manager()->GetProxyToParent(); |
| 1283 if (!proxy) { | 1284 if (!proxy) { |
| 1284 GetProcess()->ReceivedBadMessage(); | 1285 bad_message::ReceivedBadMessage(GetProcess(), |
| 1286 bad_message::RFH_NO_PROXY_TO_PARENT); |
| 1285 return; | 1287 return; |
| 1286 } | 1288 } |
| 1287 | 1289 |
| 1288 proxy->Send(new FrameMsg_DispatchLoad(proxy->GetRoutingID())); | 1290 proxy->Send(new FrameMsg_DispatchLoad(proxy->GetRoutingID())); |
| 1289 } | 1291 } |
| 1290 | 1292 |
| 1291 void RenderFrameHostImpl::OnAccessibilityEvents( | 1293 void RenderFrameHostImpl::OnAccessibilityEvents( |
| 1292 const std::vector<AccessibilityHostMsg_EventParams>& params, | 1294 const std::vector<AccessibilityHostMsg_EventParams>& params, |
| 1293 int reset_token) { | 1295 int reset_token) { |
| 1294 // Don't process this IPC if either we're waiting on a reset and this | 1296 // Don't process this IPC if either we're waiting on a reset and this |
| (...skipping 675 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1970 void RenderFrameHostImpl::DidUseGeolocationPermission() { | 1972 void RenderFrameHostImpl::DidUseGeolocationPermission() { |
| 1971 RenderFrameHost* top_frame = frame_tree_node()->frame_tree()->GetMainFrame(); | 1973 RenderFrameHost* top_frame = frame_tree_node()->frame_tree()->GetMainFrame(); |
| 1972 GetContentClient()->browser()->RegisterPermissionUsage( | 1974 GetContentClient()->browser()->RegisterPermissionUsage( |
| 1973 PERMISSION_GEOLOCATION, | 1975 PERMISSION_GEOLOCATION, |
| 1974 delegate_->GetAsWebContents(), | 1976 delegate_->GetAsWebContents(), |
| 1975 GetLastCommittedURL().GetOrigin(), | 1977 GetLastCommittedURL().GetOrigin(), |
| 1976 top_frame->GetLastCommittedURL().GetOrigin()); | 1978 top_frame->GetLastCommittedURL().GetOrigin()); |
| 1977 } | 1979 } |
| 1978 | 1980 |
| 1979 } // namespace content | 1981 } // namespace content |
| OLD | NEW |