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 "base/memory/ptr_util.h" | 9 #include "base/memory/ptr_util.h" |
10 #include "content/browser/appcache/appcache_navigation_handle.h" | 10 #include "content/browser/appcache/appcache_navigation_handle.h" |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
65 case FrameMsg_Navigate_Type::RELOAD_BYPASSING_CACHE: | 65 case FrameMsg_Navigate_Type::RELOAD_BYPASSING_CACHE: |
66 *load_flags |= net::LOAD_BYPASS_CACHE; | 66 *load_flags |= net::LOAD_BYPASS_CACHE; |
67 break; | 67 break; |
68 case FrameMsg_Navigate_Type::RESTORE: | 68 case FrameMsg_Navigate_Type::RESTORE: |
69 *load_flags |= net::LOAD_SKIP_CACHE_VALIDATION; | 69 *load_flags |= net::LOAD_SKIP_CACHE_VALIDATION; |
70 break; | 70 break; |
71 case FrameMsg_Navigate_Type::RESTORE_WITH_POST: | 71 case FrameMsg_Navigate_Type::RESTORE_WITH_POST: |
72 *load_flags |= | 72 *load_flags |= |
73 net::LOAD_ONLY_FROM_CACHE | net::LOAD_SKIP_CACHE_VALIDATION; | 73 net::LOAD_ONLY_FROM_CACHE | net::LOAD_SKIP_CACHE_VALIDATION; |
74 break; | 74 break; |
75 case FrameMsg_Navigate_Type::NORMAL: | 75 case FrameMsg_Navigate_Type::SAME_DOCUMENT: |
| 76 case FrameMsg_Navigate_Type::DIFFERENT_DOCUMENT: |
| 77 case FrameMsg_Navigate_Type::HISTORY_SAME_DOCUMENT: |
| 78 case FrameMsg_Navigate_Type::HISTORY_DIFFERENT_DOCUMENT: |
76 if (is_post) | 79 if (is_post) |
77 *load_flags |= net::LOAD_VALIDATE_CACHE; | 80 *load_flags |= net::LOAD_VALIDATE_CACHE; |
78 break; | 81 break; |
79 default: | |
80 break; | |
81 } | 82 } |
82 } | 83 } |
83 | 84 |
84 // This is based on SecurityOrigin::isPotentiallyTrustworthy. | 85 // This is based on SecurityOrigin::isPotentiallyTrustworthy. |
85 // TODO(clamy): This should be function in url::Origin. | 86 // TODO(clamy): This should be function in url::Origin. |
86 bool IsPotentiallyTrustworthyOrigin(const url::Origin& origin) { | 87 bool IsPotentiallyTrustworthyOrigin(const url::Origin& origin) { |
87 if (origin.unique()) | 88 if (origin.unique()) |
88 return false; | 89 return false; |
89 | 90 |
90 if (origin.scheme() == url::kHttpsScheme || | 91 if (origin.scheme() == url::kHttpsScheme || |
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
224 frame_tree_node, entry.ConstructCommonNavigationParams( | 225 frame_tree_node, entry.ConstructCommonNavigationParams( |
225 frame_entry, request_body, dest_url, dest_referrer, | 226 frame_entry, request_body, dest_url, dest_referrer, |
226 navigation_type, previews_state, navigation_start), | 227 navigation_type, previews_state, navigation_start), |
227 BeginNavigationParams(entry.extra_headers(), net::LOAD_NORMAL, | 228 BeginNavigationParams(entry.extra_headers(), net::LOAD_NORMAL, |
228 false, // has_user_gestures | 229 false, // has_user_gestures |
229 false, // skip_service_worker | 230 false, // skip_service_worker |
230 REQUEST_CONTEXT_TYPE_LOCATION, | 231 REQUEST_CONTEXT_TYPE_LOCATION, |
231 blink::WebMixedContentContextType::Blockable, | 232 blink::WebMixedContentContextType::Blockable, |
232 initiator), | 233 initiator), |
233 entry.ConstructRequestNavigationParams( | 234 entry.ConstructRequestNavigationParams( |
234 frame_entry, is_same_document_history_load, | 235 frame_entry, is_history_navigation_in_new_child, |
235 is_history_navigation_in_new_child, | |
236 entry.GetSubframeUniqueNames(frame_tree_node), | 236 entry.GetSubframeUniqueNames(frame_tree_node), |
237 frame_tree_node->has_committed_real_load(), | 237 frame_tree_node->has_committed_real_load(), |
238 controller->GetPendingEntryIndex() == -1, | 238 controller->GetPendingEntryIndex() == -1, |
239 controller->GetIndexOfEntry(&entry), | 239 controller->GetIndexOfEntry(&entry), |
240 controller->GetLastCommittedEntryIndex(), | 240 controller->GetLastCommittedEntryIndex(), |
241 controller->GetEntryCount()), | 241 controller->GetEntryCount()), |
242 browser_initiated, | 242 browser_initiated, |
243 true, // may_transfer | 243 true, // may_transfer |
244 &frame_entry, &entry)); | 244 &frame_entry, &entry)); |
245 return navigation_request; | 245 return navigation_request; |
246 } | 246 } |
247 | 247 |
248 // static | 248 // static |
249 std::unique_ptr<NavigationRequest> NavigationRequest::CreateRendererInitiated( | 249 std::unique_ptr<NavigationRequest> NavigationRequest::CreateRendererInitiated( |
250 FrameTreeNode* frame_tree_node, | 250 FrameTreeNode* frame_tree_node, |
251 const CommonNavigationParams& common_params, | 251 const CommonNavigationParams& common_params, |
252 const BeginNavigationParams& begin_params, | 252 const BeginNavigationParams& begin_params, |
253 int current_history_list_offset, | 253 int current_history_list_offset, |
254 int current_history_list_length) { | 254 int current_history_list_length) { |
255 // TODO(clamy): Check if some PageState should be provided here. | 255 // Only normal navigations to a different document or reloads are expected. |
| 256 // - Renderer-initiated fragment-navigations never take place in the browser, |
| 257 // even with PlzNavigate. |
| 258 // - Restore-navigations are always browser-initiated. |
| 259 // - History-navigations use the browser-initiated path, event the ones that |
| 260 // are initiated by a javascript script, please see the IPC message |
| 261 // ViewHostMsg_GoToEntryAtOffset. |
| 262 DCHECK(FrameMsg_Navigate_Type::IsReload(common_params.navigation_type) || |
| 263 common_params.navigation_type == |
| 264 FrameMsg_Navigate_Type::DIFFERENT_DOCUMENT); |
| 265 |
256 // TODO(clamy): See how we should handle override of the user agent when the | 266 // TODO(clamy): See how we should handle override of the user agent when the |
257 // navigation may start in a renderer and commit in another one. | 267 // navigation may start in a renderer and commit in another one. |
258 // TODO(clamy): See if the navigation start time should be measured in the | 268 // TODO(clamy): See if the navigation start time should be measured in the |
259 // renderer and sent to the browser instead of being measured here. | 269 // renderer and sent to the browser instead of being measured here. |
260 // TODO(clamy): The pending history list offset should be properly set. | 270 // TODO(clamy): The pending history list offset should be properly set. |
261 RequestNavigationParams request_params( | 271 RequestNavigationParams request_params( |
262 false, // is_overriding_user_agent | 272 false, // is_overriding_user_agent |
263 std::vector<GURL>(), // redirects | 273 std::vector<GURL>(), // redirects |
264 false, // can_load_local_resources | 274 false, // can_load_local_resources |
265 PageState(), // page_state | 275 PageState(), // page_state |
266 0, // nav_entry_id | 276 0, // nav_entry_id |
267 false, // is_same_document_history_load | 277 false, // is_history_navigation_in_new_child |
268 false, // is_history_navigation_in_new_child | 278 std::map<std::string, bool>(), // subframe_unique_names |
269 std::map<std::string, bool>(), // subframe_unique_names | |
270 frame_tree_node->has_committed_real_load(), | 279 frame_tree_node->has_committed_real_load(), |
271 false, // intended_as_new_entry | 280 false, // intended_as_new_entry |
272 -1, // pending_history_list_offset | 281 -1, // pending_history_list_offset |
273 current_history_list_offset, current_history_list_length, | 282 current_history_list_offset, current_history_list_length, |
274 false, // is_view_source | 283 false, // is_view_source |
275 false, // should_clear_history_list | 284 false, // should_clear_history_list |
276 begin_params.has_user_gesture); | 285 begin_params.has_user_gesture); |
277 std::unique_ptr<NavigationRequest> navigation_request( | 286 std::unique_ptr<NavigationRequest> navigation_request(new NavigationRequest( |
278 new NavigationRequest(frame_tree_node, common_params, begin_params, | 287 frame_tree_node, common_params, begin_params, request_params, |
279 request_params, | 288 false, // browser_initiated |
280 false, // browser_initiated | 289 false, // may_transfer |
281 false, // may_transfer | 290 nullptr, nullptr)); |
282 nullptr, nullptr)); | |
283 return navigation_request; | 291 return navigation_request; |
284 } | 292 } |
285 | 293 |
286 NavigationRequest::NavigationRequest( | 294 NavigationRequest::NavigationRequest( |
287 FrameTreeNode* frame_tree_node, | 295 FrameTreeNode* frame_tree_node, |
288 const CommonNavigationParams& common_params, | 296 const CommonNavigationParams& common_params, |
289 const BeginNavigationParams& begin_params, | 297 const BeginNavigationParams& begin_params, |
290 const RequestNavigationParams& request_params, | 298 const RequestNavigationParams& request_params, |
291 bool browser_initiated, | 299 bool browser_initiated, |
292 bool may_transfer, | 300 bool may_transfer, |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
339 | 347 |
340 NavigationRequest::~NavigationRequest() { | 348 NavigationRequest::~NavigationRequest() { |
341 } | 349 } |
342 | 350 |
343 void NavigationRequest::BeginNavigation() { | 351 void NavigationRequest::BeginNavigation() { |
344 DCHECK(!loader_); | 352 DCHECK(!loader_); |
345 DCHECK(state_ == NOT_STARTED || state_ == WAITING_FOR_RENDERER_RESPONSE); | 353 DCHECK(state_ == NOT_STARTED || state_ == WAITING_FOR_RENDERER_RESPONSE); |
346 state_ = STARTED; | 354 state_ = STARTED; |
347 RenderFrameDevToolsAgentHost::OnBeforeNavigation(navigation_handle_.get()); | 355 RenderFrameDevToolsAgentHost::OnBeforeNavigation(navigation_handle_.get()); |
348 | 356 |
349 if (ShouldMakeNetworkRequestForURL(common_params_.url)) { | 357 if (ShouldMakeNetworkRequestForURL(common_params_.url) && |
| 358 !navigation_handle_->IsSamePage()) { |
350 // It's safe to use base::Unretained because this NavigationRequest owns | 359 // It's safe to use base::Unretained because this NavigationRequest owns |
351 // the NavigationHandle where the callback will be stored. | 360 // the NavigationHandle where the callback will be stored. |
352 // TODO(clamy): pass the real value for |is_external_protocol| if needed. | 361 // TODO(clamy): pass the real value for |is_external_protocol| if needed. |
353 // TODO(clamy): pass the method to the NavigationHandle instead of a | 362 // TODO(clamy): pass the method to the NavigationHandle instead of a |
354 // boolean. | 363 // boolean. |
355 navigation_handle_->WillStartRequest( | 364 navigation_handle_->WillStartRequest( |
356 common_params_.method, common_params_.post_data, | 365 common_params_.method, common_params_.post_data, |
357 Referrer::SanitizeForRequest(common_params_.url, | 366 Referrer::SanitizeForRequest(common_params_.url, |
358 common_params_.referrer), | 367 common_params_.referrer), |
359 begin_params_.has_user_gesture, common_params_.transition, false, | 368 begin_params_.has_user_gesture, common_params_.transition, false, |
(...skipping 15 matching lines...) Expand all Loading... |
375 common_params_.url); | 384 common_params_.url); |
376 | 385 |
377 // Inform the NavigationHandle that the navigation will commit. | 386 // Inform the NavigationHandle that the navigation will commit. |
378 navigation_handle_->ReadyToCommitNavigation(render_frame_host); | 387 navigation_handle_->ReadyToCommitNavigation(render_frame_host); |
379 | 388 |
380 CommitNavigation(); | 389 CommitNavigation(); |
381 } | 390 } |
382 | 391 |
383 void NavigationRequest::CreateNavigationHandle(int pending_nav_entry_id) { | 392 void NavigationRequest::CreateNavigationHandle(int pending_nav_entry_id) { |
384 DCHECK_EQ(frame_tree_node_->navigation_request(), this); | 393 DCHECK_EQ(frame_tree_node_->navigation_request(), this); |
385 // TODO(nasko): Update the NavigationHandle creation to ensure that the | |
386 // proper values are specified for is_same_page. | |
387 FrameTreeNode* frame_tree_node = frame_tree_node_; | 394 FrameTreeNode* frame_tree_node = frame_tree_node_; |
388 | 395 |
389 std::vector<GURL> redirect_chain; | 396 std::vector<GURL> redirect_chain; |
390 if (!begin_params_.client_side_redirect_url.is_empty()) | 397 if (!begin_params_.client_side_redirect_url.is_empty()) |
391 redirect_chain.push_back(begin_params_.client_side_redirect_url); | 398 redirect_chain.push_back(begin_params_.client_side_redirect_url); |
392 redirect_chain.push_back(common_params_.url); | 399 redirect_chain.push_back(common_params_.url); |
393 | 400 |
394 std::unique_ptr<NavigationHandleImpl> navigation_handle = | 401 std::unique_ptr<NavigationHandleImpl> navigation_handle = |
395 NavigationHandleImpl::Create( | 402 NavigationHandleImpl::Create( |
396 common_params_.url, redirect_chain, frame_tree_node_, | 403 common_params_.url, redirect_chain, frame_tree_node_, |
397 !browser_initiated_, | 404 !browser_initiated_, FrameMsg_Navigate_Type::IsSameDocument( |
398 false, // is_same_page | 405 common_params_.navigation_type), |
399 common_params_.navigation_start, pending_nav_entry_id, | 406 common_params_.navigation_start, pending_nav_entry_id, |
400 false); // started_in_context_menu | 407 false); // started_in_context_menu |
401 | 408 |
402 if (!frame_tree_node->navigation_request()) { | 409 if (!frame_tree_node->navigation_request()) { |
403 // A callback could have cancelled this request synchronously in which case | 410 // A callback could have cancelled this request synchronously in which case |
404 // |this| is deleted. | 411 // |this| is deleted. |
405 return; | 412 return; |
406 } | 413 } |
407 | 414 |
408 navigation_handle_ = std::move(navigation_handle); | 415 navigation_handle_ = std::move(navigation_handle); |
409 | 416 |
410 if (!begin_params_.searchable_form_url.is_empty()) { | 417 if (!begin_params_.searchable_form_url.is_empty()) { |
(...skipping 305 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
716 // Have the processing of the response resume in the network stack. | 723 // Have the processing of the response resume in the network stack. |
717 loader_->ProceedWithResponse(); | 724 loader_->ProceedWithResponse(); |
718 | 725 |
719 CommitNavigation(); | 726 CommitNavigation(); |
720 | 727 |
721 // DO NOT ADD CODE after this. The previous call to CommitNavigation caused | 728 // DO NOT ADD CODE after this. The previous call to CommitNavigation caused |
722 // the destruction of the NavigationRequest. | 729 // the destruction of the NavigationRequest. |
723 } | 730 } |
724 | 731 |
725 void NavigationRequest::CommitNavigation() { | 732 void NavigationRequest::CommitNavigation() { |
726 DCHECK(response_ || !ShouldMakeNetworkRequestForURL(common_params_.url)); | 733 DCHECK(response_ || !ShouldMakeNetworkRequestForURL(common_params_.url) || |
| 734 navigation_handle_->IsSamePage()); |
727 DCHECK(!common_params_.url.SchemeIs(url::kJavaScriptScheme)); | 735 DCHECK(!common_params_.url.SchemeIs(url::kJavaScriptScheme)); |
728 | 736 |
729 // Retrieve the RenderFrameHost that needs to commit the navigation. | 737 // Retrieve the RenderFrameHost that needs to commit the navigation. |
730 RenderFrameHostImpl* render_frame_host = | 738 RenderFrameHostImpl* render_frame_host = |
731 navigation_handle_->GetRenderFrameHost(); | 739 navigation_handle_->GetRenderFrameHost(); |
732 DCHECK(render_frame_host == | 740 DCHECK(render_frame_host == |
733 frame_tree_node_->render_manager()->current_frame_host() || | 741 frame_tree_node_->render_manager()->current_frame_host() || |
734 render_frame_host == | 742 render_frame_host == |
735 frame_tree_node_->render_manager()->speculative_frame_host()); | 743 frame_tree_node_->render_manager()->speculative_frame_host()); |
736 | 744 |
737 TransferNavigationHandleOwnership(render_frame_host); | 745 TransferNavigationHandleOwnership(render_frame_host); |
738 | 746 |
739 DCHECK_EQ(request_params_.has_user_gesture, begin_params_.has_user_gesture); | 747 DCHECK_EQ(request_params_.has_user_gesture, begin_params_.has_user_gesture); |
740 | 748 |
741 render_frame_host->CommitNavigation(response_.get(), std::move(body_), | 749 render_frame_host->CommitNavigation(response_.get(), std::move(body_), |
742 common_params_, request_params_, | 750 common_params_, request_params_, |
743 is_view_source_); | 751 is_view_source_); |
744 | 752 |
745 frame_tree_node_->ResetNavigationRequest(true); | 753 frame_tree_node_->ResetNavigationRequest(true); |
746 } | 754 } |
747 | 755 |
748 } // namespace content | 756 } // namespace content |
OLD | NEW |