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

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: 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..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;
}

Powered by Google App Engine
This is Rietveld 408576698