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

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

Issue 1227823010: Handle empty error pages in DidFinishDocumentLoad (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: +test and comment in didFinishDocumentLoad Created 5 years, 5 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 2655 matching lines...) Expand 10 before | Expand all | Expand 10 after
2666 InternalDocumentStateData* internal_data = 2666 InternalDocumentStateData* internal_data =
2667 InternalDocumentStateData::FromDocumentState(document_state); 2667 InternalDocumentStateData::FromDocumentState(document_state);
2668 2668
2669 if (document_state->commit_load_time().is_null()) 2669 if (document_state->commit_load_time().is_null())
2670 document_state->set_commit_load_time(Time::Now()); 2670 document_state->set_commit_load_time(Time::Now());
2671 2671
2672 if (internal_data->must_reset_scroll_and_scale_state()) { 2672 if (internal_data->must_reset_scroll_and_scale_state()) {
2673 render_view_->webview()->resetScrollAndScaleState(); 2673 render_view_->webview()->resetScrollAndScaleState();
2674 internal_data->set_must_reset_scroll_and_scale_state(false); 2674 internal_data->set_must_reset_scroll_and_scale_state(false);
2675 } 2675 }
2676 internal_data->set_use_error_page(false);
2677 2676
2678 bool is_new_navigation = commit_type == blink::WebStandardCommit; 2677 bool is_new_navigation = commit_type == blink::WebStandardCommit;
2679 if (is_new_navigation) { 2678 if (is_new_navigation) {
2680 // We bump our Page ID to correspond with the new session history entry. 2679 // We bump our Page ID to correspond with the new session history entry.
2681 render_view_->page_id_ = render_view_->next_page_id_++; 2680 render_view_->page_id_ = render_view_->next_page_id_++;
2682 2681
2683 // Don't update history list values for kSwappedOutURL, since 2682 // Don't update history list values for kSwappedOutURL, since
2684 // we don't want to forget the entry that was there, and since we will 2683 // we don't want to forget the entry that was there, and since we will
2685 // never come back to kSwappedOutURL. Note that we have to call 2684 // never come back to kSwappedOutURL. Note that we have to call
2686 // UpdateSessionHistory and update page_id_ even in this case, so that 2685 // UpdateSessionHistory and update page_id_ even in this case, so that
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after
2828 UpdateEncoding(frame, frame->view()->pageEncoding().utf8()); 2827 UpdateEncoding(frame, frame->view()->pageEncoding().utf8());
2829 } 2828 }
2830 2829
2831 void RenderFrameImpl::didChangeIcon(blink::WebLocalFrame* frame, 2830 void RenderFrameImpl::didChangeIcon(blink::WebLocalFrame* frame,
2832 blink::WebIconURL::Type icon_type) { 2831 blink::WebIconURL::Type icon_type) {
2833 DCHECK(!frame_ || frame_ == frame); 2832 DCHECK(!frame_ || frame_ == frame);
2834 // TODO(nasko): Investigate wheather implementation should move here. 2833 // TODO(nasko): Investigate wheather implementation should move here.
2835 render_view_->didChangeIcon(frame, icon_type); 2834 render_view_->didChangeIcon(frame, icon_type);
2836 } 2835 }
2837 2836
2838 void RenderFrameImpl::didFinishDocumentLoad(blink::WebLocalFrame* frame) { 2837 void RenderFrameImpl::didFinishDocumentLoad(blink::WebLocalFrame* frame,
2838 bool document_is_empty) {
2839 TRACE_EVENT1("navigation", "RenderFrameImpl::didFinishDocumentLoad", 2839 TRACE_EVENT1("navigation", "RenderFrameImpl::didFinishDocumentLoad",
2840 "id", routing_id_); 2840 "id", routing_id_);
2841 DCHECK(!frame_ || frame_ == frame); 2841 DCHECK(!frame_ || frame_ == frame);
2842 WebDataSource* ds = frame->dataSource(); 2842 WebDataSource* ds = frame->dataSource();
2843 DocumentState* document_state = DocumentState::FromDataSource(ds); 2843 DocumentState* document_state = DocumentState::FromDataSource(ds);
2844 document_state->set_finish_document_load_time(Time::Now()); 2844 document_state->set_finish_document_load_time(Time::Now());
2845 2845
2846 Send(new FrameHostMsg_DidFinishDocumentLoad(routing_id_)); 2846 Send(new FrameHostMsg_DidFinishDocumentLoad(routing_id_));
2847 2847
2848 FOR_EACH_OBSERVER(RenderViewObserver, render_view_->observers(), 2848 FOR_EACH_OBSERVER(RenderViewObserver, render_view_->observers(),
2849 DidFinishDocumentLoad(frame)); 2849 DidFinishDocumentLoad(frame));
2850 FOR_EACH_OBSERVER(RenderFrameObserver, observers_, DidFinishDocumentLoad()); 2850 FOR_EACH_OBSERVER(RenderFrameObserver, observers_, DidFinishDocumentLoad());
2851 2851
2852 // Check whether we have new encoding name. 2852 // Check whether we have new encoding name.
2853 UpdateEncoding(frame, frame->view()->pageEncoding().utf8()); 2853 UpdateEncoding(frame, frame->view()->pageEncoding().utf8());
2854
2855 // If this is an empty document with an http status code indicating an error,
2856 // we may want to displaying our own error page, so the user doesn't end up
Charlie Reis 2015/07/13 20:42:43 s/displaying/display/
Nate Chapin 2015/07/14 18:46:23 Done.
2857 // with an unexplained blank page.
2858 if (!document_is_empty)
2859 return;
2860
2861 // Do not show error page when DevTools is attached.
2862 RenderFrameImpl* localRoot = this;
2863 while (localRoot->frame_ && localRoot->frame_->parent() &&
2864 localRoot->frame_->parent()->isWebLocalFrame()) {
2865 localRoot = RenderFrameImpl::FromWebFrame(localRoot->frame_->parent());
2866 DCHECK(localRoot);
2867 }
2868 if (localRoot->devtools_agent_ && localRoot->devtools_agent_->IsAttached())
2869 return;
2870
2871 // Display error page, if appropriate.
Charlie Reis 2015/07/13 20:42:43 nit: Display an error page instead of a blank page
Nate Chapin 2015/07/14 18:46:23 Done.
2872 std::string error_domain = "http";
2873 InternalDocumentStateData* internal_data =
2874 InternalDocumentStateData::FromDataSource(frame->dataSource());
2875 int http_status_code = internal_data->http_status_code();
2876 if (GetContentClient()->renderer()->HasErrorPage(http_status_code,
2877 &error_domain)) {
2878 WebURLError error;
2879 error.unreachableURL = frame->document().url();
2880 error.domain = WebString::fromUTF8(error_domain);
2881 error.reason = http_status_code;
2882 LoadNavigationErrorPage(frame->dataSource()->request(), error, true);
2883 }
2854 } 2884 }
2855 2885
2856 void RenderFrameImpl::didHandleOnloadEvents(blink::WebLocalFrame* frame) { 2886 void RenderFrameImpl::didHandleOnloadEvents(blink::WebLocalFrame* frame) {
2857 DCHECK(!frame_ || frame_ == frame); 2887 DCHECK(!frame_ || frame_ == frame);
2858 if (!frame->parent()) { 2888 if (!frame->parent()) {
2859 FrameMsg_UILoadMetricsReportType::Value report_type = 2889 FrameMsg_UILoadMetricsReportType::Value report_type =
2860 static_cast<FrameMsg_UILoadMetricsReportType::Value>( 2890 static_cast<FrameMsg_UILoadMetricsReportType::Value>(
2861 frame->dataSource()->request().inputPerfMetricReportPolicy()); 2891 frame->dataSource()->request().inputPerfMetricReportPolicy());
2862 base::TimeTicks ui_timestamp = base::TimeTicks() + 2892 base::TimeTicks ui_timestamp = base::TimeTicks() +
2863 base::TimeDelta::FromSecondsD( 2893 base::TimeDelta::FromSecondsD(
(...skipping 482 matching lines...) Expand 10 before | Expand all | Expand 10 after
3346 document_state->set_connection_info( 3376 document_state->set_connection_info(
3347 extra_data->connection_info()); 3377 extra_data->connection_info());
3348 document_state->set_was_fetched_via_proxy( 3378 document_state->set_was_fetched_via_proxy(
3349 extra_data->was_fetched_via_proxy()); 3379 extra_data->was_fetched_via_proxy());
3350 document_state->set_proxy_server( 3380 document_state->set_proxy_server(
3351 extra_data->proxy_server()); 3381 extra_data->proxy_server());
3352 } 3382 }
3353 InternalDocumentStateData* internal_data = 3383 InternalDocumentStateData* internal_data =
3354 InternalDocumentStateData::FromDocumentState(document_state); 3384 InternalDocumentStateData::FromDocumentState(document_state);
3355 internal_data->set_http_status_code(http_status_code); 3385 internal_data->set_http_status_code(http_status_code);
3356 // Whether or not the http status code actually corresponds to an error is
3357 // only checked when the page is done loading, if |use_error_page| is
3358 // still true.
3359 internal_data->set_use_error_page(true);
3360 }
3361
3362 void RenderFrameImpl::didFinishResourceLoad(blink::WebLocalFrame* frame,
3363 unsigned identifier) {
3364 DCHECK(!frame_ || frame_ == frame);
3365 InternalDocumentStateData* internal_data =
3366 InternalDocumentStateData::FromDataSource(frame->dataSource());
3367 if (!internal_data->use_error_page())
3368 return;
3369
3370 // Do not show error page when DevTools is attached.
3371 RenderFrameImpl* localRoot = this;
3372 while (localRoot->frame_ && localRoot->frame_->parent() &&
3373 localRoot->frame_->parent()->isWebLocalFrame()) {
3374 localRoot = RenderFrameImpl::FromWebFrame(localRoot->frame_->parent());
3375 DCHECK(localRoot);
3376 }
3377 if (localRoot->devtools_agent_ && localRoot->devtools_agent_->IsAttached())
3378 return;
3379
3380 // Display error page, if appropriate.
3381 std::string error_domain = "http";
3382 int http_status_code = internal_data->http_status_code();
3383 if (GetContentClient()->renderer()->HasErrorPage(
3384 http_status_code, &error_domain)) {
3385 WebURLError error;
3386 error.unreachableURL = frame->document().url();
3387 error.domain = WebString::fromUTF8(error_domain);
3388 error.reason = http_status_code;
3389 LoadNavigationErrorPage(frame->dataSource()->request(), error, true);
3390 }
3391 } 3386 }
3392 3387
3393 void RenderFrameImpl::didLoadResourceFromMemoryCache( 3388 void RenderFrameImpl::didLoadResourceFromMemoryCache(
3394 blink::WebLocalFrame* frame, 3389 blink::WebLocalFrame* frame,
3395 const blink::WebURLRequest& request, 3390 const blink::WebURLRequest& request,
3396 const blink::WebURLResponse& response) { 3391 const blink::WebURLResponse& response) {
3397 DCHECK(!frame_ || frame_ == frame); 3392 DCHECK(!frame_ || frame_ == frame);
3398 // The recipients of this message have no use for data: URLs: they don't 3393 // The recipients of this message have no use for data: URLs: they don't
3399 // affect the page's insecure content list and are not in the disk cache. To 3394 // affect the page's insecure content list and are not in the disk cache. To
3400 // prevent large (1M+) data: URLs from crashing in the IPC system, we simply 3395 // prevent large (1M+) data: URLs from crashing in the IPC system, we simply
(...skipping 1655 matching lines...) Expand 10 before | Expand all | Expand 10 after
5056 void RenderFrameImpl::RegisterMojoServices() { 5051 void RenderFrameImpl::RegisterMojoServices() {
5057 // Only main frame have ImageDownloader service. 5052 // Only main frame have ImageDownloader service.
5058 if (!frame_->parent()) { 5053 if (!frame_->parent()) {
5059 GetServiceRegistry()->AddService<image_downloader::ImageDownloader>( 5054 GetServiceRegistry()->AddService<image_downloader::ImageDownloader>(
5060 base::Bind(&ImageDownloaderImpl::CreateMojoService, 5055 base::Bind(&ImageDownloaderImpl::CreateMojoService,
5061 base::Unretained(this))); 5056 base::Unretained(this)));
5062 } 5057 }
5063 } 5058 }
5064 5059
5065 } // namespace content 5060 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698