| Index: chrome/android/java/src/org/chromium/chrome/browser/offlinepages/downloads/OfflinePageDownloadBridge.java
|
| diff --git a/chrome/android/java/src/org/chromium/chrome/browser/offlinepages/downloads/OfflinePageDownloadBridge.java b/chrome/android/java/src/org/chromium/chrome/browser/offlinepages/downloads/OfflinePageDownloadBridge.java
|
| index 428353e83d7a558081c4c6901eb47668b6b202bb..5a8771e68916bd88f5d26a544d56078dafe88be7 100644
|
| --- a/chrome/android/java/src/org/chromium/chrome/browser/offlinepages/downloads/OfflinePageDownloadBridge.java
|
| +++ b/chrome/android/java/src/org/chromium/chrome/browser/offlinepages/downloads/OfflinePageDownloadBridge.java
|
| @@ -4,9 +4,15 @@
|
|
|
| package org.chromium.chrome.browser.offlinepages.downloads;
|
|
|
| +import android.app.Activity;
|
| +import android.content.Intent;
|
| +import android.net.Uri;
|
| +import android.provider.Browser;
|
| +
|
| import org.chromium.base.ObserverList;
|
| import org.chromium.base.annotations.CalledByNative;
|
| import org.chromium.base.annotations.JNINamespace;
|
| +import org.chromium.chrome.browser.IntentHandler;
|
| import org.chromium.chrome.browser.profiles.Profile;
|
|
|
| import java.util.ArrayList;
|
| @@ -97,12 +103,41 @@ public class OfflinePageDownloadBridge {
|
| * Gets a download item related to the provided GUID.
|
| * @param guid a GUID of the item to get.
|
| * @return download item related to the offline page identified by GUID.
|
| - * */
|
| + */
|
| public OfflinePageDownloadItem getItem(String guid) {
|
| return nativeGetItemByGuid(mNativeOfflinePageDownloadBridge, guid);
|
| }
|
|
|
| /**
|
| + * Schedules deletion of the offline page identified by the GUID.
|
| + * If the item is still in the process of download, the download is canceled.
|
| + * Actual cancel and/or deletion happens asynchronously, Observer is notified when it's done.
|
| + * @param guid a GUID of the item to delete.
|
| + */
|
| + public void deleteItem(String guid) {
|
| + nativeDeleteItemByGuid(mNativeOfflinePageDownloadBridge, guid);
|
| + }
|
| +
|
| + /**
|
| + * 'Opens' the offline page identified by the GUID.
|
| + * This is done by creating a new tab and navigating it to the saved local snapshot.
|
| + * No automatic redirection is happening based on the connection status.
|
| + * If the item with specified GUID is not found or can't be opened, nothing happens.
|
| + * @param guid a GUID of the item to open.
|
| + * @param activity Activity requesting to open the item (offline page).
|
| + */
|
| + public void openItem(String guid, Activity activity) {
|
| + String url = nativeGetOfflineUrlByGuid(
|
| + mNativeOfflinePageDownloadBridge, guid);
|
| + if (url.isEmpty()) return;
|
| + Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
|
| + intent.putExtra(Browser.EXTRA_APPLICATION_ID,
|
| + activity.getApplicationContext().getPackageName());
|
| + intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
| + IntentHandler.startActivityForTrustedIntent(intent, activity);
|
| + }
|
| +
|
| + /**
|
| * Method to ensure that the bridge is created for tests without calling the native portion of
|
| * initialization.
|
| * @param isTesting flag indicating whether the constructor will initialize native code.
|
| @@ -163,4 +198,8 @@ public class OfflinePageDownloadBridge {
|
| long nativeOfflinePageDownloadBridge, List<OfflinePageDownloadItem> items);
|
| native OfflinePageDownloadItem nativeGetItemByGuid(
|
| long nativeOfflinePageDownloadBridge, String guid);
|
| + native void nativeDeleteItemByGuid(
|
| + long nativeOfflinePageDownloadBridge, String guid);
|
| + native String nativeGetOfflineUrlByGuid(
|
| + long nativeOfflinePageDownloadBridge, String guid);
|
| }
|
|
|