diff --git a/framework/src/org/apache/cordova/AndroidWebView.java b/framework/src/org/apache/cordova/AndroidWebView.java index a940dd5d..2603a867 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,27 +211,39 @@ 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. */ diff --git a/framework/src/org/apache/cordova/CordovaActivity.java b/framework/src/org/apache/cordova/CordovaActivity.java index 8931b518..01eff1c1 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(); } /** diff --git a/framework/src/org/apache/cordova/CordovaWebView.java b/framework/src/org/apache/cordova/CordovaWebView.java index d23baeec..a5496cfd 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);