| 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" |
| 11 #include "base/logging.h" | 11 #include "base/logging.h" |
| 12 #include "content/browser/appcache/appcache_interceptor.h" | 12 #include "content/browser/appcache/appcache_interceptor.h" |
| 13 #include "content/browser/child_process_security_policy_impl.h" | 13 #include "content/browser/child_process_security_policy_impl.h" |
| 14 #include "content/browser/frame_host/cross_site_transferring_request.h" | 14 #include "content/browser/frame_host/cross_site_transferring_request.h" |
| 15 #include "content/browser/frame_host/render_frame_host_impl.h" | 15 #include "content/browser/frame_host/render_frame_host_impl.h" |
| 16 #include "content/browser/loader/resource_dispatcher_host_impl.h" | 16 #include "content/browser/loader/resource_dispatcher_host_impl.h" |
| 17 #include "content/browser/loader/resource_request_info_impl.h" | 17 #include "content/browser/loader/resource_request_info_impl.h" |
| 18 #include "content/browser/site_instance_impl.h" | 18 #include "content/browser/site_instance_impl.h" |
| 19 #include "content/browser/transition_request_manager.h" | |
| 20 #include "content/public/browser/browser_thread.h" | 19 #include "content/public/browser/browser_thread.h" |
| 21 #include "content/public/browser/content_browser_client.h" | 20 #include "content/public/browser/content_browser_client.h" |
| 22 #include "content/public/browser/global_request_id.h" | 21 #include "content/public/browser/global_request_id.h" |
| 23 #include "content/public/browser/resource_controller.h" | 22 #include "content/public/browser/resource_controller.h" |
| 24 #include "content/public/browser/site_instance.h" | 23 #include "content/public/browser/site_instance.h" |
| 25 #include "content/public/common/content_switches.h" | 24 #include "content/public/common/content_switches.h" |
| 26 #include "content/public/common/resource_response.h" | 25 #include "content/public/common/resource_response.h" |
| 27 #include "content/public/common/url_constants.h" | 26 #include "content/public/common/url_constants.h" |
| 28 #include "net/http/http_response_headers.h" | 27 #include "net/http/http_response_headers.h" |
| 29 #include "net/url_request/url_request.h" | 28 #include "net/url_request/url_request.h" |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 79 params.global_request_id, cross_site_transferring_request.Pass(), | 78 params.global_request_id, cross_site_transferring_request.Pass(), |
| 80 params.transfer_url_chain, params.referrer, | 79 params.transfer_url_chain, params.referrer, |
| 81 params.page_transition, params.should_replace_current_entry); | 80 params.page_transition, params.should_replace_current_entry); |
| 82 } else if (leak_requests_for_testing_ && cross_site_transferring_request) { | 81 } 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 | 82 // Some unit tests expect requests to be leaked in this case, so they can |
| 84 // pass them along manually. | 83 // pass them along manually. |
| 85 cross_site_transferring_request->ReleaseRequest(); | 84 cross_site_transferring_request->ReleaseRequest(); |
| 86 } | 85 } |
| 87 } | 86 } |
| 88 | 87 |
| 89 void OnDeferredAfterResponseStartedHelper( | |
| 90 const GlobalRequestID& global_request_id, | |
| 91 int render_frame_id, | |
| 92 const TransitionLayerData& transition_data) { | |
| 93 RenderFrameHostImpl* rfh = | |
| 94 RenderFrameHostImpl::FromID(global_request_id.child_id, render_frame_id); | |
| 95 if (rfh) | |
| 96 rfh->OnDeferredAfterResponseStarted(global_request_id, transition_data); | |
| 97 } | |
| 98 | |
| 99 // Returns whether a transfer is needed by doing a check on the UI thread. | 88 // Returns whether a transfer is needed by doing a check on the UI thread. |
| 100 bool CheckNavigationPolicyOnUI(GURL url, int process_id, int render_frame_id) { | 89 bool CheckNavigationPolicyOnUI(GURL url, int process_id, int render_frame_id) { |
| 101 CHECK(base::CommandLine::ForCurrentProcess()->HasSwitch( | 90 CHECK(base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 102 switches::kSitePerProcess)); | 91 switches::kSitePerProcess)); |
| 103 RenderFrameHostImpl* rfh = | 92 RenderFrameHostImpl* rfh = |
| 104 RenderFrameHostImpl::FromID(process_id, render_frame_id); | 93 RenderFrameHostImpl::FromID(process_id, render_frame_id); |
| 105 if (!rfh) | 94 if (!rfh) |
| 106 return false; | 95 return false; |
| 107 | 96 |
| 108 // A transfer is not needed if the current SiteInstance doesn't yet have a | 97 // A transfer is not needed if the current SiteInstance doesn't yet have a |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 149 ResourceResponse* response, | 138 ResourceResponse* response, |
| 150 bool* defer) { | 139 bool* defer) { |
| 151 response_ = response; | 140 response_ = response; |
| 152 has_started_response_ = true; | 141 has_started_response_ = true; |
| 153 | 142 |
| 154 // Store this handler on the ExtraRequestInfo, so that RDH can call our | 143 // Store this handler on the ExtraRequestInfo, so that RDH can call our |
| 155 // ResumeResponse method when we are ready to resume. | 144 // ResumeResponse method when we are ready to resume. |
| 156 ResourceRequestInfoImpl* info = GetRequestInfo(); | 145 ResourceRequestInfoImpl* info = GetRequestInfo(); |
| 157 info->set_cross_site_handler(this); | 146 info->set_cross_site_handler(this); |
| 158 | 147 |
| 159 TransitionLayerData transition_data; | 148 return OnNormalResponseStarted(response, defer); |
| 160 bool is_navigation_transition = | |
| 161 TransitionRequestManager::GetInstance()->GetPendingTransitionRequest( | |
| 162 info->GetChildID(), info->GetRenderFrameID(), request()->url(), | |
| 163 &transition_data); | |
| 164 | |
| 165 if (is_navigation_transition) { | |
| 166 if (response_.get()) | |
| 167 transition_data.response_headers = response_->head.headers; | |
| 168 transition_data.request_url = request()->url(); | |
| 169 | |
| 170 return OnNavigationTransitionResponseStarted(response, defer, | |
| 171 transition_data); | |
| 172 } else { | |
| 173 return OnNormalResponseStarted(response, defer); | |
| 174 } | |
| 175 } | 149 } |
| 176 | 150 |
| 177 bool CrossSiteResourceHandler::OnNormalResponseStarted( | 151 bool CrossSiteResourceHandler::OnNormalResponseStarted( |
| 178 ResourceResponse* response, | 152 ResourceResponse* response, |
| 179 bool* defer) { | 153 bool* defer) { |
| 180 // At this point, we know that the response is safe to send back to the | 154 // At this point, we know that the response is safe to send back to the |
| 181 // renderer: it is not a download, and it has passed the SSL and safe | 155 // renderer: it is not a download, and it has passed the SSL and safe |
| 182 // browsing checks. | 156 // browsing checks. |
| 183 // We should not have already started the transition before now. | 157 // We should not have already started the transition before now. |
| 184 DCHECK(!in_cross_site_transition_); | 158 DCHECK(!in_cross_site_transition_); |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 234 // pause to let the UI thread set up the transfer. | 208 // pause to let the UI thread set up the transfer. |
| 235 StartCrossSiteTransition(response); | 209 StartCrossSiteTransition(response); |
| 236 | 210 |
| 237 // Defer loading until after the new renderer process has issued a | 211 // Defer loading until after the new renderer process has issued a |
| 238 // corresponding request. | 212 // corresponding request. |
| 239 *defer = true; | 213 *defer = true; |
| 240 OnDidDefer(); | 214 OnDidDefer(); |
| 241 return true; | 215 return true; |
| 242 } | 216 } |
| 243 | 217 |
| 244 bool CrossSiteResourceHandler::OnNavigationTransitionResponseStarted( | |
| 245 ResourceResponse* response, | |
| 246 bool* defer, | |
| 247 const TransitionLayerData& transition_data) { | |
| 248 ResourceRequestInfoImpl* info = GetRequestInfo(); | |
| 249 | |
| 250 GlobalRequestID global_id(info->GetChildID(), info->GetRequestID()); | |
| 251 int render_frame_id = info->GetRenderFrameID(); | |
| 252 BrowserThread::PostTask( | |
| 253 BrowserThread::UI, | |
| 254 FROM_HERE, | |
| 255 base::Bind( | |
| 256 &OnDeferredAfterResponseStartedHelper, | |
| 257 global_id, | |
| 258 render_frame_id, | |
| 259 transition_data)); | |
| 260 | |
| 261 *defer = true; | |
| 262 OnDidDefer(); | |
| 263 return true; | |
| 264 } | |
| 265 | |
| 266 void CrossSiteResourceHandler::ResumeResponseDeferredAtStart(int request_id) { | |
| 267 bool defer = false; | |
| 268 if (!OnNormalResponseStarted(response_.get(), &defer)) { | |
| 269 controller()->Cancel(); | |
| 270 } else if (!defer) { | |
| 271 ResumeIfDeferred(); | |
| 272 } | |
| 273 } | |
| 274 | |
| 275 void CrossSiteResourceHandler::ResumeOrTransfer(bool is_transfer) { | 218 void CrossSiteResourceHandler::ResumeOrTransfer(bool is_transfer) { |
| 276 if (is_transfer) { | 219 if (is_transfer) { |
| 277 StartCrossSiteTransition(response_.get()); | 220 StartCrossSiteTransition(response_.get()); |
| 278 } else { | 221 } else { |
| 279 ResumeResponse(); | 222 ResumeResponse(); |
| 280 } | 223 } |
| 281 } | 224 } |
| 282 | 225 |
| 283 bool CrossSiteResourceHandler::OnReadCompleted(int bytes_read, bool* defer) { | 226 bool CrossSiteResourceHandler::OnReadCompleted(int bytes_read, bool* defer) { |
| 284 CHECK(!in_cross_site_transition_); | 227 CHECK(!in_cross_site_transition_); |
| (...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 429 controller()->Resume(); | 372 controller()->Resume(); |
| 430 } | 373 } |
| 431 } | 374 } |
| 432 | 375 |
| 433 void CrossSiteResourceHandler::OnDidDefer() { | 376 void CrossSiteResourceHandler::OnDidDefer() { |
| 434 did_defer_ = true; | 377 did_defer_ = true; |
| 435 request()->LogBlockedBy("CrossSiteResourceHandler"); | 378 request()->LogBlockedBy("CrossSiteResourceHandler"); |
| 436 } | 379 } |
| 437 | 380 |
| 438 } // namespace content | 381 } // namespace content |
| OLD | NEW |