From c4fe2cba6998c14828ced5e93605c984780d8ddb Mon Sep 17 00:00:00 2001 From: jcesarmobile Date: Fri, 26 Jun 2026 17:51:08 +0200 Subject: [PATCH] refactor: remove or replace deprecated methods in engine --- .../cordova/engine/SystemWebChromeClient.java | 14 ----- .../cordova/engine/SystemWebViewClient.java | 57 +++++-------------- .../cordova/engine/SystemWebViewEngine.java | 9 --- 3 files changed, 13 insertions(+), 67 deletions(-) diff --git a/framework/src/org/apache/cordova/engine/SystemWebChromeClient.java b/framework/src/org/apache/cordova/engine/SystemWebChromeClient.java index c10c666d..81ecca19 100755 --- a/framework/src/org/apache/cordova/engine/SystemWebChromeClient.java +++ b/framework/src/org/apache/cordova/engine/SystemWebChromeClient.java @@ -42,7 +42,6 @@ import android.webkit.JsPromptResult; import android.webkit.JsResult; import android.webkit.ValueCallback; import android.webkit.WebChromeClient; -import android.webkit.WebStorage; import android.webkit.WebView; import android.webkit.PermissionRequest; import android.widget.LinearLayout; @@ -150,19 +149,6 @@ public class SystemWebChromeClient extends WebChromeClient { return true; } - /** - * Handle database quota exceeded notification. - */ - @Override - @SuppressWarnings("deprecation") - public void onExceededDatabaseQuota(String url, String databaseIdentifier, long currentQuota, long estimatedSize, - long totalUsedQuota, WebStorage.QuotaUpdater quotaUpdater) - { - LOG.d(LOG_TAG, "onExceededDatabaseQuota estimatedSize: %d currentQuota: %d totalUsedQuota: %d", estimatedSize, currentQuota, totalUsedQuota); - long MAX_QUOTA = 100 * 1024 * 1024; - quotaUpdater.updateQuota(MAX_QUOTA); - } - /** * Instructs the client to show a prompt to ask the user to set the Geolocation permission state for the specified origin. * diff --git a/framework/src/org/apache/cordova/engine/SystemWebViewClient.java b/framework/src/org/apache/cordova/engine/SystemWebViewClient.java index 7dbd7d16..41df433f 100755 --- a/framework/src/org/apache/cordova/engine/SystemWebViewClient.java +++ b/framework/src/org/apache/cordova/engine/SystemWebViewClient.java @@ -32,6 +32,7 @@ import android.webkit.RenderProcessGoneDetail; import android.webkit.ServiceWorkerClient; import android.webkit.ServiceWorkerController; import android.webkit.SslErrorHandler; +import android.webkit.WebResourceError; import android.webkit.WebResourceRequest; import android.webkit.WebResourceResponse; import android.webkit.WebView; @@ -45,8 +46,6 @@ import org.apache.cordova.CordovaResourceApi; import org.apache.cordova.LOG; import org.apache.cordova.PluginManager; -import java.io.FileNotFoundException; -import java.io.IOException; import java.io.InputStream; import java.util.Hashtable; @@ -137,13 +136,12 @@ public class SystemWebViewClient extends WebViewClient { * is about to be loaded in the current WebView. * * @param view The WebView that is initiating the callback. - * @param url The url to be loaded. + * @param request The request to be loaded. * @return true to override, false for default behavior */ @Override - @SuppressWarnings("deprecation") - public boolean shouldOverrideUrlLoading(WebView view, String url) { - return parentEngine.client.onNavigationAttempt(url); + public boolean shouldOverrideUrlLoading(WebView view, WebResourceRequest request) { + return parentEngine.client.onNavigationAttempt(request.getUrl().toString()); } /** @@ -247,13 +245,16 @@ public class SystemWebViewClient extends WebViewClient { * The errorCode parameter corresponds to one of the ERROR_* constants. * * @param view The WebView that is initiating the callback. - * @param errorCode The error code corresponding to an ERROR_* value. - * @param description A String describing the error. - * @param failingUrl The url that failed to load. + * @param request The request that caused the error. + * @param error The error object. */ @Override - @SuppressWarnings("deprecation") - public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) { + public void onReceivedError(WebView view, + WebResourceRequest request, + WebResourceError error) { + int errorCode = error.getErrorCode(); + String description = error.getDescription().toString(); + String failingUrl = request.getUrl().toString(); // Ignore error due to stopLoading(). if (!isCurrentlyLoading) { return; @@ -270,7 +271,7 @@ public class SystemWebViewClient extends WebViewClient { view.goBack(); return; } else { - super.onReceivedError(view, errorCode, description, failingUrl); + super.onReceivedError(view, request, error); } } parentEngine.client.onReceivedError(errorCode, description, failingUrl); @@ -382,38 +383,6 @@ public class SystemWebViewClient extends WebViewClient { this.authenticationTokens.clear(); } - @Override - @SuppressWarnings("deprecation") - public WebResourceResponse shouldInterceptRequest(WebView view, String url) { - try { - // Check the against the allow list and lock out access to the WebView directory - // Changing this will cause problems for your application - if (!parentEngine.pluginManager.shouldAllowRequest(url)) { - LOG.w(TAG, "URL blocked by allow list: " + url); - // Results in a 404. - return new WebResourceResponse("text/plain", "UTF-8", null); - } - - CordovaResourceApi resourceApi = parentEngine.resourceApi; - Uri origUri = Uri.parse(url); - // Allow plugins to intercept WebView requests. - Uri remappedUri = resourceApi.remapUri(origUri); - - if (!origUri.equals(remappedUri) || needsSpecialsInAssetUrlFix(origUri) || needsContentUrlFix(origUri)) { - CordovaResourceApi.OpenForReadResult result = resourceApi.openForRead(remappedUri, true); - return new WebResourceResponse(result.mimeType, "UTF-8", result.inputStream); - } - // If we don't need to special-case the request, let the browser load it. - return null; - } catch (IOException e) { - if (!(e instanceof FileNotFoundException)) { - LOG.e(TAG, "Error occurred while loading a file (returning a 404).", e); - } - // Results in a 404. - return new WebResourceResponse("text/plain", "UTF-8", null); - } - } - private static boolean needsContentUrlFix(Uri uri) { return "content".equals(uri.getScheme()); } diff --git a/framework/src/org/apache/cordova/engine/SystemWebViewEngine.java b/framework/src/org/apache/cordova/engine/SystemWebViewEngine.java index 970758f2..30220ec1 100755 --- a/framework/src/org/apache/cordova/engine/SystemWebViewEngine.java +++ b/framework/src/org/apache/cordova/engine/SystemWebViewEngine.java @@ -20,13 +20,11 @@ package org.apache.cordova.engine; import android.annotation.SuppressLint; -import android.annotation.TargetApi; import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; import android.content.IntentFilter; import android.content.pm.ApplicationInfo; -import android.os.Build; import android.view.View; import android.webkit.ValueCallback; import android.webkit.WebSettings; @@ -44,9 +42,6 @@ import org.apache.cordova.LOG; import org.apache.cordova.NativeToJsMessageQueue; import org.apache.cordova.PluginManager; -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; - /** * Glue class between CordovaWebView (main Cordova logic) and SystemWebView (the actual View). @@ -142,7 +137,6 @@ public class SystemWebViewEngine implements CordovaWebViewEngine { } @SuppressLint({"NewApi", "SetJavaScriptEnabled"}) - @SuppressWarnings("deprecation") private void initWebViewSettings() { webView.setInitialScale(0); webView.setVerticalScrollBarEnabled(false); @@ -192,9 +186,6 @@ public class SystemWebViewEngine implements CordovaWebViewEngine { enableRemoteDebugging(); } - // @todo remove when Cordova drop API level 24 support - settings.setGeolocationDatabasePath(databasePath); - // Enable DOM storage settings.setDomStorageEnabled(true);