Skip to content

Commit

Permalink
One of the outstanding TODO items from our fix to redirect navigation…
Browse files Browse the repository at this point in the history
…s to

offline pages was to switch from the provisional load events to use the
newer navigation events.

This change switches to the new events, and adds a working test.

BUG=591150

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

Cr-Commit-Position: refs/heads/master@{#379725}
(cherry picked from commit 2ec1dfe)

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

Cr-Commit-Position: refs/branch-heads/2661@{crosswalk-project#363}
Cr-Branched-From: ef6f6ae-refs/heads/master@{#378081}
  • Loading branch information
Pete Williamson committed Mar 23, 2016
1 parent 9c48e88 commit 00ff65b
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 20 deletions.
16 changes: 6 additions & 10 deletions chrome/browser/android/offline_pages/offline_page_tab_helper.cc
Original file line number Diff line number Diff line change
Expand Up @@ -61,18 +61,14 @@ void OfflinePageTabHelper::DidStartNavigation(
online_url));
}

void OfflinePageTabHelper::DidFailProvisionalLoad(
content::RenderFrameHost* render_frame_host,
const GURL& validated_url,
int error_code,
const base::string16& error_description,
bool was_ignored_by_handler) {
void OfflinePageTabHelper::DidFinishNavigation(
content::NavigationHandle* navigation_handle) {
GURL last_redirect_from_url_copy = last_redirect_from_url_;
last_redirect_from_url_ = GURL();

// Skips non-main frame or load failure other than no network.
if (error_code != net::ERR_INTERNET_DISCONNECTED ||
render_frame_host->GetParent() != nullptr) {
if (navigation_handle->GetNetErrorCode() != net::ERR_INTERNET_DISCONNECTED ||
!navigation_handle->IsInMainFrame()) {
return;
}

Expand All @@ -83,14 +79,14 @@ void OfflinePageTabHelper::DidFailProvisionalLoad(

// Skips if not loading an online version of saved page.
GURL offline_url = offline_pages::OfflinePageUtils::GetOfflineURLForOnlineURL(
web_contents()->GetBrowserContext(), validated_url);
web_contents()->GetBrowserContext(), navigation_handle->GetURL());
if (!offline_url.is_valid())
return;

// Avoids looping between online and offline redirections.
if (last_redirect_from_url_copy == offline_url)
return;
last_redirect_from_url_ = validated_url;
last_redirect_from_url_ = navigation_handle->GetURL();

base::ThreadTaskRunnerHandle::Get()->PostTask(
FROM_HERE,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,8 @@ class OfflinePageTabHelper :
// Overridden from content::WebContentsObserver:
void DidStartNavigation(
content::NavigationHandle* navigation_handle) override;
void DidFailProvisionalLoad(
content::RenderFrameHost* render_frame_host,
const GURL& validated_url,
int error_code,
const base::string16& error_description,
bool was_ignored_by_handler) override;
void DidFinishNavigation(
content::NavigationHandle* navigation_handle) override;

void RedirectFromOfflineToOnline(const GURL& online_url);
void RedirectFromOnlineToOffline(const GURL& offline_url);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,13 +133,17 @@ void OfflinePageTabHelperTest::StartLoad(const GURL& url) {

void OfflinePageTabHelperTest::CommitLoad(const GURL& url) {
int entry_id = controller().GetPendingEntry()->GetUniqueID();
content::RenderFrameHostTester::For(main_rfh())->SendNavigate(
0, entry_id, true, url);
content::RenderFrameHostTester::For(main_rfh())
->SendNavigate(0, entry_id, true, url);
}

void OfflinePageTabHelperTest::FailLoad(const GURL& url) {
content::RenderFrameHostTester::For(main_rfh())->SimulateNavigationError(
url, net::ERR_INTERNET_DISCONNECTED);
content::RenderFrameHostTester::For(main_rfh())->SimulateNavigationStart(url);
// Set up the error code for the failed navigation.
content::RenderFrameHostTester::For(main_rfh())->
SimulateNavigationError(url, net::ERR_INTERNET_DISCONNECTED);
content::RenderFrameHostTester::For(main_rfh())->
SimulateNavigationErrorPageCommit();
// Gives a chance to run delayed task to do redirection.
RunUntilIdle();
}
Expand Down

0 comments on commit 00ff65b

Please sign in to comment.