mirror of
https://github.com/apache/cordova-android.git
synced 2025-03-16 08:21:04 +08:00
Partially moved the callback server into the WebView. The WebView MUST own the CordovaWebViewClient and the CordovaWebChromeClient
This commit is contained in:
parent
59ff94fefb
commit
b793fbfc28
@ -45,6 +45,7 @@ public class CordovaChromeClient extends WebChromeClient {
|
|||||||
private String TAG = "CordovaLog";
|
private String TAG = "CordovaLog";
|
||||||
private long MAX_QUOTA = 100 * 1024 * 1024;
|
private long MAX_QUOTA = 100 * 1024 * 1024;
|
||||||
private DroidGap ctx;
|
private DroidGap ctx;
|
||||||
|
private CordovaWebView appView;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor.
|
* Constructor.
|
||||||
@ -53,6 +54,13 @@ public class CordovaChromeClient extends WebChromeClient {
|
|||||||
*/
|
*/
|
||||||
public CordovaChromeClient(Context ctx) {
|
public CordovaChromeClient(Context ctx) {
|
||||||
this.ctx = (DroidGap) ctx;
|
this.ctx = (DroidGap) ctx;
|
||||||
|
appView = this.ctx.appView;
|
||||||
|
}
|
||||||
|
|
||||||
|
public CordovaChromeClient(Context ctx, CordovaWebView app)
|
||||||
|
{
|
||||||
|
this.ctx = (DroidGap) ctx;
|
||||||
|
appView = app;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -182,7 +190,7 @@ public class CordovaChromeClient extends WebChromeClient {
|
|||||||
String action = array.getString(1);
|
String action = array.getString(1);
|
||||||
String callbackId = array.getString(2);
|
String callbackId = array.getString(2);
|
||||||
boolean async = array.getBoolean(3);
|
boolean async = array.getBoolean(3);
|
||||||
String r = ctx.pluginManager.exec(service, action, callbackId, message, async);
|
String r = appView.pluginManager.exec(service, action, callbackId, message, async);
|
||||||
result.confirm(r);
|
result.confirm(r);
|
||||||
} catch (JSONException e) {
|
} catch (JSONException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
|
@ -9,6 +9,7 @@ import java.util.regex.Matcher;
|
|||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
import org.apache.cordova.api.LOG;
|
import org.apache.cordova.api.LOG;
|
||||||
|
import org.apache.cordova.api.PluginManager;
|
||||||
import org.xmlpull.v1.XmlPullParserException;
|
import org.xmlpull.v1.XmlPullParserException;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
@ -24,10 +25,16 @@ public class CordovaWebView extends WebView {
|
|||||||
|
|
||||||
/** The authorization tokens. */
|
/** The authorization tokens. */
|
||||||
private Hashtable<String, AuthenticationToken> authenticationTokens = new Hashtable<String, AuthenticationToken>();
|
private Hashtable<String, AuthenticationToken> authenticationTokens = new Hashtable<String, AuthenticationToken>();
|
||||||
private Context mCtx;
|
|
||||||
/** The whitelist **/
|
/** The whitelist **/
|
||||||
private ArrayList<Pattern> whiteList = new ArrayList<Pattern>();
|
private ArrayList<Pattern> whiteList = new ArrayList<Pattern>();
|
||||||
private HashMap<String, Boolean> whiteListCache = new HashMap<String,Boolean>();
|
private HashMap<String, Boolean> whiteListCache = new HashMap<String,Boolean>();
|
||||||
|
protected PluginManager pluginManager;
|
||||||
|
|
||||||
|
/** Actvities and other important classes **/
|
||||||
|
private Context mCtx;
|
||||||
|
private CordovaWebViewClient viewClient;
|
||||||
|
private CordovaChromeClient chromeClient;
|
||||||
|
|
||||||
public CordovaWebView(Context context) {
|
public CordovaWebView(Context context) {
|
||||||
super(context);
|
super(context);
|
||||||
@ -74,11 +81,18 @@ public class CordovaWebView extends WebView {
|
|||||||
String databasePath = mCtx.getApplicationContext().getDir("database", Context.MODE_PRIVATE).getPath();
|
String databasePath = mCtx.getApplicationContext().getDir("database", Context.MODE_PRIVATE).getPath();
|
||||||
settings.setDatabasePath(databasePath);
|
settings.setDatabasePath(databasePath);
|
||||||
|
|
||||||
|
//Setup the WebChromeClient and WebViewClient
|
||||||
|
setWebViewClient(new CordovaWebViewClient(mCtx, this));
|
||||||
|
setWebChromeClient(new CordovaChromeClient(mCtx, this));
|
||||||
|
|
||||||
// Enable DOM storage
|
// Enable DOM storage
|
||||||
settings.setDomStorageEnabled(true);
|
settings.setDomStorageEnabled(true);
|
||||||
|
|
||||||
// Enable built-in geolocation
|
// Enable built-in geolocation
|
||||||
settings.setGeolocationEnabled(true);
|
settings.setGeolocationEnabled(true);
|
||||||
|
|
||||||
|
//Start up the plugin manager
|
||||||
|
this.pluginManager = new PluginManager(this, (DroidGap) mCtx);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -20,6 +20,7 @@ package org.apache.cordova;
|
|||||||
|
|
||||||
import org.apache.cordova.api.LOG;
|
import org.apache.cordova.api.LOG;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.pm.ApplicationInfo;
|
import android.content.pm.ApplicationInfo;
|
||||||
import android.content.pm.PackageManager;
|
import android.content.pm.PackageManager;
|
||||||
@ -41,6 +42,7 @@ public class CordovaWebViewClient extends WebViewClient {
|
|||||||
|
|
||||||
private static final String TAG = "Cordova";
|
private static final String TAG = "Cordova";
|
||||||
DroidGap ctx;
|
DroidGap ctx;
|
||||||
|
CordovaWebView appView;
|
||||||
private boolean doClearHistory = false;
|
private boolean doClearHistory = false;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -50,6 +52,13 @@ public class CordovaWebViewClient extends WebViewClient {
|
|||||||
*/
|
*/
|
||||||
public CordovaWebViewClient(DroidGap ctx) {
|
public CordovaWebViewClient(DroidGap ctx) {
|
||||||
this.ctx = ctx;
|
this.ctx = ctx;
|
||||||
|
appView = ctx.appView;
|
||||||
|
}
|
||||||
|
|
||||||
|
public CordovaWebViewClient(Context ctx, CordovaWebView view)
|
||||||
|
{
|
||||||
|
this.ctx = (DroidGap) ctx;
|
||||||
|
appView = view;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -64,7 +73,7 @@ public class CordovaWebViewClient extends WebViewClient {
|
|||||||
public boolean shouldOverrideUrlLoading(WebView view, String url) {
|
public boolean shouldOverrideUrlLoading(WebView view, String url) {
|
||||||
|
|
||||||
// First give any plugins the chance to handle the url themselves
|
// First give any plugins the chance to handle the url themselves
|
||||||
if ((this.ctx.pluginManager != null) && this.ctx.pluginManager.onOverrideUrlLoading(url)) {
|
if ((appView.pluginManager != null) && appView.pluginManager.onOverrideUrlLoading(url)) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// If dialing phone (tel:5551212)
|
// If dialing phone (tel:5551212)
|
||||||
|
@ -156,7 +156,6 @@ public class DroidGap extends Activity implements CordovaInterface {
|
|||||||
protected LinearLayout root;
|
protected LinearLayout root;
|
||||||
public boolean bound = false;
|
public boolean bound = false;
|
||||||
public CallbackServer callbackServer;
|
public CallbackServer callbackServer;
|
||||||
protected PluginManager pluginManager;
|
|
||||||
protected boolean cancelLoadUrl = false;
|
protected boolean cancelLoadUrl = false;
|
||||||
protected ProgressDialog spinnerDialog = null;
|
protected ProgressDialog spinnerDialog = null;
|
||||||
|
|
||||||
@ -285,9 +284,6 @@ public class DroidGap extends Activity implements CordovaInterface {
|
|||||||
ViewGroup.LayoutParams.FILL_PARENT,
|
ViewGroup.LayoutParams.FILL_PARENT,
|
||||||
1.0F));
|
1.0F));
|
||||||
|
|
||||||
this.appView.setWebChromeClient(webChromeClient);
|
|
||||||
this.setWebViewClient(this.appView, webViewClient);
|
|
||||||
|
|
||||||
// Add web view but make it invisible while loading URL
|
// Add web view but make it invisible while loading URL
|
||||||
this.appView.setVisibility(View.INVISIBLE);
|
this.appView.setVisibility(View.INVISIBLE);
|
||||||
root.addView(this.appView);
|
root.addView(this.appView);
|
||||||
@ -296,19 +292,6 @@ public class DroidGap extends Activity implements CordovaInterface {
|
|||||||
// Clear cancel flag
|
// Clear cancel flag
|
||||||
this.cancelLoadUrl = false;
|
this.cancelLoadUrl = false;
|
||||||
|
|
||||||
// Create plugin manager
|
|
||||||
this.pluginManager = new PluginManager(this.appView, this);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Set the WebViewClient.
|
|
||||||
*
|
|
||||||
* @param appView
|
|
||||||
* @param client
|
|
||||||
*/
|
|
||||||
protected void setWebViewClient(WebView appView, WebViewClient client) {
|
|
||||||
this.webViewClient = client;
|
|
||||||
appView.setWebViewClient(client);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -403,7 +386,7 @@ public class DroidGap extends Activity implements CordovaInterface {
|
|||||||
else {
|
else {
|
||||||
me.callbackServer.reinit(url);
|
me.callbackServer.reinit(url);
|
||||||
}
|
}
|
||||||
me.pluginManager.init();
|
appView.pluginManager.init();
|
||||||
|
|
||||||
// If loadingDialog property, then show the App loading dialog for first page of app
|
// If loadingDialog property, then show the App loading dialog for first page of app
|
||||||
String loading = null;
|
String loading = null;
|
||||||
@ -734,9 +717,7 @@ public class DroidGap extends Activity implements CordovaInterface {
|
|||||||
this.appView.loadUrl("javascript:try{cordova.require('cordova/channel').onPause.fire();}catch(e){console.log('exception firing pause event from native');};");
|
this.appView.loadUrl("javascript:try{cordova.require('cordova/channel').onPause.fire();}catch(e){console.log('exception firing pause event from native');};");
|
||||||
|
|
||||||
// Forward to plugins
|
// Forward to plugins
|
||||||
if (this.pluginManager != null) {
|
appView.pluginManager.onPause(this.keepRunning);
|
||||||
this.pluginManager.onPause(this.keepRunning);
|
|
||||||
}
|
|
||||||
|
|
||||||
// If app doesn't want to run in background
|
// If app doesn't want to run in background
|
||||||
if (!this.keepRunning) {
|
if (!this.keepRunning) {
|
||||||
@ -754,9 +735,7 @@ public class DroidGap extends Activity implements CordovaInterface {
|
|||||||
super.onNewIntent(intent);
|
super.onNewIntent(intent);
|
||||||
|
|
||||||
//Forward to plugins
|
//Forward to plugins
|
||||||
if (this.pluginManager != null) {
|
appView.pluginManager.onNewIntent(intent);
|
||||||
this.pluginManager.onNewIntent(intent);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -779,9 +758,7 @@ public class DroidGap extends Activity implements CordovaInterface {
|
|||||||
this.appView.loadUrl("javascript:try{cordova.require('cordova/channel').onResume.fire();}catch(e){console.log('exception firing resume event from native');};");
|
this.appView.loadUrl("javascript:try{cordova.require('cordova/channel').onResume.fire();}catch(e){console.log('exception firing resume event from native');};");
|
||||||
|
|
||||||
// Forward to plugins
|
// Forward to plugins
|
||||||
if (this.pluginManager != null) {
|
appView.pluginManager.onResume(this.keepRunning || this.activityResultKeepRunning);
|
||||||
this.pluginManager.onResume(this.keepRunning || this.activityResultKeepRunning);
|
|
||||||
}
|
|
||||||
|
|
||||||
// If app doesn't want to run in background
|
// If app doesn't want to run in background
|
||||||
if (!this.keepRunning || this.activityResultKeepRunning) {
|
if (!this.keepRunning || this.activityResultKeepRunning) {
|
||||||
@ -814,9 +791,7 @@ public class DroidGap extends Activity implements CordovaInterface {
|
|||||||
this.appView.loadUrl("about:blank");
|
this.appView.loadUrl("about:blank");
|
||||||
|
|
||||||
// Forward to plugins
|
// Forward to plugins
|
||||||
if (this.pluginManager != null) {
|
appView.pluginManager.onDestroy();
|
||||||
this.pluginManager.onDestroy();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
this.endActivity();
|
this.endActivity();
|
||||||
@ -832,9 +807,7 @@ public class DroidGap extends Activity implements CordovaInterface {
|
|||||||
public void postMessage(String id, Object data) {
|
public void postMessage(String id, Object data) {
|
||||||
|
|
||||||
// Forward to plugins
|
// Forward to plugins
|
||||||
if (this.pluginManager != null) {
|
appView.pluginManager.postMessage(id, data);
|
||||||
this.pluginManager.postMessage(id, data);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -848,9 +821,7 @@ public class DroidGap extends Activity implements CordovaInterface {
|
|||||||
*/
|
*/
|
||||||
@Deprecated
|
@Deprecated
|
||||||
public void addService(String serviceType, String className) {
|
public void addService(String serviceType, String className) {
|
||||||
if (this.pluginManager != null) {
|
appView.pluginManager.addService(serviceType, className);
|
||||||
this.pluginManager.addService(serviceType, className);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
x
Reference in New Issue
Block a user