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

[Android WebVIew] Prepare to support Service Worker APIs in support lib

Split/publish ServiceWorker related functionality in the android.webkit
glue layer to allow the support library glue to use that functionality.

Bug: 819595
Change-Id: Ia705f3c867400f4ab30c0cc14083e7a0abc0a269
Reviewed-on: https://chromium-review.googlesource.com/958867Reviewed-by: default avatarBo <boliu@chromium.org>
Commit-Queue: Gustav Sennton <gsennton@chromium.org>
Cr-Commit-Position: refs/heads/master@{#542566}
parent 7e6b186d
...@@ -33,6 +33,10 @@ public class ServiceWorkerClientAdapter extends AwServiceWorkerClient { ...@@ -33,6 +33,10 @@ public class ServiceWorkerClientAdapter extends AwServiceWorkerClient {
public AwWebResourceResponse shouldInterceptRequest(AwWebResourceRequest request) { public AwWebResourceResponse shouldInterceptRequest(AwWebResourceRequest request) {
WebResourceResponse response = WebResourceResponse response =
mServiceWorkerClient.shouldInterceptRequest(new WebResourceRequestAdapter(request)); mServiceWorkerClient.shouldInterceptRequest(new WebResourceRequestAdapter(request));
return fromWebResourceResponse(response);
}
public static AwWebResourceResponse fromWebResourceResponse(WebResourceResponse response) {
if (response == null) return null; if (response == null) return null;
// AwWebResourceResponse should support null headers. b/16332774. // AwWebResourceResponse should support null headers. b/16332774.
......
...@@ -11,7 +11,10 @@ import org.chromium.android_webview.AwContentsClient.AwWebResourceRequest; ...@@ -11,7 +11,10 @@ import org.chromium.android_webview.AwContentsClient.AwWebResourceRequest;
import java.util.Map; import java.util.Map;
class WebResourceRequestAdapter implements WebResourceRequest { /**
* Adapter between WebResourceRequest and AwWebResourceRequest.
*/
public class WebResourceRequestAdapter implements WebResourceRequest {
private final AwWebResourceRequest mRequest; private final AwWebResourceRequest mRequest;
public WebResourceRequestAdapter(AwWebResourceRequest request) { public WebResourceRequestAdapter(AwWebResourceRequest request) {
......
...@@ -14,7 +14,6 @@ import android.os.Process; ...@@ -14,7 +14,6 @@ import android.os.Process;
import android.util.Log; import android.util.Log;
import android.webkit.CookieManager; import android.webkit.CookieManager;
import android.webkit.GeolocationPermissions; import android.webkit.GeolocationPermissions;
import android.webkit.ServiceWorkerController;
import android.webkit.TokenBindingService; import android.webkit.TokenBindingService;
import android.webkit.WebStorage; import android.webkit.WebStorage;
import android.webkit.WebViewDatabase; import android.webkit.WebViewDatabase;
...@@ -30,6 +29,7 @@ import org.chromium.android_webview.AwCookieManager; ...@@ -30,6 +29,7 @@ import org.chromium.android_webview.AwCookieManager;
import org.chromium.android_webview.AwNetworkChangeNotifierRegistrationPolicy; import org.chromium.android_webview.AwNetworkChangeNotifierRegistrationPolicy;
import org.chromium.android_webview.AwQuotaManagerBridge; import org.chromium.android_webview.AwQuotaManagerBridge;
import org.chromium.android_webview.AwResource; import org.chromium.android_webview.AwResource;
import org.chromium.android_webview.AwServiceWorkerController;
import org.chromium.android_webview.AwSwitches; import org.chromium.android_webview.AwSwitches;
import org.chromium.android_webview.AwTracingController; import org.chromium.android_webview.AwTracingController;
import org.chromium.android_webview.HttpAuthDatabase; import org.chromium.android_webview.HttpAuthDatabase;
...@@ -66,7 +66,7 @@ public class WebViewChromiumAwInit { ...@@ -66,7 +66,7 @@ public class WebViewChromiumAwInit {
private WebIconDatabaseAdapter mWebIconDatabase; private WebIconDatabaseAdapter mWebIconDatabase;
private WebStorageAdapter mWebStorage; private WebStorageAdapter mWebStorage;
private WebViewDatabaseAdapter mWebViewDatabase; private WebViewDatabaseAdapter mWebViewDatabase;
private Object mServiceWorkerController; private AwServiceWorkerController mServiceWorkerController;
private AwTracingController mAwTracingController; private AwTracingController mAwTracingController;
// Guards accees to the other members, and is notifyAll() signalled on the UI thread // Guards accees to the other members, and is notifyAll() signalled on the UI thread
...@@ -173,10 +173,7 @@ public class WebViewChromiumAwInit { ...@@ -173,10 +173,7 @@ public class WebViewChromiumAwInit {
mFactory, awBrowserContext.getGeolocationPermissions()); mFactory, awBrowserContext.getGeolocationPermissions());
mWebStorage = new WebStorageAdapter(mFactory, AwQuotaManagerBridge.getInstance()); mWebStorage = new WebStorageAdapter(mFactory, AwQuotaManagerBridge.getInstance());
mAwTracingController = awBrowserContext.getTracingController(); mAwTracingController = awBrowserContext.getTracingController();
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.M) { mServiceWorkerController = awBrowserContext.getServiceWorkerController();
mServiceWorkerController = new ServiceWorkerControllerAdapter(
awBrowserContext.getServiceWorkerController());
}
mFactory.getRunQueue().drainQueue(); mFactory.getRunQueue().drainQueue();
...@@ -324,13 +321,13 @@ public class WebViewChromiumAwInit { ...@@ -324,13 +321,13 @@ public class WebViewChromiumAwInit {
return mCookieManager; return mCookieManager;
} }
public ServiceWorkerController getServiceWorkerController() { public AwServiceWorkerController getServiceWorkerController() {
synchronized (mLock) { synchronized (mLock) {
if (mServiceWorkerController == null) { if (mServiceWorkerController == null) {
ensureChromiumStartedLocked(true); ensureChromiumStartedLocked(true);
} }
} }
return (ServiceWorkerController) mServiceWorkerController; return mServiceWorkerController;
} }
public TokenBindingService getTokenBindingService() { public TokenBindingService getTokenBindingService() {
......
...@@ -100,6 +100,7 @@ public class WebViewChromiumFactoryProvider implements WebViewFactoryProvider { ...@@ -100,6 +100,7 @@ public class WebViewChromiumFactoryProvider implements WebViewFactoryProvider {
// Initialization guarded by mAwInit.getLock() // Initialization guarded by mAwInit.getLock()
private Statics mStaticsAdapter; private Statics mStaticsAdapter;
private Object mServiceWorkerControllerAdapter;
/** /**
* Thread-safe way to set the one and only WebViewChromiumFactoryProvider. * Thread-safe way to set the one and only WebViewChromiumFactoryProvider.
...@@ -422,7 +423,13 @@ public class WebViewChromiumFactoryProvider implements WebViewFactoryProvider { ...@@ -422,7 +423,13 @@ public class WebViewChromiumFactoryProvider implements WebViewFactoryProvider {
@Override @Override
public ServiceWorkerController getServiceWorkerController() { public ServiceWorkerController getServiceWorkerController() {
return mAwInit.getServiceWorkerController(); synchronized (mAwInit.getLock()) {
if (mServiceWorkerControllerAdapter == null) {
mServiceWorkerControllerAdapter =
new ServiceWorkerControllerAdapter(mAwInit.getServiceWorkerController());
}
}
return (ServiceWorkerController) mServiceWorkerControllerAdapter;
} }
@Override @Override
......
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