From f604988181e956a54b5c3eb6c017fb93efc887ad Mon Sep 17 00:00:00 2001 From: Ian Clelland Date: Fri, 16 Aug 2013 11:47:06 -0400 Subject: [PATCH] Refactor CordovaActivity.init so that subclasses can easily override factory methods for webview objects --- .../org/apache/cordova/CordovaActivity.java | 51 +++++++++++++++---- 1 file changed, 40 insertions(+), 11 deletions(-) diff --git a/framework/src/org/apache/cordova/CordovaActivity.java b/framework/src/org/apache/cordova/CordovaActivity.java index 7e0d1bec..9937c3fa 100755 --- a/framework/src/org/apache/cordova/CordovaActivity.java +++ b/framework/src/org/apache/cordova/CordovaActivity.java @@ -311,21 +311,50 @@ public class CordovaActivity extends Activity implements CordovaInterface { return this; } + /** + * Construct the default web view object. + * + * This is intended to be overridable by subclasses of CordovaIntent which + * require a more specialized web view. + */ + protected CordovaWebView makeWebView() { + return new CordovaWebView(CordovaActivity.this); + } + + /** + * 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. + * + * @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 new CordovaWebViewClient(this, webView); + } else { + return new IceCreamCordovaWebViewClient(this, webView); + } + } + + /** + * 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. + * + * @param webView the default constructed web view object + */ + protected CordovaChromeClient makeChromeClient(CordovaWebView webView) { + return new CordovaChromeClient(this, webView); + } + /** * Create and initialize web container with default web view objects. */ public void init() { - CordovaWebView webView = new CordovaWebView(CordovaActivity.this); - CordovaWebViewClient webViewClient; - if(android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.HONEYCOMB) - { - webViewClient = new CordovaWebViewClient(this, webView); - } - else - { - webViewClient = new IceCreamCordovaWebViewClient(this, webView); - } - this.init(webView, webViewClient, new CordovaChromeClient(this, webView)); + CordovaWebView webView = makeWebView(); + this.init(webView, makeWebViewClient(webView), makeChromeClient(webView)); } /**