You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by ia...@apache.org on 2014/04/30 21:53:09 UTC

[11/12] android commit: Defer construction of client objects to WebView

Defer construction of client objects to WebView


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

Branch: refs/heads/pluggable_webview
Commit: 8e31ef7be6165d4566e2a27d1a72b9770db10ab9
Parents: f4555f7
Author: Ian Clelland <ic...@chromium.org>
Authored: Thu Apr 24 14:57:34 2014 -0400
Committer: Ian Clelland <ic...@chromium.org>
Committed: Tue Apr 29 22:50:12 2014 -0400

----------------------------------------------------------------------
 .../src/org/apache/cordova/AndroidWebView.java  | 27 +++++++++++++-------
 .../src/org/apache/cordova/CordovaActivity.java | 18 ++++++-------
 .../src/org/apache/cordova/CordovaWebView.java  |  4 +++
 3 files changed, 30 insertions(+), 19 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-android/blob/8e31ef7b/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..2603a86 100755
--- a/framework/src/org/apache/cordova/AndroidWebView.java
+++ b/framework/src/org/apache/cordova/AndroidWebView.java
@@ -166,8 +166,6 @@ 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.initWebViewClient(this.cordova);
         this.loadConfiguration();
         this.setup();
     }
@@ -190,7 +188,6 @@ 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.loadConfiguration();
         this.setup();
     }
@@ -214,28 +211,40 @@ 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.initWebViewClient(this.cordova);
         this.loadConfiguration();
         this.setup();
     }
 
     /**
-     * set the WebViewClient, but provide special case handling for IceCreamSandwich.
+     * Create a default WebViewClient object for this webview. This can be overridden by the
+     * main application's CordovaActivity subclass.
+     *
+     * By default, it creates an AndroidWebViewClient, but we provide special case handling for
+     * IceCreamSandwich.
      */
-    private void initWebViewClient(CordovaInterface cordova) {
+    @Override
+    public CordovaWebViewClient makeWebViewClient() {
         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));
+            return (CordovaWebViewClient) new AndroidWebViewClient(this.cordova, this);
         }
         else
         {
-            this.setWebViewClient((CordovaWebViewClient) new IceCreamCordovaWebViewClient(this.cordova, this));
+            return (CordovaWebViewClient) new IceCreamCordovaWebViewClient(this.cordova, this);
         }
     }
 
     /**
+     * Create a default WebViewClient object for this webview. This can be overridden by the
+     * main application's CordovaActivity subclass.
+     */
+    @Override
+    public CordovaChromeClient makeWebChromeClient() {
+        return (CordovaChromeClient) new AndroidChromeClient(this.cordova);
+    }
+
+    /**
      * Initialize webview.
      */
     @SuppressWarnings("deprecation")

http://git-wip-us.apache.org/repos/asf/cordova-android/blob/8e31ef7b/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..01eff1c 100755
--- a/framework/src/org/apache/cordova/CordovaActivity.java
+++ b/framework/src/org/apache/cordova/CordovaActivity.java
@@ -248,29 +248,27 @@ public class CordovaActivity extends Activity implements CordovaInterface {
     /**
      * Construct the client for the default web view object.
      *
-     * This is intended to be overridable by subclasses of CordovaIntent which
-     * require a more specialized web view.
+     * This is intended to be overridable by subclasses of CordovaActivity which
+     * require a more specialized web view. By default, it allows the webView
+     * to create its own client objects.
      *
      * @param webView the default constructed web view object
      */
     protected CordovaWebViewClient makeWebViewClient(CordovaWebView 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();
     }
 
     /**
      * Construct the chrome client for the default web view object.
      *
-     * This is intended to be overridable by subclasses of CordovaIntent which
-     * require a more specialized web view.
+     * This is intended to be overridable by subclasses of CordovaActivity which
+     * require a more specialized web view. By default, it allows the webView
+     * to create its own client objects.
      *
      * @param webView the default constructed web view object
      */
     protected CordovaChromeClient makeChromeClient(CordovaWebView webView) {
-        return (CordovaChromeClient) new AndroidChromeClient(this, webView);
+        return webView.makeWebChromeClient();
     }
 
     /**

http://git-wip-us.apache.org/repos/asf/cordova-android/blob/8e31ef7b/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..a5496cf 100644
--- a/framework/src/org/apache/cordova/CordovaWebView.java
+++ b/framework/src/org/apache/cordova/CordovaWebView.java
@@ -19,6 +19,10 @@ public interface CordovaWebView {
 
     View getView();
 
+    CordovaWebViewClient makeWebViewClient();
+
+    CordovaChromeClient makeWebChromeClient();
+
     void setWebViewClient(CordovaWebViewClient webViewClient);
 
     void setWebChromeClient(CordovaChromeClient webChromeClient);