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

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

Issue 958083002: PlzNavigate: Show error pages when the navigation failed before commit (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@support-data-urls
Patch Set: Changed the way replace is computed for failed loads Created 5 years, 8 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/render_frame_impl.h ('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 1031 matching lines...) Expand 10 before | Expand all | Expand 10 after
1042 OnTextSurroundingSelectionRequest) 1042 OnTextSurroundingSelectionRequest)
1043 IPC_MESSAGE_HANDLER(FrameMsg_AddStyleSheetByURL, 1043 IPC_MESSAGE_HANDLER(FrameMsg_AddStyleSheetByURL,
1044 OnAddStyleSheetByURL) 1044 OnAddStyleSheetByURL)
1045 IPC_MESSAGE_HANDLER(FrameMsg_SetAccessibilityMode, 1045 IPC_MESSAGE_HANDLER(FrameMsg_SetAccessibilityMode,
1046 OnSetAccessibilityMode) 1046 OnSetAccessibilityMode)
1047 IPC_MESSAGE_HANDLER(FrameMsg_DisownOpener, OnDisownOpener) 1047 IPC_MESSAGE_HANDLER(FrameMsg_DisownOpener, OnDisownOpener)
1048 IPC_MESSAGE_HANDLER(FrameMsg_CommitNavigation, OnCommitNavigation) 1048 IPC_MESSAGE_HANDLER(FrameMsg_CommitNavigation, OnCommitNavigation)
1049 IPC_MESSAGE_HANDLER(FrameMsg_DidUpdateSandboxFlags, OnDidUpdateSandboxFlags) 1049 IPC_MESSAGE_HANDLER(FrameMsg_DidUpdateSandboxFlags, OnDidUpdateSandboxFlags)
1050 IPC_MESSAGE_HANDLER(FrameMsg_SetTextTrackSettings, 1050 IPC_MESSAGE_HANDLER(FrameMsg_SetTextTrackSettings,
1051 OnTextTrackSettingsChanged) 1051 OnTextTrackSettingsChanged)
1052 IPC_MESSAGE_HANDLER(FrameMsg_FailedNavigation, OnFailedNavigation)
1052 #if defined(OS_ANDROID) 1053 #if defined(OS_ANDROID)
1053 IPC_MESSAGE_HANDLER(FrameMsg_SelectPopupMenuItems, OnSelectPopupMenuItems) 1054 IPC_MESSAGE_HANDLER(FrameMsg_SelectPopupMenuItems, OnSelectPopupMenuItems)
1054 #elif defined(OS_MACOSX) 1055 #elif defined(OS_MACOSX)
1055 IPC_MESSAGE_HANDLER(FrameMsg_SelectPopupMenuItem, OnSelectPopupMenuItem) 1056 IPC_MESSAGE_HANDLER(FrameMsg_SelectPopupMenuItem, OnSelectPopupMenuItem)
1056 IPC_MESSAGE_HANDLER(InputMsg_CopyToFindPboard, OnCopyToFindPboard) 1057 IPC_MESSAGE_HANDLER(InputMsg_CopyToFindPboard, OnCopyToFindPboard)
1057 #endif 1058 #endif
1058 IPC_END_MESSAGE_MAP() 1059 IPC_END_MESSAGE_MAP()
1059 1060
1060 return handled; 1061 return handled;
1061 } 1062 }
(...skipping 1441 matching lines...) Expand 10 before | Expand all | Expand 10 after
2503 // 2504 //
2504 // Note: It is important this notification occur before DidStopLoading so the 2505 // Note: It is important this notification occur before DidStopLoading so the
2505 // SSL manager can react to the provisional load failure before being 2506 // SSL manager can react to the provisional load failure before being
2506 // notified the load stopped. 2507 // notified the load stopped.
2507 // 2508 //
2508 FOR_EACH_OBSERVER(RenderViewObserver, render_view_->observers(), 2509 FOR_EACH_OBSERVER(RenderViewObserver, render_view_->observers(),
2509 DidFailProvisionalLoad(frame, error)); 2510 DidFailProvisionalLoad(frame, error));
2510 FOR_EACH_OBSERVER(RenderFrameObserver, observers_, 2511 FOR_EACH_OBSERVER(RenderFrameObserver, observers_,
2511 DidFailProvisionalLoad(error)); 2512 DidFailProvisionalLoad(error));
2512 2513
2513 bool show_repost_interstitial = 2514 SendFailedProvisionalLoad(failed_request, error, frame);
2514 (error.reason == net::ERR_CACHE_MISS &&
2515 EqualsASCII(failed_request.httpMethod(), "POST"));
2516 2515
2517 FrameHostMsg_DidFailProvisionalLoadWithError_Params params; 2516 if (!ShouldDisplayErrorPageForFailedLoad(error.reason, error.unreachableURL))
2518 params.error_code = error.reason;
2519 GetContentClient()->renderer()->GetNavigationErrorStrings(
2520 render_view_.get(),
2521 frame,
2522 failed_request,
2523 error,
2524 NULL,
2525 &params.error_description);
2526 params.url = error.unreachableURL;
2527 params.showing_repost_interstitial = show_repost_interstitial;
2528 Send(new FrameHostMsg_DidFailProvisionalLoadWithError(
2529 routing_id_, params));
2530
2531 // Don't display an error page if this is simply a cancelled load. Aside
2532 // from being dumb, Blink doesn't expect it and it will cause a crash.
2533 if (error.reason == net::ERR_ABORTED)
2534 return; 2517 return;
2535 2518
2536 // Don't display "client blocked" error page if browser has asked us not to.
2537 if (error.reason == net::ERR_BLOCKED_BY_CLIENT &&
2538 render_view_->renderer_preferences_.disable_client_blocked_error_page) {
2539 return;
2540 }
2541
2542 // Allow the embedder to suppress an error page.
2543 if (GetContentClient()->renderer()->ShouldSuppressErrorPage(this,
2544 error.unreachableURL)) {
2545 return;
2546 }
2547
2548 if (RenderThreadImpl::current() &&
2549 RenderThreadImpl::current()->layout_test_mode()) {
2550 return;
2551 }
2552
2553 // Make sure we never show errors in view source mode. 2519 // Make sure we never show errors in view source mode.
2554 frame->enableViewSourceMode(false); 2520 frame->enableViewSourceMode(false);
2555 2521
2556 DocumentState* document_state = DocumentState::FromDataSource(ds); 2522 DocumentState* document_state = DocumentState::FromDataSource(ds);
2557 NavigationStateImpl* navigation_state = 2523 NavigationStateImpl* navigation_state =
2558 static_cast<NavigationStateImpl*>(document_state->navigation_state()); 2524 static_cast<NavigationStateImpl*>(document_state->navigation_state());
2559 2525
2560 // If this is a failed back/forward/reload navigation, then we need to do a 2526 // If this is a failed back/forward/reload navigation, then we need to do a
2561 // 'replace' load. This is necessary to avoid messing up session history. 2527 // 'replace' load. This is necessary to avoid messing up session history.
2562 // Otherwise, we do a normal load, which simulates a 'go' navigation as far 2528 // Otherwise, we do a normal load, which simulates a 'go' navigation as far
(...skipping 1498 matching lines...) Expand 10 before | Expand all | Expand 10 after
4061 request.setCheckForBrowserSideNavigation(false); 4027 request.setCheckForBrowserSideNavigation(false);
4062 4028
4063 // Record this before starting the load. A lower bound of this time is needed 4029 // Record this before starting the load. A lower bound of this time is needed
4064 // to sanitize the navigationStart override set below. 4030 // to sanitize the navigationStart override set below.
4065 base::TimeTicks renderer_navigation_start = base::TimeTicks::Now(); 4031 base::TimeTicks renderer_navigation_start = base::TimeTicks::Now();
4066 frame_->loadRequest(request); 4032 frame_->loadRequest(request);
4067 UpdateFrameNavigationTiming(frame_, request_params.browser_navigation_start, 4033 UpdateFrameNavigationTiming(frame_, request_params.browser_navigation_start,
4068 renderer_navigation_start); 4034 renderer_navigation_start);
4069 } 4035 }
4070 4036
4037 void RenderFrameImpl::OnFailedNavigation(
4038 const CommonNavigationParams& common_params,
4039 const RequestNavigationParams& request_params,
4040 bool has_stale_copy_in_cache,
4041 int error_code) {
4042 bool is_reload = IsReload(common_params.navigation_type);
4043 bool is_history_navigation = request_params.page_state.IsValid();
4044 WebURLRequest::CachePolicy cache_policy =
4045 WebURLRequest::UseProtocolCachePolicy;
4046 if (!RenderFrameImpl::PrepareRenderViewForNavigation(
4047 common_params.url, is_history_navigation, request_params, &is_reload,
4048 &cache_policy)) {
4049 return;
4050 }
4051
4052 GetContentClient()->SetActiveURL(common_params.url);
4053
4054 pending_navigation_params_.reset(new NavigationParams(
4055 common_params, StartNavigationParams(), request_params));
4056
4057 // Inform the browser of the start of the provisional load. This is needed so
4058 // that the load is properly tracked by the WebNavigation API.
4059 // TODO(clamy): Properly set is_transition_navigation.
4060 Send(new FrameHostMsg_DidStartProvisionalLoadForFrame(
4061 routing_id_, common_params.url, false));
4062
4063 // Send the provisional load failure.
4064 blink::WebURLError error =
4065 CreateWebURLError(common_params.url, has_stale_copy_in_cache, error_code);
4066 WebURLRequest failed_request = CreateURLRequestForNavigation(
4067 common_params, scoped_ptr<StreamOverrideParameters>(),
4068 frame_->isViewSourceModeEnabled());
4069 SendFailedProvisionalLoad(failed_request, error, frame_);
4070
4071 if (!ShouldDisplayErrorPageForFailedLoad(error_code, common_params.url))
4072 return;
4073
4074 // Make sure errors are not shown in view source mode.
4075 frame_->enableViewSourceMode(false);
4076
4077 // Replace the current history entry in reloads, history navigations and the
4078 // initial load in subframes. This corresponds to Blink's notion of a standard
4079 // commit.
4080 bool replace = is_reload || is_history_navigation ||
4081 (frame_->parent() && request_params.page_id == -1);
Avi (use Gerrit) 2015/04/08 14:12:13 :( Can we please not add more page id uses? I am
clamy 2015/04/08 15:02:22 It's for the case of subframes, so I'm not complet
4082 LoadNavigationErrorPage(failed_request, error, replace);
4083 }
4084
4071 WebNavigationPolicy RenderFrameImpl::DecidePolicyForNavigation( 4085 WebNavigationPolicy RenderFrameImpl::DecidePolicyForNavigation(
4072 RenderFrame* render_frame, 4086 RenderFrame* render_frame,
4073 const NavigationPolicyInfo& info) { 4087 const NavigationPolicyInfo& info) {
4074 #ifdef OS_ANDROID 4088 #ifdef OS_ANDROID
4075 // The handlenavigation API is deprecated and will be removed once 4089 // The handlenavigation API is deprecated and will be removed once
4076 // crbug.com/325351 is resolved. 4090 // crbug.com/325351 is resolved.
4077 if (info.urlRequest.url() != GURL(kSwappedOutURL) && 4091 if (info.urlRequest.url() != GURL(kSwappedOutURL) &&
4078 GetContentClient()->renderer()->HandleNavigation( 4092 GetContentClient()->renderer()->HandleNavigation(
4079 render_frame, 4093 render_frame,
4080 static_cast<DocumentState*>(info.extraData), 4094 static_cast<DocumentState*>(info.extraData),
(...skipping 477 matching lines...) Expand 10 before | Expand all | Expand 10 after
4558 WebString::fromUTF8(charset), 4572 WebString::fromUTF8(charset),
4559 base_url, 4573 base_url,
4560 params.history_url_for_data_url, 4574 params.history_url_for_data_url,
4561 false); 4575 false);
4562 } else { 4576 } else {
4563 CHECK(false) << "Invalid URL passed: " 4577 CHECK(false) << "Invalid URL passed: "
4564 << params.url.possibly_invalid_spec(); 4578 << params.url.possibly_invalid_spec();
4565 } 4579 }
4566 } 4580 }
4567 4581
4582 void RenderFrameImpl::SendFailedProvisionalLoad(
4583 const blink::WebURLRequest& request,
4584 const blink::WebURLError& error,
4585 blink::WebLocalFrame* frame) {
4586 bool show_repost_interstitial = (error.reason == net::ERR_CACHE_MISS &&
4587 EqualsASCII(request.httpMethod(), "POST"));
4588
4589 FrameHostMsg_DidFailProvisionalLoadWithError_Params params;
4590 params.error_code = error.reason;
4591 GetContentClient()->renderer()->GetNavigationErrorStrings(
4592 render_view_.get(), frame, request, error, NULL,
4593 &params.error_description);
4594 params.url = error.unreachableURL;
4595 params.showing_repost_interstitial = show_repost_interstitial;
4596 Send(new FrameHostMsg_DidFailProvisionalLoadWithError(routing_id_, params));
4597 }
4598
4599 bool RenderFrameImpl::ShouldDisplayErrorPageForFailedLoad(
4600 int error_code,
4601 const GURL& unreachable_url) {
4602 // Don't display an error page if this is simply a cancelled load. Aside
4603 // from being dumb, Blink doesn't expect it and it will cause a crash.
4604 if (error_code == net::ERR_ABORTED)
4605 return false;
4606
4607 // Don't display "client blocked" error page if browser has asked us not to.
4608 if (error_code == net::ERR_BLOCKED_BY_CLIENT &&
4609 render_view_->renderer_preferences_.disable_client_blocked_error_page) {
4610 return false;
4611 }
4612
4613 // Allow the embedder to suppress an error page.
4614 if (GetContentClient()->renderer()->ShouldSuppressErrorPage(
4615 this, unreachable_url)) {
4616 return false;
4617 }
4618
4619 if (RenderThreadImpl::current() &&
4620 RenderThreadImpl::current()->layout_test_mode()) {
4621 return false;
4622 }
4623
4624 return true;
4625 }
4626
4568 GURL RenderFrameImpl::GetLoadingUrl() const { 4627 GURL RenderFrameImpl::GetLoadingUrl() const {
4569 WebDataSource* ds = frame_->dataSource(); 4628 WebDataSource* ds = frame_->dataSource();
4570 if (ds->hasUnreachableURL()) 4629 if (ds->hasUnreachableURL())
4571 return ds->unreachableURL(); 4630 return ds->unreachableURL();
4572 4631
4573 const WebURLRequest& request = ds->request(); 4632 const WebURLRequest& request = ds->request();
4574 return request.url(); 4633 return request.url();
4575 } 4634 }
4576 4635
4577 void RenderFrameImpl::PopulateDocumentStateFromPending( 4636 void RenderFrameImpl::PopulateDocumentStateFromPending(
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
4622 // initiated any load resulting from JS execution. 4681 // initiated any load resulting from JS execution.
4623 if (!pending_navigation_params_->common_params.url.SchemeIs( 4682 if (!pending_navigation_params_->common_params.url.SchemeIs(
4624 url::kJavaScriptScheme)) { 4683 url::kJavaScriptScheme)) {
4625 return NavigationStateImpl::CreateBrowserInitiated( 4684 return NavigationStateImpl::CreateBrowserInitiated(
4626 pending_navigation_params_->common_params, 4685 pending_navigation_params_->common_params,
4627 pending_navigation_params_->start_params, 4686 pending_navigation_params_->start_params,
4628 pending_navigation_params_->request_params); 4687 pending_navigation_params_->request_params);
4629 } 4688 }
4630 return NavigationStateImpl::CreateContentInitiated(); 4689 return NavigationStateImpl::CreateContentInitiated();
4631 } 4690 }
4691
4632 #if defined(OS_ANDROID) 4692 #if defined(OS_ANDROID)
4633 4693
4634 WebMediaPlayer* RenderFrameImpl::CreateAndroidWebMediaPlayer( 4694 WebMediaPlayer* RenderFrameImpl::CreateAndroidWebMediaPlayer(
4635 const blink::WebURL& url, 4695 const blink::WebURL& url,
4636 WebMediaPlayerClient* client, 4696 WebMediaPlayerClient* client,
4637 media::MediaPermission* media_permission, 4697 media::MediaPermission* media_permission,
4638 blink::WebContentDecryptionModule* initial_cdm) { 4698 blink::WebContentDecryptionModule* initial_cdm) {
4639 GpuChannelHost* gpu_channel_host = 4699 GpuChannelHost* gpu_channel_host =
4640 RenderThreadImpl::current()->EstablishGpuChannelSync( 4700 RenderThreadImpl::current()->EstablishGpuChannelSync(
4641 CAUSE_FOR_GPU_LAUNCH_VIDEODECODEACCELERATOR_INITIALIZE); 4701 CAUSE_FOR_GPU_LAUNCH_VIDEODECODEACCELERATOR_INITIALIZE);
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
4696 #elif defined(ENABLE_BROWSER_CDMS) 4756 #elif defined(ENABLE_BROWSER_CDMS)
4697 cdm_manager_, 4757 cdm_manager_,
4698 #endif 4758 #endif
4699 this); 4759 this);
4700 } 4760 }
4701 4761
4702 return cdm_factory_; 4762 return cdm_factory_;
4703 } 4763 }
4704 4764
4705 } // namespace content 4765 } // namespace content
OLDNEW
« no previous file with comments | « content/renderer/render_frame_impl.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698