Index: chrome/android/java/src/org/chromium/chrome/browser/download/ui/DownloadHistoryItemWrapper.java |
diff --git a/chrome/android/java/src/org/chromium/chrome/browser/download/ui/DownloadHistoryItemWrapper.java b/chrome/android/java/src/org/chromium/chrome/browser/download/ui/DownloadHistoryItemWrapper.java |
index 60ca2316d82db978e7948ce9fa1cb12ba5afde23..cf1ebdf1de0c4c21159c27a0d72bd5cd403364d6 100644 |
--- a/chrome/android/java/src/org/chromium/chrome/browser/download/ui/DownloadHistoryItemWrapper.java |
+++ b/chrome/android/java/src/org/chromium/chrome/browser/download/ui/DownloadHistoryItemWrapper.java |
@@ -4,26 +4,17 @@ |
package org.chromium.chrome.browser.download.ui; |
-import android.app.PendingIntent; |
import android.content.ActivityNotFoundException; |
import android.content.ComponentName; |
import android.content.Context; |
import android.content.Intent; |
-import android.graphics.Bitmap; |
-import android.graphics.BitmapFactory; |
-import android.graphics.Color; |
import android.net.Uri; |
-import android.provider.Browser; |
-import android.support.customtabs.CustomTabsIntent; |
import android.text.TextUtils; |
import org.chromium.base.ContextUtils; |
import org.chromium.base.metrics.RecordHistogram; |
import org.chromium.chrome.R; |
import org.chromium.chrome.browser.IntentHandler; |
-import org.chromium.chrome.browser.UrlConstants; |
-import org.chromium.chrome.browser.customtabs.CustomTabActivity; |
-import org.chromium.chrome.browser.customtabs.CustomTabIntentDataProvider; |
import org.chromium.chrome.browser.download.DownloadItem; |
import org.chromium.chrome.browser.download.DownloadUtils; |
import org.chromium.chrome.browser.offlinepages.downloads.OfflinePageDownloadItem; |
@@ -31,14 +22,9 @@ import org.chromium.chrome.browser.widget.DateDividedAdapter.TimedItem; |
import org.chromium.ui.widget.Toast; |
import java.io.File; |
-import java.util.ArrayList; |
-import java.util.List; |
-import java.util.Locale; |
/** Wraps different classes that contain information about downloads. */ |
public abstract class DownloadHistoryItemWrapper implements TimedItem { |
- private static final String TAG = "download_ui"; |
- |
protected final BackendProvider mBackendProvider; |
protected final ComponentName mComponentName; |
private Long mStableId; |
@@ -118,11 +104,6 @@ public abstract class DownloadHistoryItemWrapper implements TimedItem { |
/** Wraps a {@link DownloadItem}. */ |
public static class DownloadItemWrapper extends DownloadHistoryItemWrapper { |
- private static final String MIMETYPE_VIDEO = "video"; |
- private static final String MIMETYPE_AUDIO = "audio"; |
- private static final String MIMETYPE_IMAGE = "image"; |
- private static final String MIMETYPE_DOCUMENT = "text"; |
- |
private final DownloadItem mItem; |
private final boolean mIsOffTheRecord; |
private File mFile; |
@@ -177,7 +158,7 @@ public abstract class DownloadHistoryItemWrapper implements TimedItem { |
@Override |
public int getFilterType() { |
- return convertMimeTypeToFilterType(getMimeType()); |
+ return DownloadFilter.fromMimeType(getMimeType()); |
} |
@Override |
@@ -188,7 +169,8 @@ public abstract class DownloadHistoryItemWrapper implements TimedItem { |
@Override |
public void open() { |
Context context = ContextUtils.getApplicationContext(); |
- Intent viewIntent = DownloadUtils.createViewIntentForDownloadItem(this); |
+ Intent viewIntent = DownloadUtils.createViewIntentForDownloadItem( |
+ Uri.fromFile(getFile()), getMimeType()); |
if (mItem.hasBeenExternallyRemoved()) { |
Toast.makeText(context, context.getString(R.string.download_cant_open_file), |
@@ -199,43 +181,14 @@ public abstract class DownloadHistoryItemWrapper implements TimedItem { |
// Check if Chrome should open the file itself. |
if (mBackendProvider.getDownloadDelegate().isDownloadOpenableInBrowser( |
mItem.getId(), mIsOffTheRecord)) { |
- Bitmap closeIcon = BitmapFactory.decodeResource( |
- context.getResources(), R.drawable.ic_arrow_back_white_24dp); |
- Bitmap shareIcon = BitmapFactory.decodeResource( |
- context.getResources(), R.drawable.ic_share_white_24dp); |
- |
- CustomTabsIntent.Builder builder = new CustomTabsIntent.Builder(); |
- builder.setToolbarColor(Color.BLACK); |
- builder.setCloseButtonIcon(closeIcon); |
- builder.setShowTitle(true); |
- |
- // Create a PendingIntent that can be used to view the file externally. |
- // TODO(dfalcantara): Check if this is problematic in multi-window mode, where two |
- // different viewers could be visible at the same time. |
- Intent chooserIntent = Intent.createChooser(viewIntent, null); |
- chooserIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
- String openWithStr = context.getString(R.string.download_manager_open_with); |
- PendingIntent pendingViewIntent = PendingIntent.getActivity( |
- context, 0, chooserIntent, PendingIntent.FLAG_CANCEL_CURRENT); |
- builder.addMenuItem(openWithStr, pendingViewIntent); |
- |
- // Create a PendingIntent that shares the file with external apps. |
- List<DownloadHistoryItemWrapper> items = new ArrayList<>(); |
- items.add(this); |
- PendingIntent pendingShareIntent = PendingIntent.getActivity( |
- context, 0, DownloadUtils.createShareIntent(items), 0); |
- builder.setActionButton( |
- shareIcon, context.getString(R.string.share), pendingShareIntent, true); |
- |
- // Build up the Intent further. |
- Intent intent = builder.build().intent; |
- intent.setAction(Intent.ACTION_VIEW); |
- intent.setData(Uri.parse(UrlConstants.FILE_SCHEME + getFilePath())); |
- intent.putExtra(CustomTabIntentDataProvider.EXTRA_IS_MEDIA_VIEWER, true); |
- intent.putExtra(Browser.EXTRA_APPLICATION_ID, context.getPackageName()); |
- |
- intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
- intent.setClass(context, CustomTabActivity.class); |
+ // Share URIs use the content:// scheme when able, which looks bad when displayed |
+ // in the URL bar. |
+ Uri fileUri = Uri.fromFile(getFile()); |
+ Uri shareUri = DownloadUtils.getUriForItem(getFile()); |
+ String mimeType = Intent.normalizeMimeType(getMimeType()); |
+ |
+ Intent intent = DownloadUtils.getMediaViewerIntentForDownloadItem( |
+ fileUri, shareUri, mimeType); |
IntentHandler.startActivityForTrustedIntent(intent, context); |
return; |
} |
@@ -268,26 +221,6 @@ public abstract class DownloadHistoryItemWrapper implements TimedItem { |
boolean isOffTheRecord() { |
return mIsOffTheRecord; |
} |
- |
- /** Identifies the type of file represented by the given MIME type string. */ |
- private static int convertMimeTypeToFilterType(String mimeType) { |
- if (TextUtils.isEmpty(mimeType)) return DownloadFilter.FILTER_OTHER; |
- |
- String[] pieces = mimeType.toLowerCase(Locale.getDefault()).split("/"); |
- if (pieces.length != 2) return DownloadFilter.FILTER_OTHER; |
- |
- if (MIMETYPE_VIDEO.equals(pieces[0])) { |
- return DownloadFilter.FILTER_VIDEO; |
- } else if (MIMETYPE_AUDIO.equals(pieces[0])) { |
- return DownloadFilter.FILTER_AUDIO; |
- } else if (MIMETYPE_IMAGE.equals(pieces[0])) { |
- return DownloadFilter.FILTER_IMAGE; |
- } else if (MIMETYPE_DOCUMENT.equals(pieces[0])) { |
- return DownloadFilter.FILTER_DOCUMENT; |
- } else { |
- return DownloadFilter.FILTER_OTHER; |
- } |
- } |
} |
/** Wraps a {@link OfflinePageDownloadItem}. */ |