summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--core/java/android/webkit/JniUtil.java45
1 files changed, 45 insertions, 0 deletions
diff --git a/core/java/android/webkit/JniUtil.java b/core/java/android/webkit/JniUtil.java
index 704d4dae81b6..cc1992920e8e 100644
--- a/core/java/android/webkit/JniUtil.java
+++ b/core/java/android/webkit/JniUtil.java
@@ -17,8 +17,13 @@
package android.webkit;
import android.content.Context;
+import android.net.Uri;
+import android.util.Log;
+
+import java.io.InputStream;
class JniUtil {
+ private static final String LOGTAG = "webkit";
private JniUtil() {} // Utility class, do not instantiate.
// Used by the Chromium HTTP stack.
@@ -70,6 +75,46 @@ class JniUtil {
}
/**
+ * Called by JNI. Calculates the size of an input stream by reading it.
+ * @return long The size of the stream
+ */
+ private static synchronized long contentUrlSize(String url) {
+ final String ANDROID_CONTENT = "content:";
+
+ // content://
+ if (url.startsWith(ANDROID_CONTENT)) {
+ try {
+ // Strip off mimetype, for compatibility with ContentLoader.java
+ // If we don't do this, we can fail to load Gmail attachments,
+ // because the URL being loaded doesn't exactly match the URL we
+ // have permission to read.
+ int mimeIndex = url.lastIndexOf('?');
+ if (mimeIndex != -1) {
+ url = url.substring(0, mimeIndex);
+ }
+ Uri uri = Uri.parse(url);
+ InputStream is = sContext.getContentResolver().openInputStream(uri);
+ byte[] buffer = new byte[1024];
+ int n;
+ long size = 0;
+ try {
+ while ((n = is.read(buffer)) != -1) {
+ size += n;
+ }
+ } finally {
+ is.close();
+ }
+ return size;
+ } catch (Exception e) {
+ Log.e(LOGTAG, "Exception: " + url);
+ return 0;
+ }
+ } else {
+ return 0;
+ }
+ }
+
+ /**
* Returns true if we're using the Chromium HTTP stack.
*
* TODO: Remove this if/when we permanently switch to the Chromium HTTP stack