OLD | NEW |
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/frame_host/navigation_handle_impl.h" | 5 #include "content/browser/frame_host/navigation_handle_impl.h" |
6 | 6 |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "content/browser/frame_host/frame_tree_node.h" | 8 #include "content/browser/frame_host/frame_tree_node.h" |
9 #include "content/browser/frame_host/navigator.h" | 9 #include "content/browser/frame_host/navigator.h" |
10 #include "content/browser/frame_host/navigator_delegate.h" | 10 #include "content/browser/frame_host/navigator_delegate.h" |
11 #include "content/browser/service_worker/service_worker_context_wrapper.h" | 11 #include "content/browser/service_worker/service_worker_context_wrapper.h" |
12 #include "content/browser/service_worker/service_worker_navigation_handle.h" | 12 #include "content/browser/service_worker/service_worker_navigation_handle.h" |
13 #include "content/public/browser/browser_context.h" | 13 #include "content/public/browser/browser_context.h" |
14 #include "content/public/browser/content_browser_client.h" | 14 #include "content/public/browser/content_browser_client.h" |
15 #include "content/public/browser/storage_partition.h" | 15 #include "content/public/browser/storage_partition.h" |
16 #include "content/public/common/content_client.h" | 16 #include "content/public/common/content_client.h" |
17 #include "content/public/common/content_switches.h" | 17 #include "content/public/common/content_switches.h" |
18 #include "net/url_request/redirect_info.h" | 18 #include "net/url_request/redirect_info.h" |
19 #include "third_party/WebKit/public/web/WebSandboxFlags.h" | 19 #include "third_party/WebKit/public/web/WebSandboxFlags.h" |
20 | 20 |
21 namespace content { | 21 namespace content { |
22 | 22 |
23 namespace { | 23 namespace { |
24 | 24 |
25 void UpdateThrottleCheckResult( | 25 void UpdateThrottleCheckResult( |
26 NavigationThrottle::ThrottleCheckResult* to_update, | 26 NavigationThrottle::ThrottleCheckResult* to_update, |
27 NavigationThrottle::ThrottleCheckResult result) { | 27 NavigationThrottle::ThrottleCheckResult result, |
| 28 const NavigationHandleImpl::ExtraHeadersList& headers) { |
28 *to_update = result; | 29 *to_update = result; |
29 } | 30 } |
30 | 31 |
31 } // namespace | 32 } // namespace |
32 | 33 |
33 // static | 34 // static |
34 scoped_ptr<NavigationHandleImpl> NavigationHandleImpl::Create( | 35 scoped_ptr<NavigationHandleImpl> NavigationHandleImpl::Create( |
35 const GURL& url, | 36 const GURL& url, |
36 FrameTreeNode* frame_tree_node) { | 37 FrameTreeNode* frame_tree_node) { |
37 return scoped_ptr<NavigationHandleImpl>( | 38 return scoped_ptr<NavigationHandleImpl>( |
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
211 NavigationThrottle::ThrottleCheckResult result = NavigationThrottle::DEFER; | 212 NavigationThrottle::ThrottleCheckResult result = NavigationThrottle::DEFER; |
212 WillRedirectRequest(new_url, new_method_is_post, new_referrer_url, | 213 WillRedirectRequest(new_url, new_method_is_post, new_referrer_url, |
213 new_is_external_protocol, | 214 new_is_external_protocol, |
214 base::Bind(&UpdateThrottleCheckResult, &result)); | 215 base::Bind(&UpdateThrottleCheckResult, &result)); |
215 | 216 |
216 // Reset the callback to ensure it will not be called later. | 217 // Reset the callback to ensure it will not be called later. |
217 complete_callback_.Reset(); | 218 complete_callback_.Reset(); |
218 return result; | 219 return result; |
219 } | 220 } |
220 | 221 |
| 222 void NavigationHandleImpl::AddExtraHeader(const std::string& name, |
| 223 const std::string& value) { |
| 224 // Only set headers during throttle checks, when the handler of the request |
| 225 // will be able to add them to the network request. |
| 226 DCHECK(!complete_callback_.is_null()); |
| 227 extra_headers_to_add_.push_back( |
| 228 std::pair<std::string, std::string>(name, value)); |
| 229 } |
| 230 |
221 void NavigationHandleImpl::WillStartRequest( | 231 void NavigationHandleImpl::WillStartRequest( |
222 bool is_post, | 232 bool is_post, |
223 const Referrer& sanitized_referrer, | 233 const Referrer& sanitized_referrer, |
224 bool has_user_gesture, | 234 bool has_user_gesture, |
225 ui::PageTransition transition, | 235 ui::PageTransition transition, |
226 bool is_external_protocol, | 236 bool is_external_protocol, |
227 const ThrottleChecksFinishedCallback& callback) { | 237 const ThrottleChecksFinishedCallback& callback) { |
228 // Update the navigation parameters. | 238 // Update the navigation parameters. |
229 is_post_ = is_post; | 239 is_post_ = is_post; |
230 sanitized_referrer_ = sanitized_referrer; | 240 sanitized_referrer_ = sanitized_referrer; |
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
360 } | 370 } |
361 next_index_ = 0; | 371 next_index_ = 0; |
362 state_ = WILL_REDIRECT_REQUEST; | 372 state_ = WILL_REDIRECT_REQUEST; |
363 return NavigationThrottle::PROCEED; | 373 return NavigationThrottle::PROCEED; |
364 } | 374 } |
365 | 375 |
366 void NavigationHandleImpl::RunCompleteCallback( | 376 void NavigationHandleImpl::RunCompleteCallback( |
367 NavigationThrottle::ThrottleCheckResult result) { | 377 NavigationThrottle::ThrottleCheckResult result) { |
368 DCHECK(result != NavigationThrottle::DEFER); | 378 DCHECK(result != NavigationThrottle::DEFER); |
369 if (!complete_callback_.is_null()) | 379 if (!complete_callback_.is_null()) |
370 complete_callback_.Run(result); | 380 complete_callback_.Run(result, extra_headers_to_add_); |
371 | 381 |
372 complete_callback_.Reset(); | 382 complete_callback_.Reset(); |
| 383 extra_headers_to_add_.clear(); |
373 } | 384 } |
374 | 385 |
375 } // namespace content | 386 } // namespace content |
OLD | NEW |