summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Kristian Monsen <kristianm@google.com> 2011-01-10 12:05:37 +0000
committer Kristian Monsen <kristianm@google.com> 2011-01-12 11:53:28 +0000
commit3ede315d65b60f91893ce151eba4ce2f8a5b97bb (patch)
tree7c6733cc9e98539fc2917832c6ad44c9d8bcf563
parent80ff5d82bdbad51378a45d3a378213346ea22df0 (diff)
Add a static method to get the InputStream of a content URL
Part of fix for bug 2862096 Change-Id: I91f7e7aa1f0fef10b1617e91a167594d4de41b71
-rw-r--r--core/java/android/webkit/JniUtil.java33
1 files changed, 31 insertions, 2 deletions
diff --git a/core/java/android/webkit/JniUtil.java b/core/java/android/webkit/JniUtil.java
index cc1992920e8e..62b415c78407 100644
--- a/core/java/android/webkit/JniUtil.java
+++ b/core/java/android/webkit/JniUtil.java
@@ -74,13 +74,13 @@ class JniUtil {
return sCacheDirectory;
}
+ private static final String ANDROID_CONTENT = "content:";
+
/**
* 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 {
@@ -115,6 +115,35 @@ class JniUtil {
}
/**
+ * Called by JNI.
+ *
+ * @return Opened input stream to content
+ * TODO: Make all content loading use this instead of BrowserFrame.java
+ */
+ private static synchronized InputStream contentUrlStream(String url) {
+ // 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);
+ return sContext.getContentResolver().openInputStream(uri);
+ } catch (Exception e) {
+ Log.e(LOGTAG, "Exception: " + url);
+ return null;
+ }
+ } else {
+ return null;
+ }
+ }
+
+ /**
* Returns true if we're using the Chromium HTTP stack.
*
* TODO: Remove this if/when we permanently switch to the Chromium HTTP stack