Chromium Code Reviews| 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 b3623f998fb2369049cd1a3b191a97f47b62ff39..b0ed62ed51710d6ed873a8750580672c44ee2e15 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 |
| @@ -29,6 +29,7 @@ import org.chromium.chrome.browser.snackbar.SnackbarManager.SnackbarController; |
| import org.chromium.chrome.browser.tab.Tab; |
| import org.chromium.chrome.browser.tabmodel.TabModelSelector; |
| import org.chromium.components.bookmarks.BookmarkId; |
| +import org.chromium.components.offlinepages.SavePageResult; |
| import org.chromium.content_public.browser.LoadUrlParams; |
| import org.chromium.content_public.browser.WebContents; |
| import org.chromium.net.ConnectionType; |
| @@ -276,22 +277,55 @@ public class OfflinePageUtils { |
| */ |
| public static void shareOfflinePage(final boolean shareDirectly, final Activity mainActivity, |
| final String onlineUrl, final Bitmap bitmap, final Context mContext, |
| - final Tab currentTab) { |
| + final Tab currentTab, final boolean isOnOfflinePage) { |
| final String offlineUrl = currentTab.getUrl(); |
| final String title = currentTab.getTitle(); |
| - OfflinePageBridge offlinePageBridge = |
| + final OfflinePageBridge offlinePageBridge = |
| OfflinePageBridge.getForProfile(currentTab.getProfile()); |
| + Log.d(TAG, "isOnOfflinePage?: " + isOnOfflinePage); |
| if (offlinePageBridge != null) { |
| - offlinePageBridge.getPageByOfflineUrl(offlineUrl, new Callback<OfflinePageItem>() { |
| - @Override |
| - public void onResult(OfflinePageItem item) { |
| - if (item != null) { |
| - String offlineFilePath = item.getFilePath(); |
| - prepareForSharing(shareDirectly, mainActivity, title, onlineUrl, bitmap, |
| - offlineFilePath, mContext); |
| + if (isOnOfflinePage) { |
| + // If we're currently on offline page get the saved file directly. |
| + offlinePageBridge.getPageByOfflineUrl(offlineUrl, new Callback<OfflinePageItem>() { |
| + @Override |
| + public void onResult(OfflinePageItem item) { |
| + if (item != null) { |
| + String offlineFilePath = item.getFilePath(); |
| + prepareForSharing(shareDirectly, mainActivity, title, onlineUrl, bitmap, |
| + offlineFilePath, mContext); |
| + } |
| } |
| + }); |
| + } else if (currentTab.hasOfflineCopy()) { |
| + OfflinePageItem item = offlinePageBridge.getBestPageForOnlineURL(onlineUrl); |
|
fgorski
2016/08/08 17:59:22
rewrite this part to async.
Vivian
2016/08/08 21:40:36
Done.
|
| + if (item != null) { |
| + String offlineFilePath = item.getFilePath(); |
| + prepareForSharing(shareDirectly, mainActivity, title, onlineUrl, bitmap, |
| + offlineFilePath, mContext); |
| } |
| - }); |
| + } else { |
| + // Else save the page offline. |
| + WebContents webContents = currentTab.getWebContents(); |
| + int tabId = currentTab.getId(); |
| + ClientId clientId = ClientId.createClientIdForTabId(tabId); |
| + |
| + offlinePageBridge.savePage( |
| + webContents, clientId, new OfflinePageBridge.SavePageCallback() { |
| + @Override |
| + public void onSavePageDone( |
| + int savePageResult, String url, long offlineId) { |
| + if (savePageResult == SavePageResult.SUCCESS) { |
| + OfflinePageItem item = |
| + offlinePageBridge.getPageByOfflineId(offlineId); |
|
fgorski
2016/08/08 17:59:22
rewrite to async.
Vivian
2016/08/08 21:40:36
Done.
|
| + if (item != null) { |
| + String offlineFilePath = item.getFilePath(); |
| + prepareForSharing(shareDirectly, mainActivity, title, |
| + onlineUrl, bitmap, offlineFilePath, mContext); |
| + } |
| + } |
| + } |
| + }); |
| + } |
| } else { |
| Log.e(TAG, "Unable to perform sharing on current tab."); |
| } |