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

Unified Diff: base/android/java/src/org/chromium/base/ContentUriUtils.java

Issue 739033003: Support content scheme uri for Chrome on Android (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: addressing comments Created 6 years, 1 month 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: base/android/java/src/org/chromium/base/ContentUriUtils.java
diff --git a/base/android/java/src/org/chromium/base/ContentUriUtils.java b/base/android/java/src/org/chromium/base/ContentUriUtils.java
index 70c27ed14167f8dc36774878e0f3b8df2058132c..c3f30fab6797707ed7c000054bfd1135525ca746 100644
--- a/base/android/java/src/org/chromium/base/ContentUriUtils.java
+++ b/base/android/java/src/org/chromium/base/ContentUriUtils.java
@@ -26,7 +26,7 @@ public abstract class ContentUriUtils {
*/
public interface FileProviderUtil {
/**
- * Generate a content uri from the given file.
+ * Generate a content URI from the given file.
* @param context Application context.
* @param file The file to be translated.
*/
@@ -70,7 +70,7 @@ public abstract class ContentUriUtils {
*
* @param context {@link Context} in interest.
* @param uriString the content URI to query.
- * @returns true if the uri exists, or false otherwise.
+ * @returns true if the URI exists, or false otherwise.
*/
@CalledByNative
public static boolean contentUriExists(Context context, String uriString) {
@@ -82,6 +82,21 @@ public abstract class ContentUriUtils {
}
/**
+ * Retrieve the MIME type for the content URI.
+ *
+ * @param context {@link Context} in interest.
+ * @param uriString the content URI to look up.
+ * @returns MIME type or null if the input params are empty or invalid.
nyquist 2014/11/20 20:01:11 This should be @return (throughout this file)
qinmin 2014/11/20 23:07:18 Done.
+ */
+ @CalledByNative
+ public static String getMimeType(Context context, String uriString) {
+ ContentResolver resolver = context.getContentResolver();
+ Uri uri = Uri.parse(uriString);
+ if (resolver == null || uri == null) return null;
nyquist 2014/11/20 20:01:11 Uri.parse(...) never returns null (specifically me
qinmin 2014/11/20 23:07:19 Done.
+ return resolver.getType(uri);
+ }
+
+ /**
* Helper method to open a content URI and return the ParcelFileDescriptor.
*
* @param context {@link Context} in interest.
@@ -97,6 +112,8 @@ public abstract class ContentUriUtils {
pfd = resolver.openFileDescriptor(uri, "r");
} catch (java.io.FileNotFoundException e) {
nyquist 2014/11/20 20:01:11 could you change this one to import FileNotFoundEx
qinmin 2014/11/20 23:07:18 Done.
Log.w(TAG, "Cannot find content uri: " + uriString, e);
+ } catch (SecurityException e) {
+ Log.w(TAG, "Cannot open content uri: " + uriString, e);
}
return pfd;
}

Powered by Google App Engine
This is Rietveld 408576698