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

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: Rebase 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
« no previous file with comments | « content/renderer/history_controller.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 4391 matching lines...) Expand 10 before | Expand all | Expand 10 after
4402 if (is_reload && !render_view_->history_controller()->GetCurrentEntry()) { 4402 if (is_reload && !render_view_->history_controller()->GetCurrentEntry()) {
4403 // We cannot reload if we do not have any history state. This happens, for 4403 // We cannot reload if we do not have any history state. This happens, for
4404 // example, when recovering from a crash. 4404 // example, when recovering from a crash.
4405 is_reload = false; 4405 is_reload = false;
4406 cache_policy = WebURLRequest::ReloadIgnoringCacheData; 4406 cache_policy = WebURLRequest::ReloadIgnoringCacheData;
4407 } 4407 }
4408 4408
4409 pending_navigation_params_.reset( 4409 pending_navigation_params_.reset(
4410 new NavigationParams(common_params, start_params, request_params)); 4410 new NavigationParams(common_params, start_params, request_params));
4411 4411
4412 // If we are reloading, then Blink will use the history state of the current 4412 // Create parameters for a standard navigation.
4413 // page, so we should just ignore any given history state. Otherwise, if we 4413 blink::WebFrameLoadType load_type = blink::WebFrameLoadType::Standard;
4414 // have history state, then we need to navigate to it, which corresponds to a 4414 bool should_load_request = false;
4415 // back/forward navigation event. 4415 WebHistoryItem item_for_history_navigation;
4416 if (is_reload && !browser_side_navigation) { 4416 WebURLRequest request = CreateURLRequestForNavigation(
4417 // TODO(clamy): adapt this code for PlzNavigate. In particular the stream 4417 common_params, stream_params.Pass(), frame_->isViewSourceModeEnabled());
4418 // override should be given to the generated request. 4418
4419 bool reload_original_url = 4419 // PlzNavigate: Make sure that Blink's loader will not try to use browser side
4420 (common_params.navigation_type == 4420 // navigation for this request (since it already went to the browser).
4421 FrameMsg_Navigate_Type::RELOAD_ORIGINAL_REQUEST_URL); 4421 if (browser_side_navigation)
4422 request.setCheckForBrowserSideNavigation(false);
4423
4424 // If we are reloading, then use the history state of the current frame.
4425 // Otherwise, if we have history state, then we need to navigate to it, which
4426 // corresponds to a back/forward navigation event. Update the parameters
4427 // depending on the navigation type.
4428 if (is_reload) {
4422 bool ignore_cache = (common_params.navigation_type == 4429 bool ignore_cache = (common_params.navigation_type ==
4423 FrameMsg_Navigate_Type::RELOAD_IGNORING_CACHE); 4430 FrameMsg_Navigate_Type::RELOAD_IGNORING_CACHE);
4431 load_type = ignore_cache ? blink::WebFrameLoadType::ReloadFromOrigin
4432 : blink::WebFrameLoadType::Reload;
4424 4433
4425 if (reload_original_url) 4434 if (!browser_side_navigation) {
4426 frame_->reloadWithOverrideURL(common_params.url, true); 4435 const GURL override_url =
4427 else 4436 (common_params.navigation_type ==
4428 frame_->reload(ignore_cache); 4437 FrameMsg_Navigate_Type::RELOAD_ORIGINAL_REQUEST_URL)
4429 } else if (is_history_navigation && !browser_side_navigation) { 4438 ? common_params.url
4430 // TODO(clamy): adapt this code for PlzNavigate. In particular the stream 4439 : GURL();
4431 // override should be given to the generated request. 4440 request = frame_->requestForReload(load_type, override_url);
4432 4441 }
4442 should_load_request = true;
4443 } else if (is_history_navigation) {
4433 // We must know the page ID of the page we are navigating back to. 4444 // We must know the page ID of the page we are navigating back to.
4434 DCHECK_NE(request_params.page_id, -1); 4445 DCHECK_NE(request_params.page_id, -1);
4435 // We must know the nav entry ID of the page we are navigating back to, 4446 // We must know the nav entry ID of the page we are navigating back to,
4436 // which should be the case because history navigations are routed via the 4447 // which should be the case because history navigations are routed via the
4437 // browser. 4448 // browser.
4438 DCHECK_NE(0, request_params.nav_entry_id); 4449 DCHECK_NE(0, request_params.nav_entry_id);
4439 scoped_ptr<HistoryEntry> entry = 4450 scoped_ptr<HistoryEntry> entry =
4440 PageStateToHistoryEntry(request_params.page_state); 4451 PageStateToHistoryEntry(request_params.page_state);
4441 if (entry) { 4452 if (entry) {
4442 // Ensure we didn't save the swapped out URL in UpdateState, since the 4453 // Ensure we didn't save the swapped out URL in UpdateState, since the
4443 // browser should never be telling us to navigate to swappedout://. 4454 // browser should never be telling us to navigate to swappedout://.
4444 CHECK(entry->root().urlString() != WebString::fromUTF8(kSwappedOutURL)); 4455 CHECK(entry->root().urlString() != WebString::fromUTF8(kSwappedOutURL));
4445 scoped_ptr<NavigationParams> navigation_params( 4456
4446 new NavigationParams(*pending_navigation_params_.get())); 4457 if (!browser_side_navigation) {
4447 render_view_->history_controller()->GoToEntry( 4458 scoped_ptr<NavigationParams> navigation_params(
4448 entry.Pass(), navigation_params.Pass(), cache_policy); 4459 new NavigationParams(*pending_navigation_params_.get()));
4460 render_view_->history_controller()->GoToEntry(
4461 entry.Pass(), navigation_params.Pass(), cache_policy);
4462 } else {
4463 // TODO(clamy): this should be set to the HistoryItem sent by the
4464 // browser once the HistoryController has moved to the browser.
4465 // TODO(clamy): distinguish between different document and same document
4466 // loads.
4467 // TODO(clamy): update this for subframes history loads.
4468 item_for_history_navigation =
4469 entry->GetHistoryNodeForFrame(this)->item();
4470 load_type = blink::WebFrameLoadType::BackForward;
4471 should_load_request = true;
4472 }
4449 } 4473 }
4450 } else if (!common_params.base_url_for_data_url.is_empty() ||
4451 (browser_side_navigation &&
4452 common_params.url.SchemeIs(url::kDataScheme))) {
4453 LoadDataURL(common_params, frame_);
4454 } else { 4474 } else {
4455 // Navigate to the given URL. 4475 // Navigate to the given URL.
4456 WebURLRequest request = CreateURLRequestForNavigation(
4457 common_params, stream_params.Pass(), frame_->isViewSourceModeEnabled());
4458
4459 if (!start_params.extra_headers.empty() && !browser_side_navigation) { 4476 if (!start_params.extra_headers.empty() && !browser_side_navigation) {
4460 for (net::HttpUtil::HeadersIterator i(start_params.extra_headers.begin(), 4477 for (net::HttpUtil::HeadersIterator i(start_params.extra_headers.begin(),
4461 start_params.extra_headers.end(), 4478 start_params.extra_headers.end(),
4462 "\n"); 4479 "\n");
4463 i.GetNext();) { 4480 i.GetNext();) {
4464 request.addHTTPHeaderField(WebString::fromUTF8(i.name()), 4481 request.addHTTPHeaderField(WebString::fromUTF8(i.name()),
4465 WebString::fromUTF8(i.values())); 4482 WebString::fromUTF8(i.values()));
4466 } 4483 }
4467 } 4484 }
4468 4485
4469 if (start_params.is_post && !browser_side_navigation) { 4486 if (start_params.is_post && !browser_side_navigation) {
4470 request.setHTTPMethod(WebString::fromUTF8("POST")); 4487 request.setHTTPMethod(WebString::fromUTF8("POST"));
4471 4488
4472 // Set post data. 4489 // Set post data.
4473 WebHTTPBody http_body; 4490 WebHTTPBody http_body;
4474 http_body.initialize(); 4491 http_body.initialize();
4475 const char* data = nullptr; 4492 const char* data = nullptr;
4476 if (start_params.browser_initiated_post_data.size()) { 4493 if (start_params.browser_initiated_post_data.size()) {
4477 data = reinterpret_cast<const char*>( 4494 data = reinterpret_cast<const char*>(
4478 &start_params.browser_initiated_post_data.front()); 4495 &start_params.browser_initiated_post_data.front());
4479 } 4496 }
4480 http_body.appendData( 4497 http_body.appendData(
4481 WebData(data, start_params.browser_initiated_post_data.size())); 4498 WebData(data, start_params.browser_initiated_post_data.size()));
4482 request.setHTTPBody(http_body); 4499 request.setHTTPBody(http_body);
4483 } 4500 }
4484 4501
4485 // A session history navigation should have been accompanied by state. 4502 // A session history navigation should have been accompanied by state.
4486 CHECK_EQ(request_params.page_id, -1); 4503 CHECK_EQ(request_params.page_id, -1);
4487 4504
4488 // PlzNavigate: Make sure that Blink's loader will not try to use browser 4505 should_load_request = true;
4489 // side navigation for this request (since it already went to the browser). 4506 }
4490 if (browser_side_navigation)
4491 request.setCheckForBrowserSideNavigation(false);
4492 4507
4493 // Record this before starting the load. We need a lower bound of this time 4508 if (should_load_request) {
4494 // to sanitize the navigationStart override set below. 4509 // Perform a navigation to a data url if needed.
4495 base::TimeTicks renderer_navigation_start = base::TimeTicks::Now(); 4510 if (!common_params.base_url_for_data_url.is_empty() ||
4496 frame_->loadRequest(request); 4511 (browser_side_navigation &&
4512 common_params.url.SchemeIs(url::kDataScheme))) {
4513 LoadDataURL(common_params, frame_);
4514 } else {
4515 // Record this before starting the load. We need a lower bound of this
4516 // time to sanitize the navigationStart override set below.
4517 base::TimeTicks renderer_navigation_start = base::TimeTicks::Now();
4497 4518
4498 UpdateFrameNavigationTiming(frame_, request_params.browser_navigation_start, 4519 // Load the request.
4499 renderer_navigation_start); 4520 frame_->toWebLocalFrame()->load(request, load_type,
4521 item_for_history_navigation);
4522
4523 if (load_type == blink::WebFrameLoadType::Standard) {
4524 UpdateFrameNavigationTiming(frame_,
4525 request_params.browser_navigation_start,
4526 renderer_navigation_start);
4527 }
4528 }
4500 } 4529 }
4501 4530
4502 // In case LoadRequest failed before didCreateDataSource was called. 4531 // In case LoadRequest failed before didCreateDataSource was called.
4503 pending_navigation_params_.reset(); 4532 pending_navigation_params_.reset();
4504 } 4533 }
4505 4534
4506 void RenderFrameImpl::UpdateEncoding(WebFrame* frame, 4535 void RenderFrameImpl::UpdateEncoding(WebFrame* frame,
4507 const std::string& encoding_name) { 4536 const std::string& encoding_name) {
4508 // Only update main frame's encoding_name. 4537 // Only update main frame's encoding_name.
4509 if (!frame->parent()) 4538 if (!frame->parent())
(...skipping 414 matching lines...) Expand 10 before | Expand all | Expand 10 after
4924 #elif defined(ENABLE_BROWSER_CDMS) 4953 #elif defined(ENABLE_BROWSER_CDMS)
4925 cdm_manager_, 4954 cdm_manager_,
4926 #endif 4955 #endif
4927 this); 4956 this);
4928 } 4957 }
4929 4958
4930 return cdm_factory_; 4959 return cdm_factory_;
4931 } 4960 }
4932 4961
4933 } // namespace content 4962 } // namespace content
OLDNEW
« no previous file with comments | « content/renderer/history_controller.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698