Skip to content

Commit

Permalink
[AW] Handle null ServiceWorkerClient.
Browse files Browse the repository at this point in the history
Bug: b/143102352
Change-Id: Ia60cfd8c9d8d05019c8f199496b4b6bca4921b9a
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2905774
Reviewed-by: Bo <[email protected]>
Reviewed-by: Laís Minchillo <[email protected]>
Commit-Queue: Mugdha Lakhani <[email protected]>
Cr-Commit-Position: refs/heads/master@{#885506}
  • Loading branch information
Mugdha Lakhani authored and Chromium LUCI CQ committed May 21, 2021
1 parent 97f125f commit f10638e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
import android.webkit.ServiceWorkerController;
import android.webkit.ServiceWorkerWebSettings;

import androidx.annotation.Nullable;

import org.chromium.android_webview.AwServiceWorkerController;

/**
Expand Down Expand Up @@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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;
}
}
}

0 comments on commit f10638e

Please sign in to comment.