You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by br...@apache.org on 2013/06/14 20:52:20 UTC

[1/6] android commit: Revert "Revert "DataRequest code cleaned up.""

Updated Branches:
  refs/heads/dataresource [created] aefb12951


Revert "Revert "DataRequest code cleaned up.""

This reverts commit e3989bcc2b23588def3948239fc73630192a543b.


Project: http://git-wip-us.apache.org/repos/asf/cordova-android/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-android/commit/489ce0b5
Tree: http://git-wip-us.apache.org/repos/asf/cordova-android/tree/489ce0b5
Diff: http://git-wip-us.apache.org/repos/asf/cordova-android/diff/489ce0b5

Branch: refs/heads/dataresource
Commit: 489ce0b583871aeca26902955676165f5906d001
Parents: 60a65e1
Author: Braden Shepherdson <br...@gmail.com>
Authored: Fri Jun 7 10:17:42 2013 -0400
Committer: Braden Shepherdson <br...@gmail.com>
Committed: Fri Jun 14 14:52:09 2013 -0400

----------------------------------------------------------------------
 .../src/org/apache/cordova/CameraLauncher.java  | 12 +++----
 .../src/org/apache/cordova/FileHelper.java      | 20 ++++-------
 framework/src/org/apache/cordova/FileUtils.java |  2 +-
 .../cordova/IceCreamCordovaWebViewClient.java   |  7 ++--
 .../org/apache/cordova/api/CordovaPlugin.java   |  4 +--
 .../org/apache/cordova/api/DataResource.java    | 37 +++++++++++---------
 .../apache/cordova/api/DataResourceContext.java |  9 +----
 .../org/apache/cordova/api/PluginManager.java   |  9 +++--
 8 files changed, 45 insertions(+), 55 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-android/blob/489ce0b5/framework/src/org/apache/cordova/CameraLauncher.java
----------------------------------------------------------------------
diff --git a/framework/src/org/apache/cordova/CameraLauncher.java b/framework/src/org/apache/cordova/CameraLauncher.java
index f434661..134cf09 100755
--- a/framework/src/org/apache/cordova/CameraLauncher.java
+++ b/framework/src/org/apache/cordova/CameraLauncher.java
@@ -342,7 +342,7 @@ public class CameraLauncher extends CordovaPlugin implements MediaScannerConnect
 
                             // Add compressed version of captured image to returned media store Uri
                             DataResource dataResource = DataResource.initiateNewDataRequestForUri(uri, webView.pluginManager, cordova, "CameraLauncher.CameraExitIntent");
-                            OutputStream os = dataResource.getOs();
+                            OutputStream os = dataResource.getOutputStream();
                             bitmap.compress(Bitmap.CompressFormat.JPEG, this.mQuality, os);
                             os.close();
 
@@ -540,9 +540,9 @@ public class CameraLauncher extends CordovaPlugin implements MediaScannerConnect
     private void writeUncompressedImage(Uri uri) throws FileNotFoundException,
             IOException {
         DataResource inputDataResource = DataResource.initiateNewDataRequestForUri(imageUri, webView.pluginManager, cordova, "CameraLauncher.writeUncompressedImage");
-        InputStream fis = inputDataResource.getIs();
+        InputStream fis = inputDataResource.getInputStream();
         DataResource outDataResource = DataResource.initiateNewDataRequestForUri(uri, webView.pluginManager, cordova, "CameraLauncher.writeUncompressedImage");
-        OutputStream os = outDataResource.getOs();
+        OutputStream os = outDataResource.getOutputStream();
         if(fis == null) {
             throw new FileNotFoundException("Could not get the input file");
         } else if(os == null) {
@@ -592,13 +592,13 @@ public class CameraLauncher extends CordovaPlugin implements MediaScannerConnect
         // If no new width or height were specified return the original bitmap
         DataResource dataResource = DataResource.initiateNewDataRequestForUri(imageUrl, webView.pluginManager, cordova, "CameraLauncher.getScaledBitmap");
         if (this.targetWidth <= 0 && this.targetHeight <= 0) {
-            return BitmapFactory.decodeStream(dataResource.getIs());
+            return BitmapFactory.decodeStream(dataResource.getInputStream());
         }
 
         // figure out the original width and height of the image
         BitmapFactory.Options options = new BitmapFactory.Options();
         options.inJustDecodeBounds = true;
-        BitmapFactory.decodeStream(dataResource.getIs(), null, options);
+        BitmapFactory.decodeStream(dataResource.getInputStream(), null, options);
         
         //CB-2292: WTF? Why is the width null?
         if(options.outWidth == 0 || options.outHeight == 0)
@@ -612,7 +612,7 @@ public class CameraLauncher extends CordovaPlugin implements MediaScannerConnect
         // Load in the smallest bitmap possible that is closest to the size we want
         options.inJustDecodeBounds = false;
         options.inSampleSize = calculateSampleSize(options.outWidth, options.outHeight, this.targetWidth, this.targetHeight);
-        Bitmap unscaledBitmap = BitmapFactory.decodeStream(dataResource.getIs(), null, options);
+        Bitmap unscaledBitmap = BitmapFactory.decodeStream(dataResource.getInputStream(), null, options);
         if (unscaledBitmap == null) {
             return null;
         }

http://git-wip-us.apache.org/repos/asf/cordova-android/blob/489ce0b5/framework/src/org/apache/cordova/FileHelper.java
----------------------------------------------------------------------
diff --git a/framework/src/org/apache/cordova/FileHelper.java b/framework/src/org/apache/cordova/FileHelper.java
index e7bf98a..69c7f48 100644
--- a/framework/src/org/apache/cordova/FileHelper.java
+++ b/framework/src/org/apache/cordova/FileHelper.java
@@ -130,33 +130,27 @@ public class FileHelper {
      */
     public static boolean isUriWritable(String uriString) {
         String scheme = uriString.split(":")[0];
-        String writableSchemes[] = new String[]{ "content" };
 
         if(scheme.equals("file")){
             // special case file
-            if(uriString.startsWith("file:///android_asset/")){
-                return false;
-            } else {
-                return true;
-            }
+            return !uriString.startsWith("file:///android_asset/");
         }
-        for(int i = writableSchemes.length - 1; i >= 0 ; i--){
-            if(writableSchemes[i].equals(scheme)){
-                return true;
-            }
-        }
-        return false;
+        return "content".equals(scheme);
     }
 
     /**
      * Ensures the "file://" prefix exists for the given string
-     * If the given URI string has a "file://" prefix, it is returned unchanged
+     * If the given URI string already has a scheme, it is returned unchanged
      *
      * @param path - the path string to operate on
      * @return a String with the "file://" scheme set
      */
     public static String insertFileProtocol(String path) {
         if(!path.matches("^[a-z0-9+.-]+:.*")){
+            //Ensure it is not a relative path
+            if(!path.startsWith("/")){
+                throw new IllegalArgumentException("Relative paths" + path + "are not allowed.");
+            }
             path = "file://" + path;
         }
         return path;

http://git-wip-us.apache.org/repos/asf/cordova-android/blob/489ce0b5/framework/src/org/apache/cordova/FileUtils.java
----------------------------------------------------------------------
diff --git a/framework/src/org/apache/cordova/FileUtils.java b/framework/src/org/apache/cordova/FileUtils.java
index adf788e..370bc0c 100755
--- a/framework/src/org/apache/cordova/FileUtils.java
+++ b/framework/src/org/apache/cordova/FileUtils.java
@@ -897,7 +897,7 @@ public class FileUtils extends CordovaPlugin {
             public void run() {
                 try {
                     DataResource dataResource = DataResource.initiateNewDataRequestForUri(filename, webView.pluginManager, cordova, "FileUtils.readFileAs");
-                    byte[] bytes = readAsBinaryHelper(dataResource.getIs(), start, end);
+                    byte[] bytes = readAsBinaryHelper(dataResource.getInputStream(), start, end);
                     
                     PluginResult result;
                     switch (resultType) {

http://git-wip-us.apache.org/repos/asf/cordova-android/blob/489ce0b5/framework/src/org/apache/cordova/IceCreamCordovaWebViewClient.java
----------------------------------------------------------------------
diff --git a/framework/src/org/apache/cordova/IceCreamCordovaWebViewClient.java b/framework/src/org/apache/cordova/IceCreamCordovaWebViewClient.java
index 2a686d8..4b3408c 100644
--- a/framework/src/org/apache/cordova/IceCreamCordovaWebViewClient.java
+++ b/framework/src/org/apache/cordova/IceCreamCordovaWebViewClient.java
@@ -46,16 +46,13 @@ public class IceCreamCordovaWebViewClient extends CordovaWebViewClient {
     public WebResourceResponse shouldInterceptRequest(WebView view, String url) {
         // We need to support the new DataResource intercepts without breaking the shouldInterceptRequest mechanism.
         DataResource dataResource = DataResource.initiateNewDataRequestForUri(url, this.appView.pluginManager, cordova,
-                new DataResourceContext("WebViewClient.shouldInterceptRequest", true /* this is from a browser request*/));
+                "WebViewClient.shouldInterceptRequest");
         url = dataResource.getUri().toString();
 
         // This mechanism is no longer needed due to the dataResource mechanism. It would be awesome to just get rid of it.
         //Check if plugins intercept the request
         WebResourceResponse ret = super.shouldInterceptRequest(view, url);
-//      The below bugfix is taken care of by the dataResource mechanism
-//        if(ret == null && (url.contains("?") || url.contains("#") || needsIceCreamSpaceInAssetUrlFix(url))){
-//            ret = generateWebResourceResponse(url);
-//        }
+
         if(ret == null) {
             try {
                ret = new WebResourceResponse(dataResource.getMimeType(), "UTF-8", dataResource.getInputStream());

http://git-wip-us.apache.org/repos/asf/cordova-android/blob/489ce0b5/framework/src/org/apache/cordova/api/CordovaPlugin.java
----------------------------------------------------------------------
diff --git a/framework/src/org/apache/cordova/api/CordovaPlugin.java b/framework/src/org/apache/cordova/api/CordovaPlugin.java
index 69f8fde..866677c 100644
--- a/framework/src/org/apache/cordova/api/CordovaPlugin.java
+++ b/framework/src/org/apache/cordova/api/CordovaPlugin.java
@@ -182,10 +182,10 @@ public class CordovaPlugin {
      *
      * @param dataResource          The resource to be loaded.
      * @param dataResourceContext   Context associated with the resource load
-     * @return                      Return a new DataResource if the plugin wants o assist in loading the request or null if it doesn't.
+     * @return                      Return a new DataResource if the plugin wants to assist in loading the request or null if it doesn't.
      */
     @TargetApi(Build.VERSION_CODES.HONEYCOMB)
-    public DataResource shouldInterceptDataResourceRequest(DataResource dataResource, DataResourceContext dataResourceContext) {
+    public DataResource handleDataResourceRequest(DataResource dataResource, DataResourceContext dataResourceContext) {
         return null;
     }
 

http://git-wip-us.apache.org/repos/asf/cordova-android/blob/489ce0b5/framework/src/org/apache/cordova/api/DataResource.java
----------------------------------------------------------------------
diff --git a/framework/src/org/apache/cordova/api/DataResource.java b/framework/src/org/apache/cordova/api/DataResource.java
index 38bf31b..5c1bb18 100644
--- a/framework/src/org/apache/cordova/api/DataResource.java
+++ b/framework/src/org/apache/cordova/api/DataResource.java
@@ -42,10 +42,13 @@ public class DataResource {
     private String mimeType;
     private Boolean writable;
     private File realFile;
-    private boolean retryLoad = true;
+    private boolean retryIsLoad = true;
+    private boolean retryOsLoad = true;
+    private boolean retryMimeTypeLoad = true;
+    private boolean retryWritableLoad = true;
+    private boolean retryRealFileLoad = true;
 
     public DataResource(CordovaInterface cordova, Uri uri) {
-        super();
         this.cordova = cordova;
         this.uri = uri;
     }
@@ -61,61 +64,61 @@ public class DataResource {
         // Uri is always provided
         return uri;
     }
-    public InputStream getIs() throws IOException {
-        if(is == null && retryLoad) {
+    public InputStream getInputStream() throws IOException {
+        if(is == null && retryIsLoad) {
             try {
                 is = FileHelper.getInputStreamFromUriString(uri.toString(), cordova);
             } finally {
                 // We failed loading once, don't try loading anymore
                 if(is == null) {
-                    retryLoad = false;
+                    retryIsLoad = false;
                 }
             }
         }
         return is;
     }
-    public OutputStream getOs() throws FileNotFoundException {
-        if(os == null && retryLoad) {
+    public OutputStream getOutputStream() throws FileNotFoundException {
+        if(os == null && retryOsLoad) {
             try {
                 os = FileHelper.getOutputStreamFromUriString(uri.toString(), cordova);
             } finally {
                 // We failed loading once, don't try loading anymore
                 if(os == null) {
-                    retryLoad = false;
+                    retryOsLoad = false;
                 }
             }
         }
         return os;
     }
     public String getMimeType() {
-        if(mimeType == null && retryLoad) {
+        if(mimeType == null && retryMimeTypeLoad) {
             try {
                 mimeType = FileHelper.getMimeType(uri.toString(), cordova);
             } finally {
                 // We failed loading once, don't try loading anymore
                 if(mimeType == null) {
-                    retryLoad = false;
+                    retryMimeTypeLoad = false;
                 }
             }
         }
         return mimeType;
     }
     public boolean isWritable() {
-        if(writable == null && retryLoad) {
+        if(writable == null && retryWritableLoad) {
             try {
                 writable = FileHelper.isUriWritable(uri.toString());
             } finally {
                 // We failed loading once, don't try loading anymore
                 if(writable == null) {
-                    retryLoad = false;
+                    retryWritableLoad = false;
                 }
             }
         }
         // default to false
-        return writable != null? writable.booleanValue() : false;
+        return writable != null && writable.booleanValue();
     }
     public File getRealFile() {
-        if(realFile == null && retryLoad) {
+        if(realFile == null && retryRealFileLoad) {
             try {
                 String realPath = FileHelper.getRealPath(uri, cordova);
                 if(realPath != null) {
@@ -124,7 +127,7 @@ public class DataResource {
             } finally {
                 // We failed loading once, don't try loading anymore
                 if(realFile == null) {
-                    retryLoad = false;
+                    retryRealFileLoad = false;
                 }
             }
         }
@@ -138,7 +141,7 @@ public class DataResource {
         return initiateNewDataRequestForUri(Uri.parse(uriString), pluginManager, cordova, requestSourceTag);
     }
     public static DataResource initiateNewDataRequestForUri(Uri uri, PluginManager pluginManager, CordovaInterface cordova, String requestSourceTag){
-        return initiateNewDataRequestForUri(uri, pluginManager, cordova, new DataResourceContext(requestSourceTag, false /* Assume, not a browser request by default */ ));
+        return initiateNewDataRequestForUri(uri, pluginManager, cordova, new DataResourceContext(requestSourceTag));
     }
     public static DataResource initiateNewDataRequestForUri(String uriString, PluginManager pluginManager, CordovaInterface cordova, DataResourceContext dataResourceContext){
      // if no protocol is specified, assume its file:
@@ -149,7 +152,7 @@ public class DataResource {
         DataResource dataResource = new DataResource(cordova, uri);
         if (pluginManager != null) {
             // get the resource as returned by plugins
-            dataResource = pluginManager.shouldInterceptDataResourceRequest(dataResource, dataResourceContext);
+            dataResource = pluginManager.handleDataResourceRequestWithPlugins(dataResource, dataResourceContext);
         }
         return dataResource;
     }

http://git-wip-us.apache.org/repos/asf/cordova-android/blob/489ce0b5/framework/src/org/apache/cordova/api/DataResourceContext.java
----------------------------------------------------------------------
diff --git a/framework/src/org/apache/cordova/api/DataResourceContext.java b/framework/src/org/apache/cordova/api/DataResourceContext.java
index 55bbc1d..9cfe7bc 100644
--- a/framework/src/org/apache/cordova/api/DataResourceContext.java
+++ b/framework/src/org/apache/cordova/api/DataResourceContext.java
@@ -30,15 +30,11 @@ public class DataResourceContext {
     // A tag associated with the source of this dataResourceContext
     private String source;
     // If needed, any data associated with core plugins can be a part of the context object
-    // This field indicates whether the request came from a browser network request
-    private boolean isFromBrowser;
     // If needed, any data associated with non core plugins  should store data in a Map so as to not clutter the context object
     private Map<String, Object> dataMap;
-    public DataResourceContext(String source, boolean isFromBrowser) {
-        super();
+    public DataResourceContext(String source) {
         this.requestId = new Random().nextInt();
         this.source = source;
-        this.isFromBrowser = isFromBrowser;
         this.dataMap = new HashMap<String, Object>();
     }
     public int getRequestId() {
@@ -47,9 +43,6 @@ public class DataResourceContext {
     public String getSource() {
         return source;
     }
-    public boolean isFromBrowser() {
-        return isFromBrowser;
-    }
     public Map<String, Object> getDataMap() {
         return dataMap;
     }

http://git-wip-us.apache.org/repos/asf/cordova-android/blob/489ce0b5/framework/src/org/apache/cordova/api/PluginManager.java
----------------------------------------------------------------------
diff --git a/framework/src/org/apache/cordova/api/PluginManager.java b/framework/src/org/apache/cordova/api/PluginManager.java
index 36ac357..e0ceabf 100755
--- a/framework/src/org/apache/cordova/api/PluginManager.java
+++ b/framework/src/org/apache/cordova/api/PluginManager.java
@@ -54,6 +54,7 @@ public class PluginManager {
     // Map URL schemes like foo: to plugins that want to handle those schemes
     // This would allow how all URLs are handled to be offloaded to a plugin
     protected HashMap<String, String> urlMap = new HashMap<String, String>();
+    private int MAX_REPITIONS = 1000;
 
     /**
      * Constructor.
@@ -409,13 +410,15 @@ public class PluginManager {
      * @param dataResourceContext   The context of the dataResource request
      * @return                      Return the resource request that will be loaded. The returned request may be modified or unchanged.
      */
-    public DataResource shouldInterceptDataResourceRequest(DataResource dataResource, DataResourceContext dataResourceContext){
+    public DataResource handleDataResourceRequestWithPlugins(DataResource dataResource, DataResourceContext dataResourceContext){
+        int repetitions = 0;
         boolean requestModified = true;
-        while(requestModified) {
+        while(requestModified && repetitions < MAX_REPITIONS) {
             requestModified = false;
+            repetitions ++;
             for (PluginEntry entry : this.entries.values()) {
                 if (entry.plugin != null) {
-                    DataResource ret = entry.plugin.shouldInterceptDataResourceRequest(dataResource, dataResourceContext);
+                    DataResource ret = entry.plugin.handleDataResourceRequest(dataResource, dataResourceContext);
                     if(ret != null) {
                         dataResource = ret;
                         requestModified = true;


[4/6] android commit: Revert "Revert "Added "DataResource" - allows many plugins to intercept a single request""

Posted by br...@apache.org.
Revert "Revert "Added "DataResource" - allows many plugins to intercept a single request""

This reverts commit 979d8e66f26d27a132d7514386b777fc8fc234f3.


Project: http://git-wip-us.apache.org/repos/asf/cordova-android/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-android/commit/df6d1107
Tree: http://git-wip-us.apache.org/repos/asf/cordova-android/tree/df6d1107
Diff: http://git-wip-us.apache.org/repos/asf/cordova-android/diff/df6d1107

Branch: refs/heads/dataresource
Commit: df6d110754db0c491d60f37aa97dd1503ea120a2
Parents: e6c02ca
Author: Braden Shepherdson <br...@gmail.com>
Authored: Fri Jun 7 10:17:39 2013 -0400
Committer: Braden Shepherdson <br...@gmail.com>
Committed: Fri Jun 14 14:52:09 2013 -0400

----------------------------------------------------------------------
 .../src/org/apache/cordova/FileHelper.java      |  58 ++++++-
 .../cordova/IceCreamCordovaWebViewClient.java   |  48 ++----
 .../org/apache/cordova/api/CordovaPlugin.java   |  14 ++
 .../org/apache/cordova/api/DataResource.java    | 156 +++++++++++++++++++
 .../apache/cordova/api/DataResourceContext.java |  56 +++++++
 .../org/apache/cordova/api/PluginManager.java   |  26 ++++
 6 files changed, 323 insertions(+), 35 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-android/blob/df6d1107/framework/src/org/apache/cordova/FileHelper.java
----------------------------------------------------------------------
diff --git a/framework/src/org/apache/cordova/FileHelper.java b/framework/src/org/apache/cordova/FileHelper.java
index ebbdc8d..e7bf98a 100644
--- a/framework/src/org/apache/cordova/FileHelper.java
+++ b/framework/src/org/apache/cordova/FileHelper.java
@@ -26,10 +26,11 @@ import org.apache.cordova.api.CordovaInterface;
 import org.apache.cordova.api.LOG;
 
 import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
 import java.io.IOException;
 import java.io.InputStream;
-import java.net.URLConnection;
-import java.util.Locale;
+import java.io.OutputStream;
 
 public class FileHelper {
     private static final String LOG_TAG = "FileUtils";
@@ -90,7 +91,7 @@ public class FileHelper {
      * @throws IOException
      */
     public static InputStream getInputStreamFromUriString(String uriString, CordovaInterface cordova) throws IOException {
-        if (uriString.startsWith("content")) {
+        if (uriString.startsWith("content:")) {
             Uri uri = Uri.parse(uriString);
             return cordova.getActivity().getContentResolver().openInputStream(uri);
         } else if (uriString.startsWith("file://")) {
@@ -110,6 +111,57 @@ public class FileHelper {
         }
     }
 
+    public static OutputStream getOutputStreamFromUriString(String uriString, CordovaInterface cordova) throws FileNotFoundException{
+        if (uriString.startsWith("content:")) {
+            Uri uri = Uri.parse(uriString);
+            return cordova.getActivity().getContentResolver().openOutputStream(uri);
+        } else if (uriString.startsWith("file:") && !uriString.startsWith("file:///android_asset/")) {
+            String realPath = uriString.substring(7);
+            return new FileOutputStream(realPath);
+        } else {
+            return null;
+        }
+    }
+    /**
+     * Returns whether the uri can be written to by openeing a File to that uri
+     *
+     * @param the URI to test
+     * @return boolean indicating whether the uri is writable
+     */
+    public static boolean isUriWritable(String uriString) {
+        String scheme = uriString.split(":")[0];
+        String writableSchemes[] = new String[]{ "content" };
+
+        if(scheme.equals("file")){
+            // special case file
+            if(uriString.startsWith("file:///android_asset/")){
+                return false;
+            } else {
+                return true;
+            }
+        }
+        for(int i = writableSchemes.length - 1; i >= 0 ; i--){
+            if(writableSchemes[i].equals(scheme)){
+                return true;
+            }
+        }
+        return false;
+    }
+
+    /**
+     * Ensures the "file://" prefix exists for the given string
+     * If the given URI string has a "file://" prefix, it is returned unchanged
+     *
+     * @param path - the path string to operate on
+     * @return a String with the "file://" scheme set
+     */
+    public static String insertFileProtocol(String path) {
+        if(!path.matches("^[a-z0-9+.-]+:.*")){
+            path = "file://" + path;
+        }
+        return path;
+    }
+
     /**
      * Removes the "file://" prefix from the given URI string, if applicable.
      * If the given URI string doesn't have a "file://" prefix, it is returned unchanged.

http://git-wip-us.apache.org/repos/asf/cordova-android/blob/df6d1107/framework/src/org/apache/cordova/IceCreamCordovaWebViewClient.java
----------------------------------------------------------------------
diff --git a/framework/src/org/apache/cordova/IceCreamCordovaWebViewClient.java b/framework/src/org/apache/cordova/IceCreamCordovaWebViewClient.java
index 847972e..d71fbe8 100644
--- a/framework/src/org/apache/cordova/IceCreamCordovaWebViewClient.java
+++ b/framework/src/org/apache/cordova/IceCreamCordovaWebViewClient.java
@@ -19,9 +19,10 @@
 package org.apache.cordova;
 
 import java.io.IOException;
-import java.io.InputStream;
 
 import org.apache.cordova.api.CordovaInterface;
+import org.apache.cordova.api.DataResource;
+import org.apache.cordova.api.DataResourceContext;
 import org.apache.cordova.api.LOG;
 
 import android.annotation.TargetApi;
@@ -43,41 +44,24 @@ public class IceCreamCordovaWebViewClient extends CordovaWebViewClient {
 
     @Override
     public WebResourceResponse shouldInterceptRequest(WebView view, String url) {
+        // We need to support the new DataResource intercepts without breaking the shouldInterceptRequest mechanism.
+        DataResource dataResource = DataResource.initiateNewDataRequestForUri(url, this.appView.pluginManager, cordova,
+                new DataResourceContext("WebViewClient.shouldInterceptRequest", true /* this is from a browser request*/));
+        url = dataResource.getUri().toString();
+
         //Check if plugins intercept the request
         WebResourceResponse ret = super.shouldInterceptRequest(view, url);
-        if(ret == null && (url.contains("?") || url.contains("#") || needsIceCreamSpaceInAssetUrlFix(url))){
-            ret = generateWebResourceResponse(url);
-        }
-        return ret;
-    }
-
-    private WebResourceResponse generateWebResourceResponse(String url) {
-        if (url.startsWith("file:///android_asset/")) {
-            String mimetype = FileHelper.getMimeType(url, cordova);
-
+//      The below bugfix is taken care of by the dataResource mechanism
+//        if(ret == null && (url.contains("?") || url.contains("#") || needsIceCreamSpaceInAssetUrlFix(url))){
+//            ret = generateWebResourceResponse(url);
+//        }
+        if(ret == null) {
             try {
-                InputStream stream = FileHelper.getInputStreamFromUriString(url, cordova);
-                WebResourceResponse response = new WebResourceResponse(mimetype, "UTF-8", stream);
-                return response;
-            } catch (IOException e) {
-                LOG.e("generateWebResourceResponse", e.getMessage(), e);
+               ret = new WebResourceResponse(dataResource.getMimeType(), "UTF-8", dataResource.getInputStream());
+            } catch(IOException e) {
+                LOG.e("IceCreamCordovaWebViewClient", "Error occurred while loading a file.", e);
             }
         }
-        return null;
-    }
-    
-    private static boolean needsIceCreamSpaceInAssetUrlFix(String url) {
-        if (!url.contains("%20")){
-            return false;
-        }
-
-        switch(android.os.Build.VERSION.SDK_INT){
-            case android.os.Build.VERSION_CODES.ICE_CREAM_SANDWICH:
-            case android.os.Build.VERSION_CODES.ICE_CREAM_SANDWICH_MR1:
-                return true;
-            default:
-                return false;
-        }
+        return ret;
     }
-    
 }

http://git-wip-us.apache.org/repos/asf/cordova-android/blob/df6d1107/framework/src/org/apache/cordova/api/CordovaPlugin.java
----------------------------------------------------------------------
diff --git a/framework/src/org/apache/cordova/api/CordovaPlugin.java b/framework/src/org/apache/cordova/api/CordovaPlugin.java
index 2b225e6..69f8fde 100644
--- a/framework/src/org/apache/cordova/api/CordovaPlugin.java
+++ b/framework/src/org/apache/cordova/api/CordovaPlugin.java
@@ -176,6 +176,20 @@ public class CordovaPlugin {
     }
 
     /**
+     * All plugins can now choose if they want to modify any uri requests. This includes all webview requests, opening of files, content uri's etc.
+     * This mechanism allows several plugins to modify the same request
+     * @param requestSource The source of the incoming request
+     *
+     * @param dataResource          The resource to be loaded.
+     * @param dataResourceContext   Context associated with the resource load
+     * @return                      Return a new DataResource if the plugin wants o assist in loading the request or null if it doesn't.
+     */
+    @TargetApi(Build.VERSION_CODES.HONEYCOMB)
+    public DataResource shouldInterceptDataResourceRequest(DataResource dataResource, DataResourceContext dataResourceContext) {
+        return null;
+    }
+
+    /**
      * Called when the WebView does a top-level navigation or refreshes.
      *
      * Plugins should stop any long-running processes and clean up internal state.

http://git-wip-us.apache.org/repos/asf/cordova-android/blob/df6d1107/framework/src/org/apache/cordova/api/DataResource.java
----------------------------------------------------------------------
diff --git a/framework/src/org/apache/cordova/api/DataResource.java b/framework/src/org/apache/cordova/api/DataResource.java
new file mode 100644
index 0000000..38bf31b
--- /dev/null
+++ b/framework/src/org/apache/cordova/api/DataResource.java
@@ -0,0 +1,156 @@
+/*
+       Licensed to the Apache Software Foundation (ASF) under one
+       or more contributor license agreements.  See the NOTICE file
+       distributed with this work for additional information
+       regarding copyright ownership.  The ASF licenses this file
+       to you under the Apache License, Version 2.0 (the
+       "License"); you may not use this file except in compliance
+       with the License.  You may obtain a copy of the License at
+
+         http://www.apache.org/licenses/LICENSE-2.0
+
+       Unless required by applicable law or agreed to in writing,
+       software distributed under the License is distributed on an
+       "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+       KIND, either express or implied.  See the License for the
+       specific language governing permissions and limitations
+       under the License.
+*/
+package org.apache.cordova.api;
+
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+
+import org.apache.cordova.FileHelper;
+
+import android.net.Uri;
+
+/*
+ * All requests to access files, browser network requests etc have to go through this class.
+ */
+public class DataResource {
+    private CordovaInterface cordova;
+
+    // Uri of the request. Always required.
+    private Uri uri;
+    // Remaining fields may or may not be null
+    private InputStream is;
+    private OutputStream os;
+    private String mimeType;
+    private Boolean writable;
+    private File realFile;
+    private boolean retryLoad = true;
+
+    public DataResource(CordovaInterface cordova, Uri uri) {
+        super();
+        this.cordova = cordova;
+        this.uri = uri;
+    }
+    public DataResource(CordovaInterface cordova, Uri uri, InputStream is,
+            OutputStream os, String mimeType, boolean writable, File realFile) {
+        this(cordova, uri);
+        this.is = is;
+        this.mimeType = mimeType;
+        this.writable = Boolean.valueOf(writable);
+        this.realFile = realFile;
+    }
+    public Uri getUri() {
+        // Uri is always provided
+        return uri;
+    }
+    public InputStream getIs() throws IOException {
+        if(is == null && retryLoad) {
+            try {
+                is = FileHelper.getInputStreamFromUriString(uri.toString(), cordova);
+            } finally {
+                // We failed loading once, don't try loading anymore
+                if(is == null) {
+                    retryLoad = false;
+                }
+            }
+        }
+        return is;
+    }
+    public OutputStream getOs() throws FileNotFoundException {
+        if(os == null && retryLoad) {
+            try {
+                os = FileHelper.getOutputStreamFromUriString(uri.toString(), cordova);
+            } finally {
+                // We failed loading once, don't try loading anymore
+                if(os == null) {
+                    retryLoad = false;
+                }
+            }
+        }
+        return os;
+    }
+    public String getMimeType() {
+        if(mimeType == null && retryLoad) {
+            try {
+                mimeType = FileHelper.getMimeType(uri.toString(), cordova);
+            } finally {
+                // We failed loading once, don't try loading anymore
+                if(mimeType == null) {
+                    retryLoad = false;
+                }
+            }
+        }
+        return mimeType;
+    }
+    public boolean isWritable() {
+        if(writable == null && retryLoad) {
+            try {
+                writable = FileHelper.isUriWritable(uri.toString());
+            } finally {
+                // We failed loading once, don't try loading anymore
+                if(writable == null) {
+                    retryLoad = false;
+                }
+            }
+        }
+        // default to false
+        return writable != null? writable.booleanValue() : false;
+    }
+    public File getRealFile() {
+        if(realFile == null && retryLoad) {
+            try {
+                String realPath = FileHelper.getRealPath(uri, cordova);
+                if(realPath != null) {
+                    realFile = new File(realPath);
+                }
+            } finally {
+                // We failed loading once, don't try loading anymore
+                if(realFile == null) {
+                    retryLoad = false;
+                }
+            }
+        }
+        return realFile;
+    }
+
+    // static instantiation methods
+    public static DataResource initiateNewDataRequestForUri(String uriString, PluginManager pluginManager, CordovaInterface cordova, String requestSourceTag){
+        // if no protocol is specified, assume its file:
+        uriString = FileHelper.insertFileProtocol(uriString);
+        return initiateNewDataRequestForUri(Uri.parse(uriString), pluginManager, cordova, requestSourceTag);
+    }
+    public static DataResource initiateNewDataRequestForUri(Uri uri, PluginManager pluginManager, CordovaInterface cordova, String requestSourceTag){
+        return initiateNewDataRequestForUri(uri, pluginManager, cordova, new DataResourceContext(requestSourceTag, false /* Assume, not a browser request by default */ ));
+    }
+    public static DataResource initiateNewDataRequestForUri(String uriString, PluginManager pluginManager, CordovaInterface cordova, DataResourceContext dataResourceContext){
+     // if no protocol is specified, assume its file:
+        uriString = FileHelper.insertFileProtocol(uriString);
+        return initiateNewDataRequestForUri(Uri.parse(uriString), pluginManager, cordova, dataResourceContext);
+    }
+    public static DataResource initiateNewDataRequestForUri(Uri uri, PluginManager pluginManager, CordovaInterface cordova, DataResourceContext dataResourceContext){
+        DataResource dataResource = new DataResource(cordova, uri);
+        if (pluginManager != null) {
+            // get the resource as returned by plugins
+            dataResource = pluginManager.shouldInterceptDataResourceRequest(dataResource, dataResourceContext);
+        }
+        return dataResource;
+    }
+}

http://git-wip-us.apache.org/repos/asf/cordova-android/blob/df6d1107/framework/src/org/apache/cordova/api/DataResourceContext.java
----------------------------------------------------------------------
diff --git a/framework/src/org/apache/cordova/api/DataResourceContext.java b/framework/src/org/apache/cordova/api/DataResourceContext.java
new file mode 100644
index 0000000..55bbc1d
--- /dev/null
+++ b/framework/src/org/apache/cordova/api/DataResourceContext.java
@@ -0,0 +1,56 @@
+/*
+       Licensed to the Apache Software Foundation (ASF) under one
+       or more contributor license agreements.  See the NOTICE file
+       distributed with this work for additional information
+       regarding copyright ownership.  The ASF licenses this file
+       to you under the Apache License, Version 2.0 (the
+       "License"); you may not use this file except in compliance
+       with the License.  You may obtain a copy of the License at
+
+         http://www.apache.org/licenses/LICENSE-2.0
+
+       Unless required by applicable law or agreed to in writing,
+       software distributed under the License is distributed on an
+       "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+       KIND, either express or implied.  See the License for the
+       specific language governing permissions and limitations
+       under the License.
+*/
+package org.apache.cordova.api;
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Random;
+/*
+ * Some context information associated with a DataRequest.
+ */
+public class DataResourceContext {
+    // A random id that is unique for a particular request.
+    private int requestId;
+    // A tag associated with the source of this dataResourceContext
+    private String source;
+    // If needed, any data associated with core plugins can be a part of the context object
+    // This field indicates whether the request came from a browser network request
+    private boolean isFromBrowser;
+    // If needed, any data associated with non core plugins  should store data in a Map so as to not clutter the context object
+    private Map<String, Object> dataMap;
+    public DataResourceContext(String source, boolean isFromBrowser) {
+        super();
+        this.requestId = new Random().nextInt();
+        this.source = source;
+        this.isFromBrowser = isFromBrowser;
+        this.dataMap = new HashMap<String, Object>();
+    }
+    public int getRequestId() {
+        return requestId;
+    }
+    public String getSource() {
+        return source;
+    }
+    public boolean isFromBrowser() {
+        return isFromBrowser;
+    }
+    public Map<String, Object> getDataMap() {
+        return dataMap;
+    }
+}

http://git-wip-us.apache.org/repos/asf/cordova-android/blob/df6d1107/framework/src/org/apache/cordova/api/PluginManager.java
----------------------------------------------------------------------
diff --git a/framework/src/org/apache/cordova/api/PluginManager.java b/framework/src/org/apache/cordova/api/PluginManager.java
index 71fc258..36ac357 100755
--- a/framework/src/org/apache/cordova/api/PluginManager.java
+++ b/framework/src/org/apache/cordova/api/PluginManager.java
@@ -400,4 +400,30 @@ public class PluginManager {
         LOG.e(TAG, "https://git-wip-us.apache.org/repos/asf?p=incubator-cordova-android.git;a=blob;f=framework/res/xml/plugins.xml");
         LOG.e(TAG, "=====================================================================================");
     }
+
+    /**
+     * Called when the any resource is going to be loaded - either from the webview, files or any other resource
+     *
+     *
+     * @param dataResource          The resource request to be loaded.
+     * @param dataResourceContext   The context of the dataResource request
+     * @return                      Return the resource request that will be loaded. The returned request may be modified or unchanged.
+     */
+    public DataResource shouldInterceptDataResourceRequest(DataResource dataResource, DataResourceContext dataResourceContext){
+        boolean requestModified = true;
+        while(requestModified) {
+            requestModified = false;
+            for (PluginEntry entry : this.entries.values()) {
+                if (entry.plugin != null) {
+                    DataResource ret = entry.plugin.shouldInterceptDataResourceRequest(dataResource, dataResourceContext);
+                    if(ret != null) {
+                        dataResource = ret;
+                        requestModified = true;
+                        break;
+                    }
+                }
+            }
+        }
+        return dataResource;
+    }
 }


[2/6] android commit: Revert "Trying to get DataResource reverted so that we don't have to worry about this blowing up while we're breaking things out. DataResource should be on a branch until it's ready!"

Posted by br...@apache.org.
Revert "Trying to get DataResource reverted so that we don't have to worry about this blowing up while we're breaking things out.  DataResource should be on a branch until it's ready!"

This reverts commit 3753e3f3532da0f4dbd08ee1c1b68cf5be6465b9.


Project: http://git-wip-us.apache.org/repos/asf/cordova-android/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-android/commit/e6c02ca9
Tree: http://git-wip-us.apache.org/repos/asf/cordova-android/tree/e6c02ca9
Diff: http://git-wip-us.apache.org/repos/asf/cordova-android/diff/e6c02ca9

Branch: refs/heads/dataresource
Commit: e6c02ca9b29ef0f2fc29fe031ee4d7d692fe84de
Parents: add1075
Author: Braden Shepherdson <br...@gmail.com>
Authored: Fri Jun 7 10:17:28 2013 -0400
Committer: Braden Shepherdson <br...@gmail.com>
Committed: Fri Jun 14 14:52:09 2013 -0400

----------------------------------------------------------------------
 framework/src/org/apache/cordova/FileUtils.java | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-android/blob/e6c02ca9/framework/src/org/apache/cordova/FileUtils.java
----------------------------------------------------------------------
diff --git a/framework/src/org/apache/cordova/FileUtils.java b/framework/src/org/apache/cordova/FileUtils.java
index a2f3cdc..b2e132e 100755
--- a/framework/src/org/apache/cordova/FileUtils.java
+++ b/framework/src/org/apache/cordova/FileUtils.java
@@ -949,7 +949,7 @@ public class FileUtils extends CordovaPlugin {
                             result = new PluginResult(PluginResult.Status.OK, bytes, true);
                             break;
                         default: // Base64.
-                            String contentType = FileHelper.getMimeType(filename, cordova);
+                            String contentType = dataResource.getMimeType();
                             byte[] base64 = Base64.encode(bytes, Base64.DEFAULT);
                             String s = "data:" + contentType + ";base64," + new String(base64, "US-ASCII");
                             result = new PluginResult(PluginResult.Status.OK, s);


[6/6] android commit: Fix URL encoded URLs

Posted by br...@apache.org.
Fix URL encoded URLs


Project: http://git-wip-us.apache.org/repos/asf/cordova-android/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-android/commit/aefb1295
Tree: http://git-wip-us.apache.org/repos/asf/cordova-android/tree/aefb1295
Diff: http://git-wip-us.apache.org/repos/asf/cordova-android/diff/aefb1295

Branch: refs/heads/dataresource
Commit: aefb12951b3be269ea59e750621f1868de06073e
Parents: 570173d
Author: Braden Shepherdson <br...@gmail.com>
Authored: Fri Jun 14 14:51:38 2013 -0400
Committer: Braden Shepherdson <br...@gmail.com>
Committed: Fri Jun 14 14:52:10 2013 -0400

----------------------------------------------------------------------
 framework/src/org/apache/cordova/FileHelper.java | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-android/blob/aefb1295/framework/src/org/apache/cordova/FileHelper.java
----------------------------------------------------------------------
diff --git a/framework/src/org/apache/cordova/FileHelper.java b/framework/src/org/apache/cordova/FileHelper.java
index 0d13c12..b64a5fa 100644
--- a/framework/src/org/apache/cordova/FileHelper.java
+++ b/framework/src/org/apache/cordova/FileHelper.java
@@ -18,6 +18,10 @@
  */
 package org.apache.cordova;
 
+import java.io.UnsupportedEncodingException;
+
+import java.net.URLDecoder;
+
 import android.database.Cursor;
 import android.net.Uri;
 import android.webkit.MimeTypeMap;
@@ -59,6 +63,19 @@ public class FileHelper {
             }
         } else if (uriString.startsWith("file://")) {
             realPath = uriString.substring(7);
+
+            int question = realPath.indexOf("?");
+            if (question > -1) {
+            	realPath = realPath.substring(0, question);
+            }
+
+            // Remove any URL encoding, for things like %20.
+            try {
+                realPath = URLDecoder.decode(realPath, "UTF-8");
+            } catch (UnsupportedEncodingException uee) {
+            }
+
+
             if (realPath.startsWith("/android_asset/")) {
                 LOG.e(LOG_TAG, "Cannot get real path for URI string %s because it is a file:///android_asset/ URI.", uriString);
                 realPath = null;


[3/6] android commit: Revert "Revert "Changed all usages of FileHelper to use the new DataResource mechanism.""

Posted by br...@apache.org.
Revert "Revert "Changed all usages of FileHelper to use the new DataResource mechanism.""

This reverts commit c5b37cc7e7d5bc96d98fd17ea70a165c08761682.


Project: http://git-wip-us.apache.org/repos/asf/cordova-android/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-android/commit/60a65e16
Tree: http://git-wip-us.apache.org/repos/asf/cordova-android/tree/60a65e16
Diff: http://git-wip-us.apache.org/repos/asf/cordova-android/diff/60a65e16

Branch: refs/heads/dataresource
Commit: 60a65e16a58f0b8dd9747d1886c3fbb3d70e060c
Parents: df6d110
Author: Braden Shepherdson <br...@gmail.com>
Authored: Fri Jun 7 10:17:40 2013 -0400
Committer: Braden Shepherdson <br...@gmail.com>
Committed: Fri Jun 14 14:52:09 2013 -0400

----------------------------------------------------------------------
 .../src/org/apache/cordova/AudioHandler.java    |  13 +-
 .../src/org/apache/cordova/CameraLauncher.java  |  61 ++++++----
 framework/src/org/apache/cordova/Capture.java   |  13 +-
 framework/src/org/apache/cordova/FileUtils.java | 119 +++++++------------
 .../cordova/IceCreamCordovaWebViewClient.java   |   1 +
 5 files changed, 100 insertions(+), 107 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-android/blob/60a65e16/framework/src/org/apache/cordova/AudioHandler.java
----------------------------------------------------------------------
diff --git a/framework/src/org/apache/cordova/AudioHandler.java b/framework/src/org/apache/cordova/AudioHandler.java
index fd8c9df..20c3c4e 100644
--- a/framework/src/org/apache/cordova/AudioHandler.java
+++ b/framework/src/org/apache/cordova/AudioHandler.java
@@ -20,7 +20,7 @@ package org.apache.cordova;
 
 import org.apache.cordova.api.CallbackContext;
 import org.apache.cordova.api.CordovaPlugin;
-
+import org.apache.cordova.api.DataResource;
 import android.content.Context;
 import android.media.AudioManager;
 
@@ -56,6 +56,11 @@ public class AudioHandler extends CordovaPlugin {
         this.pausedForPhone = new ArrayList<AudioPlayer>();
     }
 
+    public String getFilePath(String url, String source){
+        DataResource dataResource = DataResource.initiateNewDataRequestForUri(url, this.webView.pluginManager, cordova, source);
+        return dataResource.getRealFile().getPath();
+    }
+
     /**
      * Executes the request and returns PluginResult.
      * @param action 		The action to execute.
@@ -68,13 +73,13 @@ public class AudioHandler extends CordovaPlugin {
         String result = "";
 
         if (action.equals("startRecordingAudio")) {
-            this.startRecordingAudio(args.getString(0), FileHelper.stripFileProtocol(args.getString(1)));
+            this.startRecordingAudio(args.getString(0), getFilePath(args.getString(1), "AudioHandler.startRecordingAudio"));
         }
         else if (action.equals("stopRecordingAudio")) {
             this.stopRecordingAudio(args.getString(0));
         }
         else if (action.equals("startPlayingAudio")) {
-            this.startPlayingAudio(args.getString(0), FileHelper.stripFileProtocol(args.getString(1)));
+            this.startPlayingAudio(args.getString(0), getFilePath(args.getString(1), "AudioHandler.startPlayingAudio"));
         }
         else if (action.equals("seekToAudio")) {
             this.seekToAudio(args.getString(0), args.getInt(1));
@@ -102,7 +107,7 @@ public class AudioHandler extends CordovaPlugin {
         }
         else if (action.equals("create")) {
             String id = args.getString(0);
-            String src = FileHelper.stripFileProtocol(args.getString(1));
+            String src = getFilePath(args.getString(1), "AudioHandler.create");
             AudioPlayer audio = new AudioPlayer(this, id, src);
             this.players.put(id, audio);
         }

http://git-wip-us.apache.org/repos/asf/cordova-android/blob/60a65e16/framework/src/org/apache/cordova/CameraLauncher.java
----------------------------------------------------------------------
diff --git a/framework/src/org/apache/cordova/CameraLauncher.java b/framework/src/org/apache/cordova/CameraLauncher.java
index 8e43786..f434661 100755
--- a/framework/src/org/apache/cordova/CameraLauncher.java
+++ b/framework/src/org/apache/cordova/CameraLauncher.java
@@ -20,14 +20,15 @@ package org.apache.cordova;
 
 import java.io.ByteArrayOutputStream;
 import java.io.File;
-import java.io.FileInputStream;
 import java.io.FileNotFoundException;
 import java.io.FileOutputStream;
 import java.io.IOException;
+import java.io.InputStream;
 import java.io.OutputStream;
 
 import org.apache.cordova.api.CallbackContext;
 import org.apache.cordova.api.CordovaPlugin;
+import org.apache.cordova.api.DataResource;
 import org.apache.cordova.api.LOG;
 import org.apache.cordova.api.PluginResult;
 import org.json.JSONArray;
@@ -41,7 +42,6 @@ import android.graphics.Bitmap;
 import android.graphics.BitmapFactory;
 import android.graphics.Matrix;
 import android.graphics.Bitmap.CompressFormat;
-import android.graphics.Rect;
 import android.media.MediaScannerConnection;
 import android.media.MediaScannerConnection.MediaScannerConnectionClient;
 import android.net.Uri;
@@ -290,7 +290,7 @@ public class CameraLauncher extends CordovaPlugin implements MediaScannerConnect
 
                     // If sending base64 image back
                     if (destType == DATA_URL) {
-                        bitmap = getScaledBitmap(FileHelper.stripFileProtocol(imageUri.toString()));
+                        bitmap = getScaledBitmap(imageUri.toString());
                         if (bitmap == null) {
                             // Try to get the bitmap from intent.
                             bitmap = (Bitmap)intent.getExtras().get("data");
@@ -316,7 +316,9 @@ public class CameraLauncher extends CordovaPlugin implements MediaScannerConnect
                         if (this.saveToPhotoAlbum) {
                             Uri inputUri = getUriFromMediaStore();
                             //Just because we have a media URI doesn't mean we have a real file, we need to make it
-                            uri = Uri.fromFile(new File(FileHelper.getRealPath(inputUri, this.cordova)));
+                            DataResource dataResource = DataResource.initiateNewDataRequestForUri(inputUri, webView.pluginManager, cordova, "CameraLauncher.CameraExitIntent");
+                            File file = dataResource.getRealFile();
+                            uri = Uri.fromFile(file);
                         } else {
                             uri = Uri.fromFile(new File(DirectoryManager.getTempDirectoryPath(this.cordova.getActivity()), System.currentTimeMillis() + ".jpg"));
                         }
@@ -332,14 +334,15 @@ public class CameraLauncher extends CordovaPlugin implements MediaScannerConnect
 
                             this.callbackContext.success(uri.toString());
                         } else {
-                            bitmap = getScaledBitmap(FileHelper.stripFileProtocol(imageUri.toString()));
+                            bitmap = getScaledBitmap(imageUri.toString());
 
                             if (rotate != 0 && this.correctOrientation) {
                                 bitmap = getRotatedBitmap(rotate, bitmap, exif);
                             }
 
                             // Add compressed version of captured image to returned media store Uri
-                            OutputStream os = this.cordova.getActivity().getContentResolver().openOutputStream(uri);
+                            DataResource dataResource = DataResource.initiateNewDataRequestForUri(uri, webView.pluginManager, cordova, "CameraLauncher.CameraExitIntent");
+                            OutputStream os = dataResource.getOs();
                             bitmap.compress(Bitmap.CompressFormat.JPEG, this.mQuality, os);
                             os.close();
 
@@ -347,7 +350,7 @@ public class CameraLauncher extends CordovaPlugin implements MediaScannerConnect
                             if (this.encodingType == JPEG) {
                                 String exifPath;
                                 if (this.saveToPhotoAlbum) {
-                                    exifPath = FileHelper.getRealPath(uri, this.cordova);
+                                    exifPath = dataResource.getRealFile().getPath();
                                 } else {
                                     exifPath = uri.getPath();
                                 }
@@ -398,8 +401,9 @@ public class CameraLauncher extends CordovaPlugin implements MediaScannerConnect
                         this.callbackContext.success(uri.toString());
                     } else {
                         String uriString = uri.toString();
+                        DataResource dataResource = DataResource.initiateNewDataRequestForUri(uri, webView.pluginManager, cordova, "CameraLauncher.CameraExitIntent");
                         // Get the path to the image. Makes loading so much easier.
-                        String mimeType = FileHelper.getMimeType(uriString, this.cordova);
+                        String mimeType = dataResource.getMimeType();
                         // If we don't have a valid image so quit.
                         if (!("image/jpeg".equalsIgnoreCase(mimeType) || "image/png".equalsIgnoreCase(mimeType))) {
                         	Log.d(LOG_TAG, "I either have a null image path or bitmap");
@@ -440,7 +444,8 @@ public class CameraLauncher extends CordovaPlugin implements MediaScannerConnect
                                     // Create an ExifHelper to save the exif data that is lost during compression
                                     String resizePath = DirectoryManager.getTempDirectoryPath(this.cordova.getActivity()) + "/resize.jpg";
                                     // Some content: URIs do not map to file paths (e.g. picasa).
-                                    String realPath = FileHelper.getRealPath(uri, this.cordova);
+                                    File realFile = DataResource.initiateNewDataRequestForUri(uri, webView.pluginManager, cordova, "CameraLauncher.CameraExitIntent").getRealFile();
+                                    String realPath = realFile != null? realFile.getPath() : null;
                                     ExifHelper exif = new ExifHelper();
                                     if (realPath != null && this.encodingType == JPEG) {
                                         try {
@@ -534,8 +539,15 @@ public class CameraLauncher extends CordovaPlugin implements MediaScannerConnect
      */
     private void writeUncompressedImage(Uri uri) throws FileNotFoundException,
             IOException {
-        FileInputStream fis = new FileInputStream(FileHelper.stripFileProtocol(imageUri.toString()));
-        OutputStream os = this.cordova.getActivity().getContentResolver().openOutputStream(uri);
+        DataResource inputDataResource = DataResource.initiateNewDataRequestForUri(imageUri, webView.pluginManager, cordova, "CameraLauncher.writeUncompressedImage");
+        InputStream fis = inputDataResource.getIs();
+        DataResource outDataResource = DataResource.initiateNewDataRequestForUri(uri, webView.pluginManager, cordova, "CameraLauncher.writeUncompressedImage");
+        OutputStream os = outDataResource.getOs();
+        if(fis == null) {
+            throw new FileNotFoundException("Could not get the input file");
+        } else if(os == null) {
+            throw new FileNotFoundException("Could not get the output file");
+        }
         byte[] buffer = new byte[4096];
         int len;
         while ((len = fis.read(buffer)) != -1) {
@@ -578,14 +590,15 @@ public class CameraLauncher extends CordovaPlugin implements MediaScannerConnect
      */
     private Bitmap getScaledBitmap(String imageUrl) throws IOException {
         // If no new width or height were specified return the original bitmap
+        DataResource dataResource = DataResource.initiateNewDataRequestForUri(imageUrl, webView.pluginManager, cordova, "CameraLauncher.getScaledBitmap");
         if (this.targetWidth <= 0 && this.targetHeight <= 0) {
-            return BitmapFactory.decodeStream(FileHelper.getInputStreamFromUriString(imageUrl, cordova));
+            return BitmapFactory.decodeStream(dataResource.getIs());
         }
 
         // figure out the original width and height of the image
         BitmapFactory.Options options = new BitmapFactory.Options();
         options.inJustDecodeBounds = true;
-        BitmapFactory.decodeStream(FileHelper.getInputStreamFromUriString(imageUrl, cordova), null, options);
+        BitmapFactory.decodeStream(dataResource.getIs(), null, options);
         
         //CB-2292: WTF? Why is the width null?
         if(options.outWidth == 0 || options.outHeight == 0)
@@ -599,7 +612,7 @@ public class CameraLauncher extends CordovaPlugin implements MediaScannerConnect
         // Load in the smallest bitmap possible that is closest to the size we want
         options.inJustDecodeBounds = false;
         options.inSampleSize = calculateSampleSize(options.outWidth, options.outHeight, this.targetWidth, this.targetHeight);
-        Bitmap unscaledBitmap = BitmapFactory.decodeStream(FileHelper.getInputStreamFromUriString(imageUrl, cordova), null, options);
+        Bitmap unscaledBitmap = BitmapFactory.decodeStream(dataResource.getIs(), null, options);
         if (unscaledBitmap == null) {
             return null;
         }
@@ -698,16 +711,20 @@ public class CameraLauncher extends CordovaPlugin implements MediaScannerConnect
             bitmap.recycle();
         }
 
-        // Clean up initial camera-written image file.
-        (new File(FileHelper.stripFileProtocol(oldImage.toString()))).delete();
+        DataResource dataResource = DataResource.initiateNewDataRequestForUri(oldImage, webView.pluginManager, cordova, "CameraLauncher.cleanup");
+        File file = dataResource.getRealFile();
+        if(file != null) {
+            // Clean up initial camera-written image file.
+            file.delete();
 
-        checkForDuplicateImage(imageType);
-        // Scan for the gallery to update pic refs in gallery
-        if (this.saveToPhotoAlbum && newImage != null) {
-            this.scanForGallery(newImage);
-        }
+            checkForDuplicateImage(imageType);
+            // Scan for the gallery to update pic refs in gallery
+            if (this.saveToPhotoAlbum && newImage != null) {
+                this.scanForGallery(newImage);
+            }
 
-        System.gc();
+            System.gc();
+        }
     }
 
     /**

http://git-wip-us.apache.org/repos/asf/cordova-android/blob/60a65e16/framework/src/org/apache/cordova/Capture.java
----------------------------------------------------------------------
diff --git a/framework/src/org/apache/cordova/Capture.java b/framework/src/org/apache/cordova/Capture.java
index 5f737ca..d7ad419 100644
--- a/framework/src/org/apache/cordova/Capture.java
+++ b/framework/src/org/apache/cordova/Capture.java
@@ -26,6 +26,7 @@ import java.io.OutputStream;
 import android.os.Build;
 import org.apache.cordova.api.CallbackContext;
 import org.apache.cordova.api.CordovaPlugin;
+import org.apache.cordova.api.DataResource;
 import org.apache.cordova.api.LOG;
 import org.apache.cordova.api.PluginResult;
 import org.json.JSONArray;
@@ -129,7 +130,8 @@ public class Capture extends CordovaPlugin {
         // If the mimeType isn't set the rest will fail
         // so let's see if we can determine it.
         if (mimeType == null || mimeType.equals("") || "null".equals(mimeType)) {
-            mimeType = FileHelper.getMimeType(filePath, cordova);
+            DataResource dataResource = DataResource.initiateNewDataRequestForUri(filePath, webView.pluginManager, cordova, "Capture.dataResource");
+            mimeType = dataResource.getMimeType();
         }
         Log.d(LOG_TAG, "Mime type = " + mimeType);
 
@@ -156,7 +158,8 @@ public class Capture extends CordovaPlugin {
     private JSONObject getImageData(String filePath, JSONObject obj) throws JSONException {
         BitmapFactory.Options options = new BitmapFactory.Options();
         options.inJustDecodeBounds = true;
-        BitmapFactory.decodeFile(FileHelper.stripFileProtocol(filePath), options);
+        DataResource dataResource = DataResource.initiateNewDataRequestForUri(filePath, webView.pluginManager, cordova, "Capture.getImageData");
+        BitmapFactory.decodeFile(dataResource.getRealFile().getPath(), options);
         obj.put("height", options.outHeight);
         obj.put("width", options.outWidth);
         return obj;
@@ -348,7 +351,8 @@ public class Capture extends CordovaPlugin {
      * @throws IOException
      */
     private JSONObject createMediaFile(Uri data) {
-        File fp = new File(FileHelper.getRealPath(data, this.cordova));
+        DataResource dataResource = DataResource.initiateNewDataRequestForUri(data, webView.pluginManager, cordova, "Capture.createMediaFile");
+        File fp = dataResource.getRealFile();
         JSONObject obj = new JSONObject();
 
         try {
@@ -358,6 +362,7 @@ public class Capture extends CordovaPlugin {
             // Because of an issue with MimeTypeMap.getMimeTypeFromExtension() all .3gpp files
             // are reported as video/3gpp. I'm doing this hacky check of the URI to see if it
             // is stored in the audio or video content store.
+
             if (fp.getAbsoluteFile().toString().endsWith(".3gp") || fp.getAbsoluteFile().toString().endsWith(".3gpp")) {
                 if (data.toString().contains("/audio/")) {
                     obj.put("type", AUDIO_3GPP);
@@ -365,7 +370,7 @@ public class Capture extends CordovaPlugin {
                     obj.put("type", VIDEO_3GPP);
                 }
             } else {
-                obj.put("type", FileHelper.getMimeType(fp.getAbsolutePath(), cordova));
+                obj.put("type", dataResource.getMimeType());
             }
 
             obj.put("lastModifiedDate", fp.lastModified());

http://git-wip-us.apache.org/repos/asf/cordova-android/blob/60a65e16/framework/src/org/apache/cordova/FileUtils.java
----------------------------------------------------------------------
diff --git a/framework/src/org/apache/cordova/FileUtils.java b/framework/src/org/apache/cordova/FileUtils.java
index b2e132e..adf788e 100755
--- a/framework/src/org/apache/cordova/FileUtils.java
+++ b/framework/src/org/apache/cordova/FileUtils.java
@@ -18,8 +18,6 @@
  */
 package org.apache.cordova;
 
-import android.database.Cursor;
-import android.net.Uri;
 import android.os.Environment;
 import android.provider.MediaStore;
 import android.util.Base64;
@@ -27,6 +25,7 @@ import android.util.Log;
 
 import org.apache.cordova.api.CallbackContext;
 import org.apache.cordova.api.CordovaPlugin;
+import org.apache.cordova.api.DataResource;
 import org.apache.cordova.api.PluginResult;
 import org.apache.cordova.file.EncodingException;
 import org.apache.cordova.file.FileExistsException;
@@ -46,8 +45,6 @@ import java.io.IOException;
 import java.io.InputStream;
 import java.io.RandomAccessFile;
 import java.net.MalformedURLException;
-import java.net.URL;
-import java.net.URLDecoder;
 import java.nio.channels.FileChannel;
 
 /**
@@ -234,7 +231,7 @@ public class FileUtils extends CordovaPlugin {
      * @param filePath the path to check
      */
     private void notifyDelete(String filePath) {
-        String newFilePath = FileHelper.getRealPath(filePath, cordova);
+        String newFilePath = DataResource.initiateNewDataRequestForUri(filePath, webView.pluginManager, cordova, "FileUtils.notifyDelete").getRealFile().getPath();
         try {
             this.cordova.getActivity().getContentResolver().delete(MediaStore.Images.Media.EXTERNAL_CONTENT_URI,
                     MediaStore.Images.Media.DATA + " = ?",
@@ -256,37 +253,10 @@ public class FileUtils extends CordovaPlugin {
      * @throws IOException if the user can't read the file
      * @throws JSONException
      */
-    @SuppressWarnings("deprecation")
     private JSONObject resolveLocalFileSystemURI(String url) throws IOException, JSONException {
-        String decoded = URLDecoder.decode(url, "UTF-8");
+        File fp = DataResource.initiateNewDataRequestForUri(url, webView.pluginManager, cordova, "FileUtils.resolveLocalFileSystemURI").getRealFile();
 
-        File fp = null;
-
-        // Handle the special case where you get an Android content:// uri.
-        if (decoded.startsWith("content:")) {
-            Cursor cursor = this.cordova.getActivity().managedQuery(Uri.parse(decoded), new String[] { MediaStore.Images.Media.DATA }, null, null, null);
-            // Note: MediaStore.Images/Audio/Video.Media.DATA is always "_data"
-            int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
-            cursor.moveToFirst();
-            fp = new File(cursor.getString(column_index));
-        } else {
-            // Test to see if this is a valid URL first
-            @SuppressWarnings("unused")
-            URL testUrl = new URL(decoded);
-
-            if (decoded.startsWith("file://")) {
-                int questionMark = decoded.indexOf("?");
-                if (questionMark < 0) {
-                    fp = new File(decoded.substring(7, decoded.length()));
-                } else {
-                    fp = new File(decoded.substring(7, questionMark));
-                }
-            } else {
-                fp = new File(decoded);
-            }
-        }
-
-        if (!fp.exists()) {
+        if (fp == null || !fp.exists()) {
             throw new FileNotFoundException();
         }
         if (!fp.canRead()) {
@@ -304,9 +274,9 @@ public class FileUtils extends CordovaPlugin {
      * @throws JSONException
      */
     private JSONArray readEntries(String fileName) throws FileNotFoundException, JSONException {
-        File fp = createFileObject(fileName);
+        File fp = DataResource.initiateNewDataRequestForUri(fileName, webView.pluginManager, cordova, "FileUtils.readEntries").getRealFile();
 
-        if (!fp.exists()) {
+        if (fp == null || !fp.exists()) {
             // The directory we are listing doesn't exist so we should fail.
             throw new FileNotFoundException();
         }
@@ -341,8 +311,10 @@ public class FileUtils extends CordovaPlugin {
      * @throws FileExistsException
      */
     private JSONObject transferTo(String fileName, String newParent, String newName, boolean move) throws JSONException, NoModificationAllowedException, IOException, InvalidModificationException, EncodingException, FileExistsException {
-        String newFileName = FileHelper.getRealPath(fileName, cordova);
-        newParent = FileHelper.getRealPath(newParent, cordova);
+        DataResource dataResourceFrom = DataResource.initiateNewDataRequestForUri(fileName, webView.pluginManager, cordova, "FileUtils.transferTo");
+        String newFileName = dataResourceFrom.getRealFile().getPath();
+        DataResource dataResourceTo = DataResource.initiateNewDataRequestForUri(newParent, webView.pluginManager, cordova, "FileUtils.transferTo");
+        newParent = dataResourceTo.getRealFile().getPath();
 
         // Check for invalid file name
         if (newName != null && newName.contains(":")) {
@@ -613,7 +585,7 @@ public class FileUtils extends CordovaPlugin {
      * @throws FileExistsException
      */
     private boolean removeRecursively(String filePath) throws FileExistsException {
-        File fp = createFileObject(filePath);
+        File fp = DataResource.initiateNewDataRequestForUri(filePath, webView.pluginManager, cordova, "FileUtils.readEntries").getRealFile();
 
         // You can't delete the root directory.
         if (atRootDirectory(filePath)) {
@@ -654,7 +626,7 @@ public class FileUtils extends CordovaPlugin {
      * @throws InvalidModificationException
      */
     private boolean remove(String filePath) throws NoModificationAllowedException, InvalidModificationException {
-        File fp = createFileObject(filePath);
+        File fp = DataResource.initiateNewDataRequestForUri(filePath, webView.pluginManager, cordova, "FileUtils.readEntries").getRealFile();
 
         // You can't delete the root directory.
         if (atRootDirectory(filePath)) {
@@ -698,7 +670,8 @@ public class FileUtils extends CordovaPlugin {
             throw new EncodingException("This file has a : in it's name");
         }
 
-        File fp = createFileObject(dirPath, fileName);
+        String filePath = getFullFilePath(dirPath, fileName);
+        File fp = DataResource.initiateNewDataRequestForUri(filePath, webView.pluginManager, cordova, "FileUtils.getFile").getRealFile();
 
         if (create) {
             if (exclusive && fp.exists()) {
@@ -740,15 +713,14 @@ public class FileUtils extends CordovaPlugin {
      * @param fileName new file name
      * @return
      */
-    private File createFileObject(String dirPath, String fileName) {
-        File fp = null;
+    private String getFullFilePath(String dirPath, String fileName) {
         if (fileName.startsWith("/")) {
-            fp = new File(fileName);
+            return fileName;
         } else {
-            dirPath = FileHelper.getRealPath(dirPath, cordova);
-            fp = new File(dirPath + File.separator + fileName);
+            DataResource dataResource = DataResource.initiateNewDataRequestForUri(dirPath, webView.pluginManager, cordova, "FileUtils.getFullFilePath");
+            dirPath = dataResource.getRealFile().getPath();
+            return dirPath + File.separator + fileName;
         }
-        return fp;
     }
 
     /**
@@ -760,12 +732,13 @@ public class FileUtils extends CordovaPlugin {
      * @throws JSONException
      */
     private JSONObject getParent(String filePath) throws JSONException {
-        filePath = FileHelper.getRealPath(filePath, cordova);
+        DataResource dataResource = DataResource.initiateNewDataRequestForUri(filePath, webView.pluginManager, cordova, "FileUtils.getParent");
+        filePath = dataResource.getRealFile().getPath();
 
         if (atRootDirectory(filePath)) {
             return getEntry(filePath);
         }
-        return getEntry(new File(filePath).getParent());
+        return getEntry(dataResource.getRealFile().getParent());
     }
 
     /**
@@ -776,7 +749,7 @@ public class FileUtils extends CordovaPlugin {
      * @return true if we are at the root, false otherwise.
      */
     private boolean atRootDirectory(String filePath) {
-        filePath = FileHelper.getRealPath(filePath, cordova);
+        filePath = DataResource.initiateNewDataRequestForUri(filePath, webView.pluginManager, cordova, "FileUtils.atRootDirectory").getRealFile().getPath();
 
         if (filePath.equals(Environment.getExternalStorageDirectory().getAbsolutePath() + "/Android/data/" + cordova.getActivity().getPackageName() + "/cache") ||
                 filePath.equals(Environment.getExternalStorageDirectory().getAbsolutePath()) ||
@@ -787,19 +760,6 @@ public class FileUtils extends CordovaPlugin {
     }
 
     /**
-     * Create a File object from the passed in path
-     *
-     * @param filePath
-     * @return
-     */
-    private File createFileObject(String filePath) {
-        filePath = FileHelper.getRealPath(filePath, cordova);
-
-        File file = new File(filePath);
-        return file;
-    }
-
-    /**
      * Look up metadata about this entry.
      *
      * @param filePath to entry
@@ -807,9 +767,9 @@ public class FileUtils extends CordovaPlugin {
      * @throws FileNotFoundException
      */
     private long getMetadata(String filePath) throws FileNotFoundException {
-        File file = createFileObject(filePath);
+        File file = DataResource.initiateNewDataRequestForUri(filePath, webView.pluginManager, cordova, "FileUtils.getMetadata").getRealFile();
 
-        if (!file.exists()) {
+        if (file == null || !file.exists()) {
             throw new FileNotFoundException("Failed to find file in getMetadata");
         }
 
@@ -825,15 +785,16 @@ public class FileUtils extends CordovaPlugin {
      * @throws JSONException
      */
     private JSONObject getFileMetadata(String filePath) throws FileNotFoundException, JSONException {
-        File file = createFileObject(filePath);
+        DataResource dataResource = DataResource.initiateNewDataRequestForUri(filePath, webView.pluginManager, cordova, "FileUtils.getMetadata");
+        File file = dataResource.getRealFile();
 
-        if (!file.exists()) {
+        if (file == null || !file.exists()) {
             throw new FileNotFoundException("File: " + filePath + " does not exist.");
         }
 
         JSONObject metadata = new JSONObject();
         metadata.put("size", file.length());
-        metadata.put("type", FileHelper.getMimeType(filePath, cordova));
+        metadata.put("type", dataResource.getMimeType());
         metadata.put("name", file.getName());
         metadata.put("fullPath", filePath);
         metadata.put("lastModifiedDate", file.lastModified());
@@ -935,7 +896,8 @@ public class FileUtils extends CordovaPlugin {
         this.cordova.getThreadPool().execute(new Runnable() {
             public void run() {
                 try {
-                    byte[] bytes = readAsBinaryHelper(filename, start, end);
+                    DataResource dataResource = DataResource.initiateNewDataRequestForUri(filename, webView.pluginManager, cordova, "FileUtils.readFileAs");
+                    byte[] bytes = readAsBinaryHelper(dataResource.getIs(), start, end);
                     
                     PluginResult result;
                     switch (resultType) {
@@ -976,10 +938,9 @@ public class FileUtils extends CordovaPlugin {
      * @return                  Contents of the file as a byte[].
      * @throws IOException
      */
-    private byte[] readAsBinaryHelper(String filename, int start, int end) throws IOException {
+    private byte[] readAsBinaryHelper(InputStream inputStream, int start, int end) throws IOException {
         int numBytesToRead = end - start;
         byte[] bytes = new byte[numBytesToRead];
-        InputStream inputStream = FileHelper.getInputStreamFromUriString(filename, cordova);
         int numBytesRead = 0;
 
         if (start > 0) {
@@ -1009,7 +970,8 @@ public class FileUtils extends CordovaPlugin {
             throw new NoModificationAllowedException("Couldn't write to file given its content URI");
         }
 
-        filename = FileHelper.getRealPath(filename, cordova);
+        DataResource dataResource = DataResource.initiateNewDataRequestForUri(filename, webView.pluginManager, cordova, "FileUtils.write");
+        filename = dataResource.getRealFile().getPath();
 
         boolean append = false;
         if (offset > 0) {
@@ -1043,13 +1005,16 @@ public class FileUtils extends CordovaPlugin {
      * @throws NoModificationAllowedException
      */
     private long truncateFile(String filename, long size) throws FileNotFoundException, IOException, NoModificationAllowedException {
-        if (filename.startsWith("content://")) {
-            throw new NoModificationAllowedException("Couldn't truncate file given its content URI");
+        DataResource dataResource = DataResource.initiateNewDataRequestForUri(filename, webView.pluginManager, cordova, "FileUtils.truncateFile");
+        if(!dataResource.isWritable()) {
+            throw new NoModificationAllowedException("Couldn't truncate file as it is not writable");
+        }
+        File file = dataResource.getRealFile();
+        if(file == null) {
+            throw new FileNotFoundException("Couldn't get the file");
         }
 
-        filename = FileHelper.getRealPath(filename, cordova);
-
-        RandomAccessFile raf = new RandomAccessFile(filename, "rw");
+        RandomAccessFile raf = new RandomAccessFile(file, "rw");
         try {
             if (raf.length() >= size) {
                 FileChannel channel = raf.getChannel();

http://git-wip-us.apache.org/repos/asf/cordova-android/blob/60a65e16/framework/src/org/apache/cordova/IceCreamCordovaWebViewClient.java
----------------------------------------------------------------------
diff --git a/framework/src/org/apache/cordova/IceCreamCordovaWebViewClient.java b/framework/src/org/apache/cordova/IceCreamCordovaWebViewClient.java
index d71fbe8..2a686d8 100644
--- a/framework/src/org/apache/cordova/IceCreamCordovaWebViewClient.java
+++ b/framework/src/org/apache/cordova/IceCreamCordovaWebViewClient.java
@@ -49,6 +49,7 @@ public class IceCreamCordovaWebViewClient extends CordovaWebViewClient {
                 new DataResourceContext("WebViewClient.shouldInterceptRequest", true /* this is from a browser request*/));
         url = dataResource.getUri().toString();
 
+        // This mechanism is no longer needed due to the dataResource mechanism. It would be awesome to just get rid of it.
         //Check if plugins intercept the request
         WebResourceResponse ret = super.shouldInterceptRequest(view, url);
 //      The below bugfix is taken care of by the dataResource mechanism


[5/6] android commit: Revert "Revert "DataResource bugfix WebviewClient logs error for http urls.""

Posted by br...@apache.org.
Revert "Revert "DataResource bugfix WebviewClient logs error for http urls.""

This reverts commit 2f9c512b5942ae2c04002fe8c5581b6d514b8c52.


Project: http://git-wip-us.apache.org/repos/asf/cordova-android/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-android/commit/570173df
Tree: http://git-wip-us.apache.org/repos/asf/cordova-android/tree/570173df
Diff: http://git-wip-us.apache.org/repos/asf/cordova-android/diff/570173df

Branch: refs/heads/dataresource
Commit: 570173df5d7137b72bc453b67e3d93654e1b0776
Parents: 489ce0b
Author: Braden Shepherdson <br...@gmail.com>
Authored: Fri Jun 7 10:17:44 2013 -0400
Committer: Braden Shepherdson <br...@gmail.com>
Committed: Fri Jun 14 14:52:10 2013 -0400

----------------------------------------------------------------------
 framework/src/org/apache/cordova/FileHelper.java             | 2 +-
 .../src/org/apache/cordova/IceCreamCordovaWebViewClient.java | 8 +++++++-
 2 files changed, 8 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-android/blob/570173df/framework/src/org/apache/cordova/FileHelper.java
----------------------------------------------------------------------
diff --git a/framework/src/org/apache/cordova/FileHelper.java b/framework/src/org/apache/cordova/FileHelper.java
index 69c7f48..0d13c12 100644
--- a/framework/src/org/apache/cordova/FileHelper.java
+++ b/framework/src/org/apache/cordova/FileHelper.java
@@ -107,7 +107,7 @@ public class FileHelper {
                 return new FileInputStream(getRealPath(uriString, cordova));
             }
         } else {
-            return new FileInputStream(getRealPath(uriString, cordova));
+            return null;
         }
     }
 

http://git-wip-us.apache.org/repos/asf/cordova-android/blob/570173df/framework/src/org/apache/cordova/IceCreamCordovaWebViewClient.java
----------------------------------------------------------------------
diff --git a/framework/src/org/apache/cordova/IceCreamCordovaWebViewClient.java b/framework/src/org/apache/cordova/IceCreamCordovaWebViewClient.java
index 4b3408c..d68b6b8 100644
--- a/framework/src/org/apache/cordova/IceCreamCordovaWebViewClient.java
+++ b/framework/src/org/apache/cordova/IceCreamCordovaWebViewClient.java
@@ -19,6 +19,7 @@
 package org.apache.cordova;
 
 import java.io.IOException;
+import java.io.InputStream;
 
 import org.apache.cordova.api.CordovaInterface;
 import org.apache.cordova.api.DataResource;
@@ -55,7 +56,12 @@ public class IceCreamCordovaWebViewClient extends CordovaWebViewClient {
 
         if(ret == null) {
             try {
-               ret = new WebResourceResponse(dataResource.getMimeType(), "UTF-8", dataResource.getInputStream());
+                InputStream is = dataResource.getInputStream();
+                if(is != null) {
+                    String mimeType = dataResource.getMimeType();
+                    // If we don't know how to open this file, let the browser continue loading
+                    ret = new WebResourceResponse(mimeType, "UTF-8", is);
+                }
             } catch(IOException e) {
                 LOG.e("IceCreamCordovaWebViewClient", "Error occurred while loading a file.", e);
             }