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 <string> | 5 #include <string> |
6 | 6 |
7 #include "content/browser/renderer_host/cross_site_resource_handler.h" | 7 #include "content/browser/renderer_host/cross_site_resource_handler.h" |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
11 #include "content/browser/renderer_host/render_view_host_impl.h" | 11 #include "content/browser/renderer_host/render_view_host_impl.h" |
12 #include "content/browser/renderer_host/resource_dispatcher_host.h" | 12 #include "content/browser/renderer_host/resource_dispatcher_host.h" |
13 #include "content/browser/renderer_host/resource_dispatcher_host_request_info.h" | 13 #include "content/browser/renderer_host/resource_request_info_impl.h" |
14 #include "content/public/browser/browser_thread.h" | 14 #include "content/public/browser/browser_thread.h" |
15 #include "content/public/browser/global_request_id.h" | 15 #include "content/public/browser/global_request_id.h" |
16 #include "content/public/browser/render_view_host_delegate.h" | 16 #include "content/public/browser/render_view_host_delegate.h" |
17 #include "content/public/common/resource_response.h" | 17 #include "content/public/common/resource_response.h" |
18 #include "net/base/io_buffer.h" | 18 #include "net/base/io_buffer.h" |
19 #include "net/http/http_response_headers.h" | 19 #include "net/http/http_response_headers.h" |
20 | 20 |
21 namespace content { | 21 namespace content { |
22 | 22 |
23 namespace { | 23 namespace { |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
73 DCHECK(!in_cross_site_transition_); | 73 DCHECK(!in_cross_site_transition_); |
74 has_started_response_ = true; | 74 has_started_response_ = true; |
75 | 75 |
76 // Look up the request and associated info. | 76 // Look up the request and associated info. |
77 GlobalRequestID global_id(render_process_host_id_, request_id); | 77 GlobalRequestID global_id(render_process_host_id_, request_id); |
78 net::URLRequest* request = rdh_->GetURLRequest(global_id); | 78 net::URLRequest* request = rdh_->GetURLRequest(global_id); |
79 if (!request) { | 79 if (!request) { |
80 DLOG(WARNING) << "Request wasn't found"; | 80 DLOG(WARNING) << "Request wasn't found"; |
81 return false; | 81 return false; |
82 } | 82 } |
83 ResourceDispatcherHostRequestInfo* info = | 83 ResourceRequestInfoImpl* info = |
84 ResourceDispatcherHost::InfoForRequest(request); | 84 ResourceDispatcherHost::InfoForRequest(request); |
85 | 85 |
86 // If this is a download, just pass the response through without doing a | 86 // If this is a download, just pass the response through without doing a |
87 // cross-site check. The renderer will see it is a download and abort the | 87 // cross-site check. The renderer will see it is a download and abort the |
88 // request. | 88 // request. |
89 // | 89 // |
90 // Similarly, HTTP 204 (No Content) responses leave us showing the previous | 90 // Similarly, HTTP 204 (No Content) responses leave us showing the previous |
91 // page. We should allow the navigation to finish without running the unload | 91 // page. We should allow the navigation to finish without running the unload |
92 // handler or swapping in the pending RenderViewHost. | 92 // handler or swapping in the pending RenderViewHost. |
93 // | 93 // |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
163 // Send OnResponseStarted to the new renderer. | 163 // Send OnResponseStarted to the new renderer. |
164 DCHECK(response_); | 164 DCHECK(response_); |
165 next_handler_->OnResponseStarted(request_id_, response_); | 165 next_handler_->OnResponseStarted(request_id_, response_); |
166 | 166 |
167 // Unpause the request to resume reading. Any further reads will be | 167 // Unpause the request to resume reading. Any further reads will be |
168 // directed toward the new renderer. | 168 // directed toward the new renderer. |
169 rdh_->PauseRequest(render_process_host_id_, request_id_, false); | 169 rdh_->PauseRequest(render_process_host_id_, request_id_, false); |
170 } | 170 } |
171 | 171 |
172 // Remove ourselves from the ExtraRequestInfo. | 172 // Remove ourselves from the ExtraRequestInfo. |
173 ResourceDispatcherHostRequestInfo* info = | 173 ResourceRequestInfoImpl* info = |
174 ResourceDispatcherHost::InfoForRequest(request); | 174 ResourceDispatcherHost::InfoForRequest(request); |
175 info->set_cross_site_handler(NULL); | 175 info->set_cross_site_handler(NULL); |
176 | 176 |
177 // If the response completed during the transition, notify the next | 177 // If the response completed during the transition, notify the next |
178 // event handler. | 178 // event handler. |
179 if (completed_during_transition_) { | 179 if (completed_during_transition_) { |
180 next_handler_->OnResponseCompleted(request_id_, completed_status_, | 180 next_handler_->OnResponseCompleted(request_id_, completed_status_, |
181 completed_security_info_); | 181 completed_security_info_); |
182 rdh_->RemovePendingRequest(render_process_host_id_, request_id_); | 182 rdh_->RemovePendingRequest(render_process_host_id_, request_id_); |
183 } | 183 } |
(...skipping 11 matching lines...) Expand all Loading... |
195 request_id_ = request_id; | 195 request_id_ = request_id; |
196 response_ = response; | 196 response_ = response; |
197 | 197 |
198 // Store this handler on the ExtraRequestInfo, so that RDH can call our | 198 // Store this handler on the ExtraRequestInfo, so that RDH can call our |
199 // ResumeResponse method when the close ACK is received. | 199 // ResumeResponse method when the close ACK is received. |
200 net::URLRequest* request = rdh_->GetURLRequest(global_id); | 200 net::URLRequest* request = rdh_->GetURLRequest(global_id); |
201 if (!request) { | 201 if (!request) { |
202 DLOG(WARNING) << "Cross site response for a request that wasn't found"; | 202 DLOG(WARNING) << "Cross site response for a request that wasn't found"; |
203 return; | 203 return; |
204 } | 204 } |
205 ResourceDispatcherHostRequestInfo* info = | 205 ResourceRequestInfoImpl* info = |
206 ResourceDispatcherHost::InfoForRequest(request); | 206 ResourceDispatcherHost::InfoForRequest(request); |
207 info->set_cross_site_handler(this); | 207 info->set_cross_site_handler(this); |
208 | 208 |
209 if (has_started_response_) { | 209 if (has_started_response_) { |
210 // Pause the request until the old renderer is finished and the new | 210 // Pause the request until the old renderer is finished and the new |
211 // renderer is ready. | 211 // renderer is ready. |
212 rdh_->PauseRequest(render_process_host_id_, request_id, true); | 212 rdh_->PauseRequest(render_process_host_id_, request_id, true); |
213 } | 213 } |
214 // If our OnResponseStarted wasn't called, then we're being called by | 214 // If our OnResponseStarted wasn't called, then we're being called by |
215 // OnResponseCompleted after a failure. We don't need to pause, because | 215 // OnResponseCompleted after a failure. We don't need to pause, because |
216 // there will be no reads. | 216 // there will be no reads. |
217 | 217 |
218 // Tell the tab responsible for this request that a cross-site response is | 218 // Tell the tab responsible for this request that a cross-site response is |
219 // starting, so that it can tell its old renderer to run its onunload | 219 // starting, so that it can tell its old renderer to run its onunload |
220 // handler now. We will wait to hear the corresponding ClosePage_ACK. | 220 // handler now. We will wait to hear the corresponding ClosePage_ACK. |
221 BrowserThread::PostTask( | 221 BrowserThread::PostTask( |
222 BrowserThread::UI, | 222 BrowserThread::UI, |
223 FROM_HERE, | 223 FROM_HERE, |
224 base::Bind( | 224 base::Bind( |
225 &OnCrossSiteResponseHelper, | 225 &OnCrossSiteResponseHelper, |
226 render_process_host_id_, | 226 render_process_host_id_, |
227 render_view_id_, | 227 render_view_id_, |
228 request_id)); | 228 request_id)); |
229 | 229 |
230 // TODO(creis): If the above call should fail, then we need to notify the IO | 230 // TODO(creis): If the above call should fail, then we need to notify the IO |
231 // thread to proceed anyway, using ResourceDispatcherHost::OnClosePageACK. | 231 // thread to proceed anyway, using ResourceDispatcherHost::OnClosePageACK. |
232 } | 232 } |
233 | 233 |
234 } // namespace content | 234 } // namespace content |
OLD | NEW |