diff options
Diffstat (limited to 'src/org')
11 files changed, 160 insertions, 16 deletions
diff --git a/src/org/chromium/support_lib_boundary/JsReplyProxyBoundaryInterface.java b/src/org/chromium/support_lib_boundary/JsReplyProxyBoundaryInterface.java new file mode 100644 index 0000000..e2da069 --- /dev/null +++ b/src/org/chromium/support_lib_boundary/JsReplyProxyBoundaryInterface.java @@ -0,0 +1,12 @@ +// Copyright 2019 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 org.chromium.android_webview.WebMessageListener. + */ +public interface JsReplyProxyBoundaryInterface extends IsomorphicObjectBoundaryInterface { + void postMessage(String message); +} diff --git a/src/org/chromium/support_lib_boundary/ProxyControllerBoundaryInterface.java b/src/org/chromium/support_lib_boundary/ProxyControllerBoundaryInterface.java index f9abc59..07888ef 100644 --- a/src/org/chromium/support_lib_boundary/ProxyControllerBoundaryInterface.java +++ b/src/org/chromium/support_lib_boundary/ProxyControllerBoundaryInterface.java @@ -12,5 +12,7 @@ import java.util.concurrent.Executor; public interface ProxyControllerBoundaryInterface { void setProxyOverride( String[][] proxyRules, String[] bypassRules, Runnable listener, Executor executor); + void setProxyOverride(String[][] proxyRules, String[] bypassRules, Runnable listener, + Executor executor, boolean reverseBypass); void clearProxyOverride(Runnable listener, Executor executor); } diff --git a/src/org/chromium/support_lib_boundary/ScriptHandlerBoundaryInterface.java b/src/org/chromium/support_lib_boundary/ScriptHandlerBoundaryInterface.java new file mode 100644 index 0000000..4dcaa75 --- /dev/null +++ b/src/org/chromium/support_lib_boundary/ScriptHandlerBoundaryInterface.java @@ -0,0 +1,10 @@ +// Copyright 2020 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 AwContents.addDocumentStartJavascript(). + */ +public interface ScriptHandlerBoundaryInterface extends ScriptReferenceBoundaryInterface {} diff --git a/src/org/chromium/support_lib_boundary/ScriptReferenceBoundaryInterface.java b/src/org/chromium/support_lib_boundary/ScriptReferenceBoundaryInterface.java new file mode 100644 index 0000000..aba822a --- /dev/null +++ b/src/org/chromium/support_lib_boundary/ScriptReferenceBoundaryInterface.java @@ -0,0 +1,15 @@ +// Copyright 2020 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 AwContents.addDocumentStartJavascript(). + * + * TODO(ctzsm): Delete this interface once we've updated the APKs on + * the AndroidX bots and move the remove method to ScriptHandlerBoundaryInterface. + */ +public interface ScriptReferenceBoundaryInterface { + void remove(); +} diff --git a/src/org/chromium/support_lib_boundary/StaticsBoundaryInterface.java b/src/org/chromium/support_lib_boundary/StaticsBoundaryInterface.java index 648d416..c2d3864 100644 --- a/src/org/chromium/support_lib_boundary/StaticsBoundaryInterface.java +++ b/src/org/chromium/support_lib_boundary/StaticsBoundaryInterface.java @@ -9,12 +9,14 @@ import android.net.Uri; import android.webkit.ValueCallback; import java.util.List; +import java.util.Set; /** * Boundary interface for WebViewFactoryProvider.Statics. */ public interface StaticsBoundaryInterface { void initSafeBrowsing(Context context, ValueCallback<Boolean> callback); + void setSafeBrowsingAllowlist(Set<String> hosts, ValueCallback<Boolean> callback); void setSafeBrowsingWhitelist(List<String> hosts, ValueCallback<Boolean> callback); Uri getSafeBrowsingPrivacyPolicyUrl(); boolean isMultiProcessEnabled(); diff --git a/src/org/chromium/support_lib_boundary/WebMessageListenerBoundaryInterface.java b/src/org/chromium/support_lib_boundary/WebMessageListenerBoundaryInterface.java new file mode 100644 index 0000000..92a393f --- /dev/null +++ b/src/org/chromium/support_lib_boundary/WebMessageListenerBoundaryInterface.java @@ -0,0 +1,18 @@ +// Copyright 2019 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.net.Uri; +import android.webkit.WebView; + +import java.lang.reflect.InvocationHandler; + +/** + * Boundary interface for org.chromium.android_webview.WebMessageListener. + */ +public interface WebMessageListenerBoundaryInterface extends FeatureFlagHolderBoundaryInterface { + void onPostMessage(WebView view, /* WebMessage */ InvocationHandler message, Uri sourceOrigin, + boolean isMainFrame, /* JsReplyProxy */ InvocationHandler replyProxy); +} diff --git a/src/org/chromium/support_lib_boundary/WebSettingsBoundaryInterface.java b/src/org/chromium/support_lib_boundary/WebSettingsBoundaryInterface.java index ef4ce36..426eb6d 100644 --- a/src/org/chromium/support_lib_boundary/WebSettingsBoundaryInterface.java +++ b/src/org/chromium/support_lib_boundary/WebSettingsBoundaryInterface.java @@ -8,6 +8,10 @@ package org.chromium.support_lib_boundary; // android.webkit parameter or android.webkit return value. But for forwards compatibility all // app-facing classes should have a boundary-interface that the WebView glue layer can build // against. + +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; + /** * Boundary interface for WebSettingsCompat. */ @@ -26,4 +30,15 @@ public interface WebSettingsBoundaryInterface { void setForceDark(int forceDarkMode); int getForceDark(); + + @Retention(RetentionPolicy.SOURCE) + @interface ForceDarkBehavior { + int FORCE_DARK_ONLY = 0; + int MEDIA_QUERY_ONLY = 1; + int PREFER_MEDIA_QUERY_OVER_FORCE_DARK = 2; + } + + void setForceDarkBehavior(@ForceDarkBehavior int forceDarkBehavior); + @ForceDarkBehavior + int getForceDarkBehavior(); } diff --git a/src/org/chromium/support_lib_boundary/WebViewProviderBoundaryInterface.java b/src/org/chromium/support_lib_boundary/WebViewProviderBoundaryInterface.java index c896d89..d524b31 100644 --- a/src/org/chromium/support_lib_boundary/WebViewProviderBoundaryInterface.java +++ b/src/org/chromium/support_lib_boundary/WebViewProviderBoundaryInterface.java @@ -17,6 +17,11 @@ public interface WebViewProviderBoundaryInterface { /* VisualStateCallback */ InvocationHandler callback); /* WebMessagePort */ InvocationHandler[] createWebMessageChannel(); void postMessageToMainFrame(/* WebMessage */ InvocationHandler message, Uri targetOrigin); + void addWebMessageListener(String jsObjectName, String[] allowedOriginRules, + /* WebMessageListener */ InvocationHandler listener); + void removeWebMessageListener(String jsObjectName); + /* ScriptHandler */ InvocationHandler addDocumentStartJavaScript( + String script, String[] allowedOriginRules); WebViewClient getWebViewClient(); WebChromeClient getWebChromeClient(); /* WebViewRenderer */ InvocationHandler getWebViewRenderer(); diff --git a/src/org/chromium/support_lib_boundary/WebViewProviderFactoryBoundaryInterface.java b/src/org/chromium/support_lib_boundary/WebViewProviderFactoryBoundaryInterface.java index 15db689..902a04b 100644 --- a/src/org/chromium/support_lib_boundary/WebViewProviderFactoryBoundaryInterface.java +++ b/src/org/chromium/support_lib_boundary/WebViewProviderFactoryBoundaryInterface.java @@ -18,4 +18,5 @@ public interface WebViewProviderFactoryBoundaryInterface { /* SupportLibraryServiceWorkerController */ InvocationHandler getServiceWorkerController(); /* SupportLibraryTracingController */ InvocationHandler getTracingController(); /* SupportLibraryProxyController */ InvocationHandler getProxyController(); + void setSupportLibraryVersion(String version); } diff --git a/src/org/chromium/support_lib_boundary/util/BoundaryInterfaceReflectionUtil.java b/src/org/chromium/support_lib_boundary/util/BoundaryInterfaceReflectionUtil.java index 931cc89..0be05d2 100644 --- a/src/org/chromium/support_lib_boundary/util/BoundaryInterfaceReflectionUtil.java +++ b/src/org/chromium/support_lib_boundary/util/BoundaryInterfaceReflectionUtil.java @@ -3,10 +3,12 @@ // found in the LICENSE file. package org.chromium.support_lib_boundary.util; -import android.annotation.SuppressLint; -import android.annotation.TargetApi; import android.os.Build; +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; +import androidx.annotation.RequiresApi; + import java.lang.reflect.InvocationHandler; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; @@ -19,7 +21,6 @@ import java.util.Collection; */ // Although this is not enforced in chromium, this is a requirement enforced when this file is // mirrored into AndroidX. See http://b/120770118 for details. -@SuppressLint("BanTargetApiAnnotation") public class BoundaryInterfaceReflectionUtil { /** * Check if an object is an instance of {@code className}, resolving {@code className} in @@ -61,29 +62,57 @@ public class BoundaryInterfaceReflectionUtil { /** * Returns an implementation of the boundary interface named clazz, by delegating method calls * to the {@link InvocationHandler} invocationHandler. + * + * <p>A {@code null} {@link InvocationHandler} is treated as representing a {@code null} object. + * + * @param clazz a {@link Class} object representing the desired boundary interface. + * @param invocationHandler an {@link InvocationHandler} compatible with this boundary + * interface. */ - public static <T> T castToSuppLibClass(Class<T> clazz, InvocationHandler invocationHandler) { + @Nullable + public static <T> T castToSuppLibClass( + @NonNull Class<T> clazz, @Nullable InvocationHandler invocationHandler) { + if (invocationHandler == null) return null; return clazz.cast( Proxy.newProxyInstance(BoundaryInterfaceReflectionUtil.class.getClassLoader(), new Class[] {clazz}, invocationHandler)); } /** - * Create an {@link java.lang.reflect.InvocationHandler} that delegates method calls to - * {@param delegate}, making sure that the {@link java.lang.reflect.Method} and parameters being - * passed to {@param delegate} exist in the same {@link java.lang.ClassLoader} as {@param - * delegate}. + * Create an {@link InvocationHandler} that delegates method calls to {@code delegate}, making + * sure that the {@link Method} and parameters being passed exist in the same {@link + * ClassLoader} as {@code delegate}. + * + * <p>A {@code null} delegate is represented with a {@code null} {@link InvocationHandler}. + * + * @param delegate the object which the resulting {@link InvocationHandler} should delegate + * method calls to. + * @return an InvocationHandlerWithDelegateGetter wrapping {@code delegate} */ - @TargetApi(Build.VERSION_CODES.KITKAT) - public static InvocationHandler createInvocationHandlerFor(final Object delegate) { + @RequiresApi(Build.VERSION_CODES.KITKAT) + @Nullable + public static InvocationHandler createInvocationHandlerFor(@Nullable final Object delegate) { + if (delegate == null) return null; return new InvocationHandlerWithDelegateGetter(delegate); } /** - * Plural version of {@link #createInvocationHandlerFor(Object)}. + * Plural version of {@link #createInvocationHandlerFor(Object)}. The resulting array will be + * the same length as {@code delegates}, where the nth {@code InvocationHandler} wraps the nth + * delegate object. + * + * <p>A {@code null} array of delegates is represented with a {@code null} array of {@link + * InvocationHandler}s. Any individual {@code null} delegate is represented with a {@code null} + * {@link InvocationHandler}. + + * @param delegates an array of objects to which to delegate. + * @return an array of InvocationHandlerWithDelegateGetter instances, each delegating to + * the corresponding member of {@code delegates}. */ - @TargetApi(Build.VERSION_CODES.KITKAT) - public static InvocationHandler[] createInvocationHandlersForArray(final Object[] delegates) { + @RequiresApi(Build.VERSION_CODES.KITKAT) + @Nullable + public static InvocationHandler[] createInvocationHandlersForArray( + @Nullable final Object[] delegates) { if (delegates == null) return null; InvocationHandler[] handlers = new InvocationHandler[delegates.length]; @@ -97,8 +126,17 @@ public class BoundaryInterfaceReflectionUtil { * Assuming that the given InvocationHandler was created in the current classloader and is an * InvocationHandlerWithDelegateGetter, return the object the InvocationHandler delegates its * method calls to. + * + * <p>A {@code null} {@link InvocationHandler} is treated as wrapping a {@code null} delegate. + * + * @param invocationHandler a {@link Nullable} InvocationHandlerWithDelegateGetter. + * @return the corresponding delegate. */ - public static Object getDelegateFromInvocationHandler(InvocationHandler invocationHandler) { + @RequiresApi(Build.VERSION_CODES.KITKAT) + @Nullable + public static Object getDelegateFromInvocationHandler( + @Nullable InvocationHandler invocationHandler) { + if (invocationHandler == null) return null; InvocationHandlerWithDelegateGetter objectHolder = (InvocationHandlerWithDelegateGetter) invocationHandler; return objectHolder.getDelegate(); @@ -109,11 +147,11 @@ public class BoundaryInterfaceReflectionUtil { * This allows us to pass InvocationHandlers across the support library boundary and later * unwrap the objects used as delegates within those InvocationHandlers. */ - @TargetApi(Build.VERSION_CODES.KITKAT) + @RequiresApi(Build.VERSION_CODES.KITKAT) private static class InvocationHandlerWithDelegateGetter implements InvocationHandler { private final Object mDelegate; - public InvocationHandlerWithDelegateGetter(final Object delegate) { + public InvocationHandlerWithDelegateGetter(@NonNull final Object delegate) { mDelegate = delegate; } @@ -130,6 +168,10 @@ public class BoundaryInterfaceReflectionUtil { } } + /** + * Gets the delegate object (which is never {@code null}). + */ + @NonNull public Object getDelegate() { return mDelegate; } diff --git a/src/org/chromium/support_lib_boundary/util/Features.java b/src/org/chromium/support_lib_boundary/util/Features.java index eaf6e30..3038a4f 100644 --- a/src/org/chromium/support_lib_boundary/util/Features.java +++ b/src/org/chromium/support_lib_boundary/util/Features.java @@ -47,6 +47,9 @@ public class Features { // WebViewCompat.startSafeBrowsing public static final String START_SAFE_BROWSING = "START_SAFE_BROWSING"; + // WebViewCompat.setSafeBrowsingAllowlist + public static final String SAFE_BROWSING_ALLOWLIST = "SAFE_BROWSING_ALLOWLIST"; + // WebViewCompat.setSafeBrowsingWhitelist public static final String SAFE_BROWSING_WHITELIST = "SAFE_BROWSING_WHITELIST"; @@ -132,6 +135,9 @@ public class Features { // ProxyController.clearProxyOverride public static final String PROXY_OVERRIDE = "PROXY_OVERRIDE:3"; + // ProxyController.setProxyOverride + public static final String PROXY_OVERRIDE_REVERSE_BYPASS = "PROXY_OVERRIDE_REVERSE_BYPASS"; + // WebSettingsCompat.setWillSuppressErrorPage // WebSettingsCompat.getWillSuppressErrorPage public static final String SUPPRESS_ERROR_PAGE = "SUPPRESS_ERROR_PAGE"; @@ -163,4 +169,20 @@ public class Features { // WebSettingsCompat.setForceDark // WebSettingsCompat.getForceDark public static final String FORCE_DARK = "FORCE_DARK"; + + // Preferences between force dark and media query for dark theme support: + // + // WebSettingsCompat.setForceDarkBehavior + // WebSettingsCompat.getForceDarkBehavior + public static final String FORCE_DARK_BEHAVIOR = "FORCE_DARK_BEHAVIOR"; + + // WebViewCompat.addWebMessageListener + // WebViewCompat.removeWebMessageListener + public static final String WEB_MESSAGE_LISTENER = "WEB_MESSAGE_LISTENER"; + + // WebViewProviderFactoryAdapter.setSupportLibraryVersion + public static final String SET_SUPPORT_LIBRARY_VERSION = "SET_SUPPORT_LIBRARY_VERSION"; + + // WebViewCompat.addDocumentStartJavascript + public static final String DOCUMENT_START_SCRIPT = "DOCUMENT_START_SCRIPT"; } |