mirror of
https://github.com/apache/cordova-android.git
synced 2025-01-31 17:32:51 +08:00
Merge pull request #3 from huningxin/pluggable_webview
Make correct webview client and chrome client for specific webview engin...
This commit is contained in:
commit
bfd8bf9ca4
@ -166,7 +166,7 @@ public class AndroidWebView extends WebView implements CordovaWebView {
|
|||||||
{
|
{
|
||||||
Log.d(TAG, "Your activity must implement CordovaInterface to work");
|
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.initWebViewClient(this.cordova);
|
||||||
this.loadConfiguration();
|
this.loadConfiguration();
|
||||||
this.setup();
|
this.setup();
|
||||||
@ -190,7 +190,7 @@ public class AndroidWebView extends WebView implements CordovaWebView {
|
|||||||
{
|
{
|
||||||
Log.d(TAG, "Your activity must implement CordovaInterface to work");
|
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.loadConfiguration();
|
||||||
this.setup();
|
this.setup();
|
||||||
}
|
}
|
||||||
@ -214,7 +214,7 @@ public class AndroidWebView extends WebView implements CordovaWebView {
|
|||||||
{
|
{
|
||||||
Log.d(TAG, "Your activity must implement CordovaInterface to work");
|
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.initWebViewClient(this.cordova);
|
||||||
this.loadConfiguration();
|
this.loadConfiguration();
|
||||||
this.setup();
|
this.setup();
|
||||||
@ -224,15 +224,7 @@ public class AndroidWebView extends WebView implements CordovaWebView {
|
|||||||
* set the WebViewClient, but provide special case handling for IceCreamSandwich.
|
* set the WebViewClient, but provide special case handling for IceCreamSandwich.
|
||||||
*/
|
*/
|
||||||
private void initWebViewClient(CordovaInterface cordova) {
|
private void initWebViewClient(CordovaInterface cordova) {
|
||||||
if(android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.HONEYCOMB ||
|
this.setWebViewClient(this.makeWebViewClient());
|
||||||
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));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -1082,4 +1074,18 @@ public class AndroidWebView extends WebView implements CordovaWebView {
|
|||||||
public View getView() {
|
public View getView() {
|
||||||
return this;
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -222,8 +222,14 @@ public class CordovaActivity extends Activity implements CordovaInterface {
|
|||||||
|
|
||||||
|
|
||||||
if(CordovaWebView.class.isAssignableFrom(webViewClass)) {
|
if(CordovaWebView.class.isAssignableFrom(webViewClass)) {
|
||||||
CordovaWebView webView = (CordovaWebView) webViewConstructors[0].newInstance(this);
|
for (Constructor<CordovaWebView> constructor : webViewConstructors) {
|
||||||
|
try {
|
||||||
|
CordovaWebView webView = (CordovaWebView) constructor.newInstance(this);
|
||||||
return webView;
|
return webView;
|
||||||
|
} catch (IllegalArgumentException e) {
|
||||||
|
LOG.e(TAG, "Illegal arguments, try next constructor.");
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -254,11 +260,7 @@ public class CordovaActivity extends Activity implements CordovaInterface {
|
|||||||
* @param webView the default constructed web view object
|
* @param webView the default constructed web view object
|
||||||
*/
|
*/
|
||||||
protected CordovaWebViewClient makeWebViewClient(CordovaWebView webView) {
|
protected CordovaWebViewClient makeWebViewClient(CordovaWebView webView) {
|
||||||
if(android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.HONEYCOMB) {
|
return webView.makeWebViewClient();
|
||||||
return (CordovaWebViewClient) new AndroidWebViewClient(this, webView);
|
|
||||||
} else {
|
|
||||||
return (CordovaWebViewClient) new IceCreamCordovaWebViewClient(this, webView);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -270,7 +272,7 @@ public class CordovaActivity extends Activity implements CordovaInterface {
|
|||||||
* @param webView the default constructed web view object
|
* @param webView the default constructed web view object
|
||||||
*/
|
*/
|
||||||
protected CordovaChromeClient makeChromeClient(CordovaWebView webView) {
|
protected CordovaChromeClient makeChromeClient(CordovaWebView webView) {
|
||||||
return (CordovaChromeClient) new AndroidChromeClient(this, webView);
|
return webView.makeChromeClient();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -19,6 +19,10 @@ public interface CordovaWebView {
|
|||||||
|
|
||||||
View getView();
|
View getView();
|
||||||
|
|
||||||
|
CordovaWebViewClient makeWebViewClient();
|
||||||
|
|
||||||
|
CordovaChromeClient makeChromeClient();
|
||||||
|
|
||||||
void setWebViewClient(CordovaWebViewClient webViewClient);
|
void setWebViewClient(CordovaWebViewClient webViewClient);
|
||||||
|
|
||||||
void setWebChromeClient(CordovaChromeClient webChromeClient);
|
void setWebChromeClient(CordovaChromeClient webChromeClient);
|
||||||
|
Loading…
Reference in New Issue
Block a user