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 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
81 } else if (leak_requests_for_testing_ && cross_site_transferring_request) { | 81 } else if (leak_requests_for_testing_ && cross_site_transferring_request) { |
82 // 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 |
83 // pass them along manually. | 83 // pass them along manually. |
84 cross_site_transferring_request->ReleaseRequest(); | 84 cross_site_transferring_request->ReleaseRequest(); |
85 } | 85 } |
86 } | 86 } |
87 | 87 |
88 void OnDeferredAfterResponseStartedHelper( | 88 void OnDeferredAfterResponseStartedHelper( |
89 const GlobalRequestID& global_request_id, | 89 const GlobalRequestID& global_request_id, |
90 int render_frame_id, | 90 int render_frame_id, |
91 const scoped_refptr<net::HttpResponseHeaders>& headers, | 91 const TransitionLayerData& transition_data) { |
92 const GURL& url) { | |
93 RenderFrameHostImpl* rfh = | 92 RenderFrameHostImpl* rfh = |
94 RenderFrameHostImpl::FromID(global_request_id.child_id, render_frame_id); | 93 RenderFrameHostImpl::FromID(global_request_id.child_id, render_frame_id); |
95 if (rfh) | 94 if (rfh) |
96 rfh->OnDeferredAfterResponseStarted(global_request_id, headers, url); | 95 rfh->OnDeferredAfterResponseStarted(global_request_id, transition_data); |
97 } | 96 } |
98 | 97 |
99 bool CheckNavigationPolicyOnUI(GURL url, int process_id, int render_frame_id) { | 98 bool CheckNavigationPolicyOnUI(GURL url, int process_id, int render_frame_id) { |
100 RenderFrameHostImpl* rfh = | 99 RenderFrameHostImpl* rfh = |
101 RenderFrameHostImpl::FromID(process_id, render_frame_id); | 100 RenderFrameHostImpl::FromID(process_id, render_frame_id); |
102 if (!rfh) | 101 if (!rfh) |
103 return false; | 102 return false; |
104 | 103 |
105 // TODO(nasko): This check is very simplistic and is used temporarily only | 104 // TODO(nasko): This check is very simplistic and is used temporarily only |
106 // for --site-per-process. It should be updated to match the check performed | 105 // for --site-per-process. It should be updated to match the check performed |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
146 ResourceResponse* response, | 145 ResourceResponse* response, |
147 bool* defer) { | 146 bool* defer) { |
148 response_ = response; | 147 response_ = response; |
149 has_started_response_ = true; | 148 has_started_response_ = true; |
150 | 149 |
151 // Store this handler on the ExtraRequestInfo, so that RDH can call our | 150 // Store this handler on the ExtraRequestInfo, so that RDH can call our |
152 // ResumeResponse method when we are ready to resume. | 151 // ResumeResponse method when we are ready to resume. |
153 ResourceRequestInfoImpl* info = GetRequestInfo(); | 152 ResourceRequestInfoImpl* info = GetRequestInfo(); |
154 info->set_cross_site_handler(this); | 153 info->set_cross_site_handler(this); |
155 | 154 |
| 155 TransitionLayerData transition_data; |
156 bool is_navigation_transition = | 156 bool is_navigation_transition = |
157 TransitionRequestManager::GetInstance()->HasPendingTransitionRequest( | 157 TransitionRequestManager::GetInstance()->HasPendingTransitionRequest( |
158 info->GetChildID(), info->GetRenderFrameID()); | 158 info->GetChildID(), info->GetRenderFrameID(), request()->url(), |
| 159 &transition_data); |
159 | 160 |
160 if (is_navigation_transition) | 161 if (is_navigation_transition) { |
161 return OnNavigationTransitionResponseStarted(response, defer); | 162 if (response_) |
162 else | 163 transition_data.response_headers = response_->head.headers; |
| 164 transition_data.request_url = request()->url(); |
| 165 |
| 166 return OnNavigationTransitionResponseStarted(response, defer, |
| 167 transition_data); |
| 168 } else { |
163 return OnNormalResponseStarted(response, defer); | 169 return OnNormalResponseStarted(response, defer); |
| 170 } |
164 } | 171 } |
165 | 172 |
166 bool CrossSiteResourceHandler::OnNormalResponseStarted( | 173 bool CrossSiteResourceHandler::OnNormalResponseStarted( |
167 ResourceResponse* response, | 174 ResourceResponse* response, |
168 bool* defer) { | 175 bool* defer) { |
169 // At this point, we know that the response is safe to send back to the | 176 // At this point, we know that the response is safe to send back to the |
170 // renderer: it is not a download, and it has passed the SSL and safe | 177 // renderer: it is not a download, and it has passed the SSL and safe |
171 // browsing checks. | 178 // browsing checks. |
172 // We should not have already started the transition before now. | 179 // We should not have already started the transition before now. |
173 DCHECK(!in_cross_site_transition_); | 180 DCHECK(!in_cross_site_transition_); |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
224 StartCrossSiteTransition(response, should_transfer); | 231 StartCrossSiteTransition(response, should_transfer); |
225 | 232 |
226 // Defer loading until after the onunload event handler has run. | 233 // Defer loading until after the onunload event handler has run. |
227 *defer = true; | 234 *defer = true; |
228 OnDidDefer(); | 235 OnDidDefer(); |
229 return true; | 236 return true; |
230 } | 237 } |
231 | 238 |
232 bool CrossSiteResourceHandler::OnNavigationTransitionResponseStarted( | 239 bool CrossSiteResourceHandler::OnNavigationTransitionResponseStarted( |
233 ResourceResponse* response, | 240 ResourceResponse* response, |
234 bool* defer) { | 241 bool* defer, |
| 242 const TransitionLayerData& transition_data) { |
235 ResourceRequestInfoImpl* info = GetRequestInfo(); | 243 ResourceRequestInfoImpl* info = GetRequestInfo(); |
236 | 244 |
237 scoped_refptr<net::HttpResponseHeaders> headers; | |
238 if (response_) | |
239 headers = response_->head.headers; | |
240 GURL url = request()->url(); | |
241 | |
242 GlobalRequestID global_id(info->GetChildID(), info->GetRequestID()); | 245 GlobalRequestID global_id(info->GetChildID(), info->GetRequestID()); |
243 int render_frame_id = info->GetRenderFrameID(); | 246 int render_frame_id = info->GetRenderFrameID(); |
244 BrowserThread::PostTask( | 247 BrowserThread::PostTask( |
245 BrowserThread::UI, | 248 BrowserThread::UI, |
246 FROM_HERE, | 249 FROM_HERE, |
247 base::Bind( | 250 base::Bind( |
248 &OnDeferredAfterResponseStartedHelper, | 251 &OnDeferredAfterResponseStartedHelper, |
249 global_id, | 252 global_id, |
250 render_frame_id, | 253 render_frame_id, |
251 headers, | 254 transition_data)); |
252 url)); | |
253 | 255 |
254 *defer = true; | 256 *defer = true; |
255 OnDidDefer(); | 257 OnDidDefer(); |
256 return true; | 258 return true; |
257 } | 259 } |
258 | 260 |
259 void CrossSiteResourceHandler::ResumeResponseDeferredAtStart(int request_id) { | 261 void CrossSiteResourceHandler::ResumeResponseDeferredAtStart(int request_id) { |
260 bool defer = false; | 262 bool defer = false; |
261 if (!OnNormalResponseStarted(response_, &defer)) { | 263 if (!OnNormalResponseStarted(response_, &defer)) { |
262 controller()->Cancel(); | 264 controller()->Cancel(); |
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
439 controller()->Resume(); | 441 controller()->Resume(); |
440 } | 442 } |
441 } | 443 } |
442 | 444 |
443 void CrossSiteResourceHandler::OnDidDefer() { | 445 void CrossSiteResourceHandler::OnDidDefer() { |
444 did_defer_ = true; | 446 did_defer_ = true; |
445 request()->LogBlockedBy("CrossSiteResourceHandler"); | 447 request()->LogBlockedBy("CrossSiteResourceHandler"); |
446 } | 448 } |
447 | 449 |
448 } // namespace content | 450 } // namespace content |
OLD | NEW |