Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 4354 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 4365 if (is_reload && !render_view_->history_controller()->GetCurrentEntry()) { | 4365 if (is_reload && !render_view_->history_controller()->GetCurrentEntry()) { |
| 4366 // We cannot reload if we do not have any history state. This happens, for | 4366 // We cannot reload if we do not have any history state. This happens, for |
| 4367 // example, when recovering from a crash. | 4367 // example, when recovering from a crash. |
| 4368 is_reload = false; | 4368 is_reload = false; |
| 4369 cache_policy = WebURLRequest::ReloadIgnoringCacheData; | 4369 cache_policy = WebURLRequest::ReloadIgnoringCacheData; |
| 4370 } | 4370 } |
| 4371 | 4371 |
| 4372 pending_navigation_params_.reset( | 4372 pending_navigation_params_.reset( |
| 4373 new NavigationParams(common_params, start_params, request_params)); | 4373 new NavigationParams(common_params, start_params, request_params)); |
| 4374 | 4374 |
| 4375 // If we are reloading, then Blink will use the history state of the current | 4375 // Create parameters for a standard navigation. |
| 4376 // page, so we should just ignore any given history state. Otherwise, if we | 4376 blink::WebFrameLoadType load_type = blink::Standard; |
| 4377 // have history state, then we need to navigate to it, which corresponds to a | 4377 WebHistoryItem item_for_history_navigation; |
| 4378 // back/forward navigation event. | 4378 WebURLRequest request = CreateURLRequestForNavigation( |
| 4379 if (is_reload && !browser_side_navigation) { | 4379 common_params, stream_params.Pass(), frame_->isViewSourceModeEnabled()); |
| 4380 // TODO(clamy): adapt this code for PlzNavigate. In particular the stream | 4380 |
| 4381 // override should be given to the generated request. | 4381 // PlzNavigate: Make sure that Blink's loader will not try to use browser side |
| 4382 bool reload_original_url = | 4382 // navigation for this request (since it already went to the browser). |
| 4383 (common_params.navigation_type == | 4383 if (browser_side_navigation) |
| 4384 FrameMsg_Navigate_Type::RELOAD_ORIGINAL_REQUEST_URL); | 4384 request.setCheckForBrowserSideNavigation(false); |
| 4385 | |
| 4386 // If we are reloading, then use the history state of the current frame. | |
| 4387 // Otherwise, if we have history state, then we need to navigate to it, which | |
| 4388 // corresponds to a back/forward navigation event. Update the parameters | |
| 4389 // depending on the navigation type. | |
| 4390 if (is_reload) { | |
| 4385 bool ignore_cache = (common_params.navigation_type == | 4391 bool ignore_cache = (common_params.navigation_type == |
| 4386 FrameMsg_Navigate_Type::RELOAD_IGNORING_CACHE); | 4392 FrameMsg_Navigate_Type::RELOAD_IGNORING_CACHE); |
| 4393 load_type = ignore_cache ? blink::ReloadFromOrigin : blink::Reload; | |
| 4387 | 4394 |
| 4388 if (reload_original_url) | 4395 if (!browser_side_navigation) { |
| 4389 frame_->reloadWithOverrideURL(common_params.url, true); | 4396 const GURL override_url = |
| 4390 else | 4397 (common_params.navigation_type == |
| 4391 frame_->reload(ignore_cache); | 4398 FrameMsg_Navigate_Type::RELOAD_ORIGINAL_REQUEST_URL) |
| 4392 } else if (is_history_navigation && !browser_side_navigation) { | 4399 ? common_params.url |
| 4393 // TODO(clamy): adapt this code for PlzNavigate. In particular the stream | 4400 : GURL(); |
| 4394 // override should be given to the generated request. | 4401 request = frame_->requestForReload(load_type, override_url); |
| 4395 | 4402 } |
| 4403 } else if (is_history_navigation) { | |
| 4396 // We must know the page ID of the page we are navigating back to. | 4404 // We must know the page ID of the page we are navigating back to. |
| 4397 DCHECK_NE(request_params.page_id, -1); | 4405 DCHECK_NE(request_params.page_id, -1); |
| 4398 // We must know the nav entry ID of the page we are navigating back to, | 4406 // We must know the nav entry ID of the page we are navigating back to, |
| 4399 // which should be the case because history navigations are routed via the | 4407 // which should be the case because history navigations are routed via the |
| 4400 // browser. | 4408 // browser. |
| 4401 DCHECK_NE(0, request_params.nav_entry_id); | 4409 DCHECK_NE(0, request_params.nav_entry_id); |
| 4402 scoped_ptr<HistoryEntry> entry = | 4410 scoped_ptr<HistoryEntry> entry = |
| 4403 PageStateToHistoryEntry(request_params.page_state); | 4411 PageStateToHistoryEntry(request_params.page_state); |
| 4404 if (entry) { | 4412 if (!entry) { |
| 4405 // Ensure we didn't save the swapped out URL in UpdateState, since the | 4413 Send(new FrameHostMsg_DidDropNavigation(routing_id_)); |
|
Charlie Reis
2015/06/02 05:41:42
This method doesn't feel like it handles early ret
clamy
2015/06/02 13:30:13
I've tried to do something with a boolean and if/e
| |
| 4406 // browser should never be telling us to navigate to swappedout://. | 4414 pending_navigation_params_.reset(); |
| 4407 CHECK(entry->root().urlString() != WebString::fromUTF8(kSwappedOutURL)); | 4415 return; |
| 4416 } | |
| 4417 | |
| 4418 // Ensure we didn't save the swapped out URL in UpdateState, since the | |
| 4419 // browser should never be telling us to navigate to swappedout://. | |
| 4420 CHECK(entry->root().urlString() != WebString::fromUTF8(kSwappedOutURL)); | |
| 4421 | |
| 4422 if (!browser_side_navigation) { | |
| 4408 scoped_ptr<NavigationParams> navigation_params( | 4423 scoped_ptr<NavigationParams> navigation_params( |
| 4409 new NavigationParams(*pending_navigation_params_.get())); | 4424 new NavigationParams(*pending_navigation_params_.get())); |
| 4410 render_view_->history_controller()->GoToEntry( | 4425 render_view_->history_controller()->GoToEntry( |
| 4411 entry.Pass(), navigation_params.Pass(), cache_policy); | 4426 entry.Pass(), navigation_params.Pass(), cache_policy); |
| 4427 pending_navigation_params_.reset(); | |
| 4428 return; | |
| 4412 } | 4429 } |
| 4413 } else if (!common_params.base_url_for_data_url.is_empty() || | 4430 |
| 4414 (browser_side_navigation && | 4431 // TODO(clamy): this should be set to the HistoryItem sent by the browser |
| 4415 common_params.url.SchemeIs(url::kDataScheme))) { | 4432 // once the HistoryController has moved to the browser. |
| 4416 LoadDataURL(common_params, frame_); | 4433 // TODO(clamy): distinguish between different document and same document |
| 4434 // loads. | |
| 4435 // TODO(clamy): update this for subframes history loads. | |
| 4436 item_for_history_navigation = entry->GetHistoryNodeForFrame(this)->item(); | |
| 4437 load_type = blink::BackForward; | |
|
Charlie Reis
2015/06/02 05:41:42
Worth noting that this won't fully work today (pro
clamy
2015/06/02 13:30:13
Acknowledged. I'm waiting for the HistoryControlle
| |
| 4417 } else { | 4438 } else { |
| 4418 // Navigate to the given URL. | 4439 // Navigate to the given URL. |
| 4419 WebURLRequest request = CreateURLRequestForNavigation( | |
| 4420 common_params, stream_params.Pass(), frame_->isViewSourceModeEnabled()); | |
| 4421 | |
| 4422 if (!start_params.extra_headers.empty() && !browser_side_navigation) { | 4440 if (!start_params.extra_headers.empty() && !browser_side_navigation) { |
| 4423 for (net::HttpUtil::HeadersIterator i(start_params.extra_headers.begin(), | 4441 for (net::HttpUtil::HeadersIterator i(start_params.extra_headers.begin(), |
| 4424 start_params.extra_headers.end(), | 4442 start_params.extra_headers.end(), |
| 4425 "\n"); | 4443 "\n"); |
| 4426 i.GetNext();) { | 4444 i.GetNext();) { |
| 4427 request.addHTTPHeaderField(WebString::fromUTF8(i.name()), | 4445 request.addHTTPHeaderField(WebString::fromUTF8(i.name()), |
| 4428 WebString::fromUTF8(i.values())); | 4446 WebString::fromUTF8(i.values())); |
| 4429 } | 4447 } |
| 4430 } | 4448 } |
| 4431 | 4449 |
| 4432 if (start_params.is_post && !browser_side_navigation) { | 4450 if (start_params.is_post && !browser_side_navigation) { |
| 4433 request.setHTTPMethod(WebString::fromUTF8("POST")); | 4451 request.setHTTPMethod(WebString::fromUTF8("POST")); |
| 4434 | 4452 |
| 4435 // Set post data. | 4453 // Set post data. |
| 4436 WebHTTPBody http_body; | 4454 WebHTTPBody http_body; |
| 4437 http_body.initialize(); | 4455 http_body.initialize(); |
| 4438 const char* data = nullptr; | 4456 const char* data = nullptr; |
| 4439 if (start_params.browser_initiated_post_data.size()) { | 4457 if (start_params.browser_initiated_post_data.size()) { |
| 4440 data = reinterpret_cast<const char*>( | 4458 data = reinterpret_cast<const char*>( |
| 4441 &start_params.browser_initiated_post_data.front()); | 4459 &start_params.browser_initiated_post_data.front()); |
| 4442 } | 4460 } |
| 4443 http_body.appendData( | 4461 http_body.appendData( |
| 4444 WebData(data, start_params.browser_initiated_post_data.size())); | 4462 WebData(data, start_params.browser_initiated_post_data.size())); |
| 4445 request.setHTTPBody(http_body); | 4463 request.setHTTPBody(http_body); |
| 4446 } | 4464 } |
| 4447 | 4465 |
| 4448 // A session history navigation should have been accompanied by state. | 4466 // A session history navigation should have been accompanied by state. |
| 4449 CHECK_EQ(request_params.page_id, -1); | 4467 CHECK_EQ(request_params.page_id, -1); |
| 4450 | 4468 |
| 4451 // PlzNavigate: Make sure that Blink's loader will not try to use browser | |
| 4452 // side navigation for this request (since it already went to the browser). | |
| 4453 if (browser_side_navigation) | |
| 4454 request.setCheckForBrowserSideNavigation(false); | |
| 4455 | |
| 4456 // Record this before starting the load. We need a lower bound of this time | 4469 // Record this before starting the load. We need a lower bound of this time |
| 4457 // to sanitize the navigationStart override set below. | 4470 // to sanitize the navigationStart override set below. |
| 4458 base::TimeTicks renderer_navigation_start = base::TimeTicks::Now(); | 4471 base::TimeTicks renderer_navigation_start = base::TimeTicks::Now(); |
| 4459 frame_->loadRequest(request); | |
| 4460 | |
| 4461 UpdateFrameNavigationTiming(frame_, request_params.browser_navigation_start, | 4472 UpdateFrameNavigationTiming(frame_, request_params.browser_navigation_start, |
| 4462 renderer_navigation_start); | 4473 renderer_navigation_start); |
| 4463 } | 4474 } |
| 4464 | 4475 |
| 4476 // Perform a navigation to a data url if needed. | |
| 4477 if (!common_params.base_url_for_data_url.is_empty() || | |
| 4478 (browser_side_navigation && | |
| 4479 common_params.url.SchemeIs(url::kDataScheme))) { | |
| 4480 LoadDataURL(common_params, frame_); | |
| 4481 pending_navigation_params_.reset(); | |
| 4482 return; | |
| 4483 } | |
| 4484 | |
| 4485 // Load the request. | |
| 4486 frame_->loadRequest(request, load_type, item_for_history_navigation); | |
| 4487 | |
| 4465 // In case LoadRequest failed before didCreateDataSource was called. | 4488 // In case LoadRequest failed before didCreateDataSource was called. |
| 4466 pending_navigation_params_.reset(); | 4489 pending_navigation_params_.reset(); |
| 4467 } | 4490 } |
| 4468 | 4491 |
| 4469 void RenderFrameImpl::UpdateEncoding(WebFrame* frame, | 4492 void RenderFrameImpl::UpdateEncoding(WebFrame* frame, |
| 4470 const std::string& encoding_name) { | 4493 const std::string& encoding_name) { |
| 4471 // Only update main frame's encoding_name. | 4494 // Only update main frame's encoding_name. |
| 4472 if (!frame->parent()) | 4495 if (!frame->parent()) |
| 4473 Send(new FrameHostMsg_UpdateEncoding(routing_id_, encoding_name)); | 4496 Send(new FrameHostMsg_UpdateEncoding(routing_id_, encoding_name)); |
| 4474 } | 4497 } |
| (...skipping 402 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 4877 #elif defined(ENABLE_BROWSER_CDMS) | 4900 #elif defined(ENABLE_BROWSER_CDMS) |
| 4878 cdm_manager_, | 4901 cdm_manager_, |
| 4879 #endif | 4902 #endif |
| 4880 this); | 4903 this); |
| 4881 } | 4904 } |
| 4882 | 4905 |
| 4883 return cdm_factory_; | 4906 return cdm_factory_; |
| 4884 } | 4907 } |
| 4885 | 4908 |
| 4886 } // namespace content | 4909 } // namespace content |
| OLD | NEW |