| 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 <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "content/browser/devtools/render_frame_devtools_agent_host.h" | 10 #include "content/browser/devtools/render_frame_devtools_agent_host.h" |
| 11 #include "content/browser/frame_host/frame_tree_node.h" | 11 #include "content/browser/frame_host/frame_tree_node.h" |
| 12 #include "content/browser/frame_host/mixed_content_navigation_throttle.h" |
| 12 #include "content/browser/frame_host/navigator.h" | 13 #include "content/browser/frame_host/navigator.h" |
| 13 #include "content/browser/frame_host/navigator_delegate.h" | 14 #include "content/browser/frame_host/navigator_delegate.h" |
| 14 #include "content/browser/service_worker/service_worker_context_wrapper.h" | 15 #include "content/browser/service_worker/service_worker_context_wrapper.h" |
| 15 #include "content/common/frame_messages.h" | 16 #include "content/common/frame_messages.h" |
| 16 #include "content/common/resource_request_body_impl.h" | 17 #include "content/common/resource_request_body_impl.h" |
| 17 #include "content/public/browser/content_browser_client.h" | 18 #include "content/public/browser/content_browser_client.h" |
| 18 #include "content/public/common/browser_side_navigation_policy.h" | 19 #include "content/public/common/browser_side_navigation_policy.h" |
| 19 #include "content/public/common/content_client.h" | 20 #include "content/public/common/content_client.h" |
| 20 #include "net/url_request/redirect_info.h" | 21 #include "net/url_request/redirect_info.h" |
| 21 #include "url/gurl.h" | 22 #include "url/gurl.h" |
| (...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 263 if (is_post) { | 264 if (is_post) { |
| 264 method = "POST"; | 265 method = "POST"; |
| 265 | 266 |
| 266 std::string body = "test=body"; | 267 std::string body = "test=body"; |
| 267 resource_request_body = new ResourceRequestBodyImpl(); | 268 resource_request_body = new ResourceRequestBodyImpl(); |
| 268 resource_request_body->AppendBytes(body.data(), body.size()); | 269 resource_request_body->AppendBytes(body.data(), body.size()); |
| 269 } | 270 } |
| 270 | 271 |
| 271 WillStartRequest(method, resource_request_body, sanitized_referrer, | 272 WillStartRequest(method, resource_request_body, sanitized_referrer, |
| 272 has_user_gesture, transition, is_external_protocol, | 273 has_user_gesture, transition, is_external_protocol, |
| 274 REQUEST_CONTEXT_TYPE_LOCATION, |
| 273 base::Bind(&UpdateThrottleCheckResult, &result)); | 275 base::Bind(&UpdateThrottleCheckResult, &result)); |
| 274 | 276 |
| 275 // Reset the callback to ensure it will not be called later. | 277 // Reset the callback to ensure it will not be called later. |
| 276 complete_callback_.Reset(); | 278 complete_callback_.Reset(); |
| 277 return result; | 279 return result; |
| 278 } | 280 } |
| 279 | 281 |
| 280 NavigationThrottle::ThrottleCheckResult | 282 NavigationThrottle::ThrottleCheckResult |
| 281 NavigationHandleImpl::CallWillRedirectRequestForTesting( | 283 NavigationHandleImpl::CallWillRedirectRequestForTesting( |
| 282 const GURL& new_url, | 284 const GURL& new_url, |
| (...skipping 15 matching lines...) Expand all Loading... |
| 298 return navigation_data_.get(); | 300 return navigation_data_.get(); |
| 299 } | 301 } |
| 300 | 302 |
| 301 void NavigationHandleImpl::WillStartRequest( | 303 void NavigationHandleImpl::WillStartRequest( |
| 302 const std::string& method, | 304 const std::string& method, |
| 303 scoped_refptr<content::ResourceRequestBodyImpl> resource_request_body, | 305 scoped_refptr<content::ResourceRequestBodyImpl> resource_request_body, |
| 304 const Referrer& sanitized_referrer, | 306 const Referrer& sanitized_referrer, |
| 305 bool has_user_gesture, | 307 bool has_user_gesture, |
| 306 ui::PageTransition transition, | 308 ui::PageTransition transition, |
| 307 bool is_external_protocol, | 309 bool is_external_protocol, |
| 310 RequestContextType fetch_request_context_type, |
| 308 const ThrottleChecksFinishedCallback& callback) { | 311 const ThrottleChecksFinishedCallback& callback) { |
| 309 // |method != "POST"| should imply absence of |resource_request_body|. | 312 // |method != "POST"| should imply absence of |resource_request_body|. |
| 310 if (method != "POST" && resource_request_body) { | 313 if (method != "POST" && resource_request_body) { |
| 311 NOTREACHED(); | 314 NOTREACHED(); |
| 312 resource_request_body = nullptr; | 315 resource_request_body = nullptr; |
| 313 } | 316 } |
| 314 | 317 |
| 315 // Update the navigation parameters. | 318 // Update the navigation parameters. |
| 316 method_ = method; | 319 method_ = method; |
| 317 if (method_ == "POST") | 320 if (method_ == "POST") |
| 318 resource_request_body_ = resource_request_body; | 321 resource_request_body_ = resource_request_body; |
| 319 sanitized_referrer_ = sanitized_referrer; | 322 sanitized_referrer_ = sanitized_referrer; |
| 320 has_user_gesture_ = has_user_gesture; | 323 has_user_gesture_ = has_user_gesture; |
| 321 transition_ = transition; | 324 transition_ = transition; |
| 322 is_external_protocol_ = is_external_protocol; | 325 is_external_protocol_ = is_external_protocol; |
| 323 | 326 fetch_request_context_type_ = fetch_request_context_type; |
| 324 state_ = WILL_SEND_REQUEST; | 327 state_ = WILL_SEND_REQUEST; |
| 325 complete_callback_ = callback; | 328 complete_callback_ = callback; |
| 326 | 329 |
| 327 RegisterNavigationThrottles(); | 330 RegisterNavigationThrottles(); |
| 328 | 331 |
| 329 // Notify each throttle of the request. | 332 // Notify each throttle of the request. |
| 330 NavigationThrottle::ThrottleCheckResult result = CheckWillStartRequest(); | 333 NavigationThrottle::ThrottleCheckResult result = CheckWillStartRequest(); |
| 331 | 334 |
| 332 // If the navigation is not deferred, run the callback. | 335 // If the navigation is not deferred, run the callback. |
| 333 if (result != NavigationThrottle::DEFER) | 336 if (result != NavigationThrottle::DEFER) |
| (...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 522 | 525 |
| 523 // No code after running the callback, as it might have resulted in our | 526 // No code after running the callback, as it might have resulted in our |
| 524 // destruction. | 527 // destruction. |
| 525 } | 528 } |
| 526 | 529 |
| 527 void NavigationHandleImpl::RegisterNavigationThrottles() { | 530 void NavigationHandleImpl::RegisterNavigationThrottles() { |
| 528 // Register the navigation throttles. The ScopedVector returned by | 531 // Register the navigation throttles. The ScopedVector returned by |
| 529 // GetNavigationThrottles is not assigned to throttles_ directly because it | 532 // GetNavigationThrottles is not assigned to throttles_ directly because it |
| 530 // would overwrite any throttle previously added with | 533 // would overwrite any throttle previously added with |
| 531 // RegisterThrottleForTesting. | 534 // RegisterThrottleForTesting. |
| 535 throttles_.insert(throttles_.end(), new MixedContentNavigationThrottle(this)); |
| 532 ScopedVector<NavigationThrottle> throttles_to_register = | 536 ScopedVector<NavigationThrottle> throttles_to_register = |
| 533 GetContentClient()->browser()->CreateThrottlesForNavigation(this); | 537 GetContentClient()->browser()->CreateThrottlesForNavigation(this); |
| 534 if (throttles_to_register.size() > 0) { | 538 if (throttles_to_register.size() > 0) { |
| 535 throttles_.insert(throttles_.end(), throttles_to_register.begin(), | 539 throttles_.insert(throttles_.end(), throttles_to_register.begin(), |
| 536 throttles_to_register.end()); | 540 throttles_to_register.end()); |
| 537 throttles_to_register.weak_clear(); | 541 throttles_to_register.weak_clear(); |
| 538 } | 542 } |
| 539 std::unique_ptr<NavigationThrottle> devtools_throttle = | 543 std::unique_ptr<NavigationThrottle> devtools_throttle = |
| 540 RenderFrameDevToolsAgentHost::CreateThrottleForNavigation(this); | 544 RenderFrameDevToolsAgentHost::CreateThrottleForNavigation(this); |
| 541 if (devtools_throttle) | 545 if (devtools_throttle) |
| 542 throttles_.push_back(devtools_throttle.release()); | 546 throttles_.push_back(devtools_throttle.release()); |
| 543 } | 547 } |
| 544 | 548 |
| 545 } // namespace content | 549 } // namespace content |
| OLD | NEW |