Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(32)

Unified Diff: android_webview/java/src/org/chromium/android_webview/AwContentsStatics.java

Issue 1544863002: [Android WebView] Implement initial settings and callback support for Service Workers. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: more clean-up Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: android_webview/java/src/org/chromium/android_webview/AwContentsStatics.java
diff --git a/android_webview/java/src/org/chromium/android_webview/AwContentsStatics.java b/android_webview/java/src/org/chromium/android_webview/AwContentsStatics.java
index ed9efd865f92ed175aed3674c34abc4486d7c24a..517843da99f21eba2e2e8746845d165224e29bc5 100644
--- a/android_webview/java/src/org/chromium/android_webview/AwContentsStatics.java
+++ b/android_webview/java/src/org/chromium/android_webview/AwContentsStatics.java
@@ -4,6 +4,8 @@
package org.chromium.android_webview;
+import android.webkit.WebSettings;
+
import org.chromium.base.ThreadUtils;
import org.chromium.base.annotations.CalledByNative;
import org.chromium.base.annotations.JNINamespace;
@@ -21,6 +23,10 @@ public class AwContentsStatics {
private static boolean sRecordFullDocument = false;
+ private static AwServiceWorkerClient sServiceWorkerClient;
+ private static AwContentsIoThreadClient sServiceWorkerIoThreadClient;
+ private static AwContentsBackgroundThreadClient sServiceWorkerBackgroundThreadClient;
+
/**
* Return the client certificate lookup table.
*/
@@ -90,6 +96,82 @@ public class AwContentsStatics {
return nativeGetProductVersion();
}
+ /*
+ * Set custom client to receive callbacks from Service Workers. Can be null.
+ */
+ public static void setServiceWorkerClient(AwServiceWorkerClient client) {
+ sServiceWorkerClient = client;
+ sServiceWorkerBackgroundThreadClient = new ServiceWorkerBackgroundThreadClientImpl();
+ sServiceWorkerIoThreadClient = new ServiceWorkerIoThreadClientImpl();
+ nativeSetServiceWorkerIoThreadClient(sServiceWorkerIoThreadClient);
+ }
+
+ private static class ServiceWorkerIoThreadClientImpl extends AwContentsIoThreadClient {
+ // All methods are called on the IO thread.
+
+ @Override
+ public int getCacheMode() {
+ return WebSettings.LOAD_DEFAULT;
+ }
+
+ @Override
+ public AwContentsBackgroundThreadClient getBackgroundThreadClient() {
+ return sServiceWorkerBackgroundThreadClient;
+ }
+
+ @Override
+ public boolean shouldBlockContentUrls() {
+ return false;
+ }
+
+ @Override
+ public boolean shouldBlockFileUrls() {
+ return false;
+ }
+
+ @Override
+ public boolean shouldBlockNetworkLoads() {
+ return false;
+ }
+
+ @Override
+ public boolean shouldAcceptThirdPartyCookies() {
+ return false;
+ }
+
+ @Override
+ public void onDownloadStart(String url, String userAgent,
+ String contentDisposition, String mimeType, long contentLength) {}
+
+ @Override
+ public void newLoginRequest(String realm, String account, String args) {}
+
+ @Override
+ public void onReceivedError(AwContentsClient.AwWebResourceRequest request,
+ AwContentsClient.AwWebResourceError error) {
+ // TODO
+ }
+
+ @Override
+ public void onReceivedHttpError(AwContentsClient.AwWebResourceRequest request,
+ AwWebResourceResponse response) {
+ // TODO
+ }
+ }
+
+ private static class ServiceWorkerBackgroundThreadClientImpl
+ extends AwContentsBackgroundThreadClient {
+ // All methods are called on the background thread.
+ @Override
+ public AwWebResourceResponse shouldInterceptRequest(
+ AwContentsClient.AwWebResourceRequest request) {
+ // TODO: Consider analogy with AwContentsClient, i.e.
+ // - do we need a onloadresource callback?
+ // - do we need to post an error if the response data == null?
+ return sServiceWorkerClient.shouldInterceptRequest(request);
+ }
+ }
+
//--------------------------------------------------------------------------------------------
// Native methods
//--------------------------------------------------------------------------------------------
@@ -99,4 +181,7 @@ public class AwContentsStatics {
private static native String nativeGetUnreachableWebDataUrl();
private static native void nativeSetLegacyCacheRemovalDelayForTest(long timeoutMs);
private static native String nativeGetProductVersion();
+
+ private static native void nativeSetServiceWorkerIoThreadClient(
+ AwContentsIoThreadClient ioThreadClient);
}

Powered by Google App Engine
This is Rietveld 408576698