You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by bo...@apache.org on 2014/05/01 00:02:59 UTC

[15/18] android commit: Delegate making WebViewClient and ChromeClient to webview engine.

Delegate making WebViewClient and ChromeClient to webview engine.

Revert the change of webview preference name.


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

Branch: refs/heads/pluggable_webview
Commit: 7a5405d2ab5d482f750939b8f2c316a2ae13e998
Parents: dbfc292
Author: Ningxin Hu <ni...@intel.com>
Authored: Thu Apr 24 09:41:47 2014 +0800
Committer: Ningxin Hu <ni...@intel.com>
Committed: Thu Apr 24 09:42:51 2014 +0800

----------------------------------------------------------------------
 .../src/org/apache/cordova/AndroidWebView.java  | 30 ++++---
 .../src/org/apache/cordova/CordovaActivity.java | 86 +++-----------------
 .../src/org/apache/cordova/CordovaWebView.java  |  4 +
 3 files changed, 33 insertions(+), 87 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-android/blob/7a5405d2/framework/src/org/apache/cordova/AndroidWebView.java
----------------------------------------------------------------------
diff --git a/framework/src/org/apache/cordova/AndroidWebView.java b/framework/src/org/apache/cordova/AndroidWebView.java
index a940dd5..4e86dba 100755
--- a/framework/src/org/apache/cordova/AndroidWebView.java
+++ b/framework/src/org/apache/cordova/AndroidWebView.java
@@ -166,7 +166,7 @@ public class AndroidWebView extends WebView implements CordovaWebView {
         {
             Log.d(TAG, "Your activity must implement CordovaInterface to work");
         }
-        this.setWebChromeClient((CordovaChromeClient) new AndroidChromeClient(this.cordova, this));
+        this.setWebChromeClient(this.makeChromeClient());
         this.initWebViewClient(this.cordova);
         this.loadConfiguration();
         this.setup();
@@ -190,7 +190,7 @@ public class AndroidWebView extends WebView implements CordovaWebView {
         {
             Log.d(TAG, "Your activity must implement CordovaInterface to work");
         }
-        this.setWebChromeClient((CordovaChromeClient) new AndroidChromeClient(this.cordova, this));
+        this.setWebChromeClient(this.makeChromeClient());
         this.loadConfiguration();
         this.setup();
     }
@@ -214,7 +214,7 @@ public class AndroidWebView extends WebView implements CordovaWebView {
         {
             Log.d(TAG, "Your activity must implement CordovaInterface to work");
         }
-        this.setWebChromeClient((CordovaChromeClient) new AndroidChromeClient(this.cordova));
+        this.setWebChromeClient(this.makeChromeClient());
         this.initWebViewClient(this.cordova);
         this.loadConfiguration();
         this.setup();
@@ -224,15 +224,7 @@ public class AndroidWebView extends WebView implements CordovaWebView {
      * set the WebViewClient, but provide special case handling for IceCreamSandwich.
      */
     private void initWebViewClient(CordovaInterface cordova) {
-        if(android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.HONEYCOMB ||
-                android.os.Build.VERSION.SDK_INT > android.os.Build.VERSION_CODES.JELLY_BEAN_MR1)
-        {
-            this.setWebViewClient((CordovaWebViewClient) new AndroidWebViewClient(this.cordova, this));
-        }
-        else
-        {
-            this.setWebViewClient((CordovaWebViewClient) new IceCreamCordovaWebViewClient(this.cordova, this));
-        }
+        this.setWebViewClient(this.makeWebViewClient());
     }
 
     /**
@@ -1082,4 +1074,18 @@ public class AndroidWebView extends WebView implements CordovaWebView {
     public View getView() {
         return this;
     }
+
+    @Override
+    public CordovaWebViewClient makeWebViewClient() {
+        if(android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.HONEYCOMB) {
+            return (CordovaWebViewClient) new AndroidWebViewClient(this.cordova, this);
+        } else {
+            return (CordovaWebViewClient) new IceCreamCordovaWebViewClient(this.cordova, this);
+        }
+    }
+
+    @Override
+    public CordovaChromeClient makeChromeClient() {
+        return (CordovaChromeClient) new AndroidChromeClient(this.cordova, this);
+    }
 }

http://git-wip-us.apache.org/repos/asf/cordova-android/blob/7a5405d2/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 d566714..a161bf8 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.Android").concat("WebView");
+        String r = this.getStringProperty("webView", "org.apache.cordova.AndroidWebView");
 
         try {
             Class webViewClass = Class.forName(r);
@@ -222,8 +222,14 @@ public class CordovaActivity extends Activity implements CordovaInterface {
             
             
             if(CordovaWebView.class.isAssignableFrom(webViewClass)) {
-                CordovaWebView webView =  (CordovaWebView) webViewConstructors[0].newInstance(this);
-                return webView;
+                for (Constructor<CordovaWebView> constructor : webViewConstructors) {
+                    try {
+                        CordovaWebView webView =  (CordovaWebView) constructor.newInstance(this);
+                        return webView;
+                    } catch (IllegalArgumentException e) {
+                        LOG.e(TAG, "Illegal arguments, try next constructor.");
+                    }
+                }
             }
             else
             {
@@ -254,44 +260,7 @@ 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 {
-            return (CordovaWebViewClient) new IceCreamCordovaWebViewClient(this, webView);
-        }
+    	return webView.makeWebViewClient();
     }
 
     /**
@@ -303,40 +272,7 @@ 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);
+    	return webView.makeChromeClient();
     }
 
     /**

http://git-wip-us.apache.org/repos/asf/cordova-android/blob/7a5405d2/framework/src/org/apache/cordova/CordovaWebView.java
----------------------------------------------------------------------
diff --git a/framework/src/org/apache/cordova/CordovaWebView.java b/framework/src/org/apache/cordova/CordovaWebView.java
index d23baee..fe04390 100644
--- a/framework/src/org/apache/cordova/CordovaWebView.java
+++ b/framework/src/org/apache/cordova/CordovaWebView.java
@@ -18,6 +18,10 @@ public interface CordovaWebView {
     Object jsMessageQueue = null;
 
     View getView();
+    
+    CordovaWebViewClient makeWebViewClient();
+    
+    CordovaChromeClient makeChromeClient();
 
     void setWebViewClient(CordovaWebViewClient webViewClient);