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

Side by Side Diff: content/browser/frame_host/navigation_handle_impl.cc

Issue 2161073002: Adds RequestContextType information to the NavigationHandle. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressed clamy@'s and nasko@'s comments. Created 4 years, 5 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/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
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::GetFetchRequestContextType() const {
107 CHECK_GE(state_, WILL_SEND_REQUEST);
clamy 2016/07/22 13:51:31 DCHECK.
carlosk 2016/07/22 16:00:29 Done.
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
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 15 matching lines...) Expand all
298 return navigation_data_.get(); 305 return navigation_data_.get();
299 } 306 }
300 307
301 void NavigationHandleImpl::WillStartRequest( 308 void NavigationHandleImpl::WillStartRequest(
302 const std::string& method, 309 const std::string& method,
303 scoped_refptr<content::ResourceRequestBodyImpl> resource_request_body, 310 scoped_refptr<content::ResourceRequestBodyImpl> resource_request_body,
304 const Referrer& sanitized_referrer, 311 const Referrer& sanitized_referrer,
305 bool has_user_gesture, 312 bool has_user_gesture,
306 ui::PageTransition transition, 313 ui::PageTransition transition,
307 bool is_external_protocol, 314 bool is_external_protocol,
315 RequestContextType request_context_type,
308 const ThrottleChecksFinishedCallback& callback) { 316 const ThrottleChecksFinishedCallback& callback) {
309 // |method != "POST"| should imply absence of |resource_request_body|. 317 // |method != "POST"| should imply absence of |resource_request_body|.
310 if (method != "POST" && resource_request_body) { 318 if (method != "POST" && resource_request_body) {
311 NOTREACHED(); 319 NOTREACHED();
312 resource_request_body = nullptr; 320 resource_request_body = nullptr;
313 } 321 }
314 322
315 // Update the navigation parameters. 323 // Update the navigation parameters.
316 method_ = method; 324 method_ = method;
317 if (method_ == "POST") 325 if (method_ == "POST")
318 resource_request_body_ = resource_request_body; 326 resource_request_body_ = resource_request_body;
319 sanitized_referrer_ = sanitized_referrer; 327 sanitized_referrer_ = sanitized_referrer;
320 has_user_gesture_ = has_user_gesture; 328 has_user_gesture_ = has_user_gesture;
321 transition_ = transition; 329 transition_ = transition;
322 is_external_protocol_ = is_external_protocol; 330 is_external_protocol_ = is_external_protocol;
323 331 request_context_type_ = request_context_type;
324 state_ = WILL_SEND_REQUEST; 332 state_ = WILL_SEND_REQUEST;
325 complete_callback_ = callback; 333 complete_callback_ = callback;
326 334
327 RegisterNavigationThrottles(); 335 RegisterNavigationThrottles();
328 336
329 // Notify each throttle of the request. 337 // Notify each throttle of the request.
330 NavigationThrottle::ThrottleCheckResult result = CheckWillStartRequest(); 338 NavigationThrottle::ThrottleCheckResult result = CheckWillStartRequest();
331 339
332 // If the navigation is not deferred, run the callback. 340 // If the navigation is not deferred, run the callback.
333 if (result != NavigationThrottle::DEFER) 341 if (result != NavigationThrottle::DEFER)
(...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after
536 throttles_to_register.end()); 544 throttles_to_register.end());
537 throttles_to_register.weak_clear(); 545 throttles_to_register.weak_clear();
538 } 546 }
539 std::unique_ptr<NavigationThrottle> devtools_throttle = 547 std::unique_ptr<NavigationThrottle> devtools_throttle =
540 RenderFrameDevToolsAgentHost::CreateThrottleForNavigation(this); 548 RenderFrameDevToolsAgentHost::CreateThrottleForNavigation(this);
541 if (devtools_throttle) 549 if (devtools_throttle)
542 throttles_.push_back(devtools_throttle.release()); 550 throttles_.push_back(devtools_throttle.release());
543 } 551 }
544 552
545 } // namespace content 553 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698