Commit dc263a44 authored by petewil's avatar petewil Committed by Commit bot

If you reload an offline page while online, load the online version.

If you have an offline page showing, but connectivity has returned, when
you pull down on the page to refresh, we should reload the online version.

This change catches the onPageLoadStarted event to check for that case.
The onLoadUrl event does not get called on a reload, and the onUpdateUrl
event is also not called on a reload, so onPageLoadStarted is likely
our best candidate.

BUG=565529

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

Cr-Commit-Position: refs/heads/master@{#371572}
parent 5a35917b
...@@ -70,6 +70,11 @@ public class OfflinePageTabObserver extends EmptyTabObserver { ...@@ -70,6 +70,11 @@ public class OfflinePageTabObserver extends EmptyTabObserver {
// TODO(petewil): In case any snackbars are showing, dismiss them before we switch tabs. // TODO(petewil): In case any snackbars are showing, dismiss them before we switch tabs.
} }
@Override
public void onPageLoadStarted(Tab tab, String newUrl) {
OfflinePageUtils.preferOnlineVersion(mActivity, tab, newUrl);
}
@Override @Override
public void onDestroyed(Tab destroyedTab) { public void onDestroyed(Tab destroyedTab) {
// Unregister this tab for OS connectivity notifications. // Unregister this tab for OS connectivity notifications.
......
...@@ -192,6 +192,18 @@ public class OfflinePageUtils { ...@@ -192,6 +192,18 @@ public class OfflinePageUtils {
context, bridge, bridge.getPageByOnlineURL(onlineUrl), onlineUrl); context, bridge, bridge.getPageByOnlineURL(onlineUrl), onlineUrl);
} }
/**
* Whenever we reload an offline page, if we are online, load the online version of the page
* instead, on the theory that the user prefers the online version of the page.
*/
public static void preferOnlineVersion(ChromeActivity activity, Tab tab, String newUrl) {
// If we are reloading an offline page, but are online, get the online version.
if (newUrl.equals(tab.getUrl()) && isConnected(activity.getBaseContext())) {
Log.i(TAG, "Refreshing to the online version of an offline page, since we are online");
tab.loadUrl(new LoadUrlParams(tab.getOfflinePageOriginalUrl(), PageTransition.RELOAD));
}
}
/** /**
* Shows the snackbar for the current tab to provide offline specific information if needed. * Shows the snackbar for the current tab to provide offline specific information if needed.
* @param activity The activity owning the tab. * @param activity The activity owning the tab.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment