1 /* 2 * Copyright 2018 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package androidx.webkit; 18 19 import android.annotation.SuppressLint; 20 import android.content.Context; 21 import android.net.Uri; 22 import android.os.CancellationSignal; 23 import android.os.Handler; 24 import android.webkit.CookieManager; 25 import android.webkit.ValueCallback; 26 import android.webkit.WebResourceRequest; 27 import android.webkit.WebResourceResponse; 28 import android.webkit.WebSettings; 29 import android.webkit.WebStorage; 30 import android.webkit.WebView; 31 32 import androidx.annotation.RestrictTo; 33 import androidx.annotation.StringDef; 34 import androidx.webkit.internal.WebViewFeatureInternal; 35 36 import org.jspecify.annotations.NonNull; 37 38 import java.io.File; 39 import java.io.OutputStream; 40 import java.lang.annotation.ElementType; 41 import java.lang.annotation.Retention; 42 import java.lang.annotation.RetentionPolicy; 43 import java.lang.annotation.Target; 44 import java.util.List; 45 import java.util.Set; 46 import java.util.concurrent.Executor; 47 48 /** 49 * Utility class for checking which WebView Support Library features are supported on the device. 50 */ 51 public class WebViewFeature { 52 WebViewFeature()53 private WebViewFeature() { 54 } 55 56 /** 57 * 58 */ 59 @RestrictTo(RestrictTo.Scope.LIBRARY) 60 @StringDef(value = { 61 VISUAL_STATE_CALLBACK, 62 OFF_SCREEN_PRERASTER, 63 SAFE_BROWSING_ENABLE, 64 DISABLED_ACTION_MODE_MENU_ITEMS, 65 START_SAFE_BROWSING, 66 SAFE_BROWSING_ALLOWLIST, 67 SAFE_BROWSING_WHITELIST, 68 SAFE_BROWSING_PRIVACY_POLICY_URL, 69 SERVICE_WORKER_BASIC_USAGE, 70 SERVICE_WORKER_CACHE_MODE, 71 SERVICE_WORKER_CONTENT_ACCESS, 72 SERVICE_WORKER_FILE_ACCESS, 73 SERVICE_WORKER_BLOCK_NETWORK_LOADS, 74 SERVICE_WORKER_SHOULD_INTERCEPT_REQUEST, 75 RECEIVE_WEB_RESOURCE_ERROR, 76 RECEIVE_HTTP_ERROR, 77 SHOULD_OVERRIDE_WITH_REDIRECTS, 78 SAFE_BROWSING_HIT, 79 TRACING_CONTROLLER_BASIC_USAGE, 80 WEB_RESOURCE_REQUEST_IS_REDIRECT, 81 WEB_RESOURCE_ERROR_GET_DESCRIPTION, 82 WEB_RESOURCE_ERROR_GET_CODE, 83 SAFE_BROWSING_RESPONSE_BACK_TO_SAFETY, 84 SAFE_BROWSING_RESPONSE_PROCEED, 85 SAFE_BROWSING_RESPONSE_SHOW_INTERSTITIAL, 86 WEB_MESSAGE_PORT_POST_MESSAGE, 87 WEB_MESSAGE_PORT_CLOSE, 88 WEB_MESSAGE_ARRAY_BUFFER, 89 WEB_MESSAGE_PORT_SET_MESSAGE_CALLBACK, 90 CREATE_WEB_MESSAGE_CHANNEL, 91 POST_WEB_MESSAGE, 92 WEB_MESSAGE_CALLBACK_ON_MESSAGE, 93 GET_WEB_VIEW_CLIENT, 94 GET_WEB_CHROME_CLIENT, 95 GET_WEB_VIEW_RENDERER, 96 WEB_VIEW_RENDERER_TERMINATE, 97 WEB_VIEW_RENDERER_CLIENT_BASIC_USAGE, 98 PROXY_OVERRIDE, 99 MULTI_PROCESS, 100 FORCE_DARK, 101 FORCE_DARK_STRATEGY, 102 WEB_MESSAGE_LISTENER, 103 DOCUMENT_START_SCRIPT, 104 PROXY_OVERRIDE_REVERSE_BYPASS, 105 GET_VARIATIONS_HEADER, 106 ALGORITHMIC_DARKENING, 107 ENTERPRISE_AUTHENTICATION_APP_LINK_POLICY, 108 GET_COOKIE_INFO, 109 REQUESTED_WITH_HEADER_ALLOW_LIST, 110 USER_AGENT_METADATA, 111 MULTI_PROFILE, 112 ATTRIBUTION_REGISTRATION_BEHAVIOR, 113 WEBVIEW_MEDIA_INTEGRITY_API_STATUS, 114 MUTE_AUDIO, 115 PROFILE_URL_PREFETCH, 116 WEB_AUTHENTICATION, 117 SPECULATIVE_LOADING, 118 BACK_FORWARD_CACHE, 119 DEFAULT_TRAFFICSTATS_TAGGING, 120 DELETE_BROWSING_DATA, 121 PRERENDER_WITH_URL, 122 SAVE_STATE, 123 NAVIGATION_CALLBACK_BASIC, 124 CACHE_PROVIDER, 125 PAYMENT_REQUEST, 126 }) 127 @Retention(RetentionPolicy.SOURCE) 128 @Target({ElementType.PARAMETER, ElementType.METHOD}) 129 public @interface WebViewSupportFeature { 130 } 131 132 /** 133 * 134 */ 135 @RestrictTo(RestrictTo.Scope.LIBRARY) 136 @StringDef(value = { 137 STARTUP_FEATURE_SET_DATA_DIRECTORY_SUFFIX, 138 STARTUP_FEATURE_SET_DIRECTORY_BASE_PATHS, 139 STARTUP_FEATURE_CONFIGURE_PARTITIONED_COOKIES, 140 }) 141 @Retention(RetentionPolicy.SOURCE) 142 @Target({ElementType.PARAMETER, ElementType.METHOD}) 143 public @interface WebViewStartupFeature { 144 } 145 146 /** 147 * Feature for {@link #isFeatureSupported(String)}. 148 * This feature covers 149 * {@link WebViewCompat#postVisualStateCallback(WebView, long, 150 * WebViewCompat.VisualStateCallback)}, and {@link 151 * WebViewClientCompat#onPageCommitVisible(WebView, String)}. 152 */ 153 public static final String VISUAL_STATE_CALLBACK = "VISUAL_STATE_CALLBACK"; 154 155 /** 156 * Feature for {@link #isFeatureSupported(String)}. 157 * This feature covers 158 * {@link WebSettingsCompat#getOffscreenPreRaster(WebSettings)}, and 159 * {@link WebSettingsCompat#setOffscreenPreRaster(WebSettings, boolean)}. 160 */ 161 public static final String OFF_SCREEN_PRERASTER = "OFF_SCREEN_PRERASTER"; 162 163 /** 164 * Feature for {@link #isFeatureSupported(String)}. 165 * This feature covers 166 * {@link WebSettingsCompat#getSafeBrowsingEnabled(WebSettings)}, and 167 * {@link WebSettingsCompat#setSafeBrowsingEnabled(WebSettings, boolean)}. 168 */ 169 public static final String SAFE_BROWSING_ENABLE = "SAFE_BROWSING_ENABLE"; 170 171 /** 172 * Feature for {@link #isFeatureSupported(String)}. 173 * This feature covers 174 * {@link WebSettingsCompat#getDisabledActionModeMenuItems(WebSettings)}, and 175 * {@link WebSettingsCompat#setDisabledActionModeMenuItems(WebSettings, int)}. 176 */ 177 @SuppressLint("IntentName") // False positive: this constant is not to be used for Intents. 178 public static final String DISABLED_ACTION_MODE_MENU_ITEMS = 179 "DISABLED_ACTION_MODE_MENU_ITEMS"; 180 181 /** 182 * Feature for {@link #isFeatureSupported(String)}. 183 * This feature covers {@link WebViewCompat#startSafeBrowsing(Context, ValueCallback)}. 184 */ 185 public static final String START_SAFE_BROWSING = "START_SAFE_BROWSING"; 186 187 /** 188 * Feature for {@link #isFeatureSupported(String)}. 189 * This feature covers 190 * {@link WebViewCompat#setSafeBrowsingAllowlist(Set, ValueCallback)}. 191 */ 192 public static final String SAFE_BROWSING_ALLOWLIST = "SAFE_BROWSING_ALLOWLIST"; 193 194 /** 195 * Feature for {@link #isFeatureSupported(String)}. 196 * This feature covers 197 * {@link WebViewCompat#setSafeBrowsingWhitelist(List, ValueCallback)}. 198 * 199 * <p>This is functionally equivalent to {@link #SAFE_BROWSING_ALLOWLIST}: both constants 200 * represent the same range of compatibility across Android OS versions and WebView versions. 201 * 202 * @deprecated Please use {@link #SAFE_BROWSING_ALLOWLIST} and {@link 203 * WebViewCompat#setSafeBrowsingAllowlist(Set, ValueCallback)} instead. 204 */ 205 @Deprecated 206 public static final String SAFE_BROWSING_WHITELIST = "SAFE_BROWSING_WHITELIST"; 207 208 /** 209 * Feature for {@link #isFeatureSupported(String)}. 210 * This feature covers 211 * {@link WebViewCompat#getSafeBrowsingPrivacyPolicyUrl()}. 212 */ 213 public static final String SAFE_BROWSING_PRIVACY_POLICY_URL = 214 "SAFE_BROWSING_PRIVACY_POLICY_URL"; 215 216 /** 217 * Feature for {@link #isFeatureSupported(String)}. 218 * This feature covers 219 * {@link ServiceWorkerControllerCompat#getInstance()}. 220 */ 221 public static final String SERVICE_WORKER_BASIC_USAGE = "SERVICE_WORKER_BASIC_USAGE"; 222 223 /** 224 * Feature for {@link #isFeatureSupported(String)}. 225 * This feature covers 226 * {@link ServiceWorkerWebSettingsCompat#getCacheMode()}, and 227 * {@link ServiceWorkerWebSettingsCompat#setCacheMode(int)}. 228 */ 229 public static final String SERVICE_WORKER_CACHE_MODE = "SERVICE_WORKER_CACHE_MODE"; 230 231 /** 232 * Feature for {@link #isFeatureSupported(String)}. 233 * This feature covers 234 * {@link ServiceWorkerWebSettingsCompat#getAllowContentAccess()}, and 235 * {@link ServiceWorkerWebSettingsCompat#setAllowContentAccess(boolean)}. 236 */ 237 public static final String SERVICE_WORKER_CONTENT_ACCESS = 238 "SERVICE_WORKER_CONTENT_ACCESS"; 239 240 /** 241 * Feature for {@link #isFeatureSupported(String)}. 242 * This feature covers 243 * {@link ServiceWorkerWebSettingsCompat#getAllowFileAccess()}, and 244 * {@link ServiceWorkerWebSettingsCompat#setAllowFileAccess(boolean)}. 245 */ 246 public static final String SERVICE_WORKER_FILE_ACCESS = "SERVICE_WORKER_FILE_ACCESS"; 247 248 /** 249 * Feature for {@link #isFeatureSupported(String)}. 250 * This feature covers 251 * {@link ServiceWorkerWebSettingsCompat#getBlockNetworkLoads()}, and 252 * {@link ServiceWorkerWebSettingsCompat#setBlockNetworkLoads(boolean)}. 253 */ 254 public static final String SERVICE_WORKER_BLOCK_NETWORK_LOADS = 255 "SERVICE_WORKER_BLOCK_NETWORK_LOADS"; 256 257 /** 258 * Feature for {@link #isFeatureSupported(String)}. 259 * This feature covers 260 * {@link ServiceWorkerClientCompat#shouldInterceptRequest(WebResourceRequest)}. 261 */ 262 public static final String SERVICE_WORKER_SHOULD_INTERCEPT_REQUEST = 263 "SERVICE_WORKER_SHOULD_INTERCEPT_REQUEST"; 264 265 /** 266 * Feature for {@link #isFeatureSupported(String)}. 267 * This feature covers 268 * {@link WebViewClientCompat#onReceivedError(WebView, WebResourceRequest, 269 * WebResourceErrorCompat)}. 270 */ 271 public static final String RECEIVE_WEB_RESOURCE_ERROR = "RECEIVE_WEB_RESOURCE_ERROR"; 272 273 /** 274 * Feature for {@link #isFeatureSupported(String)}. 275 * This feature covers 276 * {@link WebViewClientCompat#onReceivedHttpError(WebView, WebResourceRequest, 277 * WebResourceResponse)}. 278 */ 279 public static final String RECEIVE_HTTP_ERROR = "RECEIVE_HTTP_ERROR"; 280 281 /** 282 * Feature for {@link #isFeatureSupported(String)}. 283 * This feature covers 284 * {@link WebViewClientCompat#shouldOverrideUrlLoading(WebView, WebResourceRequest)}. 285 */ 286 public static final String SHOULD_OVERRIDE_WITH_REDIRECTS = 287 "SHOULD_OVERRIDE_WITH_REDIRECTS"; 288 289 /** 290 * Feature for {@link #isFeatureSupported(String)}. 291 * This feature covers 292 * {@link WebViewClientCompat#onSafeBrowsingHit(WebView, 293 * WebResourceRequest, int, SafeBrowsingResponseCompat)}. 294 */ 295 public static final String SAFE_BROWSING_HIT = "SAFE_BROWSING_HIT"; 296 297 /** 298 * Feature for {@link #isFeatureSupported(String)}. 299 * This feature covers 300 * {@link TracingController#getInstance()}, 301 * {@link TracingController#isTracing()}, 302 * {@link TracingController#start(TracingConfig)}, 303 * {@link TracingController#stop(OutputStream, Executor)}. 304 */ 305 public static final String TRACING_CONTROLLER_BASIC_USAGE = 306 "TRACING_CONTROLLER_BASIC_USAGE"; 307 308 /** 309 * Feature for {@link #isFeatureSupported(String)}. 310 * This feature covers 311 * {@link WebResourceRequestCompat#isRedirect(WebResourceRequest)}. 312 */ 313 public static final String WEB_RESOURCE_REQUEST_IS_REDIRECT = 314 "WEB_RESOURCE_REQUEST_IS_REDIRECT"; 315 316 /** 317 * Feature for {@link #isFeatureSupported(String)}. 318 * This feature covers 319 * {@link WebResourceErrorCompat#getDescription()}. 320 */ 321 public static final String WEB_RESOURCE_ERROR_GET_DESCRIPTION = 322 "WEB_RESOURCE_ERROR_GET_DESCRIPTION"; 323 324 /** 325 * Feature for {@link #isFeatureSupported(String)}. 326 * This feature covers 327 * {@link WebResourceErrorCompat#getErrorCode()}. 328 */ 329 public static final String WEB_RESOURCE_ERROR_GET_CODE = 330 "WEB_RESOURCE_ERROR_GET_CODE"; 331 332 /** 333 * Feature for {@link #isFeatureSupported(String)}. 334 * This feature covers 335 * {@link SafeBrowsingResponseCompat#backToSafety(boolean)}. 336 */ 337 public static final String SAFE_BROWSING_RESPONSE_BACK_TO_SAFETY = 338 "SAFE_BROWSING_RESPONSE_BACK_TO_SAFETY"; 339 340 /** 341 * Feature for {@link #isFeatureSupported(String)}. 342 * This feature covers 343 * {@link SafeBrowsingResponseCompat#proceed(boolean)}. 344 */ 345 public static final String SAFE_BROWSING_RESPONSE_PROCEED = 346 "SAFE_BROWSING_RESPONSE_PROCEED"; 347 348 /** 349 * Feature for {@link #isFeatureSupported(String)}. 350 * This feature covers 351 * {@link SafeBrowsingResponseCompat#showInterstitial(boolean)}. 352 */ 353 public static final String SAFE_BROWSING_RESPONSE_SHOW_INTERSTITIAL = 354 "SAFE_BROWSING_RESPONSE_SHOW_INTERSTITIAL"; 355 356 /** 357 * Feature for {@link #isFeatureSupported(String)}. 358 * This feature covers {@link WebMessagePortCompat#postMessage(WebMessageCompat)}. 359 */ 360 public static final String WEB_MESSAGE_PORT_POST_MESSAGE = 361 "WEB_MESSAGE_PORT_POST_MESSAGE"; 362 363 /** 364 * Feature for {@link #isFeatureSupported(String)}. 365 * This feature covers {@link WebMessagePortCompat#close()}. 366 */ 367 public static final String WEB_MESSAGE_PORT_CLOSE = "WEB_MESSAGE_PORT_CLOSE"; 368 369 /** 370 * Feature for {@link #isFeatureSupported(String)}. 371 * This feature covers 372 * {@link WebMessagePortCompat#postMessage(WebMessageCompat)} with ArrayBuffer type, 373 * {@link WebViewCompat#postWebMessage(WebView, WebMessageCompat, Uri)} with ArrayBuffer type, 374 * and {@link JavaScriptReplyProxy#postMessage(byte[])}. 375 */ 376 public static final String WEB_MESSAGE_ARRAY_BUFFER = "WEB_MESSAGE_ARRAY_BUFFER"; 377 378 /** 379 * Feature for {@link #isFeatureSupported(String)}. 380 * This feature covers 381 * {@link WebMessagePortCompat#setWebMessageCallback( 382 *WebMessagePortCompat.WebMessageCallbackCompat)}, and 383 * {@link WebMessagePortCompat#setWebMessageCallback(Handler, 384 * WebMessagePortCompat.WebMessageCallbackCompat)}. 385 */ 386 public static final String WEB_MESSAGE_PORT_SET_MESSAGE_CALLBACK = 387 "WEB_MESSAGE_PORT_SET_MESSAGE_CALLBACK"; 388 389 /** 390 * Feature for {@link #isFeatureSupported(String)}. 391 * This feature covers {@link WebViewCompat#createWebMessageChannel(WebView)}. 392 */ 393 public static final String CREATE_WEB_MESSAGE_CHANNEL = "CREATE_WEB_MESSAGE_CHANNEL"; 394 395 /** 396 * Feature for {@link #isFeatureSupported(String)}. 397 * This feature covers {@link WebViewCompat#postWebMessage(WebView, WebMessageCompat, Uri)}. 398 */ 399 public static final String POST_WEB_MESSAGE = "POST_WEB_MESSAGE"; 400 401 /** 402 * Feature for {@link #isFeatureSupported(String)}. 403 * This feature covers 404 * {@link WebMessagePortCompat.WebMessageCallbackCompat#onMessage(WebMessagePortCompat, 405 * WebMessageCompat)}. 406 */ 407 public static final String WEB_MESSAGE_CALLBACK_ON_MESSAGE = 408 "WEB_MESSAGE_CALLBACK_ON_MESSAGE"; 409 410 /** 411 * Feature for {@link #isFeatureSupported(String)}. 412 * This feature covers {@link WebViewCompat#getWebViewClient(WebView)} 413 */ 414 public static final String GET_WEB_VIEW_CLIENT = "GET_WEB_VIEW_CLIENT"; 415 416 /** 417 * Feature for {@link #isFeatureSupported(String)}. 418 * This feature covers {@link WebViewCompat#getWebChromeClient(WebView)} 419 */ 420 public static final String GET_WEB_CHROME_CLIENT = "GET_WEB_CHROME_CLIENT"; 421 422 /** 423 * Feature for {@link #isFeatureSupported(String)}. 424 * This feature covers {@link WebViewCompat#getWebViewRenderProcess(WebView)} 425 */ 426 public static final String GET_WEB_VIEW_RENDERER = "GET_WEB_VIEW_RENDERER"; 427 428 /** 429 * Feature for {@link #isFeatureSupported(String)}. 430 * This feature covers {@link WebViewRenderProcess#terminate()} 431 */ 432 public static final String WEB_VIEW_RENDERER_TERMINATE = "WEB_VIEW_RENDERER_TERMINATE"; 433 434 /** 435 * Feature for {@link #isFeatureSupported(String)}. 436 * This feature covers 437 * {@link WebViewCompat#getWebViewRenderProcessClient(WebView)}, 438 * {@link WebViewCompat#setWebViewRenderProcessClient(WebView, WebViewRenderProcessClient)}, 439 */ 440 public static final String WEB_VIEW_RENDERER_CLIENT_BASIC_USAGE = 441 "WEB_VIEW_RENDERER_CLIENT_BASIC_USAGE"; 442 443 /** 444 * Feature for {@link #isFeatureSupported(String)}. 445 * This feature covers 446 * {@link ProxyController#setProxyOverride(ProxyConfig, Executor, Runnable)}, 447 * {@link ProxyController#clearProxyOverride(Executor, Runnable)}, and 448 */ 449 public static final String PROXY_OVERRIDE = "PROXY_OVERRIDE"; 450 451 /** 452 * Feature for {@link #isFeatureSupported(String)}. 453 * This feature covers {@link WebViewCompat#isMultiProcessEnabled()} 454 */ 455 public static final String MULTI_PROCESS = "MULTI_PROCESS"; 456 457 /** 458 * Feature for {@link #isFeatureSupported(String)}. 459 * This feature covers 460 * {@link WebSettingsCompat#setForceDark(WebSettings, int)} and 461 * {@link WebSettingsCompat#getForceDark(WebSettings)}. 462 */ 463 public static final String FORCE_DARK = "FORCE_DARK"; 464 465 /** 466 * Feature for {@link #isFeatureSupported(String)}. 467 * This feature covers 468 * {@link WebSettingsCompat#setForceDarkStrategy(WebSettings, int)} and 469 * {@link WebSettingsCompat#getForceDarkStrategy(WebSettings)}. 470 */ 471 public static final String FORCE_DARK_STRATEGY = "FORCE_DARK_STRATEGY"; 472 473 /** 474 * Feature for {@link #isFeatureSupported(String)}. 475 * This feature covers 476 * {@link WebSettingsCompat#setAlgorithmicDarkeningAllowed(WebSettings, boolean)} and 477 * {@link WebSettingsCompat#isAlgorithmicDarkeningAllowed(WebSettings)}. 478 */ 479 public static final String ALGORITHMIC_DARKENING = "ALGORITHMIC_DARKENING"; 480 481 /** 482 * Feature for {@link #isFeatureSupported(String)}. 483 * This feature covers {@link WebViewCompat#addWebMessageListener(WebView, 484 * String, Set, WebViewCompat.WebMessageListener)} and {@link 485 * WebViewCompat#removeWebMessageListener(WebView, String)}. 486 */ 487 public static final String WEB_MESSAGE_LISTENER = "WEB_MESSAGE_LISTENER"; 488 489 /** 490 * Feature for {@link #isFeatureSupported(String)}. 491 * This feature covers {@link WebViewCompat#addDocumentStartJavaScript(WebView, String, Set)}. 492 */ 493 public static final String DOCUMENT_START_SCRIPT = "DOCUMENT_START_SCRIPT"; 494 495 /** 496 * Feature for {@link #isFeatureSupported(String)}. 497 * This feature covers {@link ProxyConfig.Builder#setReverseBypassEnabled(boolean)} 498 */ 499 public static final String PROXY_OVERRIDE_REVERSE_BYPASS = "PROXY_OVERRIDE_REVERSE_BYPASS"; 500 501 /** 502 * Feature for {@link #isFeatureSupported(String)}. 503 * This feature covers {@link WebViewCompat#getVariationsHeader()}. 504 */ 505 public static final String GET_VARIATIONS_HEADER = "GET_VARIATIONS_HEADER"; 506 507 /** 508 * Feature for {@link #isFeatureSupported(String)}. 509 * This feature covers 510 * {@link WebSettingsCompat#setEnterpriseAuthenticationAppLinkPolicyEnabled(WebSettings, boolean)}and 511 * {@link WebSettingsCompat#getEnterpriseAuthenticationAppLinkPolicyEnabled(WebSettings)}. 512 */ 513 public static final String ENTERPRISE_AUTHENTICATION_APP_LINK_POLICY = 514 "ENTERPRISE_AUTHENTICATION_APP_LINK_POLICY"; 515 516 /** 517 * Feature for {@link #isFeatureSupported(String)}. 518 * This feature covers 519 * {@link CookieManagerCompat#getCookieInfo(CookieManager, String)}. 520 */ 521 public static final String GET_COOKIE_INFO = "GET_COOKIE_INFO"; 522 523 /** 524 * Feature for {@link #isStartupFeatureSupported(Context, String)}. 525 * This feature covers {@link ProcessGlobalConfig#setDataDirectorySuffix(Context, String)}. 526 */ 527 public static final String STARTUP_FEATURE_SET_DATA_DIRECTORY_SUFFIX = 528 "STARTUP_FEATURE_SET_DATA_DIRECTORY_SUFFIX"; 529 530 /** 531 * Feature for {@link #isStartupFeatureSupported(Context, String)}. 532 * This feature covers {@link ProcessGlobalConfig#setDirectoryBasePaths(Context, File, File)} 533 */ 534 public static final String STARTUP_FEATURE_SET_DIRECTORY_BASE_PATHS = 535 "STARTUP_FEATURE_SET_DIRECTORY_BASE_PATHS"; 536 537 /** 538 * Feature for {@link #isStartupFeatureSupported(Context, String)}. 539 * This feature covers {@link ProcessGlobalConfig#setDirectoryBasePaths(Context, File, File)} 540 */ 541 public static final String STARTUP_FEATURE_CONFIGURE_PARTITIONED_COOKIES = 542 "STARTUP_FEATURE_CONFIGURE_PARTITIONED_COOKIES"; 543 544 /** 545 * Feature for {@link #isFeatureSupported(String)}. 546 * This feature covers 547 * {@link WebSettingsCompat#getRequestedWithHeaderOriginAllowList(WebSettings)}, 548 * {@link WebSettingsCompat#setRequestedWithHeaderOriginAllowList(WebSettings, Set)}, 549 * {@link ServiceWorkerWebSettingsCompat#getRequestedWithHeaderOriginAllowList()}, 550 * {@link ServiceWorkerWebSettingsCompat#setRequestedWithHeaderOriginAllowList(Set)} 551 */ 552 @RestrictTo(RestrictTo.Scope.LIBRARY_GROUP) 553 public static final String REQUESTED_WITH_HEADER_ALLOW_LIST = 554 "REQUESTED_WITH_HEADER_ALLOW_LIST"; 555 556 /** 557 * Feature for {@link #isFeatureSupported(String)}. 558 * This feature covers 559 * {@link WebSettingsCompat#getUserAgentMetadata(WebSettings)}, and 560 * {@link WebSettingsCompat#setUserAgentMetadata(WebSettings, UserAgentMetadata)}. 561 */ 562 public static final String USER_AGENT_METADATA = "USER_AGENT_METADATA"; 563 564 /** 565 * Feature for {@link #isFeatureSupported(String)}. 566 * This feature covers 567 * {@link Profile#getName()}. 568 * {@link Profile#getWebStorage()}. 569 * {@link Profile#getCookieManager()}. 570 * {@link Profile#getGeolocationPermissions()}. 571 * {@link Profile#getServiceWorkerController()}. 572 * {@link ProfileStore#getProfile(String)}. 573 * {@link ProfileStore#getOrCreateProfile(String)}. 574 * {@link ProfileStore#getAllProfileNames()}. 575 * {@link ProfileStore#deleteProfile(String)}. 576 * {@link ProfileStore#getInstance()}. 577 */ 578 public static final String MULTI_PROFILE = "MULTI_PROFILE"; 579 580 /** 581 * Feature for {@link #isFeatureSupported(String)}. 582 * This feature covers 583 * {@link WebSettingsCompat#setAttributionRegistrationBehavior(WebSettings, int)} 584 * {@link WebSettingsCompat#getAttributionRegistrationBehavior(WebSettings)} 585 */ 586 public static final String ATTRIBUTION_REGISTRATION_BEHAVIOR = 587 "ATTRIBUTION_REGISTRATION_BEHAVIOR"; 588 589 /** 590 * Feature for {@link #isFeatureSupported(String)}. 591 * This feature covers 592 * {@link WebSettingsCompat#setWebViewMediaIntegrityApiStatus(WebSettings, WebViewMediaIntegrityApiStatusConfig)} 593 * {@link WebSettingsCompat#getWebViewMediaIntegrityApiStatus(WebSettings)} 594 */ 595 public static final String WEBVIEW_MEDIA_INTEGRITY_API_STATUS = 596 "WEBVIEW_MEDIA_INTEGRITY_API_STATUS"; 597 598 /** 599 * Feature for {@link #isFeatureSupported(String)}. 600 * This feature covers 601 * {@link WebViewCompat#isAudioMuted(WebView)} 602 * {@link WebViewCompat#setAudioMuted(WebView, boolean)} 603 */ 604 public static final String MUTE_AUDIO = "MUTE_AUDIO"; 605 606 /** 607 * Feature for {@link #isFeatureSupported(String)} 608 * This feature covers 609 * {@link WebSettingsCompat#setWebAuthenticationSupport(WebSettings, int)} 610 * {@link WebSettingsCompat#getWebAuthenticationSupport(WebSettings)} 611 */ 612 public static final String WEB_AUTHENTICATION = "WEB_AUTHENTICATION"; 613 614 /** 615 * Feature for {@link #isFeatureSupported(String)}. 616 * This feature covers 617 * {@link WebSettingsCompat#setSpeculativeLoadingStatus(WebSettings, int)} 618 * {@link WebSettingsCompat#getSpeculativeLoadingStatus(WebSettings)}} 619 */ 620 public static final String SPECULATIVE_LOADING = 621 "SPECULATIVE_LOADING_STATUS"; 622 623 /** 624 * Feature for {@link #isFeatureSupported(String)}. 625 * This feature covers 626 * {@link WebSettingsCompat#setBackForwardCacheEnabled(WebSettings, boolean)} 627 * {@link WebSettingsCompat#getBackForwardCacheEnabled(WebSettings)} 628 */ 629 public static final String BACK_FORWARD_CACHE = "BACK_FORWARD_CACHE"; 630 631 /** 632 * Feature for {@link #isFeatureSupported(String)}. 633 * This feature covers 634 * {@link Profile#prefetchUrlAsync(String, CancellationSignal, Executor, SpeculativeLoadingParameters, OutcomeReceiverCompat)} 635 * {@link Profile#prefetchUrlAsync(String, CancellationSignal, Executor, OutcomeReceiverCompat)} 636 * {@link Profile#clearPrefetchAsync(String, Executor, OutcomeReceiverCompat)} 637 */ 638 @Profile.ExperimentalUrlPrefetch 639 public static final String PROFILE_URL_PREFETCH = "PREFETCH_URL_V4"; 640 641 /** 642 * Feature for {@link #isFeatureSupported(String)}. 643 * This feature covers {@link WebViewCompat#setDefaultTrafficStatsTag(int)}} 644 */ 645 public static final String DEFAULT_TRAFFICSTATS_TAGGING = "DEFAULT_TRAFFICSTATS_TAGGING"; 646 647 /** 648 * Feature for {@link #isFeatureSupported(String)}. 649 * This feature covers 650 * {@link WebStorageCompat#deleteBrowsingData(WebStorage, Executor, Runnable)}, 651 * {@link WebStorageCompat#deleteBrowsingData(WebStorage, Runnable)}, 652 * {@link WebStorageCompat#deleteBrowsingDataForSite(WebStorage, String, Executor, Runnable)}, 653 * {@link WebStorageCompat#deleteBrowsingDataForSite(WebStorage, String, Runnable)} 654 */ 655 public static final String DELETE_BROWSING_DATA = "DELETE_BROWSING_DATA"; 656 657 /** 658 * Feature for {@link #isFeatureSupported(String)}. 659 * This feature covers 660 * {@link androidx.webkit.WebViewCompat#prerenderUrl(WebView, String, CancellationSignal, 661 * Executor, SpeculativeLoadingParameters, PrerenderOperationCallback)}} 662 */ 663 @WebViewCompat.ExperimentalUrlPrerender 664 public static final String PRERENDER_WITH_URL = "PRERENDER_URL_V2"; 665 666 /** 667 * Feature for {@link #isFeatureSupported(String)}. 668 * This feature covers 669 * {@link Profile#setSpeculativeLoadingConfig(SpeculativeLoadingConfig)} 670 */ 671 @Profile.ExperimentalUrlPrefetch 672 public static final String SPECULATIVE_LOADING_CONFIG = "SPECULATIVE_LOADING_CONFIG_V2"; 673 674 /** 675 * Feature for {@link #isFeatureSupported(String)}. 676 * This feature covers {@link WebViewCompat#saveState}. 677 */ 678 @WebViewCompat.ExperimentalSaveState 679 public static final String SAVE_STATE = "SAVE_STATE"; 680 681 /** 682 * Feature for {@link WebViewFeature#isFeatureSupported(String)}. 683 * This feature covers {@link WebViewCompat#getWebNavigationClient(WebView)}; 684 * This feature covers 685 * {@link WebViewCompat#setWebNavigationClient(WebView, WebNavigationClient)}; 686 * This feature covers {@link Navigation#didCommitErrorPage()}. 687 * This feature covers {@link Navigation#getPage()}. 688 * This feature covers {@link Navigation#isBack()}. 689 * This feature covers {@link Navigation#isForward()}. 690 * This feature covers {@link Navigation#isHistory()}. 691 * This feature covers {@link Navigation#isRestore()}. 692 * This feature covers {@link Navigation#isReload()}. 693 * This feature covers {@link Navigation#wasInitiatedByPage()}. 694 * This feature covers {@link Navigation#isSameDocument()}. 695 * This feature covers {@link Navigation#didCommit()}. 696 * This feature covers the initial version of {@link Page}. 697 */ 698 public static final String NAVIGATION_CALLBACK_BASIC = "WEB_VIEW_NAVIGATION_CLIENT_BASIC_USAGE"; 699 700 /** 701 * Feature for {@link #isFeatureSupported(String)}. 702 * This feature covers {@link WebViewCompat#setShouldCacheProvider(boolean)}. 703 */ 704 @WebViewCompat.ExperimentalCacheProvider 705 public static final String CACHE_PROVIDER = "CACHE_PROVIDER"; 706 707 /** 708 * Feature for {@link #isFeatureSupported(String)}. 709 * This feature covers 710 * {@link WebSettingsCompat#setPaymentRequestEnabled(WebSettings, boolean)}, 711 * {@link WebSettingsCompat#getPaymentRequestEnabled(WebSettings)}, 712 * {@link WebSettingsCompat#setHasEnrolledInstrumentEnabled(WebSettings, boolean)}, and 713 * {@link WebSettingsCompat#getHasEnrolledInstrumentEnabled(WebSettings)}, 714 */ 715 public static final String PAYMENT_REQUEST = "PAYMENT_REQUEST"; 716 717 /** 718 * Return whether a feature is supported at run-time. This will check whether a feature is 719 * supported, depending on the combination of the desired feature, the Android version of 720 * device, and the WebView APK on the device. 721 * 722 * <p class="note"><b>Note:</b> This method is different from 723 * {@link WebViewFeature#isStartupFeatureSupported(Context, String)} and this method only 724 * accepts certain features. Please verify that the correct feature checking method is used for 725 * a particular feature. 726 * 727 * <p class="note"><b>Note:</b> If this method returns {@code false}, it is not safe to invoke 728 * the methods requiring the desired feature. Furthermore, if this method returns {@code false} 729 * for a particular feature, any callback guarded by that feature will not be invoked. 730 * 731 * @param feature the feature to be checked 732 * @return whether the feature is supported given the current platform SDK and WebView version 733 */ isFeatureSupported(@ebViewSupportFeature @onNull String feature)734 public static boolean isFeatureSupported(@WebViewSupportFeature @NonNull String feature) { 735 return WebViewFeatureInternal.isSupported(feature); 736 } 737 738 /** 739 * Return whether a startup feature is supported at run-time. This will check whether a startup 740 * feature is 741 * supported, depending on the combination of the desired feature, the Android version of 742 * device, and the WebView APK on the device. 743 * 744 * <p class="note"><b>Note:</b> This method is different from 745 * {@link #isFeatureSupported(String)} and this method only accepts startup features. Please 746 * verify that the correct feature checking method is used for a particular feature. 747 * 748 * <p class="note"><b>Note:</b> If this method returns {@code false}, it is not safe to invoke 749 * the methods requiring the desired feature. Furthermore, if this method returns {@code false} 750 * for a particular feature, any callback guarded by that feature will not be invoked. 751 * 752 * @param context a Context to access application assets This value cannot be null. 753 * @param startupFeature the startup feature to be checked 754 * @return whether the feature is supported given the current platform SDK and WebView version 755 */ isStartupFeatureSupported(@onNull Context context, @WebViewStartupFeature @NonNull String startupFeature)756 public static boolean isStartupFeatureSupported(@NonNull Context context, 757 @WebViewStartupFeature @NonNull String startupFeature) { 758 return WebViewFeatureInternal.isStartupFeatureSupported(startupFeature, context); 759 } 760 } 761