diff options
| author | Xin Li <delphij@google.com> | 2021-10-06 22:53:28 +0000 |
|---|---|---|
| committer | Xin Li <delphij@google.com> | 2021-10-06 22:53:28 +0000 |
| commit | 531b8f4f2605c44cf73e8421f674a1c7a9c277ff (patch) | |
| tree | 993a3d46a469fda369f8d825e46e9ccee837673d /core/java/android/webkit | |
| parent | fa565ffc481836d7d45edd56ea41845fca8878b3 (diff) | |
| parent | ee05ff24d8533f0ede23af81dd721fb92551ba1c (diff) | |
Merge Android 12
Bug: 202323961
Merged-In: Iba1443da42161f4a41830081f2e1985b30444cc0
Change-Id: I2bebe60bb7114706a3ba6af35522268cdf031f41
Diffstat (limited to 'core/java/android/webkit')
| -rw-r--r-- | core/java/android/webkit/PacProcessor.java | 54 | ||||
| -rw-r--r-- | core/java/android/webkit/TEST_MAPPING | 36 | ||||
| -rw-r--r-- | core/java/android/webkit/UserPackage.java | 4 | ||||
| -rw-r--r-- | core/java/android/webkit/WebView.java | 66 | ||||
| -rw-r--r-- | core/java/android/webkit/WebViewDelegate.java | 58 | ||||
| -rw-r--r-- | core/java/android/webkit/WebViewFactory.java | 124 | ||||
| -rw-r--r-- | core/java/android/webkit/WebViewFactoryProvider.java | 16 | ||||
| -rw-r--r-- | core/java/android/webkit/WebViewProvider.java | 37 |
8 files changed, 329 insertions, 66 deletions
diff --git a/core/java/android/webkit/PacProcessor.java b/core/java/android/webkit/PacProcessor.java index 5ef450fa65dd..21fa6fc88c13 100644 --- a/core/java/android/webkit/PacProcessor.java +++ b/core/java/android/webkit/PacProcessor.java @@ -19,7 +19,7 @@ package android.webkit; import android.annotation.NonNull; import android.annotation.Nullable; import android.annotation.SystemApi; - +import android.net.Network; /** * Class to evaluate PAC scripts. @@ -32,6 +32,10 @@ public interface PacProcessor { /** * Returns the default PacProcessor instance. * + * <p> There can only be one default {@link PacProcessor} instance. + * This method will create a new instance if one did not already exist, or + * if the previous instance was released with {@link #release}. + * * @return the default PacProcessor instance. */ @NonNull @@ -40,6 +44,20 @@ public interface PacProcessor { } /** + * Create a new PacProcessor instance. + * + * <p> The created instance needs to be released manually once it is no longer needed + * by calling {@link #release} to prevent memory leaks. + * + * <p> The created instance is not tied to any particular {@link Network}. + * To associate {@link PacProcessor} with a {@link Network} use {@link #setNetwork} method. + */ + @NonNull + static PacProcessor createInstance() { + return WebViewFactory.getProvider().createPacProcessor(); + } + + /** * Set PAC script to use. * * @param script PAC script. @@ -55,4 +73,38 @@ public interface PacProcessor { */ @Nullable String findProxyForUrl(@NonNull String url); + + /** + * Stops support for this {@link PacProcessor} and release its resources. + * No methods of this class must be called after calling this method. + * + * <p> Released instances will not be reused; a subsequent call to + * {@link #getInstance} and {@link #getInstanceForNetwork} + * for the same network will create a new instance. + */ + default void release() { + throw new UnsupportedOperationException("Not implemented"); + } + + /** + * Associate {@link PacProcessor} instance with the {@link Network}. + * Once this method returns host resolution is done on the set {@link Network}. + + * @param network a {@link Network} which this {@link PacProcessor} + * will use for host/address resolution. If {@code null} reset + * {@link PacProcessor} instance so it is not associated with any {@link Network}. + */ + default void setNetwork(@Nullable Network network) { + throw new UnsupportedOperationException("Not implemented"); + } + + /** + * Returns a {@link Network} associated with this {@link PacProcessor}. + * + * @return an associated {@link Network} or {@code null} if a network is unspecified. + */ + @Nullable + default Network getNetwork() { + throw new UnsupportedOperationException("Not implemented"); + } } diff --git a/core/java/android/webkit/TEST_MAPPING b/core/java/android/webkit/TEST_MAPPING new file mode 100644 index 000000000000..bd25200ffc38 --- /dev/null +++ b/core/java/android/webkit/TEST_MAPPING @@ -0,0 +1,36 @@ +{ + "presubmit": [ + { + "name": "CtsWebkitTestCases", + "options": [ + { + "exclude-annotation": "androidx.test.filters.FlakyTest" + } + ] + }, + { + "name": "CtsHostsideWebViewTests", + "options": [ + { + "exclude-annotation": "androidx.test.filters.FlakyTest" + } + ] + }, + { + "name": "GtsWebViewTestCases", + "options": [ + { + "exclude-annotation": "android.test.FlakyTest" + } + ] + }, + { + "name": "GtsWebViewHostTestCases", + "options": [ + { + "exclude-annotation": "android.test.FlakyTest" + } + ] + } + ] +} diff --git a/core/java/android/webkit/UserPackage.java b/core/java/android/webkit/UserPackage.java index 556b24c94b36..5bcfa8bb6439 100644 --- a/core/java/android/webkit/UserPackage.java +++ b/core/java/android/webkit/UserPackage.java @@ -34,7 +34,7 @@ public class UserPackage { private final UserInfo mUserInfo; private final PackageInfo mPackageInfo; - public static final int MINIMUM_SUPPORTED_SDK = Build.VERSION_CODES.R; + public static final int MINIMUM_SUPPORTED_SDK = Build.VERSION_CODES.S; public UserPackage(UserInfo user, PackageInfo packageInfo) { this.mUserInfo = user; @@ -99,7 +99,7 @@ public class UserPackage { private static List<UserInfo> getAllUsers(Context context) { UserManager userManager = (UserManager) context.getSystemService(Context.USER_SERVICE); - return userManager.getUsers(false); + return userManager.getUsers(); } } diff --git a/core/java/android/webkit/WebView.java b/core/java/android/webkit/WebView.java index 56849c1491ca..0bbaac0fa987 100644 --- a/core/java/android/webkit/WebView.java +++ b/core/java/android/webkit/WebView.java @@ -45,6 +45,7 @@ import android.os.StrictMode; import android.print.PrintDocumentAdapter; import android.util.AttributeSet; import android.util.Log; +import android.util.LongSparseArray; import android.util.SparseArray; import android.view.DragEvent; import android.view.KeyEvent; @@ -55,14 +56,20 @@ import android.view.ViewGroup; import android.view.ViewHierarchyEncoder; import android.view.ViewStructure; import android.view.ViewTreeObserver; +import android.view.WindowInsets; import android.view.accessibility.AccessibilityEvent; import android.view.accessibility.AccessibilityNodeInfo; import android.view.accessibility.AccessibilityNodeProvider; +import android.view.autofill.AutofillId; import android.view.autofill.AutofillValue; import android.view.inputmethod.EditorInfo; import android.view.inputmethod.InputConnection; import android.view.inspector.InspectableProperty; import android.view.textclassifier.TextClassifier; +import android.view.translation.TranslationCapability; +import android.view.translation.TranslationSpec.DataFormat; +import android.view.translation.ViewTranslationRequest; +import android.view.translation.ViewTranslationResponse; import android.widget.AbsoluteLayout; import java.io.BufferedWriter; @@ -72,6 +79,7 @@ import java.lang.annotation.RetentionPolicy; import java.util.List; import java.util.Map; import java.util.concurrent.Executor; +import java.util.function.Consumer; /** * A View that displays web pages. @@ -703,18 +711,20 @@ public class WebView extends AbsoluteLayout return mProvider.restoreState(inState); } - /** - * Loads the given URL with the specified additional HTTP headers. + /** + * Loads the given URL with additional HTTP headers, specified as a map from + * name to value. Note that if this map contains any of the headers that are + * set by default by this WebView, such as those controlling caching, accept + * types or the User-Agent, their values may be overridden by this WebView's + * defaults. + * <p> + * Some older WebView implementations require {@code additionalHttpHeaders} + * to be mutable. * <p> * Also see compatibility note on {@link #evaluateJavascript}. * * @param url the URL of the resource to load - * @param additionalHttpHeaders the additional headers to be used in the - * HTTP request for this URL, specified as a map from name to - * value. Note that if this map contains any of the headers - * that are set by default by this WebView, such as those - * controlling caching, accept types or the User-Agent, their - * values may be overridden by this WebView's defaults. + * @param additionalHttpHeaders map with additional headers */ public void loadUrl(@NonNull String url, @NonNull Map<String, String> additionalHttpHeaders) { checkThread(); @@ -2449,6 +2459,14 @@ public class WebView extends AbsoluteLayout WebView.super.startActivityForResult(intent, requestCode); } + /** + * @see View#onApplyWindowInsets(WindowInsets) + */ + @Nullable + public WindowInsets super_onApplyWindowInsets(@Nullable WindowInsets insets) { + return WebView.super.onApplyWindowInsets(insets); + } + // ---- Access to non-public methods ---- public void overScrollBy(int deltaX, int deltaY, int scrollX, int scrollY, @@ -2843,6 +2861,31 @@ public class WebView extends AbsoluteLayout return mProvider.getViewDelegate().isVisibleToUserForAutofill(virtualId); } + @Override + @Nullable + public void onCreateVirtualViewTranslationRequests(@NonNull long[] virtualIds, + @NonNull @DataFormat int[] supportedFormats, + @NonNull Consumer<ViewTranslationRequest> requestsCollector) { + mProvider.getViewDelegate().onCreateVirtualViewTranslationRequests(virtualIds, + supportedFormats, requestsCollector); + } + + @Override + public void dispatchCreateViewTranslationRequest(@NonNull Map<AutofillId, long[]> viewIds, + @NonNull @DataFormat int[] supportedFormats, + @Nullable TranslationCapability capability, + @NonNull List<ViewTranslationRequest> requests) { + super.dispatchCreateViewTranslationRequest(viewIds, supportedFormats, capability, requests); + mProvider.getViewDelegate().dispatchCreateViewTranslationRequest(viewIds, supportedFormats, + capability, requests); + } + + @Override + public void onVirtualViewTranslationResponses( + @NonNull LongSparseArray<ViewTranslationResponse> response) { + mProvider.getViewDelegate().onVirtualViewTranslationResponses(response); + } + /** @hide */ @Override public void onInitializeAccessibilityNodeInfoInternal(AccessibilityNodeInfo info) { @@ -3078,4 +3121,11 @@ public class WebView extends AbsoluteLayout encoder.addProperty("webview:url", mProvider.getUrl()); encoder.addProperty("webview:originalUrl", mProvider.getOriginalUrl()); } + + @Override + public WindowInsets onApplyWindowInsets(WindowInsets insets) { + WindowInsets result = mProvider.getViewDelegate().onApplyWindowInsets(insets); + if (result == null) return super.onApplyWindowInsets(insets); + return result; + } } diff --git a/core/java/android/webkit/WebViewDelegate.java b/core/java/android/webkit/WebViewDelegate.java index df86926a95dc..1b9ff44c9185 100644 --- a/core/java/android/webkit/WebViewDelegate.java +++ b/core/java/android/webkit/WebViewDelegate.java @@ -77,73 +77,41 @@ public final class WebViewDelegate { } /** - * Returns {@code true} if the draw GL functor can be invoked (see {@link #invokeDrawGlFunctor}) - * and {@code false} otherwise. - * + * Throws {@link UnsupportedOperationException} * @deprecated Use {@link #drawWebViewFunctor(Canvas, int)} */ @Deprecated public boolean canInvokeDrawGlFunctor(View containerView) { - return true; + throw new UnsupportedOperationException(); } /** - * Invokes the draw GL functor. If waitForCompletion is {@code false} the functor - * may be invoked asynchronously. - * - * @param nativeDrawGLFunctor the pointer to the native functor that implements - * system/core/include/utils/Functor.h + * Throws {@link UnsupportedOperationException} * @deprecated Use {@link #drawWebViewFunctor(Canvas, int)} */ @Deprecated public void invokeDrawGlFunctor(View containerView, long nativeDrawGLFunctor, boolean waitForCompletion) { - ViewRootImpl.invokeFunctor(nativeDrawGLFunctor, waitForCompletion); + throw new UnsupportedOperationException(); } /** - * Calls the function specified with the nativeDrawGLFunctor functor pointer. This - * functionality is used by the WebView for calling into their renderer from the - * framework display lists. - * - * @param canvas a hardware accelerated canvas (see {@link Canvas#isHardwareAccelerated()}) - * @param nativeDrawGLFunctor the pointer to the native functor that implements - * system/core/include/utils/Functor.h - * @throws IllegalArgumentException if the canvas is not hardware accelerated + * Throws {@link UnsupportedOperationException} * @deprecated Use {@link #drawWebViewFunctor(Canvas, int)} */ @Deprecated public void callDrawGlFunction(Canvas canvas, long nativeDrawGLFunctor) { - if (!(canvas instanceof RecordingCanvas)) { - // Canvas#isHardwareAccelerated() is only true for subclasses of HardwareCanvas. - throw new IllegalArgumentException(canvas.getClass().getName() - + " is not a DisplayList canvas"); - } - ((RecordingCanvas) canvas).drawGLFunctor2(nativeDrawGLFunctor, null); + throw new UnsupportedOperationException(); } /** - * Calls the function specified with the nativeDrawGLFunctor functor pointer. This - * functionality is used by the WebView for calling into their renderer from the - * framework display lists. - * - * @param canvas a hardware accelerated canvas (see {@link Canvas#isHardwareAccelerated()}) - * @param nativeDrawGLFunctor the pointer to the native functor that implements - * system/core/include/utils/Functor.h - * @param releasedRunnable Called when this nativeDrawGLFunctor is no longer referenced by this - * canvas, so is safe to be destroyed. - * @throws IllegalArgumentException if the canvas is not hardware accelerated + * Throws {@link UnsupportedOperationException} * @deprecated Use {@link #drawWebViewFunctor(Canvas, int)} */ @Deprecated public void callDrawGlFunction(@NonNull Canvas canvas, long nativeDrawGLFunctor, @Nullable Runnable releasedRunnable) { - if (!(canvas instanceof RecordingCanvas)) { - // Canvas#isHardwareAccelerated() is only true for subclasses of HardwareCanvas. - throw new IllegalArgumentException(canvas.getClass().getName() - + " is not a DisplayList canvas"); - } - ((RecordingCanvas) canvas).drawGLFunctor2(nativeDrawGLFunctor, releasedRunnable); + throw new UnsupportedOperationException(); } /** @@ -250,4 +218,14 @@ public final class WebViewDelegate { public String getDataDirectorySuffix() { return WebViewFactory.getDataDirectorySuffix(); } + + /** + * Get the timestamps at which various WebView startup events occurred in this process. + * This method must be called on the same thread where the + * WebViewChromiumFactoryProvider#create method was invoked. + */ + @NonNull + public WebViewFactory.StartupTimestamps getStartupTimestamps() { + return WebViewFactory.getStartupTimestamps(); + } } diff --git a/core/java/android/webkit/WebViewFactory.java b/core/java/android/webkit/WebViewFactory.java index d388bcdff468..cf6807e41e8a 100644 --- a/core/java/android/webkit/WebViewFactory.java +++ b/core/java/android/webkit/WebViewFactory.java @@ -16,7 +16,9 @@ package android.webkit; +import android.annotation.NonNull; import android.annotation.SystemApi; +import android.annotation.UptimeMillisLong; import android.app.ActivityManager; import android.app.AppGlobals; import android.app.Application; @@ -29,6 +31,7 @@ import android.content.pm.Signature; import android.os.Build; import android.os.RemoteException; import android.os.ServiceManager; +import android.os.SystemClock; import android.os.Trace; import android.util.AndroidRuntimeException; import android.util.ArraySet; @@ -48,7 +51,7 @@ public final class WebViewFactory { // visible for WebViewZygoteInit to look up the class by reflection and call preloadInZygote. /** @hide */ private static final String CHROMIUM_WEBVIEW_FACTORY = - "com.android.webview.chromium.WebViewChromiumFactoryProviderForR"; + "com.android.webview.chromium.WebViewChromiumFactoryProviderForS"; private static final String CHROMIUM_WEBVIEW_FACTORY_METHOD = "create"; @@ -87,6 +90,97 @@ public final class WebViewFactory { // error for namespace lookup public static final int LIBLOAD_FAILED_TO_FIND_NAMESPACE = 10; + /** + * Stores the timestamps at which various WebView startup events occurred in this process. + */ + public static class StartupTimestamps { + long mWebViewLoadStart; + long mCreateContextStart; + long mCreateContextEnd; + long mAddAssetsStart; + long mAddAssetsEnd; + long mGetClassLoaderStart; + long mGetClassLoaderEnd; + long mNativeLoadStart; + long mNativeLoadEnd; + long mProviderClassForNameStart; + long mProviderClassForNameEnd; + + StartupTimestamps() {} + + /** When the overall WebView provider load began. */ + @UptimeMillisLong + public long getWebViewLoadStart() { + return mWebViewLoadStart; + } + + /** Before creating the WebView APK Context. */ + @UptimeMillisLong + public long getCreateContextStart() { + return mCreateContextStart; + } + + /** After creating the WebView APK Context. */ + @UptimeMillisLong + public long getCreateContextEnd() { + return mCreateContextEnd; + } + + /** Before adding WebView assets to AssetManager. */ + @UptimeMillisLong + public long getAddAssetsStart() { + return mAddAssetsStart; + } + + /** After adding WebView assets to AssetManager. */ + @UptimeMillisLong + public long getAddAssetsEnd() { + return mAddAssetsEnd; + } + + /** Before creating the WebView ClassLoader. */ + @UptimeMillisLong + public long getGetClassLoaderStart() { + return mGetClassLoaderStart; + } + + /** After creating the WebView ClassLoader. */ + @UptimeMillisLong + public long getGetClassLoaderEnd() { + return mGetClassLoaderEnd; + } + + /** Before preloading the WebView native library. */ + @UptimeMillisLong + public long getNativeLoadStart() { + return mNativeLoadStart; + } + + /** After preloading the WebView native library. */ + @UptimeMillisLong + public long getNativeLoadEnd() { + return mNativeLoadEnd; + } + + /** Before looking up the WebView provider class. */ + @UptimeMillisLong + public long getProviderClassForNameStart() { + return mProviderClassForNameStart; + } + + /** After looking up the WebView provider class. */ + @UptimeMillisLong + public long getProviderClassForNameEnd() { + return mProviderClassForNameEnd; + } + } + + static final StartupTimestamps sTimestamps = new StartupTimestamps(); + + @NonNull + static StartupTimestamps getStartupTimestamps() { + return sTimestamps; + } private static String getWebViewPreparationErrorReason(int error) { switch (error) { @@ -230,6 +324,7 @@ public final class WebViewFactory { // us honest and minimize usage of WebView internals when binding the proxy. if (sProviderInstance != null) return sProviderInstance; + sTimestamps.mWebViewLoadStart = SystemClock.uptimeMillis(); final int uid = android.os.Process.myUid(); if (uid == android.os.Process.ROOT_UID || uid == android.os.Process.SYSTEM_UID || uid == android.os.Process.PHONE_UID || uid == android.os.Process.NFC_UID @@ -251,15 +346,8 @@ public final class WebViewFactory { Trace.traceBegin(Trace.TRACE_TAG_WEBVIEW, "WebViewFactory.getProvider()"); try { Class<WebViewFactoryProvider> providerClass = getProviderClass(); - Method staticFactory = null; - try { - staticFactory = providerClass.getMethod( + Method staticFactory = providerClass.getMethod( CHROMIUM_WEBVIEW_FACTORY_METHOD, WebViewDelegate.class); - } catch (Exception e) { - if (DEBUG) { - Log.w(LOGTAG, "error instantiating provider with static factory method", e); - } - } Trace.traceBegin(Trace.TRACE_TAG_WEBVIEW, "WebViewFactoryProvider invocation"); try { @@ -267,12 +355,12 @@ public final class WebViewFactory { staticFactory.invoke(null, new WebViewDelegate()); if (DEBUG) Log.v(LOGTAG, "Loaded provider: " + sProviderInstance); return sProviderInstance; - } catch (Exception e) { - Log.e(LOGTAG, "error instantiating provider", e); - throw new AndroidRuntimeException(e); } finally { Trace.traceEnd(Trace.TRACE_TAG_WEBVIEW); } + } catch (Exception e) { + Log.e(LOGTAG, "error instantiating provider", e); + throw new AndroidRuntimeException(e); } finally { Trace.traceEnd(Trace.TRACE_TAG_WEBVIEW); } @@ -376,6 +464,7 @@ public final class WebViewFactory { Trace.traceBegin(Trace.TRACE_TAG_WEBVIEW, "initialApplication.createApplicationContext"); + sTimestamps.mCreateContextStart = SystemClock.uptimeMillis(); try { // Construct an app context to load the Java code into the current app. Context webViewContext = initialApplication.createApplicationContext( @@ -384,6 +473,7 @@ public final class WebViewFactory { sPackageInfo = newPackageInfo; return webViewContext; } finally { + sTimestamps.mCreateContextEnd = SystemClock.uptimeMillis(); Trace.traceEnd(Trace.TRACE_TAG_WEBVIEW); } } catch (RemoteException | PackageManager.NameNotFoundException e) { @@ -409,20 +499,26 @@ public final class WebViewFactory { Trace.traceBegin(Trace.TRACE_TAG_WEBVIEW, "WebViewFactory.getChromiumProviderClass()"); try { + sTimestamps.mAddAssetsStart = SystemClock.uptimeMillis(); for (String newAssetPath : webViewContext.getApplicationInfo().getAllApkPaths()) { initialApplication.getAssets().addAssetPathAsSharedLibrary(newAssetPath); } + sTimestamps.mAddAssetsEnd = sTimestamps.mGetClassLoaderStart = + SystemClock.uptimeMillis(); ClassLoader clazzLoader = webViewContext.getClassLoader(); - Trace.traceBegin(Trace.TRACE_TAG_WEBVIEW, "WebViewFactory.loadNativeLibrary()"); + sTimestamps.mGetClassLoaderEnd = sTimestamps.mNativeLoadStart = + SystemClock.uptimeMillis(); WebViewLibraryLoader.loadNativeLibrary(clazzLoader, getWebViewLibrary(sPackageInfo.applicationInfo)); Trace.traceEnd(Trace.TRACE_TAG_WEBVIEW); - Trace.traceBegin(Trace.TRACE_TAG_WEBVIEW, "Class.forName()"); + sTimestamps.mNativeLoadEnd = sTimestamps.mProviderClassForNameStart = + SystemClock.uptimeMillis(); try { return getWebViewProviderClass(clazzLoader); } finally { + sTimestamps.mProviderClassForNameEnd = SystemClock.uptimeMillis(); Trace.traceEnd(Trace.TRACE_TAG_WEBVIEW); } } catch (ClassNotFoundException e) { diff --git a/core/java/android/webkit/WebViewFactoryProvider.java b/core/java/android/webkit/WebViewFactoryProvider.java index f7c3ec09dd67..3d6450632e06 100644 --- a/core/java/android/webkit/WebViewFactoryProvider.java +++ b/core/java/android/webkit/WebViewFactoryProvider.java @@ -20,6 +20,7 @@ import android.annotation.NonNull; import android.annotation.SystemApi; import android.content.Context; import android.content.Intent; +import android.net.Network; import android.net.Uri; import java.util.List; @@ -175,7 +176,7 @@ public interface WebViewFactoryProvider { WebViewDatabase getWebViewDatabase(Context context); /** - * Gets the singleton PacProcessor instance. + * Gets the default PacProcessor instance. * @return the PacProcessor instance */ @NonNull @@ -184,6 +185,19 @@ public interface WebViewFactoryProvider { } /** + * Create a new PacProcessor instance. + * + * @param network a {@link Network} which needs to be associated + * with the returned {@link PacProcessor}. + * If {@code null} the method returns default {@link PacProcessor}. + * @return the {@link PacProcessor} instance associated with {@link Network}. + */ + @NonNull + default PacProcessor createPacProcessor() { + throw new UnsupportedOperationException("Not implemented"); + } + + /** * Gets the classloader used to load internal WebView implementation classes. This interface * should only be used by the WebView Support Library. */ diff --git a/core/java/android/webkit/WebViewProvider.java b/core/java/android/webkit/WebViewProvider.java index 010c0b7bd4ab..f9f823b70810 100644 --- a/core/java/android/webkit/WebViewProvider.java +++ b/core/java/android/webkit/WebViewProvider.java @@ -18,6 +18,7 @@ package android.webkit; import android.annotation.NonNull; import android.annotation.Nullable; +import android.annotation.SuppressLint; import android.annotation.SystemApi; import android.content.Intent; import android.content.res.Configuration; @@ -33,19 +34,26 @@ import android.os.Bundle; import android.os.Handler; import android.os.Message; import android.print.PrintDocumentAdapter; +import android.util.LongSparseArray; import android.util.SparseArray; import android.view.DragEvent; import android.view.KeyEvent; import android.view.MotionEvent; import android.view.View; import android.view.ViewGroup.LayoutParams; +import android.view.WindowInsets; import android.view.accessibility.AccessibilityEvent; import android.view.accessibility.AccessibilityNodeInfo; import android.view.accessibility.AccessibilityNodeProvider; +import android.view.autofill.AutofillId; import android.view.autofill.AutofillValue; import android.view.inputmethod.EditorInfo; import android.view.inputmethod.InputConnection; import android.view.textclassifier.TextClassifier; +import android.view.translation.TranslationCapability; +import android.view.translation.TranslationSpec.DataFormat; +import android.view.translation.ViewTranslationRequest; +import android.view.translation.ViewTranslationResponse; import android.webkit.WebView.HitTestResult; import android.webkit.WebView.PictureListener; import android.webkit.WebView.VisualStateCallback; @@ -53,8 +61,10 @@ import android.webkit.WebView.VisualStateCallback; import java.io.BufferedWriter; import java.io.File; +import java.util.List; import java.util.Map; import java.util.concurrent.Executor; +import java.util.function.Consumer; /** * WebView backend provider interface: this interface is the abstract backend to a WebView @@ -357,6 +367,27 @@ public interface WebViewProvider { @SuppressWarnings("unused") int flags) { } + @SuppressLint("NullableCollection") + default void onCreateVirtualViewTranslationRequests( + @NonNull @SuppressWarnings("unused") long[] virtualIds, + @NonNull @SuppressWarnings("unused") @DataFormat int[] supportedFormats, + @NonNull @SuppressWarnings("unused") + Consumer<ViewTranslationRequest> requestsCollector) { + } + + default void onVirtualViewTranslationResponses( + @NonNull @SuppressWarnings("unused") + LongSparseArray<ViewTranslationResponse> response) { + } + + default void dispatchCreateViewTranslationRequest( + @NonNull @SuppressWarnings("unused") Map<AutofillId, long[]> viewIds, + @NonNull @SuppressWarnings("unused") @DataFormat int[] supportedFormats, + @Nullable @SuppressWarnings("unused") TranslationCapability capability, + @NonNull @SuppressWarnings("unused") List<ViewTranslationRequest> requests) { + + } + public AccessibilityNodeProvider getAccessibilityNodeProvider(); public void onInitializeAccessibilityNodeInfo(AccessibilityNodeInfo info); @@ -448,6 +479,12 @@ public interface WebViewProvider { default boolean onCheckIsTextEditor() { return false; } + + @SuppressWarnings("unused") + @Nullable + default WindowInsets onApplyWindowInsets(@Nullable WindowInsets insets) { + return null; + } } interface ScrollDelegate { |
