Home | History | Annotate | Download | only in internal
      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.internal;
     18 
     19 import android.webkit.WebView;
     20 
     21 import org.chromium.support_lib_boundary.ServiceWorkerControllerBoundaryInterface;
     22 import org.chromium.support_lib_boundary.StaticsBoundaryInterface;
     23 import org.chromium.support_lib_boundary.WebViewProviderBoundaryInterface;
     24 import org.chromium.support_lib_boundary.WebViewProviderFactoryBoundaryInterface;
     25 import org.chromium.support_lib_boundary.WebkitToCompatConverterBoundaryInterface;
     26 import org.chromium.support_lib_boundary.util.BoundaryInterfaceReflectionUtil;
     27 
     28 /**
     29  * Adapter for WebViewProviderFactoryBoundaryInterface providing static WebView functionality
     30  * similar to that provided by {@link android.webkit.WebViewFactoryProvider}.
     31  */
     32 public class WebViewProviderFactoryAdapter implements WebViewProviderFactory {
     33     WebViewProviderFactoryBoundaryInterface mImpl;
     34 
     35     public WebViewProviderFactoryAdapter(WebViewProviderFactoryBoundaryInterface impl) {
     36         mImpl = impl;
     37     }
     38 
     39     /**
     40      * Adapter method for creating a new support library version of
     41      * {@link android.webkit.WebViewProvider} - the class used to implement
     42      * {@link androidx.webkit.WebViewCompat}.
     43      */
     44     @Override
     45     public WebViewProviderBoundaryInterface createWebView(WebView webview) {
     46         return BoundaryInterfaceReflectionUtil.castToSuppLibClass(
     47                 WebViewProviderBoundaryInterface.class, mImpl.createWebView(webview));
     48     }
     49 
     50     /**
     51      * Adapter method for creating a new support library version of
     52      * {@link androidx.webkit.internal.WebkitToCompatConverter}, which converts android.webkit
     53      * classes into their corresponding support library classes.
     54      */
     55     @Override
     56     public WebkitToCompatConverterBoundaryInterface getWebkitToCompatConverter() {
     57         return BoundaryInterfaceReflectionUtil.castToSuppLibClass(
     58                 WebkitToCompatConverterBoundaryInterface.class, mImpl.getWebkitToCompatConverter());
     59     }
     60 
     61     /**
     62      * Adapter method for fetching the support library class representing
     63      * {@link android.webkit.WebViewFactoryProvider#Statics}.
     64      */
     65     @Override
     66     public StaticsBoundaryInterface getStatics() {
     67         return BoundaryInterfaceReflectionUtil.castToSuppLibClass(
     68                 StaticsBoundaryInterface.class, mImpl.getStatics());
     69     }
     70 
     71     /**
     72      * Adapter method for fetching the features supported by the current WebView APK.
     73      */
     74     @Override
     75     public String[] getWebViewFeatures() {
     76         return mImpl.getSupportedFeatures();
     77     }
     78 
     79     /**
     80      * Adapter method for fetching the support library class representing
     81      * {@link android.webkit.ServiceWorkerController}.
     82      */
     83     @Override
     84     public ServiceWorkerControllerBoundaryInterface getServiceWorkerController() {
     85         return BoundaryInterfaceReflectionUtil.castToSuppLibClass(
     86                 ServiceWorkerControllerBoundaryInterface.class, mImpl.getServiceWorkerController());
     87     }
     88 }
     89