feat!: remove deprecated whitelist usage (#307)

This commit is contained in:
エリス 2021-07-28 01:12:56 +09:00 committed by GitHub
parent 648b57792f
commit 2cdb0403a8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -45,7 +45,6 @@ import org.apache.cordova.CordovaResourceApi.OpenForReadResult;
import org.apache.cordova.LOG;
import org.apache.cordova.PluginManager;
import org.apache.cordova.PluginResult;
import org.apache.cordova.Whitelist;
import org.apache.cordova.file.FileUtils;
import org.json.JSONArray;
import org.json.JSONException;
@ -676,25 +675,11 @@ public class FileTransfer extends CordovaPlugin {
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;
if (isLocalTransfer) {
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) {
try {
Method gpm = webView.getClass().getMethod("getPluginManager");
@ -708,13 +693,12 @@ public class FileTransfer extends CordovaPlugin {
}
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);
callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.IO_EXCEPTION, error));
return;
}
final RequestContext context = new RequestContext(source, target, callbackContext);
synchronized (activeRequests) {
activeRequests.put(objectId, context);