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

Side by Side Diff: content/browser/loader/navigation_resource_throttle.cc

Issue 1956383003: Forwarding POST body into renderer after a cross-site transfer. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 7 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
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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/navigation_resource_throttle.h" 5 #include "content/browser/loader/navigation_resource_throttle.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/callback.h" 8 #include "base/callback.h"
9 #include "base/location.h" 9 #include "base/location.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
11 #include "base/memory/ref_counted.h"
11 #include "content/browser/frame_host/navigation_handle_impl.h" 12 #include "content/browser/frame_host/navigation_handle_impl.h"
12 #include "content/browser/frame_host/render_frame_host_impl.h" 13 #include "content/browser/frame_host/render_frame_host_impl.h"
14 #include "content/browser/loader/resource_request_info_impl.h"
15 #include "content/common/resource_request_body.h"
13 #include "content/public/browser/browser_thread.h" 16 #include "content/public/browser/browser_thread.h"
14 #include "content/public/browser/resource_context.h" 17 #include "content/public/browser/resource_context.h"
15 #include "content/public/browser/resource_controller.h" 18 #include "content/public/browser/resource_controller.h"
16 #include "content/public/browser/resource_request_info.h" 19 #include "content/public/browser/resource_request_info.h"
17 #include "content/public/common/referrer.h" 20 #include "content/public/common/referrer.h"
18 #include "net/url_request/redirect_info.h" 21 #include "net/url_request/redirect_info.h"
19 #include "net/url_request/url_request.h" 22 #include "net/url_request/url_request.h"
20 #include "net/url_request/url_request_context.h" 23 #include "net/url_request/url_request_context.h"
21 #include "net/url_request/url_request_job_factory.h" 24 #include "net/url_request/url_request_job_factory.h"
22 #include "ui/base/page_transition_types.h" 25 #include "ui/base/page_transition_types.h"
23 26
24 namespace content { 27 namespace content {
25 28
26 namespace { 29 namespace {
27 typedef base::Callback<void(NavigationThrottle::ThrottleCheckResult)> 30 typedef base::Callback<void(NavigationThrottle::ThrottleCheckResult)>
28 UIChecksPerformedCallback; 31 UIChecksPerformedCallback;
29 32
30 void SendCheckResultToIOThread(UIChecksPerformedCallback callback, 33 void SendCheckResultToIOThread(UIChecksPerformedCallback callback,
31 NavigationThrottle::ThrottleCheckResult result) { 34 NavigationThrottle::ThrottleCheckResult result) {
32 DCHECK_CURRENTLY_ON(BrowserThread::UI); 35 DCHECK_CURRENTLY_ON(BrowserThread::UI);
33 DCHECK_NE(result, NavigationThrottle::DEFER); 36 DCHECK_NE(result, NavigationThrottle::DEFER);
34 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, 37 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE,
35 base::Bind(callback, result)); 38 base::Bind(callback, result));
36 } 39 }
37 40
38 void CheckWillStartRequestOnUIThread(UIChecksPerformedCallback callback, 41 void CheckWillStartRequestOnUIThread(
39 int render_process_id, 42 UIChecksPerformedCallback callback,
40 int render_frame_host_id, 43 int render_process_id,
41 const std::string& method, 44 int render_frame_host_id,
42 const Referrer& sanitized_referrer, 45 const std::string& method,
43 bool has_user_gesture, 46 const scoped_refptr<content::ResourceRequestBody>& resource_request_body,
44 ui::PageTransition transition, 47 const Referrer& sanitized_referrer,
45 bool is_external_protocol) { 48 bool has_user_gesture,
49 ui::PageTransition transition,
50 bool is_external_protocol) {
46 DCHECK_CURRENTLY_ON(BrowserThread::UI); 51 DCHECK_CURRENTLY_ON(BrowserThread::UI);
47 RenderFrameHostImpl* render_frame_host = 52 RenderFrameHostImpl* render_frame_host =
48 RenderFrameHostImpl::FromID(render_process_id, render_frame_host_id); 53 RenderFrameHostImpl::FromID(render_process_id, render_frame_host_id);
49 if (!render_frame_host) { 54 if (!render_frame_host) {
50 SendCheckResultToIOThread(callback, NavigationThrottle::PROCEED); 55 SendCheckResultToIOThread(callback, NavigationThrottle::PROCEED);
51 return; 56 return;
52 } 57 }
53 58
54 NavigationHandleImpl* navigation_handle = 59 NavigationHandleImpl* navigation_handle =
55 render_frame_host->navigation_handle(); 60 render_frame_host->navigation_handle();
56 if (!navigation_handle) { 61 if (!navigation_handle) {
57 SendCheckResultToIOThread(callback, NavigationThrottle::PROCEED); 62 SendCheckResultToIOThread(callback, NavigationThrottle::PROCEED);
58 return; 63 return;
59 } 64 }
60 65
61 navigation_handle->WillStartRequest( 66 navigation_handle->WillStartRequest(
62 method, sanitized_referrer, has_user_gesture, transition, 67 method, resource_request_body, sanitized_referrer, has_user_gesture,
63 is_external_protocol, base::Bind(&SendCheckResultToIOThread, callback)); 68 transition, is_external_protocol,
69 base::Bind(&SendCheckResultToIOThread, callback));
64 } 70 }
65 71
66 void CheckWillRedirectRequestOnUIThread( 72 void CheckWillRedirectRequestOnUIThread(
67 UIChecksPerformedCallback callback, 73 UIChecksPerformedCallback callback,
68 int render_process_id, 74 int render_process_id,
69 int render_frame_host_id, 75 int render_frame_host_id,
70 const GURL& new_url, 76 const GURL& new_url,
71 const std::string& new_method, 77 const std::string& new_method,
72 const GURL& new_referrer_url, 78 const GURL& new_referrer_url,
73 bool new_is_external_protocol, 79 bool new_is_external_protocol,
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
122 128
123 } // namespace 129 } // namespace
124 130
125 NavigationResourceThrottle::NavigationResourceThrottle(net::URLRequest* request) 131 NavigationResourceThrottle::NavigationResourceThrottle(net::URLRequest* request)
126 : request_(request), weak_ptr_factory_(this) {} 132 : request_(request), weak_ptr_factory_(this) {}
127 133
128 NavigationResourceThrottle::~NavigationResourceThrottle() {} 134 NavigationResourceThrottle::~NavigationResourceThrottle() {}
129 135
130 void NavigationResourceThrottle::WillStartRequest(bool* defer) { 136 void NavigationResourceThrottle::WillStartRequest(bool* defer) {
131 DCHECK_CURRENTLY_ON(BrowserThread::IO); 137 DCHECK_CURRENTLY_ON(BrowserThread::IO);
132 const ResourceRequestInfo* info = ResourceRequestInfo::ForRequest(request_); 138 const ResourceRequestInfoImpl* info =
139 ResourceRequestInfoImpl::ForRequest(request_);
133 if (!info) 140 if (!info)
134 return; 141 return;
135 142
136 int render_process_id, render_frame_id; 143 int render_process_id, render_frame_id;
137 if (!info->GetAssociatedRenderFrame(&render_process_id, &render_frame_id)) 144 if (!info->GetAssociatedRenderFrame(&render_process_id, &render_frame_id))
138 return; 145 return;
139 146
140 bool is_external_protocol = 147 bool is_external_protocol =
141 !info->GetContext()->GetRequestContext()->job_factory()->IsHandledURL( 148 !info->GetContext()->GetRequestContext()->job_factory()->IsHandledURL(
142 request_->url()); 149 request_->url());
143 UIChecksPerformedCallback callback = 150 UIChecksPerformedCallback callback =
144 base::Bind(&NavigationResourceThrottle::OnUIChecksPerformed, 151 base::Bind(&NavigationResourceThrottle::OnUIChecksPerformed,
145 weak_ptr_factory_.GetWeakPtr()); 152 weak_ptr_factory_.GetWeakPtr());
146 DCHECK(request_->method() == "POST" || request_->method() == "GET"); 153 DCHECK(request_->method() == "POST" || request_->method() == "GET");
147 BrowserThread::PostTask( 154 BrowserThread::PostTask(
148 BrowserThread::UI, FROM_HERE, 155 BrowserThread::UI, FROM_HERE,
149 base::Bind(&CheckWillStartRequestOnUIThread, callback, render_process_id, 156 base::Bind(&CheckWillStartRequestOnUIThread, callback, render_process_id,
150 render_frame_id, request_->method(), 157 render_frame_id, request_->method(), info->body(),
151 Referrer::SanitizeForRequest( 158 Referrer::SanitizeForRequest(
152 request_->url(), Referrer(GURL(request_->referrer()), 159 request_->url(), Referrer(GURL(request_->referrer()),
153 info->GetReferrerPolicy())), 160 info->GetReferrerPolicy())),
154 info->HasUserGesture(), info->GetPageTransition(), 161 info->HasUserGesture(), info->GetPageTransition(),
155 is_external_protocol)); 162 is_external_protocol));
156 *defer = true; 163 *defer = true;
157 } 164 }
158 165
159 void NavigationResourceThrottle::WillRedirectRequest( 166 void NavigationResourceThrottle::WillRedirectRequest(
160 const net::RedirectInfo& redirect_info, 167 const net::RedirectInfo& redirect_info,
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
244 // block main frame navigations in the future, we'll need to carefully 251 // block main frame navigations in the future, we'll need to carefully
245 // consider the right thing to do here. 252 // consider the right thing to do here.
246 DCHECK(!ResourceRequestInfo::ForRequest(request_)->IsMainFrame()); 253 DCHECK(!ResourceRequestInfo::ForRequest(request_)->IsMainFrame());
247 controller()->CancelWithError(net::ERR_BLOCKED_BY_RESPONSE); 254 controller()->CancelWithError(net::ERR_BLOCKED_BY_RESPONSE);
248 } else { 255 } else {
249 controller()->Resume(); 256 controller()->Resume();
250 } 257 }
251 } 258 }
252 259
253 } // namespace content 260 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698