diff options
author | android-build-prod (mdb) <android-build-team-robot@google.com> | 2020-08-26 00:33:41 +0000 |
---|---|---|
committer | android-build-prod (mdb) <android-build-team-robot@google.com> | 2020-08-26 00:33:41 +0000 |
commit | bdf9d35ce928882ef6c339ced5557c85a90a751f (patch) | |
tree | 0b80a36c9904eb1df7508ba11a729cf9fcf54d0c | |
parent | 2e8b9b6ba018303475d25a227aecc08a08280fb9 (diff) | |
parent | 021571f9ab2fb3cf7c162fa43f2a6329dcda89b4 (diff) | |
download | webview_support_interfaces-androidx-media2-media2-widget-release.tar.gz |
Snap for 6790423 from 021571f9ab2fb3cf7c162fa43f2a6329dcda89b4 to androidx-media2-media2-widget-releaseandroidx-media2-media2-widget-release
Change-Id: I63e4d5b932b05bdcf79c9d1966825c4320aad1c0
12 files changed, 170 insertions, 33 deletions
@@ -1,2 +1,4 @@ # For Android Studio, when we mirror this repo into the Android tree *.iml +.gradle/ +.settings/ diff --git a/AndroidManifest.xml b/AndroidManifest.xml deleted file mode 100644 index abe20e7..0000000 --- a/AndroidManifest.xml +++ /dev/null @@ -1,9 +0,0 @@ -<?xml version="1.0" encoding="utf-8"?> -<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example"> - <!-- This AndroidManifest file only exists to verify boundary interfaces - compile and lint correctly against API 14 (the minSdkVersion of the - support library code). As the minSdkVersion of the support library - increases, so should this value. See http://crbug.com/828184 for more - details. --> - <uses-sdk android:minSdkVersion="14" /> -</manifest> @@ -6,20 +6,22 @@ import("//build/config/android/config.gni") import("//build/config/android/rules.gni") android_library("boundary_interface_java") { - java_files = [ + sources = [ "src/org/chromium/support_lib_boundary/FeatureFlagHolderBoundaryInterface.java", "src/org/chromium/support_lib_boundary/IsomorphicObjectBoundaryInterface.java", + "src/org/chromium/support_lib_boundary/JsReplyProxyBoundaryInterface.java", "src/org/chromium/support_lib_boundary/ProxyControllerBoundaryInterface.java", "src/org/chromium/support_lib_boundary/SafeBrowsingResponseBoundaryInterface.java", + "src/org/chromium/support_lib_boundary/ScriptReferenceBoundaryInterface.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/TracingControllerBoundaryInterface.java", "src/org/chromium/support_lib_boundary/VisualStateCallbackBoundaryInterface.java", - "src/org/chromium/support_lib_boundary/WebkitToCompatConverterBoundaryInterface.java", "src/org/chromium/support_lib_boundary/WebMessageBoundaryInterface.java", "src/org/chromium/support_lib_boundary/WebMessageCallbackBoundaryInterface.java", + "src/org/chromium/support_lib_boundary/WebMessageListenerBoundaryInterface.java", "src/org/chromium/support_lib_boundary/WebMessagePortBoundaryInterface.java", "src/org/chromium/support_lib_boundary/WebResourceErrorBoundaryInterface.java", "src/org/chromium/support_lib_boundary/WebResourceRequestBoundaryInterface.java", @@ -29,17 +31,34 @@ android_library("boundary_interface_java") { "src/org/chromium/support_lib_boundary/WebViewProviderFactoryBoundaryInterface.java", "src/org/chromium/support_lib_boundary/WebViewRendererBoundaryInterface.java", "src/org/chromium/support_lib_boundary/WebViewRendererClientBoundaryInterface.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" ] - # We can't use ANY deps here, the support library should be able to build - # these interfaces without any other chromium dependencies. - deps = [] + # Our choice of deps is limited, because boundary_interfaces/ must continue to + # build when we mirror this into AndroidX. We are only permitted to depend on + # core Android classes and other AndroidX classes (must be in the androidx.* + # package name). + deps = [ "//third_party/android_deps:androidx_annotation_annotation_java" ] +} + +android_apk("boundary_interface_example_apk") { + apk_name = "BoundaryInterfaceExample" + + # Use a dummy android manifest since this code is copied to androidx. + android_manifest = "//build/android/AndroidManifest.xml" + + # This is to verify that the boundary interfaces compile and lint correctly + # against the minSdkVersion of the webkit support library module. As the + # minSdkVersion of the support library increases, so should this value. See + # http://crbug.com/828184 for more details. + min_sdk_version = 14 + + # Explicitly enable lint for this apk. + enable_lint = true - # This is to verify the boundary interfaces compile and lint correctly against - # the minSdkVersion of the webkit support library module. - android_manifest_for_lint = "AndroidManifest.xml" + deps = [ ":boundary_interface_java" ] } 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/ScriptReferenceBoundaryInterface.java b/src/org/chromium/support_lib_boundary/ScriptReferenceBoundaryInterface.java new file mode 100644 index 0000000..6358e00 --- /dev/null +++ b/src/org/chromium/support_lib_boundary/ScriptReferenceBoundaryInterface.java @@ -0,0 +1,12 @@ +// 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 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..843d387 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); + /* ScriptReference */ 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..c2dc613 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,16 @@ 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) { + @Nullable + public static Object getDelegateFromInvocationHandler( + @Nullable InvocationHandler invocationHandler) { + if (invocationHandler == null) return null; InvocationHandlerWithDelegateGetter objectHolder = (InvocationHandlerWithDelegateGetter) invocationHandler; return objectHolder.getDelegate(); @@ -109,11 +146,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 +167,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..d3a5039 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"; @@ -163,4 +166,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:1"; } |