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

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

Issue 1416953007: Add a function to add extra headers from NavigationThrottle (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@data-reduction-proxy-resource-throttle
Patch Set: Fixed compilation issue Created 5 years, 1 month 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/callback.h" 7 #include "base/callback.h"
8 #include "content/browser/frame_host/navigation_handle_impl.h" 8 #include "content/browser/frame_host/navigation_handle_impl.h"
9 #include "content/browser/frame_host/render_frame_host_impl.h" 9 #include "content/browser/frame_host/render_frame_host_impl.h"
10 #include "content/public/browser/resource_context.h" 10 #include "content/public/browser/resource_context.h"
11 #include "content/public/browser/resource_controller.h" 11 #include "content/public/browser/resource_controller.h"
12 #include "content/public/browser/resource_request_info.h" 12 #include "content/public/browser/resource_request_info.h"
13 #include "content/public/common/referrer.h" 13 #include "content/public/common/referrer.h"
14 #include "net/url_request/redirect_info.h" 14 #include "net/url_request/redirect_info.h"
15 #include "net/url_request/url_request.h" 15 #include "net/url_request/url_request.h"
16 #include "net/url_request/url_request_context.h" 16 #include "net/url_request/url_request_context.h"
17 #include "net/url_request/url_request_job_factory.h" 17 #include "net/url_request/url_request_job_factory.h"
18 #include "ui/base/page_transition_types.h" 18 #include "ui/base/page_transition_types.h"
19 19
20 namespace content { 20 namespace content {
21 21
22 namespace { 22 namespace {
23 typedef base::Callback<void(NavigationThrottle::ThrottleCheckResult)> 23 typedef base::Callback<void(
24 NavigationThrottle::ThrottleCheckResult,
25 const std::vector<std::pair<std::string, std::string>>&)>
24 UIChecksPerformedCallback; 26 UIChecksPerformedCallback;
25 27
26 void SendCheckResultToIOThread(UIChecksPerformedCallback callback, 28 void SendCheckResultToIOThread(
27 NavigationThrottle::ThrottleCheckResult result) { 29 UIChecksPerformedCallback callback,
30 NavigationThrottle::ThrottleCheckResult result,
31 const NavigationHandleImpl::ExtraHeadersList& extra_headers) {
28 DCHECK_CURRENTLY_ON(BrowserThread::UI); 32 DCHECK_CURRENTLY_ON(BrowserThread::UI);
29 CHECK(result != NavigationThrottle::DEFER); 33 CHECK(result != NavigationThrottle::DEFER);
30 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, 34 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE,
31 base::Bind(callback, result)); 35 base::Bind(callback, result, extra_headers));
32 } 36 }
33 37
34 void CheckWillStartRequestOnUIThread(UIChecksPerformedCallback callback, 38 void CheckWillStartRequestOnUIThread(UIChecksPerformedCallback callback,
35 int render_process_id, 39 int render_process_id,
36 int render_frame_host_id, 40 int render_frame_host_id,
37 bool is_post, 41 bool is_post,
38 const Referrer& sanitized_referrer, 42 const Referrer& sanitized_referrer,
39 bool has_user_gesture, 43 bool has_user_gesture,
40 ui::PageTransition transition, 44 ui::PageTransition transition,
41 bool is_external_protocol) { 45 bool is_external_protocol) {
42 DCHECK_CURRENTLY_ON(BrowserThread::UI); 46 DCHECK_CURRENTLY_ON(BrowserThread::UI);
43 RenderFrameHostImpl* render_frame_host = 47 RenderFrameHostImpl* render_frame_host =
44 RenderFrameHostImpl::FromID(render_process_id, render_frame_host_id); 48 RenderFrameHostImpl::FromID(render_process_id, render_frame_host_id);
45 if (!render_frame_host) { 49 if (!render_frame_host) {
46 SendCheckResultToIOThread(callback, NavigationThrottle::PROCEED); 50 SendCheckResultToIOThread(callback, NavigationThrottle::PROCEED,
51 NavigationHandleImpl::ExtraHeadersList());
47 return; 52 return;
48 } 53 }
49 54
50 NavigationHandleImpl* navigation_handle = 55 NavigationHandleImpl* navigation_handle =
51 render_frame_host->navigation_handle(); 56 render_frame_host->navigation_handle();
52 if (!navigation_handle) { 57 if (!navigation_handle) {
53 SendCheckResultToIOThread(callback, NavigationThrottle::PROCEED); 58 SendCheckResultToIOThread(callback, NavigationThrottle::PROCEED,
59 NavigationHandleImpl::ExtraHeadersList());
54 return; 60 return;
55 } 61 }
56 62
57 navigation_handle->WillStartRequest( 63 navigation_handle->WillStartRequest(
58 is_post, sanitized_referrer, has_user_gesture, transition, 64 is_post, sanitized_referrer, has_user_gesture, transition,
59 is_external_protocol, base::Bind(&SendCheckResultToIOThread, callback)); 65 is_external_protocol, base::Bind(&SendCheckResultToIOThread, callback));
60 } 66 }
61 67
62 void CheckWillRedirectRequestOnUIThread(UIChecksPerformedCallback callback, 68 void CheckWillRedirectRequestOnUIThread(UIChecksPerformedCallback callback,
63 int render_process_id, 69 int render_process_id,
64 int render_frame_host_id, 70 int render_frame_host_id,
65 const GURL& new_url, 71 const GURL& new_url,
66 bool new_method_is_post, 72 bool new_method_is_post,
67 const GURL& new_referrer_url, 73 const GURL& new_referrer_url,
68 bool new_is_external_protocol) { 74 bool new_is_external_protocol) {
69 DCHECK_CURRENTLY_ON(BrowserThread::UI); 75 DCHECK_CURRENTLY_ON(BrowserThread::UI);
70 RenderFrameHostImpl* render_frame_host = 76 RenderFrameHostImpl* render_frame_host =
71 RenderFrameHostImpl::FromID(render_process_id, render_frame_host_id); 77 RenderFrameHostImpl::FromID(render_process_id, render_frame_host_id);
72 if (!render_frame_host) { 78 if (!render_frame_host) {
73 SendCheckResultToIOThread(callback, NavigationThrottle::PROCEED); 79 SendCheckResultToIOThread(callback, NavigationThrottle::PROCEED,
80 NavigationHandleImpl::ExtraHeadersList());
74 return; 81 return;
75 } 82 }
76 83
77 NavigationHandleImpl* navigation_handle = 84 NavigationHandleImpl* navigation_handle =
78 render_frame_host->navigation_handle(); 85 render_frame_host->navigation_handle();
79 if (!navigation_handle) { 86 if (!navigation_handle) {
80 SendCheckResultToIOThread(callback, NavigationThrottle::PROCEED); 87 SendCheckResultToIOThread(callback, NavigationThrottle::PROCEED,
88 NavigationHandleImpl::ExtraHeadersList());
81 return; 89 return;
82 } 90 }
83 91
84 GURL new_validated_url(new_url); 92 GURL new_validated_url(new_url);
85 RenderProcessHost::FromID(render_process_id) 93 RenderProcessHost::FromID(render_process_id)
86 ->FilterURL(false, &new_validated_url); 94 ->FilterURL(false, &new_validated_url);
87 navigation_handle->WillRedirectRequest( 95 navigation_handle->WillRedirectRequest(
88 new_validated_url, new_method_is_post, new_referrer_url, 96 new_validated_url, new_method_is_post, new_referrer_url,
89 new_is_external_protocol, 97 new_is_external_protocol,
90 base::Bind(&SendCheckResultToIOThread, callback)); 98 base::Bind(&SendCheckResultToIOThread, callback));
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
151 redirect_info.new_method == "POST", 159 redirect_info.new_method == "POST",
152 GURL(redirect_info.new_referrer), new_is_external_protocol)); 160 GURL(redirect_info.new_referrer), new_is_external_protocol));
153 *defer = true; 161 *defer = true;
154 } 162 }
155 163
156 const char* NavigationResourceThrottle::GetNameForLogging() const { 164 const char* NavigationResourceThrottle::GetNameForLogging() const {
157 return "NavigationResourceThrottle"; 165 return "NavigationResourceThrottle";
158 } 166 }
159 167
160 void NavigationResourceThrottle::OnUIChecksPerformed( 168 void NavigationResourceThrottle::OnUIChecksPerformed(
161 NavigationThrottle::ThrottleCheckResult result) { 169 NavigationThrottle::ThrottleCheckResult result,
170 const std::vector<std::pair<std::string, std::string>>& extra_headers) {
162 DCHECK_CURRENTLY_ON(BrowserThread::IO); 171 DCHECK_CURRENTLY_ON(BrowserThread::IO);
163 if (result == NavigationThrottle::CANCEL_AND_IGNORE) { 172 if (result == NavigationThrottle::CANCEL_AND_IGNORE) {
164 controller()->CancelAndIgnore(); 173 controller()->CancelAndIgnore();
165 } else if (result == NavigationThrottle::CANCEL) { 174 } else if (result == NavigationThrottle::CANCEL) {
166 controller()->Cancel(); 175 controller()->Cancel();
167 } else { 176 } else {
177 DCHECK(result == NavigationThrottle::PROCEED);
178 for (auto header : extra_headers) {
179 request_->SetExtraRequestHeaderByName(header.first, header.second, true);
180 }
168 controller()->Resume(); 181 controller()->Resume();
169 } 182 }
170 } 183 }
171 184
172 } // namespace content 185 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698