[WebView Support Lib] Mix frameworks and support lib impls together.
This CL re-implements ServiceWorkerControllerCompat and
ServiceWorkerWebSettingsCompat in a fashion allowing us to choose on a
per-method basis whether to use framework APIs or the support library
glue.
This makes feature detection more consistent for post-L classes with new
methods added after P.
Bug: 77808798
Test: run androidx.webkit tests.
Change-Id: I38f4809c35432b7be9cdfdcc7256761b1a104093
diff --git a/webkit/src/main/java/androidx/webkit/ServiceWorkerControllerCompat.java b/webkit/src/main/java/androidx/webkit/ServiceWorkerControllerCompat.java
index 8d9d683..79b714a 100644
--- a/webkit/src/main/java/androidx/webkit/ServiceWorkerControllerCompat.java
+++ b/webkit/src/main/java/androidx/webkit/ServiceWorkerControllerCompat.java
@@ -16,18 +16,11 @@
package androidx.webkit;
-import android.os.Build;
-import android.webkit.ServiceWorkerController;
-
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
-import androidx.annotation.RequiresApi;
import androidx.annotation.RequiresFeature;
import androidx.annotation.RestrictTo;
-import androidx.webkit.internal.FrameworkServiceWorkerController;
-import androidx.webkit.internal.ServiceWorkerControllerAdapter;
-import androidx.webkit.internal.WebViewFeatureInternal;
-import androidx.webkit.internal.WebViewGlueCommunicator;
+import androidx.webkit.internal.ServiceWorkerControllerImpl;
/**
* Manages Service Workers used by WebView.
@@ -68,34 +61,7 @@
}
private static class LAZY_HOLDER {
- static final ServiceWorkerControllerCompat INSTANCE = createController();
-
- @SuppressWarnings("NewApi")
- private static ServiceWorkerControllerCompat createController() {
- WebViewFeatureInternal webviewFeature =
- WebViewFeatureInternal.getFeature(WebViewFeature.SERVICE_WORKER_BASIC_USAGE);
- if (webviewFeature.isSupportedByFramework()) {
- return getFrameworkControllerCompat();
- } else if (webviewFeature.isSupportedByWebView()) {
- return getSupportLibraryControllerCompat();
- } else {
- throw WebViewFeatureInternal.getUnsupportedOperationException();
- }
- }
- }
-
- /**
- * Return a version of {@link ServiceWorkerControllerCompat} that only uses framework APIs.
- */
- @RequiresApi(Build.VERSION_CODES.N)
- private static ServiceWorkerControllerCompat getFrameworkControllerCompat() {
- return new FrameworkServiceWorkerController(
- ServiceWorkerController.getInstance());
- }
-
- private static ServiceWorkerControllerCompat getSupportLibraryControllerCompat() {
- return new ServiceWorkerControllerAdapter(
- WebViewGlueCommunicator.getFactory().getServiceWorkerController());
+ static final ServiceWorkerControllerCompat INSTANCE = new ServiceWorkerControllerImpl();
}
/**
diff --git a/webkit/src/main/java/androidx/webkit/internal/FrameworkServiceWorkerController.java b/webkit/src/main/java/androidx/webkit/internal/FrameworkServiceWorkerController.java
deleted file mode 100644
index 2e02777..0000000
--- a/webkit/src/main/java/androidx/webkit/internal/FrameworkServiceWorkerController.java
+++ /dev/null
@@ -1,53 +0,0 @@
-/*
- * Copyright 2018 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package androidx.webkit.internal;
-
-import android.os.Build;
-import android.webkit.ServiceWorkerController;
-
-import androidx.annotation.RequiresApi;
-import androidx.webkit.ServiceWorkerClientCompat;
-import androidx.webkit.ServiceWorkerControllerCompat;
-import androidx.webkit.ServiceWorkerWebSettingsCompat;
-
-/**
- * Implementation of {@link ServiceWorkerControllerCompat} meant for use on up-to-date platforms.
- * This class does not use reflection to bypass framework APIs - instead it uses android.webkit
- * APIs.
- */
-@RequiresApi(Build.VERSION_CODES.N)
-public class FrameworkServiceWorkerController extends ServiceWorkerControllerCompat {
- private final ServiceWorkerController mImpl;
- private ServiceWorkerWebSettingsCompat mSettings;
-
- public FrameworkServiceWorkerController(ServiceWorkerController impl) {
- mImpl = impl;
- }
-
- @Override
- public ServiceWorkerWebSettingsCompat getServiceWorkerWebSettings() {
- if (mSettings == null) {
- mSettings = new FrameworksServiceWorkerWebSettings(mImpl.getServiceWorkerWebSettings());
- }
- return mSettings;
- }
-
- @Override
- public void setServiceWorkerClient(ServiceWorkerClientCompat client) {
- mImpl.setServiceWorkerClient(new FrameworkServiceWorkerClient(client));
- }
-}
diff --git a/webkit/src/main/java/androidx/webkit/internal/FrameworksServiceWorkerWebSettings.java b/webkit/src/main/java/androidx/webkit/internal/FrameworksServiceWorkerWebSettings.java
deleted file mode 100644
index 4373756..0000000
--- a/webkit/src/main/java/androidx/webkit/internal/FrameworksServiceWorkerWebSettings.java
+++ /dev/null
@@ -1,77 +0,0 @@
-/*
- * Copyright 2018 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package androidx.webkit.internal;
-
-import android.os.Build;
-import android.webkit.ServiceWorkerWebSettings;
-
-import androidx.annotation.RequiresApi;
-import androidx.webkit.ServiceWorkerWebSettingsCompat;
-
-/**
- * Implementation of {@link ServiceWorkerWebSettingsCompat} meant for use on up-to-date platforms.
- * This class does not use reflection to bypass framework APIs - instead it uses android.webkit
- * APIs.
- */
-@RequiresApi(Build.VERSION_CODES.N)
-public class FrameworksServiceWorkerWebSettings extends ServiceWorkerWebSettingsCompat {
- private final ServiceWorkerWebSettings mImpl;
-
- public FrameworksServiceWorkerWebSettings(ServiceWorkerWebSettings impl) {
- mImpl = impl;
- }
-
- @Override
- public void setCacheMode(int mode) {
- mImpl.setCacheMode(mode);
- }
-
- @Override
- public int getCacheMode() {
- return mImpl.getCacheMode();
- }
-
- @Override
- public void setAllowContentAccess(boolean allow) {
- mImpl.setAllowContentAccess(allow);
- }
-
- @Override
- public boolean getAllowContentAccess() {
- return mImpl.getAllowContentAccess();
- }
-
- @Override
- public void setAllowFileAccess(boolean allow) {
- mImpl.setAllowContentAccess(allow);
- }
-
- @Override
- public boolean getAllowFileAccess() {
- return mImpl.getAllowFileAccess();
- }
-
- @Override
- public void setBlockNetworkLoads(boolean flag) {
- mImpl.setAllowContentAccess(flag);
- }
-
- @Override
- public boolean getBlockNetworkLoads() {
- return mImpl.getBlockNetworkLoads();
- }
-}
diff --git a/webkit/src/main/java/androidx/webkit/internal/ServiceWorkerControllerAdapter.java b/webkit/src/main/java/androidx/webkit/internal/ServiceWorkerControllerAdapter.java
deleted file mode 100644
index 4baa3ea..0000000
--- a/webkit/src/main/java/androidx/webkit/internal/ServiceWorkerControllerAdapter.java
+++ /dev/null
@@ -1,54 +0,0 @@
-/*
- * Copyright 2018 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package androidx.webkit.internal;
-
-import androidx.webkit.ServiceWorkerClientCompat;
-import androidx.webkit.ServiceWorkerControllerCompat;
-import androidx.webkit.ServiceWorkerWebSettingsCompat;
-
-import org.chromium.support_lib_boundary.ServiceWorkerControllerBoundaryInterface;
-import org.chromium.support_lib_boundary.ServiceWorkerWebSettingsBoundaryInterface;
-import org.chromium.support_lib_boundary.util.BoundaryInterfaceReflectionUtil;
-
-/**
- * Adapter between {@link ServiceWorkerControllerCompat} and
- * {@link ServiceWorkerControllerBoundaryInterface} (the corresponding interface shared with the
- * support library glue in the WebView APK).
- */
-public class ServiceWorkerControllerAdapter extends ServiceWorkerControllerCompat {
- private final ServiceWorkerControllerBoundaryInterface mImpl;
- private final ServiceWorkerWebSettingsCompat mWebSettings;
-
- public ServiceWorkerControllerAdapter(ServiceWorkerControllerBoundaryInterface impl) {
- mImpl = impl;
- mWebSettings = new ServiceWorkerWebSettingsAdapter(
- BoundaryInterfaceReflectionUtil.castToSuppLibClass(
- ServiceWorkerWebSettingsBoundaryInterface.class,
- mImpl.getServiceWorkerWebSettings()));
- }
-
- @Override
- public ServiceWorkerWebSettingsCompat getServiceWorkerWebSettings() {
- return mWebSettings;
- }
-
- @Override
- public void setServiceWorkerClient(ServiceWorkerClientCompat client) {
- mImpl.setServiceWorkerClient(BoundaryInterfaceReflectionUtil.createInvocationHandlerFor(
- new ServiceWorkerClientAdapter(client)));
- }
-}
diff --git a/webkit/src/main/java/androidx/webkit/internal/ServiceWorkerControllerImpl.java b/webkit/src/main/java/androidx/webkit/internal/ServiceWorkerControllerImpl.java
new file mode 100644
index 0000000..17e0a7d
--- /dev/null
+++ b/webkit/src/main/java/androidx/webkit/internal/ServiceWorkerControllerImpl.java
@@ -0,0 +1,90 @@
+/*
+ * Copyright 2018 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package androidx.webkit.internal;
+
+import android.annotation.SuppressLint;
+import android.webkit.ServiceWorkerController;
+
+import androidx.webkit.ServiceWorkerClientCompat;
+import androidx.webkit.ServiceWorkerControllerCompat;
+import androidx.webkit.ServiceWorkerWebSettingsCompat;
+
+import org.chromium.support_lib_boundary.ServiceWorkerControllerBoundaryInterface;
+import org.chromium.support_lib_boundary.ServiceWorkerWebSettingsBoundaryInterface;
+import org.chromium.support_lib_boundary.util.BoundaryInterfaceReflectionUtil;
+
+/**
+ * Implementation of {@link ServiceWorkerControllerCompat}.
+ * This class uses either the framework, the WebView APK, or both, to implement
+ * {@link ServiceWorkerControllerCompat} functionality.
+ */
+public class ServiceWorkerControllerImpl extends ServiceWorkerControllerCompat {
+ private final ServiceWorkerController mFrameworksImpl;
+ private ServiceWorkerControllerBoundaryInterface mBoundaryInterface;
+ private final ServiceWorkerWebSettingsCompat mWebSettings;
+
+ @SuppressLint("NewApi")
+ public ServiceWorkerControllerImpl() {
+ final WebViewFeatureInternal feature = WebViewFeatureInternal.SERVICE_WORKER_BASIC_USAGE;
+ if (feature.isSupportedByFramework()) {
+ mFrameworksImpl = ServiceWorkerController.getInstance();
+ // The current WebView APK might not be compatible with the support library, so set the
+ // boundary interface to null for now.
+ mBoundaryInterface = null;
+ mWebSettings = new ServiceWorkerWebSettingsImpl(
+ mFrameworksImpl.getServiceWorkerWebSettings(), null);
+ } else if (feature.isSupportedByWebView()) {
+ mFrameworksImpl = null;
+ mBoundaryInterface = WebViewGlueCommunicator.getFactory().getServiceWorkerController();
+ mWebSettings = new ServiceWorkerWebSettingsImpl(null,
+ BoundaryInterfaceReflectionUtil.castToSuppLibClass(
+ ServiceWorkerWebSettingsBoundaryInterface.class,
+ mBoundaryInterface.getServiceWorkerWebSettings()));
+ } else {
+ throw WebViewFeatureInternal.getUnsupportedOperationException();
+ }
+ }
+
+ private ServiceWorkerControllerBoundaryInterface getBoundaryInterface() {
+ if (mBoundaryInterface != null) return mBoundaryInterface;
+
+ // If the boundary interface is null we must have a working frameworks implementation to
+ // convert into a boundary interface.
+ mBoundaryInterface = WebViewGlueCommunicator.getFactory().getServiceWorkerController();
+ return mBoundaryInterface;
+ }
+
+ @Override
+ public ServiceWorkerWebSettingsCompat getServiceWorkerWebSettings() {
+ return mWebSettings;
+ }
+
+ @SuppressLint("NewApi")
+ @Override
+ public void setServiceWorkerClient(ServiceWorkerClientCompat client) {
+ final WebViewFeatureInternal feature = WebViewFeatureInternal.SERVICE_WORKER_BASIC_USAGE;
+ if (feature.isSupportedByFramework()) {
+ mFrameworksImpl.setServiceWorkerClient(new FrameworkServiceWorkerClient(client));
+ } else if (feature.isSupportedByWebView()) {
+ getBoundaryInterface().setServiceWorkerClient(
+ BoundaryInterfaceReflectionUtil.createInvocationHandlerFor(
+ new ServiceWorkerClientAdapter(client)));
+ } else {
+ throw WebViewFeatureInternal.getUnsupportedOperationException();
+ }
+ }
+}
diff --git a/webkit/src/main/java/androidx/webkit/internal/ServiceWorkerWebSettingsAdapter.java b/webkit/src/main/java/androidx/webkit/internal/ServiceWorkerWebSettingsAdapter.java
deleted file mode 100644
index fd49396..0000000
--- a/webkit/src/main/java/androidx/webkit/internal/ServiceWorkerWebSettingsAdapter.java
+++ /dev/null
@@ -1,74 +0,0 @@
-/*
- * Copyright 2018 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package androidx.webkit.internal;
-
-import androidx.webkit.ServiceWorkerWebSettingsCompat;
-
-import org.chromium.support_lib_boundary.ServiceWorkerWebSettingsBoundaryInterface;
-
-/**
- * Adapter between {@link ServiceWorkerWebSettingsCompat} and
- * {@link ServiceWorkerWebSettingsBoundaryInterface} (the corresponding interface shared with the
- * support library glue in the WebView APK).
- */
-public class ServiceWorkerWebSettingsAdapter extends ServiceWorkerWebSettingsCompat {
- private final ServiceWorkerWebSettingsBoundaryInterface mImpl;
-
- public ServiceWorkerWebSettingsAdapter(ServiceWorkerWebSettingsBoundaryInterface impl) {
- mImpl = impl;
- }
-
- @Override
- public void setCacheMode(int mode) {
- mImpl.setCacheMode(mode);
- }
-
- @Override
- public int getCacheMode() {
- return mImpl.getCacheMode();
- }
-
- @Override
- public void setAllowContentAccess(boolean allow) {
- mImpl.setAllowContentAccess(allow);
- }
-
- @Override
- public boolean getAllowContentAccess() {
- return mImpl.getAllowContentAccess();
- }
-
- @Override
- public void setAllowFileAccess(boolean allow) {
- mImpl.setAllowFileAccess(allow);
- }
-
- @Override
- public boolean getAllowFileAccess() {
- return mImpl.getAllowFileAccess();
- }
-
- @Override
- public void setBlockNetworkLoads(boolean flag) {
- mImpl.setBlockNetworkLoads(flag);
- }
-
- @Override
- public boolean getBlockNetworkLoads() {
- return mImpl.getBlockNetworkLoads();
- }
-}
diff --git a/webkit/src/main/java/androidx/webkit/internal/ServiceWorkerWebSettingsImpl.java b/webkit/src/main/java/androidx/webkit/internal/ServiceWorkerWebSettingsImpl.java
new file mode 100644
index 0000000..9ac4450
--- /dev/null
+++ b/webkit/src/main/java/androidx/webkit/internal/ServiceWorkerWebSettingsImpl.java
@@ -0,0 +1,172 @@
+/*
+ * Copyright 2018 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package androidx.webkit.internal;
+
+import android.annotation.SuppressLint;
+import android.webkit.ServiceWorkerWebSettings;
+
+import androidx.webkit.ServiceWorkerWebSettingsCompat;
+
+import org.chromium.support_lib_boundary.ServiceWorkerWebSettingsBoundaryInterface;
+
+/**
+ * Implementation of {@link ServiceWorkerWebSettingsCompat}.
+ * This class uses either the framework, the WebView APK, or both, to implement
+ * {@link ServiceWorkerWebSettingsCompat} functionality.
+ */
+public class ServiceWorkerWebSettingsImpl extends ServiceWorkerWebSettingsCompat {
+ private final ServiceWorkerWebSettings mFrameworksImpl;
+ private ServiceWorkerWebSettingsBoundaryInterface mBoundaryInterface;
+
+ /**
+ * This class handles three different scenarios:
+ * 1. The Android version on the device is high enough to support all APIs used.
+ * 2. The Android version on the device is too low to support any ServiceWorkerWebSettings APIs
+ * so we use the support library glue instead through
+ * {@link ServiceWorkerWebSettingsBoundaryInterface}.
+ * 3. The Android version on the device is high enough to support some ServiceWorkerWebSettings
+ * APIs, so we call into them using {@link android.webkit.ServiceWorkerWebSettings}, but the
+ * rest of the APIs are only supported by the support library glue, so whenever we call such an
+ * API we fetch a {@link ServiceWorkerWebSettingsBoundaryInterface} corresponding to our
+ * {@link android.webkit.ServiceWorkerWebSettings}.
+ */
+ public ServiceWorkerWebSettingsImpl(ServiceWorkerWebSettings frameworksImpl,
+ ServiceWorkerWebSettingsBoundaryInterface boundaryInterface) {
+ if (frameworksImpl == null && boundaryInterface == null) {
+ throw new IllegalArgumentException(
+ "Both of the possible implementations cannot be null!");
+ }
+ mFrameworksImpl = frameworksImpl;
+ mBoundaryInterface = boundaryInterface;
+ }
+
+ private ServiceWorkerWebSettingsBoundaryInterface getBoundaryInterface() {
+ if (mBoundaryInterface != null) return mBoundaryInterface;
+ // If the boundary interface is null we must have a working frameworks implementation to
+ // convert into a boundary interface.
+ mBoundaryInterface =
+ WebViewGlueCommunicator.getCompatConverter().convertServiceWorkerSettings(
+ mFrameworksImpl);
+ return mBoundaryInterface;
+ }
+
+ @SuppressLint("NewApi")
+ @Override
+ public void setCacheMode(int mode) {
+ final WebViewFeatureInternal feature = WebViewFeatureInternal.SERVICE_WORKER_CACHE_MODE;
+ if (feature.isSupportedByFramework()) {
+ mFrameworksImpl.setCacheMode(mode);
+ } else if (feature.isSupportedByWebView()) {
+ getBoundaryInterface().setCacheMode(mode);
+ } else {
+ throw WebViewFeatureInternal.getUnsupportedOperationException();
+ }
+ }
+
+ @SuppressLint("NewApi")
+ @Override
+ public int getCacheMode() {
+ final WebViewFeatureInternal feature = WebViewFeatureInternal.SERVICE_WORKER_CACHE_MODE;
+ if (feature.isSupportedByFramework()) {
+ return mFrameworksImpl.getCacheMode();
+ } else if (feature.isSupportedByWebView()) {
+ return getBoundaryInterface().getCacheMode();
+ } else {
+ throw WebViewFeatureInternal.getUnsupportedOperationException();
+ }
+ }
+
+ @SuppressLint("NewApi")
+ @Override
+ public void setAllowContentAccess(boolean allow) {
+ final WebViewFeatureInternal feature = WebViewFeatureInternal.SERVICE_WORKER_CONTENT_ACCESS;
+ if (feature.isSupportedByFramework()) {
+ mFrameworksImpl.setAllowContentAccess(allow);
+ } else if (feature.isSupportedByWebView()) {
+ getBoundaryInterface().setAllowContentAccess(allow);
+ } else {
+ throw WebViewFeatureInternal.getUnsupportedOperationException();
+ }
+ }
+
+ @SuppressLint("NewApi")
+ @Override
+ public boolean getAllowContentAccess() {
+ final WebViewFeatureInternal feature = WebViewFeatureInternal.SERVICE_WORKER_CONTENT_ACCESS;
+ if (feature.isSupportedByFramework()) {
+ return mFrameworksImpl.getAllowContentAccess();
+ } else if (feature.isSupportedByWebView()) {
+ return getBoundaryInterface().getAllowContentAccess();
+ } else {
+ throw WebViewFeatureInternal.getUnsupportedOperationException();
+ }
+ }
+
+ @SuppressLint("NewApi")
+ @Override
+ public void setAllowFileAccess(boolean allow) {
+ final WebViewFeatureInternal feature = WebViewFeatureInternal.SERVICE_WORKER_FILE_ACCESS;
+ if (feature.isSupportedByFramework()) {
+ mFrameworksImpl.setAllowFileAccess(allow);
+ } else if (feature.isSupportedByWebView()) {
+ getBoundaryInterface().setAllowFileAccess(allow);
+ } else {
+ throw WebViewFeatureInternal.getUnsupportedOperationException();
+ }
+ }
+
+ @SuppressLint("NewApi")
+ @Override
+ public boolean getAllowFileAccess() {
+ final WebViewFeatureInternal feature = WebViewFeatureInternal.SERVICE_WORKER_FILE_ACCESS;
+ if (feature.isSupportedByFramework()) {
+ return mFrameworksImpl.getAllowFileAccess();
+ } else if (feature.isSupportedByWebView()) {
+ return getBoundaryInterface().getAllowFileAccess();
+ } else {
+ throw WebViewFeatureInternal.getUnsupportedOperationException();
+ }
+ }
+
+ @SuppressLint("NewApi")
+ @Override
+ public void setBlockNetworkLoads(boolean flag) {
+ final WebViewFeatureInternal feature =
+ WebViewFeatureInternal.SERVICE_WORKER_BLOCK_NETWORK_LOADS;
+ if (feature.isSupportedByFramework()) {
+ mFrameworksImpl.setBlockNetworkLoads(flag);
+ } else if (feature.isSupportedByWebView()) {
+ getBoundaryInterface().setBlockNetworkLoads(flag);
+ } else {
+ throw WebViewFeatureInternal.getUnsupportedOperationException();
+ }
+ }
+
+ @SuppressLint("NewApi")
+ @Override
+ public boolean getBlockNetworkLoads() {
+ final WebViewFeatureInternal feature =
+ WebViewFeatureInternal.SERVICE_WORKER_BLOCK_NETWORK_LOADS;
+ if (feature.isSupportedByFramework()) {
+ return mFrameworksImpl.getBlockNetworkLoads();
+ } else if (feature.isSupportedByWebView()) {
+ return getBoundaryInterface().getBlockNetworkLoads();
+ } else {
+ throw WebViewFeatureInternal.getUnsupportedOperationException();
+ }
+ }
+}
diff --git a/webkit/src/main/java/androidx/webkit/internal/WebkitToCompatConverter.java b/webkit/src/main/java/androidx/webkit/internal/WebkitToCompatConverter.java
index a07cf07..4d264a3 100644
--- a/webkit/src/main/java/androidx/webkit/internal/WebkitToCompatConverter.java
+++ b/webkit/src/main/java/androidx/webkit/internal/WebkitToCompatConverter.java
@@ -16,8 +16,10 @@
package androidx.webkit.internal;
+import android.webkit.ServiceWorkerWebSettings;
import android.webkit.WebSettings;
+import org.chromium.support_lib_boundary.ServiceWorkerWebSettingsBoundaryInterface;
import org.chromium.support_lib_boundary.WebSettingsBoundaryInterface;
import org.chromium.support_lib_boundary.WebkitToCompatConverterBoundaryInterface;
import org.chromium.support_lib_boundary.util.BoundaryInterfaceReflectionUtil;
@@ -42,4 +44,16 @@
return new WebSettingsAdapter(BoundaryInterfaceReflectionUtil.castToSuppLibClass(
WebSettingsBoundaryInterface.class, mImpl.convertSettings(webSettings)));
}
+
+ /**
+ * Return a {@link ServiceWorkerWebSettingsBoundaryInterface} linked to the given
+ * {@link ServiceWorkerWebSettings }such that calls on either of those objects affect the other
+ * object.
+ */
+ public ServiceWorkerWebSettingsBoundaryInterface convertServiceWorkerSettings(
+ ServiceWorkerWebSettings settings) {
+ return BoundaryInterfaceReflectionUtil.castToSuppLibClass(
+ ServiceWorkerWebSettingsBoundaryInterface.class,
+ mImpl.convertServiceWorkerSettings(settings));
+ }
}