Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(7)

Side by Side Diff: trunk/src/content/browser/loader/cross_site_resource_handler.cc

Issue 26472004: Revert 227318 "Clean up ResourceHandler API." (Closed) Base URL: svn://svn.chromium.org/chrome/
Patch Set: Created 7 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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/logging.h" 10 #include "base/logging.h"
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
42 42
43 delegate->GetRendererManagementDelegate()->OnCrossSiteResponse( 43 delegate->GetRendererManagementDelegate()->OnCrossSiteResponse(
44 rvh, global_request_id, is_transfer, transfer_url, referrer, frame_id); 44 rvh, global_request_id, is_transfer, transfer_url, referrer, frame_id);
45 } 45 }
46 46
47 } // namespace 47 } // namespace
48 48
49 CrossSiteResourceHandler::CrossSiteResourceHandler( 49 CrossSiteResourceHandler::CrossSiteResourceHandler(
50 scoped_ptr<ResourceHandler> next_handler, 50 scoped_ptr<ResourceHandler> next_handler,
51 net::URLRequest* request) 51 net::URLRequest* request)
52 : LayeredResourceHandler(request, next_handler.Pass()), 52 : LayeredResourceHandler(next_handler.Pass()),
53 request_(request),
53 has_started_response_(false), 54 has_started_response_(false),
54 in_cross_site_transition_(false), 55 in_cross_site_transition_(false),
55 completed_during_transition_(false), 56 completed_during_transition_(false),
56 did_defer_(false), 57 did_defer_(false),
57 completed_status_(), 58 completed_status_(),
58 response_(NULL) { 59 response_(NULL) {
59 } 60 }
60 61
61 CrossSiteResourceHandler::~CrossSiteResourceHandler() { 62 CrossSiteResourceHandler::~CrossSiteResourceHandler() {
62 // Cleanup back-pointer stored on the request info. 63 // Cleanup back-pointer stored on the request info.
63 GetRequestInfo()->set_cross_site_handler(NULL); 64 ResourceRequestInfoImpl::ForRequest(request_)->set_cross_site_handler(NULL);
64 } 65 }
65 66
66 bool CrossSiteResourceHandler::OnRequestRedirected( 67 bool CrossSiteResourceHandler::OnRequestRedirected(
67 int request_id, 68 int request_id,
68 const GURL& new_url, 69 const GURL& new_url,
69 ResourceResponse* response, 70 ResourceResponse* response,
70 bool* defer) { 71 bool* defer) {
71 // We should not have started the transition before being redirected. 72 // We should not have started the transition before being redirected.
72 DCHECK(!in_cross_site_transition_); 73 DCHECK(!in_cross_site_transition_);
73 return next_handler_->OnRequestRedirected( 74 return next_handler_->OnRequestRedirected(
74 request_id, new_url, response, defer); 75 request_id, new_url, response, defer);
75 } 76 }
76 77
77 bool CrossSiteResourceHandler::OnResponseStarted( 78 bool CrossSiteResourceHandler::OnResponseStarted(
78 int request_id, 79 int request_id,
79 ResourceResponse* response, 80 ResourceResponse* response,
80 bool* defer) { 81 bool* defer) {
81 // At this point, we know that the response is safe to send back to the 82 // At this point, we know that the response is safe to send back to the
82 // renderer: it is not a download, and it has passed the SSL and safe 83 // renderer: it is not a download, and it has passed the SSL and safe
83 // browsing checks. 84 // browsing checks.
84 // We should not have already started the transition before now. 85 // We should not have already started the transition before now.
85 DCHECK(!in_cross_site_transition_); 86 DCHECK(!in_cross_site_transition_);
86 has_started_response_ = true; 87 has_started_response_ = true;
87 88
88 ResourceRequestInfoImpl* info = GetRequestInfo(); 89 ResourceRequestInfoImpl* info = ResourceRequestInfoImpl::ForRequest(request_);
89 90
90 // We will need to swap processes if either (1) a redirect that requires a 91 // We will need to swap processes if either (1) a redirect that requires a
91 // transfer occurred before we got here, or (2) a pending cross-site request 92 // transfer occurred before we got here, or (2) a pending cross-site request
92 // was already in progress. Note that a swap may no longer be needed if we 93 // was already in progress. Note that a swap may no longer be needed if we
93 // transferred back into the original process due to a redirect. 94 // transferred back into the original process due to a redirect.
94 bool should_transfer = 95 bool should_transfer =
95 GetContentClient()->browser()->ShouldSwapProcessesForRedirect( 96 GetContentClient()->browser()->ShouldSwapProcessesForRedirect(
96 info->GetContext(), request()->original_url(), request()->url()); 97 info->GetContext(), request_->original_url(), request_->url());
97 bool swap_needed = should_transfer || 98 bool swap_needed = should_transfer ||
98 CrossSiteRequestManager::GetInstance()-> 99 CrossSiteRequestManager::GetInstance()->
99 HasPendingCrossSiteRequest(info->GetChildID(), info->GetRouteID()); 100 HasPendingCrossSiteRequest(info->GetChildID(), info->GetRouteID());
100 101
101 // If this is a download, just pass the response through without doing a 102 // If this is a download, just pass the response through without doing a
102 // cross-site check. The renderer will see it is a download and abort the 103 // cross-site check. The renderer will see it is a download and abort the
103 // request. 104 // request.
104 // 105 //
105 // Similarly, HTTP 204 (No Content) responses leave us showing the previous 106 // Similarly, HTTP 204 (No Content) responses leave us showing the previous
106 // page. We should allow the navigation to finish without running the unload 107 // page. We should allow the navigation to finish without running the unload
(...skipping 24 matching lines...) Expand all
131 bool* defer) { 132 bool* defer) {
132 CHECK(!in_cross_site_transition_); 133 CHECK(!in_cross_site_transition_);
133 return next_handler_->OnReadCompleted(request_id, bytes_read, defer); 134 return next_handler_->OnReadCompleted(request_id, bytes_read, defer);
134 } 135 }
135 136
136 bool CrossSiteResourceHandler::OnResponseCompleted( 137 bool CrossSiteResourceHandler::OnResponseCompleted(
137 int request_id, 138 int request_id,
138 const net::URLRequestStatus& status, 139 const net::URLRequestStatus& status,
139 const std::string& security_info) { 140 const std::string& security_info) {
140 if (!in_cross_site_transition_) { 141 if (!in_cross_site_transition_) {
141 ResourceRequestInfoImpl* info = GetRequestInfo(); 142 ResourceRequestInfoImpl* info =
143 ResourceRequestInfoImpl::ForRequest(request_);
142 // If we've already completed the transition, or we're canceling the 144 // If we've already completed the transition, or we're canceling the
143 // request, or an error occurred with no cross-process navigation in 145 // request, or an error occurred with no cross-process navigation in
144 // progress, then we should just pass this through. 146 // progress, then we should just pass this through.
145 if (has_started_response_ || 147 if (has_started_response_ ||
146 status.status() != net::URLRequestStatus::FAILED || 148 status.status() != net::URLRequestStatus::FAILED ||
147 !CrossSiteRequestManager::GetInstance()->HasPendingCrossSiteRequest( 149 !CrossSiteRequestManager::GetInstance()->HasPendingCrossSiteRequest(
148 info->GetChildID(), info->GetRouteID())) { 150 info->GetChildID(), info->GetRouteID())) {
149 return next_handler_->OnResponseCompleted(request_id, status, 151 return next_handler_->OnResponseCompleted(request_id, status,
150 security_info); 152 security_info);
151 } 153 }
(...skipping 12 matching lines...) Expand all
164 166
165 // Return false to tell RDH not to notify the world or clean up the 167 // Return false to tell RDH not to notify the world or clean up the
166 // pending request. We will do so in ResumeResponse. 168 // pending request. We will do so in ResumeResponse.
167 did_defer_ = true; 169 did_defer_ = true;
168 return false; 170 return false;
169 } 171 }
170 172
171 // We can now send the response to the new renderer, which will cause 173 // We can now send the response to the new renderer, which will cause
172 // WebContentsImpl to swap in the new renderer and destroy the old one. 174 // WebContentsImpl to swap in the new renderer and destroy the old one.
173 void CrossSiteResourceHandler::ResumeResponse() { 175 void CrossSiteResourceHandler::ResumeResponse() {
174 DCHECK(request()); 176 DCHECK(request_);
175 DCHECK(in_cross_site_transition_); 177 DCHECK(in_cross_site_transition_);
176 in_cross_site_transition_ = false; 178 in_cross_site_transition_ = false;
177 ResourceRequestInfoImpl* info = GetRequestInfo(); 179 ResourceRequestInfoImpl* info =
180 ResourceRequestInfoImpl::ForRequest(request_);
178 181
179 if (has_started_response_) { 182 if (has_started_response_) {
180 // Send OnResponseStarted to the new renderer. 183 // Send OnResponseStarted to the new renderer.
181 DCHECK(response_); 184 DCHECK(response_);
182 bool defer = false; 185 bool defer = false;
183 if (!next_handler_->OnResponseStarted(info->GetRequestID(), response_, 186 if (!next_handler_->OnResponseStarted(info->GetRequestID(), response_,
184 &defer)) { 187 &defer)) {
185 controller()->Cancel(); 188 controller()->Cancel();
186 } else if (!defer) { 189 } else if (!defer) {
187 // Unpause the request to resume reading. Any further reads will be 190 // Unpause the request to resume reading. Any further reads will be
(...skipping 20 matching lines...) Expand all
208 // telling the old RenderViewHost to run its onunload handler. 211 // telling the old RenderViewHost to run its onunload handler.
209 void CrossSiteResourceHandler::StartCrossSiteTransition( 212 void CrossSiteResourceHandler::StartCrossSiteTransition(
210 int request_id, 213 int request_id,
211 ResourceResponse* response, 214 ResourceResponse* response,
212 bool should_transfer) { 215 bool should_transfer) {
213 in_cross_site_transition_ = true; 216 in_cross_site_transition_ = true;
214 response_ = response; 217 response_ = response;
215 218
216 // Store this handler on the ExtraRequestInfo, so that RDH can call our 219 // Store this handler on the ExtraRequestInfo, so that RDH can call our
217 // ResumeResponse method when we are ready to resume. 220 // ResumeResponse method when we are ready to resume.
218 ResourceRequestInfoImpl* info = GetRequestInfo(); 221 ResourceRequestInfoImpl* info =
222 ResourceRequestInfoImpl::ForRequest(request_);
219 info->set_cross_site_handler(this); 223 info->set_cross_site_handler(this);
220 224
221 DCHECK_EQ(request_id, info->GetRequestID()); 225 DCHECK_EQ(request_id, info->GetRequestID());
222 GlobalRequestID global_id(info->GetChildID(), info->GetRequestID()); 226 GlobalRequestID global_id(info->GetChildID(), info->GetRequestID());
223 227
224 // Tell the contents responsible for this request that a cross-site response 228 // Tell the contents responsible for this request that a cross-site response
225 // is starting, so that it can tell its old renderer to run its onunload 229 // is starting, so that it can tell its old renderer to run its onunload
226 // handler now. We will wait until the unload is finished and (if a transfer 230 // handler now. We will wait until the unload is finished and (if a transfer
227 // is needed) for the new renderer's request to arrive. 231 // is needed) for the new renderer's request to arrive.
228 GURL transfer_url; 232 GURL transfer_url;
229 Referrer referrer; 233 Referrer referrer;
230 int frame_id = -1; 234 int frame_id = -1;
231 if (should_transfer) { 235 if (should_transfer) {
232 transfer_url = request()->url(); 236 transfer_url = request_->url();
233 referrer = Referrer(GURL(request()->referrer()), info->GetReferrerPolicy()); 237 referrer = Referrer(GURL(request_->referrer()), info->GetReferrerPolicy());
234 frame_id = info->GetFrameID(); 238 frame_id = info->GetFrameID();
235 239
236 ResourceDispatcherHostImpl::Get()->MarkAsTransferredNavigation( 240 ResourceDispatcherHostImpl::Get()->MarkAsTransferredNavigation(
237 global_id, transfer_url); 241 global_id, transfer_url);
238 } 242 }
239 BrowserThread::PostTask( 243 BrowserThread::PostTask(
240 BrowserThread::UI, 244 BrowserThread::UI,
241 FROM_HERE, 245 FROM_HERE,
242 base::Bind( 246 base::Bind(
243 &OnCrossSiteResponseHelper, 247 &OnCrossSiteResponseHelper,
244 info->GetChildID(), 248 info->GetChildID(),
245 info->GetRouteID(), 249 info->GetRouteID(),
246 global_id, 250 global_id,
247 should_transfer, 251 should_transfer,
248 transfer_url, 252 transfer_url,
249 referrer, 253 referrer,
250 frame_id)); 254 frame_id));
251 } 255 }
252 256
253 void CrossSiteResourceHandler::ResumeIfDeferred() { 257 void CrossSiteResourceHandler::ResumeIfDeferred() {
254 if (did_defer_) { 258 if (did_defer_) {
255 did_defer_ = false; 259 did_defer_ = false;
256 controller()->Resume(); 260 controller()->Resume();
257 } 261 }
258 } 262 }
259 263
260 } // namespace content 264 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698