Skip to content

Commit

Permalink
Use the same reload policy of the failed request in NetErrorHelper's …
Browse files Browse the repository at this point in the history
…auto-reload.

When the user does a hard refresh (ctrl+ shift + r) and a network error happens,
NetErrorHelper tries to auto-reload the page. But NetErrorHelper::ReloadPage()
doesn't care about the |ignoreCache| flag. So the reloaded page will be the
result of normal reload.

This cl introduces was_ignoring_cache flag to ErrorPageInfo and set the
|ignoreCache| flag if the cache policy of the failed first reload request was
ReloadBypassingCache which is set in FrameLoader::resourceRequestForReload().

BUG=489051

Review URL: https://codereview.chromium.org/1414603009

Cr-Commit-Position: refs/heads/master@{#359010}
  • Loading branch information
horo-t authored and Commit bot committed Nov 11, 2015
1 parent bf58fa0 commit e6daac4
Show file tree
Hide file tree
Showing 6 changed files with 242 additions and 164 deletions.
9 changes: 6 additions & 3 deletions chrome/renderer/chrome_content_renderer_client.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1106,9 +1106,12 @@ void ChromeContentRendererClient::GetNavigationErrorStrings(

bool is_post = base::EqualsASCII(
base::StringPiece16(failed_request.httpMethod()), "POST");

if (error_html)
NetErrorHelper::Get(render_frame)->GetErrorHTML(error, is_post, error_html);
bool is_ignoring_cache = failed_request.cachePolicy() ==
blink::WebURLRequest::ReloadBypassingCache;
if (error_html) {
NetErrorHelper::Get(render_frame)
->GetErrorHTML(error, is_post, is_ignoring_cache, error_html);
}

if (error_description)
*error_description = LocalizedError::GetErrorDetails(error, is_post);
Expand Down
14 changes: 7 additions & 7 deletions chrome/renderer/net/net_error_helper.cc
Original file line number Diff line number Diff line change
Expand Up @@ -155,12 +155,12 @@ void NetErrorHelper::NetworkStateChanged(bool enabled) {
core_->NetworkStateChanged(enabled);
}

void NetErrorHelper::GetErrorHTML(
const blink::WebURLError& error,
bool is_failed_post,
std::string* error_html) {
void NetErrorHelper::GetErrorHTML(const blink::WebURLError& error,
bool is_failed_post,
bool is_ignoring_cache,
std::string* error_html) {
core_->GetErrorHTML(GetFrameType(render_frame()), error, is_failed_post,
error_html);
is_ignoring_cache, error_html);
}

bool NetErrorHelper::ShouldSuppressErrorPage(const GURL& url) {
Expand Down Expand Up @@ -289,8 +289,8 @@ void NetErrorHelper::SendTrackingRequest(
base::Unretained(this)));
}

void NetErrorHelper::ReloadPage() {
render_frame()->GetWebFrame()->reload(false);
void NetErrorHelper::ReloadPage(bool ignore_cache) {
render_frame()->GetWebFrame()->reload(ignore_cache);
}

void NetErrorHelper::LoadPageFromCache(const GURL& page_url) {
Expand Down
3 changes: 2 additions & 1 deletion chrome/renderer/net/net_error_helper.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ class NetErrorHelper
// loaded immediately.
void GetErrorHTML(const blink::WebURLError& error,
bool is_failed_post,
bool is_ignoring_cache,
std::string* error_html);

// Returns whether a load for |url| in the |frame| the NetErrorHelper is
Expand Down Expand Up @@ -98,7 +99,7 @@ class NetErrorHelper
void CancelFetchNavigationCorrections() override;
void SendTrackingRequest(const GURL& tracking_url,
const std::string& tracking_request_body) override;
void ReloadPage() override;
void ReloadPage(bool ignore_cache) override;
void LoadPageFromCache(const GURL& page_url) override;
void DiagnoseError(const GURL& page_url) override;

Expand Down
37 changes: 21 additions & 16 deletions components/error_page/renderer/net_error_helper_core.cc
Original file line number Diff line number Diff line change
Expand Up @@ -369,21 +369,24 @@ void ReportAutoReloadFailure(const blink::WebURLError& error, size_t count) {
} // namespace

struct NetErrorHelperCore::ErrorPageInfo {
ErrorPageInfo(blink::WebURLError error, bool was_failed_post)
ErrorPageInfo(blink::WebURLError error,
bool was_failed_post,
bool was_ignoring_cache)
: error(error),
was_failed_post(was_failed_post),
was_ignoring_cache(was_ignoring_cache),
needs_dns_updates(false),
needs_load_navigation_corrections(false),
reload_button_in_page(false),
show_saved_copy_button_in_page(false),
show_cached_copy_button_in_page(false),
is_finished_loading(false),
auto_reload_triggered(false) {
}
auto_reload_triggered(false) {}

// Information about the failed page load.
blink::WebURLError error;
bool was_failed_post;
bool was_ignoring_cache;

// Information about the status of the error page.

Expand Down Expand Up @@ -623,18 +626,19 @@ void NetErrorHelperCore::OnFinishLoad(FrameType frame_type) {
UpdateErrorPage();
}

void NetErrorHelperCore::GetErrorHTML(
FrameType frame_type,
const blink::WebURLError& error,
bool is_failed_post,
std::string* error_html) {
void NetErrorHelperCore::GetErrorHTML(FrameType frame_type,
const blink::WebURLError& error,
bool is_failed_post,
bool is_ignoring_cache,
std::string* error_html) {
if (frame_type == MAIN_FRAME) {
// If navigation corrections were needed before, that should have been
// cancelled earlier by starting a new page load (Which has now failed).
DCHECK(!committed_error_page_info_ ||
!committed_error_page_info_->needs_load_navigation_corrections);

pending_error_page_info_.reset(new ErrorPageInfo(error, is_failed_post));
pending_error_page_info_.reset(
new ErrorPageInfo(error, is_failed_post, is_ignoring_cache));
pending_error_page_info_->navigation_correction_params.reset(
new NavigationCorrectionParams(navigation_correction_params_));
GetErrorHtmlForMainFrame(pending_error_page_info_.get(), error_html);
Expand Down Expand Up @@ -753,9 +757,10 @@ void NetErrorHelperCore::OnNavigationCorrectionsFetched(
DCHECK(committed_error_page_info_->needs_load_navigation_corrections);
DCHECK(committed_error_page_info_->navigation_correction_params);

pending_error_page_info_.reset(
new ErrorPageInfo(committed_error_page_info_->error,
committed_error_page_info_->was_failed_post));
pending_error_page_info_.reset(new ErrorPageInfo(
committed_error_page_info_->error,
committed_error_page_info_->was_failed_post,
committed_error_page_info_->was_ignoring_cache));
pending_error_page_info_->navigation_correction_response =
ParseNavigationCorrectionResponse(corrections);

Expand Down Expand Up @@ -811,11 +816,11 @@ blink::WebURLError NetErrorHelperCore::GetUpdatedError(
return updated_error;
}

void NetErrorHelperCore::Reload() {
void NetErrorHelperCore::Reload(bool ignore_cache) {
if (!committed_error_page_info_) {
return;
}
delegate_->ReloadPage();
delegate_->ReloadPage(ignore_cache);
}

bool NetErrorHelperCore::MaybeStartAutoReloadTimer() {
Expand Down Expand Up @@ -859,7 +864,7 @@ void NetErrorHelperCore::AutoReloadTimerFired() {

auto_reload_count_++;
auto_reload_in_flight_ = true;
Reload();
Reload(committed_error_page_info_->was_ignoring_cache);
}

void NetErrorHelperCore::PauseAutoReloadTimer() {
Expand Down Expand Up @@ -918,7 +923,7 @@ void NetErrorHelperCore::ExecuteButtonPress(Button button) {
RecordEvent(NETWORK_ERROR_PAGE_BOTH_BUTTONS_RELOAD_CLICKED);
}
navigation_from_button_ = RELOAD_BUTTON;
Reload();
Reload(false);
return;
case SHOW_SAVED_COPY_BUTTON:
RecordEvent(NETWORK_ERROR_PAGE_SHOW_SAVED_COPY_BUTTON_CLICKED);
Expand Down
5 changes: 3 additions & 2 deletions components/error_page/renderer/net_error_helper_core.h
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ class NetErrorHelperCore {
const std::string& tracking_request_body) = 0;

// Starts a reload of the page in the observed frame.
virtual void ReloadPage() = 0;
virtual void ReloadPage(bool ignore_cache) = 0;

// Load the original page from cache.
virtual void LoadPageFromCache(const GURL& page_url) = 0;
Expand Down Expand Up @@ -137,6 +137,7 @@ class NetErrorHelperCore {
void GetErrorHTML(FrameType frame_type,
const blink::WebURLError& error,
bool is_failed_post,
bool is_ignoring_cache,
std::string* error_html);

// These methods handle tracking the actual state of the page.
Expand Down Expand Up @@ -217,7 +218,7 @@ class NetErrorHelperCore {

blink::WebURLError GetUpdatedError(const blink::WebURLError& error) const;

void Reload();
void Reload(bool ignore_cache);
bool MaybeStartAutoReloadTimer();
void StartAutoReloadTimer();
void AutoReloadTimerFired();
Expand Down
Loading

0 comments on commit e6daac4

Please sign in to comment.