mirror of
https://github.com/apache/cordova-android.git
synced 2025-01-19 15:12:51 +08:00
CB-3504: Fixing issue with the use of WebResourceResponse on pre-Honeycomb devices.
This commit is contained in:
parent
add107583f
commit
90f83db9c9
@ -211,35 +211,7 @@ 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
|
||||||
|
@ -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,11 +46,27 @@ 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/")) {
|
||||||
|
Loading…
Reference in New Issue
Block a user