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.WebkitToCompatConverterBoundaryInterface;
     25 
     26 /**
     27  * This is a stub class used when the WebView Support Library is invoked on a device incompatible
     28  * with the library (either a pre-L device or a device without a compatible WebView APK).
     29  * The only method in this class that should be called is {@link #getWebViewFeatures()}.
     30  */
     31 public class IncompatibleApkWebViewProviderFactory implements WebViewProviderFactory {
     32     private static final String[] EMPTY_STRING_ARRAY = new String[0];
     33     private static final String UNSUPPORTED_EXCEPTION_EXPLANATION =
     34             "This should never happen, if this method was called it means we're trying to reach "
     35             + "into WebView APK code on an incompatible device. This most likely means the current "
     36             + "method is being called too early, or is being called on start-up rather than lazily";
     37 
     38     @Override
     39     public WebViewProviderBoundaryInterface createWebView(WebView webview) {
     40         throw new UnsupportedOperationException(UNSUPPORTED_EXCEPTION_EXPLANATION);
     41     }
     42 
     43     @Override
     44     public WebkitToCompatConverterBoundaryInterface getWebkitToCompatConverter() {
     45         throw new UnsupportedOperationException(UNSUPPORTED_EXCEPTION_EXPLANATION);
     46     }
     47 
     48     @Override
     49     public StaticsBoundaryInterface getStatics() {
     50         throw new UnsupportedOperationException(UNSUPPORTED_EXCEPTION_EXPLANATION);
     51     }
     52 
     53     @Override
     54     public String[] getWebViewFeatures() {
     55         return EMPTY_STRING_ARRAY;
     56     }
     57 
     58     @Override
     59     public ServiceWorkerControllerBoundaryInterface getServiceWorkerController() {
     60         throw new UnsupportedOperationException(UNSUPPORTED_EXCEPTION_EXPLANATION);
     61     }
     62 }
     63