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

Unified Diff: android_webview/java/src/org/chromium/android_webview/AwServiceWorkerController.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: rebase 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/AwServiceWorkerController.java
diff --git a/android_webview/java/src/org/chromium/android_webview/AwServiceWorkerController.java b/android_webview/java/src/org/chromium/android_webview/AwServiceWorkerController.java
new file mode 100644
index 0000000000000000000000000000000000000000..699b0e97ec22a8025cc4058f8a4d5bd49d0176e6
--- /dev/null
+++ b/android_webview/java/src/org/chromium/android_webview/AwServiceWorkerController.java
@@ -0,0 +1,117 @@
+// Copyright 2016 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.android_webview;
+
+import android.content.Context;
+
+/**
+ * Manages clients and settings for Service Workers.
+ */
+public class AwServiceWorkerController {
+ private AwServiceWorkerClient mServiceWorkerClient;
+ private AwContentsIoThreadClient mServiceWorkerIoThreadClient;
+ private AwContentsBackgroundThreadClient mServiceWorkerBackgroundThreadClient;
+ private AwServiceWorkerSettings mServiceWorkerSettings;
+ private AwBrowserContext mBrowserContext;
+
+ public AwServiceWorkerController(Context applicationContext, AwBrowserContext browserContext) {
+ mServiceWorkerSettings = new AwServiceWorkerSettings(applicationContext);
+ mBrowserContext = browserContext;
+ }
+
+ /**
+ * Returns the current settings for Service Worker.
+ */
+ public AwServiceWorkerSettings getAwServiceWorkerSettings() {
+ return mServiceWorkerSettings;
+ }
+
+ /**
+ * Set custom client to receive callbacks from Service Workers. Can be null.
+ */
+ public void setServiceWorkerClient(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);
+ }
+ }
+
+ // Helper classes implementations
+
+ private class ServiceWorkerIoThreadClientImpl extends AwContentsIoThreadClient {
+ // All methods are called on the IO thread.
+
+ @Override
+ public int getCacheMode() {
+ return mServiceWorkerSettings.getCacheMode();
+ }
+
+ @Override
+ public AwContentsBackgroundThreadClient getBackgroundThreadClient() {
+ return mServiceWorkerBackgroundThreadClient;
+ }
+
+ @Override
+ public boolean shouldBlockContentUrls() {
+ return !mServiceWorkerSettings.getAllowContentAccess();
+ }
+
+ @Override
+ public boolean shouldBlockFileUrls() {
+ return !mServiceWorkerSettings.getAllowFileAccess();
+ }
+
+ @Override
+ public boolean shouldBlockNetworkLoads() {
+ return mServiceWorkerSettings.getBlockNetworkLoads();
+ }
+
+ @Override
+ public boolean shouldAcceptThirdPartyCookies() {
+ // We currently don't allow third party cookies in service workers,
+ // see e.g. AwCookieAccessPolicy::GetShouldAcceptThirdPartyCookies.
+ 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 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 an onloadresource callback?
+ // - do we need to post an error if the response data == null?
+ return mServiceWorkerClient.shouldInterceptRequest(request);
+ }
+ }
+}

Powered by Google App Engine
This is Rietveld 408576698