diff options
11 files changed, 157 insertions, 5 deletions
@@ -7,13 +7,21 @@ import("//build/config/android/rules.gni") android_library("boundary_interface_java") { java_files = [ + "src/org/chromium/support_lib_boundary/SafeBrowsingResponseBoundaryInterface.java", + "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", + "src/org/chromium/support_lib_boundary/WebResourceErrorBoundaryInterface.java", "src/org/chromium/support_lib_boundary/WebSettingsBoundaryInterface.java", + "src/org/chromium/support_lib_boundary/WebViewClientBoundaryInterface.java", "src/org/chromium/support_lib_boundary/WebViewProviderBoundaryInterface.java", "src/org/chromium/support_lib_boundary/WebViewProviderFactoryBoundaryInterface.java", "src/org/chromium/support_lib_boundary/WebkitToCompatConverterBoundaryInterface.java", "src/org/chromium/support_lib_boundary/util/BoundaryInterfaceReflectionUtil.java", + "src/org/chromium/support_lib_boundary/util/Features.java", ] proguard_configs = [ "proguard.flags" ] diff --git a/src/org/chromium/support_lib_boundary/SafeBrowsingResponseBoundaryInterface.java b/src/org/chromium/support_lib_boundary/SafeBrowsingResponseBoundaryInterface.java new file mode 100644 index 0000000..93a7a25 --- /dev/null +++ b/src/org/chromium/support_lib_boundary/SafeBrowsingResponseBoundaryInterface.java @@ -0,0 +1,14 @@ +// 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 SafeBrowsingResponseCompat. + */ +public interface SafeBrowsingResponseBoundaryInterface { + public void showInterstitial(boolean allowReporting); + public void proceed(boolean report); + public void backToSafety(boolean report); +} diff --git a/src/org/chromium/support_lib_boundary/ServiceWorkerClientBoundaryInterface.java b/src/org/chromium/support_lib_boundary/ServiceWorkerClientBoundaryInterface.java new file mode 100644 index 0000000..36a9cfc --- /dev/null +++ b/src/org/chromium/support_lib_boundary/ServiceWorkerClientBoundaryInterface.java @@ -0,0 +1,15 @@ +// 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); +} diff --git a/src/org/chromium/support_lib_boundary/ServiceWorkerControllerBoundaryInterface.java b/src/org/chromium/support_lib_boundary/ServiceWorkerControllerBoundaryInterface.java new file mode 100644 index 0000000..e25e3ed --- /dev/null +++ b/src/org/chromium/support_lib_boundary/ServiceWorkerControllerBoundaryInterface.java @@ -0,0 +1,15 @@ +// 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); +} diff --git a/src/org/chromium/support_lib_boundary/ServiceWorkerWebSettingsBoundaryInterface.java b/src/org/chromium/support_lib_boundary/ServiceWorkerWebSettingsBoundaryInterface.java new file mode 100644 index 0000000..dfd61fa --- /dev/null +++ b/src/org/chromium/support_lib_boundary/ServiceWorkerWebSettingsBoundaryInterface.java @@ -0,0 +1,26 @@ +// 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(); +} diff --git a/src/org/chromium/support_lib_boundary/SupportLibraryInfoBoundaryInterface.java b/src/org/chromium/support_lib_boundary/SupportLibraryInfoBoundaryInterface.java new file mode 100644 index 0000000..11a141f --- /dev/null +++ b/src/org/chromium/support_lib_boundary/SupportLibraryInfoBoundaryInterface.java @@ -0,0 +1,12 @@ +// 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; + +/** + * Contains information about the WebView support library side, e.g. which features are supported on + * that side. + * This is passed to the WebView APK code on support library initialization. + */ +public interface SupportLibraryInfoBoundaryInterface { String[] getSupportedFeatures(); } diff --git a/src/org/chromium/support_lib_boundary/WebResourceErrorBoundaryInterface.java b/src/org/chromium/support_lib_boundary/WebResourceErrorBoundaryInterface.java new file mode 100644 index 0000000..52db23c --- /dev/null +++ b/src/org/chromium/support_lib_boundary/WebResourceErrorBoundaryInterface.java @@ -0,0 +1,13 @@ +// 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 WebResourceErrorCompat. + */ +public interface WebResourceErrorBoundaryInterface { + public int getErrorCode(); + public CharSequence getDescription(); +} diff --git a/src/org/chromium/support_lib_boundary/WebViewClientBoundaryInterface.java b/src/org/chromium/support_lib_boundary/WebViewClientBoundaryInterface.java new file mode 100644 index 0000000..2fccfe4 --- /dev/null +++ b/src/org/chromium/support_lib_boundary/WebViewClientBoundaryInterface.java @@ -0,0 +1,25 @@ +// 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; +import android.webkit.WebView; + +import java.lang.reflect.InvocationHandler; + +/** + * Boundary interface for WebViewClientCompat. + */ +public interface WebViewClientBoundaryInterface { + void onPageCommitVisible(WebView view, String url); + void onReceivedError(WebView view, WebResourceRequest request, + /* WebResourceError */ InvocationHandler error); + void onReceivedHttpError( + WebView view, WebResourceRequest request, WebResourceResponse errorResponse); + void onSafeBrowsingHit(WebView view, WebResourceRequest request, int threatType, + /* SafeBrowsingResponse */ InvocationHandler callback); + boolean shouldOverrideUrlLoading(WebView view, WebResourceRequest request); +} diff --git a/src/org/chromium/support_lib_boundary/WebViewProviderFactoryBoundaryInterface.java b/src/org/chromium/support_lib_boundary/WebViewProviderFactoryBoundaryInterface.java index e868f7a..380bf42 100644 --- a/src/org/chromium/support_lib_boundary/WebViewProviderFactoryBoundaryInterface.java +++ b/src/org/chromium/support_lib_boundary/WebViewProviderFactoryBoundaryInterface.java @@ -14,4 +14,6 @@ public interface WebViewProviderFactoryBoundaryInterface { /* SupportLibraryWebViewChromium */ InvocationHandler createWebView(WebView webview); /* SupportLibWebkitToCompatConverter */ InvocationHandler getWebkitToCompatConverter(); /* StaticsAdapter */ InvocationHandler getStatics(); + String[] getSupportedFeatures(); + /* SupportLibraryServiceWorkerController */ InvocationHandler getServiceWorkerController(); } diff --git a/src/org/chromium/support_lib_boundary/util/BoundaryInterfaceReflectionUtil.java b/src/org/chromium/support_lib_boundary/util/BoundaryInterfaceReflectionUtil.java index 5a772c5..51c78ed 100644 --- a/src/org/chromium/support_lib_boundary/util/BoundaryInterfaceReflectionUtil.java +++ b/src/org/chromium/support_lib_boundary/util/BoundaryInterfaceReflectionUtil.java @@ -16,13 +16,14 @@ import java.lang.reflect.Proxy; */ public class BoundaryInterfaceReflectionUtil { /** - * Utility method for fetching a method from the current classloader, with the same signature + * Utility method for fetching a method from {@param delegateLoader}, with the same signature * (package + class + method name + parameters) as a given method defined in another * classloader. */ - public static Method dupeMethod(Method method) + public static Method dupeMethod(Method method, ClassLoader delegateLoader) throws ClassNotFoundException, NoSuchMethodException { - Class<?> declaringClass = Class.forName(method.getDeclaringClass().getName()); + Class<?> declaringClass = + Class.forName(method.getDeclaringClass().getName(), true, delegateLoader); Class[] otherSideParameterClasses = method.getParameterTypes(); Class[] parameterClasses = new Class[otherSideParameterClasses.length]; for (int n = 0; n < parameterClasses.length; n++) { @@ -30,7 +31,9 @@ public class BoundaryInterfaceReflectionUtil { // Primitive classes are shared between the classloaders - so we can use the same // primitive class declarations on either side. Non-primitive classes must be looked up // by name. - parameterClasses[n] = clazz.isPrimitive() ? clazz : Class.forName(clazz.getName()); + parameterClasses[n] = clazz.isPrimitive() + ? clazz + : Class.forName(clazz.getName(), true, delegateLoader); } return declaringClass.getDeclaredMethod(method.getName(), parameterClasses); } @@ -53,11 +56,12 @@ public class BoundaryInterfaceReflectionUtil { */ @TargetApi(Build.VERSION_CODES.KITKAT) public static InvocationHandler createInvocationHandlerFor(final Object delegate) { + final ClassLoader delegateLoader = delegate.getClass().getClassLoader(); return new InvocationHandler() { @Override public Object invoke(Object o, Method method, Object[] objects) throws Throwable { try { - return dupeMethod(method).invoke(delegate, objects); + return dupeMethod(method, delegateLoader).invoke(delegate, objects); } catch (InvocationTargetException e) { // If something went wrong, ensure we throw the original exception. throw e.getTargetException(); diff --git a/src/org/chromium/support_lib_boundary/util/Features.java b/src/org/chromium/support_lib_boundary/util/Features.java new file mode 100644 index 0000000..d74ea55 --- /dev/null +++ b/src/org/chromium/support_lib_boundary/util/Features.java @@ -0,0 +1,18 @@ +// 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.util; + +/** + * Class containing all the features the support library can support. + * This class lives in the boundary interface directory so that the Android Support Library and + * Chromium can share its definition. + */ +public class Features { + // This class just contains constants representing features. + private Features() {} + + // WebViewCompat.postVisualStateCallback + public static final String VISUAL_STATE_CALLBACK = "VISUAL_STATE_CALLBACK"; +} |