[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[tor-commits] [tor-browser/tor-browser-60.4.0esr-8.5-1] Bug 1450449 - Part 2: Use content:// URI for capturing images from FilePicker. r=jchen



commit f74197a8e82b67b0351e91e134138f91ae0173d4
Author: Jan Henning <jh+bugzilla@xxxxxxxxxxxxxxx>
Date:   Sat May 12 23:02:19 2018 +0200

    Bug 1450449 - Part 2: Use content:// URI for capturing images from FilePicker. r=jchen
    
    Since it is only us and the camera app who have to deal with the content:// URI,
    it should be safe enough to use content:// URIs on all supported versions.
    
    MozReview-Commit-ID: JMIhBRlCiA4
    
    --HG--
    extra : rebase_source : 7a19ea138459f4a153a931db1500a0b2cb0649da
---
 .../base/java/org/mozilla/gecko/FilePicker.java       |  4 ++--
 .../base/java/org/mozilla/gecko/IntentHelper.java     | 19 ++++++++++++++++---
 2 files changed, 18 insertions(+), 5 deletions(-)

diff --git a/mobile/android/base/java/org/mozilla/gecko/FilePicker.java b/mobile/android/base/java/org/mozilla/gecko/FilePicker.java
index 91fcaa16d130..c9ea347e6c88 100644
--- a/mobile/android/base/java/org/mozilla/gecko/FilePicker.java
+++ b/mobile/android/base/java/org/mozilla/gecko/FilePicker.java
@@ -176,7 +176,7 @@ public class FilePicker implements BundleEventListener {
             if (mimeType.equals("image/*") &&
                     hasPermissionsForMimeType(mimeType, availPermissions)) {
                 // We also add a capture intent
-                Intent intent = IntentHelper.getImageCaptureIntent(
+                Intent intent = IntentHelper.getImageCaptureIntent(context,
                         new File(Environment.getExternalStorageDirectory(),
                                 fileHandler.generateImageName()));
                 addActivities(intent, intents, baseIntents);
@@ -201,7 +201,7 @@ public class FilePicker implements BundleEventListener {
                 addActivities(intent, intents, baseIntents);
             }
             if (hasPermissionsForMimeType("image/*", availPermissions)) {
-                intent = IntentHelper.getImageCaptureIntent(
+                intent = IntentHelper.getImageCaptureIntent(context,
                         new File(Environment.getExternalStorageDirectory(),
                                 fileHandler.generateImageName()));
                 addActivities(intent, intents, baseIntents);
diff --git a/mobile/android/base/java/org/mozilla/gecko/IntentHelper.java b/mobile/android/base/java/org/mozilla/gecko/IntentHelper.java
index 9f6422263bbe..f2810a92af51 100644
--- a/mobile/android/base/java/org/mozilla/gecko/IntentHelper.java
+++ b/mobile/android/base/java/org/mozilla/gecko/IntentHelper.java
@@ -19,6 +19,7 @@ import org.mozilla.gecko.widget.ExternalIntentDuringPrivateBrowsingPromptFragmen
 
 import android.annotation.TargetApi;
 import android.app.Activity;
+import android.content.ClipData;
 import android.content.Context;
 import android.content.Intent;
 import android.content.pm.PackageManager;
@@ -29,6 +30,7 @@ import android.provider.Browser;
 import android.provider.MediaStore;
 import android.support.annotation.Nullable;
 import android.support.v4.app.FragmentActivity;
+import android.support.v4.content.FileProvider;
 import android.text.TextUtils;
 import android.util.Log;
 import android.webkit.MimeTypeMap;
@@ -243,10 +245,21 @@ public final class IntentHelper implements BundleEventListener {
         return new Intent(MediaStore.Audio.Media.RECORD_SOUND_ACTION);
     }
 
-    public static Intent getImageCaptureIntent(final File destinationFile) {
+    public static Intent getImageCaptureIntent(final Context context, final File destinationFile) {
         final Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
-        intent.putExtra(MediaStore.EXTRA_OUTPUT,
-                Uri.fromFile(destinationFile));
+        Uri destination = FileProvider.getUriForFile(context,
+                AppConstants.MOZ_FILE_PROVIDER_AUTHORITY, destinationFile);
+        intent.putExtra(MediaStore.EXTRA_OUTPUT, destination);
+
+        if (AppConstants.Versions.preLollipop) {
+            // As per https://github.com/commonsguy/cw-omnibus/blob/master/Camera/FileProvider/
+            // app/src/main/java/com/commonsware/android/camcon/MainActivity.java - at least we
+            // don't have to support anything below Jelly Bean.
+            ClipData clip =
+                    ClipData.newUri(context.getContentResolver(), null, destination);
+            intent.setClipData(clip);
+        }
+        intent.addFlags(Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
         return intent;
     }
 



_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits