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

Unified Diff: ui/android/java/src/org/chromium/ui/base/SelectFileDialog.java

Issue 489053003: Use content URI to upload photos taken by camera (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: addressing tedchoc's comments Created 6 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
Index: ui/android/java/src/org/chromium/ui/base/SelectFileDialog.java
diff --git a/ui/android/java/src/org/chromium/ui/base/SelectFileDialog.java b/ui/android/java/src/org/chromium/ui/base/SelectFileDialog.java
index 05186ebc77fc76b1e6f110d6777b1f1301508844..b8cb85286ef4095201939136fde8f2be8281e000 100644
--- a/ui/android/java/src/org/chromium/ui/base/SelectFileDialog.java
+++ b/ui/android/java/src/org/chromium/ui/base/SelectFileDialog.java
@@ -8,12 +8,13 @@ import android.annotation.TargetApi;
import android.app.Activity;
import android.content.ClipData;
import android.content.ContentResolver;
+import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.os.AsyncTask;
import android.os.Build;
-import android.os.Environment;
import android.provider.MediaStore;
+import android.support.v4.content.FileProvider;
import android.text.TextUtils;
import org.chromium.base.CalledByNative;
@@ -40,6 +41,8 @@ class SelectFileDialog implements WindowAndroid.IntentCallback{
private static final String ALL_AUDIO_TYPES = AUDIO_TYPE + "*";
private static final String ANY_TYPES = "*/*";
private static final String CAPTURE_IMAGE_DIRECTORY = "browser-photos";
+ private static final String API_AUTHORITY_SUFFIX = ".FileProvider";
+ private static final String IMAGE_FILE_PATH = "images";
palmer 2014/08/21 22:21:28 Comment that this has to be the same as the resour
qinmin 2014/08/22 00:11:21 Done.
private final long mNativeSelectFileDialog;
private List<String> mFileTypes;
@@ -66,8 +69,14 @@ class SelectFileDialog implements WindowAndroid.IntentCallback{
Intent chooser = new Intent(Intent.ACTION_CHOOSER);
Intent camera = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
- mCameraOutputUri = Uri.fromFile(getFileForImageCapture());
+ camera.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION |
+ Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
+ Context context = window.getApplicationContext();
+ mCameraOutputUri = FileProvider.getUriForFile(context,
+ context.getPackageName() + API_AUTHORITY_SUFFIX, getFileForImageCapture(context));
camera.putExtra(MediaStore.EXTRA_OUTPUT, mCameraOutputUri);
+ camera.setClipData(
+ ClipData.newUri(context.getContentResolver(), IMAGE_FILE_PATH, mCameraOutputUri));
Intent camcorder = new Intent(MediaStore.ACTION_VIDEO_CAPTURE);
Intent soundRecorder = new Intent(
MediaStore.Audio.Media.RECORD_SOUND_ACTION);
@@ -125,18 +134,16 @@ class SelectFileDialog implements WindowAndroid.IntentCallback{
}
/**
- * Get a file for the image capture in the CAPTURE_IMAGE_DIRECTORY directory.
+ * Get a file for the image capture in the IMAGE_FILE_PATH directory.
+ * @param context The application context.
*/
- private File getFileForImageCapture() {
- File externalDataDir = Environment.getExternalStoragePublicDirectory(
- Environment.DIRECTORY_DCIM);
- File cameraDataDir = new File(externalDataDir.getAbsolutePath() +
- File.separator + CAPTURE_IMAGE_DIRECTORY);
- if (!cameraDataDir.exists() && !cameraDataDir.mkdirs()) {
- cameraDataDir = externalDataDir;
+ private File getFileForImageCapture(Context context) {
+ final File path = new File(context.getFilesDir(), IMAGE_FILE_PATH);
+ if (!path.exists()) {
+ path.mkdir();
}
- File photoFile = new File(cameraDataDir.getAbsolutePath() +
- File.separator + System.currentTimeMillis() + ".jpg");
+ File photoFile = new File(path + File.separator + System.currentTimeMillis() +
palmer 2014/08/21 22:21:28 There is an extremely tiny chance that this method
qinmin 2014/08/22 00:11:21 Done.
+ ".jpg");
return photoFile;
}
@@ -160,7 +167,8 @@ class SelectFileDialog implements WindowAndroid.IntentCallback{
if (results == null) {
// If we have a successful return but no data, then assume this is the camera returning
// the photo that we requested.
- nativeOnFileSelected(mNativeSelectFileDialog, mCameraOutputUri.getPath(), "");
+ nativeOnFileSelected(mNativeSelectFileDialog, mCameraOutputUri.toString(),
+ mCameraOutputUri.getLastPathSegment());
// Broadcast to the media scanner that there's a new photo on the device so it will
// show up right away in the gallery (rather than waiting until the next time the media

Powered by Google App Engine
This is Rietveld 408576698