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..35d46287bf44dce631147220ce8b79a1e11194a3 100644 |
--- a/base/android/java/src/org/chromium/base/ContentUriUtils.java |
+++ b/base/android/java/src/org/chromium/base/ContentUriUtils.java |
@@ -82,6 +82,21 @@ public abstract class ContentUriUtils { |
} |
/** |
+ * Retrieve the mime type for the content URI. |
nyquist
2014/11/19 00:06:25
Nit: MIME here and below?
qinmin
2014/11/19 02:13:07
Done.
|
+ * |
+ * @param context {@link Context} in interest. |
+ * @param uriString the content URI to open. |
nyquist
2014/11/19 00:06:25
It feels a bit off that we say 'open' here. Maybe
qinmin
2014/11/19 02:13:07
Done.
|
+ * @returns mime type or an empty string if the input params are invalid. |
nyquist
2014/11/19 00:06:25
This leads to believe that the method can never re
palmer
2014/11/19 00:23:54
FWIW, The Java Way would be to throw, not return,
qinmin
2014/11/19 02:13:07
Ok, changed the description to just return NULL on
qinmin
2014/11/19 02:13:07
This method is called by native, so either the jav
|
+ */ |
+ @CalledByNative |
+ public static String getMimeType(Context context, String uriString) { |
+ ContentResolver resolver = context.getContentResolver(); |
+ Uri uri = Uri.parse(uriString); |
+ if (resolver == null || uri == null) return ""; |
+ return resolver.getType(uri); |
nyquist
2014/11/19 00:06:25
Do we want to ensure that this never returns null?
qinmin
2014/11/19 02:13:07
returned null for the empty inputs case
|
+ } |
+ |
+ /** |
* 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) { |
Log.w(TAG, "Cannot find content uri: " + uriString, e); |
+ } catch (java.lang.SecurityException e) { |
nyquist
2014/11/19 00:06:25
Do you really need the 'java.lang.' prefix here?
palmer
2014/11/19 00:23:54
Nope.
qinmin
2014/11/19 02:13:07
removed
|
+ Log.w(TAG, "Cannot open content uri: " + uriString, e); |
} |
return pfd; |
} |