Ejemplo n.º 1
0
  public TiUIWebView(TiViewProxy proxy) {
    super(proxy);
    this.isFocusable = true;
    TiWebView webView =
        isHTCSenseDevice()
            ? new TiWebView(proxy.getActivity())
            : new NonHTCWebView(proxy.getActivity());
    webView.setVerticalScrollbarOverlay(true);

    WebSettings settings = webView.getSettings();
    settings.setUseWideViewPort(true);
    settings.setJavaScriptEnabled(true);
    settings.setSupportMultipleWindows(true);
    settings.setJavaScriptCanOpenWindowsAutomatically(true);
    settings.setAllowFileAccess(true);
    settings.setDomStorageEnabled(
        true); // Required by some sites such as Twitter. This is in our iOS WebView too.
    File path = TiApplication.getInstance().getFilesDir();
    if (path != null) {
      settings.setDatabasePath(path.getAbsolutePath());
      settings.setDatabaseEnabled(true);
    }

    File cacheDir = TiApplication.getInstance().getCacheDir();
    if (cacheDir != null) {
      settings.setAppCacheEnabled(true);
      settings.setAppCachePath(cacheDir.getAbsolutePath());
    }

    // enable zoom controls by default
    boolean enableZoom = true;

    if (proxy.hasProperty(TiC.PROPERTY_ENABLE_ZOOM_CONTROLS)) {
      enableZoom = TiConvert.toBoolean(proxy.getProperty(TiC.PROPERTY_ENABLE_ZOOM_CONTROLS));
    }

    settings.setBuiltInZoomControls(enableZoom);
    settings.setSupportZoom(enableZoom);

    if (TiC.JELLY_BEAN_OR_GREATER) {
      settings.setAllowUniversalAccessFromFileURLs(
          true); // default is "false" for JellyBean, TIMOB-13065
    }

    // We can only support webview settings for plugin/flash in API 8 and higher.
    if (Build.VERSION.SDK_INT > Build.VERSION_CODES.ECLAIR_MR1) {
      initializePluginAPI(webView);
    }

    boolean enableJavascriptInterface =
        TiConvert.toBoolean(proxy.getProperty(TiC.PROPERTY_ENABLE_JAVASCRIPT_INTERFACE), true);
    chromeClient = new TiWebChromeClient(this);
    webView.setWebChromeClient(chromeClient);
    client = new TiWebViewClient(this, webView);
    webView.setWebViewClient(client);
    if (Build.VERSION.SDK_INT > 16 || enableJavascriptInterface) {
      client.getBinding().addJavascriptInterfaces();
    }
    webView.client = client;

    if (proxy instanceof WebViewProxy) {
      WebViewProxy webProxy = (WebViewProxy) proxy;
      String username = webProxy.getBasicAuthenticationUserName();
      String password = webProxy.getBasicAuthenticationPassword();
      if (username != null && password != null) {
        setBasicAuthentication(username, password);
      }
      webProxy.clearBasicAuthentication();
    }

    TiCompositeLayout.LayoutParams params = getLayoutParams();
    params.autoFillsHeight = true;
    params.autoFillsWidth = true;

    setNativeView(webView);
  }