private void initializePluginAPI(TiWebView webView) { try { synchronized (this.getClass()) { // Initialize if (enumPluginStateOff == null) { Class<?> webSettings = Class.forName("android.webkit.WebSettings"); Class<?> pluginState = Class.forName("android.webkit.WebSettings$PluginState"); Field f = pluginState.getDeclaredField("OFF"); enumPluginStateOff = (Enum<?>) f.get(null); f = pluginState.getDeclaredField("ON"); enumPluginStateOn = (Enum<?>) f.get(null); f = pluginState.getDeclaredField("ON_DEMAND"); enumPluginStateOnDemand = (Enum<?>) f.get(null); internalSetPluginState = webSettings.getMethod("setPluginState", pluginState); // Hidden APIs // http://android.git.kernel.org/?p=platform/frameworks/base.git;a=blob;f=core/java/android/webkit/WebView.java;h=bbd8b95c7bea66b7060b5782fae4b3b2c4f04966;hb=4db1f432b853152075923499768639e14403b73a#l2558 internalWebViewPause = webView.getClass().getMethod("onPause"); internalWebViewResume = webView.getClass().getMethod("onResume"); } } } catch (ClassNotFoundException e) { Log.e(TAG, "ClassNotFound: " + e.getMessage(), e); } catch (NoSuchMethodException e) { Log.e(TAG, "NoSuchMethod: " + e.getMessage(), e); } catch (NoSuchFieldException e) { Log.e(TAG, "NoSuchField: " + e.getMessage(), e); } catch (IllegalAccessException e) { Log.e(TAG, "IllegalAccess: " + e.getMessage(), e); } }
public void setPluginState(int pluginState) { if (Build.VERSION.SDK_INT > Build.VERSION_CODES.ECLAIR_MR1) { TiWebView webView = (TiWebView) getNativeView(); WebSettings webSettings = webView.getSettings(); if (webView != null) { try { switch (pluginState) { case PLUGIN_STATE_OFF: internalSetPluginState.invoke(webSettings, enumPluginStateOff); break; case PLUGIN_STATE_ON: internalSetPluginState.invoke(webSettings, enumPluginStateOn); break; case PLUGIN_STATE_ON_DEMAND: internalSetPluginState.invoke(webSettings, enumPluginStateOnDemand); break; default: Log.w(TAG, "Not a valid plugin state. Ignoring setPluginState request"); } } catch (InvocationTargetException e) { Log.e(TAG, "Method not supported", e); } catch (IllegalAccessException e) { Log.e(TAG, "Illegal Access", e); } } } }
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); }