Index: chrome/android/java/src/org/chromium/chrome/browser/offlinepages/OfflinePageUtils.java |
diff --git a/chrome/android/java/src/org/chromium/chrome/browser/offlinepages/OfflinePageUtils.java b/chrome/android/java/src/org/chromium/chrome/browser/offlinepages/OfflinePageUtils.java |
index c5e4dd7919b8d84e6b832dda3d203b05b4a6cdc7..a7ab9fa216ba50df287c092da932bf254a057a83 100644 |
--- a/chrome/android/java/src/org/chromium/chrome/browser/offlinepages/OfflinePageUtils.java |
+++ b/chrome/android/java/src/org/chromium/chrome/browser/offlinepages/OfflinePageUtils.java |
@@ -71,6 +71,26 @@ public class OfflinePageUtils { |
} |
/** |
+ * Returns the offline URL corresponding to the given online URL if it is available and the |
+ * network is not connected, otherwise returns the given online URL. If an offline URL is |
+ * returned, it is also marked as accessed. |
+ * @param context Context associated with the activity. |
+ * @param bridge The OfflinePageBridge. |
+ * @param onlineUrl The online URL in question. |
+ */ |
+ public static String getOfflineUrlIfNecessary( |
+ Context context, OfflinePageBridge bridge, String onlineUrl) { |
+ if (OfflinePageBridge.isEnabled() && bridge != null && !isConnected(context)) { |
+ OfflinePageItem offlineItem = bridge.getPageByOnlineURL(onlineUrl); |
+ if (offlineItem != null) { |
+ bridge.markPageAccessed(offlineItem.getBookmarkId()); |
+ return offlineItem.getOfflineUrl(); |
+ } |
+ } |
+ return onlineUrl; |
+ } |
+ |
+ /** |
* Shows the snackbar for the current tab to provide offline specific information if needed. |
* @param activity The activity owning the tab. |
* @param tab The current tab. |