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

[WebView Support Library] Support service worker APIs.

Provide (chromium-side) support for ServiceWorkers in the WebView
Support Library.
We'll add feature flags for the ServiceWorker APIs in a follow-up.

Bug: 819595
Change-Id: Id4c79e3970706633e36b28538c443a00c7e59e03
Reviewed-on: https://chromium-review.googlesource.com/964142Reviewed-by: default avatarRichard Coles <torne@chromium.org>
Reviewed-by: default avatarNate Fischer <ntfschr@chromium.org>
Commit-Queue: Gustav Sennton <gsennton@chromium.org>
Cr-Commit-Position: refs/heads/master@{#545024}
parent e76515b1
......@@ -8,6 +8,9 @@ import("//build/config/android/rules.gni")
android_library("support_lib_glue_java") {
java_files = [
"java/src/org/chromium/support_lib_glue/SupportLibReflectionUtil.java",
"java/src/org/chromium/support_lib_glue/SupportLibServiceWorkerClientAdapter.java",
"java/src/org/chromium/support_lib_glue/SupportLibServiceWorkerControllerAdapter.java",
"java/src/org/chromium/support_lib_glue/SupportLibServiceWorkerSettingsAdapter.java",
"java/src/org/chromium/support_lib_glue/SupportLibWebSettingsAdapter.java",
"java/src/org/chromium/support_lib_glue/SupportLibWebViewChromium.java",
"java/src/org/chromium/support_lib_glue/SupportLibWebViewChromiumFactory.java",
......
......@@ -7,6 +7,9 @@ import("//build/config/android/rules.gni")
android_library("boundary_interface_java") {
java_files = [
"src/org/chromium/support_lib_boundary/ServiceWorkerClientBoundaryInterface.java",
"src/org/chromium/support_lib_boundary/ServiceWorkerControllerBoundaryInterface.java",
"src/org/chromium/support_lib_boundary/ServiceWorkerWebSettingsBoundaryInterface.java",
"src/org/chromium/support_lib_boundary/StaticsBoundaryInterface.java",
"src/org/chromium/support_lib_boundary/SupportLibraryInfoBoundaryInterface.java",
"src/org/chromium/support_lib_boundary/VisualStateCallbackBoundaryInterface.java",
......
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
package org.chromium.support_lib_boundary;
import android.webkit.WebResourceRequest;
import android.webkit.WebResourceResponse;
/**
* Boundary interface for ServiceWorkerClient.
*/
public interface ServiceWorkerClientBoundaryInterface {
WebResourceResponse shouldInterceptRequest(WebResourceRequest request);
}
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
package org.chromium.support_lib_boundary;
import java.lang.reflect.InvocationHandler;
/**
* Boundary interface for ServiceWorkerController.
*/
public interface ServiceWorkerControllerBoundaryInterface {
/* ServiceWorkerWebSettings */ InvocationHandler getServiceWorkerWebSettings();
void setServiceWorkerClient(/* ServiceWorkerClient */ InvocationHandler client);
}
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
package org.chromium.support_lib_boundary;
/**
* Boundary interface for ServiceWorkerWebSettings.
*/
public interface ServiceWorkerWebSettingsBoundaryInterface {
void setCacheMode(int mode);
int getCacheMode();
void setAllowContentAccess(boolean allow);
boolean getAllowContentAccess();
void setAllowFileAccess(boolean allow);
boolean getAllowFileAccess();
void setBlockNetworkLoads(boolean flag);
boolean getBlockNetworkLoads();
}
......@@ -15,4 +15,5 @@ public interface WebViewProviderFactoryBoundaryInterface {
/* SupportLibWebkitToCompatConverter */ InvocationHandler getWebkitToCompatConverter();
/* StaticsAdapter */ InvocationHandler getStatics();
String[] getSupportedFeatures();
/* SupportLibraryServiceWorkerController */ InvocationHandler getServiceWorkerController();
}
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
package org.chromium.support_lib_glue;
import android.webkit.WebResourceResponse;
import com.android.webview.chromium.ServiceWorkerClientAdapter;
import com.android.webview.chromium.WebResourceRequestAdapter;
import org.chromium.android_webview.AwContentsClient.AwWebResourceRequest;
import org.chromium.android_webview.AwServiceWorkerClient;
import org.chromium.android_webview.AwWebResourceResponse;
import org.chromium.support_lib_boundary.ServiceWorkerClientBoundaryInterface;
/**
* Adapter between ServiceWorkerClientBoundaryInterface and AwServiceWorkerClient.
*/
class SupportLibServiceWorkerClientAdapter extends AwServiceWorkerClient {
ServiceWorkerClientBoundaryInterface mImpl;
SupportLibServiceWorkerClientAdapter(ServiceWorkerClientBoundaryInterface impl) {
mImpl = impl;
}
@Override
public AwWebResourceResponse shouldInterceptRequest(AwWebResourceRequest request) {
WebResourceResponse response =
mImpl.shouldInterceptRequest(new WebResourceRequestAdapter(request));
return ServiceWorkerClientAdapter.fromWebResourceResponse(response);
}
}
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
package org.chromium.support_lib_glue;
import org.chromium.android_webview.AwServiceWorkerController;
import org.chromium.support_lib_boundary.ServiceWorkerClientBoundaryInterface;
import org.chromium.support_lib_boundary.ServiceWorkerControllerBoundaryInterface;
import org.chromium.support_lib_boundary.util.BoundaryInterfaceReflectionUtil;
import java.lang.reflect.InvocationHandler;
/**
* Adapter between AwServiceWorkerController and ServiceWorkerControllerBoundaryInterface.
*/
class SupportLibServiceWorkerControllerAdapter implements ServiceWorkerControllerBoundaryInterface {
AwServiceWorkerController mAwServiceWorkerController;
SupportLibServiceWorkerControllerAdapter(AwServiceWorkerController awServiceController) {
mAwServiceWorkerController = awServiceController;
}
@Override
public InvocationHandler getServiceWorkerWebSettings() {
return BoundaryInterfaceReflectionUtil.createInvocationHandlerFor(
new SupportLibServiceWorkerSettingsAdapter(
mAwServiceWorkerController.getAwServiceWorkerSettings()));
}
@Override
public void setServiceWorkerClient(InvocationHandler client) {
mAwServiceWorkerController.setServiceWorkerClient(new SupportLibServiceWorkerClientAdapter(
BoundaryInterfaceReflectionUtil.castToSuppLibClass(
ServiceWorkerClientBoundaryInterface.class, client)));
}
}
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
package org.chromium.support_lib_glue;
import org.chromium.android_webview.AwServiceWorkerSettings;
import org.chromium.support_lib_boundary.ServiceWorkerWebSettingsBoundaryInterface;
/**
* Adapter between AwServiceWorkerSettings and ServiceWorkerWebSettingsBoundaryInterface.
*/
class SupportLibServiceWorkerSettingsAdapter implements ServiceWorkerWebSettingsBoundaryInterface {
private AwServiceWorkerSettings mAwServiceWorkerSettings;
SupportLibServiceWorkerSettingsAdapter(AwServiceWorkerSettings settings) {
mAwServiceWorkerSettings = settings;
}
@Override
public void setCacheMode(int mode) {
mAwServiceWorkerSettings.setCacheMode(mode);
}
@Override
public int getCacheMode() {
return mAwServiceWorkerSettings.getCacheMode();
}
@Override
public void setAllowContentAccess(boolean allow) {
mAwServiceWorkerSettings.setAllowContentAccess(allow);
}
@Override
public boolean getAllowContentAccess() {
return mAwServiceWorkerSettings.getAllowContentAccess();
}
@Override
public void setAllowFileAccess(boolean allow) {
mAwServiceWorkerSettings.setAllowFileAccess(allow);
}
@Override
public boolean getAllowFileAccess() {
return mAwServiceWorkerSettings.getAllowFileAccess();
}
@Override
public void setBlockNetworkLoads(boolean flag) {
mAwServiceWorkerSettings.setBlockNetworkLoads(flag);
}
@Override
public boolean getBlockNetworkLoads() {
return mAwServiceWorkerSettings.getBlockNetworkLoads();
}
}
......@@ -36,6 +36,7 @@ class SupportLibWebViewChromiumFactory implements WebViewProviderFactoryBoundary
// Initialization guarded by mAwInit.getLock()
private InvocationHandler mStatics;
private InvocationHandler mServiceWorkerController;
public SupportLibWebViewChromiumFactory(
/* SupportLibraryInfo */ InvocationHandler supportLibraryInfo) {
......@@ -101,4 +102,17 @@ class SupportLibWebViewChromiumFactory implements WebViewProviderFactoryBoundary
public String[] getSupportedFeatures() {
return mWebViewSupportedFeatures;
}
@Override
public InvocationHandler getServiceWorkerController() {
synchronized (mAwInit.getLock()) {
if (mServiceWorkerController == null) {
mServiceWorkerController =
BoundaryInterfaceReflectionUtil.createInvocationHandlerFor(
new SupportLibServiceWorkerControllerAdapter(
mAwInit.getServiceWorkerController()));
}
}
return mServiceWorkerController;
}
}
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