CB-3504: Fixing issue with the use of WebResourceResponse on pre-Honeycomb devices.

This commit is contained in:
Joe Bowser 2013-06-14 15:29:30 -07:00
parent add107583f
commit 90f83db9c9
2 changed files with 18 additions and 29 deletions

View File

@ -212,34 +212,6 @@ public class CordovaWebViewClient extends WebViewClient {
return true; return true;
} }
/**
* Check for intercepting any requests for resources.
* This includes images and scripts and so on, not just top-level pages.
* @param view The WebView.
* @param url The URL to be loaded.
* @return Either null to proceed as normal, or a WebResourceResponse.
*/
@Override
public WebResourceResponse shouldInterceptRequest(WebView view, String url) {
//If something isn't whitelisted, just send a blank response
if(!Config.isUrlWhiteListed(url) && (url.startsWith("http://") || url.startsWith("https://")))
{
return getWhitelistResponse();
}
if (this.appView.pluginManager != null) {
return this.appView.pluginManager.shouldInterceptRequest(url);
}
return null;
}
private WebResourceResponse getWhitelistResponse()
{
WebResourceResponse emptyResponse;
String empty = "";
ByteArrayInputStream data = new ByteArrayInputStream(empty.getBytes());
return new WebResourceResponse("text/plain", "UTF-8", data);
}
/** /**
* On received http auth request. * On received http auth request.
* The method reacts on all registered authentication tokens. There is one and only one authentication token for any host + realm combination * The method reacts on all registered authentication tokens. There is one and only one authentication token for any host + realm combination

View File

@ -18,6 +18,7 @@
*/ */
package org.apache.cordova; package org.apache.cordova;
import java.io.ByteArrayInputStream;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
@ -45,12 +46,28 @@ public class IceCreamCordovaWebViewClient extends CordovaWebViewClient {
public WebResourceResponse shouldInterceptRequest(WebView view, String url) { public WebResourceResponse shouldInterceptRequest(WebView view, String url) {
//Check if plugins intercept the request //Check if plugins intercept the request
WebResourceResponse ret = super.shouldInterceptRequest(view, url); WebResourceResponse ret = super.shouldInterceptRequest(view, url);
if(ret == null && (url.contains("?") || url.contains("#") || needsIceCreamSpaceInAssetUrlFix(url))){
if(!Config.isUrlWhiteListed(url) && (url.startsWith("http://") || url.startsWith("https://")))
{
ret = getWhitelistResponse();
}
else if(ret == null && (url.contains("?") || url.contains("#") || needsIceCreamSpaceInAssetUrlFix(url))){
ret = generateWebResourceResponse(url); ret = generateWebResourceResponse(url);
} }
else if (ret == null && this.appView.pluginManager != null) {
ret = this.appView.pluginManager.shouldInterceptRequest(url);
}
return ret; return ret;
} }
private WebResourceResponse getWhitelistResponse()
{
WebResourceResponse emptyResponse;
String empty = "";
ByteArrayInputStream data = new ByteArrayInputStream(empty.getBytes());
return new WebResourceResponse("text/plain", "UTF-8", data);
}
private WebResourceResponse generateWebResourceResponse(String url) { private WebResourceResponse generateWebResourceResponse(String url) {
if (url.startsWith("file:///android_asset/")) { if (url.startsWith("file:///android_asset/")) {
String mimetype = FileHelper.getMimeType(url, cordova); String mimetype = FileHelper.getMimeType(url, cordova);