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

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

Issue 2230803004: [Downloads] Use content:// URIs when sharing (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: [Downloads] Use content:// URIs when sharing 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 | « chrome/android/java/src/org/chromium/chrome/browser/download/ui/DownloadHistoryItemWrapper.java ('k') | 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/DownloadManagerUi.java
diff --git a/chrome/android/java/src/org/chromium/chrome/browser/download/ui/DownloadManagerUi.java b/chrome/android/java/src/org/chromium/chrome/browser/download/ui/DownloadManagerUi.java
index 5ea54ce7cd36205f6ed8e6b6f14e012de006758a..52a2dccb5e69a27f444ffb431fc1b12dc0d72a79 100644
--- a/chrome/android/java/src/org/chromium/chrome/browser/download/ui/DownloadManagerUi.java
+++ b/chrome/android/java/src/org/chromium/chrome/browser/download/ui/DownloadManagerUi.java
@@ -7,6 +7,7 @@ package org.chromium.chrome.browser.download.ui;
import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
+import android.os.StrictMode;
import android.support.v4.widget.DrawerLayout;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
@@ -20,6 +21,8 @@ import android.view.ViewGroup;
import android.widget.ListView;
import org.chromium.base.ApiCompatibilityUtils;
+import org.chromium.base.ContentUriUtils;
+import org.chromium.base.Log;
import org.chromium.base.ObserverList;
import org.chromium.chrome.R;
import org.chromium.chrome.browser.BasicNativePage;
@@ -254,7 +257,7 @@ public class DownloadManagerUi implements OnMenuItemClickListener {
if (selectedItems.size() == 1) {
// Set up intent for 1 item.
intentAction = Intent.ACTION_SEND;
- shareIntent.putExtra(Intent.EXTRA_STREAM, selectedItems.get(0).getUri());
+ shareIntent.putExtra(Intent.EXTRA_STREAM, getUriForItem(selectedItems.get(0)));
} else {
// Set up intent for multiple items.
intentAction = Intent.ACTION_SEND_MULTIPLE;
@@ -264,7 +267,7 @@ public class DownloadManagerUi implements OnMenuItemClickListener {
if (intentMimeType != null) intentMimeParts = intentMimeType.split(MIME_TYPE_DELIMITER);
for (DownloadHistoryItemWrapper itemWrapper : mSelectionDelegate.getSelectedItems()) {
- itemUris.add(itemWrapper.getUri());
+ itemUris.add(getUriForItem(itemWrapper));
String mimeType = Intent.normalizeMimeType(itemWrapper.getMimeType());
@@ -302,6 +305,30 @@ public class DownloadManagerUi implements OnMenuItemClickListener {
mActivity.getString(R.string.share_link_chooser_title)));
}
+ private Uri getUriForItem(DownloadHistoryItemWrapper itemWrapper) {
+ Uri uri = null;
+
+ // #getContentUriFromFile causes a disk read when it calls into FileProvider#getUriForFile.
+ // Obtaining a content URI is on the critical path for creating a share intent after the
+ // user taps on the share button, so even if we were to run this method on a background
+ // thread we would have to wait. As it depends on user-selected items, we cannot
+ // know/preload which URIs we need until the user presses share.
+ StrictMode.ThreadPolicy oldPolicy = StrictMode.allowThreadDiskReads();
+ try {
+ // Try to obtain a content:// URI, which is preferred to a file:/// URI so that
+ // receiving apps don't attempt to determine the file's mime type (which often fails).
+ uri = ContentUriUtils.getContentUriFromFile(mActivity.getApplicationContext(),
+ itemWrapper.getFile());
+ } catch (IllegalArgumentException e) {
+ Log.e(TAG, "Could not create content uri: " + e);
+ }
+ StrictMode.setThreadPolicy(oldPolicy);
+
+ if (uri == null) uri = Uri.fromFile(itemWrapper.getFile());
+
+ return uri;
+ }
+
private void deleteSelectedItems() {
for (DownloadHistoryItemWrapper wrappedItem : mSelectionDelegate.getSelectedItems()) {
wrappedItem.delete();
« no previous file with comments | « chrome/android/java/src/org/chromium/chrome/browser/download/ui/DownloadHistoryItemWrapper.java ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698