mirror of
https://github.com/apache/cordova-plugin-file-transfer.git
synced 2026-04-10 00:00:03 +08:00
feat!: remove deprecated whitelist usage (#307)
This commit is contained in:
@@ -45,7 +45,6 @@ import org.apache.cordova.CordovaResourceApi.OpenForReadResult;
|
|||||||
import org.apache.cordova.LOG;
|
import org.apache.cordova.LOG;
|
||||||
import org.apache.cordova.PluginManager;
|
import org.apache.cordova.PluginManager;
|
||||||
import org.apache.cordova.PluginResult;
|
import org.apache.cordova.PluginResult;
|
||||||
import org.apache.cordova.Whitelist;
|
|
||||||
import org.apache.cordova.file.FileUtils;
|
import org.apache.cordova.file.FileUtils;
|
||||||
import org.json.JSONArray;
|
import org.json.JSONArray;
|
||||||
import org.json.JSONException;
|
import org.json.JSONException;
|
||||||
@@ -676,25 +675,11 @@ public class FileTransfer extends CordovaPlugin {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* This code exists for compatibility between 3.x and 4.x versions of Cordova.
|
|
||||||
* Previously the CordovaWebView class had a method, getWhitelist, which would
|
|
||||||
* return a Whitelist object. Since the fixed whitelist is removed in Cordova 4.x,
|
|
||||||
* the correct call now is to shouldAllowRequest from the plugin manager.
|
|
||||||
*/
|
|
||||||
Boolean shouldAllowRequest = null;
|
Boolean shouldAllowRequest = null;
|
||||||
if (isLocalTransfer) {
|
if (isLocalTransfer) {
|
||||||
shouldAllowRequest = true;
|
shouldAllowRequest = true;
|
||||||
}
|
}
|
||||||
if (shouldAllowRequest == null) {
|
|
||||||
try {
|
|
||||||
Method gwl = webView.getClass().getMethod("getWhitelist");
|
|
||||||
Whitelist whitelist = (Whitelist)gwl.invoke(webView);
|
|
||||||
shouldAllowRequest = whitelist.isUrlWhiteListed(source);
|
|
||||||
} catch (NoSuchMethodException e) {
|
|
||||||
} catch (IllegalAccessException e) {
|
|
||||||
} catch (InvocationTargetException e) {
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (shouldAllowRequest == null) {
|
if (shouldAllowRequest == null) {
|
||||||
try {
|
try {
|
||||||
Method gpm = webView.getClass().getMethod("getPluginManager");
|
Method gpm = webView.getClass().getMethod("getPluginManager");
|
||||||
@@ -708,13 +693,12 @@ public class FileTransfer extends CordovaPlugin {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!Boolean.TRUE.equals(shouldAllowRequest)) {
|
if (!Boolean.TRUE.equals(shouldAllowRequest)) {
|
||||||
LOG.w(LOG_TAG, "Source URL is not in white list: '" + source + "'");
|
LOG.w(LOG_TAG, "The Source URL is not in the Allow List: '" + source + "'");
|
||||||
JSONObject error = createFileTransferError(CONNECTION_ERR, source, target, null, 401, null);
|
JSONObject error = createFileTransferError(CONNECTION_ERR, source, target, null, 401, null);
|
||||||
callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.IO_EXCEPTION, error));
|
callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.IO_EXCEPTION, error));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
final RequestContext context = new RequestContext(source, target, callbackContext);
|
final RequestContext context = new RequestContext(source, target, callbackContext);
|
||||||
synchronized (activeRequests) {
|
synchronized (activeRequests) {
|
||||||
activeRequests.put(objectId, context);
|
activeRequests.put(objectId, context);
|
||||||
|
|||||||
Reference in New Issue
Block a user