1 // Copyright 2013 The Chromium Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #include "base/android/content_uri_utils.h" 6 7 #include "base/android/jni_android.h" 8 #include "base/android/jni_string.h" 9 #include "jni/ContentUriUtils_jni.h" 10 11 using base::android::ConvertUTF8ToJavaString; 12 using base::android::ScopedJavaLocalRef; 13 14 namespace base { 15 ContentUriExists(const FilePath & content_uri)16bool ContentUriExists(const FilePath& content_uri) { 17 JNIEnv* env = base::android::AttachCurrentThread(); 18 ScopedJavaLocalRef<jstring> j_uri = 19 ConvertUTF8ToJavaString(env, content_uri.value()); 20 return Java_ContentUriUtils_contentUriExists(env, j_uri); 21 } 22 OpenContentUriForRead(const FilePath & content_uri)23File OpenContentUriForRead(const FilePath& content_uri) { 24 JNIEnv* env = base::android::AttachCurrentThread(); 25 ScopedJavaLocalRef<jstring> j_uri = 26 ConvertUTF8ToJavaString(env, content_uri.value()); 27 jint fd = Java_ContentUriUtils_openContentUriForRead(env, j_uri); 28 if (fd < 0) 29 return File(); 30 return File(fd); 31 } 32 GetContentUriMimeType(const FilePath & content_uri)33std::string GetContentUriMimeType(const FilePath& content_uri) { 34 JNIEnv* env = base::android::AttachCurrentThread(); 35 ScopedJavaLocalRef<jstring> j_uri = 36 ConvertUTF8ToJavaString(env, content_uri.value()); 37 ScopedJavaLocalRef<jstring> j_mime = 38 Java_ContentUriUtils_getMimeType(env, j_uri); 39 if (j_mime.is_null()) 40 return std::string(); 41 42 return base::android::ConvertJavaStringToUTF8(env, j_mime.obj()); 43 } 44 45 } // namespace base 46