diff --git a/android_webview/glue/java/src/com/android/webview/chromium/ServiceWorkerControllerAdapter.java b/android_webview/glue/java/src/com/android/webview/chromium/ServiceWorkerControllerAdapter.java index 3f930c7562f39c..701a6eddaa7487 100644 --- a/android_webview/glue/java/src/com/android/webview/chromium/ServiceWorkerControllerAdapter.java +++ b/android_webview/glue/java/src/com/android/webview/chromium/ServiceWorkerControllerAdapter.java @@ -10,6 +10,8 @@ import android.webkit.ServiceWorkerController; import android.webkit.ServiceWorkerWebSettings; +import androidx.annotation.Nullable; + import org.chromium.android_webview.AwServiceWorkerController; /** @@ -37,7 +39,8 @@ public ServiceWorkerWebSettings getServiceWorkerWebSettings() { * Sets the client to capture service worker related callbacks. */ @Override - public void setServiceWorkerClient(ServiceWorkerClient client) { - mAwServiceWorkerController.setServiceWorkerClient(new ServiceWorkerClientAdapter(client)); + public void setServiceWorkerClient(@Nullable ServiceWorkerClient client) { + mAwServiceWorkerController.setServiceWorkerClient( + client != null ? new ServiceWorkerClientAdapter(client) : null); } } diff --git a/android_webview/java/src/org/chromium/android_webview/AwServiceWorkerController.java b/android_webview/java/src/org/chromium/android_webview/AwServiceWorkerController.java index 3b9e70c5e890c9..f1da0d8d1518dd 100644 --- a/android_webview/java/src/org/chromium/android_webview/AwServiceWorkerController.java +++ b/android_webview/java/src/org/chromium/android_webview/AwServiceWorkerController.java @@ -6,6 +6,8 @@ import android.content.Context; +import androidx.annotation.Nullable; + import org.chromium.android_webview.safe_browsing.AwSafeBrowsingConfigHelper; import org.chromium.base.annotations.DoNotInline; import org.chromium.components.embedder_support.util.WebResourceResponseInfo; @@ -36,18 +38,17 @@ public AwServiceWorkerSettings getAwServiceWorkerSettings() { /** * Set custom client to receive callbacks from Service Workers. Can be null. */ - public void setServiceWorkerClient(AwServiceWorkerClient client) { + public void setServiceWorkerClient(@Nullable AwServiceWorkerClient client) { mServiceWorkerClient = client; if (client != null) { mServiceWorkerBackgroundThreadClient = new ServiceWorkerBackgroundThreadClientImpl(); mServiceWorkerIoThreadClient = new ServiceWorkerIoThreadClientImpl(); - AwContentsStatics.setServiceWorkerIoThreadClient( - mServiceWorkerIoThreadClient, mBrowserContext); } else { mServiceWorkerBackgroundThreadClient = null; mServiceWorkerIoThreadClient = null; - AwContentsStatics.setServiceWorkerIoThreadClient(null, mBrowserContext); } + AwContentsStatics.setServiceWorkerIoThreadClient( + mServiceWorkerIoThreadClient, mBrowserContext); } // Helper classes implementations @@ -102,7 +103,9 @@ public WebResourceResponseInfo shouldInterceptRequest( // TODO: Consider analogy with AwContentsClient, i.e. // - do we need an onloadresource callback? // - do we need to post an error if the response data == null? - return mServiceWorkerClient.shouldInterceptRequest(request); + return mServiceWorkerClient != null + ? mServiceWorkerClient.shouldInterceptRequest(request) + : null; } } }