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.net.Uri;
24 
25 import java.util.List;
26 
27 /**
28  * This is the main entry-point into the WebView back end implementations, which the WebView
29  * proxy class uses to instantiate all the other objects as needed. The backend must provide an
30  * implementation of this interface, and make it available to the WebView via mechanism TBD.
31  * @hide
32  */
33 @SystemApi
34 public interface WebViewFactoryProvider {
35     /**
36      * This Interface provides glue for implementing the backend of WebView static methods which
37      * cannot be implemented in-situ in the proxy class.
38      */
39     interface Statics {
40         /**
41          * Implements the API method:
42          * {@link android.webkit.WebView#findAddress(String)}
43          */
findAddress(String addr)44         String findAddress(String addr);
45 
46         /**
47          * Implements the API method:
48          * {@link android.webkit.WebSettings#getDefaultUserAgent(Context) }
49          */
getDefaultUserAgent(Context context)50         String getDefaultUserAgent(Context context);
51 
52         /**
53          * Used for tests only.
54          */
freeMemoryForTests()55          void freeMemoryForTests();
56 
57         /**
58          * Implements the API method:
59          * {@link android.webkit.WebView#setWebContentsDebuggingEnabled(boolean) }
60          */
setWebContentsDebuggingEnabled(boolean enable)61         void setWebContentsDebuggingEnabled(boolean enable);
62 
63         /**
64          * Implements the API method:
65          * {@link android.webkit.WebView#clearClientCertPreferences(Runnable) }
66          */
clearClientCertPreferences(Runnable onCleared)67         void clearClientCertPreferences(Runnable onCleared);
68 
69         /**
70          * Implements the API method:
71          * {@link android.webkit.WebView#setSlowWholeDocumentDrawEnabled(boolean) }
72          */
enableSlowWholeDocumentDraw()73         void enableSlowWholeDocumentDraw();
74 
75         /**
76          * Implement the API method
77          * {@link android.webkit.WebChromeClient.FileChooserParams#parseResult(int, Intent)}
78          */
parseFileChooserResult(int resultCode, Intent intent)79         Uri[] parseFileChooserResult(int resultCode, Intent intent);
80 
81         /**
82          * Implement the API method
83          * {@link android.webkit.WebView#startSafeBrowsing(Context , ValueCallback<Boolean>)}
84          */
initSafeBrowsing(Context context, ValueCallback<Boolean> callback)85         void initSafeBrowsing(Context context, ValueCallback<Boolean> callback);
86 
87         /**
88         * Implement the API method
89         * {@link android.webkit.WebView#setSafeBrowsingWhitelist(List<String>,
90         * ValueCallback<Boolean>)}
91         */
setSafeBrowsingWhitelist(List<String> hosts, ValueCallback<Boolean> callback)92         void setSafeBrowsingWhitelist(List<String> hosts, ValueCallback<Boolean> callback);
93 
94         /**
95          * Implement the API method
96          * {@link android.webkit.WebView#getSafeBrowsingPrivacyPolicyUrl()}
97          */
98         @NonNull
getSafeBrowsingPrivacyPolicyUrl()99         Uri getSafeBrowsingPrivacyPolicyUrl();
100     }
101 
getStatics()102     Statics getStatics();
103 
104     /**
105      * Construct a new WebViewProvider.
106      * @param webView the WebView instance bound to this implementation instance. Note it will not
107      * necessarily be fully constructed at the point of this call: defer real initialization to
108      * WebViewProvider.init().
109      * @param privateAccess provides access into WebView internal methods.
110      */
createWebView(WebView webView, WebView.PrivateAccess privateAccess)111     WebViewProvider createWebView(WebView webView, WebView.PrivateAccess privateAccess);
112 
113     /**
114      * Gets the singleton GeolocationPermissions instance for this WebView implementation. The
115      * implementation must return the same instance on subsequent calls.
116      * @return the single GeolocationPermissions instance.
117      */
getGeolocationPermissions()118     GeolocationPermissions getGeolocationPermissions();
119 
120     /**
121      * Gets the singleton CookieManager instance for this WebView implementation. The
122      * implementation must return the same instance on subsequent calls.
123      *
124      * @return the singleton CookieManager instance
125      */
getCookieManager()126     CookieManager getCookieManager();
127 
128     /**
129      * Gets the TokenBindingService instance for this WebView implementation. The
130      * implementation must return the same instance on subsequent calls.
131      *
132      * @deprecated this method only returns {@code null}
133      * @return the TokenBindingService instance (which is always {@code null})
134      */
getTokenBindingService()135     TokenBindingService getTokenBindingService();
136 
137     /**
138      * Gets the TracingController instance for this WebView implementation. The
139      * implementation must return the same instance on subsequent calls.
140      *
141      * @return the TracingController instance
142      */
getTracingController()143     TracingController getTracingController();
144 
145     /**
146      * Gets the ServiceWorkerController instance for this WebView implementation. The
147      * implementation must return the same instance on subsequent calls.
148      *
149      * @return the ServiceWorkerController instance
150      */
getServiceWorkerController()151     ServiceWorkerController getServiceWorkerController();
152 
153     /**
154      * Gets the singleton WebIconDatabase instance for this WebView implementation. The
155      * implementation must return the same instance on subsequent calls.
156      *
157      * @return the singleton WebIconDatabase instance
158      */
getWebIconDatabase()159     WebIconDatabase getWebIconDatabase();
160 
161     /**
162      * Gets the singleton WebStorage instance for this WebView implementation. The
163      * implementation must return the same instance on subsequent calls.
164      *
165      * @return the singleton WebStorage instance
166      */
getWebStorage()167     WebStorage getWebStorage();
168 
169     /**
170      * Gets the singleton WebViewDatabase instance for this WebView implementation. The
171      * implementation must return the same instance on subsequent calls.
172      *
173      * @return the singleton WebViewDatabase instance
174      */
getWebViewDatabase(Context context)175     WebViewDatabase getWebViewDatabase(Context context);
176 
177     /**
178      * Gets the classloader used to load internal WebView implementation classes. This interface
179      * should only be used by the WebView Support Library.
180      */
getWebViewClassLoader()181     ClassLoader getWebViewClassLoader();
182 }
183