Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(534)

Unified Diff: chrome/android/java/src/org/chromium/chrome/browser/download/ui/DownloadHistoryItemWrapper.java

Issue 2256773003: [Downloads] Better handle opening files (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Don't open deleted files Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 9e810225fbfe8e0624d262c2b73b5965e8e87c6f..68a25ce2fb3a5f5183a61b99ae1386f79a79aa0e 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
@@ -8,8 +8,6 @@ import android.content.ActivityNotFoundException;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
-import android.content.pm.PackageManager;
-import android.content.pm.ResolveInfo;
import android.net.Uri;
import android.os.AsyncTask;
import android.text.TextUtils;
@@ -26,7 +24,6 @@ import org.chromium.chrome.browser.widget.DateDividedAdapter.TimedItem;
import org.chromium.ui.widget.Toast;
import java.io.File;
-import java.util.List;
import java.util.Locale;
/** Wraps different classes that contain information about downloads. */
@@ -145,7 +142,12 @@ abstract class DownloadHistoryItemWrapper implements TimedItem {
@Override
public void open() {
Context context = ContextUtils.getApplicationContext();
- boolean success = false;
+
+ if (mItem.hasBeenExternallyRemoved()) {
+ Toast.makeText(context, context.getString(R.string.download_cant_open_file),
+ Toast.LENGTH_SHORT).show();
+ return;
+ }
String mimeType = Intent.normalizeMimeType(mItem.getDownloadInfo().getMimeType());
Uri fileUri = Uri.fromFile(getFile());
@@ -159,20 +161,11 @@ abstract class DownloadHistoryItemWrapper implements TimedItem {
fileIntent.setDataAndType(fileUri, mimeType);
}
fileIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
- List<ResolveInfo> handlers = context.getPackageManager()
- .queryIntentActivities(fileIntent, PackageManager.MATCH_DEFAULT_ONLY);
- if (handlers.size() > 0) {
- Intent chooserIntent = Intent.createChooser(fileIntent, null);
- chooserIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
- try {
- context.startActivity(chooserIntent);
- success = true;
- } catch (ActivityNotFoundException e) {
- // Can't launch the Intent.
- }
- }
- if (!success) {
+ try {
+ context.startActivity(fileIntent);
+ } catch (ActivityNotFoundException e) {
+ // Can't launch the Intent.
Toast.makeText(context, context.getString(R.string.download_cant_open_file),
Toast.LENGTH_SHORT).show();
}
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698