| 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" |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 65 is_renderer_initiated_(is_renderer_initiated), | 65 is_renderer_initiated_(is_renderer_initiated), |
| 66 is_same_page_(false), | 66 is_same_page_(false), |
| 67 is_synchronous_(is_synchronous), | 67 is_synchronous_(is_synchronous), |
| 68 is_srcdoc_(is_srcdoc), | 68 is_srcdoc_(is_srcdoc), |
| 69 was_redirected_(false), | 69 was_redirected_(false), |
| 70 state_(INITIAL), | 70 state_(INITIAL), |
| 71 is_transferring_(false), | 71 is_transferring_(false), |
| 72 frame_tree_node_(frame_tree_node), | 72 frame_tree_node_(frame_tree_node), |
| 73 next_index_(0), | 73 next_index_(0), |
| 74 navigation_start_(navigation_start), | 74 navigation_start_(navigation_start), |
| 75 pending_nav_entry_id_(pending_nav_entry_id) { | 75 pending_nav_entry_id_(pending_nav_entry_id), |
| 76 request_context_type_(REQUEST_CONTEXT_TYPE_UNSPECIFIED) { |
| 76 DCHECK(!navigation_start.is_null()); | 77 DCHECK(!navigation_start.is_null()); |
| 77 GetDelegate()->DidStartNavigation(this); | 78 GetDelegate()->DidStartNavigation(this); |
| 78 | 79 |
| 79 if (IsInMainFrame()) { | 80 if (IsInMainFrame()) { |
| 80 TRACE_EVENT_ASYNC_BEGIN_WITH_TIMESTAMP1( | 81 TRACE_EVENT_ASYNC_BEGIN_WITH_TIMESTAMP1( |
| 81 "navigation", "Navigation StartToCommit", this, | 82 "navigation", "Navigation StartToCommit", this, |
| 82 navigation_start.ToInternalValue(), "Initial URL", url_.spec()); | 83 navigation_start.ToInternalValue(), "Initial URL", url_.spec()); |
| 83 } | 84 } |
| 84 } | 85 } |
| 85 | 86 |
| 86 NavigationHandleImpl::~NavigationHandleImpl() { | 87 NavigationHandleImpl::~NavigationHandleImpl() { |
| 87 GetDelegate()->DidFinishNavigation(this); | 88 GetDelegate()->DidFinishNavigation(this); |
| 88 | 89 |
| 89 // Cancel the navigation on the IO thread if the NavigationHandle is being | 90 // Cancel the navigation on the IO thread if the NavigationHandle is being |
| 90 // destroyed in the middle of the NavigationThrottles checks. | 91 // destroyed in the middle of the NavigationThrottles checks. |
| 91 if (!IsBrowserSideNavigationEnabled() && !complete_callback_.is_null()) | 92 if (!IsBrowserSideNavigationEnabled() && !complete_callback_.is_null()) |
| 92 RunCompleteCallback(NavigationThrottle::CANCEL_AND_IGNORE); | 93 RunCompleteCallback(NavigationThrottle::CANCEL_AND_IGNORE); |
| 93 | 94 |
| 94 if (IsInMainFrame()) { | 95 if (IsInMainFrame()) { |
| 95 TRACE_EVENT_ASYNC_END2("navigation", "Navigation StartToCommit", this, | 96 TRACE_EVENT_ASYNC_END2("navigation", "Navigation StartToCommit", this, |
| 96 "URL", url_.spec(), "Net Error Code", | 97 "URL", url_.spec(), "Net Error Code", |
| 97 net_error_code_); | 98 net_error_code_); |
| 98 } | 99 } |
| 99 } | 100 } |
| 100 | 101 |
| 101 NavigatorDelegate* NavigationHandleImpl::GetDelegate() const { | 102 NavigatorDelegate* NavigationHandleImpl::GetDelegate() const { |
| 102 return frame_tree_node_->navigator()->GetDelegate(); | 103 return frame_tree_node_->navigator()->GetDelegate(); |
| 103 } | 104 } |
| 104 | 105 |
| 106 RequestContextType NavigationHandleImpl::GetRequestContextType() const { |
| 107 DCHECK_GE(state_, WILL_SEND_REQUEST); |
| 108 return request_context_type_; |
| 109 } |
| 110 |
| 105 const GURL& NavigationHandleImpl::GetURL() { | 111 const GURL& NavigationHandleImpl::GetURL() { |
| 106 return url_; | 112 return url_; |
| 107 } | 113 } |
| 108 | 114 |
| 109 bool NavigationHandleImpl::IsInMainFrame() { | 115 bool NavigationHandleImpl::IsInMainFrame() { |
| 110 return frame_tree_node_->IsMainFrame(); | 116 return frame_tree_node_->IsMainFrame(); |
| 111 } | 117 } |
| 112 | 118 |
| 113 bool NavigationHandleImpl::IsParentMainFrame() { | 119 bool NavigationHandleImpl::IsParentMainFrame() { |
| 114 if (frame_tree_node_->parent()) | 120 if (frame_tree_node_->parent()) |
| (...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 263 if (is_post) { | 269 if (is_post) { |
| 264 method = "POST"; | 270 method = "POST"; |
| 265 | 271 |
| 266 std::string body = "test=body"; | 272 std::string body = "test=body"; |
| 267 resource_request_body = new ResourceRequestBodyImpl(); | 273 resource_request_body = new ResourceRequestBodyImpl(); |
| 268 resource_request_body->AppendBytes(body.data(), body.size()); | 274 resource_request_body->AppendBytes(body.data(), body.size()); |
| 269 } | 275 } |
| 270 | 276 |
| 271 WillStartRequest(method, resource_request_body, sanitized_referrer, | 277 WillStartRequest(method, resource_request_body, sanitized_referrer, |
| 272 has_user_gesture, transition, is_external_protocol, | 278 has_user_gesture, transition, is_external_protocol, |
| 279 REQUEST_CONTEXT_TYPE_LOCATION, |
| 273 base::Bind(&UpdateThrottleCheckResult, &result)); | 280 base::Bind(&UpdateThrottleCheckResult, &result)); |
| 274 | 281 |
| 275 // Reset the callback to ensure it will not be called later. | 282 // Reset the callback to ensure it will not be called later. |
| 276 complete_callback_.Reset(); | 283 complete_callback_.Reset(); |
| 277 return result; | 284 return result; |
| 278 } | 285 } |
| 279 | 286 |
| 280 NavigationThrottle::ThrottleCheckResult | 287 NavigationThrottle::ThrottleCheckResult |
| 281 NavigationHandleImpl::CallWillRedirectRequestForTesting( | 288 NavigationHandleImpl::CallWillRedirectRequestForTesting( |
| 282 const GURL& new_url, | 289 const GURL& new_url, |
| (...skipping 28 matching lines...) Expand all Loading... |
| 311 return navigation_data_.get(); | 318 return navigation_data_.get(); |
| 312 } | 319 } |
| 313 | 320 |
| 314 void NavigationHandleImpl::WillStartRequest( | 321 void NavigationHandleImpl::WillStartRequest( |
| 315 const std::string& method, | 322 const std::string& method, |
| 316 scoped_refptr<content::ResourceRequestBodyImpl> resource_request_body, | 323 scoped_refptr<content::ResourceRequestBodyImpl> resource_request_body, |
| 317 const Referrer& sanitized_referrer, | 324 const Referrer& sanitized_referrer, |
| 318 bool has_user_gesture, | 325 bool has_user_gesture, |
| 319 ui::PageTransition transition, | 326 ui::PageTransition transition, |
| 320 bool is_external_protocol, | 327 bool is_external_protocol, |
| 328 RequestContextType request_context_type, |
| 321 const ThrottleChecksFinishedCallback& callback) { | 329 const ThrottleChecksFinishedCallback& callback) { |
| 322 // |method != "POST"| should imply absence of |resource_request_body|. | 330 // |method != "POST"| should imply absence of |resource_request_body|. |
| 323 if (method != "POST" && resource_request_body) { | 331 if (method != "POST" && resource_request_body) { |
| 324 NOTREACHED(); | 332 NOTREACHED(); |
| 325 resource_request_body = nullptr; | 333 resource_request_body = nullptr; |
| 326 } | 334 } |
| 327 | 335 |
| 328 // Update the navigation parameters. | 336 // Update the navigation parameters. |
| 329 method_ = method; | 337 method_ = method; |
| 330 if (method_ == "POST") | 338 if (method_ == "POST") |
| 331 resource_request_body_ = resource_request_body; | 339 resource_request_body_ = resource_request_body; |
| 332 sanitized_referrer_ = sanitized_referrer; | 340 sanitized_referrer_ = sanitized_referrer; |
| 333 has_user_gesture_ = has_user_gesture; | 341 has_user_gesture_ = has_user_gesture; |
| 334 transition_ = transition; | 342 transition_ = transition; |
| 335 is_external_protocol_ = is_external_protocol; | 343 is_external_protocol_ = is_external_protocol; |
| 336 | 344 request_context_type_ = request_context_type; |
| 337 state_ = WILL_SEND_REQUEST; | 345 state_ = WILL_SEND_REQUEST; |
| 338 complete_callback_ = callback; | 346 complete_callback_ = callback; |
| 339 | 347 |
| 340 RegisterNavigationThrottles(); | 348 RegisterNavigationThrottles(); |
| 341 | 349 |
| 342 // Notify each throttle of the request. | 350 // Notify each throttle of the request. |
| 343 NavigationThrottle::ThrottleCheckResult result = CheckWillStartRequest(); | 351 NavigationThrottle::ThrottleCheckResult result = CheckWillStartRequest(); |
| 344 | 352 |
| 345 // If the navigation is not deferred, run the callback. | 353 // If the navigation is not deferred, run the callback. |
| 346 if (result != NavigationThrottle::DEFER) | 354 if (result != NavigationThrottle::DEFER) |
| (...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 549 throttles_to_register.end()); | 557 throttles_to_register.end()); |
| 550 throttles_to_register.weak_clear(); | 558 throttles_to_register.weak_clear(); |
| 551 } | 559 } |
| 552 std::unique_ptr<NavigationThrottle> devtools_throttle = | 560 std::unique_ptr<NavigationThrottle> devtools_throttle = |
| 553 RenderFrameDevToolsAgentHost::CreateThrottleForNavigation(this); | 561 RenderFrameDevToolsAgentHost::CreateThrottleForNavigation(this); |
| 554 if (devtools_throttle) | 562 if (devtools_throttle) |
| 555 throttles_.push_back(devtools_throttle.release()); | 563 throttles_.push_back(devtools_throttle.release()); |
| 556 } | 564 } |
| 557 | 565 |
| 558 } // namespace content | 566 } // namespace content |
| OLD | NEW |