Commit 80014088 authored by Gustav Sennton's avatar Gustav Sennton Committed by Commit Bot

[android webview] Future-proof ServiceWorker...shouldInterceptRequest

Guard the callback ServiceWorkerClientCompat.shouldInterceptRequest with
a feature flag to ensure that if we ever remove/replace that callback
from the support library in the future, existing WebView APKs won't call
into it.

Bug: 819595
Change-Id: Id9796f695cc9fd66caf5739efeb77dd02e215821
Reviewed-on: https://chromium-review.googlesource.com/998164Reviewed-by: default avatarNate Fischer <ntfschr@chromium.org>
Reviewed-by: default avatarRichard Coles <torne@chromium.org>
Commit-Queue: Gustav Sennton <gsennton@chromium.org>
Cr-Commit-Position: refs/heads/master@{#549312}
parent 77f5f37d
...@@ -10,6 +10,6 @@ import android.webkit.WebResourceResponse; ...@@ -10,6 +10,6 @@ import android.webkit.WebResourceResponse;
/** /**
* Boundary interface for ServiceWorkerClient. * Boundary interface for ServiceWorkerClient.
*/ */
public interface ServiceWorkerClientBoundaryInterface { public interface ServiceWorkerClientBoundaryInterface extends FeatureFlagHolderBoundaryInterface {
WebResourceResponse shouldInterceptRequest(WebResourceRequest request); WebResourceResponse shouldInterceptRequest(WebResourceRequest request);
} }
...@@ -71,4 +71,15 @@ public class BoundaryInterfaceReflectionUtil { ...@@ -71,4 +71,15 @@ public class BoundaryInterfaceReflectionUtil {
} }
}; };
} }
/**
* Check whether a set of features {@param features} contains a certain feature {@param
* soughtFeature}.
*/
public static boolean containsFeature(String[] features, String soughtFeature) {
for (String feature : features) {
if (feature.equals(soughtFeature)) return true;
}
return false;
}
} }
...@@ -13,6 +13,8 @@ import org.chromium.android_webview.AwContentsClient.AwWebResourceRequest; ...@@ -13,6 +13,8 @@ import org.chromium.android_webview.AwContentsClient.AwWebResourceRequest;
import org.chromium.android_webview.AwServiceWorkerClient; import org.chromium.android_webview.AwServiceWorkerClient;
import org.chromium.android_webview.AwWebResourceResponse; import org.chromium.android_webview.AwWebResourceResponse;
import org.chromium.support_lib_boundary.ServiceWorkerClientBoundaryInterface; import org.chromium.support_lib_boundary.ServiceWorkerClientBoundaryInterface;
import org.chromium.support_lib_boundary.util.BoundaryInterfaceReflectionUtil;
import org.chromium.support_lib_boundary.util.Features;
/** /**
* Adapter between ServiceWorkerClientBoundaryInterface and AwServiceWorkerClient. * Adapter between ServiceWorkerClientBoundaryInterface and AwServiceWorkerClient.
...@@ -26,6 +28,11 @@ class SupportLibServiceWorkerClientAdapter extends AwServiceWorkerClient { ...@@ -26,6 +28,11 @@ class SupportLibServiceWorkerClientAdapter extends AwServiceWorkerClient {
@Override @Override
public AwWebResourceResponse shouldInterceptRequest(AwWebResourceRequest request) { public AwWebResourceResponse shouldInterceptRequest(AwWebResourceRequest request) {
if (!BoundaryInterfaceReflectionUtil.containsFeature(mImpl.getSupportedFeatures(),
Features.SERVICE_WORKER_SHOULD_INTERCEPT_REQUEST)) {
// If the shouldInterceptRequest callback isn't supported, return null;
return null;
}
WebResourceResponse response = WebResourceResponse response =
mImpl.shouldInterceptRequest(new WebResourceRequestAdapter(request)); mImpl.shouldInterceptRequest(new WebResourceRequestAdapter(request));
return ServiceWorkerClientAdapter.fromWebResourceResponse(response); return ServiceWorkerClientAdapter.fromWebResourceResponse(response);
......
...@@ -43,7 +43,8 @@ class SupportLibWebViewChromiumFactory implements WebViewProviderFactoryBoundary ...@@ -43,7 +43,8 @@ class SupportLibWebViewChromiumFactory implements WebViewProviderFactoryBoundary
Features.SERVICE_WORKER_CACHE_MODE, Features.SERVICE_WORKER_CACHE_MODE,
Features.SERVICE_WORKER_CONTENT_ACCESS, Features.SERVICE_WORKER_CONTENT_ACCESS,
Features.SERVICE_WORKER_FILE_ACCESS, Features.SERVICE_WORKER_FILE_ACCESS,
Features.SERVICE_WORKER_BLOCK_NETWORK_LOADS Features.SERVICE_WORKER_BLOCK_NETWORK_LOADS,
Features.SERVICE_WORKER_SHOULD_INTERCEPT_REQUEST
}; };
// clang-format on // clang-format on
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment