| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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_request.h" | 5 #include "content/browser/frame_host/navigation_request.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "content/browser/frame_host/frame_tree.h" | 9 #include "content/browser/frame_host/frame_tree.h" |
| 10 #include "content/browser/frame_host/frame_tree_node.h" | 10 #include "content/browser/frame_host/frame_tree_node.h" |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 64 FrameTreeNode* frame_tree_node, | 64 FrameTreeNode* frame_tree_node, |
| 65 const GURL& dest_url, | 65 const GURL& dest_url, |
| 66 const Referrer& dest_referrer, | 66 const Referrer& dest_referrer, |
| 67 const FrameNavigationEntry& frame_entry, | 67 const FrameNavigationEntry& frame_entry, |
| 68 const NavigationEntryImpl& entry, | 68 const NavigationEntryImpl& entry, |
| 69 FrameMsg_Navigate_Type::Value navigation_type, | 69 FrameMsg_Navigate_Type::Value navigation_type, |
| 70 LoFiState lofi_state, | 70 LoFiState lofi_state, |
| 71 bool is_same_document_history_load, | 71 bool is_same_document_history_load, |
| 72 const base::TimeTicks& navigation_start, | 72 const base::TimeTicks& navigation_start, |
| 73 NavigationControllerImpl* controller) { | 73 NavigationControllerImpl* controller) { |
| 74 std::string method = entry.GetHasPostData() ? "POST" : "GET"; | |
| 75 | |
| 76 // Copy existing headers and add necessary headers that may not be present | 74 // Copy existing headers and add necessary headers that may not be present |
| 77 // in the RequestNavigationParams. | 75 // in the RequestNavigationParams. |
| 78 net::HttpRequestHeaders headers; | 76 net::HttpRequestHeaders headers; |
| 79 headers.AddHeadersFromString(entry.extra_headers()); | 77 headers.AddHeadersFromString(entry.extra_headers()); |
| 80 headers.SetHeaderIfMissing(net::HttpRequestHeaders::kUserAgent, | 78 headers.SetHeaderIfMissing(net::HttpRequestHeaders::kUserAgent, |
| 81 GetContentClient()->GetUserAgent()); | 79 GetContentClient()->GetUserAgent()); |
| 82 // TODO(clamy): match what blink is doing with accept headers. | 80 // TODO(clamy): match what blink is doing with accept headers. |
| 83 headers.SetHeaderIfMissing("Accept", "*/*"); | 81 headers.SetHeaderIfMissing("Accept", "*/*"); |
| 84 | 82 |
| 85 // Fill POST data from the browser in the request body. | 83 // Fill POST data from the browser in the request body. |
| 86 scoped_refptr<ResourceRequestBody> request_body; | 84 scoped_refptr<ResourceRequestBody> request_body; |
| 87 if (entry.GetHasPostData()) { | 85 if (entry.GetHasPostData()) { |
| 88 request_body = new ResourceRequestBody(); | 86 request_body = new ResourceRequestBody(); |
| 89 request_body->AppendBytes( | 87 request_body->AppendBytes( |
| 90 reinterpret_cast<const char *>( | 88 reinterpret_cast<const char *>( |
| 91 entry.GetBrowserInitiatedPostData()->front()), | 89 entry.GetBrowserInitiatedPostData()->front()), |
| 92 entry.GetBrowserInitiatedPostData()->size()); | 90 entry.GetBrowserInitiatedPostData()->size()); |
| 93 } | 91 } |
| 94 | 92 |
| 95 scoped_ptr<NavigationRequest> navigation_request(new NavigationRequest( | 93 scoped_ptr<NavigationRequest> navigation_request(new NavigationRequest( |
| 96 frame_tree_node, entry.ConstructCommonNavigationParams( | 94 frame_tree_node, entry.ConstructCommonNavigationParams( |
| 97 dest_url, dest_referrer, navigation_type, lofi_state, | 95 dest_url, dest_referrer, navigation_type, lofi_state, |
| 98 navigation_start), | 96 navigation_start), |
| 99 BeginNavigationParams(method, headers.ToString(), | 97 BeginNavigationParams(headers.ToString(), |
| 100 LoadFlagFromNavigationType(navigation_type), | 98 LoadFlagFromNavigationType(navigation_type), |
| 101 false, // has_user_gestures | 99 false, // has_user_gestures |
| 102 false, // skip_service_worker | 100 false, // skip_service_worker |
| 103 REQUEST_CONTEXT_TYPE_LOCATION), | 101 REQUEST_CONTEXT_TYPE_LOCATION), |
| 104 entry.ConstructRequestNavigationParams( | 102 entry.ConstructRequestNavigationParams( |
| 105 frame_entry, is_same_document_history_load, | 103 frame_entry, is_same_document_history_load, |
| 106 frame_tree_node->has_committed_real_load(), | 104 frame_tree_node->has_committed_real_load(), |
| 107 controller->GetPendingEntryIndex() == -1, | 105 controller->GetPendingEntryIndex() == -1, |
| 108 controller->GetIndexOfEntry(&entry), | 106 controller->GetIndexOfEntry(&entry), |
| 109 controller->GetLastCommittedEntryIndex(), | 107 controller->GetLastCommittedEntryIndex(), |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 203 | 201 |
| 204 void NavigationRequest::BeginNavigation() { | 202 void NavigationRequest::BeginNavigation() { |
| 205 DCHECK(!loader_); | 203 DCHECK(!loader_); |
| 206 DCHECK(state_ == NOT_STARTED || state_ == WAITING_FOR_RENDERER_RESPONSE); | 204 DCHECK(state_ == NOT_STARTED || state_ == WAITING_FOR_RENDERER_RESPONSE); |
| 207 state_ = STARTED; | 205 state_ = STARTED; |
| 208 | 206 |
| 209 if (ShouldMakeNetworkRequestForURL(common_params_.url)) { | 207 if (ShouldMakeNetworkRequestForURL(common_params_.url)) { |
| 210 // It's safe to use base::Unretained because this NavigationRequest owns | 208 // It's safe to use base::Unretained because this NavigationRequest owns |
| 211 // the NavigationHandle where the callback will be stored. | 209 // the NavigationHandle where the callback will be stored. |
| 212 // TODO(clamy): pass the real value for |is_external_protocol| if needed. | 210 // TODO(clamy): pass the real value for |is_external_protocol| if needed. |
| 211 // TODO(clamy): pass the method to the NavigationHandle instead of a |
| 212 // boolean. |
| 213 navigation_handle_->WillStartRequest( | 213 navigation_handle_->WillStartRequest( |
| 214 begin_params_.method == "POST", | 214 common_params_.method == "POST", |
| 215 Referrer::SanitizeForRequest(common_params_.url, | 215 Referrer::SanitizeForRequest(common_params_.url, |
| 216 common_params_.referrer), | 216 common_params_.referrer), |
| 217 begin_params_.has_user_gesture, common_params_.transition, false, | 217 begin_params_.has_user_gesture, common_params_.transition, false, |
| 218 base::Bind(&NavigationRequest::OnStartChecksComplete, | 218 base::Bind(&NavigationRequest::OnStartChecksComplete, |
| 219 base::Unretained(this))); | 219 base::Unretained(this))); |
| 220 return; | 220 return; |
| 221 } | 221 } |
| 222 | 222 |
| 223 // There is no need to make a network request for this navigation, so commit | 223 // There is no need to make a network request for this navigation, so commit |
| 224 // it immediately. | 224 // it immediately. |
| (...skipping 14 matching lines...) Expand all Loading... |
| 239 | 239 |
| 240 void NavigationRequest::TransferNavigationHandleOwnership( | 240 void NavigationRequest::TransferNavigationHandleOwnership( |
| 241 RenderFrameHostImpl* render_frame_host) { | 241 RenderFrameHostImpl* render_frame_host) { |
| 242 render_frame_host->SetNavigationHandle(std::move(navigation_handle_)); | 242 render_frame_host->SetNavigationHandle(std::move(navigation_handle_)); |
| 243 } | 243 } |
| 244 | 244 |
| 245 void NavigationRequest::OnRequestRedirected( | 245 void NavigationRequest::OnRequestRedirected( |
| 246 const net::RedirectInfo& redirect_info, | 246 const net::RedirectInfo& redirect_info, |
| 247 const scoped_refptr<ResourceResponse>& response) { | 247 const scoped_refptr<ResourceResponse>& response) { |
| 248 common_params_.url = redirect_info.new_url; | 248 common_params_.url = redirect_info.new_url; |
| 249 begin_params_.method = redirect_info.new_method; | 249 common_params_.method = redirect_info.new_method; |
| 250 common_params_.referrer.url = GURL(redirect_info.new_referrer); | 250 common_params_.referrer.url = GURL(redirect_info.new_referrer); |
| 251 | 251 |
| 252 // TODO(clamy): Have CSP + security upgrade checks here. | 252 // TODO(clamy): Have CSP + security upgrade checks here. |
| 253 // TODO(clamy): Kill the renderer if FilterURL fails? | 253 // TODO(clamy): Kill the renderer if FilterURL fails? |
| 254 | 254 |
| 255 // It's safe to use base::Unretained because this NavigationRequest owns the | 255 // It's safe to use base::Unretained because this NavigationRequest owns the |
| 256 // NavigationHandle where the callback will be stored. | 256 // NavigationHandle where the callback will be stored. |
| 257 // TODO(clamy): pass the real value for |is_external_protocol| if needed. | 257 // TODO(clamy): pass the real value for |is_external_protocol| if needed. |
| 258 navigation_handle_->WillRedirectRequest( | 258 navigation_handle_->WillRedirectRequest( |
| 259 common_params_.url, begin_params_.method == "POST", | 259 common_params_.url, common_params_.method == "POST", |
| 260 common_params_.referrer.url, false, response->head.headers, | 260 common_params_.referrer.url, false, response->head.headers, |
| 261 base::Bind(&NavigationRequest::OnRedirectChecksComplete, | 261 base::Bind(&NavigationRequest::OnRedirectChecksComplete, |
| 262 base::Unretained(this))); | 262 base::Unretained(this))); |
| 263 } | 263 } |
| 264 | 264 |
| 265 void NavigationRequest::OnResponseStarted( | 265 void NavigationRequest::OnResponseStarted( |
| 266 const scoped_refptr<ResourceResponse>& response, | 266 const scoped_refptr<ResourceResponse>& response, |
| 267 scoped_ptr<StreamHandle> body) { | 267 scoped_ptr<StreamHandle> body) { |
| 268 DCHECK(state_ == STARTED); | 268 DCHECK(state_ == STARTED); |
| 269 state_ = RESPONSE_STARTED; | 269 state_ = RESPONSE_STARTED; |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 365 browser_context, navigating_frame_host->GetSiteInstance()); | 365 browser_context, navigating_frame_host->GetSiteInstance()); |
| 366 DCHECK(partition); | 366 DCHECK(partition); |
| 367 | 367 |
| 368 ServiceWorkerContextWrapper* service_worker_context = | 368 ServiceWorkerContextWrapper* service_worker_context = |
| 369 static_cast<ServiceWorkerContextWrapper*>( | 369 static_cast<ServiceWorkerContextWrapper*>( |
| 370 partition->GetServiceWorkerContext()); | 370 partition->GetServiceWorkerContext()); |
| 371 navigation_handle_->InitServiceWorkerHandle(service_worker_context); | 371 navigation_handle_->InitServiceWorkerHandle(service_worker_context); |
| 372 } | 372 } |
| 373 | 373 |
| 374 } // namespace content | 374 } // namespace content |
| OLD | NEW |