1 /* 2 * Copyright (C) 2012 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 android.webkit; 18 19 import android.annotation.NonNull; 20 import android.annotation.SystemApi; 21 import android.content.Context; 22 import android.content.Intent; 23 import android.content.pm.PackageInfo; 24 import android.net.Network; 25 import android.net.Uri; 26 import android.os.Build; 27 import android.text.TextUtils; 28 29 import java.util.List; 30 31 /** 32 * This is the main entry-point into the WebView back end implementations, which the WebView 33 * proxy class uses to instantiate all the other objects as needed. The backend must provide an 34 * implementation of this interface, and make it available to the WebView via mechanism TBD. 35 * @hide 36 */ 37 @SystemApi 38 public interface WebViewFactoryProvider { 39 /** 40 * Used as the requirement when Flags.useBEntryPoint() is false. 41 * @hide 42 */ 43 int MINIMUM_SUPPORTED_TARGET_SDK = Build.VERSION_CODES.TIRAMISU; 44 45 /** 46 * Used as the requirement when Flags.useBEntryPoint() is true. 47 * TODO: set to the actual minimum required version code - this is just the 48 * version shipped in V. 49 * @hide 50 */ 51 long MINIMUM_SUPPORTED_VERSION_CODE = 661308800L; 52 53 /** 54 * Returns whether the WebView implementation represented by {@code packageInfo} 55 * is compatible with this version of Android. 56 * @hide 57 */ isCompatibleImplementationPackage(@onNull PackageInfo packageInfo)58 static boolean isCompatibleImplementationPackage(@NonNull PackageInfo packageInfo) { 59 if (Flags.useBEntryPoint()) { 60 return packageInfo.versionCode >= MINIMUM_SUPPORTED_VERSION_CODE; 61 } else { 62 return packageInfo.applicationInfo.targetSdkVersion >= MINIMUM_SUPPORTED_TARGET_SDK; 63 } 64 } 65 66 /** 67 * Returns a string describing the minimum requirement for a WebView implementation 68 * to be compatible with this version of Android, for debugging purposes. 69 * @hide 70 */ describeCompatibleImplementationPackage()71 static @NonNull String describeCompatibleImplementationPackage() { 72 if (Flags.useBEntryPoint()) { 73 return TextUtils.formatSimple("Minimum versionCode for OS support: %d", 74 MINIMUM_SUPPORTED_VERSION_CODE); 75 } else { 76 return TextUtils.formatSimple("Minimum targetSdkVersion: %d", 77 MINIMUM_SUPPORTED_TARGET_SDK); 78 } 79 } 80 81 /** 82 * Returns the name of the class that should be used when loading the 83 * WebView implementation on this version of Android. 84 * @hide 85 */ getWebViewFactoryClassName()86 static @NonNull String getWebViewFactoryClassName() { 87 if (Flags.useBEntryPoint()) { 88 return "com.android.webview.chromium.WebViewChromiumFactoryProviderForB"; 89 } else { 90 return "com.android.webview.chromium.WebViewChromiumFactoryProviderForT"; 91 } 92 } 93 94 /** 95 * This Interface provides glue for implementing the backend of WebView static methods which 96 * cannot be implemented in-situ in the proxy class. 97 */ 98 interface Statics { 99 /** 100 * Implements the API method: 101 * {@link android.webkit.WebView#findAddress(String)} 102 */ findAddress(String addr)103 String findAddress(String addr); 104 105 /** 106 * Implements the API method: 107 * {@link android.webkit.WebSettings#getDefaultUserAgent(Context) } 108 */ getDefaultUserAgent(Context context)109 String getDefaultUserAgent(Context context); 110 111 /** 112 * Used for tests only. 113 */ freeMemoryForTests()114 void freeMemoryForTests(); 115 116 /** 117 * Implements the API method: 118 * {@link android.webkit.WebView#setWebContentsDebuggingEnabled(boolean) } 119 */ setWebContentsDebuggingEnabled(boolean enable)120 void setWebContentsDebuggingEnabled(boolean enable); 121 122 /** 123 * Implements the API method: 124 * {@link android.webkit.WebView#clearClientCertPreferences(Runnable) } 125 */ clearClientCertPreferences(Runnable onCleared)126 void clearClientCertPreferences(Runnable onCleared); 127 128 /** 129 * Implements the API method: 130 * {@link android.webkit.WebView#setSlowWholeDocumentDrawEnabled(boolean) } 131 */ enableSlowWholeDocumentDraw()132 void enableSlowWholeDocumentDraw(); 133 134 /** 135 * Implement the API method 136 * {@link android.webkit.WebChromeClient.FileChooserParams#parseResult(int, Intent)} 137 */ parseFileChooserResult(int resultCode, Intent intent)138 Uri[] parseFileChooserResult(int resultCode, Intent intent); 139 140 /** 141 * Implement the API method 142 * {@link android.webkit.WebView#startSafeBrowsing(Context , ValueCallback<Boolean>)} 143 */ initSafeBrowsing(Context context, ValueCallback<Boolean> callback)144 void initSafeBrowsing(Context context, ValueCallback<Boolean> callback); 145 146 /** 147 * Implement the API method 148 * {@link android.webkit.WebView#setSafeBrowsingWhitelist(List<String>, 149 * ValueCallback<Boolean>)} 150 */ setSafeBrowsingWhitelist(List<String> hosts, ValueCallback<Boolean> callback)151 void setSafeBrowsingWhitelist(List<String> hosts, ValueCallback<Boolean> callback); 152 153 /** 154 * Implement the API method 155 * {@link android.webkit.WebView#getSafeBrowsingPrivacyPolicyUrl()} 156 */ 157 @NonNull getSafeBrowsingPrivacyPolicyUrl()158 Uri getSafeBrowsingPrivacyPolicyUrl(); 159 } 160 getStatics()161 Statics getStatics(); 162 163 /** 164 * Construct a new WebViewProvider. 165 * @param webView the WebView instance bound to this implementation instance. Note it will not 166 * necessarily be fully constructed at the point of this call: defer real initialization to 167 * WebViewProvider.init(). 168 * @param privateAccess provides access into WebView internal methods. 169 */ createWebView(WebView webView, WebView.PrivateAccess privateAccess)170 WebViewProvider createWebView(WebView webView, WebView.PrivateAccess privateAccess); 171 172 /** 173 * Gets the singleton GeolocationPermissions instance for this WebView implementation. The 174 * implementation must return the same instance on subsequent calls. 175 * @return the single GeolocationPermissions instance. 176 */ getGeolocationPermissions()177 GeolocationPermissions getGeolocationPermissions(); 178 179 /** 180 * Gets the singleton CookieManager instance for this WebView implementation. The 181 * implementation must return the same instance on subsequent calls. 182 * 183 * @return the singleton CookieManager instance 184 */ getCookieManager()185 CookieManager getCookieManager(); 186 187 /** 188 * Gets the TokenBindingService instance for this WebView implementation. The 189 * implementation must return the same instance on subsequent calls. 190 * 191 * @deprecated this method only returns {@code null} 192 * @return the TokenBindingService instance (which is always {@code null}) 193 */ getTokenBindingService()194 TokenBindingService getTokenBindingService(); 195 196 /** 197 * Gets the TracingController instance for this WebView implementation. The 198 * implementation must return the same instance on subsequent calls. 199 * 200 * @return the TracingController instance 201 */ getTracingController()202 TracingController getTracingController(); 203 204 /** 205 * Gets the ServiceWorkerController instance for this WebView implementation. The 206 * implementation must return the same instance on subsequent calls. 207 * 208 * @return the ServiceWorkerController instance 209 */ getServiceWorkerController()210 ServiceWorkerController getServiceWorkerController(); 211 212 /** 213 * Gets the singleton WebIconDatabase instance for this WebView implementation. The 214 * implementation must return the same instance on subsequent calls. 215 * 216 * @return the singleton WebIconDatabase instance 217 */ getWebIconDatabase()218 WebIconDatabase getWebIconDatabase(); 219 220 /** 221 * Gets the singleton WebStorage instance for this WebView implementation. The 222 * implementation must return the same instance on subsequent calls. 223 * 224 * @return the singleton WebStorage instance 225 */ getWebStorage()226 WebStorage getWebStorage(); 227 228 /** 229 * Gets the singleton WebViewDatabase instance for this WebView implementation. The 230 * implementation must return the same instance on subsequent calls. 231 * 232 * @return the singleton WebViewDatabase instance 233 */ getWebViewDatabase(Context context)234 WebViewDatabase getWebViewDatabase(Context context); 235 236 /** 237 * Gets the default PacProcessor instance. 238 * @return the PacProcessor instance 239 */ 240 @NonNull getPacProcessor()241 default PacProcessor getPacProcessor() { 242 throw new UnsupportedOperationException("Not implemented"); 243 } 244 245 /** 246 * Create a new PacProcessor instance. 247 * 248 * @param network a {@link Network} which needs to be associated 249 * with the returned {@link PacProcessor}. 250 * If {@code null} the method returns default {@link PacProcessor}. 251 * @return the {@link PacProcessor} instance associated with {@link Network}. 252 */ 253 @NonNull createPacProcessor()254 default PacProcessor createPacProcessor() { 255 throw new UnsupportedOperationException("Not implemented"); 256 } 257 258 /** 259 * Gets the classloader used to load internal WebView implementation classes. This interface 260 * should only be used by the WebView Support Library. 261 */ getWebViewClassLoader()262 ClassLoader getWebViewClassLoader(); 263 } 264