cordova-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bows...@apache.org
Subject [13/18] android commit: Make correct webview client and chrome client for specific webview engine.
Date Wed, 30 Apr 2014 22:02:57 GMT
Make correct webview client and chrome client for specific webview engine.

It changes the webview preference naming from full name to prefix, since the
prefix is also used to construct the name of WebView, WebViewClient and
ChromeClient.

For example, for Crosswalk webview, config.xml contains:
<preference name="webView" value="org.apache.cordova.engine.crosswalk.XWalkCordova" />


Project: http://git-wip-us.apache.org/repos/asf/cordova-android/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-android/commit/dbfc2923
Tree: http://git-wip-us.apache.org/repos/asf/cordova-android/tree/dbfc2923
Diff: http://git-wip-us.apache.org/repos/asf/cordova-android/diff/dbfc2923

Branch: refs/heads/pluggable_webview
Commit: dbfc292353616051452101df0b68eecc9828af08
Parents: b9a24f0
Author: Ningxin Hu <ningxin.hu@intel.com>
Authored: Wed Apr 23 16:33:31 2014 +0800
Committer: Ningxin Hu <ningxin.hu@intel.com>
Committed: Wed Apr 23 16:33:31 2014 +0800

----------------------------------------------------------------------
 .../src/org/apache/cordova/CordovaActivity.java | 68 +++++++++++++++++++-
 1 file changed, 67 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-android/blob/dbfc2923/framework/src/org/apache/cordova/CordovaActivity.java
----------------------------------------------------------------------
diff --git a/framework/src/org/apache/cordova/CordovaActivity.java b/framework/src/org/apache/cordova/CordovaActivity.java
index 8931b51..d566714 100755
--- a/framework/src/org/apache/cordova/CordovaActivity.java
+++ b/framework/src/org/apache/cordova/CordovaActivity.java
@@ -214,7 +214,7 @@ public class CordovaActivity extends Activity implements CordovaInterface
{
      * require a more specialized web view.
      */
     protected CordovaWebView makeWebView() {
-        String r = this.getStringProperty("webView", "org.apache.cordova.AndroidWebView");
+        String r = this.getStringProperty("webView", "org.apache.cordova.Android").concat("WebView");
 
         try {
             Class webViewClass = Class.forName(r);
@@ -254,6 +254,39 @@ public class CordovaActivity extends Activity implements CordovaInterface
{
      * @param webView the default constructed web view object
      */
     protected CordovaWebViewClient makeWebViewClient(CordovaWebView webView) {
+    	String r = this.getStringProperty("webView", "org.apache.cordova.Android").concat("WebViewClient");
+
+        try {
+            Class webViewClientClass = Class.forName(r);
+            Constructor<CordovaWebViewClient> [] webViewClientConstructors = webViewClientClass.getConstructors();
+            
+            
+            if(CordovaWebViewClient.class.isAssignableFrom(webViewClientClass)) {
+            	for (Constructor<CordovaWebViewClient> constructor : webViewClientConstructors)
{
+            		try {
+            			CordovaWebViewClient webViewClient =  (CordovaWebViewClient) constructor.newInstance(this,
webView);
+                        return webViewClient;
+            		} catch (IllegalArgumentException e) {
+                        LOG.e(TAG, "Illegal arguments, try next constructor.");
+                    }
+            	}
+            }
+            else
+            {
+                LOG.e(TAG, "The WebView Engine is NOT a proper WebView, defaulting to system
WebView");
+            }
+        } catch (ClassNotFoundException e) {
+            LOG.e(TAG, "The WebView Engine was not found, defaulting to system WebView");
+        } catch (InstantiationException e) {
+            LOG.e(TAG, "Unable to instantiate the WebView, defaulting to system WebView");
+        } catch (IllegalAccessException e) {
+            LOG.e(TAG, "Illegal Access to Constructor.  This should never happen, defaulting
to system WebView");
+        } catch (IllegalArgumentException e) {
+            LOG.e(TAG, "The WebView does not implement the default constructor, defaulting
to system WebView");
+        } catch (InvocationTargetException e) {
+            LOG.e(TAG, "Invocation Target Exception! Reflection is hard, defaulting to system
WebView");
+        }
+
         if(android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.HONEYCOMB)
{
             return (CordovaWebViewClient) new AndroidWebViewClient(this, webView);
         } else {
@@ -270,6 +303,39 @@ public class CordovaActivity extends Activity implements CordovaInterface
{
      * @param webView the default constructed web view object
      */
     protected CordovaChromeClient makeChromeClient(CordovaWebView webView) {
+    	String r = this.getStringProperty("webView", "org.apache.cordova.Android").concat("ChromeClient");
+
+        try {
+            Class chromeClientClass = Class.forName(r);
+            Constructor<CordovaChromeClient> [] chromeClientConstructors = chromeClientClass.getConstructors();
+            
+            
+            if(CordovaChromeClient.class.isAssignableFrom(chromeClientClass)) {
+            	for (Constructor<CordovaChromeClient> constructor : chromeClientConstructors)
{
+            		try {
+            			CordovaChromeClient chromeClient =  (CordovaChromeClient) constructor.newInstance(this,
webView);
+            			return chromeClient;
+            		} catch (IllegalArgumentException e) {
+                        LOG.e(TAG, "Illegal arguments, try next constructor.");
+                    }
+            	}
+            }
+            else
+            {
+                LOG.e(TAG, "The WebView Engine is NOT a proper WebView, defaulting to system
WebView");
+            }
+        } catch (ClassNotFoundException e) {
+            LOG.e(TAG, "The WebView Engine was not found, defaulting to system WebView");
+        } catch (InstantiationException e) {
+            LOG.e(TAG, "Unable to instantiate the WebView, defaulting to system WebView");
+        } catch (IllegalAccessException e) {
+            LOG.e(TAG, "Illegal Access to Constructor.  This should never happen, defaulting
to system WebView");
+        } catch (IllegalArgumentException e) {
+            LOG.e(TAG, "The WebView does not implement the default constructor, defaulting
to system WebView");
+        } catch (InvocationTargetException e) {
+            LOG.e(TAG, "Invocation Target Exception! Reflection is hard, defaulting to system
WebView");
+        }
+
         return (CordovaChromeClient) new AndroidChromeClient(this, webView);
     }
 


Mime
View raw message