| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/loader/cross_site_resource_handler.h" | 5 #include "content/browser/loader/cross_site_resource_handler.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 79 params.global_request_id, cross_site_transferring_request.Pass(), | 79 params.global_request_id, cross_site_transferring_request.Pass(), |
| 80 params.transfer_url_chain, params.referrer, | 80 params.transfer_url_chain, params.referrer, |
| 81 params.page_transition, params.should_replace_current_entry); | 81 params.page_transition, params.should_replace_current_entry); |
| 82 } else if (leak_requests_for_testing_ && cross_site_transferring_request) { | 82 } else if (leak_requests_for_testing_ && cross_site_transferring_request) { |
| 83 // Some unit tests expect requests to be leaked in this case, so they can | 83 // Some unit tests expect requests to be leaked in this case, so they can |
| 84 // pass them along manually. | 84 // pass them along manually. |
| 85 cross_site_transferring_request->ReleaseRequest(); | 85 cross_site_transferring_request->ReleaseRequest(); |
| 86 } | 86 } |
| 87 } | 87 } |
| 88 | 88 |
| 89 // Determines whether a navigation to |dest_url| may be completed using an | |
| 90 // existing RenderFrameHost, or whether transferring to a new RenderFrameHost | |
| 91 // backed by a different render process is required. This is a security policy | |
| 92 // check determined by the current site isolation mode, and must be done | |
| 93 // before the resource at |dest_url| is delivered to |rfh|. | |
| 94 // | |
| 95 // When this function returns true for a subframe, an out-of-process iframe | |
| 96 // must be created. | |
| 97 // | |
| 98 // TODO(nick): Move this function to RFHM. | |
| 99 bool IsRendererTransferNeededForNavigation(RenderFrameHostImpl* rfh, | |
| 100 const GURL& dest_url) { | |
| 101 // A transfer is not needed if the current SiteInstance doesn't yet have a | |
| 102 // site. This is the case for tests that use NavigateToURL. | |
| 103 if (!rfh->GetSiteInstance()->HasSite()) | |
| 104 return false; | |
| 105 | |
| 106 // For now, GuestViews never transfer on cross-site navigations. | |
| 107 WebContentsImpl* web_contents = | |
| 108 static_cast<WebContentsImpl*>(WebContents::FromRenderFrameHost(rfh)); | |
| 109 if (web_contents->GetBrowserPluginGuest()) | |
| 110 return false; | |
| 111 | |
| 112 GURL effective_url = SiteInstanceImpl::GetEffectiveURL( | |
| 113 rfh->GetSiteInstance()->GetBrowserContext(), dest_url); | |
| 114 | |
| 115 // TODO(nasko, nick): These following --site-per-process checks are | |
| 116 // overly simplistic. Update them to match all the cases | |
| 117 // considered by RenderFrameHostManager::DetermineSiteInstanceForURL. | |
| 118 if (SiteInstance::IsSameWebSite(rfh->GetSiteInstance()->GetBrowserContext(), | |
| 119 rfh->GetSiteInstance()->GetSiteURL(), | |
| 120 dest_url)) { | |
| 121 return false; // The same site, no transition needed. | |
| 122 } | |
| 123 | |
| 124 // The sites differ. If either one requires a dedicated process, | |
| 125 // then a transfer is needed. | |
| 126 return rfh->GetSiteInstance()->RequiresDedicatedProcess() || | |
| 127 SiteIsolationPolicy::DoesSiteRequireDedicatedProcess(effective_url); | |
| 128 } | |
| 129 | |
| 130 // Returns whether a transfer is needed by doing a check on the UI thread. | 89 // Returns whether a transfer is needed by doing a check on the UI thread. |
| 131 CrossSiteResourceHandler::NavigationDecision | 90 CrossSiteResourceHandler::NavigationDecision |
| 132 CheckNavigationPolicyOnUI(GURL real_url, int process_id, int render_frame_id) { | 91 CheckNavigationPolicyOnUI(GURL real_url, int process_id, int render_frame_id) { |
| 133 CHECK(SiteIsolationPolicy::AreCrossProcessFramesPossible()); | 92 CHECK(SiteIsolationPolicy::AreCrossProcessFramesPossible()); |
| 134 RenderFrameHostImpl* rfh = | 93 RenderFrameHostImpl* rfh = |
| 135 RenderFrameHostImpl::FromID(process_id, render_frame_id); | 94 RenderFrameHostImpl::FromID(process_id, render_frame_id); |
| 136 | 95 |
| 137 // Without a valid RFH against which to check, we must cancel the request, | 96 // Without a valid RFH against which to check, we must cancel the request, |
| 138 // to prevent the resource at |url| from being delivered to a potentially | 97 // to prevent the resource at |url| from being delivered to a potentially |
| 139 // unsuitable renderer process. | 98 // unsuitable renderer process. |
| 140 if (!rfh) | 99 if (!rfh) |
| 141 return CrossSiteResourceHandler::NavigationDecision::CANCEL_REQUEST; | 100 return CrossSiteResourceHandler::NavigationDecision::CANCEL_REQUEST; |
| 142 | 101 |
| 143 if (IsRendererTransferNeededForNavigation(rfh, real_url)) | 102 RenderFrameHostManager* manager = rfh->frame_tree_node()->render_manager(); |
| 103 if (manager->IsRendererTransferNeededForNavigation(rfh, real_url)) |
| 144 return CrossSiteResourceHandler::NavigationDecision::TRANSFER_REQUIRED; | 104 return CrossSiteResourceHandler::NavigationDecision::TRANSFER_REQUIRED; |
| 145 else | 105 else |
| 146 return CrossSiteResourceHandler::NavigationDecision::USE_EXISTING_RENDERER; | 106 return CrossSiteResourceHandler::NavigationDecision::USE_EXISTING_RENDERER; |
| 147 } | 107 } |
| 148 | 108 |
| 149 } // namespace | 109 } // namespace |
| 150 | 110 |
| 151 CrossSiteResourceHandler::CrossSiteResourceHandler( | 111 CrossSiteResourceHandler::CrossSiteResourceHandler( |
| 152 scoped_ptr<ResourceHandler> next_handler, | 112 scoped_ptr<ResourceHandler> next_handler, |
| 153 net::URLRequest* request) | 113 net::URLRequest* request) |
| (...skipping 267 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 421 controller()->Resume(); | 381 controller()->Resume(); |
| 422 } | 382 } |
| 423 } | 383 } |
| 424 | 384 |
| 425 void CrossSiteResourceHandler::OnDidDefer() { | 385 void CrossSiteResourceHandler::OnDidDefer() { |
| 426 did_defer_ = true; | 386 did_defer_ = true; |
| 427 request()->LogBlockedBy("CrossSiteResourceHandler"); | 387 request()->LogBlockedBy("CrossSiteResourceHandler"); |
| 428 } | 388 } |
| 429 | 389 |
| 430 } // namespace content | 390 } // namespace content |
| OLD | NEW |