diff options
author | Kristian Monsen <kristianm@google.com> | 2011-01-10 12:23:24 +0000 |
---|---|---|
committer | Kristian Monsen <kristianm@google.com> | 2011-01-13 16:01:59 +0000 |
commit | 69dbe9fcda26341f31379053f8123d7f611c0be1 (patch) | |
tree | 282ae77c6741636bbb49d0c8659f8f11bd0d229a /android | |
parent | be79c5f177f2c8d49c414a2230e372adc0d9e625 (diff) | |
download | external_chromium-69dbe9fcda26341f31379053f8123d7f611c0be1.zip external_chromium-69dbe9fcda26341f31379053f8123d7f611c0be1.tar.gz external_chromium-69dbe9fcda26341f31379053f8123d7f611c0be1.tar.bz2 |
Uploads for content uri's
Looking for content:// uri when doing file uploads. If it is a
content file, use the android jni methods instead of file
operations.
Fix for bug 2862096
Change-Id: Ice5047e85878aadc17c0994186dc7aa74ca63322
Diffstat (limited to 'android')
-rw-r--r-- | android/jni/platform_file_jni.cc | 64 | ||||
-rw-r--r-- | android/jni/platform_file_jni.h | 27 |
2 files changed, 91 insertions, 0 deletions
diff --git a/android/jni/platform_file_jni.cc b/android/jni/platform_file_jni.cc new file mode 100644 index 0000000..658b417 --- /dev/null +++ b/android/jni/platform_file_jni.cc @@ -0,0 +1,64 @@ +// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "android/jni/jni_utils.h" +#include "android/jni/platform_file_jni.h" +#include "base/file_path.h" +#include "base/logging.h" + +namespace android { + +JavaInputStreamWrapper::JavaInputStreamWrapper(const FilePath& path) { + JNIEnv* env = GetJNIEnv(); + jclass inputStreamClass = env->FindClass("java/io/InputStream"); + m_read = env->GetMethodID(inputStreamClass, "read", "([B)I"); + m_close = env->GetMethodID(inputStreamClass, "close", "()V"); + + jclass bridgeClass = env->FindClass("android/webkit/JniUtil"); + jmethodID method = env->GetStaticMethodID( + bridgeClass, + "contentUrlStream", + "(Ljava/lang/String;)Ljava/io/InputStream;"); + m_inputStream = env->NewGlobalRef(env->CallStaticObjectMethod( + bridgeClass, + method, + ConvertUTF8ToJavaString(env, path.value()))); + env->DeleteLocalRef(bridgeClass); + env->DeleteLocalRef(inputStreamClass); +} + +JavaInputStreamWrapper::~JavaInputStreamWrapper() { + JNIEnv* env = GetJNIEnv(); + env->CallVoidMethod(m_inputStream, m_close); + CheckException(env); + env->DeleteGlobalRef(m_inputStream); +} + +int JavaInputStreamWrapper::Read(char* out, int length) { + JNIEnv* env = GetJNIEnv(); + jbyteArray buffer = env->NewByteArray(length); + + int size = (int) env->CallIntMethod(m_inputStream, m_read, buffer); + if (CheckException(env) || size < 0) { + env->DeleteLocalRef(buffer); + return 0; + } + + env->GetByteArrayRegion(buffer, 0, size, (jbyte*)out); + env->DeleteLocalRef(buffer); + return size; +} + +uint64 contentUrlSize(const FilePath& name) { + JNIEnv* env = GetJNIEnv(); + jclass bridgeClass = env->FindClass("android/webkit/JniUtil"); + jmethodID method = env->GetStaticMethodID(bridgeClass, "contentUrlSize", "(Ljava/lang/String;)J"); + jlong length = env->CallStaticLongMethod(bridgeClass, method, ConvertUTF8ToJavaString(env, name.value())); + env->DeleteLocalRef(bridgeClass); + + return static_cast<uint64>(length); +} + +} + diff --git a/android/jni/platform_file_jni.h b/android/jni/platform_file_jni.h new file mode 100644 index 0000000..dd4254a --- /dev/null +++ b/android/jni/platform_file_jni.h @@ -0,0 +1,27 @@ +// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "android/jni/jni_utils.h" +#include "base/platform_file.h" + +#include <string> + +namespace android { + +uint64 contentUrlSize(const FilePath& name); + +class JavaInputStreamWrapper { +public: + JavaInputStreamWrapper(const FilePath& path); + ~JavaInputStreamWrapper(); + + int Read(char* out, int length); + +private: + jobject m_inputStream; + jmethodID m_read; + jmethodID m_close; +}; + +} |