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

Side by Side Diff: content/renderer/render_frame_impl.cc

Issue 1157863005: Use WebFrame::loadRequest for reloads and history navigations (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 6 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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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/renderer/render_frame_impl.h" 5 #include "content/renderer/render_frame_impl.h"
6 6
7 #include <map> 7 #include <map>
8 #include <string> 8 #include <string>
9 9
10 #include "base/auto_reset.h" 10 #include "base/auto_reset.h"
(...skipping 4397 matching lines...) Expand 10 before | Expand all | Expand 10 after
4408 if (is_reload && !render_view_->history_controller()->GetCurrentEntry()) { 4408 if (is_reload && !render_view_->history_controller()->GetCurrentEntry()) {
4409 // We cannot reload if we do not have any history state. This happens, for 4409 // We cannot reload if we do not have any history state. This happens, for
4410 // example, when recovering from a crash. 4410 // example, when recovering from a crash.
4411 is_reload = false; 4411 is_reload = false;
4412 cache_policy = WebURLRequest::ReloadIgnoringCacheData; 4412 cache_policy = WebURLRequest::ReloadIgnoringCacheData;
4413 } 4413 }
4414 4414
4415 pending_navigation_params_.reset( 4415 pending_navigation_params_.reset(
4416 new NavigationParams(common_params, start_params, request_params)); 4416 new NavigationParams(common_params, start_params, request_params));
4417 4417
4418 // If we are reloading, then Blink will use the history state of the current 4418 // Create parameters for a standard navigation.
4419 // page, so we should just ignore any given history state. Otherwise, if we 4419 WebFrame::WebFrameLoadType load_type = WebFrame::WebFrameLoadTypeStandard;
4420 // have history state, then we need to navigate to it, which corresponds to a 4420 WebHistoryItem item_for_history_navigation;
4421 // back/forward navigation event. 4421 WebURLRequest request = CreateURLRequestForNavigation(
4422 if (is_reload && !browser_side_navigation) { 4422 common_params, stream_params.Pass(), frame_->isViewSourceModeEnabled());
4423 // TODO(clamy): adapt this code for PlzNavigate. In particular the stream 4423
4424 // override should be given to the generated request. 4424 // PlzNavigate: Make sure that Blink's loader will not try to use browser side
4425 bool reload_original_url = 4425 // navigation for this request (since it already went to the browser).
4426 (common_params.navigation_type == 4426 if (browser_side_navigation)
4427 FrameMsg_Navigate_Type::RELOAD_ORIGINAL_REQUEST_URL); 4427 request.setCheckForBrowserSideNavigation(false);
4428
4429 // If we are reloading, then use the history state of the current frame.
4430 // Otherwise, if we have history state, then we need to navigate to it, which
4431 // corresponds to a back/forward navigation event. Update the parameters
4432 // depending on the navigation type.
4433 if (is_reload) {
4428 bool ignore_cache = (common_params.navigation_type == 4434 bool ignore_cache = (common_params.navigation_type ==
4429 FrameMsg_Navigate_Type::RELOAD_IGNORING_CACHE); 4435 FrameMsg_Navigate_Type::RELOAD_IGNORING_CACHE);
4436 load_type = ignore_cache ? WebFrame::WebFrameLoadTypeReloadFromOrigin
4437 : WebFrame::WebFrameLoadTypeReload;
4430 4438
4431 if (reload_original_url) 4439 if (!browser_side_navigation) {
4432 frame_->reloadWithOverrideURL(common_params.url, true); 4440 WebHistoryItem current_item = frame_->CurrentItem();
4433 else 4441 if (current_item.isNull()) {
4434 frame_->reload(ignore_cache); 4442 Send(new FrameHostMsg_DidDropNavigation(routing_id_));
Charlie Reis 2015/05/27 23:34:36 I don't understand this case. When would this hap
clamy 2015/05/29 14:47:01 Following interface changes in the blink patch thi
4435 } else if (is_history_navigation && !browser_side_navigation) { 4443 pending_navigation_params_.reset();
4436 // TODO(clamy): adapt this code for PlzNavigate. In particular the stream 4444 return;
4437 // override should be given to the generated request. 4445 }
4438 4446 const GURL override_url =
4447 (common_params.navigation_type ==
4448 FrameMsg_Navigate_Type::RELOAD_ORIGINAL_REQUEST_URL)
4449 ? common_params.url
4450 : GURL();
4451 request = frame_->RequestForReload(current_item, load_type, override_url);
4452 }
4453 } else if (is_history_navigation) {
4439 // We must know the page ID of the page we are navigating back to. 4454 // We must know the page ID of the page we are navigating back to.
4440 DCHECK_NE(request_params.page_id, -1); 4455 DCHECK_NE(request_params.page_id, -1);
4441 // We must know the nav entry ID of the page we are navigating back to, 4456 // We must know the nav entry ID of the page we are navigating back to,
4442 // which should be the case because history navigations are routed via the 4457 // which should be the case because history navigations are routed via the
4443 // browser. 4458 // browser.
4444 DCHECK_NE(0, request_params.nav_entry_id); 4459 DCHECK_NE(0, request_params.nav_entry_id);
4445 scoped_ptr<HistoryEntry> entry = 4460 scoped_ptr<HistoryEntry> entry =
4446 PageStateToHistoryEntry(request_params.page_state); 4461 PageStateToHistoryEntry(request_params.page_state);
4447 if (entry) { 4462 if (!entry) {
4448 // Ensure we didn't save the swapped out URL in UpdateState, since the 4463 Send(new FrameHostMsg_DidDropNavigation(routing_id_));
Charlie Reis 2015/05/27 23:34:36 It feels awkward to have this in multiple places,
clamy 2015/05/29 14:47:01 I can remove it. It just seemed weird to me that t
4449 // browser should never be telling us to navigate to swappedout://. 4464 pending_navigation_params_.reset();
4450 CHECK(entry->root().urlString() != WebString::fromUTF8(kSwappedOutURL)); 4465 return;
4451 scoped_ptr<NavigationParams> navigation_params( 4466 }
4452 new NavigationParams(*pending_navigation_params_.get())); 4467
4468 // Ensure we didn't save the swapped out URL in UpdateState, since the
4469 // browser should never be telling us to navigate to swappedout://.
4470 CHECK(entry->root().urlString() != WebString::fromUTF8(kSwappedOutURL));
4471 scoped_ptr<NavigationParams> navigation_params(
4472 new NavigationParams(*pending_navigation_params_.get()));
4473 if (!browser_side_navigation) {
4453 render_view_->history_controller()->GoToEntry( 4474 render_view_->history_controller()->GoToEntry(
4454 entry.Pass(), navigation_params.Pass(), cache_policy); 4475 entry.Pass(), navigation_params.Pass(), cache_policy);
4476 pending_navigation_params_.reset();
4477 return;
4478 } else {
Charlie Reis 2015/05/27 23:34:36 No else needed after a return.
clamy 2015/05/29 14:47:01 Done.
4479 item_for_history_navigation =
4480 render_view_->history_controller()->FindItemForFrame(
Charlie Reis 2015/05/27 23:34:36 This isn't going to make sense soon, and I'm not s
clamy 2015/05/29 14:47:01 With PlzNavigate we also get to NavigateInternal o
4481 entry.Pass(), this, cache_policy, &load_type);
4455 } 4482 }
4456 } else if (!common_params.base_url_for_data_url.is_empty() ||
4457 (browser_side_navigation &&
4458 common_params.url.SchemeIs(url::kDataScheme))) {
4459 LoadDataURL(common_params, frame_);
4460 } else { 4483 } else {
4461 // Navigate to the given URL. 4484 // Navigate to the given URL.
4462 WebURLRequest request = CreateURLRequestForNavigation(
4463 common_params, stream_params.Pass(), frame_->isViewSourceModeEnabled());
4464
4465 if (!start_params.extra_headers.empty() && !browser_side_navigation) { 4485 if (!start_params.extra_headers.empty() && !browser_side_navigation) {
4466 for (net::HttpUtil::HeadersIterator i(start_params.extra_headers.begin(), 4486 for (net::HttpUtil::HeadersIterator i(start_params.extra_headers.begin(),
4467 start_params.extra_headers.end(), 4487 start_params.extra_headers.end(),
4468 "\n"); 4488 "\n");
4469 i.GetNext();) { 4489 i.GetNext();) {
4470 request.addHTTPHeaderField(WebString::fromUTF8(i.name()), 4490 request.addHTTPHeaderField(WebString::fromUTF8(i.name()),
4471 WebString::fromUTF8(i.values())); 4491 WebString::fromUTF8(i.values()));
4472 } 4492 }
4473 } 4493 }
4474 4494
4475 if (start_params.is_post && !browser_side_navigation) { 4495 if (start_params.is_post && !browser_side_navigation) {
4476 request.setHTTPMethod(WebString::fromUTF8("POST")); 4496 request.setHTTPMethod(WebString::fromUTF8("POST"));
4477 4497
4478 // Set post data. 4498 // Set post data.
4479 WebHTTPBody http_body; 4499 WebHTTPBody http_body;
4480 http_body.initialize(); 4500 http_body.initialize();
4481 const char* data = nullptr; 4501 const char* data = nullptr;
4482 if (start_params.browser_initiated_post_data.size()) { 4502 if (start_params.browser_initiated_post_data.size()) {
4483 data = reinterpret_cast<const char*>( 4503 data = reinterpret_cast<const char*>(
4484 &start_params.browser_initiated_post_data.front()); 4504 &start_params.browser_initiated_post_data.front());
4485 } 4505 }
4486 http_body.appendData( 4506 http_body.appendData(
4487 WebData(data, start_params.browser_initiated_post_data.size())); 4507 WebData(data, start_params.browser_initiated_post_data.size()));
4488 request.setHTTPBody(http_body); 4508 request.setHTTPBody(http_body);
4489 } 4509 }
4490 4510
4491 // A session history navigation should have been accompanied by state. 4511 // A session history navigation should have been accompanied by state.
4492 CHECK_EQ(request_params.page_id, -1); 4512 CHECK_EQ(request_params.page_id, -1);
4493 4513
4494 // PlzNavigate: Make sure that Blink's loader will not try to use browser
4495 // side navigation for this request (since it already went to the browser).
4496 if (browser_side_navigation)
4497 request.setCheckForBrowserSideNavigation(false);
4498
4499 // Record this before starting the load. We need a lower bound of this time 4514 // Record this before starting the load. We need a lower bound of this time
4500 // to sanitize the navigationStart override set below. 4515 // to sanitize the navigationStart override set below.
4501 base::TimeTicks renderer_navigation_start = base::TimeTicks::Now(); 4516 base::TimeTicks renderer_navigation_start = base::TimeTicks::Now();
4502 frame_->loadRequest(request);
4503
4504 UpdateFrameNavigationTiming(frame_, request_params.browser_navigation_start, 4517 UpdateFrameNavigationTiming(frame_, request_params.browser_navigation_start,
4505 renderer_navigation_start); 4518 renderer_navigation_start);
4506 } 4519 }
4507 4520
4521 // Perform a navigation to a data url if needed.
4522 if (!common_params.base_url_for_data_url.is_empty() ||
4523 (browser_side_navigation &&
4524 common_params.url.SchemeIs(url::kDataScheme))) {
4525 LoadDataURL(common_params, frame_);
4526 pending_navigation_params_.reset();
4527 return;
4528 }
4529
4530 // Load the request.
4531 frame_->loadRequest(request, load_type, item_for_history_navigation);
4532
4508 // In case LoadRequest failed before didCreateDataSource was called. 4533 // In case LoadRequest failed before didCreateDataSource was called.
4509 pending_navigation_params_.reset(); 4534 pending_navigation_params_.reset();
4510 } 4535 }
4511 4536
4512 void RenderFrameImpl::UpdateEncoding(WebFrame* frame, 4537 void RenderFrameImpl::UpdateEncoding(WebFrame* frame,
4513 const std::string& encoding_name) { 4538 const std::string& encoding_name) {
4514 // Only update main frame's encoding_name. 4539 // Only update main frame's encoding_name.
4515 if (!frame->parent()) 4540 if (!frame->parent())
4516 Send(new FrameHostMsg_UpdateEncoding(routing_id_, encoding_name)); 4541 Send(new FrameHostMsg_UpdateEncoding(routing_id_, encoding_name));
4517 } 4542 }
(...skipping 398 matching lines...) Expand 10 before | Expand all | Expand 10 after
4916 #elif defined(ENABLE_BROWSER_CDMS) 4941 #elif defined(ENABLE_BROWSER_CDMS)
4917 cdm_manager_, 4942 cdm_manager_,
4918 #endif 4943 #endif
4919 this); 4944 this);
4920 } 4945 }
4921 4946
4922 return cdm_factory_; 4947 return cdm_factory_;
4923 } 4948 }
4924 4949
4925 } // namespace content 4950 } // namespace content
OLDNEW
« content/renderer/history_controller.cc ('K') | « content/renderer/render_frame_impl.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698