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

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: Fixed compilation error 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 1027 matching lines...) Expand 10 before | Expand all | Expand 10 after
1038 IPC_MESSAGE_HANDLER(FrameMsg_Reload, OnReload) 1038 IPC_MESSAGE_HANDLER(FrameMsg_Reload, OnReload)
1039 IPC_MESSAGE_HANDLER(FrameMsg_TextSurroundingSelectionRequest, 1039 IPC_MESSAGE_HANDLER(FrameMsg_TextSurroundingSelectionRequest,
1040 OnTextSurroundingSelectionRequest) 1040 OnTextSurroundingSelectionRequest)
1041 IPC_MESSAGE_HANDLER(FrameMsg_AddStyleSheetByURL, 1041 IPC_MESSAGE_HANDLER(FrameMsg_AddStyleSheetByURL,
1042 OnAddStyleSheetByURL) 1042 OnAddStyleSheetByURL)
1043 IPC_MESSAGE_HANDLER(FrameMsg_SetAccessibilityMode, 1043 IPC_MESSAGE_HANDLER(FrameMsg_SetAccessibilityMode,
1044 OnSetAccessibilityMode) 1044 OnSetAccessibilityMode)
1045 IPC_MESSAGE_HANDLER(FrameMsg_DisownOpener, OnDisownOpener) 1045 IPC_MESSAGE_HANDLER(FrameMsg_DisownOpener, OnDisownOpener)
1046 IPC_MESSAGE_HANDLER(FrameMsg_CommitNavigation, OnCommitNavigation) 1046 IPC_MESSAGE_HANDLER(FrameMsg_CommitNavigation, OnCommitNavigation)
1047 IPC_MESSAGE_HANDLER(FrameMsg_DidUpdateSandboxFlags, OnDidUpdateSandboxFlags) 1047 IPC_MESSAGE_HANDLER(FrameMsg_DidUpdateSandboxFlags, OnDidUpdateSandboxFlags)
1048 IPC_MESSAGE_HANDLER(FrameMsg_FailedNavigation, OnFailedNavigation)
1048 #if defined(OS_ANDROID) 1049 #if defined(OS_ANDROID)
1049 IPC_MESSAGE_HANDLER(FrameMsg_SelectPopupMenuItems, OnSelectPopupMenuItems) 1050 IPC_MESSAGE_HANDLER(FrameMsg_SelectPopupMenuItems, OnSelectPopupMenuItems)
1050 #elif defined(OS_MACOSX) 1051 #elif defined(OS_MACOSX)
1051 IPC_MESSAGE_HANDLER(FrameMsg_SelectPopupMenuItem, OnSelectPopupMenuItem) 1052 IPC_MESSAGE_HANDLER(FrameMsg_SelectPopupMenuItem, OnSelectPopupMenuItem)
1052 IPC_MESSAGE_HANDLER(InputMsg_CopyToFindPboard, OnCopyToFindPboard) 1053 IPC_MESSAGE_HANDLER(InputMsg_CopyToFindPboard, OnCopyToFindPboard)
1053 #endif 1054 #endif
1054 IPC_END_MESSAGE_MAP() 1055 IPC_END_MESSAGE_MAP()
1055 1056
1056 return handled; 1057 return handled;
1057 } 1058 }
(...skipping 1433 matching lines...) Expand 10 before | Expand all | Expand 10 after
2491 // 2492 //
2492 // Note: It is important this notification occur before DidStopLoading so the 2493 // Note: It is important this notification occur before DidStopLoading so the
2493 // SSL manager can react to the provisional load failure before being 2494 // SSL manager can react to the provisional load failure before being
2494 // notified the load stopped. 2495 // notified the load stopped.
2495 // 2496 //
2496 FOR_EACH_OBSERVER(RenderViewObserver, render_view_->observers(), 2497 FOR_EACH_OBSERVER(RenderViewObserver, render_view_->observers(),
2497 DidFailProvisionalLoad(frame, error)); 2498 DidFailProvisionalLoad(frame, error));
2498 FOR_EACH_OBSERVER(RenderFrameObserver, observers_, 2499 FOR_EACH_OBSERVER(RenderFrameObserver, observers_,
2499 DidFailProvisionalLoad(error)); 2500 DidFailProvisionalLoad(error));
2500 2501
2501 bool show_repost_interstitial = 2502 SendFailedProvisionalLoad(failed_request, error, frame);
2502 (error.reason == net::ERR_CACHE_MISS &&
2503 EqualsASCII(failed_request.httpMethod(), "POST"));
2504 2503
2505 FrameHostMsg_DidFailProvisionalLoadWithError_Params params; 2504 if (!ShouldDisplayErrorPageForFailedLoad(error.reason, error.unreachableURL))
2506 params.error_code = error.reason;
2507 GetContentClient()->renderer()->GetNavigationErrorStrings(
2508 render_view_.get(),
2509 frame,
2510 failed_request,
2511 error,
2512 NULL,
2513 &params.error_description);
2514 params.url = error.unreachableURL;
2515 params.showing_repost_interstitial = show_repost_interstitial;
2516 Send(new FrameHostMsg_DidFailProvisionalLoadWithError(
2517 routing_id_, params));
2518
2519 // Don't display an error page if this is simply a cancelled load. Aside
2520 // from being dumb, WebCore doesn't expect it and it will cause a crash.
2521 if (error.reason == net::ERR_ABORTED)
2522 return; 2505 return;
2523 2506
2524 // Don't display "client blocked" error page if browser has asked us not to.
2525 if (error.reason == net::ERR_BLOCKED_BY_CLIENT &&
2526 render_view_->renderer_preferences_.disable_client_blocked_error_page) {
2527 return;
2528 }
2529
2530 // Allow the embedder to suppress an error page.
2531 if (GetContentClient()->renderer()->ShouldSuppressErrorPage(this,
2532 error.unreachableURL)) {
2533 return;
2534 }
2535
2536 if (RenderThreadImpl::current() &&
2537 RenderThreadImpl::current()->layout_test_mode()) {
2538 return;
2539 }
2540
2541 // Make sure we never show errors in view source mode. 2507 // Make sure we never show errors in view source mode.
2542 frame->enableViewSourceMode(false); 2508 frame->enableViewSourceMode(false);
2543 2509
2544 DocumentState* document_state = DocumentState::FromDataSource(ds); 2510 DocumentState* document_state = DocumentState::FromDataSource(ds);
2545 NavigationStateImpl* navigation_state = 2511 NavigationStateImpl* navigation_state =
2546 static_cast<NavigationStateImpl*>(document_state->navigation_state()); 2512 static_cast<NavigationStateImpl*>(document_state->navigation_state());
2547 2513
2548 // If this is a failed back/forward/reload navigation, then we need to do a 2514 // If this is a failed back/forward/reload navigation, then we need to do a
2549 // 'replace' load. This is necessary to avoid messing up session history. 2515 // 'replace' load. This is necessary to avoid messing up session history.
2550 // Otherwise, we do a normal load, which simulates a 'go' navigation as far 2516 // Otherwise, we do a normal load, which simulates a 'go' navigation as far
(...skipping 1527 matching lines...) Expand 10 before | Expand all | Expand 10 after
4078 request.setCheckForBrowserSideNavigation(false); 4044 request.setCheckForBrowserSideNavigation(false);
4079 4045
4080 // Record this before starting the load. A lower bound of this time is needed 4046 // Record this before starting the load. A lower bound of this time is needed
4081 // to sanitize the navigationStart override set below. 4047 // to sanitize the navigationStart override set below.
4082 base::TimeTicks renderer_navigation_start = base::TimeTicks::Now(); 4048 base::TimeTicks renderer_navigation_start = base::TimeTicks::Now();
4083 frame_->loadRequest(request); 4049 frame_->loadRequest(request);
4084 UpdateFrameNavigationTiming(frame_, request_params.browser_navigation_start, 4050 UpdateFrameNavigationTiming(frame_, request_params.browser_navigation_start,
4085 renderer_navigation_start); 4051 renderer_navigation_start);
4086 } 4052 }
4087 4053
4054 void RenderFrameImpl::OnFailedNavigation(
4055 const CommonNavigationParams& common_params,
4056 const RequestNavigationParams& request_params,
4057 bool has_stale_copy_in_cache,
4058 int error_code) {
4059 bool is_reload = false;
4060 bool is_history_navigation = request_params.page_state.IsValid();
4061 WebURLRequest::CachePolicy cache_policy =
4062 WebURLRequest::UseProtocolCachePolicy;
4063 if (!RenderFrameImpl::PrepareRenderViewForNavigation(
4064 common_params.url, is_history_navigation, request_params, &is_reload,
4065 &cache_policy)) {
4066 return;
4067 }
4068
4069 GetContentClient()->SetActiveURL(common_params.url);
4070
4071 pending_navigation_params_.reset(new NavigationParams(
4072 common_params, StartNavigationParams(), request_params));
4073
4074 // Inform the browser of the start of the provisional load. This is needed so
4075 // that the load is properly tracked by the WebNavigation API.
4076 // TODO(clamy): Properly set is_transition_navigation.
4077 Send(new FrameHostMsg_DidStartProvisionalLoadForFrame(
4078 routing_id_, common_params.url, false));
4079
4080 // Send the provisional load failure.
4081 blink::WebURLError error =
4082 CreateWebURLError(common_params.url, has_stale_copy_in_cache, error_code);
4083 WebURLRequest failed_request = CreateURLRequestForNavigation(
4084 common_params, scoped_ptr<StreamOverrideParameters>(),
4085 frame_->isViewSourceModeEnabled());
4086 SendFailedProvisionalLoad(failed_request, error, frame_);
4087
4088 if (!ShouldDisplayErrorPageForFailedLoad(error_code, common_params.url))
4089 return;
4090
4091 // Make sure errors are not shown in view source mode.
4092 frame_->enableViewSourceMode(false);
4093
4094 bool replace =
4095 request_params.page_id != -1 ||
4096 ui::PageTransitionCoreTypeIs(common_params.transition,
4097 ui::PAGE_TRANSITION_AUTO_SUBFRAME);
Avi (use Gerrit) 2015/04/01 16:45:42 This definition of replace is wrong when we use it
clamy 2015/04/02 08:21:10 Then can we just use should_replace_current_entry
Avi (use Gerrit) 2015/04/02 15:05:23 should_replace_current_entry is a browser-side fla
clamy 2015/04/08 12:53:49 Thanks! I've tried to emulate what blink::WebStand
Avi (use Gerrit) 2015/04/08 14:12:12 Can you manually test? Type aslkdfjalskdjflasdkjf
4098 LoadNavigationErrorPage(failed_request, error, replace);
4099 }
4100
4088 WebNavigationPolicy RenderFrameImpl::DecidePolicyForNavigation( 4101 WebNavigationPolicy RenderFrameImpl::DecidePolicyForNavigation(
4089 RenderFrame* render_frame, 4102 RenderFrame* render_frame,
4090 const NavigationPolicyInfo& info) { 4103 const NavigationPolicyInfo& info) {
4091 #ifdef OS_ANDROID 4104 #ifdef OS_ANDROID
4092 // The handlenavigation API is deprecated and will be removed once 4105 // The handlenavigation API is deprecated and will be removed once
4093 // crbug.com/325351 is resolved. 4106 // crbug.com/325351 is resolved.
4094 if (info.urlRequest.url() != GURL(kSwappedOutURL) && 4107 if (info.urlRequest.url() != GURL(kSwappedOutURL) &&
4095 GetContentClient()->renderer()->HandleNavigation( 4108 GetContentClient()->renderer()->HandleNavigation(
4096 render_frame, 4109 render_frame,
4097 static_cast<DocumentState*>(info.extraData), 4110 static_cast<DocumentState*>(info.extraData),
(...skipping 477 matching lines...) Expand 10 before | Expand all | Expand 10 after
4575 WebString::fromUTF8(charset), 4588 WebString::fromUTF8(charset),
4576 base_url, 4589 base_url,
4577 params.history_url_for_data_url, 4590 params.history_url_for_data_url,
4578 false); 4591 false);
4579 } else { 4592 } else {
4580 CHECK(false) << "Invalid URL passed: " 4593 CHECK(false) << "Invalid URL passed: "
4581 << params.url.possibly_invalid_spec(); 4594 << params.url.possibly_invalid_spec();
4582 } 4595 }
4583 } 4596 }
4584 4597
4598 void RenderFrameImpl::SendFailedProvisionalLoad(
4599 const blink::WebURLRequest& request,
4600 const blink::WebURLError& error,
4601 blink::WebLocalFrame* frame) {
4602 bool show_repost_interstitial = (error.reason == net::ERR_CACHE_MISS &&
4603 EqualsASCII(request.httpMethod(), "POST"));
4604
4605 FrameHostMsg_DidFailProvisionalLoadWithError_Params params;
4606 params.error_code = error.reason;
4607 GetContentClient()->renderer()->GetNavigationErrorStrings(
4608 render_view_.get(), frame, request, error, NULL,
4609 &params.error_description);
4610 params.url = error.unreachableURL;
4611 params.showing_repost_interstitial = show_repost_interstitial;
4612 Send(new FrameHostMsg_DidFailProvisionalLoadWithError(routing_id_, params));
4613 }
4614
4615 bool RenderFrameImpl::ShouldDisplayErrorPageForFailedLoad(
4616 int error_code,
4617 const GURL& unreachable_url) {
4618 // Don't display an error page if this is simply a cancelled load. Aside
4619 // from being dumb, WebCore doesn't expect it and it will cause a crash.
Avi (use Gerrit) 2015/04/01 16:45:41 Blink
clamy 2015/04/08 12:53:49 Done.
4620 if (error_code == net::ERR_ABORTED)
4621 return false;
4622
4623 // Don't display "client blocked" error page if browser has asked us not to.
4624 if (error_code == net::ERR_BLOCKED_BY_CLIENT &&
4625 render_view_->renderer_preferences_.disable_client_blocked_error_page) {
4626 return false;
4627 }
4628
4629 // Allow the embedder to suppress an error page.
4630 if (GetContentClient()->renderer()->ShouldSuppressErrorPage(
4631 this, unreachable_url)) {
4632 return false;
4633 }
4634
4635 if (RenderThreadImpl::current() &&
4636 RenderThreadImpl::current()->layout_test_mode()) {
4637 return false;
4638 }
4639
4640 return true;
4641 }
4642
4585 GURL RenderFrameImpl::GetLoadingUrl() const { 4643 GURL RenderFrameImpl::GetLoadingUrl() const {
4586 WebDataSource* ds = frame_->dataSource(); 4644 WebDataSource* ds = frame_->dataSource();
4587 if (ds->hasUnreachableURL()) 4645 if (ds->hasUnreachableURL())
4588 return ds->unreachableURL(); 4646 return ds->unreachableURL();
4589 4647
4590 const WebURLRequest& request = ds->request(); 4648 const WebURLRequest& request = ds->request();
4591 return request.url(); 4649 return request.url();
4592 } 4650 }
4593 4651
4594 void RenderFrameImpl::PopulateDocumentStateFromPending( 4652 void RenderFrameImpl::PopulateDocumentStateFromPending(
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
4639 // initiated any load resulting from JS execution. 4697 // initiated any load resulting from JS execution.
4640 if (!pending_navigation_params_->common_params.url.SchemeIs( 4698 if (!pending_navigation_params_->common_params.url.SchemeIs(
4641 url::kJavaScriptScheme)) { 4699 url::kJavaScriptScheme)) {
4642 return NavigationStateImpl::CreateBrowserInitiated( 4700 return NavigationStateImpl::CreateBrowserInitiated(
4643 pending_navigation_params_->common_params, 4701 pending_navigation_params_->common_params,
4644 pending_navigation_params_->start_params, 4702 pending_navigation_params_->start_params,
4645 pending_navigation_params_->request_params); 4703 pending_navigation_params_->request_params);
4646 } 4704 }
4647 return NavigationStateImpl::CreateContentInitiated(); 4705 return NavigationStateImpl::CreateContentInitiated();
4648 } 4706 }
4707
4649 #if defined(OS_ANDROID) 4708 #if defined(OS_ANDROID)
4650 4709
4651 WebMediaPlayer* RenderFrameImpl::CreateAndroidWebMediaPlayer( 4710 WebMediaPlayer* RenderFrameImpl::CreateAndroidWebMediaPlayer(
4652 const blink::WebURL& url, 4711 const blink::WebURL& url,
4653 WebMediaPlayerClient* client, 4712 WebMediaPlayerClient* client,
4654 media::MediaPermission* media_permission, 4713 media::MediaPermission* media_permission,
4655 blink::WebContentDecryptionModule* initial_cdm) { 4714 blink::WebContentDecryptionModule* initial_cdm) {
4656 GpuChannelHost* gpu_channel_host = 4715 GpuChannelHost* gpu_channel_host =
4657 RenderThreadImpl::current()->EstablishGpuChannelSync( 4716 RenderThreadImpl::current()->EstablishGpuChannelSync(
4658 CAUSE_FOR_GPU_LAUNCH_VIDEODECODEACCELERATOR_INITIALIZE); 4717 CAUSE_FOR_GPU_LAUNCH_VIDEODECODEACCELERATOR_INITIALIZE);
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
4701 4760
4702 #if defined(ENABLE_BROWSER_CDMS) 4761 #if defined(ENABLE_BROWSER_CDMS)
4703 RendererCdmManager* RenderFrameImpl::GetCdmManager() { 4762 RendererCdmManager* RenderFrameImpl::GetCdmManager() {
4704 if (!cdm_manager_) 4763 if (!cdm_manager_)
4705 cdm_manager_ = new RendererCdmManager(this); 4764 cdm_manager_ = new RendererCdmManager(this);
4706 return cdm_manager_; 4765 return cdm_manager_;
4707 } 4766 }
4708 #endif // defined(ENABLE_BROWSER_CDMS) 4767 #endif // defined(ENABLE_BROWSER_CDMS)
4709 4768
4710 } // namespace content 4769 } // 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