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

Side by Side Diff: chrome/renderer/render_view.cc

Issue 6546069: Only display Link Doctor page on 404 errors with no body (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Remove all postponed data code Created 9 years, 10 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 "chrome/renderer/render_view.h" 5 #include "chrome/renderer/render_view.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <cmath> 8 #include <cmath>
9 #include <string> 9 #include <string>
10 #include <vector> 10 #include <vector>
(...skipping 3366 matching lines...) Expand 10 before | Expand all | Expand 10 after
3377 3377
3378 // Fallback to a local error page. 3378 // Fallback to a local error page.
3379 LoadNavigationErrorPage(frame, failed_request, error, std::string(), replace); 3379 LoadNavigationErrorPage(frame, failed_request, error, std::string(), replace);
3380 } 3380 }
3381 3381
3382 void RenderView::didReceiveDocumentData( 3382 void RenderView::didReceiveDocumentData(
3383 WebFrame* frame, const char* data, size_t data_len, 3383 WebFrame* frame, const char* data, size_t data_len,
3384 bool& prevent_default) { 3384 bool& prevent_default) {
3385 NavigationState* navigation_state = 3385 NavigationState* navigation_state =
3386 NavigationState::FromDataSource(frame->dataSource()); 3386 NavigationState::FromDataSource(frame->dataSource());
3387 if (!navigation_state->postpone_loading_data()) 3387 navigation_state->set_maybe_use_error_page(false);
3388 return;
3389
3390 // We're going to call commitDocumentData ourselves...
3391 prevent_default = true;
3392
3393 // Continue buffering the response data for the original error page. If it
3394 // grows too large, then we'll just let it through. For any error other than
3395 // a 404, "too large" means any data at all.
3396 navigation_state->append_postponed_data(data, data_len);
3397 if (navigation_state->postponed_data().size() >= 512 ||
3398 navigation_state->http_status_code() != 404) {
3399 navigation_state->set_postpone_loading_data(false);
3400 frame->commitDocumentData(navigation_state->postponed_data().data(),
3401 navigation_state->postponed_data().size());
3402 navigation_state->clear_postponed_data();
3403 }
3404 } 3388 }
3405 3389
3406 void RenderView::didCommitProvisionalLoad(WebFrame* frame, 3390 void RenderView::didCommitProvisionalLoad(WebFrame* frame,
3407 bool is_new_navigation) { 3391 bool is_new_navigation) {
3408 NavigationState* navigation_state = 3392 NavigationState* navigation_state =
3409 NavigationState::FromDataSource(frame->dataSource()); 3393 NavigationState::FromDataSource(frame->dataSource());
3410 3394
3411 navigation_state->set_commit_load_time(Time::Now()); 3395 navigation_state->set_commit_load_time(Time::Now());
3412 if (is_new_navigation) { 3396 if (is_new_navigation) {
3413 // When we perform a new navigation, we need to update the last committed 3397 // When we perform a new navigation, we need to update the last committed
(...skipping 270 matching lines...) Expand 10 before | Expand all | Expand 10 after
3684 CHECK(navigation_state); 3668 CHECK(navigation_state);
3685 int http_status_code = response.httpStatusCode(); 3669 int http_status_code = response.httpStatusCode();
3686 3670
3687 // Record page load flags. 3671 // Record page load flags.
3688 navigation_state->set_was_fetched_via_spdy(response.wasFetchedViaSPDY()); 3672 navigation_state->set_was_fetched_via_spdy(response.wasFetchedViaSPDY());
3689 navigation_state->set_was_npn_negotiated(response.wasNpnNegotiated()); 3673 navigation_state->set_was_npn_negotiated(response.wasNpnNegotiated());
3690 navigation_state->set_was_alternate_protocol_available( 3674 navigation_state->set_was_alternate_protocol_available(
3691 response.wasAlternateProtocolAvailable()); 3675 response.wasAlternateProtocolAvailable());
3692 navigation_state->set_was_fetched_via_proxy(response.wasFetchedViaProxy()); 3676 navigation_state->set_was_fetched_via_proxy(response.wasFetchedViaProxy());
3693 navigation_state->set_http_status_code(http_status_code); 3677 navigation_state->set_http_status_code(http_status_code);
3694 3678 // Whether or not the http status code actually corresponds to an error is
3695 // Consider loading an alternate error page for 404 responses. 3679 // only checked when the page is done loading, if |maybe_use_error_page| is
3696 if (http_status_code == 404) { 3680 // still true.
3697 // Can we even load an alternate error page for this URL? 3681 navigation_state->set_maybe_use_error_page(true);
3698 if (!GetAlternateErrorPageURL(response.url(), HTTP_404).is_valid())
3699 return;
3700 } else if (!LocalizedError::HasStrings(LocalizedError::kHttpErrorDomain,
3701 http_status_code)) {
3702 // If no corresponding error strings for a particular status code, just
3703 // render any received data, regardless of whether or not the status code
3704 // indicates an error.
3705 return;
3706 }
3707
3708 navigation_state->set_postpone_loading_data(true);
3709 navigation_state->clear_postponed_data();
3710 } 3682 }
3711 3683
3712 void RenderView::didFinishResourceLoad( 3684 void RenderView::didFinishResourceLoad(
3713 WebFrame* frame, unsigned identifier) { 3685 WebFrame* frame, unsigned identifier) {
3714 NavigationState* navigation_state = 3686 NavigationState* navigation_state =
3715 NavigationState::FromDataSource(frame->dataSource()); 3687 NavigationState::FromDataSource(frame->dataSource());
3716 if (!navigation_state->postpone_loading_data()) 3688 if (!navigation_state->maybe_use_error_page())
3717 return; 3689 return;
3718 3690
3719 // The server returned an error and the content was < 512 bytes (which we 3691 // Display error page, if appropriate.
3720 // suppressed). Go ahead and fetch the alternate page content.
3721 int http_status_code = navigation_state->http_status_code(); 3692 int http_status_code = navigation_state->http_status_code();
3722 if (http_status_code == 404) { 3693 if (http_status_code == 404) {
3723 // On 404s, try a remote search page as a fallback. 3694 // On 404s, try a remote search page as a fallback.
3724 const GURL& frame_url = frame->url(); 3695 const GURL& frame_url = frame->url();
3725 3696
3726 const GURL& error_page_url = GetAlternateErrorPageURL(frame_url, HTTP_404); 3697 const GURL& error_page_url = GetAlternateErrorPageURL(frame_url, HTTP_404);
3727 DCHECK(error_page_url.is_valid()); 3698 if (error_page_url.is_valid()) {
tony 2011/02/23 21:43:20 When will this be invalid? Should we at least kee
mmenke 2011/02/23 21:53:36 It's an empty string (And thus invalid) when chrom
3699 WebURLError original_error;
3700 original_error.unreachableURL = frame_url;
3728 3701
3729 WebURLError original_error; 3702 navigation_state->set_alt_error_page_fetcher(
3730 original_error.unreachableURL = frame_url; 3703 new AltErrorPageResourceFetcher(
3704 error_page_url, frame, original_error,
3705 NewCallback(this, &RenderView::AltErrorPageFinished)));
3706 return;
3707 }
3708 }
3731 3709
3732 navigation_state->set_alt_error_page_fetcher( 3710 // Use an internal error page, if we have one for the status code.
3733 new AltErrorPageResourceFetcher( 3711 if (LocalizedError::HasStrings(LocalizedError::kHttpErrorDomain,
3734 error_page_url, frame, original_error, 3712 http_status_code)) {
tony 2011/02/23 21:43:20 Do we have a test for some of the other http statu
mmenke 2011/02/23 21:53:36 No, we don't. They only trigger on responses with
3735 NewCallback(this, &RenderView::AltErrorPageFinished)));
3736 } else {
3737 // On other errors, use an internal error page.
3738 WebURLError error; 3713 WebURLError error;
3739 error.unreachableURL = frame->url(); 3714 error.unreachableURL = frame->url();
3740 error.domain = WebString::fromUTF8(LocalizedError::kHttpErrorDomain); 3715 error.domain = WebString::fromUTF8(LocalizedError::kHttpErrorDomain);
3741 error.reason = http_status_code; 3716 error.reason = http_status_code;
3742 3717
3743 LoadNavigationErrorPage(frame, frame->dataSource()->request(), error, 3718 LoadNavigationErrorPage(frame, frame->dataSource()->request(), error,
3744 std::string(), true); 3719 std::string(), true);
3745 } 3720 }
3746 } 3721 }
3747 3722
(...skipping 1310 matching lines...) Expand 10 before | Expand all | Expand 10 after
5058 5033
5059 // "t" is the id of the templates root node. 5034 // "t" is the id of the templates root node.
5060 return jstemplate_builder::GetTemplatesHtml( 5035 return jstemplate_builder::GetTemplatesHtml(
5061 template_html, &error_strings, "t"); 5036 template_html, &error_strings, "t");
5062 } 5037 }
5063 5038
5064 void RenderView::AltErrorPageFinished(WebFrame* frame, 5039 void RenderView::AltErrorPageFinished(WebFrame* frame,
5065 const WebURLError& original_error, 5040 const WebURLError& original_error,
5066 const std::string& html) { 5041 const std::string& html) {
5067 // Here, we replace the blank page we loaded previously. 5042 // Here, we replace the blank page we loaded previously.
5068 5043 // If we failed to download the alternate error page, LoadNavigationErrorPage
5069 // If we failed to download the alternate error page, fall back to the
5070 // original error page if present. Otherwise, LoadNavigationErrorPage
5071 // will simply display a default error page. 5044 // will simply display a default error page.
5072 const std::string* html_to_load = &html; 5045 LoadNavigationErrorPage(frame, WebURLRequest(), original_error, html, true);
5073 if (html.empty()) {
5074 NavigationState* navigation_state =
5075 NavigationState::FromDataSource(frame->dataSource());
5076 html_to_load = &navigation_state->postponed_data();
5077 }
5078 LoadNavigationErrorPage(frame, WebURLRequest(), original_error, *html_to_load,
5079 true);
5080 } 5046 }
5081 5047
5082 void RenderView::OnMoveOrResizeStarted() { 5048 void RenderView::OnMoveOrResizeStarted() {
5083 if (webview()) 5049 if (webview())
5084 webview()->hidePopups(); 5050 webview()->hidePopups();
5085 } 5051 }
5086 5052
5087 void RenderView::OnResize(const gfx::Size& new_size, 5053 void RenderView::OnResize(const gfx::Size& new_size,
5088 const gfx::Rect& resizer_rect) { 5054 const gfx::Rect& resizer_rect) {
5089 if (webview()) { 5055 if (webview()) {
(...skipping 617 matching lines...) Expand 10 before | Expand all | Expand 10 after
5707 } 5673 }
5708 } 5674 }
5709 5675
5710 void RenderView::OnContextMenuClosed( 5676 void RenderView::OnContextMenuClosed(
5711 const webkit_glue::CustomContextMenuContext& custom_context) { 5677 const webkit_glue::CustomContextMenuContext& custom_context) {
5712 if (custom_context.is_pepper_menu) 5678 if (custom_context.is_pepper_menu)
5713 pepper_delegate_.OnContextMenuClosed(custom_context); 5679 pepper_delegate_.OnContextMenuClosed(custom_context);
5714 else 5680 else
5715 context_menu_node_.reset(); 5681 context_menu_node_.reset();
5716 } 5682 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698